diff --git a/.travis.yml b/.travis.yml index 7d6b654..3a74055 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,3 +14,5 @@ script: - export CC=gcc-7 - cd ./tests - make +after_success: + - bash <(curl -s https://codecov.io/bash) diff --git a/CHANGELOG b/CHANGELOG index 8b18076..c6ea673 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,10 +1,18 @@ # MAJOR.MINOR.ADJUSTMENTS +1.5.2 + Added utl/test.h + Added utl/assert.h + Added tests/list.c - UnitTest for LIST + Small fixes on utl/foreach.h, utl/test.h and redone utl/timer.h + Removed utl/log.h functions that were unnecessary + Added the CMC namespace to CONCATC and CONCATH at macro_collections.h + 1.5.1 New queue benchmark Added sac/queue.h Added utl/timer.h - Fixing descriptions other minor fixes + Fixing descriptions and other minor fixes 1.5.0 Changed tests compilation and execution to a single Makefile diff --git a/benchmarks/benchmark.c b/benchmarks/benchmark.c index c5dc53a..1f81ec9 100644 --- a/benchmarks/benchmark.c +++ b/benchmarks/benchmark.c @@ -13,7 +13,6 @@ * - Output */ #include "macro_collections.h" -#include "utl/timer.h" #include "util/twister.c" #include #include @@ -82,17 +81,17 @@ COLLECTION_GENERATE(HASHMAP, hm, hmap, /* FMOD */, int, int) \ sname *coll = initfunc; \ \ - TIMER_START(total) \ - TIMER_START(timer) \ + timer_start(total); \ + timer_start(timer); \ \ for (size_t i = 0; i < NTOTAL; i++) \ { \ insertbody; \ } \ \ - TIMER_STOP(timer) \ + timer_stop(timer); \ \ - TIMER_CALC(timer) \ + timer_calc(timer); \ \ size_t s1 = PFX##_count(coll); \ \ @@ -100,16 +99,16 @@ COLLECTION_GENERATE(HASHMAP, hm, hmap, /* FMOD */, int, int) \ double input_time = timer.result; \ \ - TIMER_START(timer) \ + timer_start(timer); \ \ for (size_t i = 0; i < s; i++) \ { \ searchbody; \ } \ \ - TIMER_STOP(timer) \ + timer_stop(timer); \ \ - TIMER_CALC(timer) \ + timer_calc(timer); \ \ printf(" SEARCH %10s TOOK %8.0lf milliseconds for %8" PRIuMAX " elements\n", #NAME, timer.result, s); \ \ @@ -117,30 +116,30 @@ COLLECTION_GENERATE(HASHMAP, hm, hmap, /* FMOD */, int, int) \ sname##_iter iter; \ \ - TIMER_START(timer) \ + timer_start(timer); \ \ for (PFX##_iter_init(&iter, coll); !PFX##_iter_end(&iter); PFX##_iter_next(&iter)) \ { \ } \ \ - TIMER_STOP(timer) \ + timer_stop(timer); \ \ - TIMER_CALC(timer) \ + timer_calc(timer); \ \ printf("ITERATION %10s TOOK %8.0lf milliseconds for %8" PRIuMAX " elements\n", #NAME, timer.result, s1); \ \ double iter_time = timer.result; \ \ - TIMER_START(timer); \ + timer_start(timer); \ \ for (size_t i = 0; i < NTOTAL; i++) \ { \ removebody; \ } \ \ - TIMER_STOP(timer) \ + timer_stop(timer); \ \ - TIMER_CALC(timer) \ + timer_calc(timer); \ \ size_t s2 = PFX##_count(coll); \ \ @@ -148,8 +147,8 @@ COLLECTION_GENERATE(HASHMAP, hm, hmap, /* FMOD */, int, int) \ double output_time = timer.result; \ \ - TIMER_STOP(total) \ - TIMER_CALC(total) \ + timer_stop(total); \ + timer_calc(total); \ \ PFX##_free(coll); \ \ diff --git a/examples/hashmap/foreach.c b/examples/hashmap/foreach.c index 4692905..fde60ec 100644 --- a/examples/hashmap/foreach.c +++ b/examples/hashmap/foreach.c @@ -57,7 +57,7 @@ int main(void) // Inside, the variable 'iter' will be available and from it you can access // the key, value or index. printf("MAP[%4d] = %.3lf\n", hm_iter_key(&iter), hm_iter_value(&iter)); - }) + }); hm_free(map); diff --git a/examples/others/book_store/main.c b/examples/others/book_store/main.c index 38339e5..e9653bd 100644 --- a/examples/others/book_store/main.c +++ b/examples/others/book_store/main.c @@ -61,7 +61,7 @@ int main(int argc, char const *argv[]) map_insert(library, value->isbn, value->name); set_insert(counter, value->name); - }) + }); printf("Library Size: %d\n", map_count(library)); printf("Unique book titles: %d\n\n", set_count(counter)); @@ -69,7 +69,7 @@ int main(int argc, char const *argv[]) FOR_EACH(q, queue, shelf, { book *value = q_iter_value(&iter); printf("[ %d : %-45s ]\n", value->isbn, value->name); - }) + }); printf("\n"); set_free(counter); @@ -122,11 +122,11 @@ int main(int argc, char const *argv[]) if (chrcmp(buffer, value) == 0) il_push_back(search_list, key); - }) + }); FOR_EACH(il, intlist, search_list, { printf("[ %d ]\n", il_iter_value(&iter)); - }) + }); il_free(search_list); } @@ -140,7 +140,7 @@ int main(int argc, char const *argv[]) free(b->name); free(b); - }) + }); l_free(books); q_free(shelf); diff --git a/examples/others/for_each.c b/examples/others/for_each.c index d199a4c..23c43f1 100644 --- a/examples/others/for_each.c +++ b/examples/others/for_each.c @@ -67,7 +67,7 @@ int main(int argc, char const *argv[]) printf("%d ]\n", value); else printf("%d, ", value); - }) + }); FOR_EACH(s, stack, s, { int value = s_iter_value(&iter); @@ -78,7 +78,7 @@ int main(int argc, char const *argv[]) printf("%d ]\n", value); else printf("%d, ", value); - }) + }); FOR_EACH(q, queue, q, { int value = q_iter_value(&iter); @@ -89,7 +89,7 @@ int main(int argc, char const *argv[]) printf("%d ]\n", value); else printf("%d, ", value); - }) + }); FOR_EACH(d, deque, d, { int value = d_iter_value(&iter); @@ -100,7 +100,7 @@ int main(int argc, char const *argv[]) printf("%d ]\n", value); else printf("%d, ", value); - }) + }); FOR_EACH(ll, llist, ll, { int value = ll_iter_value(&iter); @@ -111,7 +111,7 @@ int main(int argc, char const *argv[]) printf("%d ]\n", value); else printf("%d, ", value); - }) + }); FOR_EACH(ts, tset, ts, { int value = ts_iter_value(&iter); @@ -122,7 +122,7 @@ int main(int argc, char const *argv[]) printf("%d ]\n", value); else printf("%d, ", value); - }) + }); l_free(l); ll_free(ll); diff --git a/examples/others/separate_header_source/main.c b/examples/others/separate_header_source/main.c index 53ffc58..a877c76 100644 --- a/examples/others/separate_header_source/main.c +++ b/examples/others/separate_header_source/main.c @@ -186,7 +186,7 @@ int main(void) int sum = 0; FOR_EACH(il, int_list, integers, { sum += il_iter_value(&iter); - }) + }); printf("\n\nSUM: %d\n", sum); @@ -256,7 +256,7 @@ int main(void) FOR_EACH(dq, deque, d, { sum3 += dq_iter_value(&iter); - }) + }); printf("Deque sum: %d\n", sum3); diff --git a/src/macro_collections.h b/src/macro_collections.h index 3cfb625..f4164d6 100644 --- a/src/macro_collections.h +++ b/src/macro_collections.h @@ -11,22 +11,22 @@ #ifndef CMC_MACRO_COLLECTIONS #define CMC_MACRO_COLLECTIONS -#define CONCATH_(C) C##_WRAPGEN_HEADER -#define CONCATC_(C) C##_WRAPGEN_SOURCE +#define CMC_CONCATH_(C) C##_WRAPGEN_HEADER +#define CMC_CONCATC_(C) C##_WRAPGEN_SOURCE -#define CONCATH(C) CONCATH_(C) -#define CONCATC(C) CONCATC_(C) +#define CMC_CONCATH(C) CMC_CONCATH_(C) +#define CMC_CONCATC(C) CMC_CONCATC_(C) #define COLLECTION_GENERATE(C, PFX, SNAME, FMOD, K, V) \ COLLECTION_GENERATE_HEADER(C, PFX, SNAME, FMOD, K, V) \ COLLECTION_GENERATE_SOURCE(C, PFX, SNAME, FMOD, K, V) #define COLLECTION_GENERATE_HEADER(C, PFX, SNAME, FMOD, K, V) \ - CONCATH(C) \ + CMC_CONCATH(C) \ (PFX, SNAME, FMOD, K, V) #define COLLECTION_GENERATE_SOURCE(C, PFX, SNAME, FMOD, K, V) \ - CONCATC(C) \ + CMC_CONCATC(C) \ (PFX, SNAME, FMOD, K, V) #include "cmc/deque.h" @@ -45,6 +45,7 @@ #include "sac/queue.h" #include "sac/stack.h" +#include "utl/assert.h" #include "utl/foreach.h" #include "utl/log.h" #include "utl/test.h" diff --git a/src/utl/assert.h b/src/utl/assert.h index b0b3afa..0c84840 100644 --- a/src/utl/assert.h +++ b/src/utl/assert.h @@ -9,8 +9,11 @@ */ /** - * Definition of many typed non-abortive assertions. There are 4 main macros: + * Definition of many typed non-abortive assertions. Every assertion that fails + * will print a message to stdint but will not abort the program execution. + * There are 4 main macros: * + * - cmc_assert * - cmc_assert_equals * - cmc_assert_not_equals * - cmc_assert_in_range @@ -45,6 +48,20 @@ #define CMC_ASSERT_GLUE_(dtype, assertion) cmc_assert_##assertion##_##dtype #define CMC_ASSERT_GLUE(dtype, assertion) CMC_ASSERT_GLUE_(dtype, assertion) +/** + * expression : An expression that is expected to be evaluated to true. + */ +#define cmc_assert(expression) \ + do \ + { \ + const char *str = #expression; \ + if (!(expression)) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }\n", \ + __FILE__, __func__, __LINE__, str); \ + } \ + } while (0) + /** * dtype : One of the data types listed at the beggining of this file. * expected : Expected value for the assertion to pass. @@ -87,840 +104,840 @@ CMC_ASSERT_GLUE(dtype, not_in_range) \ (lower_bound, upper_bound, actual) -#define cmc_assert_equals_int8_t(expected, actual) \ - do \ - { \ - const char *str = #actual; \ - int8_t expected_ = expected; \ - int8_t actual_ = actual; \ - \ - if (expected_ != actual_) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Expected: %" PRId8 " Actual: %" PRId8 "\n", \ - __FILE__, __func__, __LINE__, str, expected_, actual_); \ - } \ - \ +#define cmc_assert_equals_int8_t(expected, actual) \ + do \ + { \ + const char *str = #actual; \ + int8_t expected_ = expected; \ + int8_t actual_ = actual; \ + \ + if (expected_ != actual_) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Expected: %" PRId8 " Actual: %" PRId8 "\n", \ + __FILE__, __func__, __LINE__, str, expected_, actual_); \ + } \ + \ } while (0) -#define cmc_assert_equals_int16_t(expected, actual) \ - do \ - { \ - const char *str = #actual; \ - int16_t expected_ = expected; \ - int16_t actual_ = actual; \ - \ - if (expected_ != actual_) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Expected: %" PRId16 " Actual: %" PRId16 "\n", \ - __FILE__, __func__, __LINE__, str, expected_, actual_); \ - } \ - \ +#define cmc_assert_equals_int16_t(expected, actual) \ + do \ + { \ + const char *str = #actual; \ + int16_t expected_ = expected; \ + int16_t actual_ = actual; \ + \ + if (expected_ != actual_) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Expected: %" PRId16 " Actual: %" PRId16 "\n", \ + __FILE__, __func__, __LINE__, str, expected_, actual_); \ + } \ + \ } while (0) -#define cmc_assert_equals_int32_t(expected, actual) \ - do \ - { \ - const char *str = #actual; \ - int32_t expected_ = expected; \ - int32_t actual_ = actual; \ - \ - if (expected_ != actual_) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Expected: %" PRId32 " Actual: %" PRId32 "\n", \ - __FILE__, __func__, __LINE__, str, expected_, actual_); \ - } \ - \ +#define cmc_assert_equals_int32_t(expected, actual) \ + do \ + { \ + const char *str = #actual; \ + int32_t expected_ = expected; \ + int32_t actual_ = actual; \ + \ + if (expected_ != actual_) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Expected: %" PRId32 " Actual: %" PRId32 "\n", \ + __FILE__, __func__, __LINE__, str, expected_, actual_); \ + } \ + \ } while (0) -#define cmc_assert_equals_int64_t(expected, actual) \ - do \ - { \ - const char *str = #actual; \ - int64_t expected_ = expected; \ - int64_t actual_ = actual; \ - \ - if (expected_ != actual_) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Expected: %" PRId64 " Actual: %" PRId64 "\n", \ - __FILE__, __func__, __LINE__, str, expected_, actual_); \ - } \ - \ +#define cmc_assert_equals_int64_t(expected, actual) \ + do \ + { \ + const char *str = #actual; \ + int64_t expected_ = expected; \ + int64_t actual_ = actual; \ + \ + if (expected_ != actual_) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Expected: %" PRId64 " Actual: %" PRId64 "\n", \ + __FILE__, __func__, __LINE__, str, expected_, actual_); \ + } \ + \ } while (0) -#define cmc_assert_equals_uint8_t(expected, actual) \ - do \ - { \ - const char *str = #actual; \ - uint8_t expected_ = expected; \ - uint8_t actual_ = actual; \ - \ - if (expected_ != actual_) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Expected: %" PRIu8 " Actual: %" PRIu8 "\n", \ - __FILE__, __func__, __LINE__, str, expected_, actual_); \ - } \ - \ +#define cmc_assert_equals_uint8_t(expected, actual) \ + do \ + { \ + const char *str = #actual; \ + uint8_t expected_ = expected; \ + uint8_t actual_ = actual; \ + \ + if (expected_ != actual_) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Expected: %" PRIu8 " Actual: %" PRIu8 "\n", \ + __FILE__, __func__, __LINE__, str, expected_, actual_); \ + } \ + \ } while (0) -#define cmc_assert_equals_uint16_t(expected, actual) \ - do \ - { \ - const char *str = #actual; \ - uint16_t expected_ = expected; \ - uint16_t actual_ = actual; \ - \ - if (expected_ != actual_) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Expected: %" PRIu16 " Actual: %" PRIu16 "\n", \ - __FILE__, __func__, __LINE__, str, expected_, actual_); \ - } \ - \ +#define cmc_assert_equals_uint16_t(expected, actual) \ + do \ + { \ + const char *str = #actual; \ + uint16_t expected_ = expected; \ + uint16_t actual_ = actual; \ + \ + if (expected_ != actual_) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Expected: %" PRIu16 " Actual: %" PRIu16 "\n", \ + __FILE__, __func__, __LINE__, str, expected_, actual_); \ + } \ + \ } while (0) -#define cmc_assert_equals_uint32_t(expected, actual) \ - do \ - { \ - const char *str = #actual; \ - uint32_t expected_ = expected; \ - uint32_t actual_ = actual; \ - \ - if (expected_ != actual_) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Expected: %" PRIu32 " Actual: %" PRIu32 "\n", \ - __FILE__, __func__, __LINE__, str, expected_, actual_); \ - } \ - \ +#define cmc_assert_equals_uint32_t(expected, actual) \ + do \ + { \ + const char *str = #actual; \ + uint32_t expected_ = expected; \ + uint32_t actual_ = actual; \ + \ + if (expected_ != actual_) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Expected: %" PRIu32 " Actual: %" PRIu32 "\n", \ + __FILE__, __func__, __LINE__, str, expected_, actual_); \ + } \ + \ } while (0) -#define cmc_assert_equals_uint64_t(expected, actual) \ - do \ - { \ - const char *str = #actual; \ - uint64_t expected_ = expected; \ - uint64_t actual_ = actual; \ - \ - if (expected_ != actual_) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Expected: %" PRIu64 " Actual: %" PRIu64 "\n", \ - __FILE__, __func__, __LINE__, str, expected_, actual_); \ - } \ - \ +#define cmc_assert_equals_uint64_t(expected, actual) \ + do \ + { \ + const char *str = #actual; \ + uint64_t expected_ = expected; \ + uint64_t actual_ = actual; \ + \ + if (expected_ != actual_) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Expected: %" PRIu64 " Actual: %" PRIu64 "\n", \ + __FILE__, __func__, __LINE__, str, expected_, actual_); \ + } \ + \ } while (0) -#define cmc_assert_equals_intmax_t(expected, actual) \ - do \ - { \ - const char *str = #actual; \ - intmax_t expected_ = expected; \ - intmax_t actual_ = actual; \ - \ - if (expected_ != actual_) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Expected: %" PRIdMAX " Actual: %" PRIdMAX "\n", \ - __FILE__, __func__, __LINE__, str, expected_, actual_); \ - } \ - \ +#define cmc_assert_equals_intmax_t(expected, actual) \ + do \ + { \ + const char *str = #actual; \ + intmax_t expected_ = expected; \ + intmax_t actual_ = actual; \ + \ + if (expected_ != actual_) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Expected: %" PRIdMAX " Actual: %" PRIdMAX "\n", \ + __FILE__, __func__, __LINE__, str, expected_, actual_); \ + } \ + \ } while (0) -#define cmc_assert_equals_uintmax_t(expected, actual) \ - do \ - { \ - const char *str = #actual; \ - uintmax_t expected_ = expected; \ - uintmax_t actual_ = actual; \ - \ - if (expected_ != actual_) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Expected: %" PRIuMAX " Actual: %" PRIuMAX "\n", \ - __FILE__, __func__, __LINE__, str, expected_, actual_); \ - } \ - \ +#define cmc_assert_equals_uintmax_t(expected, actual) \ + do \ + { \ + const char *str = #actual; \ + uintmax_t expected_ = expected; \ + uintmax_t actual_ = actual; \ + \ + if (expected_ != actual_) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Expected: %" PRIuMAX " Actual: %" PRIuMAX "\n", \ + __FILE__, __func__, __LINE__, str, expected_, actual_); \ + } \ + \ } while (0) -#define cmc_assert_equals_size_t(expected, actual) \ - do \ - { \ - const char *str = #actual; \ - size_t expected_ = expected; \ - size_t actual_ = actual; \ - \ - if (expected_ != actual_) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Expected: %" PRIuMAX " Actual: %" PRIuMAX "\n", \ - __FILE__, __func__, __LINE__, str, expected_, actual_); \ - } \ - \ +#define cmc_assert_equals_size_t(expected, actual) \ + do \ + { \ + const char *str = #actual; \ + size_t expected_ = expected; \ + size_t actual_ = actual; \ + \ + if (expected_ != actual_) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Expected: %" PRIuMAX " Actual: %" PRIuMAX "\n", \ + __FILE__, __func__, __LINE__, str, expected_, actual_); \ + } \ + \ } while (0) -#define cmc_assert_equals_float(expected, actual) \ - do \ - { \ - const char *str = #actual; \ - float expected_ = expected; \ - float actual_ = actual; \ - \ - if (expected_ != actual_) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Expected: %f Actual: %f\n", \ - __FILE__, __func__, __LINE__, str, expected_, actual_); \ - } \ - \ +#define cmc_assert_equals_float(expected, actual) \ + do \ + { \ + const char *str = #actual; \ + float expected_ = expected; \ + float actual_ = actual; \ + \ + if (expected_ != actual_) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Expected: %f Actual: %f\n", \ + __FILE__, __func__, __LINE__, str, expected_, actual_); \ + } \ + \ } while (0) -#define cmc_assert_equals_double(expected, actual) \ - do \ - { \ - const char *str = #actual; \ - double expected_ = expected; \ - double actual_ = actual; \ - \ - if (expected_ != actual_) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Expected: %lf Actual: %lf\n", \ - __FILE__, __func__, __LINE__, str, expected_, actual_); \ - } \ - \ +#define cmc_assert_equals_double(expected, actual) \ + do \ + { \ + const char *str = #actual; \ + double expected_ = expected; \ + double actual_ = actual; \ + \ + if (expected_ != actual_) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Expected: %lf Actual: %lf\n", \ + __FILE__, __func__, __LINE__, str, expected_, actual_); \ + } \ + \ } while (0) -#define cmc_assert_equals_ptr(expected, actual) \ - do \ - { \ - const char *str = #actual; \ - void *expected_ = expected; \ - void *actual_ = actual; \ - \ - if (expected_ != actual_) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Expected: %p Actual: %p\n", \ - __FILE__, __func__, __LINE__, str, expected_, actual_); \ - } \ - \ +#define cmc_assert_equals_ptr(expected, actual) \ + do \ + { \ + const char *str = #actual; \ + void *expected_ = expected; \ + void *actual_ = actual; \ + \ + if (expected_ != actual_) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Expected: %p Actual: %p\n", \ + __FILE__, __func__, __LINE__, str, expected_, actual_); \ + } \ + \ } while (0) -#define cmc_assert_not_equals_int8_t(not_expected, actual) \ - do \ - { \ - const char *str = #actual; \ - int8_t not_expected_ = not_expected; \ - int8_t actual_ = actual; \ - \ - if (not_expected_ == actual_) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Not Expected: %" PRId8 " Actual: %" PRId8 "\n", \ - __FILE__, __func__, __LINE__, str, not_expected_, actual_); \ - } \ - \ +#define cmc_assert_not_equals_int8_t(not_expected, actual) \ + do \ + { \ + const char *str = #actual; \ + int8_t not_expected_ = not_expected; \ + int8_t actual_ = actual; \ + \ + if (not_expected_ == actual_) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Not Expected: %" PRId8 " Actual: %" PRId8 "\n", \ + __FILE__, __func__, __LINE__, str, not_expected_, actual_); \ + } \ + \ } while (0) -#define cmc_assert_not_equals_int16_t(not_expected, actual) \ - do \ - { \ - const char *str = #actual; \ - int16_t not_expected_ = not_expected; \ - int16_t actual_ = actual; \ - \ - if (not_expected_ == actual_) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Not Expected: %" PRId16 " Actual: %" PRId16 "\n", \ - __FILE__, __func__, __LINE__, str, not_expected_, actual_); \ - } \ - \ +#define cmc_assert_not_equals_int16_t(not_expected, actual) \ + do \ + { \ + const char *str = #actual; \ + int16_t not_expected_ = not_expected; \ + int16_t actual_ = actual; \ + \ + if (not_expected_ == actual_) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Not Expected: %" PRId16 " Actual: %" PRId16 "\n", \ + __FILE__, __func__, __LINE__, str, not_expected_, actual_); \ + } \ + \ } while (0) -#define cmc_assert_not_equals_int32_t(not_expected, actual) \ - do \ - { \ - const char *str = #actual; \ - int32_t not_expected_ = not_expected; \ - int32_t actual_ = actual; \ - \ - if (not_expected_ == actual_) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Not Expected: %" PRId32 " Actual: %" PRId32 "\n", \ - __FILE__, __func__, __LINE__, str, not_expected_, actual_); \ - } \ - \ +#define cmc_assert_not_equals_int32_t(not_expected, actual) \ + do \ + { \ + const char *str = #actual; \ + int32_t not_expected_ = not_expected; \ + int32_t actual_ = actual; \ + \ + if (not_expected_ == actual_) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Not Expected: %" PRId32 " Actual: %" PRId32 "\n", \ + __FILE__, __func__, __LINE__, str, not_expected_, actual_); \ + } \ + \ } while (0) -#define cmc_assert_not_equals_int64_t(not_expected, actual) \ - do \ - { \ - const char *str = #actual; \ - int64_t not_expected_ = not_expected; \ - int64_t actual_ = actual; \ - \ - if (not_expected_ == actual_) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Not Expected: %" PRId64 " Actual: %" PRId64 "\n", \ - __FILE__, __func__, __LINE__, str, not_expected_, actual_); \ - } \ - \ +#define cmc_assert_not_equals_int64_t(not_expected, actual) \ + do \ + { \ + const char *str = #actual; \ + int64_t not_expected_ = not_expected; \ + int64_t actual_ = actual; \ + \ + if (not_expected_ == actual_) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Not Expected: %" PRId64 " Actual: %" PRId64 "\n", \ + __FILE__, __func__, __LINE__, str, not_expected_, actual_); \ + } \ + \ } while (0) -#define cmc_assert_not_equals_uint8_t(not_expected, actual) \ - do \ - { \ - const char *str = #actual; \ - uint8_t not_expected_ = not_expected; \ - uint8_t actual_ = actual; \ - \ - if (not_expected_ == actual_) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Not Expected: %" PRIu8 " Actual: %" PRIu8 "\n", \ - __FILE__, __func__, __LINE__, str, not_expected_, actual_); \ - } \ - \ +#define cmc_assert_not_equals_uint8_t(not_expected, actual) \ + do \ + { \ + const char *str = #actual; \ + uint8_t not_expected_ = not_expected; \ + uint8_t actual_ = actual; \ + \ + if (not_expected_ == actual_) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Not Expected: %" PRIu8 " Actual: %" PRIu8 "\n", \ + __FILE__, __func__, __LINE__, str, not_expected_, actual_); \ + } \ + \ } while (0) -#define cmc_assert_not_equals_uint16_t(not_expected, actual) \ - do \ - { \ - const char *str = #actual; \ - uint16_t not_expected_ = not_expected; \ - uint16_t actual_ = actual; \ - \ - if (not_expected_ == actual_) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Not Expected: %" PRIu16 " Actual: %" PRIu16 "\n", \ - __FILE__, __func__, __LINE__, str, not_expected_, actual_); \ - } \ - \ +#define cmc_assert_not_equals_uint16_t(not_expected, actual) \ + do \ + { \ + const char *str = #actual; \ + uint16_t not_expected_ = not_expected; \ + uint16_t actual_ = actual; \ + \ + if (not_expected_ == actual_) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Not Expected: %" PRIu16 " Actual: %" PRIu16 "\n", \ + __FILE__, __func__, __LINE__, str, not_expected_, actual_); \ + } \ + \ } while (0) -#define cmc_assert_not_equals_uint32_t(not_expected, actual) \ - do \ - { \ - const char *str = #actual; \ - uint32_t not_expected_ = not_expected; \ - uint32_t actual_ = actual; \ - \ - if (not_expected_ == actual_) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Not Expected: %" PRIu32 " Actual: %" PRIu32 "\n", \ - __FILE__, __func__, __LINE__, str, not_expected_, actual_); \ - } \ - \ +#define cmc_assert_not_equals_uint32_t(not_expected, actual) \ + do \ + { \ + const char *str = #actual; \ + uint32_t not_expected_ = not_expected; \ + uint32_t actual_ = actual; \ + \ + if (not_expected_ == actual_) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Not Expected: %" PRIu32 " Actual: %" PRIu32 "\n", \ + __FILE__, __func__, __LINE__, str, not_expected_, actual_); \ + } \ + \ } while (0) -#define cmc_assert_not_equals_uint64_t(not_expected, actual) \ - do \ - { \ - const char *str = #actual; \ - uint64_t not_expected_ = not_expected; \ - uint64_t actual_ = actual; \ - \ - if (not_expected_ == actual_) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Not Expected: %" PRIu64 " Actual: %" PRIu64 "\n", \ - __FILE__, __func__, __LINE__, str, not_expected_, actual_); \ - } \ - \ +#define cmc_assert_not_equals_uint64_t(not_expected, actual) \ + do \ + { \ + const char *str = #actual; \ + uint64_t not_expected_ = not_expected; \ + uint64_t actual_ = actual; \ + \ + if (not_expected_ == actual_) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Not Expected: %" PRIu64 " Actual: %" PRIu64 "\n", \ + __FILE__, __func__, __LINE__, str, not_expected_, actual_); \ + } \ + \ } while (0) -#define cmc_assert_not_equals_intmax_t(not_expected, actual) \ - do \ - { \ - const char *str = #actual; \ - intmax_t not_expected_ = not_expected; \ - intmax_t actual_ = actual; \ - \ - if (not_expected_ == actual_) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Not Expected: %" PRIdMAX " Actual: %" PRIdMAX "\n", \ - __FILE__, __func__, __LINE__, str, not_expected_, actual_); \ - } \ - \ +#define cmc_assert_not_equals_intmax_t(not_expected, actual) \ + do \ + { \ + const char *str = #actual; \ + intmax_t not_expected_ = not_expected; \ + intmax_t actual_ = actual; \ + \ + if (not_expected_ == actual_) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Not Expected: %" PRIdMAX " Actual: %" PRIdMAX "\n", \ + __FILE__, __func__, __LINE__, str, not_expected_, actual_); \ + } \ + \ } while (0) -#define cmc_assert_not_equals_uintmax_t(not_expected, actual) \ - do \ - { \ - const char *str = #actual; \ - uintmax_t not_expected_ = not_expected; \ - uintmax_t actual_ = actual; \ - \ - if (not_expected_ == actual_) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Not Expected: %" PRIuMAX " Actual: %" PRIuMAX "\n", \ - __FILE__, __func__, __LINE__, str, not_expected_, actual_); \ - } \ - \ +#define cmc_assert_not_equals_uintmax_t(not_expected, actual) \ + do \ + { \ + const char *str = #actual; \ + uintmax_t not_expected_ = not_expected; \ + uintmax_t actual_ = actual; \ + \ + if (not_expected_ == actual_) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Not Expected: %" PRIuMAX " Actual: %" PRIuMAX "\n", \ + __FILE__, __func__, __LINE__, str, not_expected_, actual_); \ + } \ + \ } while (0) -#define cmc_assert_not_equals_size_t(not_expected, actual) \ - do \ - { \ - const char *str = #actual; \ - size_t not_expected_ = not_expected; \ - size_t actual_ = actual; \ - \ - if (not_expected_ == actual_) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Not Expected: %" PRIuMAX " Actual: %" PRIuMAX "\n", \ - __FILE__, __func__, __LINE__, str, not_expected_, actual_); \ - } \ - \ +#define cmc_assert_not_equals_size_t(not_expected, actual) \ + do \ + { \ + const char *str = #actual; \ + size_t not_expected_ = not_expected; \ + size_t actual_ = actual; \ + \ + if (not_expected_ == actual_) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Not Expected: %" PRIuMAX " Actual: %" PRIuMAX "\n", \ + __FILE__, __func__, __LINE__, str, not_expected_, actual_); \ + } \ + \ } while (0) -#define cmc_assert_not_equals_float(not_expected, actual) \ - do \ - { \ - const char *str = #actual; \ - float not_expected_ = not_expected; \ - float actual_ = actual; \ - \ - if (not_expected_ == actual_) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Not Expected: %f Actual: %f\n", \ - __FILE__, __func__, __LINE__, str, not_expected_, actual_); \ - } \ - \ +#define cmc_assert_not_equals_float(not_expected, actual) \ + do \ + { \ + const char *str = #actual; \ + float not_expected_ = not_expected; \ + float actual_ = actual; \ + \ + if (not_expected_ == actual_) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Not Expected: %f Actual: %f\n", \ + __FILE__, __func__, __LINE__, str, not_expected_, actual_); \ + } \ + \ } while (0) -#define cmc_assert_not_equals_double(not_expected, actual) \ - do \ - { \ - const char *str = #actual; \ - double not_expected_ = not_expected; \ - double actual_ = actual; \ - \ - if (not_expected_ == actual_) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Not Expected: %lf Actual: %lf\n", \ - __FILE__, __func__, __LINE__, str, not_expected_, actual_); \ - } \ - \ +#define cmc_assert_not_equals_double(not_expected, actual) \ + do \ + { \ + const char *str = #actual; \ + double not_expected_ = not_expected; \ + double actual_ = actual; \ + \ + if (not_expected_ == actual_) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Not Expected: %lf Actual: %lf\n", \ + __FILE__, __func__, __LINE__, str, not_expected_, actual_); \ + } \ + \ } while (0) -#define cmc_assert_not_equals_ptr(not_expected, actual) \ - do \ - { \ - const char *str = #actual; \ - void *not_expected_ = not_expected; \ - void *actual_ = actual; \ - \ - if (not_expected_ == actual_) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Not Expected: %p Actual: %p\n", \ - __FILE__, __func__, __LINE__, str, not_expected_, actual_); \ - } \ - \ +#define cmc_assert_not_equals_ptr(not_expected, actual) \ + do \ + { \ + const char *str = #actual; \ + void *not_expected_ = not_expected; \ + void *actual_ = actual; \ + \ + if (not_expected_ == actual_) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Not Expected: %p Actual: %p\n", \ + __FILE__, __func__, __LINE__, str, not_expected_, actual_); \ + } \ + \ } while (0) -#define cmc_assert_in_range_int8_t(lower_bound, upper_bound, actual) \ - do \ - { \ - const char *str = #actual; \ - int8_t lower_bound_ = lower_bound; \ - int8_t upper_bound_ = upper_bound; \ - int8_t actual_ = actual; \ - \ - if (actual < lower_bound_ || actual > upper_bound_) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Expected Range: [%" PRId8 ", %" PRId8 "] Actual: %" PRId8 "\n", \ - __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ - } \ - \ - } while (0) - -#define cmc_assert_in_range_int16_t(lower_bound, upper_bound, actual) \ +#define cmc_assert_in_range_int8_t(lower_bound, upper_bound, actual) \ do \ { \ const char *str = #actual; \ - int16_t lower_bound_ = lower_bound; \ - int16_t upper_bound_ = upper_bound; \ - int16_t actual_ = actual; \ + int8_t lower_bound_ = lower_bound; \ + int8_t upper_bound_ = upper_bound; \ + int8_t actual_ = actual; \ \ if (actual < lower_bound_ || actual > upper_bound_) \ { \ - printf("%s:%s:%u Assertion Failed for { %s }: Expected Range: [%" PRId16 ", %" PRId16 "] Actual: %" PRId16 "\n", \ + printf("Assertion Failed at %s:%s:%u for { %s }: Expected Range: [%" PRId8 ", %" PRId8 "] Actual: %" PRId8 "\n", \ __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ } \ \ } while (0) -#define cmc_assert_in_range_int32_t(lower_bound, upper_bound, actual) \ - do \ - { \ - const char *str = #actual; \ - int32_t lower_bound_ = lower_bound; \ - int32_t upper_bound_ = upper_bound; \ - int32_t actual_ = actual; \ - \ - if (actual < lower_bound_ || actual > upper_bound_) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Expected Range: [%" PRId32 ", %" PRId32 "] Actual: %" PRId32 "\n", \ - __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ - } \ - \ - } while (0) - -#define cmc_assert_in_range_int64_t(lower_bound, upper_bound, actual) \ - do \ - { \ - const char *str = #actual; \ - int64_t lower_bound_ = lower_bound; \ - int64_t upper_bound_ = upper_bound; \ - int64_t actual_ = actual; \ - \ - if (actual < lower_bound_ || actual > upper_bound_) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Expected Range: [%" PRId32 ", %" PRId32 "] Actual: %" PRId32 "\n", \ - __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ - } \ - \ - } while (0) - -#define cmc_assert_in_range_uint8_t(lower_bound, upper_bound, actual) \ - do \ - { \ - const char *str = #actual; \ - uint8_t lower_bound_ = lower_bound; \ - uint8_t upper_bound_ = upper_bound; \ - uint8_t actual_ = actual; \ - \ - if (actual < lower_bound_ || actual > upper_bound_) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Expected Range: [%" PRIu8 ", %" PRIu8 "] Actual: %" PRIu8 "\n", \ - __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ - } \ - \ - } while (0) - -#define cmc_assert_in_range_uint16_t(lower_bound, upper_bound, actual) \ - do \ - { \ - const char *str = #actual; \ - uint16_t lower_bound_ = lower_bound; \ - uint16_t upper_bound_ = upper_bound; \ - uint16_t actual_ = actual; \ - \ - if (actual < lower_bound_ || actual > upper_bound_) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Expected Range: [%" PRIu16 ", %" PRIu16 "] Actual: %" PRIu16 "\n", \ - __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ - } \ - \ - } while (0) - -#define cmc_assert_in_range_uint32_t(lower_bound, upper_bound, actual) \ - do \ - { \ - const char *str = #actual; \ - uint32_t lower_bound_ = lower_bound; \ - uint32_t upper_bound_ = upper_bound; \ - uint32_t actual_ = actual; \ - \ - if (actual < lower_bound_ || actual > upper_bound_) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Expected Range: [%" PRIu32 ", %" PRIu32 "] Actual: %" PRIu32 "\n", \ - __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ - } \ - \ - } while (0) - -#define cmc_assert_in_range_uint64_t(lower_bound, upper_bound, actual) \ - do \ - { \ - const char *str = #actual; \ - uint64_t lower_bound_ = lower_bound; \ - uint64_t upper_bound_ = upper_bound; \ - uint64_t actual_ = actual; \ - \ - if (actual < lower_bound_ || actual > upper_bound_) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Expected Range: [%" PRIu64 ", %" PRIu64 "] Actual: %" PRIu64 "\n", \ - __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ - } \ - \ - } while (0) - -#define cmc_assert_in_range_intmax_t(lower_bound, upper_bound, actual) \ +#define cmc_assert_in_range_int16_t(lower_bound, upper_bound, actual) \ do \ { \ const char *str = #actual; \ - intmax_t lower_bound_ = lower_bound; \ - intmax_t upper_bound_ = upper_bound; \ - intmax_t actual_ = actual; \ + int16_t lower_bound_ = lower_bound; \ + int16_t upper_bound_ = upper_bound; \ + int16_t actual_ = actual; \ \ if (actual < lower_bound_ || actual > upper_bound_) \ { \ - printf("%s:%s:%u Assertion Failed for { %s }: Expected Range: [%" PRIdMAX ", %" PRIdMAX "] Actual: %" PRIdMAX "\n", \ + printf("Assertion Failed at %s:%s:%u for { %s }: Expected Range: [%" PRId16 ", %" PRId16 "] Actual: %" PRId16 "\n", \ __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ } \ \ } while (0) -#define cmc_assert_in_range_uintmax_t(lower_bound, upper_bound, actual) \ +#define cmc_assert_in_range_int32_t(lower_bound, upper_bound, actual) \ do \ { \ const char *str = #actual; \ - uintmax_t lower_bound_ = lower_bound; \ - uintmax_t upper_bound_ = upper_bound; \ - uintmax_t actual_ = actual; \ + int32_t lower_bound_ = lower_bound; \ + int32_t upper_bound_ = upper_bound; \ + int32_t actual_ = actual; \ \ if (actual < lower_bound_ || actual > upper_bound_) \ { \ - printf("%s:%s:%u Assertion Failed for { %s }: Expected Range: [%" PRIuMAX ", %" PRIuMAX "] Actual: %" PRIuMAX "\n", \ + printf("Assertion Failed at %s:%s:%u for { %s }: Expected Range: [%" PRId32 ", %" PRId32 "] Actual: %" PRId32 "\n", \ __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ } \ \ } while (0) -#define cmc_assert_in_range_size_t(lower_bound, upper_bound, actual) \ +#define cmc_assert_in_range_int64_t(lower_bound, upper_bound, actual) \ do \ { \ const char *str = #actual; \ - size_t lower_bound_ = lower_bound; \ - size_t upper_bound_ = upper_bound; \ - size_t actual_ = actual; \ + int64_t lower_bound_ = lower_bound; \ + int64_t upper_bound_ = upper_bound; \ + int64_t actual_ = actual; \ \ if (actual < lower_bound_ || actual > upper_bound_) \ { \ - printf("%s:%s:%u Assertion Failed for { %s }: Expected Range: [%" PRIuMAX ", %" PRIuMAX "] Actual: %" PRIuMAX "\n", \ + printf("Assertion Failed at %s:%s:%u for { %s }: Expected Range: [%" PRId32 ", %" PRId32 "] Actual: %" PRId32 "\n", \ __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ } \ \ } while (0) -#define cmc_assert_in_range_float(lower_bound, upper_bound, actual) \ - do \ - { \ - const char *str = #actual; \ - float lower_bound_ = lower_bound; \ - float upper_bound_ = upper_bound; \ - float actual_ = actual; \ - \ - if (actual < lower_bound_ || actual > upper_bound_) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Expected Range: [%f, %f] Actual: %f\n", \ - __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ - } \ - \ +#define cmc_assert_in_range_uint8_t(lower_bound, upper_bound, actual) \ + do \ + { \ + const char *str = #actual; \ + uint8_t lower_bound_ = lower_bound; \ + uint8_t upper_bound_ = upper_bound; \ + uint8_t actual_ = actual; \ + \ + if (actual < lower_bound_ || actual > upper_bound_) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Expected Range: [%" PRIu8 ", %" PRIu8 "] Actual: %" PRIu8 "\n", \ + __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ + } \ + \ } while (0) -#define cmc_assert_in_range_double(lower_bound, upper_bound, actual) \ +#define cmc_assert_in_range_uint16_t(lower_bound, upper_bound, actual) \ + do \ + { \ + const char *str = #actual; \ + uint16_t lower_bound_ = lower_bound; \ + uint16_t upper_bound_ = upper_bound; \ + uint16_t actual_ = actual; \ + \ + if (actual < lower_bound_ || actual > upper_bound_) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Expected Range: [%" PRIu16 ", %" PRIu16 "] Actual: %" PRIu16 "\n", \ + __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ + } \ + \ + } while (0) + +#define cmc_assert_in_range_uint32_t(lower_bound, upper_bound, actual) \ + do \ + { \ + const char *str = #actual; \ + uint32_t lower_bound_ = lower_bound; \ + uint32_t upper_bound_ = upper_bound; \ + uint32_t actual_ = actual; \ + \ + if (actual < lower_bound_ || actual > upper_bound_) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Expected Range: [%" PRIu32 ", %" PRIu32 "] Actual: %" PRIu32 "\n", \ + __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ + } \ + \ + } while (0) + +#define cmc_assert_in_range_uint64_t(lower_bound, upper_bound, actual) \ + do \ + { \ + const char *str = #actual; \ + uint64_t lower_bound_ = lower_bound; \ + uint64_t upper_bound_ = upper_bound; \ + uint64_t actual_ = actual; \ + \ + if (actual < lower_bound_ || actual > upper_bound_) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Expected Range: [%" PRIu64 ", %" PRIu64 "] Actual: %" PRIu64 "\n", \ + __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ + } \ + \ + } while (0) + +#define cmc_assert_in_range_intmax_t(lower_bound, upper_bound, actual) \ + do \ + { \ + const char *str = #actual; \ + intmax_t lower_bound_ = lower_bound; \ + intmax_t upper_bound_ = upper_bound; \ + intmax_t actual_ = actual; \ + \ + if (actual < lower_bound_ || actual > upper_bound_) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Expected Range: [%" PRIdMAX ", %" PRIdMAX "] Actual: %" PRIdMAX "\n", \ + __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ + } \ + \ + } while (0) + +#define cmc_assert_in_range_uintmax_t(lower_bound, upper_bound, actual) \ + do \ + { \ + const char *str = #actual; \ + uintmax_t lower_bound_ = lower_bound; \ + uintmax_t upper_bound_ = upper_bound; \ + uintmax_t actual_ = actual; \ + \ + if (actual < lower_bound_ || actual > upper_bound_) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Expected Range: [%" PRIuMAX ", %" PRIuMAX "] Actual: %" PRIuMAX "\n", \ + __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ + } \ + \ + } while (0) + +#define cmc_assert_in_range_size_t(lower_bound, upper_bound, actual) \ + do \ + { \ + const char *str = #actual; \ + size_t lower_bound_ = lower_bound; \ + size_t upper_bound_ = upper_bound; \ + size_t actual_ = actual; \ + \ + if (actual < lower_bound_ || actual > upper_bound_) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Expected Range: [%" PRIuMAX ", %" PRIuMAX "] Actual: %" PRIuMAX "\n", \ + __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ + } \ + \ + } while (0) + +#define cmc_assert_in_range_float(lower_bound, upper_bound, actual) \ do \ { \ const char *str = #actual; \ - double lower_bound_ = lower_bound; \ - double upper_bound_ = upper_bound; \ - double actual_ = actual; \ + float lower_bound_ = lower_bound; \ + float upper_bound_ = upper_bound; \ + float actual_ = actual; \ \ if (actual < lower_bound_ || actual > upper_bound_) \ { \ - printf("%s:%s:%u Assertion Failed for { %s }: Expected Range: [%lf, %lf] Actual: %lf\n", \ + printf("Assertion Failed at %s:%s:%u for { %s }: Expected Range: [%f, %f] Actual: %f\n", \ __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ } \ \ } while (0) -#define cmc_assert_not_in_range_int8_t(lower_bound, upper_bound, actual) \ - do \ - { \ - const char *str = #actual; \ - int8_t lower_bound_ = lower_bound; \ - int8_t upper_bound_ = upper_bound; \ - int8_t actual_ = actual; \ - \ - if (actual >= lower_bound && actual <= upper_bound) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Not Expected Range: [%" PRId8 ", %" PRId8 "] Actual: %" PRId8 "\n", \ - __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ - } \ - \ +#define cmc_assert_in_range_double(lower_bound, upper_bound, actual) \ + do \ + { \ + const char *str = #actual; \ + double lower_bound_ = lower_bound; \ + double upper_bound_ = upper_bound; \ + double actual_ = actual; \ + \ + if (actual < lower_bound_ || actual > upper_bound_) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Expected Range: [%lf, %lf] Actual: %lf\n", \ + __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ + } \ + \ } while (0) -#define cmc_assert_not_in_range_int16_t(lower_bound, upper_bound, actual) \ +#define cmc_assert_not_in_range_int8_t(lower_bound, upper_bound, actual) \ do \ { \ const char *str = #actual; \ - int16_t lower_bound_ = lower_bound; \ - int16_t upper_bound_ = upper_bound; \ - int16_t actual_ = actual; \ + int8_t lower_bound_ = lower_bound; \ + int8_t upper_bound_ = upper_bound; \ + int8_t actual_ = actual; \ \ if (actual >= lower_bound && actual <= upper_bound) \ { \ - printf("%s:%s:%u Assertion Failed for { %s }: Not Expected Range: [%" PRId16 ", %" PRId16 "] Actual: %" PRId16 "\n", \ + printf("Assertion Failed at %s:%s:%u for { %s }: Not Expected Range: [%" PRId8 ", %" PRId8 "] Actual: %" PRId8 "\n", \ __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ } \ \ } while (0) -#define cmc_assert_not_in_range_int32_t(lower_bound, upper_bound, actual) \ - do \ - { \ - const char *str = #actual; \ - int32_t lower_bound_ = lower_bound; \ - int32_t upper_bound_ = upper_bound; \ - int32_t actual_ = actual; \ - \ - if (actual >= lower_bound && actual <= upper_bound) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Not Expected Range: [%" PRId32 ", %" PRId32 "] Actual: %" PRId32 "\n", \ - __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ - } \ - \ - } while (0) - -#define cmc_assert_not_in_range_int64_t(lower_bound, upper_bound, actual) \ - do \ - { \ - const char *str = #actual; \ - int64_t lower_bound_ = lower_bound; \ - int64_t upper_bound_ = upper_bound; \ - int64_t actual_ = actual; \ - \ - if (actual >= lower_bound && actual <= upper_bound) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Not Expected Range: [%" PRId32 ", %" PRId32 "] Actual: %" PRId32 "\n", \ - __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ - } \ - \ - } while (0) - -#define cmc_assert_not_in_range_uint8_t(lower_bound, upper_bound, actual) \ - do \ - { \ - const char *str = #actual; \ - uint8_t lower_bound_ = lower_bound; \ - uint8_t upper_bound_ = upper_bound; \ - uint8_t actual_ = actual; \ - \ - if (actual >= lower_bound && actual <= upper_bound) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Not Expected Range: [%" PRIu8 ", %" PRIu8 "] Actual: %" PRIu8 "\n", \ - __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ - } \ - \ - } while (0) - -#define cmc_assert_not_in_range_uint16_t(lower_bound, upper_bound, actual) \ - do \ - { \ - const char *str = #actual; \ - uint16_t lower_bound_ = lower_bound; \ - uint16_t upper_bound_ = upper_bound; \ - uint16_t actual_ = actual; \ - \ - if (actual >= lower_bound && actual <= upper_bound) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Not Expected Range: [%" PRIu16 ", %" PRIu16 "] Actual: %" PRIu16 "\n", \ - __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ - } \ - \ - } while (0) - -#define cmc_assert_not_in_range_uint32_t(lower_bound, upper_bound, actual) \ - do \ - { \ - const char *str = #actual; \ - uint32_t lower_bound_ = lower_bound; \ - uint32_t upper_bound_ = upper_bound; \ - uint32_t actual_ = actual; \ - \ - if (actual >= lower_bound && actual <= upper_bound) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Not Expected Range: [%" PRIu32 ", %" PRIu32 "] Actual: %" PRIu32 "\n", \ - __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ - } \ - \ - } while (0) - -#define cmc_assert_not_in_range_uint64_t(lower_bound, upper_bound, actual) \ - do \ - { \ - const char *str = #actual; \ - uint64_t lower_bound_ = lower_bound; \ - uint64_t upper_bound_ = upper_bound; \ - uint64_t actual_ = actual; \ - \ - if (actual >= lower_bound && actual <= upper_bound) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Not Expected Range: [%" PRIu64 ", %" PRIu64 "] Actual: %" PRIu64 "\n", \ - __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ - } \ - \ - } while (0) - -#define cmc_assert_not_in_range_intmax_t(lower_bound, upper_bound, actual) \ +#define cmc_assert_not_in_range_int16_t(lower_bound, upper_bound, actual) \ do \ { \ const char *str = #actual; \ - intmax_t lower_bound_ = lower_bound; \ - intmax_t upper_bound_ = upper_bound; \ - intmax_t actual_ = actual; \ + int16_t lower_bound_ = lower_bound; \ + int16_t upper_bound_ = upper_bound; \ + int16_t actual_ = actual; \ \ if (actual >= lower_bound && actual <= upper_bound) \ { \ - printf("%s:%s:%u Assertion Failed for { %s }: Not Expected Range: [%" PRIdMAX ", %" PRIdMAX "] Actual: %" PRIdMAX "\n", \ + printf("Assertion Failed at %s:%s:%u for { %s }: Not Expected Range: [%" PRId16 ", %" PRId16 "] Actual: %" PRId16 "\n", \ __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ } \ \ } while (0) -#define cmc_assert_not_in_range_uintmax_t(lower_bound, upper_bound, actual) \ +#define cmc_assert_not_in_range_int32_t(lower_bound, upper_bound, actual) \ do \ { \ const char *str = #actual; \ - uintmax_t lower_bound_ = lower_bound; \ - uintmax_t upper_bound_ = upper_bound; \ - uintmax_t actual_ = actual; \ + int32_t lower_bound_ = lower_bound; \ + int32_t upper_bound_ = upper_bound; \ + int32_t actual_ = actual; \ \ if (actual >= lower_bound && actual <= upper_bound) \ { \ - printf("%s:%s:%u Assertion Failed for { %s }: Not Expected Range: [%" PRIuMAX ", %" PRIuMAX "] Actual: %" PRIuMAX "\n", \ + printf("Assertion Failed at %s:%s:%u for { %s }: Not Expected Range: [%" PRId32 ", %" PRId32 "] Actual: %" PRId32 "\n", \ __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ } \ \ } while (0) -#define cmc_assert_not_in_range_size_t(lower_bound, upper_bound, actual) \ +#define cmc_assert_not_in_range_int64_t(lower_bound, upper_bound, actual) \ do \ { \ const char *str = #actual; \ - size_t lower_bound_ = lower_bound; \ - size_t upper_bound_ = upper_bound; \ - size_t actual_ = actual; \ + int64_t lower_bound_ = lower_bound; \ + int64_t upper_bound_ = upper_bound; \ + int64_t actual_ = actual; \ \ if (actual >= lower_bound && actual <= upper_bound) \ { \ - printf("%s:%s:%u Assertion Failed for { %s }: Not Expected Range: [%" PRIuMAX ", %" PRIuMAX "] Actual: %" PRIuMAX "\n", \ + printf("Assertion Failed at %s:%s:%u for { %s }: Not Expected Range: [%" PRId32 ", %" PRId32 "] Actual: %" PRId32 "\n", \ __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ } \ \ } while (0) -#define cmc_assert_not_in_range_float(lower_bound, upper_bound, actual) \ - do \ - { \ - const char *str = #actual; \ - float lower_bound_ = lower_bound; \ - float upper_bound_ = upper_bound; \ - float actual_ = actual; \ - \ - if (actual >= lower_bound && actual <= upper_bound) \ - { \ - printf("%s:%s:%u Assertion Failed for { %s }: Not Expected Range: [%f, %f] Actual: %f\n", \ - __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ - } \ - \ +#define cmc_assert_not_in_range_uint8_t(lower_bound, upper_bound, actual) \ + do \ + { \ + const char *str = #actual; \ + uint8_t lower_bound_ = lower_bound; \ + uint8_t upper_bound_ = upper_bound; \ + uint8_t actual_ = actual; \ + \ + if (actual >= lower_bound && actual <= upper_bound) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Not Expected Range: [%" PRIu8 ", %" PRIu8 "] Actual: %" PRIu8 "\n", \ + __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ + } \ + \ } while (0) -#define cmc_assert_not_in_range_double(lower_bound, upper_bound, actual) \ +#define cmc_assert_not_in_range_uint16_t(lower_bound, upper_bound, actual) \ + do \ + { \ + const char *str = #actual; \ + uint16_t lower_bound_ = lower_bound; \ + uint16_t upper_bound_ = upper_bound; \ + uint16_t actual_ = actual; \ + \ + if (actual >= lower_bound && actual <= upper_bound) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Not Expected Range: [%" PRIu16 ", %" PRIu16 "] Actual: %" PRIu16 "\n", \ + __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ + } \ + \ + } while (0) + +#define cmc_assert_not_in_range_uint32_t(lower_bound, upper_bound, actual) \ + do \ + { \ + const char *str = #actual; \ + uint32_t lower_bound_ = lower_bound; \ + uint32_t upper_bound_ = upper_bound; \ + uint32_t actual_ = actual; \ + \ + if (actual >= lower_bound && actual <= upper_bound) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Not Expected Range: [%" PRIu32 ", %" PRIu32 "] Actual: %" PRIu32 "\n", \ + __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ + } \ + \ + } while (0) + +#define cmc_assert_not_in_range_uint64_t(lower_bound, upper_bound, actual) \ + do \ + { \ + const char *str = #actual; \ + uint64_t lower_bound_ = lower_bound; \ + uint64_t upper_bound_ = upper_bound; \ + uint64_t actual_ = actual; \ + \ + if (actual >= lower_bound && actual <= upper_bound) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Not Expected Range: [%" PRIu64 ", %" PRIu64 "] Actual: %" PRIu64 "\n", \ + __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ + } \ + \ + } while (0) + +#define cmc_assert_not_in_range_intmax_t(lower_bound, upper_bound, actual) \ + do \ + { \ + const char *str = #actual; \ + intmax_t lower_bound_ = lower_bound; \ + intmax_t upper_bound_ = upper_bound; \ + intmax_t actual_ = actual; \ + \ + if (actual >= lower_bound && actual <= upper_bound) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Not Expected Range: [%" PRIdMAX ", %" PRIdMAX "] Actual: %" PRIdMAX "\n", \ + __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ + } \ + \ + } while (0) + +#define cmc_assert_not_in_range_uintmax_t(lower_bound, upper_bound, actual) \ + do \ + { \ + const char *str = #actual; \ + uintmax_t lower_bound_ = lower_bound; \ + uintmax_t upper_bound_ = upper_bound; \ + uintmax_t actual_ = actual; \ + \ + if (actual >= lower_bound && actual <= upper_bound) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Not Expected Range: [%" PRIuMAX ", %" PRIuMAX "] Actual: %" PRIuMAX "\n", \ + __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ + } \ + \ + } while (0) + +#define cmc_assert_not_in_range_size_t(lower_bound, upper_bound, actual) \ + do \ + { \ + const char *str = #actual; \ + size_t lower_bound_ = lower_bound; \ + size_t upper_bound_ = upper_bound; \ + size_t actual_ = actual; \ + \ + if (actual >= lower_bound && actual <= upper_bound) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Not Expected Range: [%" PRIuMAX ", %" PRIuMAX "] Actual: %" PRIuMAX "\n", \ + __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ + } \ + \ + } while (0) + +#define cmc_assert_not_in_range_float(lower_bound, upper_bound, actual) \ do \ { \ const char *str = #actual; \ - double lower_bound_ = lower_bound; \ - double upper_bound_ = upper_bound; \ - double actual_ = actual; \ + float lower_bound_ = lower_bound; \ + float upper_bound_ = upper_bound; \ + float actual_ = actual; \ \ if (actual >= lower_bound && actual <= upper_bound) \ { \ - printf("%s:%s:%u Assertion Failed for { %s }: Not Expected Range: [%lf, %lf] Actual: %lf\n", \ + printf("Assertion Failed at %s:%s:%u for { %s }: Not Expected Range: [%f, %f] Actual: %f\n", \ __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ } \ \ } while (0) +#define cmc_assert_not_in_range_double(lower_bound, upper_bound, actual) \ + do \ + { \ + const char *str = #actual; \ + double lower_bound_ = lower_bound; \ + double upper_bound_ = upper_bound; \ + double actual_ = actual; \ + \ + if (actual >= lower_bound && actual <= upper_bound) \ + { \ + printf("Assertion Failed at %s:%s:%u for { %s }: Not Expected Range: [%lf, %lf] Actual: %lf\n", \ + __FILE__, __func__, __LINE__, str, lower_bound_, upper_bound_, actual_); \ + } \ + \ + } while (0) + #endif /* CMC_ASSERT_H */ diff --git a/src/utl/foreach.h b/src/utl/foreach.h index 4d60514..f9c1b6d 100644 --- a/src/utl/foreach.h +++ b/src/utl/foreach.h @@ -24,7 +24,7 @@ { \ BODY; \ } \ - } while (0); + } while (0) #define FOR_EACH_REV(PFX, SNAME, TARGET, BODY) \ do \ @@ -33,6 +33,6 @@ { \ BODY; \ } \ - } while (0); + } while (0) #endif /* CMC_FOR_EACH */ diff --git a/src/utl/test.h b/src/utl/test.h index d39643b..493510f 100644 --- a/src/utl/test.h +++ b/src/utl/test.h @@ -103,10 +103,10 @@ static void cmc_test_log(const char *unit_name, const char *current_test, bool a tinfo.verbose = VERBOSE; \ \ /* Tests */ \ - TIMER_START(timer); \ + timer_start(timer); \ BODY; \ - TIMER_STOP(timer); \ - TIMER_CALC(timer); \ + timer_stop(timer); \ + timer_calc(timer); \ \ unittest_abort: \ if (tinfo.aborted) \ @@ -133,7 +133,7 @@ static void cmc_test_log(const char *unit_name, const char *current_test, bool a \ BODY; \ \ - } while (0); + } while (0) #define CMC_TEST_PASS() \ do \ diff --git a/src/utl/timer.h b/src/utl/timer.h index 583000c..7850547 100644 --- a/src/utl/timer.h +++ b/src/utl/timer.h @@ -22,13 +22,26 @@ typedef struct timer_s double result; } timer_t; -#define TIMER_START(timer) \ - timer.start = clock(); +#define timer_start(timer) \ + do \ + { \ + (timer).start = clock(); \ + \ + } while (0) -#define TIMER_STOP(timer) \ - timer.stop = clock(); +#define timer_stop(timer) \ + do \ + { \ + (timer).stop = clock(); \ + \ + } while (0) -#define TIMER_CALC(timer) \ - timer.result = (double)(((timer.stop - timer.start) * 1000.0) / CLOCKS_PER_SEC); +#define timer_calc(timer) \ + do \ + { \ + timer_t *t = &(timer); \ + t->result = (double)(t->stop - t->start) * 1000.0 / CLOCKS_PER_SEC; \ + \ + } while (0) #endif /* CMC_TIMER_H */ diff --git a/tests/Makefile b/tests/Makefile index f6a0125..fe6f135 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,15 +1,21 @@ -CFLAGS= -Wno-unused-function -Wno-unused-paramter -Wno-unused-variable -std=c11 -Wall -Wextra +CC = gcc +CFLAGS = -std=c11 -Wall -Wextra +CFLAGS += -Wno-unused-function -Wno-unused-paramter -Wno-unused-variable -Wno-unused-label +CVFLAGS = --coverage -O0 main: - gcc foreach.c -o foreach $(CFLAGS) + $(CC) foreach.c -o foreach $(CFLAGS) ./foreach - gcc iterators.c -o iterators $(CFLAGS) + $(CC) iterators.c -o iterators $(CFLAGS) ./iterators - gcc contains.c -o contains $(CFLAGS) + $(CC) contains.c -o contains $(CFLAGS) ./contains - gcc types.c -o types $(CFLAGS) + $(CC) types.c -o types $(CFLAGS) ./types - gcc -c ./sep/sep.c -o ./sep/sep.o $(CFLAGS) - gcc -c ./sep/main.c -o ./sep/main.o $(CFLAGS) - gcc ./sep/sep.o ./sep/main.o -o ./sep/sep + $(CC) -c ./sep/sep.c -o ./sep/sep.o $(CFLAGS) + $(CC) -c ./sep/main.c -o ./sep/main.o $(CFLAGS) + $(CC) ./sep/sep.o ./sep/main.o -o ./sep/sep ./sep/sep + $(CC) list.c -o list $(CFLAGS) $(CVFLAGS) + ./list + gcov ./list.c diff --git a/tests/foreach.c b/tests/foreach.c index 9f98432..db7ccf8 100644 --- a/tests/foreach.c +++ b/tests/foreach.c @@ -72,45 +72,45 @@ int main(void) FOR_EACH(d, deque, d, { sum3 += d_iter_value(&iter); - }) + }); FOR_EACH(hm, hmap, hm, { sum10 += hm_iter_key(&iter); sum11 += hm_iter_value(&iter); - }) + }); FOR_EACH(hs, hset, hs, { sum9 += hs_iter_value(&iter); - }) + }); FOR_EACH(h, heap, h, { sum5 += h_iter_value(&iter); - }) + }); FOR_EACH(ll, linked, ll, { sum4 += ll_iter_value(&iter); - }) + }); FOR_EACH(l, list, l, { sum0 += l_iter_value(&iter); - }) + }); FOR_EACH(q, queue, q, { sum2 += q_iter_value(&iter); - }) + }); FOR_EACH(s, stack, s, { sum1 += s_iter_value(&iter); - }) + }); FOR_EACH(tm, tmap, tm, { sum7 += tm_iter_key(&iter); sum8 += tm_iter_value(&iter); - }) + }); FOR_EACH(ts, tset, ts, { sum6 += ts_iter_value(&iter); - }) + }); printf("\n-------------------- FOR_EACH --------------------\n"); if (sum3 == 50005000) @@ -161,45 +161,45 @@ int main(void) FOR_EACH_REV(d, deque, d, { sum3 += d_iter_value(&iter); - }) + }); FOR_EACH_REV(hm, hmap, hm, { sum10 += hm_iter_key(&iter); sum11 += hm_iter_value(&iter); - }) + }); FOR_EACH_REV(hs, hset, hs, { sum9 += hs_iter_value(&iter); - }) + }); FOR_EACH_REV(h, heap, h, { sum5 += h_iter_value(&iter); - }) + }); FOR_EACH_REV(ll, linked, ll, { sum4 += ll_iter_value(&iter); - }) + }); FOR_EACH_REV(l, list, l, { sum0 += l_iter_value(&iter); - }) + }); FOR_EACH_REV(q, queue, q, { sum2 += q_iter_value(&iter); - }) + }); FOR_EACH_REV(s, stack, s, { sum1 += s_iter_value(&iter); - }) + }); FOR_EACH_REV(tm, tmap, tm, { sum7 += tm_iter_key(&iter); sum8 += tm_iter_value(&iter); - }) + }); FOR_EACH_REV(ts, tset, ts, { sum6 += ts_iter_value(&iter); - }) + }); printf("-------------------- FOR_EACH_REV --------------------\n"); if (sum3 == 50005000) diff --git a/tests/list.c b/tests/list.c new file mode 100644 index 0000000..315497e --- /dev/null +++ b/tests/list.c @@ -0,0 +1,221 @@ +#include "../src/macro_collections.h" + +LIST_GENERATE(l, list, , size_t) + +CMC_CREATE_UNIT(list_test, true, { + CMC_CREATE_TEST(new, { + list *l = l_new(1000000); + + cmc_assert_not_equals(ptr, NULL, l); + + bool passed = l->capacity == 1000000 && l->count == 0 && l->buffer; + + cmc_assert_equals(size_t, 1000000, l->capacity); + cmc_assert_equals(size_t, 0, l_count(l)); + cmc_assert_not_equals(ptr, NULL, l->buffer); + + if (passed) + CMC_TEST_PASS(); + else + CMC_TEST_FAIL(); + + l_free(l); + }); + + CMC_CREATE_TEST(new [edge_case:capacity = 0], { + list *l = l_new(0); + + cmc_assert_equals(ptr, NULL, l); + + CMC_TEST_PASS_ELSE_FAIL(l == NULL); + }); + + CMC_CREATE_TEST(new_from[count item_preservation], { + size_t v[5]; + + for (size_t i = 0; i < 5; i++) + { + v[i] = i; + } + + list *l = l_new_from(v, 5); + + cmc_assert_not_equals(ptr, NULL, l); + + bool passed = true; + + for (size_t i = 0; i < 5; i++) + { + cmc_assert_equals(size_t, i, l_get(l, i)); + + passed = passed && l_get(l, i) == i; + } + + CMC_TEST_PASS_ELSE_FAIL(passed && l_count(l) == 5); + + l_free(l); + }); + + CMC_CREATE_TEST(new_from [edge_case:size = 1], { + size_t a = 10; + + size_t *values = &a; + + list *l = l_new_from(values, 1); + + cmc_assert_not_equals(ptr, NULL, l); + + CMC_TEST_PASS_ELSE_FAIL(l_count(l) == 1); + + l_free(l); + }); + + CMC_CREATE_TEST(clear[count capacity], { + list *l = l_new(100); + + cmc_assert_not_equals(ptr, NULL, l); + + for (size_t i = 0; i < 50; i++) + l_push_back(l, i); + + l_clear(l); + + CMC_TEST_PASS_ELSE_FAIL(l_count(l) == 0 && l_capacity(l) == 100); + + l_free(l); + }); + + CMC_CREATE_TEST(push_front[count capacity item_preservation grow], { + list *l = l_new(100); + + cmc_assert_not_equals(ptr, NULL, l); + + for (size_t i = 0; i < 200; i++) + l_push_front(l, i); + + bool passed = true; + + for (size_t i = 0; i < l_count(l); i++) + { + passed = passed && l_get(l, i) == (l_count(l) - i - 1); + + cmc_assert_equals(size_t, l_get(l, i), l_count(l) - i - 1); + } + + CMC_TEST_PASS_ELSE_FAIL(passed && l_count(l) == 200); + + l_free(l); + }); + + CMC_CREATE_TEST(push[count capacity item_preservation grow], { + list *l = l_new(100); + + cmc_assert_not_equals(ptr, NULL, l); + + for (size_t i = 0; i < 200; i++) + l_push(l, i, l_count(l)); + + bool passed = true; + + for (size_t i = 0; i < l_count(l); i++) + { + passed = passed && l_get(l, i) == i; + + cmc_assert_equals(size_t, l_get(l, i), i); + } + + CMC_TEST_PASS_ELSE_FAIL(passed && l_count(l) == 200); + + l_free(l); + }); + + CMC_CREATE_TEST(push_back[count capacity item_preservation grow], { + list *l = l_new(100); + + cmc_assert_not_equals(ptr, NULL, l); + + for (size_t i = 0; i < 200; i++) + l_push_back(l, i); + + bool passed = true; + + for (size_t i = 0; i < l_count(l); i++) + { + passed = passed && l_get(l, i) == i; + + cmc_assert_equals(size_t, l_get(l, i), i); + } + + CMC_TEST_PASS_ELSE_FAIL(passed && l_count(l) == 200); + + l_free(l); + }); + + CMC_CREATE_TEST(pop_front[count item_preservation], { + list *l = l_new(100); + + cmc_assert_not_equals(ptr, NULL, l); + + for (size_t i = 0; i < 200; i++) + l_push_back(l, i); + + bool passed = l_pop_front(l); + + for (size_t i = 0; i < l_count(l); i++) + { + passed = passed && l_get(l, i) == i + 1; + + cmc_assert_equals(size_t, l_get(l, i), i + 1); + } + + CMC_TEST_PASS_ELSE_FAIL(passed && l_count(l) == 199); + + l_free(l); + }); + + CMC_CREATE_TEST(pop_front [edge_case:count = 1], { + list *l = l_new(100); + + cmc_assert_not_equals(ptr, NULL, l); + cmc_assert(l_push_back(l, 10)); + cmc_assert(l_pop_front(l)); + + CMC_TEST_PASS_ELSE_FAIL(l_count(l) == 0); + + l_free(l); + }); + + CMC_CREATE_TEST(pop_front [edge_case:count = 2], { + list *l = l_new(100); + + cmc_assert(l_push_back(l, 10)); + cmc_assert(l_push_front(l, 10)); + + CMC_TEST_PASS_ELSE_FAIL(l_pop_front(l) && l_count(l) == 1); + + l_free(l); + }); + + CMC_CREATE_TEST(pop_front[buffer_clear], { + list *l = l_new(100); + + cmc_assert(l_push_back(l, 10)); + cmc_assert(l_push_front(l, 10)); + + // Default value is all bytes are 0 + bool passed = l_pop_front(l) && l->buffer[1] == 0; + + cmc_assert_equals(size_t, 0, l->buffer[1]); + + CMC_TEST_PASS_ELSE_FAIL(passed && l_count(l) == 1); + + l_free(l); + }); +}) + +int main(void) +{ + list_test(); + + return 0; +}