aboutsummaryrefslogtreecommitdiffstats
path: root/librecrypt_concat_char_no_nul_.c
diff options
context:
space:
mode:
authorMattias Andrée <m@maandree.se>2026-09-25 23:42:55 +0200
committerMattias Andrée <m@maandree.se>2026-09-25 23:42:55 +0200
commit4e81cb177ab77904e7a21ce70b9a5506bf09ad6e (patch)
tree05634bdcd5b52c25bbeb986748d6b2c5acb728fb /librecrypt_concat_char_no_nul_.c
parentm (diff)
downloadlibrecrypt-4e81cb177ab77904e7a21ce70b9a5506bf09ad6e.tar.gz
librecrypt-4e81cb177ab77904e7a21ce70b9a5506bf09ad6e.tar.bz2
librecrypt-4e81cb177ab77904e7a21ce70b9a5506bf09ad6e.tar.xz
Add tests
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to '')
-rw-r--r--librecrypt_concat_char_no_nul_.c22
1 files changed, 21 insertions, 1 deletions
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;