Changeset 988 for vendor/current/lib/util/tests
- Timestamp:
- Nov 24, 2016, 1:14:11 PM (9 years ago)
- Location:
- vendor/current/lib/util/tests
- Files:
-
- 1 added
- 1 deleted
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/lib/util/tests/asn1_tests.c
r740 r988 5 5 6 6 Copyright (C) Kamen Mazdrashki <kamen.mazdrashki@postpath.com> 2009 7 Copyright (C) Volker Lendecke 2004 8 Copyright (C) Andrew Bartlett 2011 7 9 8 10 This program is free software; you can redistribute it and/or modify … … 22 24 #include "includes.h" 23 25 #include "torture/torture.h" 26 #include "torture/local/proto.h" 24 27 #include "../asn1.h" 25 28 … … 104 107 }; 105 108 109 static const struct { 110 DATA_BLOB blob; 111 int value; 112 } integer_tests[] = { 113 { 114 .blob = { discard_const_p(uint8_t, "\x02\x01\x00"), 3}, 115 .value = 0 116 }, 117 { 118 .blob = { discard_const_p(uint8_t, "\x02\x01\x7f"), 3}, 119 .value = 127 120 }, 121 { 122 .blob = { discard_const_p(uint8_t, "\x02\x02\x00\x80"), 4}, 123 .value = 128 124 }, 125 { 126 .blob = { discard_const_p(uint8_t, "\x02\x02\x01\x00"), 4}, 127 .value = 256 128 }, 129 { 130 .blob = { discard_const_p(uint8_t, "\x02\x01\x80"), 3}, 131 .value = -128 132 }, 133 { 134 .blob = { discard_const_p(uint8_t, "\x02\x02\xff\x7f"), 4}, 135 .value = -129 136 }, 137 { 138 .blob = { discard_const_p(uint8_t, "\x02\x01\xff"), 3}, 139 .value = -1 140 }, 141 { 142 .blob = { discard_const_p(uint8_t, "\x02\x02\xff\x01"), 4}, 143 .value = -255 144 }, 145 { 146 .blob = { discard_const_p(uint8_t, "\x02\x02\x00\xff"), 4}, 147 .value = 255 148 }, 149 { 150 .blob = { discard_const_p(uint8_t, "\x02\x04\x80\x00\x00\x00"), 6}, 151 .value = 0x80000000 152 }, 153 { 154 .blob = { discard_const_p(uint8_t, "\x02\x04\x7f\xff\xff\xff"), 6}, 155 .value = 0x7fffffff 156 } 157 }; 106 158 107 159 /* Testing ber_write_OID_String() function */ … … 261 313 } 262 314 315 /* 316 * Testing asn1_read_Integer and asn1_write_Integer functions, 317 * inspired by Love Hornquist Astrand 318 */ 319 320 static bool test_asn1_Integer(struct torture_context *tctx) 321 { 322 int i; 323 TALLOC_CTX *mem_ctx; 324 bool ret = false; 325 326 mem_ctx = talloc_new(tctx); 327 328 for (i = 0; i < ARRAY_SIZE(integer_tests); i++) { 329 ASN1_DATA *data; 330 DATA_BLOB blob; 331 int val; 332 333 data = asn1_init(mem_ctx); 334 if (!data) { 335 goto err; 336 } 337 338 if (!asn1_write_Integer(data, integer_tests[i].value)) goto err; 339 340 if (!asn1_blob(data, &blob)) { 341 goto err; 342 } 343 344 torture_assert_data_blob_equal(tctx, blob, integer_tests[i].blob, "asn1_write_Integer gave incorrect result"); 345 346 if (!asn1_load(data, blob)) goto err; 347 torture_assert(tctx, asn1_read_Integer(data, &val), "asn1_write_Integer output could not be read by asn1_read_Integer()"); 348 349 torture_assert_int_equal(tctx, val, integer_tests[i].value, 350 "readback of asn1_write_Integer output by asn1_read_Integer() failed"); 351 } 352 353 ret = true; 354 355 err: 356 357 talloc_free(mem_ctx); 358 return ret; 359 } 360 263 361 264 362 /* LOCAL-ASN1 test suite creation */ … … 279 377 test_ber_read_partial_OID_String); 280 378 379 torture_suite_add_simple_test(suite, "asn1_Integer", 380 test_asn1_Integer); 381 281 382 return suite; 282 383 } -
vendor/current/lib/util/tests/data_blob.c
r740 r988 22 22 #include "includes.h" 23 23 #include "torture/torture.h" 24 #include "torture/local/proto.h" 24 25 25 26 static bool test_string(struct torture_context *tctx) -
vendor/current/lib/util/tests/dlinklist.c
r740 r988 22 22 #include "includes.h" 23 23 #include "torture/torture.h" 24 #include "torture/local/proto.h" 24 25 #include "lib/util/dlinklist.h" 25 26 … … 43 44 for (i=0; i<5; i++) { 44 45 el = talloc(mem_ctx, struct listel); 45 DLIST_ADD_END(l1, el , NULL);46 DLIST_ADD_END(l1, el); 46 47 } 47 48 … … 57 58 el = DLIST_TAIL(l1); 58 59 DLIST_REMOVE(l1, el); 59 DLIST_ADD_END(l2, el , NULL);60 DLIST_ADD_END(l2, el); 60 61 } 61 62 … … 87 88 88 89 torture_comment(tctx, "check DLIST_DEMOTE\n"); 89 DLIST_DEMOTE(l1, el , NULL);90 DLIST_DEMOTE(l1, el); 90 91 torture_assert(tctx, el->next == NULL, "last in list"); 91 92 torture_assert(tctx, el2->prev == el, "backlink from head"); … … 100 101 101 102 torture_comment(tctx, "check DLIST_CONCATENATE\n"); 102 DLIST_CONCATENATE(l1, l2 , NULL);103 DLIST_CONCATENATE(l1, l2); 103 104 torture_comment(tctx, "count forward\n"); 104 105 for (i=0,el=l1; el; el=el->next) i++; -
vendor/current/lib/util/tests/file.c
r740 r988 23 23 #include "system/filesys.h" 24 24 #include "torture/torture.h" 25 #include "torture/local/proto.h" 25 26 26 27 #define TEST_FILENAME "utilfile.test" … … 66 67 char *line; 67 68 TALLOC_CTX *mem_ctx = tctx; 69 bool ret = false; 68 70 69 71 torture_assert(tctx, file_save(TEST_FILENAME, (const void *)TEST_DATA, … … 76 78 77 79 line = afdgets(fd, mem_ctx, 8); 78 torture_assert(tctx, strcmp(line, TEST_LINE1) == 0, "line 1 mismatch"); 80 torture_assert_goto(tctx, strcmp(line, TEST_LINE1) == 0, ret, done, 81 "line 1 mismatch"); 79 82 80 83 line = afdgets(fd, mem_ctx, 8); 81 torture_assert(tctx, strcmp(line, TEST_LINE2) == 0, "line 2 mismatch"); 84 torture_assert_goto(tctx, strcmp(line, TEST_LINE2) == 0, ret, done, 85 "line 2 mismatch"); 82 86 83 87 line = afdgets(fd, mem_ctx, 8); 84 torture_assert(tctx, strcmp(line, TEST_LINE3) == 0, "line 3 mismatch"); 85 88 torture_assert_goto(tctx, strcmp(line, TEST_LINE3) == 0, ret, done, 89 "line 3 mismatch"); 90 ret = true; 91 done: 86 92 close(fd); 87 93 88 94 unlink(TEST_FILENAME); 89 return true;95 return ret; 90 96 } 91 97 -
vendor/current/lib/util/tests/genrand.c
r740 r988 22 22 #include "includes.h" 23 23 #include "torture/torture.h" 24 25 static void dummy_reseed(void *userdata, int *d) 26 { 27 *d = 42; 28 } 29 30 static bool test_reseed_callback(struct torture_context *tctx) 31 { 32 set_rand_reseed_callback(dummy_reseed, NULL); 33 return true; 34 } 24 #include "torture/local/proto.h" 35 25 36 26 static bool test_check_password_quality(struct torture_context *tctx) … … 42 32 torture_assert(tctx, !check_password_quality("123"), "digits only"); 43 33 torture_assert(tctx, !check_password_quality("matthiéu"), "not enough high symbols"); 44 torture_assert(tctx, check_password_quality("abcdééà çÚ"), "valid"); 34 torture_assert(tctx, !check_password_quality("abcdééà çÚ"), "only lower case"); 35 torture_assert(tctx, !check_password_quality("abcdééà çÚ+"), "only lower and symbols"); 36 torture_assert(tctx, check_password_quality("abcdééà çÚ+à€¢"), "valid"); 37 torture_assert(tctx, check_password_quality("ç+à€¢"), "valid"); 45 38 torture_assert(tctx, check_password_quality("A2e"), "valid"); 46 39 torture_assert(tctx, check_password_quality("BA2eLi443"), "valid"); … … 61 54 { 62 55 struct torture_suite *suite = torture_suite_create(mem_ctx, "genrand"); 63 torture_suite_add_simple_test(suite, "reseed_callback", test_reseed_callback);64 56 torture_suite_add_simple_test(suite, "check_password_quality", test_check_password_quality); 65 57 torture_suite_add_simple_test(suite, "generate_random_str", test_generate_random_str); -
vendor/current/lib/util/tests/idtree.c
r740 r988 22 22 #include "includes.h" 23 23 #include "torture/torture.h" 24 #include "torture/local/proto.h" 24 25 25 26 static bool torture_local_idtree_simple(struct torture_context *tctx) -
vendor/current/lib/util/tests/str.c
r740 r988 22 22 #include "includes.h" 23 23 #include "torture/torture.h" 24 #include "torture/local/proto.h" 24 25 25 26 static bool test_string_sub_simple(struct torture_context *tctx) 26 27 { 27 28 char tmp[100]; 28 s afe_strcpy(tmp, "foobar", sizeof(tmp));29 strlcpy(tmp, "foobar", sizeof(tmp)); 29 30 string_sub(tmp, "foo", "bar", sizeof(tmp)); 30 31 torture_assert_str_equal(tctx, tmp, "barbar", "invalid sub"); … … 35 36 { 36 37 char tmp[100]; 37 s afe_strcpy(tmp, "fooblafoo", sizeof(tmp));38 strlcpy(tmp, "fooblafoo", sizeof(tmp)); 38 39 string_sub(tmp, "foo", "bar", sizeof(tmp)); 39 40 torture_assert_str_equal(tctx, tmp, "barblabar", "invalid sub"); … … 44 45 { 45 46 char tmp[100]; 46 s afe_strcpy(tmp, "foobla", sizeof(tmp));47 strlcpy(tmp, "foobla", sizeof(tmp)); 47 48 string_sub(tmp, "foo", "blie", sizeof(tmp)); 48 49 torture_assert_str_equal(tctx, tmp, "bliebla", "invalid sub"); … … 53 54 { 54 55 char tmp[100]; 55 s afe_strcpy(tmp, "foobla", sizeof(tmp));56 strlcpy(tmp, "foobla", sizeof(tmp)); 56 57 string_sub(tmp, "foo", "bl", sizeof(tmp)); 57 58 torture_assert_str_equal(tctx, tmp, "blbla", "invalid sub"); … … 62 63 { 63 64 char tmp[100]; 64 s afe_strcpy(tmp, "foobla", sizeof(tmp));65 strlcpy(tmp, "foobla", sizeof(tmp)); 65 66 string_sub(tmp, "foo", "%b;l", sizeof(tmp)); 66 67 torture_assert_str_equal(tctx, tmp, "_b_lbla", "invalid sub"); -
vendor/current/lib/util/tests/strlist.c
r740 r988 23 23 #include "includes.h" 24 24 #include "torture/torture.h" 25 #include "torture/local/proto.h" 25 26 #include "param/param.h" 26 27 … … 111 112 112 113 torture_assert(tctx, ret1, "str_list_make_shell() must not return NULL"); 113 tmp = str_list_join_shell(mem_ctx, (const char **) ret1, element->separators ? *element->separators : ' '); 114 tmp = str_list_join_shell(mem_ctx, discard_const_p(const char *, ret1), 115 element->separators ? *element->separators : ' '); 114 116 ret2 = str_list_make_shell(mem_ctx, tmp, element->separators); 115 117 … … 161 163 const char *empty_list[] = { NULL }; 162 164 const char **null_list = NULL; 163 164 result = (const char **)str_list_copy(tctx, list); 165 char **l; 166 167 l = str_list_copy(tctx, list); 168 result = discard_const_p(const char *, l); 165 169 torture_assert_int_equal(tctx, str_list_length(result), 2, "list length"); 166 170 torture_assert_str_equal(tctx, result[0], "foo", "element 0"); … … 168 172 torture_assert_str_equal(tctx, result[2], NULL, "element 2"); 169 173 170 result = (const char **)str_list_copy(tctx, empty_list); 174 l = str_list_copy(tctx, empty_list); 175 result = discard_const_p(const char *, l); 171 176 torture_assert_int_equal(tctx, str_list_length(result), 0, "list length"); 172 177 torture_assert_str_equal(tctx, result[0], NULL, "element 0"); 173 178 174 result = (const char **)str_list_copy(tctx, null_list); 179 l = str_list_copy(tctx, null_list); 180 result = discard_const_p(const char *, l); 175 181 torture_assert(tctx, result == NULL, "result NULL"); 176 182 … … 262 268 NULL 263 269 }; 264 result = (const char **) str_list_make(tctx, "element_0, element_1, element_2", NULL); 270 char **l; 271 272 l = str_list_make(tctx, "element_0, element_1, element_2", NULL); 273 result = discard_const_p(const char *, l); 265 274 torture_assert(tctx, result, "str_list_make() must not return NULL"); 266 result2 = str_list_add( (const char **)result, "element_3");275 result2 = str_list_add(result, "element_3"); 267 276 torture_assert(tctx, result2, "str_list_add() must not return NULL"); 268 277 torture_assert(tctx, str_list_equal(result2, list), … … 282 291 NULL 283 292 }; 284 result = (const char **) str_list_make(tctx, "element_0, element_1, element_2", NULL); 293 char **l; 294 295 l = str_list_make(tctx, "element_0, element_1, element_2", NULL); 296 result = discard_const_p(const char *, l); 285 297 torture_assert(tctx, result, "str_list_make() must not return NULL"); 286 298 result2 = str_list_add_const(result, "element_3"); … … 301 313 NULL 302 314 }; 303 result = (const char **) str_list_make(tctx, "element_0, element_1, element_2, element_3", NULL); 315 char **l; 316 317 l = str_list_make(tctx, "element_0, element_1, element_2, element_3", NULL); 318 result = discard_const_p(const char *, l); 304 319 torture_assert(tctx, result, "str_list_make() must not return NULL"); 305 320 str_list_remove(result, "element_2"); … … 358 373 NULL 359 374 }; 360 result = (const char **) str_list_copy(tctx, list_dup); 375 char **l; 376 377 l = str_list_copy(tctx, list_dup); 378 result = discard_const_p(const char *, l); 361 379 /* We must copy the list, as str_list_unique does a talloc_realloc() on it's parameter */ 362 380 result = str_list_unique(result); … … 374 392 int count, num_dups; 375 393 const char **result; 376 const char **list = (const char **)str_list_make_empty(tctx); 377 const char **list_dup = (const char **)str_list_make_empty(tctx); 394 char **l1 = str_list_make_empty(tctx); 395 char **l2 = str_list_make_empty(tctx); 396 const char **list = discard_const_p(const char *, l1); 397 const char **list_dup = discard_const_p(const char *, l2); 398 char **l; 378 399 379 400 count = lpcfg_parm_int(tctx->lp_ctx, NULL, "list_unique", "count", 9); … … 389 410 } 390 411 391 result = (const char **)str_list_copy(tctx, list_dup); 412 l = str_list_copy(tctx, list_dup); 413 result = discard_const_p(const char *, l); 392 414 /* We must copy the list, as str_list_unique does a talloc_realloc() on it's parameter */ 393 415 result = str_list_unique(result); … … 424 446 NULL 425 447 }; 426 result = (const char **) str_list_copy(tctx, list); 448 char **l; 449 l = str_list_copy(tctx, list); 450 result = discard_const_p(const char *, l); 427 451 torture_assert(tctx, result, "str_list_copy() must not return NULL"); 428 452 result = str_list_append(result, list2); … … 458 482 NULL 459 483 }; 460 result = (const char **) str_list_copy(tctx, list); 484 char **l; 485 l = str_list_copy(tctx, list); 486 result = discard_const_p(const char *, l); 461 487 torture_assert(tctx, result, "str_list_copy() must not return NULL"); 462 488 result = str_list_append_const(result, list2); -
vendor/current/lib/util/tests/time.c
r740 r988 22 22 #include "includes.h" 23 23 #include "torture/torture.h" 24 #include "torture/local/proto.h" 24 25 25 26 static bool test_null_time(struct torture_context *tctx) … … 82 83 } 83 84 84 static bool test_get_time_zone(struct torture_context *tctx)85 {86 time_t t = time(NULL);87 int old_extra_time_offset = extra_time_offset;88 int old_offset, new_offset;89 /* test that extra_time_offset works */90 91 old_offset = get_time_zone(t);92 extra_time_offset = 42;93 new_offset = get_time_zone(t);94 extra_time_offset = old_extra_time_offset;95 torture_assert_int_equal(tctx, old_offset+60*42, new_offset,96 "time offset not used");97 return true;98 }99 100 101 85 struct torture_suite *torture_local_util_time(TALLOC_CTX *mem_ctx) 102 86 { … … 104 88 105 89 torture_suite_add_simple_test(suite, "null_time", test_null_time); 106 torture_suite_add_simple_test(suite, "get_time_zone", test_get_time_zone);107 90 torture_suite_add_simple_test(suite, "null_nttime", test_null_nttime); 108 91 torture_suite_add_simple_test(suite, "http_timestring",
Note:
See TracChangeset
for help on using the changeset viewer.