tests/test_printf.c

changeset 849
edb9f875b7f9
parent 810
85859399a0cc
     1.1 --- a/tests/test_printf.c	Wed Apr 03 21:22:23 2024 +0200
     1.2 +++ b/tests/test_printf.c	Fri Apr 12 21:48:12 2024 +0200
     1.3 @@ -301,9 +301,11 @@
     1.4      CxAllocator *alloc = &talloc.base;
     1.5      CX_TEST_DO {
     1.6          char *oldbuf = buf;
     1.7 -        size_t len = cx_sprintf_a(alloc, &buf, 16, "Test %d %s", 47, "string");
     1.8 +        size_t buflen = 16;
     1.9 +        size_t len = cx_sprintf_a(alloc, &buf, &buflen, "Test %d %s", 47, "string");
    1.10          CX_TEST_ASSERT(oldbuf == buf);
    1.11          CX_TEST_ASSERT(len == 14);
    1.12 +        CX_TEST_ASSERT(buflen == 16);
    1.13          CX_TEST_ASSERT(0 == memcmp(buf, "Test 47 string", 15));
    1.14          CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
    1.15      }
    1.16 @@ -317,8 +319,10 @@
    1.17      CxAllocator *alloc = &talloc.base;
    1.18      char *buf = cxMalloc(alloc, 8);
    1.19      CX_TEST_DO {
    1.20 -        size_t len = cx_sprintf_a(alloc, &buf, 8, "Test %d %s", 47, "foobar");
    1.21 +        size_t buflen = 8;
    1.22 +        size_t len = cx_sprintf_a(alloc, &buf, &buflen, "Test %d %s", 47, "foobar");
    1.23          CX_TEST_ASSERT(len == 14);
    1.24 +        CX_TEST_ASSERT(buflen == 15);
    1.25          CX_TEST_ASSERT(0 == memcmp(buf, "Test 47 foobar", 15));
    1.26          cxFree(alloc, buf);
    1.27          CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
    1.28 @@ -333,8 +337,10 @@
    1.29      // make it so that only the zero-terminator does not fit
    1.30      char *buf = cxMalloc(alloc, 14);
    1.31      CX_TEST_DO {
    1.32 -        size_t len = cx_sprintf_a(alloc, &buf, 14, "Test %d %s", 13, "string");
    1.33 +        size_t buflen = 14;
    1.34 +        size_t len = cx_sprintf_a(alloc, &buf, &buflen, "Test %d %s", 13, "string");
    1.35          CX_TEST_ASSERT(len == 14);
    1.36 +        CX_TEST_ASSERT(buflen == 15);
    1.37          CX_TEST_ASSERT(0 == memcmp(buf, "Test 13 string", 15));
    1.38          cxFree(alloc, buf);
    1.39          CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
    1.40 @@ -349,8 +355,10 @@
    1.41      CxAllocator *alloc = &talloc.base;
    1.42      CX_TEST_DO {
    1.43          char *str;
    1.44 -        size_t len = cx_sprintf_sa(alloc, buf, 16, &str, "Test %d %s", 47, "string");
    1.45 +        size_t buflen = 16;
    1.46 +        size_t len = cx_sprintf_sa(alloc, buf, &buflen, &str, "Test %d %s", 47, "string");
    1.47          CX_TEST_ASSERT(str == buf);
    1.48 +        CX_TEST_ASSERT(buflen == 16);
    1.49          CX_TEST_ASSERT(len == 14);
    1.50          CX_TEST_ASSERT(0 == memcmp(buf, "Test 47 string", 15));
    1.51          CX_TEST_ASSERT(0 == memcmp(str, "Test 47 string", 15));
    1.52 @@ -367,8 +375,10 @@
    1.53      CxAllocator *alloc = &talloc.base;
    1.54      CX_TEST_DO {
    1.55          char *str;
    1.56 -        size_t len = cx_sprintf_sa(alloc, buf, 16, &str, "Hello %d %s", 4711, "larger string");
    1.57 +        size_t buflen = 16;
    1.58 +        size_t len = cx_sprintf_sa(alloc, buf, &buflen, &str, "Hello %d %s", 4711, "larger string");
    1.59          CX_TEST_ASSERT(str != buf);
    1.60 +        CX_TEST_ASSERT(buflen == 25);
    1.61          CX_TEST_ASSERT(len == 24);
    1.62          CX_TEST_ASSERT(0 == memcmp(str, "Hello 4711 larger string", 25));
    1.63          cxFree(alloc, str);
    1.64 @@ -385,9 +395,11 @@
    1.65      CxAllocator *alloc = &talloc.base;
    1.66      CX_TEST_DO {
    1.67          char *str;
    1.68 -        size_t len = cx_sprintf_sa(alloc, buf, 16, &str, "Hello %d %s", 112, "string");
    1.69 +        size_t buflen = 16;
    1.70 +        size_t len = cx_sprintf_sa(alloc, buf,&buflen, &str, "Hello %d %s", 112, "string");
    1.71          CX_TEST_ASSERT(str != buf);
    1.72          CX_TEST_ASSERT(len == 16);
    1.73 +        CX_TEST_ASSERT(buflen == 17);
    1.74          CX_TEST_ASSERT(0 == memcmp(str, "Hello 112 string", 17)); // include terminator
    1.75          cxFree(alloc, str);
    1.76          CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));

mercurial