diff options
-rw-r--r-- | regress/unittests/sshbuf/test_sshbuf_misc.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/regress/unittests/sshbuf/test_sshbuf_misc.c b/regress/unittests/sshbuf/test_sshbuf_misc.c index f155491a0..762a6c31c 100644 --- a/regress/unittests/sshbuf/test_sshbuf_misc.c +++ b/regress/unittests/sshbuf/test_sshbuf_misc.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: test_sshbuf_misc.c,v 1.1 2014/04/30 05:32:00 djm Exp $ */ | 1 | /* $OpenBSD: test_sshbuf_misc.c,v 1.2 2016/05/03 13:48:33 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Regress test for sshbuf.h buffer API | 3 | * Regress test for sshbuf.h buffer API |
4 | * | 4 | * |
@@ -134,5 +134,34 @@ sshbuf_misc_tests(void) | |||
134 | ASSERT_U32_EQ(PEEK_U32(sshbuf_ptr(p1)), 0xd00fd00f); | 134 | ASSERT_U32_EQ(PEEK_U32(sshbuf_ptr(p1)), 0xd00fd00f); |
135 | sshbuf_free(p1); | 135 | sshbuf_free(p1); |
136 | TEST_DONE(); | 136 | TEST_DONE(); |
137 | |||
138 | TEST_START("sshbuf_dup_string"); | ||
139 | p1 = sshbuf_new(); | ||
140 | ASSERT_PTR_NE(p1, NULL); | ||
141 | /* Check empty buffer */ | ||
142 | p = sshbuf_dup_string(p1); | ||
143 | ASSERT_PTR_NE(p, NULL); | ||
144 | ASSERT_SIZE_T_EQ(strlen(p), 0); | ||
145 | free(p); | ||
146 | /* Check buffer with string */ | ||
147 | ASSERT_INT_EQ(sshbuf_put(p1, "quad1", strlen("quad1")), 0); | ||
148 | p = sshbuf_dup_string(p1); | ||
149 | ASSERT_PTR_NE(p, NULL); | ||
150 | ASSERT_SIZE_T_EQ(strlen(p), strlen("quad1")); | ||
151 | ASSERT_STRING_EQ(p, "quad1"); | ||
152 | free(p); | ||
153 | /* Check buffer with terminating nul */ | ||
154 | ASSERT_INT_EQ(sshbuf_put(p1, "\0", 1), 0); | ||
155 | p = sshbuf_dup_string(p1); | ||
156 | ASSERT_PTR_NE(p, NULL); | ||
157 | ASSERT_SIZE_T_EQ(strlen(p), strlen("quad1")); | ||
158 | ASSERT_STRING_EQ(p, "quad1"); | ||
159 | free(p); | ||
160 | /* Check buffer with data after nul (expect failure) */ | ||
161 | ASSERT_INT_EQ(sshbuf_put(p1, "quad2", strlen("quad2")), 0); | ||
162 | p = sshbuf_dup_string(p1); | ||
163 | ASSERT_PTR_EQ(p, NULL); | ||
164 | sshbuf_free(p1); | ||
165 | TEST_DONE(); | ||
137 | } | 166 | } |
138 | 167 | ||