diff options
Diffstat (limited to '')
| -rw-r--r-- | common.h | 4 | ||||
| -rw-r--r-- | librecrypt.h | 2 | ||||
| -rw-r--r-- | librecrypt_concat_char_no_nul_.c | 22 | ||||
| -rw-r--r-- | librecrypt_concat_mem_.c | 18 | ||||
| -rw-r--r-- | librecrypt_concat_str_.c | 16 | ||||
| -rw-r--r-- | librecrypt_concat_uint_.c | 17 | ||||
| -rw-r--r-- | librecrypt_concat_void_.c | 26 | ||||
| -rw-r--r-- | librecrypt_post_concat_adjust_.c | 15 | ||||
| -rw-r--r-- | librecrypt_version.c | 23 |
9 files changed, 133 insertions, 10 deletions
@@ -408,7 +408,7 @@ librecrypt_concat_void_(struct concat_state *state, size_t len) { size_t n = state->size ? MIN(state->size - 1u, len) : 0u; if (len > SIZE_MAX - state->len) - abort(); /* TODO not covered */ + abort(); /* $covered$ */ state->len += len; if (n) { state->buf = &state->buf[n]; @@ -495,7 +495,7 @@ inline void librecrypt_concat_char_no_nul_(struct concat_state *state, char c) { if (state->len == SIZE_MAX) - abort(); /* TODO not covered */ + abort(); /* $covered$ */ state->len += 1u; if (state->size > 1u) { *state->buf++ = c; diff --git a/librecrypt.h b/librecrypt.h index dec9f2c..aec7574 100644 --- a/librecrypt.h +++ b/librecrypt.h @@ -187,7 +187,6 @@ extern const int librecrypt_version_patch; * * @since 1.2 */ -/* TODO test */ #define LIBRECRYPT_VERSION_CMP_BUILD(MAJOR, MINOR, PATCH)\ LIBRECRYPT_VERSION_CMP__(MAJOR, LIBRECRYPT_VERSION_MAJOR,\ MINOR, LIBRECRYPT_VERSION_MINOR,\ @@ -221,7 +220,6 @@ extern const int librecrypt_version_patch; * * @since 1.2 */ -/* TODO test */ #define LIBRECRYPT_VERSION_CMP_LINK(MAJOR, MINOR, PATCH)\ LIBRECRYPT_VERSION_CMP__(MAJOR, librecrypt_version_major,\ MINOR, librecrypt_version_minor,\ diff --git a/librecrypt_concat_char_no_nul_.c b/librecrypt_concat_char_no_nul_.c index 421509c..a873bcb 100644 --- a/librecrypt_concat_char_no_nul_.c +++ b/librecrypt_concat_char_no_nul_.c @@ -12,10 +12,30 @@ extern inline void librecrypt_concat_char_no_nul_(struct concat_state *state, ch int main(void) { + char buf[3]; + struct concat_state state = {buf, sizeof(buf), 0u}; + SET_UP_ALARM(); + INIT_TEST_ABORT(); INIT_RESOURCE_TEST(); - /* TODO test */ + memset(buf, 'x', sizeof(buf)); + + librecrypt_concat_char_no_nul_(&state, 'a'); + librecrypt_concat_char_no_nul_(&state, 'b'); + librecrypt_concat_char_no_nul_(&state, 'c'); + librecrypt_concat_char_no_nul_(&state, 'd'); + assert(!memcmp(buf, "abx", sizeof(buf))); + assert(state.buf == &buf[2u]); + assert(state.size == 1u); + assert(state.len == 4u); + + state = (struct concat_state){NULL, 0u, 0u}; + librecrypt_concat_char_no_nul_(&state, 'a'); + assert(state.len == 1u); + + state = (struct concat_state){NULL, 0u, SIZE_MAX}; + EXPECT_ABORT(librecrypt_concat_char_no_nul_(&state, 'a')); STOP_RESOURCE_TEST(); return 0; diff --git a/librecrypt_concat_mem_.c b/librecrypt_concat_mem_.c index edc826a..296303e 100644 --- a/librecrypt_concat_mem_.c +++ b/librecrypt_concat_mem_.c @@ -12,10 +12,26 @@ extern inline void librecrypt_concat_mem_(struct concat_state *state, const char int main(void) { + char buf[5]; + struct concat_state state = {buf, sizeof(buf), 0u}; + SET_UP_ALARM(); INIT_RESOURCE_TEST(); - /* TODO test */ + memset(buf, 'x', sizeof(buf)); + + librecrypt_concat_mem_(&state, "abcdef", 6u); + assert(!memcmp(buf, "abcd\0", sizeof(buf))); + assert(state.buf == &buf[4u]); + assert(state.size == 1u); + assert(state.len == 6u); + librecrypt_concat_mem_(&state, "z", 1u); + assert(!memcmp(buf, "abcd\0", sizeof(buf))); + assert(state.len == 7u); + + state = (struct concat_state){NULL, 0u, 0u}; + librecrypt_concat_mem_(&state, "abc", 3u); + assert(state.len == 3u); STOP_RESOURCE_TEST(); return 0; diff --git a/librecrypt_concat_str_.c b/librecrypt_concat_str_.c index 6ad7e48..d89f4dd 100644 --- a/librecrypt_concat_str_.c +++ b/librecrypt_concat_str_.c @@ -12,10 +12,24 @@ extern inline void librecrypt_concat_str_(struct concat_state *state, const char int main(void) { + char buf[5]; + struct concat_state state = {buf, sizeof(buf), 0u}; + SET_UP_ALARM(); INIT_RESOURCE_TEST(); - /* TODO test */ + memset(buf, 'x', sizeof(buf)); + + librecrypt_concat_str_(&state, "ab"); + librecrypt_concat_str_(&state, "cdef"); + assert(!memcmp(buf, "abcd\0", sizeof(buf))); + assert(state.buf == &buf[4u]); + assert(state.size == 1u); + assert(state.len == 6u); + + state = (struct concat_state){NULL, 0u, 0u}; + librecrypt_concat_str_(&state, "abc"); + assert(state.len == 3u); STOP_RESOURCE_TEST(); return 0; diff --git a/librecrypt_concat_uint_.c b/librecrypt_concat_uint_.c index a492e0b..2f74272 100644 --- a/librecrypt_concat_uint_.c +++ b/librecrypt_concat_uint_.c @@ -28,10 +28,25 @@ librecrypt_concat_uint_(struct concat_state *state, uintmax_t value) int main(void) { + char buf[sizeof("0") + 3u * sizeof(uintmax_t)]; + char expected[sizeof(buf)]; + struct concat_state state = {buf, sizeof(buf), 0u}; + SET_UP_ALARM(); INIT_RESOURCE_TEST(); - /* TODO test */ + memset(buf, 'x', sizeof(buf)); + assert(sprintf(expected, "0%ju", UINTMAX_MAX) > 0); + + librecrypt_concat_uint_(&state, 0u); + librecrypt_concat_uint_(&state, UINTMAX_MAX); + assert(state.len == strlen(expected)); + assert(!strcmp(buf, expected)); + + state = (struct concat_state){buf, 3u, 0u}; + librecrypt_concat_uint_(&state, 123u); + assert(!strcmp(buf, "12")); + assert(state.len == 3u); STOP_RESOURCE_TEST(); return 0; diff --git a/librecrypt_concat_void_.c b/librecrypt_concat_void_.c index 889aed1..82bbef6 100644 --- a/librecrypt_concat_void_.c +++ b/librecrypt_concat_void_.c @@ -12,10 +12,34 @@ extern inline size_t librecrypt_concat_void_(struct concat_state *state, size_t int main(void) { + char buf[4]; + struct concat_state state = {buf, sizeof(buf), 0u}; + SET_UP_ALARM(); + INIT_TEST_ABORT(); INIT_RESOURCE_TEST(); - /* TODO test */ + memset(buf, 'x', sizeof(buf)); + + assert(librecrypt_concat_void_(&state, 2u) == 2u); + assert(state.buf == &buf[2u]); + assert(state.size == 2u); + assert(state.len == 2u); + assert(!memcmp(buf, "xx\0x", sizeof(buf))); + assert(librecrypt_concat_void_(&state, 5u) == 1u); + assert(state.buf == &buf[3u]); + assert(state.size == 1u); + assert(state.len == 7u); + assert(!memcmp(buf, "xx\0\0", sizeof(buf))); + + state = (struct concat_state){NULL, 0u, 0u}; + assert(librecrypt_concat_void_(&state, 5u) == 0u); + assert(state.buf == NULL); + assert(state.size == 0u); + assert(state.len == 5u); + + state = (struct concat_state){NULL, 0u, SIZE_MAX}; + EXPECT_ABORT(state.size = librecrypt_concat_void_(&state, 1u)); STOP_RESOURCE_TEST(); return 0; diff --git a/librecrypt_post_concat_adjust_.c b/librecrypt_post_concat_adjust_.c index 04715fd..458f4cb 100644 --- a/librecrypt_post_concat_adjust_.c +++ b/librecrypt_post_concat_adjust_.c @@ -12,10 +12,23 @@ extern inline int librecrypt_post_concat_adjust_(struct concat_state *state, siz int main(void) { + char buf[4]; + struct concat_state state = {buf, sizeof(buf), 0u}; + SET_UP_ALARM(); INIT_RESOURCE_TEST(); - /* TODO test */ + assert(librecrypt_post_concat_adjust_(&state, 2u) == 0); + assert(state.buf == &buf[2u]); + assert(state.size == 2u); + assert(state.len == 2u); + assert(librecrypt_post_concat_adjust_(&state, 5u) == 0); + assert(state.buf == &buf[3u]); + assert(state.size == 1u); + assert(state.len == 7u); + + state = (struct concat_state){buf, sizeof(buf), SIZE_MAX}; + assert(librecrypt_post_concat_adjust_(&state, 1u) == -1); STOP_RESOURCE_TEST(); return 0; diff --git a/librecrypt_version.c b/librecrypt_version.c index c5be2e1..ae5d861 100644 --- a/librecrypt_version.c +++ b/librecrypt_version.c @@ -14,6 +14,8 @@ const int librecrypt_version_patch = LIBRECRYPT_VERSION_PATCH; int main(void) { + int i, j, k; + SET_UP_ALARM(); INIT_RESOURCE_TEST(); @@ -24,6 +26,27 @@ main(void) EXPECT(LIBRECRYPT_VERSION_MINOR == LIB_MINOR); EXPECT(LIBRECRYPT_VERSION_PATCH == LIB_PATCH); + EXPECT(LIBRECRYPT_VERSION_CMP_BUILD(LIB_MAJOR, LIB_MINOR, LIB_PATCH) == 0); + EXPECT(LIBRECRYPT_VERSION_CMP_LINK(LIB_MAJOR, LIB_MINOR, LIB_PATCH) == 0); + for (i = 1; i <= 3; i++) { + EXPECT(LIBRECRYPT_VERSION_CMP_BUILD(LIB_MAJOR, LIB_MINOR, LIB_PATCH - i) == -1); + EXPECT(LIBRECRYPT_VERSION_CMP_BUILD(LIB_MAJOR, LIB_MINOR, LIB_PATCH + i) == +1); + EXPECT(LIBRECRYPT_VERSION_CMP_LINK(LIB_MAJOR, LIB_MINOR, LIB_PATCH - i) == -1); + EXPECT(LIBRECRYPT_VERSION_CMP_LINK(LIB_MAJOR, LIB_MINOR, LIB_PATCH + i) == +1); + for (j = -3; j <= 3; j++) { + EXPECT(LIBRECRYPT_VERSION_CMP_BUILD(LIB_MAJOR, LIB_MINOR - i, LIB_PATCH + j) == -2); + EXPECT(LIBRECRYPT_VERSION_CMP_BUILD(LIB_MAJOR, LIB_MINOR + i, LIB_PATCH + j) == +2); + EXPECT(LIBRECRYPT_VERSION_CMP_LINK(LIB_MAJOR, LIB_MINOR - i, LIB_PATCH + j) == -2); + EXPECT(LIBRECRYPT_VERSION_CMP_LINK(LIB_MAJOR, LIB_MINOR + i, LIB_PATCH + j) == +2); + for (k = -3; k <= 3; k++) { + EXPECT(LIBRECRYPT_VERSION_CMP_BUILD(LIB_MAJOR - i, LIB_MINOR + j, LIB_PATCH + k) == -3); + EXPECT(LIBRECRYPT_VERSION_CMP_BUILD(LIB_MAJOR + i, LIB_MINOR + j, LIB_PATCH + k) == +3); + EXPECT(LIBRECRYPT_VERSION_CMP_LINK(LIB_MAJOR - i, LIB_MINOR + j, LIB_PATCH + k) == -3); + EXPECT(LIBRECRYPT_VERSION_CMP_LINK(LIB_MAJOR + i, LIB_MINOR + j, LIB_PATCH + k) == +3); + } + } + } + STOP_RESOURCE_TEST(); return 0; } |
