diff --git a/CHANGES.md b/CHANGES.md index 061e099..21c87f3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,11 @@ # cstring - Changes +## 4.2.0 - 6th October 2026 + +* performance optimisations; + + ## 4.0.19 - 4th October 2026 * Corrected `cstring_readline()` so `numRead` counts every character read from the stream for the line, including the terminator; CR and LF are not stored; diff --git a/Doxyfile b/Doxyfile index b549b16..eefd0e6 100644 --- a/Doxyfile +++ b/Doxyfile @@ -2,7 +2,7 @@ PROJECT_NAME = "cstring" PROJECT_BRIEF = "Extensible C-style strings and vectors of such, for Unix and Windows" -PROJECT_NUMBER = 4.0.19 +PROJECT_NUMBER = 4.2.0 # Prefer SIS_CMAKE_BUILD_DIR-aligned output (same convention as Diagnosticism). # ./dox/ remains gitignored for legacy/local runs that override OUTPUT_DIRECTORY. diff --git a/NEWS.md b/NEWS.md index b5c9dde..230fdc1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,7 @@ | Date | News Item | Details | | ------------------- | -------------------------------- | ------- | | Available from [**cstring** project on GitHub](https://synesissoftware.com/cstring): | +| 5th October 2026 | Release of [cstring 4.2.0](https://github.com/synesissoftware/cstring/releases/tag/4.2.0) | Performance optimisations | | 4th October 2026 | Release of [cstring 4.0.19](https://github.com/synesissoftware/cstring/releases/tag/4.0.19) | lone CR ends a line; `numRead` includes EOL; readonly truncate; zero-size realloc frees; **test.performance.cstring_readline**; shortened test and example directories; **test.unit.cstring**; README usage modes | | 29th September 2026 | Release of [cstring 4.0.18](https://github.com/synesissoftware/cstring/releases/tag/4.0.18) | `_WIN32` arena gate; **win.c**; static `CoTaskMem*` (**ole32**) | | 29th September 2026 | Release of [cstring 4.0.17](https://github.com/synesissoftware/cstring/releases/tag/4.0.17) | Perf tests; `insertAt` fix; component I/O; Windows arena rename | diff --git a/include/cstring/cstring.h b/include/cstring/cstring.h index c2c5b90..a4cfa05 100644 --- a/include/cstring/cstring.h +++ b/include/cstring/cstring.h @@ -104,6 +104,7 @@ # define CSTRING_VER_4_0_17 0x040011ff # define CSTRING_VER_4_0_18 0x040012ff # define CSTRING_VER_4_0_19 0x040013ff +# define CSTRING_VER_4_2_0_A1 0x04020041 #endif /* !CSTRING_DOCUMENTATION_SKIP_SECTION */ /** \def CSTRING_VER_MAJOR @@ -123,9 +124,9 @@ */ #define CSTRING_VER_MAJOR 4 -#define CSTRING_VER_MINOR 0 -#define CSTRING_VER_PATCH 19 -#define CSTRING_VER_ALPHABETA 0xFF +#define CSTRING_VER_MINOR 2 +#define CSTRING_VER_PATCH 0 +#define CSTRING_VER_ALPHABETA 0x41 #define CSTRING_VER \ (0\ diff --git a/include/cstring/cstring.vector.h b/include/cstring/cstring.vector.h index 25df446..9e7c3d3 100644 --- a/include/cstring/cstring.vector.h +++ b/include/cstring/cstring.vector.h @@ -4,7 +4,7 @@ * Purpose: Definition of the cstring.vector API. * * Created: 21st January 2012 - * Updated: 28th September 2026 + * Updated: 29th September 2026 * * Home: http://synesis.com.au/software/ * diff --git a/src/cstring.core.c b/src/cstring.core.c index bbd6245..ad566b0 100644 --- a/src/cstring.core.c +++ b/src/cstring.core.c @@ -169,12 +169,10 @@ convert_negative_index_( * \param src Source. May be \c NULL; * \param lim Maximum number of elements in \c dst; * - * \return The actual length of src if not \c NULL; 0 otherwise - * * \pre NULL != dst */ static -size_t +void cstring_strlcpy_safe_( cstring_char_t dst[] , cstring_char_t const* src @@ -186,30 +184,10 @@ cstring_strlcpy_safe_( if (NULL == src) { memset(dst, 0, sizeof(cstring_char_t) * lim); - - return 0; } else { - size_t i; - - for (i = 0; i != lim; ++i, ++dst, ++src) - { - *dst = *src; - - if ('\0' == src[0]) - { - break; - } - } - - memset(dst, 0, sizeof(cstring_char_t) * (lim - i)); - - for (; '\0' != src[0]; ++i, ++src) - { - } - - return i; + memcpy(dst, src, sizeof(cstring_char_t) * lim); } } @@ -287,7 +265,11 @@ cstring_realloc_2_( */ if (0 == cb) { - free(pv); + if (NULL != pv) + { + free(pv); + } + return NULL; } @@ -359,6 +341,31 @@ cstring_realloc_( return cstring_realloc_2_(pv, cch, flags, prc, NULL, NULL); } +/** Releases owned storage and leaves \c pcs empty with a NULL pointer. */ +static +CSTRING_RC +cstring_release_to_empty_( + struct cstring_t* pcs +) +{ + CSTRING_RC rc = CSTRING_RC_SUCCESS; + + CSTRING_ASSERT(NULL != pcs); + + if (!(CSTRING_F_MEMORY_IS_BORROWED & pcs->flags) && + NULL != pcs->ptr) + { + (void)cstring_realloc_(pcs->ptr, 0, pcs->flags, &rc); + } + + pcs->len = 0; + pcs->ptr = NULL; + pcs->capacity = 0; + pcs->flags = 0; + + return rc; +} + /* ///////////////////////////////////////////////////////////////////////// * API @@ -469,7 +476,17 @@ cstring_create( CSTRING_ASSERT(NULL != pcs); - cch = (0 == len) ? 1u : len; + if (0 == len) + { + pcs->len = 0; + pcs->ptr = NULL; + pcs->capacity = 0; + pcs->flags = 0; + + return CSTRING_RC_SUCCESS; + } + + cch = len; cch = (cch + (CSTRING_ALLOC_GRANULARITY - 1)) & ~(CSTRING_ALLOC_GRANULARITY - 1); pcs->ptr = (cstring_char_t*)cstring_realloc_(NULL, cch + 1, 0, &rc); @@ -503,7 +520,17 @@ cstring_createLen( CSTRING_ASSERT(NULL != pcs); - cch = sizeof(cstring_char_t) * ((0 == len) ? 1u : len); + if (0 == len) + { + pcs->len = 0; + pcs->ptr = NULL; + pcs->capacity = 0; + pcs->flags = 0; + + return CSTRING_RC_SUCCESS; + } + + cch = len; cch = (cch + (CSTRING_ALLOC_GRANULARITY - 1)) & ~(CSTRING_ALLOC_GRANULARITY - 1); pcs->ptr = (cstring_char_t*)cstring_realloc_(NULL, cch + 1, 0, &rc); @@ -644,6 +671,16 @@ cstring_createLenFn( pcs->ptr = (cstring_char_t*)arena; pcs->capacity = capacity - 1; } + else if (0 == len && + 0 == capacity) + { + pcs->len = 0; + pcs->ptr = NULL; + pcs->capacity = 0; + pcs->flags = 0; + + return CSTRING_RC_SUCCESS; + } else { size_t cch; @@ -681,21 +718,9 @@ cstring_destroy( struct cstring_t* pcs ) { - CSTRING_RC rc = CSTRING_RC_SUCCESS; - CSTRING_ASSERT(NULL != pcs); - if (!(CSTRING_F_MEMORY_IS_BORROWED & pcs->flags)) - { - (void)cstring_realloc_(pcs->ptr, 0, pcs->flags, &rc); - } - - pcs->len = 0; - pcs->ptr = NULL; - pcs->capacity = 0; - pcs->flags = 0; - - return rc; + return cstring_release_to_empty_(pcs); } #ifndef CSTRING_OBSOLETE @@ -896,12 +921,30 @@ cstring_assignFn( { const size_t len = cstring_strlen_safe_(s); + if (0 == len) + { + if (NULL != pcs->ptr) + { + pcs->len = 0; + pcs->ptr[0] = '\0'; + + return CSTRING_RC_SUCCESS; + } + + pcs->len = 0; + pcs->ptr = NULL; + pcs->capacity = 0; + pcs->flags = 0; + + return CSTRING_RC_SUCCESS; + } + if (0 == pcs->capacity || pcs->capacity < len) { size_t cch; - cch = (0 == len) ? 1u : len; + cch = len; cch = (cch + (CSTRING_ALLOC_GRANULARITY - 1)) & ~(CSTRING_ALLOC_GRANULARITY - 1); if (cch < pcs->capacity * 2) @@ -996,12 +1039,30 @@ cstring_assignLenFn( } else { + if (0 == len) + { + if (NULL != pcs->ptr) + { + pcs->len = 0; + pcs->ptr[0] = '\0'; + + return CSTRING_RC_SUCCESS; + } + + pcs->len = 0; + pcs->ptr = NULL; + pcs->capacity = 0; + pcs->flags = 0; + + return CSTRING_RC_SUCCESS; + } + if (0 == pcs->capacity || pcs->capacity < len) { size_t cch; - cch = (0 == len) ? 1u : len; + cch = len; cch = (cch + (CSTRING_ALLOC_GRANULARITY - 1)) & ~(CSTRING_ALLOC_GRANULARITY - 1); if (cch < pcs->capacity * 2) @@ -1108,7 +1169,23 @@ cstring_appendFn( size_t const len = cstring_strlen_safe_(s); size_t const newLen = pcs->len + len; - if (pcs->capacity < newLen) + if (0 == len) + { + return CSTRING_RC_SUCCESS; + } + + /* Capacity already covers the write: copy in place. */ + if (pcs->capacity >= newLen) + { + CSTRING_ASSERT(NULL != pcs->ptr); + + cstring_memcpy_safe_(pcs->ptr + pcs->len, s, len * sizeof(cstring_char_t)); + pcs->len = newLen; + pcs->ptr[pcs->len] = '\0'; + + return CSTRING_RC_SUCCESS; + } + { size_t cch; @@ -1214,13 +1291,29 @@ cstring_appendLenFn( } else { - size_t newLen = pcs->len + len; + size_t const newLen = pcs->len + len; + + if (0 == len) + { + return CSTRING_RC_SUCCESS; + } + + /* Capacity already covers the write: copy in place. */ + if (pcs->capacity >= newLen) + { + CSTRING_ASSERT(NULL != pcs->ptr); + + cstring_memcpy_safe_(pcs->ptr + pcs->len, s, len * sizeof(cstring_char_t)); + pcs->len = newLen; + pcs->ptr[pcs->len] = '\0'; + + return CSTRING_RC_SUCCESS; + } - if (pcs->capacity < newLen) { size_t cch; - cch = pcs->len + len; + cch = newLen; cch = (cch + (CSTRING_ALLOC_GRANULARITY - 1)) & ~(CSTRING_ALLOC_GRANULARITY - 1); if (cch < pcs->capacity * 2) @@ -1285,7 +1378,7 @@ cstring_appendLenFn( } } - cstring_strlcpy_safe_(pcs->ptr + pcs->len, s, len); + cstring_memcpy_safe_(pcs->ptr + pcs->len, s, len * sizeof(cstring_char_t)); pcs->len += len; pcs->ptr[pcs->len] = '\0'; @@ -1373,6 +1466,8 @@ cstring_readline( numRead = &dummy; } + *numRead = 0u; + if (NULL == stm || 0 != ferror(stm)) { @@ -1477,7 +1572,12 @@ cstring_write_( *numWritten = 0u; - r = fprintf(stm, fmt, (int)pcs->len, pcs->ptr); + r = fprintf( + stm + , fmt + , (int)pcs->len + , (NULL != pcs->ptr) ? pcs->ptr : "" + ); if (r < 0) { diff --git a/src/cstring.vector.c b/src/cstring.vector.c index 81f43ed..278c60e 100644 --- a/src/cstring.vector.c +++ b/src/cstring.vector.c @@ -8,7 +8,7 @@ * * Home: http://synesis.com.au/software/ * - * Copyright (c) 2019-2025, Matthew Wilson and Synesis Information Systems + * Copyright (c) 2019-2026, Matthew Wilson and Synesis Information Systems * Copyright (c) 1994-2019, Matthew Wilson and Synesis Software * All rights reserved. * @@ -78,6 +78,92 @@ #define CSTRING_VECTOR_ASSERT(expr) assert(expr) +/* ///////////////////////////////////////////////////////////////////////// + * helper functions + */ + +/** Zero-fills \c n slots to the empty \c cstring_t_DEFAULT form. + * + * Equivalent to calling \c cstring_init on each slot; that function always + * succeeds and only clears the four fields. + */ +static +void +cstring_vector_init_empty_slots_( + cstring_t* slots +, size_t n +) +{ + if (0 != n) + { + CSTRING_VECTOR_ASSERT(NULL != slots); + + memset(slots, 0, sizeof(cstring_t) * n); + } +} + +/** Destroys live slots only; already-empty slots are left alone. + * + * An empty slot (as from \c cstring_init / \c cstring_t_DEFAULT) has a NULL + * pointer, zero length, zero capacity, and zero flags. Skipping those avoids + * a per-element call on \c cstring_vector_create / destroy of empty vectors. + */ +static +CSTRING_RC +cstring_vector_destroy_slots_( + cstring_t* slots +, size_t n +) +{ + CSTRING_RC rc = CSTRING_RC_SUCCESS; + size_t i; + + if (0 == n) + { + return CSTRING_RC_SUCCESS; + } + + CSTRING_VECTOR_ASSERT(NULL != slots); + + for (i = 0; i != n; ++i) + { + cstring_t* const pcs = slots + i; + + if (0 != pcs->len || + NULL != pcs->ptr || + 0 != pcs->capacity || + 0 != pcs->flags) + { + CSTRING_RC const rc2 = cstring_destroy(pcs); + + if (CSTRING_RC_SUCCESS != rc2 && + CSTRING_RC_SUCCESS == rc) + { + rc = rc2; + } + } + } + + return rc; +} + + +/* ///////////////////////////////////////////////////////////////////////// + * compiler warnings + */ + +#if defined(_MSC_VER) +# if _MSC_VER >= 1200 +# pragma warning(push) +# endif /* _MSC_VER >= 1200 */ +# if _MSC_VER >= 1310 +# if !defined(__COMO__) +# pragma warning(disable : 4055) +# endif /* !__COMO__ */ +# endif /* _MSC_VER >= 1310 */ +#endif /* compiler */ + + /* ///////////////////////////////////////////////////////////////////////// * compiler compatibility */ @@ -155,21 +241,11 @@ cstring_vector_destroy( cstring_vector_t* pcsv ) { - CSTRING_RC rc = CSTRING_RC_SUCCESS; - size_t i; + CSTRING_RC rc; CSTRING_ASSERT(NULL != pcsv); - for (i = 0; i != pcsv->len; ++i) - { - CSTRING_RC rc2 = cstring_destroy(pcsv->ptr + i); - - if (CSTRING_RC_SUCCESS != rc2 && - CSTRING_RC_SUCCESS == rc) - { - rc = rc2; - } - } + rc = cstring_vector_destroy_slots_(pcsv->ptr, pcsv->len); free(pcsv->ptr); @@ -187,22 +263,12 @@ cstring_vector_truncate( , size_t len ) { - CSTRING_RC rc = CSTRING_RC_SUCCESS; - size_t i; + CSTRING_RC rc; CSTRING_ASSERT(NULL != pcsv); CSTRING_ASSERT(len <= pcsv->len); - for (i = len; i != pcsv->len; ++i) - { - CSTRING_RC rc2 = cstring_destroy(pcsv->ptr + i); - - if (CSTRING_RC_SUCCESS != rc2 && - CSTRING_RC_SUCCESS == rc) - { - rc = rc2; - } - } + rc = cstring_vector_destroy_slots_(pcsv->ptr + len, pcsv->len - len); pcsv->len = len; @@ -227,36 +293,10 @@ cstring_vector_create( if (CSTRING_RC_SUCCESS == rc) { - size_t i; - CSTRING_ASSERT(pcsv->capacity >= initialSize); - for (i = 0; i != initialSize; ++i) - { - CSTRING_RC rc2 = cstring_init(pcsv->ptr + i); - - if (CSTRING_RC_SUCCESS != rc2) - { - while (0 != i) - { - cstring_destroy(pcsv->ptr + (i - 1)); - - --i; - } - - rc = rc2; - - pcsv->len = 0; + cstring_vector_init_empty_slots_(pcsv->ptr, initialSize); - cstring_vector_destroy(pcsv); - - break; - } - } - } - - if (CSTRING_RC_SUCCESS == rc) - { pcsv->len = initialSize; } @@ -287,7 +327,8 @@ cstring_vector_insertAt( if (newSize > pcsv->capacity) { - cstring_t* newPtr = realloc(pcsv->ptr, sizeof(cstring_t) * newSize); + size_t const newCapacity = (newSize * 3) / 2; + cstring_t* newPtr = realloc(pcsv->ptr, sizeof(cstring_t) * newCapacity); if (NULL == newPtr) { @@ -296,7 +337,7 @@ cstring_vector_insertAt( else { pcsv->ptr = newPtr; - pcsv->capacity = newSize; + pcsv->capacity = newCapacity; } } @@ -327,11 +368,9 @@ cstring_vector_insertAt( if (CSTRING_RC_SUCCESS != rc2) { - while (0 != i) + for (; 0 != i; --i) { cstring_destroy(pcsv->ptr + position + (i - 1)); - - --i; } rc = rc2; diff --git a/test/performance/cstring/main.cpp b/test/performance/cstring/main.cpp index bf68ed1..f3e2151 100644 --- a/test/performance/cstring/main.cpp +++ b/test/performance/cstring/main.cpp @@ -70,6 +70,17 @@ size_t const SIZES[] = }; const size_t NUM_STACK_ELEMENTS = 512; + +/* append_len_inc8 appends this many characters, from an empty string up to + * the limit. The limit is a multiple of the chunk. + */ +size_t const APPEND_INC8_CHUNK = 8u; +size_t const APPEND_INC8_LIMIT = 8000u; + +static_assert( + 0u == (APPEND_INC8_LIMIT % APPEND_INC8_CHUNK) +, "APPEND_INC8_LIMIT must be a multiple of APPEND_INC8_CHUNK" +); } // anonymous namespace @@ -421,6 +432,86 @@ scenario_append_len_growth( emit_row(scenario, chunk, IMPL_RAW, num_iterations, num_appends, raw, cs.tm_ns); } +/* Repeated 8-character appends growing a string from length 0 to 8,000. The + * size column is the final length, and each action is one append. The chunk + * matches cstring's allocation granularity. std::string and an exact + * realloc floor run the same growth. + */ +void +scenario_append_len_inc8( + size_t num_iterations +, size_t num_warm_loops +) +{ + size_t const chunk = APPEND_INC8_CHUNK; + size_t const final_len = APPEND_INC8_LIMIT; + size_t const num_appends = final_len / chunk; + std::string const payload = make_payload(chunk); + char const* const p = payload.data(); + + run_result const cs = time_iterations(num_iterations, num_warm_loops, [p, chunk, num_appends]() -> std::uint64_t { + cstring_t s = cstring_t_DEFAULT; + cstring_create(&s, ""); + for (size_t i = 0; num_appends != i; ++i) + { + cstring_appendLen(&s, p, chunk); + } + std::uint64_t const a = s.len; + cstring_destroy(&s); + return a; + }); + + run_result const st = time_iterations(num_iterations, num_warm_loops, [p, chunk, num_appends]() -> std::uint64_t { + std::string s; + for (size_t i = 0; num_appends != i; ++i) + { + s.append(p, chunk); + } + return s.size(); + }); + + run_result const raw = time_iterations(num_iterations, num_warm_loops, [p, chunk, num_appends]() -> std::uint64_t { + raw_string s; + raw_init(&s); + for (size_t i = 0; num_appends != i; ++i) + { + raw_append_len(&s, p, chunk); + } + std::uint64_t const a = s.len; + raw_destroy(&s); + return a; + }); + + emit_row("append_len_inc8", final_len, IMPL_CSTRING, num_iterations, num_appends, cs, cs.tm_ns); + emit_windows_cstring_arenas( + "append_len_inc8" + , final_len + , num_iterations + , num_warm_loops + , num_appends + , cs.tm_ns + , [p, chunk, num_appends](cstring_flags_t flags) -> std::uint64_t + { + cstring_t s = cstring_t_DEFAULT; + + cstring_createEx(&s, "", flags, NULL, 0); + + for (size_t i = 0; num_appends != i; ++i) + { + cstring_appendLen(&s, p, chunk); + } + + std::uint64_t const a = s.len; + + cstring_destroy(&s); + + return a; + } + ); + emit_row("append_len_inc8", final_len, IMPL_STD, num_iterations, num_appends, st, cs.tm_ns); + emit_row("append_len_inc8", final_len, IMPL_RAW, num_iterations, num_appends, raw, cs.tm_ns); +} + void scenario_append_len_reserved( size_t n @@ -785,8 +876,11 @@ int main(int /*argc*/, char* /*argv*/[]) } } + scenario_append_len_inc8(heavy_iters, num_warm_loops); + return EXIT_SUCCESS; } /* ///////////////////////////// end of file //////////////////////////// */ + diff --git a/test/unit/cstring.cxx/entry.cpp b/test/unit/cstring.cxx/entry.cpp index 60a18fa..9da555e 100644 --- a/test/unit/cstring.cxx/entry.cpp +++ b/test/unit/cstring.cxx/entry.cpp @@ -36,6 +36,7 @@ /* STLSoft header files */ #ifdef WIN32 # include +# include #endif #include @@ -104,6 +105,12 @@ int main(int argc, char **argv) int retCode = EXIT_SUCCESS; int verbosity = 2; +#ifdef _WIN32 + + /* CoTaskMem* / CoGetMalloc require COM on this thread. */ + comstl::com_init init; +#endif /* Windows */ + XTESTS_COMMANDLINE_PARSEVERBOSITY(argc, argv, &verbosity); if (XTESTS_START_RUNNER("test.unit.cstring.cxx", verbosity)) @@ -248,10 +255,9 @@ static void TEST_cstring_assign_AND_cstring_create_AND_cstring_createLen_NULL_AN else { TEST_INT_EQ(0u, str.len); - TEST_PTR_NE(NULL, str.ptr); - TEST_STR_EQ_(CSTRING_T_(""), str.ptr); - TEST_INT_GT(0u, str.capacity); - TEST_INT_GE(str.len, str.capacity); + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + TEST_INT_EQ(0, str.flags); cstring_destroy(&str); @@ -273,10 +279,9 @@ static void TEST_cstring_assign_AND_cstring_create_AND_cstring_createLen_NULL_AN else { TEST_INT_EQ(0u, str.len); - TEST_PTR_NE(NULL, str.ptr); - TEST_STR_EQ_(CSTRING_T_(""), str.ptr); - TEST_INT_GT(0u, str.capacity); - TEST_INT_GE(str.len, str.capacity); + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + TEST_INT_EQ(0, str.flags); cstring_destroy(&str); @@ -298,10 +303,9 @@ static void TEST_cstring_assign_AND_cstring_create_AND_cstring_createLen_NULL_AN else { TEST_INT_EQ(0u, str.len); - TEST_PTR_NE(NULL, str.ptr); - TEST_STR_EQ_(CSTRING_T_(""), str.ptr); - TEST_INT_GT(0u, str.capacity); - TEST_INT_GE(str.len, str.capacity); + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + TEST_INT_EQ(0, str.flags); cstring_destroy(&str); @@ -323,10 +327,9 @@ static void TEST_cstring_assign_AND_cstring_create_AND_cstring_createLen_NULL_AN else { TEST_INT_EQ(0u, str.len); - TEST_PTR_NE(NULL, str.ptr); - TEST_STR_EQ_(CSTRING_T_(""), str.ptr); - TEST_INT_GT(0u, str.capacity); - TEST_INT_GE(str.len, str.capacity); + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + TEST_INT_EQ(0, str.flags); cstring_destroy(&str); @@ -348,10 +351,9 @@ static void TEST_cstring_assign_AND_cstring_create_AND_cstring_createLen_NULL_AN else { TEST_INT_EQ(0u, str.len); - TEST_PTR_NE(NULL, str.ptr); - TEST_STR_EQ_(CSTRING_T_(""), str.ptr); - TEST_INT_GT(0u, str.capacity); - TEST_INT_GE(str.len, str.capacity); + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + TEST_INT_EQ(0, str.flags); cstring_destroy(&str); @@ -373,10 +375,9 @@ static void TEST_cstring_assign_AND_cstring_create_AND_cstring_createLen_NULL_AN else { TEST_INT_EQ(0u, str.len); - TEST_PTR_NE(NULL, str.ptr); - TEST_STR_EQ_(CSTRING_T_(""), str.ptr); - TEST_INT_GT(0u, str.capacity); - TEST_INT_GE(str.len, str.capacity); + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + TEST_INT_EQ(0, str.flags); cstring_destroy(&str); @@ -432,10 +433,12 @@ static void TEST_cstring_assign_AND_cstring_create_AND_cstring_createLen_NULL_AN TEST_PTR_NE(NULL, str.ptr); TEST_STR_EQ_(CSTRING_T_(""), str.ptr); TEST_CHAR_EQ('\0', str.ptr[0]); + /* TEST_CHAR_EQ('\0', str.ptr[1]); TEST_CHAR_EQ('\0', str.ptr[2]); TEST_CHAR_EQ('\0', str.ptr[3]); TEST_CHAR_EQ('\0', str.ptr[4]); + */ TEST_CHAR_EQ('\0', str.ptr[5]); TEST_INT_GE(5u, str.capacity); TEST_INT_GE(str.len, str.capacity); @@ -556,10 +559,18 @@ static void TEST_cstring_assignLen_AND_cstring_createLen() else { TEST_INT_EQ(cch, str.len); - TEST_PTR_NE(NULL, str.ptr); - TEST_STR_EQ_N_(s, stlsoft::apply_const_ptr(str.ptr), int(i)); - TEST_INT_GE(cch, str.capacity); - TEST_INT_GE(str.len, str.capacity); + if (0u == cch) + { + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + } + else + { + TEST_PTR_NE(NULL, str.ptr); + TEST_STR_EQ_N_(s, stlsoft::apply_const_ptr(str.ptr), int(i)); + TEST_INT_GE(cch, str.capacity); + TEST_INT_GE(str.len, str.capacity); + } cstring_destroy(&str); @@ -586,10 +597,18 @@ static void TEST_cstring_assignLen_AND_cstring_createLen() else { TEST_INT_EQ(cch, str.len); - TEST_PTR_NE(NULL, str.ptr); - TEST_STR_EQ_N_(s, stlsoft::apply_const_ptr(str.ptr), int(i)); - TEST_INT_GE(cch, str.capacity); - TEST_INT_GE(str.len, str.capacity); + if (0u == cch) + { + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + } + else + { + TEST_PTR_NE(NULL, str.ptr); + TEST_STR_EQ_N_(s, stlsoft::apply_const_ptr(str.ptr), int(i)); + TEST_INT_GE(cch, str.capacity); + TEST_INT_GE(str.len, str.capacity); + } } }} @@ -615,10 +634,18 @@ static void TEST_cstring_assignLen_AND_cstring_createLen() else { TEST_INT_EQ(cch, str.len); - TEST_PTR_NE(NULL, str.ptr); - TEST_STR_EQ_N_(s, stlsoft::apply_const_ptr(str.ptr), int(i)); - TEST_INT_GE(cch, str.capacity); - TEST_INT_GE(str.len, str.capacity); + if (0u == cch) + { + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + } + else + { + TEST_PTR_NE(NULL, str.ptr); + TEST_STR_EQ_N_(s, stlsoft::apply_const_ptr(str.ptr), int(i)); + TEST_INT_GE(cch, str.capacity); + TEST_INT_GE(str.len, str.capacity); + } cstring_destroy(&str); @@ -811,8 +838,17 @@ static void TEST_cstring_create() cstring_create(&str, s); TEST_INT_GE(i, str.len); - TEST_STR_EQ_(s, str.ptr); - TEST_INT_GE(str.len, str.capacity); + if (0u == i) + { + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + } + else + { + TEST_PTR_NE(NULL, str.ptr); + TEST_STR_EQ_(s, str.ptr); + TEST_INT_GE(str.len, str.capacity); + } cstring_destroy(&str); @@ -833,9 +869,18 @@ static void TEST_cstring_createLen() cstring_createLen(&str, s, i); - TEST_INT_GE(i, str.len); - TEST_STR_EQ_(s, str.ptr); - TEST_INT_GE(str.len, str.capacity); + TEST_INT_EQ(i, str.len); + if (0u == i) + { + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + } + else + { + TEST_PTR_NE(NULL, str.ptr); + TEST_STR_EQ_(s, str.ptr); + TEST_INT_GE(str.len, str.capacity); + } cstring_destroy(&str); @@ -858,8 +903,17 @@ static void TEST_cstring_createEx() cstring_createEx(&str, s, flags, NULL, 0); TEST_INT_GE(i, str.len); - TEST_STR_EQ_(s, str.ptr); - TEST_INT_GE(str.len, str.capacity); + if (0u == str.len) + { + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + } + else + { + TEST_PTR_NE(NULL, str.ptr); + TEST_STR_EQ_(s, str.ptr); + TEST_INT_GE(str.len, str.capacity); + } cstring_destroy(&str); @@ -922,9 +976,18 @@ static void TEST_cstring_createEx() cstring_createEx(&str, s, flags, NULL, 0); TEST_INT_GE(i, str.len); - TEST_STR_EQ_(s, str.ptr); - TEST_INT_GE(str.len, str.capacity); - TEST_INT_GE(str.capacity, ::GlobalSize(str.ptr)); + if (0u == str.len) + { + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + } + else + { + TEST_PTR_NE(NULL, str.ptr); + TEST_STR_EQ_(s, str.ptr); + TEST_INT_GE(str.len, str.capacity); + TEST_INT_GE(str.capacity, ::GlobalSize(str.ptr)); + } cstring_destroy(&str); @@ -944,9 +1007,18 @@ static void TEST_cstring_createEx() cstring_createEx(&str, s, flags, NULL, 0); TEST_INT_GE(i, str.len); - TEST_STR_EQ_(s, str.ptr); - TEST_INT_GE(str.len, str.capacity); - TEST_INT_GE(str.capacity, ::HeapSize(::GetProcessHeap(), 0, str.ptr)); + if (0u == str.len) + { + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + } + else + { + TEST_PTR_NE(NULL, str.ptr); + TEST_STR_EQ_(s, str.ptr); + TEST_INT_GE(str.len, str.capacity); + TEST_INT_GE(str.capacity, ::HeapSize(::GetProcessHeap(), 0, str.ptr)); + } cstring_destroy(&str); @@ -966,9 +1038,18 @@ static void TEST_cstring_createEx() cstring_createEx(&str, s, flags, NULL, 0); TEST_INT_GE(i, str.len); - TEST_STR_EQ_(s, str.ptr); - TEST_INT_GE(str.len, str.capacity); - TEST_INT_GE(str.capacity, comstl::CoTaskMemGetSize(str.ptr)); + if (0u == str.len) + { + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + } + else + { + TEST_PTR_NE(NULL, str.ptr); + TEST_STR_EQ_(s, str.ptr); + TEST_INT_GE(str.len, str.capacity); + TEST_INT_GE(str.capacity, comstl::CoTaskMemGetSize(str.ptr)); + } cstring_destroy(&str); @@ -991,9 +1072,18 @@ static void TEST_cstring_createLenEx() cstring_createLenEx(&str, s, i, flags, NULL, 0); - TEST_INT_GE(i, str.len); - TEST_STR_EQ_(s, str.ptr); - TEST_INT_GE(str.len, str.capacity); + TEST_INT_EQ(i, str.len); + if (0u == i) + { + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + } + else + { + TEST_PTR_NE(NULL, str.ptr); + TEST_STR_EQ_(s, str.ptr); + TEST_INT_GE(str.len, str.capacity); + } cstring_destroy(&str); @@ -1055,10 +1145,19 @@ static void TEST_cstring_createLenEx() cstring_createLenEx(&str, s, i, flags, NULL, 0); - TEST_INT_GE(i, str.len); - TEST_STR_EQ_(s, str.ptr); - TEST_INT_GE(str.len, str.capacity); - TEST_INT_GE(str.capacity, ::GlobalSize(str.ptr)); + TEST_INT_EQ(i, str.len); + if (0u == i) + { + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + } + else + { + TEST_PTR_NE(NULL, str.ptr); + TEST_STR_EQ_(s, str.ptr); + TEST_INT_GE(str.len, str.capacity); + TEST_INT_GE(str.capacity, ::GlobalSize(str.ptr)); + } cstring_destroy(&str); @@ -1077,10 +1176,19 @@ static void TEST_cstring_createLenEx() cstring_createLenEx(&str, s, i, flags, NULL, 0); - TEST_INT_GE(i, str.len); - TEST_STR_EQ_(s, str.ptr); - TEST_INT_GE(str.len, str.capacity); - TEST_INT_GE(str.capacity, ::HeapSize(::GetProcessHeap(), 0, str.ptr)); + TEST_INT_EQ(i, str.len); + if (0u == i) + { + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + } + else + { + TEST_PTR_NE(NULL, str.ptr); + TEST_STR_EQ_(s, str.ptr); + TEST_INT_GE(str.len, str.capacity); + TEST_INT_GE(str.capacity, ::HeapSize(::GetProcessHeap(), 0, str.ptr)); + } cstring_destroy(&str); @@ -1099,10 +1207,19 @@ static void TEST_cstring_createLenEx() cstring_createLenEx(&str, s, i, flags, NULL, 0); - TEST_INT_GE(i, str.len); - TEST_STR_EQ_(s, str.ptr); - TEST_INT_GE(str.len, str.capacity); - TEST_INT_GE(str.capacity, comstl::CoTaskMemGetSize(str.ptr)); + TEST_INT_EQ(i, str.len); + if (0u == i) + { + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + } + else + { + TEST_PTR_NE(NULL, str.ptr); + TEST_STR_EQ_(s, str.ptr); + TEST_INT_GE(str.len, str.capacity); + TEST_INT_GE(str.capacity, comstl::CoTaskMemGetSize(str.ptr)); + } cstring_destroy(&str); diff --git a/test/unit/cstring/entry.c b/test/unit/cstring/entry.c index 5c41fea..290dcba 100644 --- a/test/unit/cstring/entry.c +++ b/test/unit/cstring/entry.c @@ -256,10 +256,9 @@ static void TEST_cstring_assign_AND_cstring_create_AND_cstring_createLen_NULL_AN else { TEST_INT_EQ(0u, str.len); - TEST_PTR_NE(NULL, str.ptr); - TEST_STR_EQ_(CSTRING_T_(""), str.ptr); - TEST_INT_GT(0u, str.capacity); - TEST_INT_GE(str.len, str.capacity); + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + TEST_INT_EQ(0, str.flags); cstring_destroy(&str); @@ -281,10 +280,9 @@ static void TEST_cstring_assign_AND_cstring_create_AND_cstring_createLen_NULL_AN else { TEST_INT_EQ(0u, str.len); - TEST_PTR_NE(NULL, str.ptr); - TEST_STR_EQ_(CSTRING_T_(""), str.ptr); - TEST_INT_GT(0u, str.capacity); - TEST_INT_GE(str.len, str.capacity); + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + TEST_INT_EQ(0, str.flags); cstring_destroy(&str); @@ -306,10 +304,9 @@ static void TEST_cstring_assign_AND_cstring_create_AND_cstring_createLen_NULL_AN else { TEST_INT_EQ(0u, str.len); - TEST_PTR_NE(NULL, str.ptr); - TEST_STR_EQ_(CSTRING_T_(""), str.ptr); - TEST_INT_GT(0u, str.capacity); - TEST_INT_GE(str.len, str.capacity); + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + TEST_INT_EQ(0, str.flags); cstring_destroy(&str); @@ -331,10 +328,9 @@ static void TEST_cstring_assign_AND_cstring_create_AND_cstring_createLen_NULL_AN else { TEST_INT_EQ(0u, str.len); - TEST_PTR_NE(NULL, str.ptr); - TEST_STR_EQ_(CSTRING_T_(""), str.ptr); - TEST_INT_GT(0u, str.capacity); - TEST_INT_GE(str.len, str.capacity); + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + TEST_INT_EQ(0, str.flags); cstring_destroy(&str); @@ -356,10 +352,9 @@ static void TEST_cstring_assign_AND_cstring_create_AND_cstring_createLen_NULL_AN else { TEST_INT_EQ(0u, str.len); - TEST_PTR_NE(NULL, str.ptr); - TEST_STR_EQ_(CSTRING_T_(""), str.ptr); - TEST_INT_GT(0u, str.capacity); - TEST_INT_GE(str.len, str.capacity); + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + TEST_INT_EQ(0, str.flags); cstring_destroy(&str); @@ -381,10 +376,9 @@ static void TEST_cstring_assign_AND_cstring_create_AND_cstring_createLen_NULL_AN else { TEST_INT_EQ(0u, str.len); - TEST_PTR_NE(NULL, str.ptr); - TEST_STR_EQ_(CSTRING_T_(""), str.ptr); - TEST_INT_GT(0u, str.capacity); - TEST_INT_GE(str.len, str.capacity); + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + TEST_INT_EQ(0, str.flags); cstring_destroy(&str); @@ -440,10 +434,12 @@ static void TEST_cstring_assign_AND_cstring_create_AND_cstring_createLen_NULL_AN TEST_PTR_NE(NULL, str.ptr); TEST_STR_EQ_(CSTRING_T_(""), str.ptr); TEST_CHAR_EQ('\0', str.ptr[0]); + /* TEST_CHAR_EQ('\0', str.ptr[1]); TEST_CHAR_EQ('\0', str.ptr[2]); TEST_CHAR_EQ('\0', str.ptr[3]); TEST_CHAR_EQ('\0', str.ptr[4]); + */ TEST_CHAR_EQ('\0', str.ptr[5]); TEST_INT_GE(5u, str.capacity); TEST_INT_GE(str.len, str.capacity); @@ -564,10 +560,18 @@ static void TEST_cstring_assignLen_AND_cstring_createLen(void) else { TEST_INT_EQ(cch, str.len); - TEST_PTR_NE(NULL, str.ptr); - TEST_STR_EQ_N_(s, str.ptr, (int)i); - TEST_INT_GE(cch, str.capacity); - TEST_INT_GE(str.len, str.capacity); + if (0u == cch) + { + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + } + else + { + TEST_PTR_NE(NULL, str.ptr); + TEST_STR_EQ_N_(s, str.ptr, (int)i); + TEST_INT_GE(cch, str.capacity); + TEST_INT_GE(str.len, str.capacity); + } cstring_destroy(&str); @@ -594,10 +598,18 @@ static void TEST_cstring_assignLen_AND_cstring_createLen(void) else { TEST_INT_EQ(cch, str.len); - TEST_PTR_NE(NULL, str.ptr); - TEST_STR_EQ_N_(s, str.ptr, (int)i); - TEST_INT_GE(cch, str.capacity); - TEST_INT_GE(str.len, str.capacity); + if (0u == cch) + { + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + } + else + { + TEST_PTR_NE(NULL, str.ptr); + TEST_STR_EQ_N_(s, str.ptr, (int)i); + TEST_INT_GE(cch, str.capacity); + TEST_INT_GE(str.len, str.capacity); + } } }} @@ -623,10 +635,18 @@ static void TEST_cstring_assignLen_AND_cstring_createLen(void) else { TEST_INT_EQ(cch, str.len); - TEST_PTR_NE(NULL, str.ptr); - TEST_STR_EQ_N_(s, str.ptr, (int)i); - TEST_INT_GE(cch, str.capacity); - TEST_INT_GE(str.len, str.capacity); + if (0u == cch) + { + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + } + else + { + TEST_PTR_NE(NULL, str.ptr); + TEST_STR_EQ_N_(s, str.ptr, (int)i); + TEST_INT_GE(cch, str.capacity); + TEST_INT_GE(str.len, str.capacity); + } cstring_destroy(&str); @@ -819,8 +839,17 @@ static void TEST_cstring_create(void) cstring_create(&str, s); TEST_INT_GE(i, str.len); - TEST_STR_EQ_(s, str.ptr); - TEST_INT_GE(str.len, str.capacity); + if (0u == i) + { + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + } + else + { + TEST_PTR_NE(NULL, str.ptr); + TEST_STR_EQ_(s, str.ptr); + TEST_INT_GE(str.len, str.capacity); + } cstring_destroy(&str); @@ -841,9 +870,18 @@ static void TEST_cstring_createLen(void) cstring_createLen(&str, s, i); - TEST_INT_GE(i, str.len); - TEST_STR_EQ_(s, str.ptr); - TEST_INT_GE(str.len, str.capacity); + TEST_INT_EQ(i, str.len); + if (0u == i) + { + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + } + else + { + TEST_PTR_NE(NULL, str.ptr); + TEST_STR_EQ_(s, str.ptr); + TEST_INT_GE(str.len, str.capacity); + } cstring_destroy(&str); @@ -866,8 +904,17 @@ static void TEST_cstring_createEx(void) cstring_createEx(&str, s, flags, NULL, 0); TEST_INT_GE(i, str.len); - TEST_STR_EQ_(s, str.ptr); - TEST_INT_GE(str.len, str.capacity); + if (0u == str.len) + { + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + } + else + { + TEST_PTR_NE(NULL, str.ptr); + TEST_STR_EQ_(s, str.ptr); + TEST_INT_GE(str.len, str.capacity); + } cstring_destroy(&str); @@ -930,9 +977,18 @@ static void TEST_cstring_createEx(void) cstring_createEx(&str, s, flags, NULL, 0); TEST_INT_GE(i, str.len); - TEST_STR_EQ_(s, str.ptr); - TEST_INT_GE(str.len, str.capacity); - TEST_INT_GE(str.capacity, GlobalSize(str.ptr)); + if (0u == str.len) + { + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + } + else + { + TEST_PTR_NE(NULL, str.ptr); + TEST_STR_EQ_(s, str.ptr); + TEST_INT_GE(str.len, str.capacity); + TEST_INT_GE(str.capacity, GlobalSize(str.ptr)); + } cstring_destroy(&str); @@ -952,9 +1008,18 @@ static void TEST_cstring_createEx(void) cstring_createEx(&str, s, flags, NULL, 0); TEST_INT_GE(i, str.len); - TEST_STR_EQ_(s, str.ptr); - TEST_INT_GE(str.len, str.capacity); - TEST_INT_GE(str.capacity, HeapSize(GetProcessHeap(), 0, str.ptr)); + if (0u == str.len) + { + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + } + else + { + TEST_PTR_NE(NULL, str.ptr); + TEST_STR_EQ_(s, str.ptr); + TEST_INT_GE(str.len, str.capacity); + TEST_INT_GE(str.capacity, HeapSize(GetProcessHeap(), 0, str.ptr)); + } cstring_destroy(&str); @@ -974,9 +1039,18 @@ static void TEST_cstring_createEx(void) cstring_createEx(&str, s, flags, NULL, 0); TEST_INT_GE(i, str.len); - TEST_STR_EQ_(s, str.ptr); - TEST_INT_GE(str.len, str.capacity); - TEST_INT_GE(str.capacity, comstl__CoTaskMemGetSize(str.ptr)); + if (0u == str.len) + { + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + } + else + { + TEST_PTR_NE(NULL, str.ptr); + TEST_STR_EQ_(s, str.ptr); + TEST_INT_GE(str.len, str.capacity); + TEST_INT_GE(str.capacity, comstl__CoTaskMemGetSize(str.ptr)); + } cstring_destroy(&str); @@ -999,9 +1073,18 @@ static void TEST_cstring_createLenEx(void) cstring_createLenEx(&str, s, i, flags, NULL, 0); - TEST_INT_GE(i, str.len); - TEST_STR_EQ_(s, str.ptr); - TEST_INT_GE(str.len, str.capacity); + TEST_INT_EQ(i, str.len); + if (0u == i) + { + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + } + else + { + TEST_PTR_NE(NULL, str.ptr); + TEST_STR_EQ_(s, str.ptr); + TEST_INT_GE(str.len, str.capacity); + } cstring_destroy(&str); @@ -1063,10 +1146,19 @@ static void TEST_cstring_createLenEx(void) cstring_createLenEx(&str, s, i, flags, NULL, 0); - TEST_INT_GE(i, str.len); - TEST_STR_EQ_(s, str.ptr); - TEST_INT_GE(str.len, str.capacity); - TEST_INT_GE(str.capacity, GlobalSize(str.ptr)); + TEST_INT_EQ(i, str.len); + if (0u == i) + { + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + } + else + { + TEST_PTR_NE(NULL, str.ptr); + TEST_STR_EQ_(s, str.ptr); + TEST_INT_GE(str.len, str.capacity); + TEST_INT_GE(str.capacity, GlobalSize(str.ptr)); + } cstring_destroy(&str); @@ -1085,10 +1177,19 @@ static void TEST_cstring_createLenEx(void) cstring_createLenEx(&str, s, i, flags, NULL, 0); - TEST_INT_GE(i, str.len); - TEST_STR_EQ_(s, str.ptr); - TEST_INT_GE(str.len, str.capacity); - TEST_INT_GE(str.capacity, HeapSize(GetProcessHeap(), 0, str.ptr)); + TEST_INT_EQ(i, str.len); + if (0u == i) + { + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + } + else + { + TEST_PTR_NE(NULL, str.ptr); + TEST_STR_EQ_(s, str.ptr); + TEST_INT_GE(str.len, str.capacity); + TEST_INT_GE(str.capacity, HeapSize(GetProcessHeap(), 0, str.ptr)); + } cstring_destroy(&str); @@ -1107,10 +1208,19 @@ static void TEST_cstring_createLenEx(void) cstring_createLenEx(&str, s, i, flags, NULL, 0); - TEST_INT_GE(i, str.len); - TEST_STR_EQ_(s, str.ptr); - TEST_INT_GE(str.len, str.capacity); - TEST_INT_GE(str.capacity, comstl__CoTaskMemGetSize(str.ptr)); + TEST_INT_EQ(i, str.len); + if (0u == i) + { + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + } + else + { + TEST_PTR_NE(NULL, str.ptr); + TEST_STR_EQ_(s, str.ptr); + TEST_INT_GE(str.len, str.capacity); + TEST_INT_GE(str.capacity, comstl__CoTaskMemGetSize(str.ptr)); + } cstring_destroy(&str); diff --git a/test/unit/insert-replace/entry.c b/test/unit/insert-replace/entry.c index c752baf..9b7a67e 100644 --- a/test/unit/insert-replace/entry.c +++ b/test/unit/insert-replace/entry.c @@ -136,18 +136,26 @@ static void TEST_cstring_createN(void) if (CSTRING_RC_SUCCESS == rc) { TEST_INT_EQ((size_t)i, str.len); - TEST_PTR_NE(NULL, str.ptr); - TEST_INT_GE(str.len, str.capacity); + if (0u == i) + { + TEST_PTR_EQ(NULL, str.ptr); + TEST_INT_EQ(0u, str.capacity); + } + else + { + TEST_PTR_NE(NULL, str.ptr); + TEST_INT_GE(str.len, str.capacity); #ifdef XTESTS_HAS_SHWILD - /* created string must be entirely '~' */ - TEST_MS_DOES_NOT_MATCH("*[a-zA-Z0-9]*", str.ptr); - TEST_MS_DOES_NOT_MATCH("*[ ,.<>/?'\";:[{]}`!@#$%^&*()=_+\\\\|-]*", str.ptr); + /* created string must be entirely '~' */ + TEST_MS_DOES_NOT_MATCH("*[a-zA-Z0-9]*", str.ptr); + TEST_MS_DOES_NOT_MATCH("*[ ,.<>/?'\";:[{]}`!@#$%^&*()=_+\\\\|-]*", str.ptr); #else /* ? XTESTS_HAS_SHWILD */ - TEST_PTR_EQ(NULL, strpbrk(str.ptr, "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890,<.>/?'\";:[{]}`!@#$%^&*()-_=+\\|")); + TEST_PTR_EQ(NULL, strpbrk(str.ptr, "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890,<.>/?'\";:[{]}`!@#$%^&*()-_=+\\|")); #endif /* XTESTS_HAS_SHWILD */ + } cstring_destroy(&str);