45 ucx_fprintf(b1, (write_func)ucx_buffer_write, "\nend.\n"); |
45 ucx_fprintf(b1, (write_func)ucx_buffer_write, "\nend.\n"); |
46 UCX_TEST_ASSERT(!strcmp(b1->space, "Hello World\nend.\n"), |
46 UCX_TEST_ASSERT(!strcmp(b1->space, "Hello World\nend.\n"), |
47 "wrong content in b1 after second fprintf"); |
47 "wrong content in b1 after second fprintf"); |
48 |
48 |
49 ucx_fprintf(b2, (write_func)ucx_buffer_write, "%s%s", teststr1, teststr2); |
49 ucx_fprintf(b2, (write_func)ucx_buffer_write, "%s%s", teststr1, teststr2); |
|
50 UCX_TEST_ASSERT(b2->pos == 2046, "wrong length"); |
50 UCX_TEST_ASSERT(!memcmp(b2->space, teststr1, 1023), |
51 UCX_TEST_ASSERT(!memcmp(b2->space, teststr1, 1023), |
51 "wrong first half in b2"); |
52 "wrong first half in b2"); |
52 UCX_TEST_ASSERT(!memcmp(b2->space+1023, teststr2, 1023), |
53 UCX_TEST_ASSERT(!memcmp(b2->space+1023, teststr2, 1023), |
53 "wrong second half in b2"); |
54 "wrong second half in b2"); |
54 |
55 |
55 UCX_TEST_END |
56 UCX_TEST_END |
|
57 |
|
58 ucx_buffer_free(b1); |
|
59 ucx_buffer_free(b2); |
56 } |
60 } |
57 |
61 |
58 UCX_TEST(test_ucx_asprintf) { |
62 UCX_TEST(test_ucx_asprintf) { |
59 char *teststr1 = (char*)calloc(1, 1024); |
63 char *teststr1 = (char*)calloc(1, 1024); |
60 char *teststr2 = (char*)calloc(1, 1024); |
64 char *teststr2 = (char*)calloc(1, 1024); |
69 UCX_TEST_ASSERT(s1.length == 21, "wrong length"); |
73 UCX_TEST_ASSERT(s1.length == 21, "wrong length"); |
70 UCX_TEST_ASSERT(!sstrcmp(s1, S("int: 123\nHello World!")), "wrong content"); |
74 UCX_TEST_ASSERT(!sstrcmp(s1, S("int: 123\nHello World!")), "wrong content"); |
71 free(s1.ptr); |
75 free(s1.ptr); |
72 |
76 |
73 sstr_t s2 = ucx_asprintf(a, "%s%s", teststr1, teststr2); |
77 sstr_t s2 = ucx_asprintf(a, "%s%s", teststr1, teststr2); |
|
78 UCX_TEST_ASSERT(s2.ptr, "s2.ptr is NULL"); |
|
79 UCX_TEST_ASSERT(s2.length == 2046, "wrong length"); |
74 UCX_TEST_ASSERT(!memcmp(s2.ptr, teststr1, 1023), |
80 UCX_TEST_ASSERT(!memcmp(s2.ptr, teststr1, 1023), |
75 "wrong first half in s2"); |
81 "wrong first half in s2"); |
76 UCX_TEST_ASSERT(!memcmp(s2.ptr+1023, teststr2, 1023), |
82 UCX_TEST_ASSERT(!memcmp(s2.ptr+1023, teststr2, 1023), |
77 "wrong second half in s2"); |
83 "wrong second half in s2"); |
|
84 free(s2.ptr); |
78 |
85 |
79 UCX_TEST_END |
86 UCX_TEST_END |
80 } |
87 } |