From bbac126ab9d815d8519dfe3f008db572a3ea4305 Mon Sep 17 00:00:00 2001 From: Marvin Humphrey Date: Tue, 26 Apr 2016 15:43:31 -0700 Subject: [PATCH 1/3] Switch test macro from signed to unsigned. Use TEST_UINT_EQ instead of TEST_INT_EQ as needed. --- core/Lucy/Test/Index/TestPolyReader.c | 2 +- core/Lucy/Test/Util/TestMemoryPool.c | 12 ++++++------ core/Lucy/Test/Util/TestNumberUtils.c | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/core/Lucy/Test/Index/TestPolyReader.c b/core/Lucy/Test/Index/TestPolyReader.c index 44a99a91a..91ebd98d0 100644 --- a/core/Lucy/Test/Index/TestPolyReader.c +++ b/core/Lucy/Test/Index/TestPolyReader.c @@ -40,7 +40,7 @@ test_sub_tick(TestBatchRunner *runner) { for (i = 1; i < num_segs; i++) { if (PolyReader_sub_tick(offsets, i) != i - 1) { break; } } - TEST_INT_EQ(runner, i, num_segs, "got all sub_tick() calls right"); + TEST_UINT_EQ(runner, i, num_segs, "got all sub_tick() calls right"); DECREF(offsets); FREEMEM(ints); } diff --git a/core/Lucy/Test/Util/TestMemoryPool.c b/core/Lucy/Test/Util/TestMemoryPool.c index 02b2ac73e..7e960ab30 100644 --- a/core/Lucy/Test/Util/TestMemoryPool.c +++ b/core/Lucy/Test/Util/TestMemoryPool.c @@ -39,11 +39,11 @@ TestMemPool_Run_IMP(TestMemoryPool *self, TestBatchRunner *runner) { ptr_a = (char*)MemPool_Grab(mem_pool, 10); size_t expected = sizeof(void*) == 8 ? 16 : 12; - TEST_INT_EQ(runner, MemPool_Get_Consumed(mem_pool), expected, - "Round up allocation to word size"); + TEST_UINT_EQ(runner, MemPool_Get_Consumed(mem_pool), expected, + "Round up allocation to word size"); ptr_b = (char*)MemPool_Grab(mem_pool, 10); - TEST_INT_EQ(runner, MemPool_Get_Consumed(mem_pool), expected * 2, - "Accumulate consumed."); + TEST_UINT_EQ(runner, MemPool_Get_Consumed(mem_pool), expected * 2, + "Accumulate consumed."); ptr_a = ivars->buf; MemPool_Resize(mem_pool, ptr_b, 6); @@ -52,8 +52,8 @@ TestMemPool_Run_IMP(TestMemoryPool *self, TestBatchRunner *runner) { "Resize() adjusts `consumed`"); MemPool_Release_All(mem_pool); - TEST_INT_EQ(runner, MemPool_Get_Consumed(mem_pool), 0, - "Release_All() resets `consumed`"); + TEST_UINT_EQ(runner, MemPool_Get_Consumed(mem_pool), 0, + "Release_All() resets `consumed`"); DECREF(mem_pool); } diff --git a/core/Lucy/Test/Util/TestNumberUtils.c b/core/Lucy/Test/Util/TestNumberUtils.c index 58b60e210..0835b087b 100644 --- a/core/Lucy/Test/Util/TestNumberUtils.c +++ b/core/Lucy/Test/Util/TestNumberUtils.c @@ -167,8 +167,8 @@ test_cu32(TestBatchRunner *runner) { decode = encoded; skip = encoded; for (size_t i = 0; i < count; i++) { - TEST_INT_EQ(runner, NumUtil_decode_cu32(&decode), ints[i], - "cu32 %lu", (long)ints[i]); + TEST_UINT_EQ(runner, NumUtil_decode_cu32(&decode), ints[i], + "cu32 %lu", (unsigned long)ints[i]); NumUtil_skip_cint(&skip); if (decode > limit) { THROW(ERR, "overrun"); } } @@ -185,8 +185,8 @@ test_cu32(TestBatchRunner *runner) { decode = encoded; skip = encoded; for (size_t i = 0; i < count; i++) { - TEST_INT_EQ(runner, NumUtil_decode_cu32(&decode), ints[i], - "padded cu32 %lu", (long)ints[i]); + TEST_UINT_EQ(runner, NumUtil_decode_cu32(&decode), ints[i], + "padded cu32 %lu", (unsigned long)ints[i]); NumUtil_skip_cint(&skip); if (decode > limit) { THROW(ERR, "overrun"); } } @@ -197,7 +197,7 @@ test_cu32(TestBatchRunner *runner) { target = encoded; NumUtil_encode_cu32(UINT32_MAX, &target); decode = encoded; - TEST_INT_EQ(runner, NumUtil_decode_cu32(&decode), UINT32_MAX, "cu32 UINT32_MAX"); + TEST_UINT_EQ(runner, NumUtil_decode_cu32(&decode), UINT32_MAX, "cu32 UINT32_MAX"); FREEMEM(encoded); FREEMEM(ints); @@ -346,7 +346,7 @@ test_bigend_u32(TestBatchRunner *runner) { target = encoded; for (size_t i = 0; i < count; i++) { uint32_t got = NumUtil_decode_bigend_u32(target); - TEST_INT_EQ(runner, got, ints[i], "bigend u32"); + TEST_UINT_EQ(runner, got, ints[i], "bigend u32"); target += sizeof(uint32_t); } From 641449dfe744acce2bcee78f7312d40fbf90dd04 Mon Sep 17 00:00:00 2001 From: Marvin Humphrey Date: Tue, 26 Apr 2016 18:03:08 -0700 Subject: [PATCH 2/3] Be consistent about using correct integer type. --- core/Lucy/Test/Search/TestQueryParserLogic.c | 24 ++++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/core/Lucy/Test/Search/TestQueryParserLogic.c b/core/Lucy/Test/Search/TestQueryParserLogic.c index e3066e16c..22104fd76 100644 --- a/core/Lucy/Test/Search/TestQueryParserLogic.c +++ b/core/Lucy/Test/Search/TestQueryParserLogic.c @@ -477,7 +477,7 @@ logical_test_a_AND_b_AND_c_d(uint32_t boolop) { Query *left = make_poly_query(BOOLOP_AND, a_query, b_query, c_query, NULL); Query *tree = make_poly_query(boolop, left, d_query, NULL); - int32_t num_hits = boolop == BOOLOP_AND ? 1 : 2; + uint32_t num_hits = boolop == BOOLOP_AND ? 1 : 2; return TestQP_new("a AND b AND c d", tree, NULL, num_hits); } @@ -490,7 +490,7 @@ logical_test_a_AND_b_OR_c_d(uint32_t boolop) { Query *inner = make_poly_query(BOOLOP_AND, a_query, b_query, NULL); Query *left = make_poly_query(BOOLOP_OR, inner, c_query, NULL); Query *tree = make_poly_query(boolop, left, d_query, NULL); - int32_t num_hits = boolop == BOOLOP_AND ? 1 : 3; + uint32_t num_hits = boolop == BOOLOP_AND ? 1 : 3; return TestQP_new("a AND b OR c d", tree, NULL, num_hits); } @@ -503,7 +503,7 @@ logical_test_a_OR_b_AND_c_d(uint32_t boolop) { Query *inner = make_poly_query(BOOLOP_AND, b_query, c_query, NULL); Query *left = make_poly_query(BOOLOP_OR, a_query, inner, NULL); Query *tree = make_poly_query(boolop, left, d_query, NULL); - int32_t num_hits = boolop == BOOLOP_AND ? 1 : 4; + uint32_t num_hits = boolop == BOOLOP_AND ? 1 : 4; return TestQP_new("a OR b AND c d", tree, NULL, num_hits); } @@ -516,7 +516,7 @@ logical_test_a_OR_b_OR_c_d(uint32_t boolop) { Query *left = make_poly_query(BOOLOP_OR, a_query, b_query, c_query, NULL); Query *tree = make_poly_query(boolop, left, d_query, NULL); - int32_t num_hits = boolop == BOOLOP_AND ? 1 : 4; + uint32_t num_hits = boolop == BOOLOP_AND ? 1 : 4; return TestQP_new("a OR b OR c d", tree, NULL, num_hits); } @@ -529,7 +529,7 @@ logical_test_a_AND_b_c_AND_d(uint32_t boolop) { Query *left = make_poly_query(BOOLOP_AND, a_query, b_query, NULL); Query *right = make_poly_query(BOOLOP_AND, c_query, d_query, NULL); Query *tree = make_poly_query(boolop, left, right, NULL); - int32_t num_hits = boolop == BOOLOP_AND ? 1 : 3; + uint32_t num_hits = boolop == BOOLOP_AND ? 1 : 3; return TestQP_new("a AND b c AND d", tree, NULL, num_hits); } @@ -542,7 +542,7 @@ logical_test_a_AND_b_c_OR_d(uint32_t boolop) { Query *left = make_poly_query(BOOLOP_AND, a_query, b_query, NULL); Query *right = make_poly_query(BOOLOP_OR, c_query, d_query, NULL); Query *tree = make_poly_query(boolop, left, right, NULL); - int32_t num_hits = boolop == BOOLOP_AND ? 2 : 3; + uint32_t num_hits = boolop == BOOLOP_AND ? 2 : 3; return TestQP_new("a AND b c OR d", tree, NULL, num_hits); } @@ -555,7 +555,7 @@ logical_test_a_OR_b_c_AND_d(uint32_t boolop) { Query *left = make_poly_query(BOOLOP_OR, a_query, b_query, NULL); Query *right = make_poly_query(BOOLOP_AND, c_query, d_query, NULL); Query *tree = make_poly_query(boolop, left, right, NULL); - int32_t num_hits = boolop == BOOLOP_AND ? 1 : 4; + uint32_t num_hits = boolop == BOOLOP_AND ? 1 : 4; return TestQP_new("a OR b c AND d", tree, NULL, num_hits); } @@ -568,7 +568,7 @@ logical_test_a_OR_b_c_OR_d(uint32_t boolop) { Query *left = make_poly_query(BOOLOP_OR, a_query, b_query, NULL); Query *right = make_poly_query(BOOLOP_OR, c_query, d_query, NULL); Query *tree = make_poly_query(boolop, left, right, NULL); - int32_t num_hits = boolop == BOOLOP_AND ? 2 : 4; + uint32_t num_hits = boolop == BOOLOP_AND ? 2 : 4; return TestQP_new("a OR b c OR d", tree, NULL, num_hits); } @@ -581,7 +581,7 @@ logical_test_a_b_AND_c_AND_d(uint32_t boolop) { Query *right = make_poly_query(BOOLOP_AND, b_query, c_query, d_query, NULL); Query *tree = make_poly_query(boolop, a_query, right, NULL); - int32_t num_hits = boolop == BOOLOP_AND ? 1 : 4; + uint32_t num_hits = boolop == BOOLOP_AND ? 1 : 4; return TestQP_new("a b AND c AND d", tree, NULL, num_hits); } @@ -594,7 +594,7 @@ logical_test_a_b_AND_c_OR_d(uint32_t boolop) { Query *inner = make_poly_query(BOOLOP_AND, b_query, c_query, NULL); Query *right = make_poly_query(BOOLOP_OR, inner, d_query, NULL); Query *tree = make_poly_query(boolop, a_query, right, NULL); - int32_t num_hits = boolop == BOOLOP_AND ? 2 : 4; + uint32_t num_hits = boolop == BOOLOP_AND ? 2 : 4; return TestQP_new("a b AND c OR d", tree, NULL, num_hits); } @@ -607,7 +607,7 @@ logical_test_a_b_OR_c_AND_d(uint32_t boolop) { Query *inner = make_poly_query(BOOLOP_AND, c_query, d_query, NULL); Query *right = make_poly_query(BOOLOP_OR, b_query, inner, NULL); Query *tree = make_poly_query(boolop, a_query, right, NULL); - int32_t num_hits = boolop == BOOLOP_AND ? 3 : 4; + uint32_t num_hits = boolop == BOOLOP_AND ? 3 : 4; return TestQP_new("a b OR c AND d", tree, NULL, num_hits); } @@ -620,7 +620,7 @@ logical_test_a_b_OR_c_OR_d(uint32_t boolop) { Query *right = make_poly_query(BOOLOP_OR, b_query, c_query, d_query, NULL); Query *tree = make_poly_query(boolop, a_query, right, NULL); - int32_t num_hits = boolop == BOOLOP_AND ? 3 : 4; + uint32_t num_hits = boolop == BOOLOP_AND ? 3 : 4; return TestQP_new("a b OR c OR d", tree, NULL, num_hits); } From 882fbc1e9e0006e79d4eaaacef8f30444e88c924 Mon Sep 17 00:00:00 2001 From: Marvin Humphrey Date: Tue, 26 Apr 2016 18:05:44 -0700 Subject: [PATCH 3/3] Make straightforward int type adjustments. Either cast or change types to quiet -Wconversion warnings. --- core/Lucy/Test/Analysis/TestNormalizer.c | 2 +- core/Lucy/Test/Index/TestPolyReader.c | 8 ++++---- core/Lucy/Test/Search/TestSeriesMatcher.c | 2 +- core/Lucy/Test/Store/TestIOPrimitives.c | 6 +++--- core/Lucy/Test/Store/TestInStream.c | 2 +- core/Lucy/Test/Util/TestSortExternal.c | 20 ++++++++++---------- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/core/Lucy/Test/Analysis/TestNormalizer.c b/core/Lucy/Test/Analysis/TestNormalizer.c index 2323c2e35..6bb0fb71a 100644 --- a/core/Lucy/Test/Analysis/TestNormalizer.c +++ b/core/Lucy/Test/Analysis/TestNormalizer.c @@ -156,7 +156,7 @@ test_utf8proc_normalization(TestBatchRunner *runner) { // Normalize again. size_t normalized_len = strlen((char*)normalized); uint8_t *dupe; - int32_t dupe_check = utf8proc_map(normalized, normalized_len, &dupe, + int32_t dupe_check = utf8proc_map(normalized, (ssize_t)normalized_len, &dupe, UTF8PROC_STABLE | UTF8PROC_COMPOSE | UTF8PROC_COMPAT | diff --git a/core/Lucy/Test/Index/TestPolyReader.c b/core/Lucy/Test/Index/TestPolyReader.c index 91ebd98d0..e8b8a6703 100644 --- a/core/Lucy/Test/Index/TestPolyReader.c +++ b/core/Lucy/Test/Index/TestPolyReader.c @@ -30,15 +30,15 @@ TestPolyReader_new() { static void test_sub_tick(TestBatchRunner *runner) { - size_t num_segs = 255; + uint32_t num_segs = 255; int32_t *ints = (int32_t*)MALLOCATE(num_segs * sizeof(int32_t)); - size_t i; + uint32_t i; for (i = 0; i < num_segs; i++) { - ints[i] = i; + ints[i] = (int32_t)i; } I32Array *offsets = I32Arr_new(ints, num_segs); for (i = 1; i < num_segs; i++) { - if (PolyReader_sub_tick(offsets, i) != i - 1) { break; } + if (PolyReader_sub_tick(offsets, (int32_t)i) != i - 1) { break; } } TEST_UINT_EQ(runner, i, num_segs, "got all sub_tick() calls right"); DECREF(offsets); diff --git a/core/Lucy/Test/Search/TestSeriesMatcher.c b/core/Lucy/Test/Search/TestSeriesMatcher.c index 0fd0ae621..bdd2e78cc 100644 --- a/core/Lucy/Test/Search/TestSeriesMatcher.c +++ b/core/Lucy/Test/Search/TestSeriesMatcher.c @@ -61,7 +61,7 @@ S_make_series_matcher(I32Array *doc_ids, I32Array *offsets, int32_t doc_max) { static I32Array* S_generate_match_list(int32_t first, int32_t max, int32_t doc_inc) { int32_t count = (max - first + doc_inc - 1) / doc_inc; - int32_t *doc_ids = (int32_t*)MALLOCATE(count * sizeof(int32_t)); + int32_t *doc_ids = (int32_t*)MALLOCATE((size_t)count * sizeof(int32_t)); int32_t doc_id = first; int32_t i = 0; diff --git a/core/Lucy/Test/Store/TestIOPrimitives.c b/core/Lucy/Test/Store/TestIOPrimitives.c index 9b78e8255..e7d32f23a 100644 --- a/core/Lucy/Test/Store/TestIOPrimitives.c +++ b/core/Lucy/Test/Store/TestIOPrimitives.c @@ -48,7 +48,7 @@ test_i8(TestBatchRunner *runner) { int i; for (i = -128; i < 128; i++) { - OutStream_Write_I8(outstream, i); + OutStream_Write_I8(outstream, (int8_t)i); } OutStream_Close(outstream); @@ -72,7 +72,7 @@ test_u8(TestBatchRunner *runner) { int i; for (i = 0; i < 256; i++) { - OutStream_Write_U8(outstream, i); + OutStream_Write_U8(outstream, (uint8_t)i); } OutStream_Close(outstream); @@ -398,7 +398,7 @@ test_cu64(TestBatchRunner *runner) { for (i = 0; i < 1000; i++) { char buffer[10]; const char *buf = buffer; - size_t size = InStream_Read_Raw_C64(raw_instream, buffer); + int size = InStream_Read_Raw_C64(raw_instream, buffer); uint64_t got = NumUtil_decode_cu64(&buf); UNUSED_VAR(size); if (got != ints[i]) { diff --git a/core/Lucy/Test/Store/TestInStream.c b/core/Lucy/Test/Store/TestInStream.c index 3aaf42d40..c32f98580 100644 --- a/core/Lucy/Test/Store/TestInStream.c +++ b/core/Lucy/Test/Store/TestInStream.c @@ -104,7 +104,7 @@ test_Clone_and_Reopen(TestBatchRunner *runner) { InStream *clone; InStream *reopened; - for (uint32_t i = 0; i < 26; i++) { + for (uint8_t i = 0; i < 26; i++) { OutStream_Write_U8(outstream, 'a' + i); } OutStream_Close(outstream); diff --git a/core/Lucy/Test/Util/TestSortExternal.c b/core/Lucy/Test/Util/TestSortExternal.c index c64859525..b55dcc24a 100644 --- a/core/Lucy/Test/Util/TestSortExternal.c +++ b/core/Lucy/Test/Util/TestSortExternal.c @@ -234,12 +234,12 @@ test_sort_packed_ints(TestBatchRunner *runner) { Vector *blobs = Vec_new(num_ints); for (uint32_t i = 0; i < num_ints; ++i) { - char buf[4]; - buf[0] = i >> 24; - buf[1] = i >> 16; - buf[2] = i >> 8; - buf[3] = i; - Blob *blob = Blob_new(buf, 4); + uint8_t buf[4]; + buf[0] = (uint8_t)((i >> 24) & 0xFF); + buf[1] = (uint8_t)((i >> 16) & 0xFF); + buf[2] = (uint8_t)((i >> 8) & 0xFF); + buf[3] = (uint8_t)(i & 0xFF); + Blob *blob = Blob_new((char*)buf, 4); Vec_Push(blobs, (Obj*)blob); } @@ -254,12 +254,12 @@ test_sort_random_strings(TestBatchRunner *runner) { Vector *blobs = Vec_new(num_strings); for (uint32_t i = 0; i < num_strings; ++i) { - char buf[1201]; + uint8_t buf[1201]; int size = rand() % 1200 + 1; for (int i = 0; i < size; ++i) { - buf[i] = rand(); + buf[i] = (uint8_t)(rand() % 256); } - Blob *blob = Blob_new(buf, (size_t)size); + Blob *blob = Blob_new((char*)buf, (size_t)size); Vec_Push(blobs, (Obj*)blob); } @@ -273,7 +273,7 @@ test_sort_random_strings(TestBatchRunner *runner) { static void test_run(TestBatchRunner *runner) { Vector *letters = Vec_new(26); - for (int i = 0; i < 26; ++i) { + for (char i = 0; i < 26; ++i) { char ch = 'a' + i; Blob *blob = Blob_new(&ch, 1); Vec_Push(letters, (Obj*)blob);