diff options
author | Damien Miller <djm@cvs.openbsd.org> | 2016-05-03 13:48:34 +0000 |
---|---|---|
committer | Damien Miller <djm@cvs.openbsd.org> | 2016-05-03 13:48:34 +0000 |
commit | 5909a3aa652f7276383cd69f3123db33e63373bf (patch) | |
tree | 6ba8c8ef2ce0ca705de8b94408c3417910ab4fd7 /regress/usr.bin/ssh/unittests | |
parent | 03576c73f47c3b6aa6efcc8bf9da306510b81a11 (diff) |
unit tests for sshbuf_dup_string()
Diffstat (limited to 'regress/usr.bin/ssh/unittests')
-rw-r--r-- | regress/usr.bin/ssh/unittests/sshbuf/test_sshbuf_misc.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/regress/usr.bin/ssh/unittests/sshbuf/test_sshbuf_misc.c b/regress/usr.bin/ssh/unittests/sshbuf/test_sshbuf_misc.c index a5b1ab2c95e..d61c760444c 100644 --- a/regress/usr.bin/ssh/unittests/sshbuf/test_sshbuf_misc.c +++ b/regress/usr.bin/ssh/unittests/sshbuf/test_sshbuf_misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: test_sshbuf_misc.c,v 1.1 2014/04/30 05:32:00 djm Exp $ */ +/* $OpenBSD: test_sshbuf_misc.c,v 1.2 2016/05/03 13:48:33 djm Exp $ */ /* * Regress test for sshbuf.h buffer API * @@ -130,5 +130,34 @@ sshbuf_misc_tests(void) ASSERT_U32_EQ(PEEK_U32(sshbuf_ptr(p1)), 0xd00fd00f); sshbuf_free(p1); TEST_DONE(); + + TEST_START("sshbuf_dup_string"); + p1 = sshbuf_new(); + ASSERT_PTR_NE(p1, NULL); + /* Check empty buffer */ + p = sshbuf_dup_string(p1); + ASSERT_PTR_NE(p, NULL); + ASSERT_SIZE_T_EQ(strlen(p), 0); + free(p); + /* Check buffer with string */ + ASSERT_INT_EQ(sshbuf_put(p1, "quad1", strlen("quad1")), 0); + p = sshbuf_dup_string(p1); + ASSERT_PTR_NE(p, NULL); + ASSERT_SIZE_T_EQ(strlen(p), strlen("quad1")); + ASSERT_STRING_EQ(p, "quad1"); + free(p); + /* Check buffer with terminating nul */ + ASSERT_INT_EQ(sshbuf_put(p1, "\0", 1), 0); + p = sshbuf_dup_string(p1); + ASSERT_PTR_NE(p, NULL); + ASSERT_SIZE_T_EQ(strlen(p), strlen("quad1")); + ASSERT_STRING_EQ(p, "quad1"); + free(p); + /* Check buffer with data after nul (expect failure) */ + ASSERT_INT_EQ(sshbuf_put(p1, "quad2", strlen("quad2")), 0); + p = sshbuf_dup_string(p1); + ASSERT_PTR_EQ(p, NULL); + sshbuf_free(p1); + TEST_DONE(); } |