test/string_tests.c

changeset 179
ee25d79a4187
parent 177
11ad03783baf
child 180
2185f19dcc45
equal deleted inserted replaced
178:8c89e454000f 179:ee25d79a4187
38 UCX_TEST_ASSERT(s2.length == 2, "s2 length must be 2"); 38 UCX_TEST_ASSERT(s2.length == 2, "s2 length must be 2");
39 39
40 UCX_TEST_END 40 UCX_TEST_END
41 } 41 }
42 42
43 UCX_TEST(test_sstr_len_cat) { 43 UCX_TEST(test_sstr_len) {
44 sstr_t s1 = ST("1234"); 44 sstr_t s1 = ST("1234");
45 sstr_t s2 = ST(".:.:."); 45 sstr_t s2 = ST(".:.:.");
46 sstr_t s3 = ST("X"); 46 sstr_t s3 = ST("X");
47 47
48 size_t len = sstrnlen(3, s1, s2, s3); 48 size_t len = sstrnlen(3, s1, s2, s3);
49 sstr_t cat;
50 cat.ptr = (char*) malloc(16);
51 cat.length = 16;
52 cat = sstrncat(cat, 3, s1, s2, s3);
53 49
54 UCX_TEST_BEGIN 50 UCX_TEST_BEGIN
55 51
56 UCX_TEST_ASSERT(len == 10, "sstrnlen returned wrong size"); 52 UCX_TEST_ASSERT(len == 10, "sstrnlen returned wrong size");
57 53
58 UCX_TEST_ASSERT(cat.ptr[0] == '1', "sstrncat, wrong content"); 54 UCX_TEST_END
59 UCX_TEST_ASSERT(cat.ptr[1] == '2', "sstrncat, wrong content");
60 UCX_TEST_ASSERT(cat.ptr[2] == '3', "sstrncat, wrong content");
61 UCX_TEST_ASSERT(cat.ptr[3] == '4', "sstrncat, wrong content");
62 UCX_TEST_ASSERT(cat.ptr[4] == '.', "sstrncat, wrong content");
63 UCX_TEST_ASSERT(cat.ptr[8] == '.', "sstrncat, wrong content");
64 UCX_TEST_ASSERT(cat.ptr[9] == 'X', "sstrncat, wrong content");
65 UCX_TEST_ASSERT(cat.length == 10, "sstrncat, wrong length");
66
67 UCX_TEST_END
68
69 free(cat.ptr);
70 } 55 }
71 56
72 UCX_TEST(test_sstrchr_sstrrchr) { 57 UCX_TEST(test_sstrchr_sstrrchr) {
73 sstr_t str = ST("I will find you - and I will kill you"); 58 sstr_t str = ST("I will find you - and I will kill you");
74 UCX_TEST_BEGIN 59 UCX_TEST_BEGIN

mercurial