Skip to content

Commit

Permalink
Tests: Use proper order for EXPECT_EQ()
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyvfx committed Feb 3, 2017
1 parent aea17a6 commit 030e995
Show file tree
Hide file tree
Showing 13 changed files with 152 additions and 152 deletions.
20 changes: 10 additions & 10 deletions tests/gtests/blenlib/BLI_array_store_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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;

Expand All @@ -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);
}

Expand All @@ -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);
Expand Down Expand Up @@ -425,7 +425,7 @@ TEST(array_store, TextDupeIncreaseDecrease)
testbuffer_list_store_populate(bs, &lb);
EXPECT_TRUE(testbuffer_list_validate(&lb));
EXPECT_TRUE(BLI_array_store_is_valid(bs));
EXPECT_EQ(strlen(D), BLI_array_store_calc_size_compacted_get(bs));
EXPECT_EQ(BLI_array_store_calc_size_compacted_get(bs), strlen(D));

testbuffer_list_store_clear(bs, &lb);
BLI_listbase_reverse(&lb);
Expand All @@ -435,7 +435,7 @@ TEST(array_store, TextDupeIncreaseDecrease)
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); \
Expand Down Expand Up @@ -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);

Expand Down
36 changes: 18 additions & 18 deletions tests/gtests/blenlib/BLI_array_utils_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand Down
18 changes: 9 additions & 9 deletions tests/gtests/blenlib/BLI_ghash_performance_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
32 changes: 16 additions & 16 deletions tests/gtests/blenlib/BLI_ghash_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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};

Expand All @@ -186,15 +186,15 @@ TEST(ghash, Pop)
}
}

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;
while (BLI_ghash_pop(ghash, &pop_state, &k, &v)) {
EXPECT_EQ(k, v);
}
}
EXPECT_EQ(0, BLI_ghash_size(ghash));
EXPECT_EQ(BLI_ghash_size(ghash), 0);

BLI_ghash_free(ghash, NULL, NULL);
}
16 changes: 8 additions & 8 deletions tests/gtests/blenlib/BLI_hash_mm2a_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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)
Expand All @@ -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);
}
Loading

0 comments on commit 030e995

Please sign in to comment.