diff options
Diffstat (limited to 'src/libstrongswan/tests/suites')
-rw-r--r-- | src/libstrongswan/tests/suites/test_array.c | 2 | ||||
-rw-r--r-- | src/libstrongswan/tests/suites/test_asn1.c | 6 | ||||
-rw-r--r-- | src/libstrongswan/tests/suites/test_bio_reader.c | 20 | ||||
-rw-r--r-- | src/libstrongswan/tests/suites/test_chunk.c | 38 | ||||
-rw-r--r-- | src/libstrongswan/tests/suites/test_host.c | 6 | ||||
-rw-r--r-- | src/libstrongswan/tests/suites/test_iv_gen.c | 32 | ||||
-rw-r--r-- | src/libstrongswan/tests/suites/test_ntru.c | 8 | ||||
-rw-r--r-- | src/libstrongswan/tests/suites/test_printf.c | 12 | ||||
-rw-r--r-- | src/libstrongswan/tests/suites/test_traffic_selector.c | 40 | ||||
-rw-r--r-- | src/libstrongswan/tests/suites/test_utils.c | 96 |
10 files changed, 171 insertions, 89 deletions
diff --git a/src/libstrongswan/tests/suites/test_array.c b/src/libstrongswan/tests/suites/test_array.c index eda72e10a..eed8fba56 100644 --- a/src/libstrongswan/tests/suites/test_array.c +++ b/src/libstrongswan/tests/suites/test_array.c @@ -512,7 +512,7 @@ END_TEST START_TEST(test_insert_create_value) { array_t *array = NULL; - u_int16_t v; + uint16_t v; v = 1; array_insert_create_value(&array, sizeof(v), ARRAY_TAIL, &v); diff --git a/src/libstrongswan/tests/suites/test_asn1.c b/src/libstrongswan/tests/suites/test_asn1.c index ac7c5519e..fa02df9ca 100644 --- a/src/libstrongswan/tests/suites/test_asn1.c +++ b/src/libstrongswan/tests/suites/test_asn1.c @@ -462,7 +462,7 @@ START_TEST(test_asn1_to_time) { typedef struct { time_t time; - u_int8_t type; + uint8_t type; char *string; } testdata_t; @@ -525,7 +525,7 @@ START_TEST(test_asn1_from_time) { typedef struct { time_t time; - u_int8_t type; + uint8_t type; chunk_t chunk; } testdata_t; @@ -759,7 +759,7 @@ END_TEST START_TEST(test_asn1_parse_integer_uint64) { typedef struct { - u_int64_t n; + uint64_t n; chunk_t chunk; } testdata_t; diff --git a/src/libstrongswan/tests/suites/test_bio_reader.c b/src/libstrongswan/tests/suites/test_bio_reader.c index 6a9743d62..d3b4b4358 100644 --- a/src/libstrongswan/tests/suites/test_bio_reader.c +++ b/src/libstrongswan/tests/suites/test_bio_reader.c @@ -65,7 +65,7 @@ START_TEST(test_read_uint8) { chunk_t data = chunk_from_chars(0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07); - u_int8_t val; + uint8_t val; assert_integer_read(data, 8, val); assert_basic_read(8, val); @@ -76,7 +76,7 @@ END_TEST START_TEST(test_read_uint16) { chunk_t data = chunk_from_chars(0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03); - u_int16_t val; + uint16_t val; assert_integer_read(data, 16, val); assert_basic_read(16, val); @@ -87,7 +87,7 @@ END_TEST START_TEST(test_read_uint24) { chunk_t data = chunk_from_chars(0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x03); - u_int32_t val; + uint32_t val; assert_integer_read(data, 24, val); assert_basic_read(24, val); @@ -99,7 +99,7 @@ START_TEST(test_read_uint32) { chunk_t data = chunk_from_chars(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03); - u_int32_t val; + uint32_t val; assert_integer_read(data, 32, val); assert_basic_read(32, val); @@ -113,7 +113,7 @@ START_TEST(test_read_uint64) 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03); - u_int64_t val; + uint64_t val; assert_integer_read(data, 64, val); assert_basic_read(64, val); @@ -170,7 +170,7 @@ END_TEST START_TEST(test_read_uint8_end) { chunk_t data = chunk_from_chars(0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00); - u_int8_t val; + uint8_t val; assert_integer_read_end(data, 8, val); assert_basic_read_end(8, val); @@ -181,7 +181,7 @@ END_TEST START_TEST(test_read_uint16_end) { chunk_t data = chunk_from_chars(0x00, 0x03, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00); - u_int16_t val; + uint16_t val; assert_integer_read_end(data, 16, val); assert_basic_read_end(16, val); @@ -192,7 +192,7 @@ END_TEST START_TEST(test_read_uint24_end) { chunk_t data = chunk_from_chars(0x00, 0x00, 0x03, 0x00, 0x00, 0x02, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00); - u_int32_t val; + uint32_t val; assert_integer_read_end(data, 24, val); assert_basic_read_end(24, val); @@ -204,7 +204,7 @@ START_TEST(test_read_uint32_end) { chunk_t data = chunk_from_chars(0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00); - u_int32_t val; + uint32_t val; assert_integer_read_end(data, 32, val); assert_basic_read_end(32, val); @@ -218,7 +218,7 @@ START_TEST(test_read_uint64_end) 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); - u_int64_t val; + uint64_t val; assert_integer_read_end(data, 64, val); assert_basic_read_end(64, val); diff --git a/src/libstrongswan/tests/suites/test_chunk.c b/src/libstrongswan/tests/suites/test_chunk.c index 6272ca795..b82b1436f 100644 --- a/src/libstrongswan/tests/suites/test_chunk.c +++ b/src/libstrongswan/tests/suites/test_chunk.c @@ -316,11 +316,11 @@ START_TEST(test_chunk_skip) foobar = chunk_from_str("foobar"); a = foobar; a = chunk_skip(a, 0); - ck_assert(chunk_equals(a, foobar)); + ck_assert_chunk_eq(a, foobar); a = chunk_skip(a, 1); - ck_assert(chunk_equals(a, chunk_from_str("oobar"))); + ck_assert_chunk_eq(a, chunk_from_str("oobar")); a = chunk_skip(a, 2); - ck_assert(chunk_equals(a, chunk_from_str("bar"))); + ck_assert_chunk_eq(a, chunk_from_str("bar")); a = chunk_skip(a, 3); assert_chunk_empty(a); @@ -338,20 +338,24 @@ START_TEST(test_chunk_skip_zero) { chunk_t foobar, a; - a = chunk_empty; - a = chunk_skip_zero(a); + a = chunk_skip_zero(chunk_empty); assert_chunk_empty(a); foobar = chunk_from_str("foobar"); - a = foobar; - a = chunk_skip_zero(a); - ck_assert(chunk_equals(a, foobar)); + a = chunk_skip_zero(foobar); + ck_assert_chunk_eq(a, foobar); - a = chunk_from_chars(0x00, 0xaa, 0xbb, 0xcc); - a = chunk_skip_zero(a); - ck_assert(chunk_equals(a, chunk_from_chars(0xaa, 0xbb, 0xcc))); + foobar = chunk_from_chars(0x00); + a = chunk_skip_zero(foobar); + ck_assert_chunk_eq(a, foobar); + + a = chunk_skip_zero(chunk_from_chars(0x00, 0xaa, 0xbb, 0xcc)); + ck_assert_chunk_eq(a, chunk_from_chars(0xaa, 0xbb, 0xcc)); a = chunk_skip_zero(a); - ck_assert(chunk_equals(a, chunk_from_chars(0xaa, 0xbb, 0xcc))); + ck_assert_chunk_eq(a, chunk_from_chars(0xaa, 0xbb, 0xcc)); + + a = chunk_skip_zero(chunk_from_chars(0x00, 0x00, 0xaa, 0xbb, 0xcc)); + ck_assert_chunk_eq(a, chunk_from_chars(0xaa, 0xbb, 0xcc)); } END_TEST @@ -736,7 +740,7 @@ START_TEST(test_chunk_mac) { chunk_t in; u_char key[16]; - u_int64_t out; + uint64_t out; int i, count; count = countof(sip_vectors); @@ -765,7 +769,7 @@ END_TEST START_TEST(test_chunk_hash) { chunk_t chunk; - u_int32_t hash_a, hash_b, hash_c; + uint32_t hash_a, hash_b, hash_c; chunk = chunk_from_str("asdf"); @@ -787,7 +791,7 @@ END_TEST START_TEST(test_chunk_hash_static) { chunk_t in; - u_int32_t out, hash_a, hash_b, hash_inc = 0x7b891a95; + uint32_t out, hash_a, hash_b, hash_inc = 0x7b891a95; int i, count; count = countof(sip_vectors); @@ -813,7 +817,7 @@ END_TEST * test for chunk_internet_checksum[_inc]() */ -static inline u_int16_t compensate_alignment(u_int16_t val) +static inline uint16_t compensate_alignment(uint16_t val) { return ((val & 0xff) << 8) | (val >> 8); } @@ -821,7 +825,7 @@ static inline u_int16_t compensate_alignment(u_int16_t val) START_TEST(test_chunk_internet_checksum) { chunk_t chunk; - u_int16_t sum; + uint16_t sum; chunk = chunk_from_chars(0x45,0x00,0x00,0x30,0x44,0x22,0x40,0x00,0x80,0x06, 0x00,0x00,0x8c,0x7c,0x19,0xac,0xae,0x24,0x1e,0x2b); diff --git a/src/libstrongswan/tests/suites/test_host.c b/src/libstrongswan/tests/suites/test_host.c index 5cb8013ff..5d054577a 100644 --- a/src/libstrongswan/tests/suites/test_host.c +++ b/src/libstrongswan/tests/suites/test_host.c @@ -46,7 +46,7 @@ static void verify_netmask(chunk_t addr, int mask) * host_create_any */ -static void verify_any(host_t *host, int family, u_int16_t port) +static void verify_any(host_t *host, int family, uint16_t port) { verify_netmask(host->get_address(host), 0); ck_assert(host->is_anyaddr(host)); @@ -88,7 +88,7 @@ END_TEST * host_create_from_string */ -static void verify_address(host_t *host, chunk_t addr, int family, u_int16_t port) +static void verify_address(host_t *host, chunk_t addr, int family, uint16_t port) { ck_assert(chunk_equals(host->get_address(host), addr)); ck_assert(!host->is_anyaddr(host)); @@ -656,7 +656,7 @@ END_TEST static struct { char *addr; - u_int16_t port; + uint16_t port; /* results for %H, %+H, %#H (falls back to [0]) */ char *result[3]; } printf_data[] = { diff --git a/src/libstrongswan/tests/suites/test_iv_gen.c b/src/libstrongswan/tests/suites/test_iv_gen.c index 4e45c8538..8b0a14b79 100644 --- a/src/libstrongswan/tests/suites/test_iv_gen.c +++ b/src/libstrongswan/tests/suites/test_iv_gen.c @@ -21,17 +21,17 @@ START_TEST(test_iv_gen_seq) { iv_gen_t *iv_gen; - u_int64_t iv0, iv1_1, iv1_2; + uint64_t iv0, iv1_1, iv1_2; iv_gen = iv_gen_seq_create(); - ck_assert(iv_gen->get_iv(iv_gen, 0, 8, (u_int8_t*)&iv0)); - ck_assert(iv_gen->get_iv(iv_gen, 1, 8, (u_int8_t*)&iv1_1)); + ck_assert(iv_gen->get_iv(iv_gen, 0, 8, (uint8_t*)&iv0)); + ck_assert(iv_gen->get_iv(iv_gen, 1, 8, (uint8_t*)&iv1_1)); ck_assert(iv0 != iv1_1); /* every sequence number may be used twice, but results in a different IV */ - ck_assert(iv_gen->get_iv(iv_gen, 1, 8, (u_int8_t*)&iv1_2)); + ck_assert(iv_gen->get_iv(iv_gen, 1, 8, (uint8_t*)&iv1_2)); ck_assert(iv0 != iv1_2); ck_assert(iv1_1 != iv1_2); - ck_assert(!iv_gen->get_iv(iv_gen, 1, 8, (u_int8_t*)&iv1_2)); + ck_assert(!iv_gen->get_iv(iv_gen, 1, 8, (uint8_t*)&iv1_2)); iv_gen->destroy(iv_gen); } END_TEST @@ -39,19 +39,19 @@ END_TEST START_TEST(test_iv_gen_seq_len) { iv_gen_t *iv_gen; - u_int64_t iv; - u_int8_t buf[9]; + uint64_t iv; + uint8_t buf[9]; iv_gen = iv_gen_seq_create(); - ck_assert(!iv_gen->get_iv(iv_gen, 0, 0, (u_int8_t*)&iv)); - ck_assert(!iv_gen->get_iv(iv_gen, 0, 1, (u_int8_t*)&iv)); - ck_assert(!iv_gen->get_iv(iv_gen, 0, 2, (u_int8_t*)&iv)); - ck_assert(!iv_gen->get_iv(iv_gen, 0, 3, (u_int8_t*)&iv)); - ck_assert(!iv_gen->get_iv(iv_gen, 0, 4, (u_int8_t*)&iv)); - ck_assert(!iv_gen->get_iv(iv_gen, 0, 5, (u_int8_t*)&iv)); - ck_assert(!iv_gen->get_iv(iv_gen, 0, 6, (u_int8_t*)&iv)); - ck_assert(!iv_gen->get_iv(iv_gen, 0, 7, (u_int8_t*)&iv)); - ck_assert(iv_gen->get_iv(iv_gen, 0, 8, (u_int8_t*)&iv)); + ck_assert(!iv_gen->get_iv(iv_gen, 0, 0, (uint8_t*)&iv)); + ck_assert(!iv_gen->get_iv(iv_gen, 0, 1, (uint8_t*)&iv)); + ck_assert(!iv_gen->get_iv(iv_gen, 0, 2, (uint8_t*)&iv)); + ck_assert(!iv_gen->get_iv(iv_gen, 0, 3, (uint8_t*)&iv)); + ck_assert(!iv_gen->get_iv(iv_gen, 0, 4, (uint8_t*)&iv)); + ck_assert(!iv_gen->get_iv(iv_gen, 0, 5, (uint8_t*)&iv)); + ck_assert(!iv_gen->get_iv(iv_gen, 0, 6, (uint8_t*)&iv)); + ck_assert(!iv_gen->get_iv(iv_gen, 0, 7, (uint8_t*)&iv)); + ck_assert(iv_gen->get_iv(iv_gen, 0, 8, (uint8_t*)&iv)); ck_assert(iv_gen->get_iv(iv_gen, 0, 9, buf)); iv_gen->destroy(iv_gen); } diff --git a/src/libstrongswan/tests/suites/test_ntru.c b/src/libstrongswan/tests/suites/test_ntru.c index d209fa2bc..0a6d24d04 100644 --- a/src/libstrongswan/tests/suites/test_ntru.c +++ b/src/libstrongswan/tests/suites/test_ntru.c @@ -25,7 +25,7 @@ #include <plugins/ntru/ntru_private_key.h> IMPORT_FUNCTION_FOR_TESTS(ntru, ntru_drbg_create, ntru_drbg_t*, - u_int32_t strength, chunk_t pers_str, rng_t *entropy) + uint32_t strength, chunk_t pers_str, rng_t *entropy) IMPORT_FUNCTION_FOR_TESTS(ntru, ntru_trits_create, ntru_trits_t*, size_t len, hash_algorithm_t alg, chunk_t seed) @@ -36,7 +36,7 @@ IMPORT_FUNCTION_FOR_TESTS(ntru, ntru_poly_create_from_seed, ntru_poly_t*, uint32_t indices_len_m, bool is_product_form) IMPORT_FUNCTION_FOR_TESTS(ntru, ntru_poly_create_from_data, ntru_poly_t*, - u_int16_t *data, uint16_t N, uint16_t q, + uint16_t *data, uint16_t N, uint16_t q, uint32_t indices_len_p, uint32_t indices_len_m, bool is_product_form) @@ -73,8 +73,8 @@ char *parameter_sets[] = { }; typedef struct { - u_int32_t requested; - u_int32_t standard; + uint32_t requested; + uint32_t standard; }strength_t; strength_t strengths[] = { diff --git a/src/libstrongswan/tests/suites/test_printf.c b/src/libstrongswan/tests/suites/test_printf.c index 9e40d1fc0..377f2a767 100644 --- a/src/libstrongswan/tests/suites/test_printf.c +++ b/src/libstrongswan/tests/suites/test_printf.c @@ -75,7 +75,7 @@ END_TEST START_TEST(test_printf_unsigned) { - verify("1 23 456", "%u %lu %llu", 1, (u_long)23, (u_int64_t)456); + verify("1 23 456", "%u %lu %llu", 1, (u_long)23, (uint64_t)456); verify("65535 255", "%hu %hhu", 0x1ffff, 0x1ff); verify("123456789", "%zu", (size_t)123456789); verify(" 12", "%5u", 12); @@ -99,7 +99,7 @@ END_TEST START_TEST(test_printf_hex) { - verify("1 23 456", "%x %lx %llx", 1, (u_long)0x23, (u_int64_t)0x456); + verify("1 23 456", "%x %lx %llx", 1, (u_long)0x23, (uint64_t)0x456); verify("12abcdef 12ABCDEF", "%x %X", 0x12ABCDEF, 0x12ABCDEF); verify("ffff ff", "%hx %hhx", 0x1ffff, 0x1ff); verify("23456789", "%zx", (size_t)0x23456789); @@ -170,10 +170,10 @@ END_TEST START_TEST(test_printf_pri) { - verify("255", "%" PRIu8, (u_int8_t)0xFF); - verify("65535", "%" PRIu16, (u_int16_t)0xFFFF); - verify("4294967295", "%" PRIu32, (u_int32_t)0x1FFFFFFFFll); - verify("18446744073709551615", "%" PRIu64, (u_int64_t)0xFFFFFFFFFFFFFFFFll); + verify("255", "%" PRIu8, (uint8_t)0xFF); + verify("65535", "%" PRIu16, (uint16_t)0xFFFF); + verify("4294967295", "%" PRIu32, (uint32_t)0x1FFFFFFFFll); + verify("18446744073709551615", "%" PRIu64, (uint64_t)0xFFFFFFFFFFFFFFFFll); verify("-1", "%" PRId8, (int8_t)-1); verify("-1", "%" PRId16, (int16_t)-1); diff --git a/src/libstrongswan/tests/suites/test_traffic_selector.c b/src/libstrongswan/tests/suites/test_traffic_selector.c index 5c0fb754d..0d5d877ac 100644 --- a/src/libstrongswan/tests/suites/test_traffic_selector.c +++ b/src/libstrongswan/tests/suites/test_traffic_selector.c @@ -198,7 +198,7 @@ struct { char *from; char *to; char *net; - u_int8_t mask; + uint8_t mask; bool exact; } to_subnet_tests[] = { { TS_IPV4_ADDR_RANGE, "10.0.0.1", "10.0.0.1", "10.0.0.1", 32, TRUE }, @@ -218,7 +218,7 @@ START_TEST(test_to_subnet) { traffic_selector_t *ts; host_t *net, *exp_net; - u_int8_t mask; + uint8_t mask; ts = traffic_selector_create_from_string(0, to_subnet_tests[_i].type, to_subnet_tests[_i].from, 0, to_subnet_tests[_i].to, 0); @@ -234,9 +234,9 @@ END_TEST struct { char *cidr; - u_int16_t from_port; - u_int16_t to_port; - u_int16_t port; + uint16_t from_port; + uint16_t to_port; + uint16_t port; } to_subnet_port_tests[] = { { "10.0.0.0/8", 0, 0, 0 }, { "10.0.0.1/32", 80, 80, 80 }, @@ -252,7 +252,7 @@ START_TEST(test_to_subnet_port) { traffic_selector_t *ts; host_t *net, *exp_net; - u_int8_t mask; + uint8_t mask; int exp_mask; ts = traffic_selector_create_from_cidr(to_subnet_port_tests[_i].cidr, 0, @@ -431,9 +431,9 @@ struct { bool contained; struct { char *net; - u_int8_t proto; - u_int16_t from_port; - u_int16_t to_port; + uint8_t proto; + uint16_t from_port; + uint16_t to_port; } a, b; } is_contained_in_tests[] = { { TRUE, { "10.0.0.0/16", 0, 0, 65535 }, { "10.0.0.0/16", 0, 0, 65535 }, }, @@ -555,9 +555,9 @@ struct { int res; struct { char *net; - u_int8_t proto; - u_int16_t from_port; - u_int16_t to_port; + uint8_t proto; + uint16_t from_port; + uint16_t to_port; } a, b; } cmp_tests[] = { { 0, { "10.0.0.0/8", 0, 0, 65535 }, { "10.0.0.0/8", 0, 0, 65535 }, }, @@ -706,13 +706,13 @@ START_TEST(test_hash) END_TEST struct { - u_int8_t proto; - u_int16_t from_port; - u_int16_t to_port; - u_int8_t from_type; - u_int8_t from_code; - u_int8_t to_type; - u_int8_t to_code; + uint8_t proto; + uint16_t from_port; + uint16_t to_port; + uint8_t from_type; + uint8_t from_code; + uint8_t to_type; + uint8_t to_code; char *str; char *str_alt; } icmp_tests[] = { @@ -731,7 +731,7 @@ struct { START_TEST(test_icmp) { traffic_selector_t *ts; - u_int16_t from, to; + uint16_t from, to; ts = traffic_selector_create_dynamic(icmp_tests[_i].proto, icmp_tests[_i].from_port, icmp_tests[_i].to_port); diff --git a/src/libstrongswan/tests/suites/test_utils.c b/src/libstrongswan/tests/suites/test_utils.c index 104b0b2c0..1eb3c8bc3 100644 --- a/src/libstrongswan/tests/suites/test_utils.c +++ b/src/libstrongswan/tests/suites/test_utils.c @@ -121,9 +121,9 @@ END_TEST START_TEST(test_htoun) { chunk_t net64, expected; - u_int16_t host16 = 513; - u_int32_t net16 = 0, host32 = 67305985; - u_int64_t net32 = 0, host64 = 578437695752307201ULL; + uint16_t host16 = 513; + uint32_t net16 = 0, host32 = 67305985; + uint64_t net32 = 0, host64 = 578437695752307201ULL; net64 = chunk_alloca(16); memset(net64.ptr, 0, net64.len); @@ -133,14 +133,14 @@ START_TEST(test_htoun) ck_assert(chunk_equals(expected, chunk_from_thing(net16))); expected = chunk_from_chars(0x00, 0x00, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00); - htoun32((u_int16_t*)&net32 + 1, host32); + htoun32((uint16_t*)&net32 + 1, host32); ck_assert(chunk_equals(expected, chunk_from_thing(net32))); expected = chunk_from_chars(0x00, 0x00, 0x00, 0x00, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00); - htoun64((u_int32_t*)net64.ptr + 1, host64); + htoun64((uint32_t*)net64.ptr + 1, host64); ck_assert(chunk_equals(expected, net64)); } END_TEST @@ -148,9 +148,9 @@ END_TEST START_TEST(test_untoh) { chunk_t net; - u_int16_t host16; - u_int32_t host32; - u_int64_t host64; + uint16_t host16; + uint32_t host32; + uint64_t host64; net = chunk_from_chars(0x00, 0x02, 0x01, 0x00); host16 = untoh16(net.ptr + 1); @@ -197,6 +197,82 @@ START_TEST(test_round) END_TEST /******************************************************************************* + * streq + */ + +static struct { + char *a; + char *b; + bool eq; + bool case_eq; +} streq_data[] = { + {NULL, NULL, TRUE, TRUE}, + {NULL, "", FALSE, FALSE}, + {"", NULL, FALSE, FALSE}, + {"abc", "", FALSE, FALSE}, + {"abc", "abc", TRUE, TRUE}, + {"abc", "ABC", FALSE, TRUE}, +}; + +START_TEST(test_streq) +{ + bool eq; + + ck_assert(streq(streq_data[_i].a, streq_data[_i].a)); + ck_assert(streq(streq_data[_i].b, streq_data[_i].b)); + eq = streq(streq_data[_i].a, streq_data[_i].b); + ck_assert(eq == streq_data[_i].eq); + + ck_assert(strcaseeq(streq_data[_i].a, streq_data[_i].a)); + ck_assert(strcaseeq(streq_data[_i].b, streq_data[_i].b)); + eq = strcaseeq(streq_data[_i].a, streq_data[_i].b); + ck_assert(eq == streq_data[_i].case_eq); +} +END_TEST + +/******************************************************************************* + * strneq + */ + +static struct { + char *a; + char *b; + size_t n; + bool eq; + bool case_eq; +} strneq_data[] = { + {NULL, NULL, 0, TRUE, TRUE}, + {NULL, NULL, 10, TRUE, TRUE}, + {NULL, "", 0, FALSE, FALSE}, + {"", NULL, 0, FALSE, FALSE}, + {"abc", "", 0, TRUE, TRUE}, + {"abc", "", 1, FALSE, FALSE}, + {"abc", "ab", 1, TRUE, TRUE}, + {"abc", "ab", 2, TRUE, TRUE}, + {"abc", "ab", 3, FALSE, FALSE}, + {"abc", "abc", 3, TRUE, TRUE}, + {"abc", "abc", 4, TRUE, TRUE}, + {"abc", "abC", 2, TRUE, TRUE}, + {"abc", "abC", 3, FALSE, TRUE}, +}; + +START_TEST(test_strneq) +{ + bool eq; + + ck_assert(strneq(strneq_data[_i].a, strneq_data[_i].a, strneq_data[_i].n)); + ck_assert(strneq(strneq_data[_i].b, strneq_data[_i].b, strneq_data[_i].n)); + eq = strneq(strneq_data[_i].a, strneq_data[_i].b, strneq_data[_i].n); + ck_assert(eq == strneq_data[_i].eq); + + ck_assert(strncaseeq(strneq_data[_i].a, strneq_data[_i].a, strneq_data[_i].n)); + ck_assert(strncaseeq(strneq_data[_i].b, strneq_data[_i].b, strneq_data[_i].n)); + eq = strncaseeq(strneq_data[_i].a, strneq_data[_i].b, strneq_data[_i].n); + ck_assert(eq == strneq_data[_i].case_eq); +} +END_TEST + +/******************************************************************************* * strpfx */ @@ -308,7 +384,7 @@ END_TEST START_TEST(test_memxor_aligned) { - u_int64_t a = 0, b = 0; + uint64_t a = 0, b = 0; chunk_t ca, cb; int i; @@ -848,6 +924,8 @@ Suite *utils_suite_create() suite_add_tcase(s, tc); tc = tcase_create("string helper"); + tcase_add_loop_test(tc, test_streq, 0, countof(streq_data)); + tcase_add_loop_test(tc, test_strneq, 0, countof(strneq_data)); tcase_add_loop_test(tc, test_strpfx, 0, countof(strpfx_data)); suite_add_tcase(s, tc); |