diff options
Diffstat (limited to 'tests/gtests/blenlib')
-rw-r--r-- | tests/gtests/blenlib/BLI_array_store_test.cc | 68 | ||||
-rw-r--r-- | tests/gtests/blenlib/BLI_array_utils_test.cc | 38 | ||||
-rw-r--r-- | tests/gtests/blenlib/BLI_ghash_performance_test.cc | 18 | ||||
-rw-r--r-- | tests/gtests/blenlib/BLI_ghash_test.cc | 34 | ||||
-rw-r--r-- | tests/gtests/blenlib/BLI_hash_mm2a_test.cc | 16 | ||||
-rw-r--r-- | tests/gtests/blenlib/BLI_kdopbvh_test.cc | 97 | ||||
-rw-r--r-- | tests/gtests/blenlib/BLI_listbase_test.cc | 26 | ||||
-rw-r--r-- | tests/gtests/blenlib/BLI_math_geom_test.cc | 2 | ||||
-rw-r--r-- | tests/gtests/blenlib/BLI_path_util_test.cc | 255 | ||||
-rw-r--r-- | tests/gtests/blenlib/BLI_polyfill2d_test.cc | 87 | ||||
-rw-r--r-- | tests/gtests/blenlib/BLI_stack_test.cc | 32 | ||||
-rw-r--r-- | tests/gtests/blenlib/BLI_string_test.cc | 104 | ||||
-rw-r--r-- | tests/gtests/blenlib/BLI_string_utf8_test.cc | 304 | ||||
-rw-r--r-- | tests/gtests/blenlib/CMakeLists.txt | 29 | ||||
-rw-r--r-- | tests/gtests/blenlib/stubs/bf_intern_eigen_stubs.h | 18 |
15 files changed, 929 insertions, 199 deletions
diff --git a/tests/gtests/blenlib/BLI_array_store_test.cc b/tests/gtests/blenlib/BLI_array_store_test.cc index b71dc4575f1..370a4111bae 100644 --- a/tests/gtests/blenlib/BLI_array_store_test.cc +++ b/tests/gtests/blenlib/BLI_array_store_test.cc @@ -36,15 +36,15 @@ static void print_mem_saved(const char *id, const BArrayStore *bs) /* -------------------------------------------------------------------- */ /* Test Chunks (building data from list of chunks) */ -typedef struct TestChunnk { - struct TestChunnk *next, *prev; +typedef struct TestChunk { + struct TestChunk *next, *prev; const void *data; size_t data_len; -} TestChunnk; +} TestChunk; -static TestChunnk *testchunk_list_add(ListBase *lb, const void *data, size_t data_len) +static TestChunk *testchunk_list_add(ListBase *lb, const void *data, size_t data_len) { - TestChunnk *tc = (TestChunnk *)MEM_mallocN(sizeof(*tc), __func__); + TestChunk *tc = (TestChunk *)MEM_mallocN(sizeof(*tc), __func__); tc->data = data; tc->data_len = data_len; BLI_addtail(lb, tc); @@ -53,7 +53,7 @@ static TestChunnk *testchunk_list_add(ListBase *lb, const void *data, size_t dat } #if 0 -static TestChunnk *testchunk_list_add_copydata(ListBase *lb, const void *data, size_t data_len) +static TestChunk *testchunk_list_add_copydata(ListBase *lb, const void *data, size_t data_len) { void *data_copy = MEM_mallocN(data_len, __func__); memcpy(data_copy, data, data_len); @@ -63,7 +63,7 @@ static TestChunnk *testchunk_list_add_copydata(ListBase *lb, const void *data, s static void testchunk_list_free(ListBase *lb) { - for (TestChunnk *tc = (TestChunnk *)lb->first, *tb_next; tc; tc = tb_next) { + for (TestChunk *tc = (TestChunk *)lb->first, *tb_next; tc; tc = tb_next) { tb_next = tc->next; MEM_freeN((void *)tc->data); MEM_freeN(tc); @@ -77,12 +77,12 @@ static char *testchunk_as_data( size_t *r_data_len) { size_t data_len = 0; - for (TestChunnk *tc = (TestChunnk *)lb->first; tc; tc = tc->next) { + for (TestChunk *tc = (TestChunk *)lb->first; tc; tc = tc->next) { data_len += tc->data_len; } char *data = (char *)MEM_mallocN(data_len, __func__); size_t i = 0; - for (TestChunnk *tc = (TestChunnk *)lb->first; tc; tc = tc->next) { + for (TestChunk *tc = (TestChunk *)lb->first; tc; tc = tc->next) { memcpy(&data[i], tc->data, tc->data_len); data_len += tc->data_len; i += tc->data_len; @@ -95,7 +95,7 @@ static char *testchunk_as_data( #endif static char *testchunk_as_data_array( - TestChunnk **tc_array, int tc_array_len, + TestChunk **tc_array, int tc_array_len, size_t *r_data_len) { size_t data_len = 0; @@ -105,7 +105,7 @@ static char *testchunk_as_data_array( char *data = (char *)MEM_mallocN(data_len, __func__); size_t i = 0; for (int tc_index = 0; tc_index < tc_array_len; tc_index++) { - TestChunnk *tc = tc_array[tc_index]; + TestChunk *tc = tc_array[tc_index]; memcpy(&data[i], tc->data, tc->data_len); i += tc->data_len; } @@ -280,8 +280,8 @@ static void testbuffer_run_tests_single( BArrayStore *bs, ListBase *lb) { testbuffer_list_store_populate(bs, lb); - EXPECT_EQ(true, testbuffer_list_validate(lb)); - EXPECT_EQ(true, BLI_array_store_is_valid(bs)); + EXPECT_TRUE(testbuffer_list_validate(lb)); + EXPECT_TRUE(BLI_array_store_is_valid(bs)); #ifdef DEBUG_PRINT print_mem_saved("data", bs); #endif @@ -326,7 +326,7 @@ TEST(array_store, NopState) BArrayStore *bs = BLI_array_store_create(1, 32); const unsigned char data[] = "test"; BArrayState *state = BLI_array_store_state_add(bs, data, sizeof(data) - 1, NULL); - EXPECT_EQ(sizeof(data) - 1, BLI_array_store_state_size_get(state)); + EXPECT_EQ(BLI_array_store_state_size_get(state), sizeof(data) - 1); BLI_array_store_state_remove(bs, state); BLI_array_store_destroy(bs); } @@ -340,7 +340,7 @@ TEST(array_store, Single) size_t data_dst_len; data_dst = (char *)BLI_array_store_state_data_get_alloc(state, &data_dst_len); EXPECT_STREQ(data_src, data_dst); - EXPECT_EQ(sizeof(data_src), data_dst_len); + EXPECT_EQ(data_dst_len, sizeof(data_src)); BLI_array_store_destroy(bs); MEM_freeN((void *)data_dst); } @@ -354,8 +354,8 @@ TEST(array_store, DoubleNop) BArrayState *state_a = BLI_array_store_state_add(bs, data_src, sizeof(data_src), NULL); BArrayState *state_b = BLI_array_store_state_add(bs, data_src, sizeof(data_src), state_a); - EXPECT_EQ(sizeof(data_src), BLI_array_store_calc_size_compacted_get(bs)); - EXPECT_EQ(sizeof(data_src) * 2, BLI_array_store_calc_size_expanded_get(bs)); + EXPECT_EQ(BLI_array_store_calc_size_compacted_get(bs), sizeof(data_src)); + EXPECT_EQ(BLI_array_store_calc_size_expanded_get(bs), sizeof(data_src) * 2); size_t data_dst_len; @@ -367,7 +367,7 @@ TEST(array_store, DoubleNop) EXPECT_STREQ(data_src, data_dst); MEM_freeN((void *)data_dst); - EXPECT_EQ(sizeof(data_src), data_dst_len); + EXPECT_EQ(data_dst_len, sizeof(data_src)); BLI_array_store_destroy(bs); } @@ -382,8 +382,8 @@ TEST(array_store, DoubleDiff) BArrayState *state_b = BLI_array_store_state_add(bs, data_src_b, sizeof(data_src_b), state_a); size_t data_dst_len; - EXPECT_EQ(sizeof(data_src_a) * 2, BLI_array_store_calc_size_compacted_get(bs)); - EXPECT_EQ(sizeof(data_src_a) * 2, BLI_array_store_calc_size_expanded_get(bs)); + EXPECT_EQ(BLI_array_store_calc_size_compacted_get(bs), sizeof(data_src_a) * 2); + EXPECT_EQ(BLI_array_store_calc_size_expanded_get(bs), sizeof(data_src_a) * 2); data_dst = (char *)BLI_array_store_state_data_get_alloc(state_a, &data_dst_len); EXPECT_STREQ(data_src_a, data_dst); @@ -423,19 +423,19 @@ TEST(array_store, TextDupeIncreaseDecrease) /* forward */ testbuffer_list_store_populate(bs, &lb); - EXPECT_EQ(true, testbuffer_list_validate(&lb)); - EXPECT_EQ(true, BLI_array_store_is_valid(bs)); - EXPECT_EQ(strlen(D), BLI_array_store_calc_size_compacted_get(bs)); + EXPECT_TRUE(testbuffer_list_validate(&lb)); + EXPECT_TRUE(BLI_array_store_is_valid(bs)); + EXPECT_EQ(BLI_array_store_calc_size_compacted_get(bs), strlen(D)); testbuffer_list_store_clear(bs, &lb); BLI_listbase_reverse(&lb); /* backwards */ testbuffer_list_store_populate(bs, &lb); - EXPECT_EQ(true, testbuffer_list_validate(&lb)); - EXPECT_EQ(true, BLI_array_store_is_valid(bs)); + EXPECT_TRUE(testbuffer_list_validate(&lb)); + EXPECT_TRUE(BLI_array_store_is_valid(bs)); /* larger since first block doesn't de-duplicate */ - EXPECT_EQ(strlen(D) * 4, BLI_array_store_calc_size_compacted_get(bs)); + EXPECT_EQ(BLI_array_store_calc_size_compacted_get(bs), strlen(D) * 4); #undef D testbuffer_list_free(&lb); \ @@ -677,9 +677,9 @@ static void random_chunk_mutate_helper( ListBase random_chunks; BLI_listbase_clear(&random_chunks); random_chunk_generate(&random_chunks, chunks_per_buffer, stride, chunk_count, random_seed); - TestChunnk **chunks_array = (TestChunnk **)MEM_mallocN(chunks_per_buffer * sizeof(TestChunnk *), __func__); + TestChunk **chunks_array = (TestChunk **)MEM_mallocN(chunks_per_buffer * sizeof(TestChunk *), __func__); { - TestChunnk *tc = (TestChunnk *)random_chunks.first; + TestChunk *tc = (TestChunk *)random_chunks.first; for (int i = 0; i < chunks_per_buffer; i++, tc = tc->next) { chunks_array[i] = tc; } @@ -692,7 +692,7 @@ static void random_chunk_mutate_helper( { RNG *rng = BLI_rng_new(random_seed); for (int i = 0; i < items_total; i++) { - BLI_rng_shuffle_array(rng, chunks_array, sizeof(TestChunnk *), chunks_per_buffer); + BLI_rng_shuffle_array(rng, chunks_array, sizeof(TestChunk *), chunks_per_buffer); size_t data_len; char *data = testchunk_as_data_array(chunks_array, chunks_per_buffer, &data_len); BLI_assert(data_len == chunks_per_buffer * chunk_count * stride); @@ -708,7 +708,7 @@ static void random_chunk_mutate_helper( testbuffer_run_tests_single(bs, &lb); size_t expected_size = chunks_per_buffer * chunk_count * stride; - EXPECT_EQ(expected_size, BLI_array_store_calc_size_compacted_get(bs)); + EXPECT_EQ(BLI_array_store_calc_size_compacted_get(bs), expected_size); BLI_array_store_destroy(bs); @@ -782,8 +782,8 @@ TEST(array_store, PlainTextFiles) /* forwards */ testbuffer_list_store_populate(bs, &lb); - EXPECT_EQ(true, testbuffer_list_validate(&lb)); - EXPECT_EQ(true, BLI_array_store_is_valid(bs)); + EXPECT_TRUE(testbuffer_list_validate(&lb)); + EXPECT_TRUE(BLI_array_store_is_valid(bs)); #ifdef DEBUG_PRINT print_mem_saved("source code forward", bs); #endif @@ -793,8 +793,8 @@ TEST(array_store, PlainTextFiles) /* backwards */ testbuffer_list_store_populate(bs, &lb); - EXPECT_EQ(true, testbuffer_list_validate(&lb)); - EXPECT_EQ(true, BLI_array_store_is_valid(bs)); + EXPECT_TRUE(testbuffer_list_validate(&lb)); + EXPECT_TRUE(BLI_array_store_is_valid(bs)); #ifdef DEBUG_PRINT print_mem_saved("source code backwards", bs); #endif diff --git a/tests/gtests/blenlib/BLI_array_utils_test.cc b/tests/gtests/blenlib/BLI_array_utils_test.cc index eabf5bc72cf..c4601e00fbd 100644 --- a/tests/gtests/blenlib/BLI_array_utils_test.cc +++ b/tests/gtests/blenlib/BLI_array_utils_test.cc @@ -5,7 +5,7 @@ extern "C" { #include "BLI_utildefines.h" #include "BLI_array_utils.h" -#include "BLI_stackdefines.h" +#include "BLI_utildefines_stack.h" } /* -------------------------------------------------------------------- */ @@ -45,50 +45,50 @@ TEST(array_utils, ReverseInt4) TEST(array_utils, FindIndexStringEmpty) { char data[] = "", find = '0'; - EXPECT_EQ(-1, BLI_array_findindex(data, ARRAY_SIZE(data) - 1, &find)); - EXPECT_EQ(-1, BLI_array_rfindindex(data, ARRAY_SIZE(data) - 1, &find)); + EXPECT_EQ(BLI_array_findindex(data, ARRAY_SIZE(data) - 1, &find), -1); + EXPECT_EQ(BLI_array_rfindindex(data, ARRAY_SIZE(data) - 1, &find), -1); } TEST(array_utils, FindIndexStringSingle) { char data[] = "0", find = '0'; - EXPECT_EQ(0, BLI_array_findindex(data, ARRAY_SIZE(data) - 1, &find)); - EXPECT_EQ(0, BLI_array_rfindindex(data, ARRAY_SIZE(data) - 1, &find)); + EXPECT_EQ(BLI_array_findindex(data, ARRAY_SIZE(data) - 1, &find), 0); + EXPECT_EQ(BLI_array_rfindindex(data, ARRAY_SIZE(data) - 1, &find), 0); } TEST(array_utils, FindIndexStringSingleMissing) { char data[] = "1", find = '0'; - EXPECT_EQ(-1, BLI_array_findindex(data, ARRAY_SIZE(data) - 1, &find)); - EXPECT_EQ(-1, BLI_array_rfindindex(data, ARRAY_SIZE(data) - 1, &find)); + EXPECT_EQ(BLI_array_findindex(data, ARRAY_SIZE(data) - 1, &find), -1); + EXPECT_EQ(BLI_array_rfindindex(data, ARRAY_SIZE(data) - 1, &find), -1); } TEST(array_utils, FindIndexString4) { char data[] = "0123", find = '3'; - EXPECT_EQ(3, BLI_array_findindex(data, ARRAY_SIZE(data) - 1, &find)); - EXPECT_EQ(3, BLI_array_rfindindex(data, ARRAY_SIZE(data) - 1, &find)); + EXPECT_EQ(BLI_array_findindex(data, ARRAY_SIZE(data) - 1, &find), 3); + EXPECT_EQ(BLI_array_rfindindex(data, ARRAY_SIZE(data) - 1, &find), 3); } TEST(array_utils, FindIndexInt4) { int data[] = {0, 1, 2, 3}, find = 3; - EXPECT_EQ(3, BLI_array_findindex(data, ARRAY_SIZE(data), &find)); - EXPECT_EQ(3, BLI_array_rfindindex(data, ARRAY_SIZE(data), &find)); + EXPECT_EQ(BLI_array_findindex(data, ARRAY_SIZE(data), &find), 3); + EXPECT_EQ(BLI_array_rfindindex(data, ARRAY_SIZE(data), &find), 3); } TEST(array_utils, FindIndexInt4_DupeEnd) { int data[] = {0, 1, 2, 0}, find = 0; - EXPECT_EQ(0, BLI_array_findindex(data, ARRAY_SIZE(data), &find)); - EXPECT_EQ(3, BLI_array_rfindindex(data, ARRAY_SIZE(data), &find)); + EXPECT_EQ(BLI_array_findindex(data, ARRAY_SIZE(data), &find), 0); + EXPECT_EQ(BLI_array_rfindindex(data, ARRAY_SIZE(data), &find), 3); } TEST(array_utils, FindIndexInt4_DupeMid) { int data[] = {1, 0, 0, 3}, find = 0; - EXPECT_EQ(1, BLI_array_findindex(data, ARRAY_SIZE(data), &find)); - EXPECT_EQ(2, BLI_array_rfindindex(data, ARRAY_SIZE(data), &find)); + EXPECT_EQ(BLI_array_findindex(data, ARRAY_SIZE(data), &find), 1); + EXPECT_EQ(BLI_array_rfindindex(data, ARRAY_SIZE(data), &find), 2); } TEST(array_utils, FindIndexPointer) @@ -102,18 +102,18 @@ TEST(array_utils, FindIndexPointer) #define STACK_PUSH_AND_CHECK_FORWARD(v, i) { \ STACK_PUSH(data, v); \ - EXPECT_EQ(i, BLI_array_findindex(data, STACK_SIZE(data), &(v))); \ + EXPECT_EQ(BLI_array_findindex(data, STACK_SIZE(data), &(v)), i); \ } ((void)0) #define STACK_PUSH_AND_CHECK_BACKWARD(v, i) { \ STACK_PUSH(data, v); \ - EXPECT_EQ(i, BLI_array_rfindindex(data, STACK_SIZE(data), &(v))); \ + EXPECT_EQ(BLI_array_rfindindex(data, STACK_SIZE(data), &(v)), i); \ } ((void)0) #define STACK_PUSH_AND_CHECK_BOTH(v, i) { \ STACK_PUSH(data, v); \ - EXPECT_EQ(i, BLI_array_findindex(data, STACK_SIZE(data), &(v))); \ - EXPECT_EQ(i, BLI_array_rfindindex(data, STACK_SIZE(data), &(v))); \ + EXPECT_EQ(BLI_array_findindex(data, STACK_SIZE(data), &(v)), i); \ + EXPECT_EQ(BLI_array_rfindindex(data, STACK_SIZE(data), &(v)), i); \ } ((void)0) STACK_PUSH_AND_CHECK_BOTH(a, 0); diff --git a/tests/gtests/blenlib/BLI_ghash_performance_test.cc b/tests/gtests/blenlib/BLI_ghash_performance_test.cc index fb32cb3f0a5..924c84d72d0 100644 --- a/tests/gtests/blenlib/BLI_ghash_performance_test.cc +++ b/tests/gtests/blenlib/BLI_ghash_performance_test.cc @@ -118,21 +118,21 @@ static void str_ghash_tests(GHash *ghash, const char *id) TIMEIT_START(string_lookup); v = BLI_ghash_lookup(ghash, data_bis); - EXPECT_EQ(data_bis[0], GET_INT_FROM_POINTER(v)); + EXPECT_EQ(GET_INT_FROM_POINTER(v), data_bis[0]); for (p = w = c = data_bis; *c; c++) { if (*c == '.') { *c = '\0'; v = BLI_ghash_lookup(ghash, w); - EXPECT_EQ(w[0], GET_INT_FROM_POINTER(v)); + EXPECT_EQ(GET_INT_FROM_POINTER(v), w[0]); v = BLI_ghash_lookup(ghash, p); - EXPECT_EQ(p[0], GET_INT_FROM_POINTER(v)); + EXPECT_EQ(GET_INT_FROM_POINTER(v), p[0]); p = w = c + 1; } else if (*c == ' ') { *c = '\0'; v = BLI_ghash_lookup(ghash, w); - EXPECT_EQ(w[0], GET_INT_FROM_POINTER(v)); + EXPECT_EQ(GET_INT_FROM_POINTER(v), w[0]); w = c + 1; } } @@ -195,7 +195,7 @@ static void int_ghash_tests(GHash *ghash, const char *id, const unsigned int nbr while (i--) { void *v = BLI_ghash_lookup(ghash, SET_UINT_IN_POINTER(i)); - EXPECT_EQ(i, GET_UINT_FROM_POINTER(v)); + EXPECT_EQ(GET_UINT_FROM_POINTER(v), i); } TIMEIT_END(int_lookup); @@ -214,7 +214,7 @@ static void int_ghash_tests(GHash *ghash, const char *id, const unsigned int nbr TIMEIT_END(int_pop); } - EXPECT_EQ(0, BLI_ghash_size(ghash)); + EXPECT_EQ(BLI_ghash_size(ghash), 0); BLI_ghash_free(ghash, NULL, NULL); @@ -292,7 +292,7 @@ static void randint_ghash_tests(GHash *ghash, const char *id, const unsigned int for (i = nbr, dt = data; i--; dt++) { void *v = BLI_ghash_lookup(ghash, SET_UINT_IN_POINTER(*dt)); - EXPECT_EQ(*dt, GET_UINT_FROM_POINTER(v)); + EXPECT_EQ(GET_UINT_FROM_POINTER(v), *dt); } TIMEIT_END(int_lookup); @@ -403,7 +403,7 @@ static void int4_ghash_tests(GHash *ghash, const char *id, const unsigned int nb for (i = nbr, dt = data; i--; dt++) { void *v = BLI_ghash_lookup(ghash, (void *)(*dt)); - EXPECT_EQ(i, GET_UINT_FROM_POINTER(v)); + EXPECT_EQ(GET_UINT_FROM_POINTER(v), i); } TIMEIT_END(int_v4_lookup); @@ -469,7 +469,7 @@ static void multi_small_ghash_tests_one(GHash *ghash, RNG *rng, const unsigned i for (i = nbr, dt = data; i--; dt++) { void *v = BLI_ghash_lookup(ghash, SET_UINT_IN_POINTER(*dt)); - EXPECT_EQ(*dt, GET_UINT_FROM_POINTER(v)); + EXPECT_EQ(GET_UINT_FROM_POINTER(v), *dt); } BLI_ghash_clear(ghash, NULL, NULL); diff --git a/tests/gtests/blenlib/BLI_ghash_test.cc b/tests/gtests/blenlib/BLI_ghash_test.cc index ffbe5f5547f..6d075e29114 100644 --- a/tests/gtests/blenlib/BLI_ghash_test.cc +++ b/tests/gtests/blenlib/BLI_ghash_test.cc @@ -62,11 +62,11 @@ TEST(ghash, InsertLookup) BLI_ghash_insert(ghash, SET_UINT_IN_POINTER(*k), SET_UINT_IN_POINTER(*k)); } - EXPECT_EQ(TESTCASE_SIZE, BLI_ghash_size(ghash)); + EXPECT_EQ(BLI_ghash_size(ghash), TESTCASE_SIZE); for (i = TESTCASE_SIZE, k = keys; i--; k++) { void *v = BLI_ghash_lookup(ghash, SET_UINT_IN_POINTER(*k)); - EXPECT_EQ(*k, GET_UINT_FROM_POINTER(v)); + EXPECT_EQ(GET_UINT_FROM_POINTER(v), *k); } BLI_ghash_free(ghash, NULL, NULL); @@ -85,16 +85,16 @@ TEST(ghash, InsertRemove) BLI_ghash_insert(ghash, SET_UINT_IN_POINTER(*k), SET_UINT_IN_POINTER(*k)); } - EXPECT_EQ(TESTCASE_SIZE, BLI_ghash_size(ghash)); + EXPECT_EQ(BLI_ghash_size(ghash), TESTCASE_SIZE); bkt_size = BLI_ghash_buckets_size(ghash); for (i = TESTCASE_SIZE, k = keys; i--; k++) { void *v = BLI_ghash_popkey(ghash, SET_UINT_IN_POINTER(*k), NULL); - EXPECT_EQ(*k, GET_UINT_FROM_POINTER(v)); + EXPECT_EQ(GET_UINT_FROM_POINTER(v), *k); } - EXPECT_EQ(0, BLI_ghash_size(ghash)); - EXPECT_EQ(bkt_size, BLI_ghash_buckets_size(ghash)); + EXPECT_EQ(BLI_ghash_size(ghash), 0); + EXPECT_EQ(BLI_ghash_buckets_size(ghash), bkt_size); BLI_ghash_free(ghash, NULL, NULL); } @@ -113,15 +113,15 @@ TEST(ghash, InsertRemoveShrink) BLI_ghash_insert(ghash, SET_UINT_IN_POINTER(*k), SET_UINT_IN_POINTER(*k)); } - EXPECT_EQ(TESTCASE_SIZE, BLI_ghash_size(ghash)); + EXPECT_EQ(BLI_ghash_size(ghash), TESTCASE_SIZE); bkt_size = BLI_ghash_buckets_size(ghash); for (i = TESTCASE_SIZE, k = keys; i--; k++) { void *v = BLI_ghash_popkey(ghash, SET_UINT_IN_POINTER(*k), NULL); - EXPECT_EQ(*k, GET_UINT_FROM_POINTER(v)); + EXPECT_EQ(GET_UINT_FROM_POINTER(v), *k); } - EXPECT_EQ(0, BLI_ghash_size(ghash)); + EXPECT_EQ(BLI_ghash_size(ghash), 0); EXPECT_LT(BLI_ghash_buckets_size(ghash), bkt_size); BLI_ghash_free(ghash, NULL, NULL); @@ -141,16 +141,16 @@ TEST(ghash, Copy) BLI_ghash_insert(ghash, SET_UINT_IN_POINTER(*k), SET_UINT_IN_POINTER(*k)); } - EXPECT_EQ(TESTCASE_SIZE, BLI_ghash_size(ghash)); + EXPECT_EQ(BLI_ghash_size(ghash), TESTCASE_SIZE); ghash_copy = BLI_ghash_copy(ghash, NULL, NULL); - EXPECT_EQ(TESTCASE_SIZE, BLI_ghash_size(ghash_copy)); - EXPECT_EQ(BLI_ghash_buckets_size(ghash), BLI_ghash_buckets_size(ghash_copy)); + EXPECT_EQ(BLI_ghash_size(ghash_copy), TESTCASE_SIZE); + EXPECT_EQ(BLI_ghash_buckets_size(ghash_copy), BLI_ghash_buckets_size(ghash)); for (i = TESTCASE_SIZE, k = keys; i--; k++) { void *v = BLI_ghash_lookup(ghash_copy, SET_UINT_IN_POINTER(*k)); - EXPECT_EQ(*k, GET_UINT_FROM_POINTER(v)); + EXPECT_EQ(GET_UINT_FROM_POINTER(v), *k); } BLI_ghash_free(ghash, NULL, NULL); @@ -171,7 +171,7 @@ TEST(ghash, Pop) BLI_ghash_insert(ghash, SET_UINT_IN_POINTER(*k), SET_UINT_IN_POINTER(*k)); } - EXPECT_EQ(TESTCASE_SIZE, BLI_ghash_size(ghash)); + EXPECT_EQ(BLI_ghash_size(ghash), TESTCASE_SIZE); GHashIterState pop_state = {0}; @@ -179,14 +179,14 @@ TEST(ghash, Pop) void *k, *v; bool success = BLI_ghash_pop(ghash, &pop_state, &k, &v); EXPECT_EQ(k, v); - EXPECT_EQ(success, true); + EXPECT_TRUE(success); if (i % 2) { BLI_ghash_insert(ghash, SET_UINT_IN_POINTER(i * 4), SET_UINT_IN_POINTER(i * 4)); } } - EXPECT_EQ((TESTCASE_SIZE - TESTCASE_SIZE / 2 + TESTCASE_SIZE / 4), BLI_ghash_size(ghash)); + EXPECT_EQ(BLI_ghash_size(ghash), (TESTCASE_SIZE - TESTCASE_SIZE / 2 + TESTCASE_SIZE / 4)); { void *k, *v; @@ -194,7 +194,7 @@ TEST(ghash, Pop) EXPECT_EQ(k, v); } } - EXPECT_EQ(0, BLI_ghash_size(ghash)); + EXPECT_EQ(BLI_ghash_size(ghash), 0); BLI_ghash_free(ghash, NULL, NULL); } diff --git a/tests/gtests/blenlib/BLI_hash_mm2a_test.cc b/tests/gtests/blenlib/BLI_hash_mm2a_test.cc index b35a1a809d6..109c925af4c 100644 --- a/tests/gtests/blenlib/BLI_hash_mm2a_test.cc +++ b/tests/gtests/blenlib/BLI_hash_mm2a_test.cc @@ -19,9 +19,9 @@ TEST(hash_mm2a, MM2ABasic) BLI_hash_mm2a_init(&mm2, 0); BLI_hash_mm2a_add(&mm2, (const unsigned char *)data, strlen(data)); #ifdef __LITTLE_ENDIAN__ - EXPECT_EQ(1633988145, BLI_hash_mm2a_end(&mm2)); + EXPECT_EQ(BLI_hash_mm2a_end(&mm2), 1633988145); #else - EXPECT_EQ(959283772, BLI_hash_mm2a_end(&mm2)); + EXPECT_EQ(BLI_hash_mm2a_end(&mm2), 959283772); #endif } @@ -43,11 +43,11 @@ TEST(hash_mm2a, MM2AConcatenateStrings) BLI_hash_mm2a_init(&mm2, 0); BLI_hash_mm2a_add(&mm2, (const unsigned char *)data123, strlen(data123)); #ifdef __LITTLE_ENDIAN__ - EXPECT_EQ(1545105348, hash); + EXPECT_EQ(hash, 1545105348); #else - EXPECT_EQ(2604964730, hash); + EXPECT_EQ(hash, 2604964730); #endif - EXPECT_EQ(hash, BLI_hash_mm2a_end(&mm2)); + EXPECT_EQ(BLI_hash_mm2a_end(&mm2), hash); } TEST(hash_mm2a, MM2AIntegers) @@ -67,9 +67,9 @@ TEST(hash_mm2a, MM2AIntegers) BLI_hash_mm2a_add(&mm2, (const unsigned char *)ints, sizeof(ints)); /* Yes, same hash here on little and big endian. */ #ifdef __LITTLE_ENDIAN__ - EXPECT_EQ(405493096, hash); + EXPECT_EQ(hash, 405493096); #else - EXPECT_EQ(405493096, hash); + EXPECT_EQ(hash, 405493096); #endif - EXPECT_EQ(hash, BLI_hash_mm2a_end(&mm2)); + EXPECT_EQ(BLI_hash_mm2a_end(&mm2), hash); } diff --git a/tests/gtests/blenlib/BLI_kdopbvh_test.cc b/tests/gtests/blenlib/BLI_kdopbvh_test.cc new file mode 100644 index 00000000000..74db7cf20a0 --- /dev/null +++ b/tests/gtests/blenlib/BLI_kdopbvh_test.cc @@ -0,0 +1,97 @@ +/* Apache License, Version 2.0 */ + +#include "testing/testing.h" + +/* TODO: ray intersection, overlap ... etc.*/ + +extern "C" { +#include "BLI_compiler_attrs.h" +#include "BLI_kdopbvh.h" +#include "BLI_rand.h" +#include "BLI_math_vector.h" +#include "MEM_guardedalloc.h" +} + +#include "stubs/bf_intern_eigen_stubs.h" + +/* -------------------------------------------------------------------- */ +/* Helper Functions */ + +static void rng_v3_round( + float *coords, int coords_len, + struct RNG *rng, int round, float scale) +{ + for (int i = 0; i < coords_len; i++) { + float f = BLI_rng_get_float(rng) * 2.0f - 1.0f; + coords[i] = ((float)((int)(f * round)) / (float)round) * scale; + } +} + +/* -------------------------------------------------------------------- */ +/* Tests */ + +TEST(kdopbvh, Empty) +{ + BVHTree *tree = BLI_bvhtree_new(0, 0.0, 8, 8); + BLI_bvhtree_balance(tree); + EXPECT_EQ(0, BLI_bvhtree_get_size(tree)); + BLI_bvhtree_free(tree); +} + +TEST(kdopbvh, Single) +{ + BVHTree *tree = BLI_bvhtree_new(1, 0.0, 8, 8); + { + float co[3] = {0}; + BLI_bvhtree_insert(tree, 0, co, 1); + } + + EXPECT_EQ(BLI_bvhtree_get_size(tree), 1); + + BLI_bvhtree_balance(tree); + BLI_bvhtree_free(tree); +} + +/** + * Note that a small epsilon is added to the BVH nodes bounds, even if we pass in zero. + * Use rounding to ensure very close nodes don't cause the wrong node to be found as nearest. + */ +static void find_nearest_points_test(int points_len, float scale, int round, int random_seed) +{ + struct RNG *rng = BLI_rng_new(random_seed); + BVHTree *tree = BLI_bvhtree_new(points_len, 0.0, 8, 8); + + void *mem = MEM_mallocN(sizeof(float[3]) * points_len, __func__); + float (*points)[3] = (float (*)[3])mem; + + for (int i = 0; i < points_len; i++) { + rng_v3_round(points[i], 3, rng, round, scale); + BLI_bvhtree_insert(tree, i, points[i], 1); + } + BLI_bvhtree_balance(tree); + /* first find each point */ + for (int i = 0; i < points_len; i++) { + const int j = BLI_bvhtree_find_nearest(tree, points[i], NULL, NULL, NULL); + if (j != i) { +#if 0 + const float dist = len_v3v3(points[i], points[j]); + if (dist > (1.0f / (float)round)) { + printf("%.15f (%d %d)\n", dist, i, j); + print_v3_id(points[i]); + print_v3_id(points[j]); + fflush(stdout); + } +#endif + EXPECT_GE(j, 0); + EXPECT_LT(j, points_len); + EXPECT_EQ_ARRAY(points[i], points[j], 3); + } + } + BLI_bvhtree_free(tree); + BLI_rng_free(rng); + MEM_freeN(points); +} + +TEST(kdopbvh, FindNearest_1) { find_nearest_points_test(1, 1.0, 1000, 1234); } +TEST(kdopbvh, FindNearest_2) { find_nearest_points_test(2, 1.0, 1000, 123); } +TEST(kdopbvh, FindNearest_500) { find_nearest_points_test(500, 1.0, 1000, 12); } diff --git a/tests/gtests/blenlib/BLI_listbase_test.cc b/tests/gtests/blenlib/BLI_listbase_test.cc index 994b8f74541..4dac2d05bd8 100644 --- a/tests/gtests/blenlib/BLI_listbase_test.cc +++ b/tests/gtests/blenlib/BLI_listbase_test.cc @@ -74,25 +74,25 @@ TEST(listbase, FindLinkOrIndex) /* Empty list */ BLI_listbase_clear(&lb); - EXPECT_EQ(NULL, BLI_findlink(&lb, -1)); - EXPECT_EQ(NULL, BLI_findlink(&lb, 0)); - EXPECT_EQ(NULL, BLI_findlink(&lb, 1)); - EXPECT_EQ(NULL, BLI_rfindlink(&lb, -1)); - EXPECT_EQ(NULL, BLI_rfindlink(&lb, 0)); - EXPECT_EQ(NULL, BLI_rfindlink(&lb, 1)); - EXPECT_EQ(-1, BLI_findindex(&lb, link1)); + EXPECT_EQ(BLI_findlink(&lb, -1), (void*)NULL); + EXPECT_EQ(BLI_findlink(&lb, 0), (void*)NULL); + EXPECT_EQ(BLI_findlink(&lb, 1), (void*)NULL); + EXPECT_EQ(BLI_rfindlink(&lb, -1), (void*)NULL); + EXPECT_EQ(BLI_rfindlink(&lb, 0), (void*)NULL); + EXPECT_EQ(BLI_rfindlink(&lb, 1), (void*)NULL); + EXPECT_EQ(BLI_findindex(&lb, link1), -1); /* One link */ BLI_addtail(&lb, link1); - EXPECT_EQ(link1, BLI_findlink(&lb, 0)); - EXPECT_EQ(link1, BLI_rfindlink(&lb, 0)); - EXPECT_EQ(0, BLI_findindex(&lb, link1)); + EXPECT_EQ(BLI_findlink(&lb, 0), link1); + EXPECT_EQ(BLI_rfindlink(&lb, 0), link1); + EXPECT_EQ(BLI_findindex(&lb, link1), 0); /* Two links */ BLI_addtail(&lb, link2); - EXPECT_EQ(link2, BLI_findlink(&lb, 1)); - EXPECT_EQ(link2, BLI_rfindlink(&lb, 0)); - EXPECT_EQ(1, BLI_findindex(&lb, link2)); + EXPECT_EQ(BLI_findlink(&lb, 1), link2); + EXPECT_EQ(BLI_rfindlink(&lb, 0), link2); + EXPECT_EQ(BLI_findindex(&lb, link2), 1); BLI_freelistN(&lb); } diff --git a/tests/gtests/blenlib/BLI_math_geom_test.cc b/tests/gtests/blenlib/BLI_math_geom_test.cc index cd15a4eb8ff..92e2532392e 100644 --- a/tests/gtests/blenlib/BLI_math_geom_test.cc +++ b/tests/gtests/blenlib/BLI_math_geom_test.cc @@ -4,6 +4,8 @@ #include "BLI_math.h" +#include "stubs/bf_intern_eigen_stubs.h" + TEST(math_geom, DistToLine2DSimple) { float p[2] = {5.0f, 1.0f}, diff --git a/tests/gtests/blenlib/BLI_path_util_test.cc b/tests/gtests/blenlib/BLI_path_util_test.cc index c80987c3586..41fad661ea9 100644 --- a/tests/gtests/blenlib/BLI_path_util_test.cc +++ b/tests/gtests/blenlib/BLI_path_util_test.cc @@ -5,6 +5,7 @@ extern "C" { #include "BLI_fileops.h" #include "BLI_path_util.h" +#include "BLI_string.h" #include "../../../source/blender/imbuf/IMB_imbuf.h" #ifdef _WIN32 @@ -40,7 +41,7 @@ const char *GHOST_getSystemDir(int version, const char *versionstr) struct ImBuf; void IMB_freeImBuf(struct ImBuf *ibuf) {} -struct ImBuf *IMB_dupImBuf(struct ImBuf *ibuf) {return NULL;} +struct ImBuf *IMB_dupImBuf(const ImBuf *ibuf) {return NULL;} #ifdef __linux__ char *zLhm65070058860608_br_find_exe(const char *default_exe) @@ -57,7 +58,7 @@ char *zLhm65070058860608_br_find_exe(const char *default_exe) /* BLI_cleanup_path */ #ifndef _WIN32 -TEST(path_util, PathUtilClean) +TEST(path_util, Clean) { /* "/./" -> "/" */ { @@ -113,50 +114,280 @@ TEST(path_util, PathUtilClean) } #endif + +#define AT_INDEX(str_input, index_input, str_expect) \ + { \ + char path[] = str_input; \ + const char *expect = str_expect; \ + int index_output, len_output; \ + const bool ret = BLI_path_name_at_index(path, index_input, &index_output, &len_output); \ + if (expect == NULL) { \ + EXPECT_EQ(ret, false); \ + } \ + else { \ + EXPECT_EQ(ret, true); \ + EXPECT_EQ(strlen(expect), len_output); \ + path[index_output + len_output] = '\0'; \ + EXPECT_STREQ(&path[index_output], expect); \ + } \ + }((void)0) + +/* BLI_path_name_at_index */ +TEST(path_util, NameAtIndex_Single) +{ + AT_INDEX("/a", 0, "a"); + AT_INDEX("/a/", 0, "a"); + AT_INDEX("a/", 0, "a"); + AT_INDEX("//a//", 0, "a"); + AT_INDEX("a/b", 0, "a"); + + AT_INDEX("/a", 1, NULL); + AT_INDEX("/a/", 1, NULL); + AT_INDEX("a/", 1, NULL); + AT_INDEX("//a//", 1, NULL); +} +TEST(path_util, NameAtIndex_SingleNeg) +{ + AT_INDEX("/a", -1, "a"); + AT_INDEX("/a/", -1, "a"); + AT_INDEX("a/", -1, "a"); + AT_INDEX("//a//", -1, "a"); + AT_INDEX("a/b", -1, "b"); + + AT_INDEX("/a", -2, NULL); + AT_INDEX("/a/", -2, NULL); + AT_INDEX("a/", -2, NULL); + AT_INDEX("//a//", -2, NULL); +} + +TEST(path_util, NameAtIndex_Double) +{ + AT_INDEX("/ab", 0, "ab"); + AT_INDEX("/ab/", 0, "ab"); + AT_INDEX("ab/", 0, "ab"); + AT_INDEX("//ab//", 0, "ab"); + AT_INDEX("ab/c", 0, "ab"); + + AT_INDEX("/ab", 1, NULL); + AT_INDEX("/ab/", 1, NULL); + AT_INDEX("ab/", 1, NULL); + AT_INDEX("//ab//", 1, NULL); +} + +TEST(path_util, NameAtIndex_DoublNeg) +{ + AT_INDEX("/ab", -1, "ab"); + AT_INDEX("/ab/", -1, "ab"); + AT_INDEX("ab/", -1, "ab"); + AT_INDEX("//ab//", -1, "ab"); + AT_INDEX("ab/c", -1, "c"); + + AT_INDEX("/ab", -2, NULL); + AT_INDEX("/ab/", -2, NULL); + AT_INDEX("ab/", -2, NULL); + AT_INDEX("//ab//", -2, NULL); +} + +TEST(path_util, NameAtIndex_Misc) +{ + AT_INDEX("/how/now/brown/cow", 0, "how"); + AT_INDEX("/how/now/brown/cow", 1, "now"); + AT_INDEX("/how/now/brown/cow", 2, "brown"); + AT_INDEX("/how/now/brown/cow", 3, "cow"); + AT_INDEX("/how/now/brown/cow", 4, NULL); + AT_INDEX("/how/now/brown/cow/", 4, NULL); +} + +TEST(path_util, NameAtIndex_MiscNeg) +{ + AT_INDEX("/how/now/brown/cow", 0, "how"); + AT_INDEX("/how/now/brown/cow", 1, "now"); + AT_INDEX("/how/now/brown/cow", 2, "brown"); + AT_INDEX("/how/now/brown/cow", 3, "cow"); + AT_INDEX("/how/now/brown/cow", 4, NULL); + AT_INDEX("/how/now/brown/cow/", 4, NULL); +} + +TEST(path_util, NameAtIndex_MiscComplex) +{ + AT_INDEX("how//now/brown/cow", 0, "how"); + AT_INDEX("//how///now\\/brown/cow", 1, "now"); + AT_INDEX("/how/now\\//brown\\/cow", 2, "brown"); + AT_INDEX("/how/now/brown/cow//\\", 3, "cow"); + AT_INDEX("/how/now/brown/\\cow", 4, NULL); + AT_INDEX("how/now/brown/\\cow\\", 4, NULL); +} + +TEST(path_util, NameAtIndex_MiscComplexNeg) +{ + AT_INDEX("how//now/brown/cow", -4, "how"); + AT_INDEX("//how///now\\/brown/cow", -3, "now"); + AT_INDEX("/how/now\\//brown\\/cow", -2, "brown"); + AT_INDEX("/how/now/brown/cow//\\", -1, "cow"); + AT_INDEX("/how/now/brown/\\cow", -5, NULL); + AT_INDEX("how/now/brown/\\cow\\", -5, NULL); +} + +TEST(path_util, NameAtIndex_NoneComplex) +{ + AT_INDEX("", 0, NULL); + AT_INDEX("/", 0, NULL); + AT_INDEX("//", 0, NULL); + AT_INDEX("///", 0, NULL); +} + +TEST(path_util, NameAtIndex_NoneComplexNeg) +{ + AT_INDEX("", -1, NULL); + AT_INDEX("/", -1, NULL); + AT_INDEX("//", -1, NULL); + AT_INDEX("///", -1, NULL); +} + +#undef AT_INDEX + +#define JOIN(str_expect, out_size, ...) \ + { \ + const char *expect = str_expect; \ + char result[(out_size) + 1024]; \ + /* check we don't write past the last byte */ \ + result[out_size] = '\0'; \ + BLI_path_join(result, out_size, __VA_ARGS__, NULL); \ + /* simplify expected string */ \ + BLI_str_replace_char(result, '\\', '/'); \ + EXPECT_STREQ(result, expect); \ + EXPECT_EQ(result[out_size], '\0'); \ + } ((void)0) + +/* BLI_path_join */ +TEST(path_util, JoinNop) +{ + JOIN("", 100, ""); + JOIN("", 100, "", ""); + JOIN("", 100, "", "", ""); + JOIN("/", 100, "/", "", ""); + JOIN("/", 100, "/", "/"); + JOIN("/", 100, "/", "", "/"); + JOIN("/", 100, "/", "", "/", ""); +} + +TEST(path_util, JoinSingle) +{ + JOIN("test", 100, "test"); + JOIN("", 100, ""); + JOIN("a", 100, "a"); + JOIN("/a", 100, "/a"); + JOIN("a/", 100, "a/"); + JOIN("/a/", 100, "/a/"); + JOIN("/a/", 100, "/a//"); + JOIN("//a/", 100, "//a//"); +} + +TEST(path_util, JoinTriple) +{ + JOIN("/a/b/c", 100, "/a", "b", "c"); + JOIN("/a/b/c", 100, "/a/", "/b/", "/c"); + JOIN("/a/b/c", 100, "/a/b/", "/c"); + JOIN("/a/b/c", 100, "/a/b/c"); + JOIN("/a/b/c", 100, "/", "a/b/c"); + + JOIN("/a/b/c/", 100, "/a/", "/b/", "/c/"); + JOIN("/a/b/c/", 100, "/a/b/c/"); + JOIN("/a/b/c/", 100, "/a/b/", "/c/"); + JOIN("/a/b/c/", 100, "/a/b/c", "/"); + JOIN("/a/b/c/", 100, "/", "a/b/c", "/"); +} + +TEST(path_util, JoinTruncateShort) +{ + JOIN("", 1, "/"); + JOIN("/", 2, "/"); + JOIN("a", 2, "", "aa"); + JOIN("a", 2, "", "a/"); + JOIN("a/b", 4, "a", "bc"); + JOIN("ab/", 4, "ab", "c"); + JOIN("/a/", 4, "/a", "b"); + JOIN("/a/", 4, "/a/", "b/"); + JOIN("/a/", 4, "/a", "/b/"); + JOIN("/a/", 4, "/", "a/b/"); + JOIN("//a", 4, "//", "a/b/"); + + JOIN("/a/b", 5, "/a", "b", "c"); +} + +TEST(path_util, JoinTruncateLong) +{ + JOIN("", 1, "//", "//longer", "path"); + JOIN("/", 2, "//", "//longer", "path"); + JOIN("//", 3, "//", "//longer", "path"); + JOIN("//l", 4, "//", "//longer", "path"); + /* snip */ + JOIN("//longe", 8, "//", "//longer", "path"); + JOIN("//longer", 9, "//", "//longer", "path"); + JOIN("//longer/", 10, "//", "//longer", "path"); + JOIN("//longer/p", 11, "//", "//longer", "path"); + JOIN("//longer/pa", 12, "//", "//longer", "path"); + JOIN("//longer/pat", 13, "//", "//longer", "path"); + JOIN("//longer/path", 14, "//", "//longer", "path"); // not truncated + JOIN("//longer/path", 14, "//", "//longer", "path/"); + JOIN("//longer/path/", 15, "//", "//longer", "path/"); // not truncated + JOIN("//longer/path/", 15, "//", "//longer", "path/", "trunc"); + JOIN("//longer/path/t", 16, "//", "//longer", "path/", "trunc"); +} + +TEST(path_util, JoinComplex) +{ + JOIN("/a/b/c/d/e/f/g/", 100, "/", "\\a/b", "//////c/d", "", "e\\\\", "f", "g//"); + JOIN("/aa/bb/cc/dd/ee/ff/gg/", 100, "/", "\\aa/bb", "//////cc/dd", "", "ee\\\\", "ff", "gg//"); + JOIN("1/2/3/", 100, "1", "////////", "", "2", "3\\"); +} + +#undef JOIN + /* BLI_path_frame */ -TEST(path_util, PathUtilFrame) +TEST(path_util, Frame) { bool ret; { char path[FILE_MAX] = ""; ret = BLI_path_frame(path, 123, 1); - EXPECT_EQ(1, ret); + EXPECT_EQ(ret, 1); EXPECT_STREQ("123", path); } { char path[FILE_MAX] = ""; ret = BLI_path_frame(path, 123, 12); - EXPECT_EQ(1, ret); + EXPECT_EQ(ret, 1); EXPECT_STREQ("000000000123", path); } { char path[FILE_MAX] = "test_"; ret = BLI_path_frame(path, 123, 1); - EXPECT_EQ(1, ret); + EXPECT_EQ(ret, 1); EXPECT_STREQ("test_123", path); } { char path[FILE_MAX] = "test_"; ret = BLI_path_frame(path, 1, 12); - EXPECT_EQ(1, ret); + EXPECT_EQ(ret, 1); EXPECT_STREQ("test_000000000001", path); } { char path[FILE_MAX] = "test_############"; ret = BLI_path_frame(path, 1, 0); - EXPECT_EQ(1, ret); + EXPECT_EQ(ret, 1); EXPECT_STREQ("test_000000000001", path); } { char path[FILE_MAX] = "test_#_#_middle"; ret = BLI_path_frame(path, 123, 0); - EXPECT_EQ(1, ret); + EXPECT_EQ(ret, 1); EXPECT_STREQ("test_#_123_middle", path); } @@ -164,20 +395,20 @@ TEST(path_util, PathUtilFrame) { char path[FILE_MAX] = ""; ret = BLI_path_frame(path, 123, 0); - EXPECT_EQ(0, ret); + EXPECT_EQ(ret, 0); EXPECT_STREQ("", path); } { char path[FILE_MAX] = "test_middle"; ret = BLI_path_frame(path, 123, 0); - EXPECT_EQ(0, ret); + EXPECT_EQ(ret, 0); EXPECT_STREQ("test_middle", path); } } /* BLI_split_dirfile */ -TEST(path_util, PathUtilSplitDirfile) +TEST(path_util, SplitDirfile) { { const char *path = ""; diff --git a/tests/gtests/blenlib/BLI_polyfill2d_test.cc b/tests/gtests/blenlib/BLI_polyfill2d_test.cc index a4ed70fbec9..df98ead4cb9 100644 --- a/tests/gtests/blenlib/BLI_polyfill2d_test.cc +++ b/tests/gtests/blenlib/BLI_polyfill2d_test.cc @@ -27,6 +27,8 @@ extern "C" { #endif } +#include "stubs/bf_intern_eigen_stubs.h" + static void polyfill_to_obj( const char *id, const float poly[][2], const unsigned int poly_tot, @@ -98,14 +100,14 @@ static void test_polyfill_topology( } } } - EXPECT_EQ(poly_tot + (poly_tot - 3), BLI_edgehash_size(edgehash)); + EXPECT_EQ(BLI_edgehash_size(edgehash), poly_tot + (poly_tot - 3)); for (i = 0; i < poly_tot; i++) { const unsigned int v1 = i; const unsigned int v2 = (i + 1) % poly_tot; void **p = BLI_edgehash_lookup_p(edgehash, v1, v2); - EXPECT_EQ(1, (void *)p != NULL); - EXPECT_EQ(1, (intptr_t)*p); + EXPECT_EQ((void *)p != NULL, 1); + EXPECT_EQ((intptr_t)*p, 1); } for (ehi = BLI_edgehashIterator_new(edgehash), i = 0; @@ -113,7 +115,7 @@ static void test_polyfill_topology( BLI_edgehashIterator_step(ehi), i++) { void **p = BLI_edgehashIterator_getValue_p(ehi); - EXPECT_EQ(true, ELEM((intptr_t)*p, 1, 2)); + EXPECT_TRUE(ELEM((intptr_t)*p, 1, 2)); } BLI_edgehashIterator_free(ehi); @@ -135,7 +137,7 @@ static void test_polyfill_winding( count[winding_test < 0.0f] += 1; } } - EXPECT_EQ(true, ELEM(0, count[0], count[1])); + EXPECT_TRUE(ELEM(0, count[0], count[1])); } /** @@ -208,6 +210,26 @@ static void test_polyfill_template( #endif } +static void test_polyfill_template_flip_sign( + const char *id, bool is_degenerate, + const float poly[][2], const unsigned int poly_tot, + unsigned int tris[][3], const unsigned int tris_tot) +{ + float (*poly_copy)[2] = (float (*)[2])MEM_mallocN(sizeof(float[2]) * poly_tot, id); + for (int flip_x = 0; flip_x < 2; flip_x++) { + for (int flip_y = 0; flip_y < 2; flip_y++) { + float sign_x = flip_x ? -1.0f : 1.0f; + float sign_y = flip_y ? -1.0f : 1.0f; + for (int i = 0; i < poly_tot; i++) { + poly_copy[i][0] = poly[i][0] * sign_x; + poly_copy[i][1] = poly[i][1] * sign_y; + } + test_polyfill_template(id, is_degenerate, poly_copy, poly_tot, tris, tris_tot); + } + } + MEM_freeN(poly_copy); +} + #ifdef USE_COMBINATIONS_ALL static void test_polyfill_template_main( const char *id, bool is_degenerate, @@ -230,7 +252,7 @@ static void test_polyfill_template_main( for (poly_cycle = 0; poly_cycle < poly_tot; poly_cycle++) { // printf("polytest %s ofs=%d, reverse=%d\n", id, poly_cycle, poly_reverse); - test_polyfill_template(id, is_degenerate, poly, poly_tot, tris, tris_tot); + test_polyfill_template_flip_sign(id, is_degenerate, poly, poly_tot, tris, tris_tot); /* cycle */ copy_v2_v2(tmp, poly_copy[0]); @@ -247,7 +269,7 @@ static void test_polyfill_template_main( const float poly[][2], const unsigned int poly_tot, unsigned int tris[][3], const unsigned int tris_tot) { - test_polyfill_template(id, is_degenerate, poly, poly_tot, tris, tris_tot); + test_polyfill_template_flip_sign(id, is_degenerate, poly, poly_tot, tris, tris_tot); } #endif /* USE_COMBINATIONS_ALL */ @@ -307,6 +329,43 @@ static void polyfill_to_obj( /* -------------------------------------------------------------------- */ /* tests */ +/** + * Script to generate the data below: + * + * \code{.py} + * # This example assumes we have a mesh object in edit-mode + * + * import bpy + * import bmesh + * + * obj = bpy.context.edit_object + * me = obj.data + * bm = bmesh.from_edit_mesh(me) + * + * def clean_float(num): + * if int(num) == num: + * return str(int(num)) + * prec = 1 + * while True: + * text = f"{num:.{prec}f}" + * if float(text) == num: + * return text + * prec += 1 + * + * for f in bm.faces: + * if f.select: + * print(f"\t// data for face: {f.index}") + * print("\tconst float poly[][2] = {", end="") + * coords = [[clean_float(num) for num in l.vert.co[0:2]] for l in f.loops] + * print("\t ", end="") + * for i, (x, y) in enumerate(coords): + * if (i % 2) == 0: + * print("\n\t ", end="") + * print(f"{{{x}, {y}}}", end=",") + * print("\n\t};") + * \endcode + */ + #define POLY_TRI_COUNT(len) ((len) - 2) @@ -517,3 +576,17 @@ TEST(polyfill2d, IssueT41986_axis_align) TEST_POLYFILL_TEMPLATE_STATIC(poly, false); } + +/* Blender bug T52834 */ +TEST(polyfill2d, IssueT52834_axis_align_co_linear) +{ + const float poly[][2] = { + {40, 0}, {36, 0}, {36, 5}, {35, 5}, {35, 0}, {30, 0}, {30, 5}, {29, 5}, {29, 0}, {24, 0}, {24, 3}, + {23, 4}, {23, 0}, {18, 0}, {18, 5}, {17, 5}, {17, 0}, {12, 0}, {12, 5}, {11, 5}, {11, 0}, {6, 0}, + {6, 5}, {5, 5}, {5, 0}, {0, 0}, {0, 5}, {-1, 5}, {-1, 0}, {-6, 0}, {-9, -3}, {-6, -3}, {-6, -2}, + {-1, -2}, {0, -2}, {5, -2}, {6, -2}, {11, -2}, {12, -2}, {17, -2}, {18, -2}, {23, -2}, {24, -2}, + {29, -2}, {30, -2}, {35, -2}, {36, -2}, {40, -2}, + }; + + TEST_POLYFILL_TEMPLATE_STATIC(poly, false); +} diff --git a/tests/gtests/blenlib/BLI_stack_test.cc b/tests/gtests/blenlib/BLI_stack_test.cc index 4c0b95f4b6b..18188937355 100644 --- a/tests/gtests/blenlib/BLI_stack_test.cc +++ b/tests/gtests/blenlib/BLI_stack_test.cc @@ -24,7 +24,7 @@ TEST(stack, Empty) BLI_Stack *stack; stack = BLI_stack_new(sizeof(int), __func__); - EXPECT_EQ(BLI_stack_is_empty(stack), true); + EXPECT_TRUE(BLI_stack_is_empty(stack)); EXPECT_EQ(BLI_stack_count(stack), 0); BLI_stack_free(stack); } @@ -37,11 +37,11 @@ TEST(stack, One) stack = BLI_stack_new(sizeof(in), __func__); BLI_stack_push(stack, (void *)&in); - EXPECT_EQ(BLI_stack_is_empty(stack), false); + EXPECT_FALSE(BLI_stack_is_empty(stack)); EXPECT_EQ(BLI_stack_count(stack), 1); BLI_stack_pop(stack, (void *)&out); - EXPECT_EQ(in, out); - EXPECT_EQ(BLI_stack_is_empty(stack), true); + EXPECT_EQ(out, in); + EXPECT_TRUE(BLI_stack_is_empty(stack)); EXPECT_EQ(BLI_stack_count(stack), 0); BLI_stack_free(stack); } @@ -59,12 +59,12 @@ TEST(stack, Range) } for (in = tot - 1; in >= 0; in--) { - EXPECT_EQ(BLI_stack_is_empty(stack), false); + EXPECT_FALSE(BLI_stack_is_empty(stack)); BLI_stack_pop(stack, (void *)&out); - EXPECT_EQ(in, out); + EXPECT_EQ(out, in); } - EXPECT_EQ(BLI_stack_is_empty(stack), true); + EXPECT_TRUE(BLI_stack_is_empty(stack)); BLI_stack_free(stack); } @@ -86,12 +86,12 @@ TEST(stack, String) } for (i = tot - 1; i >= 0; i--) { - EXPECT_EQ(BLI_stack_is_empty(stack), false); + EXPECT_FALSE(BLI_stack_is_empty(stack)); *((int *)in) = i; BLI_stack_pop(stack, (void *)&out); EXPECT_STREQ(in, out); } - EXPECT_EQ(BLI_stack_is_empty(stack), true); + EXPECT_TRUE(BLI_stack_is_empty(stack)); BLI_stack_free(stack); } @@ -115,7 +115,7 @@ TEST(stack, Peek) EXPECT_EQ(*ret, in[i % ARRAY_SIZE(in)]); } - EXPECT_EQ(BLI_stack_is_empty(stack), true); + EXPECT_TRUE(BLI_stack_is_empty(stack)); BLI_stack_free(stack); } @@ -140,7 +140,7 @@ TEST(stack, Clear) } BLI_stack_clear(stack); - EXPECT_EQ(BLI_stack_is_empty(stack), true); + EXPECT_TRUE(BLI_stack_is_empty(stack)); /* and again, this time check its valid */ for (in = 0; in < tot; in++) { @@ -148,12 +148,12 @@ TEST(stack, Clear) } for (in = tot - 1; in >= 0; in--) { - EXPECT_EQ(BLI_stack_is_empty(stack), false); + EXPECT_FALSE(BLI_stack_is_empty(stack)); BLI_stack_pop(stack, (void *)&out); - EXPECT_EQ(in, out); + EXPECT_EQ(out, in); } - EXPECT_EQ(BLI_stack_is_empty(stack), true); + EXPECT_TRUE(BLI_stack_is_empty(stack)); /* without this, we wont test case when mixed free/used */ tot /= 2; @@ -204,10 +204,10 @@ TEST(stack, Reuse) while (!BLI_stack_is_empty(stack)) { i--; BLI_stack_pop(stack, (void *)&sizes_test[i]); - EXPECT_EQ(sizes[i], sizes_test[i]); + EXPECT_EQ(sizes_test[i], sizes[i]); EXPECT_GT(i, -1); } - EXPECT_EQ(i, 0); + EXPECT_EQ(0, i); EXPECT_EQ(memcmp(sizes, sizes_test, sizeof(sizes) - sizeof(int)), 0); diff --git a/tests/gtests/blenlib/BLI_string_test.cc b/tests/gtests/blenlib/BLI_string_test.cc index 17a4b5e82b9..f6f7e17c8ca 100644 --- a/tests/gtests/blenlib/BLI_string_test.cc +++ b/tests/gtests/blenlib/BLI_string_test.cc @@ -44,7 +44,7 @@ TEST(string, StrPartition) /* "mat.e-r_ial" -> "mat", '.', "e-r_ial", 3 */ pre_ln = BLI_str_partition(str, delim, &sep, &suf); - EXPECT_EQ(3, pre_ln); + EXPECT_EQ(pre_ln, 3); EXPECT_EQ(&str[3], sep); EXPECT_STREQ("e-r_ial", suf); } @@ -55,7 +55,7 @@ TEST(string, StrPartition) /* ".mate-rial--" -> "", '.', "mate-rial--", 0 */ pre_ln = BLI_str_partition(str, delim, &sep, &suf); - EXPECT_EQ(0, pre_ln); + EXPECT_EQ(pre_ln, 0); EXPECT_EQ(&str[0], sep); EXPECT_STREQ("mate-rial--", suf); } @@ -65,7 +65,7 @@ TEST(string, StrPartition) /* ".__.--_" -> "", '.', "__.--_", 0 */ pre_ln = BLI_str_partition(str, delim, &sep, &suf); - EXPECT_EQ(0, pre_ln); + EXPECT_EQ(pre_ln, 0); EXPECT_EQ(&str[0], sep); EXPECT_STREQ("__.--_", suf); } @@ -75,9 +75,9 @@ TEST(string, StrPartition) /* "" -> "", NULL, NULL, 0 */ pre_ln = BLI_str_partition(str, delim, &sep, &suf); - EXPECT_EQ(0, pre_ln); - EXPECT_EQ(NULL, sep); - EXPECT_EQ(NULL, suf); + EXPECT_EQ(pre_ln, 0); + EXPECT_EQ(sep, (void*)NULL); + EXPECT_EQ(suf, (void*)NULL); } { @@ -85,9 +85,9 @@ TEST(string, StrPartition) /* "material" -> "material", NULL, NULL, 8 */ pre_ln = BLI_str_partition(str, delim, &sep, &suf); - EXPECT_EQ(8, pre_ln); - EXPECT_EQ(NULL, sep); - EXPECT_EQ(NULL, suf); + EXPECT_EQ(pre_ln, 8); + EXPECT_EQ(sep, (void*)NULL); + EXPECT_EQ(suf, (void*)NULL); } } @@ -103,7 +103,7 @@ TEST(string, StrRPartition) /* "mat.e-r_ial" -> "mat.e-r", '_', "ial", 7 */ pre_ln = BLI_str_rpartition(str, delim, &sep, &suf); - EXPECT_EQ(7, pre_ln); + EXPECT_EQ(pre_ln, 7); EXPECT_EQ(&str[7], sep); EXPECT_STREQ("ial", suf); } @@ -114,7 +114,7 @@ TEST(string, StrRPartition) /* ".mate-rial--" -> ".mate-rial-", '-', "", 11 */ pre_ln = BLI_str_rpartition(str, delim, &sep, &suf); - EXPECT_EQ(11, pre_ln); + EXPECT_EQ(pre_ln, 11); EXPECT_EQ(&str[11], sep); EXPECT_STREQ("", suf); } @@ -124,7 +124,7 @@ TEST(string, StrRPartition) /* ".__.--_" -> ".__.--", '_', "", 6 */ pre_ln = BLI_str_rpartition(str, delim, &sep, &suf); - EXPECT_EQ(6, pre_ln); + EXPECT_EQ(pre_ln, 6); EXPECT_EQ(&str[6], sep); EXPECT_STREQ("", suf); } @@ -134,9 +134,9 @@ TEST(string, StrRPartition) /* "" -> "", NULL, NULL, 0 */ pre_ln = BLI_str_rpartition(str, delim, &sep, &suf); - EXPECT_EQ(0, pre_ln); - EXPECT_EQ(NULL, sep); - EXPECT_EQ(NULL, suf); + EXPECT_EQ(pre_ln, 0); + EXPECT_EQ(sep, (void*)NULL); + EXPECT_EQ(suf, (void*)NULL); } { @@ -144,9 +144,9 @@ TEST(string, StrRPartition) /* "material" -> "material", NULL, NULL, 8 */ pre_ln = BLI_str_rpartition(str, delim, &sep, &suf); - EXPECT_EQ(8, pre_ln); - EXPECT_EQ(NULL, sep); - EXPECT_EQ(NULL, suf); + EXPECT_EQ(pre_ln, 8); + EXPECT_EQ(sep, (void*)NULL); + EXPECT_EQ(suf, (void*)NULL); } } @@ -164,7 +164,7 @@ TEST(string, StrPartitionEx) /* "mat.e-r_ia.l" over "mat.e-r" -> "mat.e", '.', "r_ia.l", 3 */ pre_ln = BLI_str_partition_ex(str, str + 6, delim, &sep, &suf, true); - EXPECT_EQ(5, pre_ln); + EXPECT_EQ(pre_ln, 5); EXPECT_EQ(&str[5], sep); EXPECT_STREQ("r_ia.l", suf); } @@ -175,9 +175,9 @@ TEST(string, StrPartitionEx) /* "mate.rial" over "mate" -> "mate.rial", NULL, NULL, 4 */ pre_ln = BLI_str_partition_ex(str, str + 4, delim, &sep, &suf, true); - EXPECT_EQ(4, pre_ln); - EXPECT_EQ(NULL, sep); - EXPECT_EQ(NULL, suf); + EXPECT_EQ(pre_ln, 4); + EXPECT_EQ(sep, (void*)NULL); + EXPECT_EQ(suf, (void*)NULL); } } @@ -193,7 +193,7 @@ TEST(string, StrPartitionUtf8) /* "ma\xc3\xb1te-r\xe2\x98\xafial" -> "ma", '\xc3\xb1', "te-r\xe2\x98\xafial", 2 */ pre_ln = BLI_str_partition_utf8(str, delim, &sep, &suf); - EXPECT_EQ(2, pre_ln); + EXPECT_EQ(pre_ln, 2); EXPECT_EQ(&str[2], sep); EXPECT_STREQ("te-r\xe2\x98\xafial", suf); } @@ -204,7 +204,7 @@ TEST(string, StrPartitionUtf8) /* "\xe2\x98\xafmate-rial-\xc3\xb1" -> "", '\xe2\x98\xaf', "mate-rial-\xc3\xb1", 0 */ pre_ln = BLI_str_partition_utf8(str, delim, &sep, &suf); - EXPECT_EQ(0, pre_ln); + EXPECT_EQ(pre_ln, 0); EXPECT_EQ(&str[0], sep); EXPECT_STREQ("mate-rial-\xc3\xb1", suf); } @@ -214,7 +214,7 @@ TEST(string, StrPartitionUtf8) /* "\xe2\x98\xaf.\xc3\xb1_.--\xc3\xb1" -> "", '\xe2\x98\xaf', ".\xc3\xb1_.--\xc3\xb1", 0 */ pre_ln = BLI_str_partition_utf8(str, delim, &sep, &suf); - EXPECT_EQ(0, pre_ln); + EXPECT_EQ(pre_ln, 0); EXPECT_EQ(&str[0], sep); EXPECT_STREQ(".\xc3\xb1_.--\xc3\xb1", suf); } @@ -224,9 +224,9 @@ TEST(string, StrPartitionUtf8) /* "" -> "", NULL, NULL, 0 */ pre_ln = BLI_str_partition_utf8(str, delim, &sep, &suf); - EXPECT_EQ(0, pre_ln); - EXPECT_EQ(NULL, sep); - EXPECT_EQ(NULL, suf); + EXPECT_EQ(pre_ln, 0); + EXPECT_EQ(sep, (void*)NULL); + EXPECT_EQ(suf, (void*)NULL); } { @@ -234,9 +234,9 @@ TEST(string, StrPartitionUtf8) /* "material" -> "material", NULL, NULL, 8 */ pre_ln = BLI_str_partition_utf8(str, delim, &sep, &suf); - EXPECT_EQ(8, pre_ln); - EXPECT_EQ(NULL, sep); - EXPECT_EQ(NULL, suf); + EXPECT_EQ(pre_ln, 8); + EXPECT_EQ(sep, (void*)NULL); + EXPECT_EQ(suf, (void*)NULL); } } @@ -252,7 +252,7 @@ TEST(string, StrRPartitionUtf8) /* "ma\xc3\xb1te-r\xe2\x98\xafial" -> "mat\xc3\xb1te-r", '\xe2\x98\xaf', "ial", 8 */ pre_ln = BLI_str_rpartition_utf8(str, delim, &sep, &suf); - EXPECT_EQ(8, pre_ln); + EXPECT_EQ(pre_ln, 8); EXPECT_EQ(&str[8], sep); EXPECT_STREQ("ial", suf); } @@ -263,7 +263,7 @@ TEST(string, StrRPartitionUtf8) /* "\xe2\x98\xafmate-rial-\xc3\xb1" -> "\xe2\x98\xafmate-rial-", '\xc3\xb1', "", 13 */ pre_ln = BLI_str_rpartition_utf8(str, delim, &sep, &suf); - EXPECT_EQ(13, pre_ln); + EXPECT_EQ(pre_ln, 13); EXPECT_EQ(&str[13], sep); EXPECT_STREQ("", suf); } @@ -273,7 +273,7 @@ TEST(string, StrRPartitionUtf8) /* "\xe2\x98\xaf.\xc3\xb1_.--\xc3\xb1" -> "\xe2\x98\xaf.\xc3\xb1_.--", '\xc3\xb1', "", 10 */ pre_ln = BLI_str_rpartition_utf8(str, delim, &sep, &suf); - EXPECT_EQ(10, pre_ln); + EXPECT_EQ(pre_ln, 10); EXPECT_EQ(&str[10], sep); EXPECT_STREQ("", suf); } @@ -283,9 +283,9 @@ TEST(string, StrRPartitionUtf8) /* "" -> "", NULL, NULL, 0 */ pre_ln = BLI_str_rpartition_utf8(str, delim, &sep, &suf); - EXPECT_EQ(0, pre_ln); - EXPECT_EQ(NULL, sep); - EXPECT_EQ(NULL, suf); + EXPECT_EQ(pre_ln, 0); + EXPECT_EQ(sep, (void*)NULL); + EXPECT_EQ(suf, (void*)NULL); } { @@ -293,9 +293,9 @@ TEST(string, StrRPartitionUtf8) /* "material" -> "material", NULL, NULL, 8 */ pre_ln = BLI_str_rpartition_utf8(str, delim, &sep, &suf); - EXPECT_EQ(8, pre_ln); - EXPECT_EQ(NULL, sep); - EXPECT_EQ(NULL, suf); + EXPECT_EQ(pre_ln, 8); + EXPECT_EQ(sep, (void*)NULL); + EXPECT_EQ(suf, (void*)NULL); } } @@ -313,7 +313,7 @@ TEST(string, StrPartitionExUtf8) /* "ma\xc3\xb1te-r\xe2\x98\xafial" over "ma\xc3\xb1te" -> "ma", '\xc3\xb1', "te-r\xe2\x98\xafial", 2 */ pre_ln = BLI_str_partition_ex_utf8(str, str + 6, delim, &sep, &suf, true); - EXPECT_EQ(2, pre_ln); + EXPECT_EQ(pre_ln, 2); EXPECT_EQ(&str[2], sep); EXPECT_STREQ("te-r\xe2\x98\xafial", suf); } @@ -324,9 +324,9 @@ TEST(string, StrPartitionExUtf8) /* "mate\xe2\x98\xafrial" over "mate" -> "mate\xe2\x98\xafrial", NULL, NULL, 4 */ pre_ln = BLI_str_partition_ex_utf8(str, str + 4, delim, &sep, &suf, true); - EXPECT_EQ(4, pre_ln); - EXPECT_EQ(NULL, sep); - EXPECT_EQ(NULL, suf); + EXPECT_EQ(pre_ln, 4); + EXPECT_EQ(sep, (void*)NULL); + EXPECT_EQ(suf, (void*)NULL); } } @@ -373,8 +373,8 @@ TEST(string, StrFormatIntGrouped) const int word_cmp_size = ARRAY_SIZE(word_cmp); \ const int word_num = BLI_string_find_split_words( \ word_str_src, word_str_src_len, ' ', word_info, word_cmp_size_input); \ - EXPECT_EQ(word_num, word_cmp_size - 1); \ - EXPECT_EQ_ARRAY_ND(word_cmp, word_info, word_cmp_size, 2); \ + EXPECT_EQ(word_cmp_size - 1, word_num); \ + EXPECT_EQ_ARRAY_ND<const int[2]>(word_cmp, word_info, word_cmp_size, 2); \ } ((void)0) #define STRING_FIND_SPLIT_WORDS(word_str_src, ...) \ @@ -449,20 +449,20 @@ TEST(string, StringStrncasestr) const char *res; res = BLI_strncasestr(str_test0, "", 0); - EXPECT_EQ(str_test0, res); + EXPECT_EQ(res, str_test0); res = BLI_strncasestr(str_test0, " ", 1); - EXPECT_EQ(str_test0 + 6, res); + EXPECT_EQ(res, str_test0 + 6); res = BLI_strncasestr(str_test0, "her", 3); - EXPECT_EQ(str_test0 + 7, res); + EXPECT_EQ(res, str_test0 + 7); res = BLI_strncasestr(str_test0, "ARCh", 4); - EXPECT_EQ(str_test0 + 2, res); + EXPECT_EQ(res, str_test0 + 2); res = BLI_strncasestr(str_test0, "earcq", 4); - EXPECT_EQ(str_test0 + 1, res); + EXPECT_EQ(res, str_test0 + 1); res = BLI_strncasestr(str_test0, "not there", 9); - EXPECT_EQ(NULL, res); + EXPECT_EQ(res, (void*)NULL); } diff --git a/tests/gtests/blenlib/BLI_string_utf8_test.cc b/tests/gtests/blenlib/BLI_string_utf8_test.cc new file mode 100644 index 00000000000..95d73b4242f --- /dev/null +++ b/tests/gtests/blenlib/BLI_string_utf8_test.cc @@ -0,0 +1,304 @@ +/* Apache License, Version 2.0 */ + +#include "testing/testing.h" + +extern "C" { +#include "BLI_utildefines.h" +#include "BLI_string.h" +#include "BLI_string_utf8.h" +} + +/* Note that 'common' utf-8 variants of string functions (like copy, etc.) are tested in BLI_string_test.cc + * However, tests below are specific utf-8 conformance ones, and since they eat quite their share of lines, + * they deserved their own file. */ + +/* -------------------------------------------------------------------- */ +/* stubs */ + +extern "C" { + +int mk_wcwidth(wchar_t ucs); +int mk_wcswidth(const wchar_t *pwcs, size_t n); + +int mk_wcwidth(wchar_t ucs) +{ + return 0; +} + +int mk_wcswidth(const wchar_t *pwcs, size_t n) +{ + return 0; +} + +} + +/* -------------------------------------------------------------------- */ +/* tests */ + +/* Each test is made of a 79 bytes (80 with NULL char) string to test, expected string result after + * stripping invalid utf8 bytes, and a single-byte string encoded with expected number of errors. + * + * Based on utf-8 decoder stress-test (https://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt) + * by Markus Kuhn <http://www.cl.cam.ac.uk/~mgk25/> - 2015-08-28 - CC BY 4.0 + */ +const char *utf8_invalid_tests[][3] = { +// 1 Some correct UTF-8 text + {"You should see the Greek word 'kosme': \"\xce\xba\xe1\xbd\xb9\xcf\x83\xce\xbc\xce\xb5\" |", + "You should see the Greek word 'kosme': \"\xce\xba\xe1\xbd\xb9\xcf\x83\xce\xbc\xce\xb5\" |", "\x00"}, + +// 2 Boundary condition test cases +// Note that those will pass for us, those are not erronéous unicode code points +// (asside from \x00, which is only valid as string terminator). +// 2.1 First possible sequence of a certain length + {"2.1.1 1 byte (U-00000000): \"\x00\" |", + "2.1.1 1 byte (U-00000000): \"\" |", "\x01"}, + {"2.1.2 2 bytes (U-00000080): \"\xc2\x80\" |", + "2.1.2 2 bytes (U-00000080): \"\xc2\x80\" |", "\x00"}, + {"2.1.3 3 bytes (U-00000800): \"\xe0\xa0\x80\" |", + "2.1.3 3 bytes (U-00000800): \"\xe0\xa0\x80\" |", "\x00"}, + {"2.1.4 4 bytes (U-00010000): \"\xf0\x90\x80\x80\" |", + "2.1.4 4 bytes (U-00010000): \"\xf0\x90\x80\x80\" |", "\x00"}, + {"2.1.5 5 bytes (U-00200000): \"\xf8\x88\x80\x80\x80\" |", + "2.1.5 5 bytes (U-00200000): \"\xf8\x88\x80\x80\x80\" |", "\x00"}, + {"2.1.6 6 bytes (U-04000000): \"\xfc\x84\x80\x80\x80\x80\" |", + "2.1.6 6 bytes (U-04000000): \"\xfc\x84\x80\x80\x80\x80\" |", "\x00"}, +// 2.2 Last possible sequence of a certain length + {"2.2.1 1 byte (U-0000007F): \"\x7f\" |", + "2.2.1 1 byte (U-0000007F): \"\x7f\" |", "\x00"}, + {"2.2.2 2 bytes (U-000007FF): \"\xdf\xbf\" |", + "2.2.2 2 bytes (U-000007FF): \"\xdf\xbf\" |", "\x00"}, + {"2.2.3 3 bytes (U-0000FFFF): \"\xef\xbf\xbf\" |", + "2.2.3 3 bytes (U-0000FFFF): \"\" |", "\x03"}, /* matches one of 5.3 sequences... */ + {"2.2.4 4 bytes (U-001FFFFF): \"\xf7\xbf\xbf\xbf\" |", + "2.2.4 4 bytes (U-001FFFFF): \"\xf7\xbf\xbf\xbf\" |", "\x00"}, + {"2.2.5 5 bytes (U-03FFFFFF): \"\xfb\xbf\xbf\xbf\xbf\" |", + "2.2.5 5 bytes (U-03FFFFFF): \"\xfb\xbf\xbf\xbf\xbf\" |", "\x00"}, + {"2.2.6 6 bytes (U-7FFFFFFF): \"\xfd\xbf\xbf\xbf\xbf\xbf\" |", + "2.2.6 6 bytes (U-7FFFFFFF): \"\xfd\xbf\xbf\xbf\xbf\xbf\" |", "\x00"}, +// 2.3 Other boundary conditions + {"2.3.1 U-0000D7FF = ed 9f bf = \"\xed\x9f\xbf\" |", + "2.3.1 U-0000D7FF = ed 9f bf = \"\xed\x9f\xbf\" |", "\x00"}, + {"2.3.2 U-0000E000 = ee 80 80 = \"\xee\x80\x80\" |", + "2.3.2 U-0000E000 = ee 80 80 = \"\xee\x80\x80\" |", "\x00"}, + {"2.3.3 U-0000FFFD = ef bf bd = \"\xef\xbf\xbd\" |", + "2.3.3 U-0000FFFD = ef bf bd = \"\xef\xbf\xbd\" |", "\x00"}, + {"2.3.4 U-0010FFFF = f4 8f bf bf = \"\xf4\x8f\xbf\xbf\" |", + "2.3.4 U-0010FFFF = f4 8f bf bf = \"\xf4\x8f\xbf\xbf\" |", "\x00"}, + {"2.3.5 U-00110000 = f4 90 80 80 = \"\xf4\x90\x80\x80\" |", + "2.3.5 U-00110000 = f4 90 80 80 = \"\xf4\x90\x80\x80\" |", "\x00"}, + +// 3 Malformed sequences +// 3.1 Unexpected continuation bytes +// Each unexpected continuation byte should be separately signalled as a malformed sequence of its own. + {"3.1.1 First continuation byte 0x80: \"\x80\" |", + "3.1.1 First continuation byte 0x80: \"\" |", "\x01"}, + {"3.1.2 Last continuation byte 0xbf: \"\xbf\" |", + "3.1.2 Last continuation byte 0xbf: \"\" |", "\x01"}, + {"3.1.3 2 continuation bytes: \"\x80\xbf\" |", + "3.1.3 2 continuation bytes: \"\" |", "\x02"}, + {"3.1.4 3 continuation bytes: \"\x80\xbf\x80\" |", + "3.1.4 3 continuation bytes: \"\" |", "\x03"}, + {"3.1.5 4 continuation bytes: \"\x80\xbf\x80\xbf\" |", + "3.1.5 4 continuation bytes: \"\" |", "\x04"}, + {"3.1.6 5 continuation bytes: \"\x80\xbf\x80\xbf\x80\" |", + "3.1.6 5 continuation bytes: \"\" |", "\x05"}, + {"3.1.7 6 continuation bytes: \"\x80\xbf\x80\xbf\x80\xbf\" |", + "3.1.7 6 continuation bytes: \"\" |", "\x06"}, + {"3.1.8 7 continuation bytes: \"\x80\xbf\x80\xbf\x80\xbf\x80\" |", + "3.1.8 7 continuation bytes: \"\" |", "\x07"}, +// 3.1.9 Sequence of all 64 possible continuation bytes (0x80-0xbf): | + {"3.1.9 \"\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f" + "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f" + "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf" + "\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\" |", + "3.1.9 \"\" |", "\x40"}, +// 3.2 Lonely start characters +// 3.2.1 All 32 first bytes of 2-byte sequences (0xc0-0xdf), each followed by a space character: + {"3.2.1 \"\xc0 \xc1 \xc2 \xc3 \xc4 \xc5 \xc6 \xc7 \xc8 \xc9 \xca \xcb \xcc \xcd \xce \xcf " + "\xd0 \xd1 \xd2 \xd3 \xd4 \xd5 \xd6 \xd7 \xd8 \xd9 \xda \xdb \xdc \xdd \xde \xdf \" |", + "3.2.1 \" \" |", "\x20"}, +// 3.2.2 All 16 first bytes of 3-byte sequences (0xe0-0xef), each followed by a space character: + {"3.2.2 \"\xe0 \xe1 \xe2 \xe3 \xe4 \xe5 \xe6 \xe7 \xe8 \xe9 \xea \xeb \xec \xed \xee \xef \" |", + "3.2.2 \" \" |", "\x10"}, +// 3.2.3 All 8 first bytes of 4-byte sequences (0xf0-0xf7), each followed by a space character: + {"3.2.3 \"\xf0 \xf1 \xf2 \xf3 \xf4 \xf5 \xf6 \xf7 \" |", + "3.2.3 \" \" |", "\x08"}, +// 3.2.4 All 4 first bytes of 5-byte sequences (0xf8-0xfb), each followed by a space character: + {"3.2.4 \"\xf8 \xf9 \xfa \xfb \" |", + "3.2.4 \" \" |", "\x04"}, +// 3.2.5 All 2 first bytes of 6-byte sequences (0xfc-0xfd), each followed by a space character: + {"3.2.4 \"\xfc \xfd \" |", + "3.2.4 \" \" |", "\x02"}, +// 3.3 Sequences with last continuation byte missing +// All bytes of an incomplete sequence should be signalled as a single malformed sequence, +// i.e., you should see only a single replacement character in each of the next 10 tests. +// (Characters as in section 2) + {"3.3.1 2-byte sequence with last byte missing (U+0000): \"\xc0\" |", + "3.3.1 2-byte sequence with last byte missing (U+0000): \"\" |", "\x01"}, + {"3.3.2 3-byte sequence with last byte missing (U+0000): \"\xe0\x80\" |", + "3.3.2 3-byte sequence with last byte missing (U+0000): \"\" |", "\x02"}, + {"3.3.3 4-byte sequence with last byte missing (U+0000): \"\xf0\x80\x80\" |", + "3.3.3 4-byte sequence with last byte missing (U+0000): \"\" |", "\x03"}, + {"3.3.4 5-byte sequence with last byte missing (U+0000): \"\xf8\x80\x80\x80\" |", + "3.3.4 5-byte sequence with last byte missing (U+0000): \"\" |", "\x04"}, + {"3.3.5 6-byte sequence with last byte missing (U+0000): \"\xfc\x80\x80\x80\x80\" |", + "3.3.5 6-byte sequence with last byte missing (U+0000): \"\" |", "\x05"}, + {"3.3.6 2-byte sequence with last byte missing (U-000007FF): \"\xdf\" |", + "3.3.6 2-byte sequence with last byte missing (U-000007FF): \"\" |", "\x01"}, + {"3.3.7 3-byte sequence with last byte missing (U-0000FFFF): \"\xef\xbf\" |", + "3.3.7 3-byte sequence with last byte missing (U-0000FFFF): \"\" |", "\x02"}, + {"3.3.8 4-byte sequence with last byte missing (U-001FFFFF): \"\xf7\xbf\xbf\" |", + "3.3.8 4-byte sequence with last byte missing (U-001FFFFF): \"\" |", "\x03"}, + {"3.3.9 5-byte sequence with last byte missing (U-03FFFFFF): \"\xfb\xbf\xbf\xbf\" |", + "3.3.9 5-byte sequence with last byte missing (U-03FFFFFF): \"\" |", "\x04"}, + {"3.3.10 6-byte sequence with last byte missing (U-7FFFFFFF): \"\xfd\xbf\xbf\xbf\xbf\" |", + "3.3.10 6-byte sequence with last byte missing (U-7FFFFFFF): \"\" |", "\x05"}, +// 3.4 Concatenation of incomplete sequences +// All the 10 sequences of 3.3 concatenated, you should see 10 malformed sequences being signalled: + {"3.4 \"\xc0\xe0\x80\xf0\x80\x80\xf8\x80\x80\x80\xfc\x80\x80\x80\x80" + "\xdf\xef\xbf\xf7\xbf\xbf\xfb\xbf\xbf\xbf\xfd\xbf\xbf\xbf\xbf\"" + " |", + "3.4 \"\" |", "\x1e"}, +// 3.5 Impossible bytes +// The following two bytes cannot appear in a correct UTF-8 string + {"3.5.1 fe = \"\xfe\" |", + "3.5.1 fe = \"\" |", "\x01"}, + {"3.5.2 ff = \"\xff\" |", + "3.5.2 ff = \"\" |", "\x01"}, + {"3.5.3 fe fe ff ff = \"\xfe\xfe\xff\xff\" |", + "3.5.3 fe fe ff ff = \"\" |", "\x04"}, + +// 4 Overlong sequences +// The following sequences are not malformed according to the letter of the Unicode 2.0 standard. +// However, they are longer then necessary and a correct UTF-8 encoder is not allowed to produce them. +// A "safe UTF-8 decoder" should reject them just like malformed sequences for two reasons: +// (1) It helps to debug applications if overlong sequences are not treated as valid representations +// of characters, because this helps to spot problems more quickly. (2) Overlong sequences provide +// alternative representations of characters, that could maliciously be used to bypass filters that check +// only for ASCII characters. For instance, a 2-byte encoded line feed (LF) would not be caught by a +// line counter that counts only 0x0a bytes, but it would still be processed as a line feed by an unsafe +// UTF-8 decoder later in the pipeline. From a security point of view, ASCII compatibility of UTF-8 +// sequences means also, that ASCII characters are *only* allowed to be represented by ASCII bytes +// in the range 0x00-0x7f. To ensure this aspect of ASCII compatibility, use only "safe UTF-8 decoders" +// that reject overlong UTF-8 sequences for which a shorter encoding exists. +// +// 4.1 Examples of an overlong ASCII character +// With a safe UTF-8 decoder, all of the following five overlong representations of the ASCII character +// slash ("/") should be rejected like a malformed UTF-8 sequence, for instance by substituting it with +// a replacement character. If you see a slash below, you do not have a safe UTF-8 decoder! + {"4.1.1 U+002F = c0 af = \"\xc0\xaf\" |", + "4.1.1 U+002F = c0 af = \"\" |", "\x02"}, + {"4.1.2 U+002F = e0 80 af = \"\xe0\x80\xaf\" |", + "4.1.2 U+002F = e0 80 af = \"\" |", "\x03"}, + {"4.1.3 U+002F = f0 80 80 af = \"\xf0\x80\x80\xaf\" |", + "4.1.3 U+002F = f0 80 80 af = \"\" |", "\x04"}, + {"4.1.4 U+002F = f8 80 80 80 af = \"\xf8\x80\x80\x80\xaf\" |", + "4.1.4 U+002F = f8 80 80 80 af = \"\" |", "\x05"}, + {"4.1.5 U+002F = fc 80 80 80 80 af = \"\xfc\x80\x80\x80\x80\xaf\" |", + "4.1.5 U+002F = fc 80 80 80 80 af = \"\" |", "\x06"}, +// 4.2 Maximum overlong sequences +// Below you see the highest Unicode value that is still resulting in an overlong sequence if represented +// with the given number of bytes. This is a boundary test for safe UTF-8 decoders. All five characters +// should be rejected like malformed UTF-8 sequences. + {"4.2.1 U-0000007F = c1 bf = \"\xc1\xbf\" |", + "4.2.1 U-0000007F = c1 bf = \"\" |", "\x02"}, + {"4.2.2 U-000007FF = e0 9f bf = \"\xe0\x9f\xbf\" |", + "4.2.2 U-000007FF = e0 9f bf = \"\" |", "\x03"}, + {"4.2.3 U-0000FFFF = f0 8f bf bf = \"\xf0\x8f\xbf\xbf\" |", + "4.2.3 U-0000FFFF = f0 8f bf bf = \"\" |", "\x04"}, + {"4.2.4 U-001FFFFF = f8 87 bf bf bf = \"\xf8\x87\xbf\xbf\xbf\" |", + "4.2.4 U-001FFFFF = f8 87 bf bf bf = \"\" |", "\x05"}, + {"4.2.5 U+0000 = fc 83 bf bf bf bf = \"\xfc\x83\xbf\xbf\xbf\xbf\" |", + "4.2.5 U+0000 = fc 83 bf bf bf bf = \"\" |", "\x06"}, +// 4.3 Overlong representation of the NUL character +// The following five sequences should also be rejected like malformed UTF-8 sequences and should not be +// treated like the ASCII NUL character. + {"4.3.1 U+0000 = c0 80 = \"\xc0\x80\" |", + "4.3.1 U+0000 = c0 80 = \"\" |", "\x02"}, + {"4.3.2 U+0000 = e0 80 80 = \"\xe0\x80\x80\" |", + "4.3.2 U+0000 = e0 80 80 = \"\" |", "\x03"}, + {"4.3.3 U+0000 = f0 80 80 80 = \"\xf0\x80\x80\x80\" |", + "4.3.3 U+0000 = f0 80 80 80 = \"\" |", "\x04"}, + {"4.3.4 U+0000 = f8 80 80 80 80 = \"\xf8\x80\x80\x80\x80\" |", + "4.3.4 U+0000 = f8 80 80 80 80 = \"\" |", "\x05"}, + {"4.3.5 U+0000 = fc 80 80 80 80 80 = \"\xfc\x80\x80\x80\x80\x80\" |", + "4.3.5 U+0000 = fc 80 80 80 80 80 = \"\" |", "\x06"}, + +// 5 Illegal code positions +// The following UTF-8 sequences should be rejected like malformed sequences, because they never represent +// valid ISO 10646 characters and a UTF-8 decoder that accepts them might introduce security problems +// comparable to overlong UTF-8 sequences. +// 5.1 Single UTF-16 surrogates + {"5.1.1 U+D800 = ed a0 80 = \"\xed\xa0\x80\" |", + "5.1.1 U+D800 = ed a0 80 = \"\" |", "\x03"}, + {"5.1.2 U+DB7F = ed ad bf = \"\xed\xad\xbf\" |", + "5.1.2 U+DB7F = ed ad bf = \"\" |", "\x03"}, + {"5.1.3 U+DB80 = ed ae 80 = \"\xed\xae\x80\" |", + "5.1.3 U+DB80 = ed ae 80 = \"\" |", "\x03"}, + {"5.1.4 U+DBFF = ed af bf = \"\xed\xaf\xbf\" |", + "5.1.4 U+DBFF = ed af bf = \"\" |", "\x03"}, + {"5.1.5 U+DC00 = ed b0 80 = \"\xed\xb0\x80\" |", + "5.1.5 U+DC00 = ed b0 80 = \"\" |", "\x03"}, + {"5.1.6 U+DF80 = ed be 80 = \"\xed\xbe\x80\" |", + "5.1.6 U+DF80 = ed be 80 = \"\" |", "\x03"}, + {"5.1.7 U+DFFF = ed bf bf = \"\xed\xbf\xbf\" |", + "5.1.7 U+DFFF = ed bf bf = \"\" |", "\x03"}, +// 5.2 Paired UTF-16 surrogates + {"5.2.1 U+D800 U+DC00 = ed a0 80 ed b0 80 = \"\xed\xa0\x80\xed\xb0\x80\" |", + "5.2.1 U+D800 U+DC00 = ed a0 80 ed b0 80 = \"\" |", "\x06"}, + {"5.2.2 U+D800 U+DFFF = ed a0 80 ed bf bf = \"\xed\xa0\x80\xed\xbf\xbf\" |", + "5.2.2 U+D800 U+DFFF = ed a0 80 ed bf bf = \"\" |", "\x06"}, + {"5.2.3 U+DB7F U+DC00 = ed ad bf ed b0 80 = \"\xed\xad\xbf\xed\xb0\x80\" |", + "5.2.3 U+DB7F U+DC00 = ed ad bf ed b0 80 = \"\" |", "\x06"}, + {"5.2.4 U+DB7F U+DFFF = ed ad bf ed bf bf = \"\xed\xad\xbf\xed\xbf\xbf\" |", + "5.2.4 U+DB7F U+DFFF = ed ad bf ed bf bf = \"\" |", "\x06"}, + {"5.2.5 U+DB80 U+DC00 = ed ae 80 ed b0 80 = \"\xed\xae\x80\xed\xb0\x80\" |", + "5.2.5 U+DB80 U+DC00 = ed ae 80 ed b0 80 = \"\" |", "\x06"}, + {"5.2.6 U+DB80 U+DFFF = ed ae 80 ed bf bf = \"\xed\xae\x80\xed\xbf\xbf\" |", + "5.2.6 U+DB80 U+DFFF = ed ae 80 ed bf bf = \"\" |", "\x06"}, + {"5.2.7 U+DBFF U+DC00 = ed af bf ed b0 80 = \"\xed\xaf\xbf\xed\xb0\x80\" |", + "5.2.7 U+DBFF U+DC00 = ed af bf ed b0 80 = \"\" |", "\x06"}, + {"5.2.8 U+DBFF U+DFFF = ed af bf ed bf bf = \"\xed\xaf\xbf\xed\xbf\xbf\" |", + "5.2.8 U+DBFF U+DFFF = ed af bf ed bf bf = \"\" |", "\x06"}, +// 5.3 Noncharacter code positions +// The following "noncharacters" are "reserved for internal use" by applications, and according to older versions +// of the Unicode Standard "should never be interchanged". Unicode Corrigendum #9 dropped the latter restriction. +// Nevertheless, their presence in incoming UTF-8 data can remain a potential security risk, depending +// on what use is made of these codes subsequently. Examples of such internal use: +// - Some file APIs with 16-bit characters may use the integer value -1 = U+FFFF to signal +// an end-of-file (EOF) or error condition. +// - In some UTF-16 receivers, code point U+FFFE might trigger a byte-swap operation +// (to convert between UTF-16LE and UTF-16BE). +// With such internal use of noncharacters, it may be desirable and safer to block those code points in +// UTF-8 decoders, as they should never occur legitimately in incoming UTF-8 data, and could trigger +// unsafe behaviour in subsequent processing. +// +// Particularly problematic noncharacters in 16-bit applications: + {"5.3.1 U+FFFE = ef bf be = \"\xef\xbf\xbe\" |", + "5.3.1 U+FFFE = ef bf be = \"\" |", "\x03"}, + {"5.3.2 U+FFFF = ef bf bf = \"\xef\xbf\xbf\" |", + "5.3.2 U+FFFF = ef bf bf = \"\" |", "\x03"}, + /* Fo now, we ignore those, they do not seem to be crucial anyway... */ +// 5.3.3 U+FDD0 .. U+FDEF +// 5.3.4 U+nFFFE U+nFFFF (for n = 1..10) + {NULL, NULL, NULL} +}; + +/* BLI_utf8_invalid_strip (and indirectly, BLI_utf8_invalid_byte). */ +TEST(string, Utf8InvalidBytes) +{ + for (int i = 0; utf8_invalid_tests[i][0] != NULL; i++) { + const char *tst = utf8_invalid_tests[i][0]; + const char *tst_stripped = utf8_invalid_tests[i][1]; + const int num_errors = (int)utf8_invalid_tests[i][2][0]; + + char buff[80]; + memcpy(buff, tst, sizeof(buff)); + + const int num_errors_found = BLI_utf8_invalid_strip(buff, sizeof(buff) - 1); + + printf("[%02d] -> [%02d] \"%s\" -> \"%s\"\n", num_errors, num_errors_found, tst, buff); + EXPECT_EQ(num_errors_found, num_errors); + EXPECT_STREQ(buff, tst_stripped); + } +} diff --git a/tests/gtests/blenlib/CMakeLists.txt b/tests/gtests/blenlib/CMakeLists.txt index 12112e7a481..ffdb8d08d31 100644 --- a/tests/gtests/blenlib/CMakeLists.txt +++ b/tests/gtests/blenlib/CMakeLists.txt @@ -34,22 +34,27 @@ include_directories(${INC}) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PLATFORM_LINKFLAGS}") set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${PLATFORM_LINKFLAGS_DEBUG}") +if(WIN32) + set(BLI_path_util_extra_libs "bf_blenlib;bf_intern_utfconv;extern_wcwidth;${ZLIB_LIBRARIES}") +else() + set(BLI_path_util_extra_libs "bf_blenlib;extern_wcwidth;${ZLIB_LIBRARIES}") +endif() BLENDER_TEST(BLI_array_store "bf_blenlib") BLENDER_TEST(BLI_array_utils "bf_blenlib") -BLENDER_TEST(BLI_stack "bf_blenlib") -BLENDER_TEST(BLI_math_color "bf_blenlib") -BLENDER_TEST(BLI_math_geom "bf_blenlib;bf_intern_eigen") +BLENDER_TEST(BLI_ghash "bf_blenlib") +BLENDER_TEST(BLI_hash_mm2a "bf_blenlib") +BLENDER_TEST(BLI_kdopbvh "bf_blenlib") +BLENDER_TEST(BLI_listbase "bf_blenlib") BLENDER_TEST(BLI_math_base "bf_blenlib") +BLENDER_TEST(BLI_math_color "bf_blenlib") +BLENDER_TEST(BLI_math_geom "bf_blenlib") +BLENDER_TEST(BLI_path_util "${BLI_path_util_extra_libs}") +BLENDER_TEST(BLI_polyfill2d "bf_blenlib") +BLENDER_TEST(BLI_stack "bf_blenlib") BLENDER_TEST(BLI_string "bf_blenlib") -if(WIN32) - BLENDER_TEST(BLI_path_util "bf_blenlib;bf_intern_utfconv;extern_wcwidth;${ZLIB_LIBRARIES}") -else() - BLENDER_TEST(BLI_path_util "bf_blenlib;extern_wcwidth;${ZLIB_LIBRARIES}") -endif() -BLENDER_TEST(BLI_polyfill2d "bf_blenlib;bf_intern_eigen") -BLENDER_TEST(BLI_listbase "bf_blenlib") -BLENDER_TEST(BLI_hash_mm2a "bf_blenlib") -BLENDER_TEST(BLI_ghash "bf_blenlib") +BLENDER_TEST(BLI_string_utf8 "bf_blenlib") BLENDER_TEST_PERFORMANCE(BLI_ghash_performance "bf_blenlib") + +unset(BLI_path_util_extra_libs) diff --git a/tests/gtests/blenlib/stubs/bf_intern_eigen_stubs.h b/tests/gtests/blenlib/stubs/bf_intern_eigen_stubs.h new file mode 100644 index 00000000000..dad77a257d5 --- /dev/null +++ b/tests/gtests/blenlib/stubs/bf_intern_eigen_stubs.h @@ -0,0 +1,18 @@ +/* Apache License, Version 2.0 */ + +extern "C" { + +bool EIG_self_adjoint_eigen_solve(const int size, const float *matrix, float *r_eigen_values, float *r_eigen_vectors) +{ + BLI_assert(0); + UNUSED_VARS(size, matrix, r_eigen_values, r_eigen_vectors); + return false; +} + +void EIG_svd_square_matrix(const int size, const float *matrix, float *r_U, float *r_S, float *r_V) +{ + BLI_assert(0); + UNUSED_VARS(size, matrix, r_U, r_S, r_V); +} + +} |