summaryrefslogtreecommitdiff
path: root/librpc
diff options
context:
space:
mode:
authorAndreas Schneider <asn@samba.org>2019-12-16 16:45:38 +0100
committerAndrew Bartlett <abartlet@samba.org>2019-12-20 09:01:30 +0000
commitb28d1dca86d33efac9d03b35c5c9804e02ddfb9a (patch)
treec4bee4d217b1f26f72c3b531100403e2886b1abe /librpc
parentf11e207e01c52566c47e350ff240fe95392de0c3 (diff)
downloadsamba-b28d1dca86d33efac9d03b35c5c9804e02ddfb9a.tar.gz
librpc: Add test for ndr_string_length()
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Autobuild-User(master): Andrew Bartlett <abartlet@samba.org> Autobuild-Date(master): Fri Dec 20 09:01:30 UTC 2019 on sn-devel-184
Diffstat (limited to 'librpc')
-rw-r--r--librpc/tests/test_ndr_string.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/librpc/tests/test_ndr_string.c b/librpc/tests/test_ndr_string.c
index 6baa41bec31..b3b297c550c 100644
--- a/librpc/tests/test_ndr_string.c
+++ b/librpc/tests/test_ndr_string.c
@@ -127,12 +127,47 @@ static void test_pull_string_len_2_nul_term(void **state)
}
+static void test_ndr_string_n_length(void **state)
+{
+ char test_str1[5] = "Test";
+ char test_str2[5] = {0};
+ char test_str3[32] = "This is a test too";
+ uint8_t test_str_u16[64] = {
+ 0x5C, 0x00, 0x5C, 0x00, 0x4C, 0x00, 0x6F, 0x00,
+ 0x67, 0x00, 0x6F, 0x00, 0x6E, 0x00, 0x2D, 0x00,
+ 0x6D, 0x00, 0x75, 0x00, 0x63, 0x00, 0x5C, 0x00,
+ 0x6B, 0x00, 0x79, 0x00, 0x6F, 0x00, 0x63, 0x00,
+ 0x65, 0x00, 0x72, 0x00, 0x61, 0x00, 0x2D, 0x00,
+ 0x6D, 0x00, 0x75, 0x00, 0x63, 0x00, 0x2D, 0x00,
+ 0x6E, 0x00, 0x00, 0x00 };
+ size_t len;
+
+ len = ndr_string_n_length(test_str1, sizeof(test_str1), 1);
+ assert_int_equal(len, 5);
+
+ len = ndr_string_n_length(test_str1, sizeof(test_str1) - 1, 1);
+ assert_int_equal(len, 4);
+
+ len = ndr_string_n_length(test_str2, sizeof(test_str2), 1);
+ assert_int_equal(len, 1);
+
+ len = ndr_string_n_length(test_str3, sizeof(test_str3), 1);
+ assert_int_equal(len, 19);
+
+ len = ndr_string_n_length(test_str3, 0, 1);
+ assert_int_equal(len, 0);
+
+ len = ndr_string_n_length(test_str_u16, 32, 2);
+ assert_int_equal(len, 26);
+}
+
int main(int argc, const char **argv)
{
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_pull_string_zero_len_nul_term),
cmocka_unit_test(test_pull_string_len_1_nul_term),
- cmocka_unit_test(test_pull_string_len_2_nul_term)
+ cmocka_unit_test(test_pull_string_len_2_nul_term),
+ cmocka_unit_test(test_ndr_string_n_length)
};
cmocka_set_message_output(CM_OUTPUT_SUBUNIT);