Skip to content

Commit

Permalink
tests: use ASSERT_EQUAL where applicable (#396)
Browse files Browse the repository at this point in the history
* tests: use ASSERT_EQUAL where applicable

* Update tests/special_tests.cpp

* Update tests/special_tests.cpp

* Update tests/special_tests.cpp

---------

Co-authored-by: Daniel Lemire <daniel@lemire.me>
  • Loading branch information
WojciechMula and lemire committed Apr 10, 2024
1 parent 1de7438 commit 258340b
Show file tree
Hide file tree
Showing 18 changed files with 107 additions and 113 deletions.
18 changes: 9 additions & 9 deletions tests/base64_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ TEST(encode_base64_cases) {
size_t s = implementation.binary_to_base64(p.first.data(), p.first.size(),
buffer.data());
ASSERT_EQUAL(s, p.second.size());
ASSERT_TRUE(std::string(buffer.data(), buffer.size()) == p.second);
ASSERT_EQUAL(std::string(buffer.data(), buffer.size()), p.second);
}
printf(" -- ");
for (std::pair<std::string, std::string> p : cases) {
Expand Down Expand Up @@ -233,7 +233,7 @@ TEST(encode_base64url_cases) {
printf(" %.*s\n", (int)s, buffer.data());
printf(" %.*s\n", (int)s, p.second.data());
}
ASSERT_TRUE(std::string(buffer.data(), buffer.size()) == p.second);
ASSERT_EQUAL(std::string(buffer.data(), buffer.size()), p.second);
}
printf(" -- ");
for (std::pair<std::string, std::string> p : cases) {
Expand Down Expand Up @@ -365,7 +365,7 @@ TEST(roundtrip_base64) {
}
size_t size = implementation.binary_to_base64(
source.data(), source.size(), buffer.data());
ASSERT_TRUE(size == implementation.base64_length_from_binary(len));
ASSERT_EQUAL(size, implementation.base64_length_from_binary(len));
simdutf::result r =
implementation.base64_to_binary(buffer.data(), size, back.data());
ASSERT_EQUAL(r.error, simdutf::error_code::SUCCESS);
Expand Down Expand Up @@ -410,7 +410,7 @@ TEST(roundtrip_base64_16) {
for (size_t i = 0; i < buffer.size(); i++) {
buffer16[i] = buffer[i];
}
ASSERT_TRUE(size == implementation.base64_length_from_binary(len));
ASSERT_EQUAL(size, implementation.base64_length_from_binary(len));
simdutf::result r =
implementation.base64_to_binary(buffer16.data(), size, back.data());
ASSERT_EQUAL(r.error, simdutf::error_code::SUCCESS);
Expand Down Expand Up @@ -451,7 +451,7 @@ TEST(roundtrip_base64url) {
}
size_t size = implementation.binary_to_base64(
source.data(), source.size(), buffer.data(), simdutf::base64_url);
ASSERT_TRUE(size == implementation.base64_length_from_binary(len, simdutf::base64_url));
ASSERT_EQUAL(size, implementation.base64_length_from_binary(len, simdutf::base64_url));
simdutf::result r =
implementation.base64_to_binary(buffer.data(), size, back.data(), simdutf::base64_url);
ASSERT_EQUAL(r.error, simdutf::error_code::SUCCESS);
Expand Down Expand Up @@ -496,7 +496,7 @@ TEST(roundtrip_base64url_16) {
for (size_t i = 0; i < buffer.size(); i++) {
buffer16[i] = buffer[i];
}
ASSERT_TRUE(size == implementation.base64_length_from_binary(len, simdutf::base64_url));
ASSERT_EQUAL(size, implementation.base64_length_from_binary(len, simdutf::base64_url));
simdutf::result r =
implementation.base64_to_binary(buffer16.data(), size, back.data(), simdutf::base64_url);
ASSERT_EQUAL(r.error, simdutf::error_code::SUCCESS);
Expand Down Expand Up @@ -751,7 +751,7 @@ TEST(roundtrip_base64_16_with_spaces) {
for (size_t i = 0; i < buffer.size(); i++) {
buffer16[i] = buffer[i];
}
ASSERT_TRUE(size == implementation.base64_length_from_binary(len));
ASSERT_EQUAL(size, implementation.base64_length_from_binary(len));
simdutf::result r = implementation.base64_to_binary(
buffer16.data(), buffer16.size(), back.data());
ASSERT_EQUAL(r.error, simdutf::error_code::SUCCESS);
Expand Down Expand Up @@ -843,7 +843,7 @@ TEST(aborted_safe_roundtrip_base64_16) {
for (size_t i = 0; i < buffer.size(); i++) {
buffer16[i] = buffer[i];
}
ASSERT_TRUE(size == implementation.base64_length_from_binary(len));
ASSERT_EQUAL(size, implementation.base64_length_from_binary(len));
size_t limited_length = len - offset; // intentionally too little
back.resize(limited_length);
back.shrink_to_fit();
Expand Down Expand Up @@ -945,7 +945,7 @@ TEST(aborted_safe_roundtrip_base64_16_with_spaces) {
for (size_t i = 0; i < buffer.size(); i++) {
buffer16[i] = buffer[i];
}
ASSERT_TRUE(size == implementation.base64_length_from_binary(len));
ASSERT_EQUAL(size, implementation.base64_length_from_binary(len));
size_t limited_length = len - offset; // intentionally too little
back.resize(limited_length);
back.shrink_to_fit();
Expand Down
14 changes: 7 additions & 7 deletions tests/basic_fuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,15 +323,15 @@ TEST(garbage_utf8_fuzz_with_errors) {
// r.count: In case of error, indicates the position of the error in the input.
// In case of success, indicates the number of code units validated/written.
if(r.error == simdutf::SUCCESS) {
ASSERT_TRUE((r.count == expected_utf16_length));
ASSERT_EQUAL(r.count, expected_utf16_length);
} else {
ASSERT_TRUE(r.count < length);
}
r = implementation.convert_utf8_to_utf16be_with_errors(
utf8_buffer.get(), length,
utf16_buffer.get());
if(r.error == simdutf::SUCCESS) {
ASSERT_TRUE((r.count == expected_utf16_length));
ASSERT_EQUAL(r.count, expected_utf16_length);
} else {
ASSERT_TRUE(r.count < length);
}
Expand All @@ -341,7 +341,7 @@ TEST(garbage_utf8_fuzz_with_errors) {
utf8_buffer.get(), length,
utf32_buffer.get());
if(r.error == simdutf::SUCCESS) {
ASSERT_TRUE((r.count == expected_utf32_length));
ASSERT_EQUAL(r.count, expected_utf32_length);
} else {
ASSERT_TRUE(r.count < length);
}
Expand Down Expand Up @@ -369,21 +369,21 @@ TEST(garbage_utf8_fuzz) {
utf8_buffer.get(), length,
utf16_buffer.get());
if(r != 0) {
ASSERT_TRUE((r == expected_utf16_length));
ASSERT_EQUAL(r, expected_utf16_length);
}
r = implementation.convert_utf8_to_utf16be(
utf8_buffer.get(), length,
utf16_buffer.get());
if(r != 0) {
ASSERT_TRUE((r == expected_utf16_length));
ASSERT_EQUAL(r, expected_utf16_length);
}
size_t expected_utf32_length = implementation.utf32_length_from_utf8(utf8_buffer.get(), length);
std::unique_ptr<char32_t[]> utf32_buffer(new char32_t[expected_utf32_length]);
r = implementation.convert_utf8_to_utf32(
utf8_buffer.get(), length,
utf32_buffer.get());
if(r != 0) {
ASSERT_TRUE((r == expected_utf32_length));
ASSERT_EQUAL(r, expected_utf32_length);
}
}
}
Expand Down Expand Up @@ -672,4 +672,4 @@ int main(int argc, char *argv[]) {
input_size.push_back(std::uniform_int_distribution<uint32_t>{50, 800}(gen)); // Range must be less than max_size
}
return simdutf::test::main((argc==2) ? 1 : argc, argv);
}
}
8 changes: 4 additions & 4 deletions tests/convert_utf16le_to_utf8_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ TEST(issue_a73) {
"\xad";
size_t utf8size =
implementation.convert_utf16le_to_utf8(utf16, len, output.data());
ASSERT_TRUE(utf8size == expected_length);
ASSERT_EQUAL(utf8size, expected_length);
for (size_t i = 0; i < expected_length; i++) {
ASSERT_TRUE(output[i] == expected[i]);
ASSERT_EQUAL(output[i], expected[i]);
}
}
#endif
Expand All @@ -102,9 +102,9 @@ TEST(issue_a72) {
"\xe9\x93\xa1\xe9\x87\xbf";
char utf8[96];
size_t utf8size = implementation.convert_utf16le_to_utf8(utf16, 32, utf8);
ASSERT_TRUE(utf8size == 96);
ASSERT_EQUAL(utf8size, 96);
for (size_t i = 0; i < 96; i++) {
ASSERT_TRUE(utf8[i] == expected[i]);
ASSERT_EQUAL(utf8[i], expected[i]);
}
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions tests/convert_utf32_to_utf8_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ TEST(special_cases) {
std::unique_ptr<char[]> utf8(new char[utf8len]);
size_t utf8size = implementation.convert_utf32_to_utf8((const char32_t*)utf32, 9, utf8.get());
for(size_t i = 0; i < utf8len; i++) {
ASSERT_TRUE(utf8[i] == expected[i]);
ASSERT_EQUAL(utf8[i], expected[i]);
}
ASSERT_TRUE(utf8size == utf8len);
ASSERT_EQUAL(utf8size, utf8len);
}

TEST_MAIN
4 changes: 2 additions & 2 deletions tests/convert_utf32_to_utf8_with_errors_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ TEST(special_cases) {
ASSERT_EQUAL(res.error, simdutf::error_code::SUCCESS);
size_t utf8size = res.count;
for(size_t i = 0; i < utf8len; i++) {
ASSERT_TRUE(utf8[i] == expected[i]);
ASSERT_EQUAL(utf8[i], expected[i]);
}
ASSERT_TRUE(utf8size == utf8len);
ASSERT_EQUAL(utf8size, utf8len);
}

TEST_MAIN
6 changes: 3 additions & 3 deletions tests/convert_utf8_to_utf16be_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ TEST(special_cases) {
const uint8_t utf8[] = {0xC2, 0xA9}; // copyright sign
const uint8_t expected[] = {0x00, 0xA9}; // expected UTF-16BE
size_t utf16len = implementation.utf16_length_from_utf8((const char*)utf8, 2);
ASSERT_TRUE(utf16len == 1);
ASSERT_EQUAL(utf16len, 1);
std::unique_ptr<char16_t[]> utf16(new char16_t[utf16len]);
size_t utf16size = implementation.convert_utf8_to_utf16be((const char*)utf8, 2, utf16.get());
ASSERT_TRUE(utf16size == utf16len);
ASSERT_TRUE(memcmp((const char*)utf16.get(), expected, 2) == 0);
ASSERT_EQUAL(utf16size, utf16len);
ASSERT_EQUAL(memcmp((const char*)utf16.get(), expected, 2), 0);
}

TEST_MAIN
2 changes: 1 addition & 1 deletion tests/convert_utf8_to_utf16be_with_errors_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ TEST(issue_213) {
ASSERT_TRUE(r.error != simdutf::SUCCESS);
// r.count: In case of error, indicates the position of the error in the input.
// In case of success, indicates the number of code units validated/written.
ASSERT_TRUE(r.count == 0);
ASSERT_EQUAL(r.count, 0);
}

TEST_LOOP(trials, convert_pure_ASCII) {
Expand Down
21 changes: 9 additions & 12 deletions tests/convert_utf8_to_utf16le_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ TEST(convert_check_validation) {
(implementation.convert_utf8_to_utf16le((const char *)UTF8.data(), UTF8.size(), buffer.get()) > 0);
bool is_ok_reference =
simdutf::tests::reference::validate_utf8((const char *)UTF8.data(), UTF8.size());
ASSERT_TRUE(is_ok == is_ok_reference);
ASSERT_EQUAL(is_ok, is_ok_reference);
}
}
}
Expand Down Expand Up @@ -90,7 +90,7 @@ TEST(convert_check_validation_examples) {
for (size_t i = 0; i < sizeof(badsequences)/sizeof(badsequences[0]); i++) {
size_t len = std::strlen(badsequences[i]);
std::unique_ptr<char16_t[]> buffer(new char16_t[len]);
ASSERT_TRUE(implementation.convert_utf8_to_utf16le(badsequences[i], len, buffer.get()) == 0);
ASSERT_EQUAL(implementation.convert_utf8_to_utf16le(badsequences[i], len, buffer.get()), 0);
}
}

Expand Down Expand Up @@ -205,30 +205,27 @@ TEST(issue111) {
char16_t input[] = u"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\u30b3aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
size_t utf16_len = sizeof(input) / sizeof(char16_t) - 1;
ASSERT_TRUE(implementation.validate_utf16le(input, utf16_len));
ASSERT_TRUE(implementation.utf8_length_from_utf16le(input, utf16_len)
== 2 + utf16_len);
ASSERT_EQUAL(implementation.utf8_length_from_utf16le(input, utf16_len), 2 + utf16_len);
size_t utf8_len = implementation.utf8_length_from_utf16le(input, utf16_len);
std::unique_ptr<char[]> utf8_buffer{new char[utf8_len]};
ASSERT_TRUE(implementation.convert_utf16le_to_utf8(input, utf16_len, utf8_buffer.get())
== utf8_len);
ASSERT_EQUAL(implementation.convert_utf16le_to_utf8(input, utf16_len, utf8_buffer.get()), utf8_len);

std::unique_ptr<char16_t[]> utf16_buffer{new char16_t[utf16_len]};

ASSERT_TRUE(implementation.convert_utf8_to_utf16le(utf8_buffer.get(), utf8_len, utf16_buffer.get())
== utf16_len);
ASSERT_TRUE(std::char_traits<char16_t>::compare(input, utf16_buffer.get(), utf16_len) == 0);
ASSERT_EQUAL(implementation.convert_utf8_to_utf16le(utf8_buffer.get(), utf8_len, utf16_buffer.get()), utf16_len);
ASSERT_EQUAL(std::char_traits<char16_t>::compare(input, utf16_buffer.get(), utf16_len), 0);
}
#endif

TEST(special_cases) {
const uint8_t utf8[] = {0xC2, 0xA9}; // copyright sign
const uint8_t expected[] = {0xA9, 0x00}; // expected UTF-16LE
size_t utf16len = implementation.utf16_length_from_utf8((const char*)utf8, 2);
ASSERT_TRUE(utf16len == 1);
ASSERT_EQUAL(utf16len, 1);
std::unique_ptr<char16_t[]> utf16(new char16_t[utf16len]);
size_t utf16size = implementation.convert_utf8_to_utf16le((const char*)utf8, 2, utf16.get());
ASSERT_TRUE(utf16size == utf16len);
ASSERT_TRUE(memcmp((const char*)utf16.get(), expected, 2) == 0);
ASSERT_EQUAL(utf16size, utf16len);
ASSERT_EQUAL(memcmp((const char*)utf16.get(), expected, 2), 0);
}


Expand Down
2 changes: 1 addition & 1 deletion tests/convert_utf8_to_utf16le_with_errors_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ TEST(issue_213) {
ASSERT_TRUE(r.error != simdutf::SUCCESS);
// r.count: In case of error, indicates the position of the error in the input.
// In case of success, indicates the number of code units validated/written.
ASSERT_TRUE(r.count == 0);
ASSERT_EQUAL(r.count, 0);
}

TEST_LOOP(trials, convert_pure_ASCII) {
Expand Down
2 changes: 1 addition & 1 deletion tests/convert_utf8_to_utf32_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ TEST(convert_invalid_special_cases) {
std::unique_ptr<char32_t[]> utf32_output{new char32_t[expected_utf32words]};
size_t utf32words = implementation.convert_utf8_to_utf32(
source.c_str(), source.size(), utf32_output.get());
ASSERT_TRUE(utf32words == 0);
ASSERT_EQUAL(utf32words, 0);
}

TEST_MAIN
2 changes: 1 addition & 1 deletion tests/convert_utf8_to_utf32_with_errors_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ TEST(issue_213) {
ASSERT_TRUE(r.error != simdutf::SUCCESS);
//r.count: In case of error, indicates the position of the error in the input.
// In case of success, indicates the number of code units validated/written.
ASSERT_TRUE(r.count == 0);
ASSERT_EQUAL(r.count, 0);
}

TEST_LOOP(trials, convert_pure_ASCII) {
Expand Down
8 changes: 4 additions & 4 deletions tests/convert_valid_utf16le_to_utf8_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ TEST(issue_a73) {
"\xad";
size_t utf8size =
implementation.convert_valid_utf16le_to_utf8(utf16, len, output.data());
ASSERT_TRUE(utf8size == expected_length);
ASSERT_EQUAL(utf8size, expected_length);
for (size_t i = 0; i < expected_length; i++) {
ASSERT_TRUE(output[i] == expected[i]);
ASSERT_EQUAL(output[i], expected[i]);
}
}
#endif
Expand All @@ -103,9 +103,9 @@ TEST(issue_a72) {
"\xe9\x93\xa1\xe9\x87\xbf";
char utf8[96];
size_t utf8size = implementation.convert_valid_utf16le_to_utf8(utf16, 32, utf8);
ASSERT_TRUE(utf8size == 96);
ASSERT_EQUAL(utf8size, 96);
for (size_t i = 0; i < 96; i++) {
ASSERT_TRUE(utf8[i] == expected[i]);
ASSERT_EQUAL(utf8[i], expected[i]);
}
}
#endif
Expand Down
6 changes: 3 additions & 3 deletions tests/convert_valid_utf8_to_utf16be_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ TEST(special_cases) {
const uint8_t utf8[] = {0xC2, 0xA9}; // copyright sign
const uint8_t expected[] = {0x00, 0xA9}; // expected UTF-16BE
size_t utf16len = implementation.utf16_length_from_utf8((const char*)utf8, 2);
ASSERT_TRUE(utf16len == 1);
ASSERT_EQUAL(utf16len, 1);
std::unique_ptr<char16_t[]> utf16(new char16_t[utf16len]);
size_t utf16size = implementation.convert_valid_utf8_to_utf16be((const char*)utf8, 2, utf16.get());
ASSERT_TRUE(utf16size == utf16len);
ASSERT_TRUE(memcmp((const char*)utf16.get(), expected, 2) == 0);
ASSERT_EQUAL(utf16size, utf16len);
ASSERT_EQUAL(memcmp((const char*)utf16.get(), expected, 2), 0);
}

TEST_MAIN
17 changes: 7 additions & 10 deletions tests/convert_valid_utf8_to_utf16le_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,16 @@ TEST(issue111) {
char16_t input[] = u"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\u30b3aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
size_t utf16_len = sizeof(input) / sizeof(char16_t) - 1;
ASSERT_TRUE(implementation.validate_utf16le(input, utf16_len));
ASSERT_TRUE(implementation.utf8_length_from_utf16le(input, utf16_len)
== 2 + utf16_len);
ASSERT_EQUAL(implementation.utf8_length_from_utf16le(input, utf16_len), 2 + utf16_len);
size_t utf8_len = implementation.utf8_length_from_utf16le(input, utf16_len);
std::unique_ptr<char[]> utf8_buffer{new char[utf8_len]};
ASSERT_TRUE(implementation.convert_valid_utf16le_to_utf8(input, utf16_len, utf8_buffer.get())
== utf8_len);
ASSERT_EQUAL(implementation.convert_valid_utf16le_to_utf8(input, utf16_len, utf8_buffer.get()), utf8_len);

std::unique_ptr<char16_t[]> utf16_buffer{new char16_t[utf16_len]};

ASSERT_TRUE(implementation.convert_valid_utf8_to_utf16le(utf8_buffer.get(), utf8_len, utf16_buffer.get())
== utf16_len);
ASSERT_EQUAL(implementation.convert_valid_utf8_to_utf16le(utf8_buffer.get(), utf8_len, utf16_buffer.get()), utf16_len);

ASSERT_TRUE(std::char_traits<char16_t>::compare(input, utf16_buffer.get(), utf16_len) == 0);
ASSERT_EQUAL(std::char_traits<char16_t>::compare(input, utf16_buffer.get(), utf16_len), 0);
}
#endif

Expand All @@ -135,11 +132,11 @@ TEST(special_cases) {
const uint8_t utf8[] = {0xC2, 0xA9}; // copyright sign
const uint8_t expected[] = {0xA9, 0x00}; // expected UTF-16LE
size_t utf16len = implementation.utf16_length_from_utf8((const char*)utf8, 2);
ASSERT_TRUE(utf16len == 1);
ASSERT_EQUAL(utf16len, 1);
std::unique_ptr<char16_t[]> utf16(new char16_t[utf16len]);
size_t utf16size = implementation.convert_valid_utf8_to_utf16le((const char*)utf8, 2, utf16.get());
ASSERT_TRUE(utf16size == utf16len);
ASSERT_TRUE(memcmp((const char*)utf16.get(), expected, 2) == 0);
ASSERT_EQUAL(utf16size, utf16len);
ASSERT_EQUAL(memcmp((const char*)utf16.get(), expected, 2), 0);
}

TEST_MAIN
8 changes: 4 additions & 4 deletions tests/detect_encodings_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ TEST(boommmmm) {
const char* utf8_bom = "\xef\xbb\xbf";
const char* utf16be_bom = "\xfe\xff";
const char* utf16le_bom = "\xff\xfe";
ASSERT_TRUE(implementation.detect_encodings(utf8_bom, 3) == simdutf::encoding_type::UTF8);
ASSERT_TRUE(implementation.detect_encodings(utf16be_bom, 2) == simdutf::encoding_type::UTF16_BE);
ASSERT_TRUE(implementation.detect_encodings(utf16le_bom, 2) == simdutf::encoding_type::UTF16_LE);
ASSERT_EQUAL(implementation.detect_encodings(utf8_bom, 3), simdutf::encoding_type::UTF8);
ASSERT_EQUAL(implementation.detect_encodings(utf16be_bom, 2), simdutf::encoding_type::UTF16_BE);
ASSERT_EQUAL(implementation.detect_encodings(utf16le_bom, 2), simdutf::encoding_type::UTF16_LE);
}


Expand All @@ -43,7 +43,7 @@ TEST(pure_utf8_ASCII) {
auto actual = implementation.detect_encodings(
reinterpret_cast<const char *>(generated.first.data()),
size);
ASSERT_TRUE(actual == expected);
ASSERT_EQUAL(actual, expected);
}
}
}
Expand Down
Loading

0 comments on commit 258340b

Please sign in to comment.