From 6de6577e1c9f8fad2852abb3b850f563fb7a04c6 Mon Sep 17 00:00:00 2001 From: Zufu Liu Date: Mon, 21 Jun 2021 13:35:09 +1000 Subject: Fix some warnings in unit tests. --- test/unit/testCharClassify.cxx | 16 +++++++--------- test/unit/testDecoration.cxx | 12 ++++++------ test/unit/testPartitioning.cxx | 4 ++-- test/unit/testSplitVector.cxx | 12 ++++++------ test/unit/testUniConversion.cxx | 2 +- 5 files changed, 22 insertions(+), 24 deletions(-) (limited to 'test/unit') diff --git a/test/unit/testCharClassify.cxx b/test/unit/testCharClassify.cxx index 0dd75c514..18bf9dc29 100644 --- a/test/unit/testCharClassify.cxx +++ b/test/unit/testCharClassify.cxx @@ -26,7 +26,7 @@ class CharClassifyTest { CharClassifyTest(const CharClassifyTest &) = delete; protected: CharClassifyTest() { - pcc.reset(new CharClassify()); + pcc = std::make_unique(); for (int ch = 0; ch < 256; ch++) { if (ch == '\r' || ch == '\n') charClass[ch] = CharacterClass::newLine; @@ -39,9 +39,6 @@ protected: } } - ~CharClassifyTest() { - } - std::unique_ptr pcc; CharacterClass charClass[256]; @@ -100,26 +97,27 @@ TEST_CASE_METHOD(CharClassifyTest, "CharsOfClass") { CharacterClass thisClass = CharacterClass(classVal % 4); int size = pcc->GetCharsOfClass(thisClass, NULL); std::vector buffer(size+1); - pcc->GetCharsOfClass(thisClass, &buffer[0]); + void *pBuffer = static_cast(buffer.data()); + pcc->GetCharsOfClass(thisClass, buffer.data()); for (int i = 1; i < 256; i++) { if (charClass[i] == thisClass) { - if (!memchr(reinterpret_cast(&buffer[0]), i, size)) + if (!memchr(pBuffer, i, size)) std::cerr << "Character " << i << " should be class " << GetClassName(thisClass) << ", but was not in GetCharsOfClass;" << " it is reported to be " << GetClassName(pcc->GetClass(i)) << std::endl; - REQUIRE(memchr(reinterpret_cast(&buffer[0]), i, size)); + REQUIRE(memchr(pBuffer, i, size)); } else { - if (memchr(reinterpret_cast(&buffer[0]), i, size)) + if (memchr(pBuffer, i, size)) std::cerr << "Character " << i << " should not be class " << GetClassName(thisClass) << ", but was in GetCharsOfClass" << " it is reported to be " << GetClassName(pcc->GetClass(i)) << std::endl; - REQUIRE_FALSE(memchr(reinterpret_cast(&buffer[0]), i, size)); + REQUIRE_FALSE(memchr(pBuffer, i, size)); } } } diff --git a/test/unit/testDecoration.cxx b/test/unit/testDecoration.cxx index 023b44163..fd43bc238 100644 --- a/test/unit/testDecoration.cxx +++ b/test/unit/testDecoration.cxx @@ -22,7 +22,7 @@ #include "catch.hpp" -const int indicator=4; +constexpr int indicator=4; using namespace Scintilla::Internal; @@ -66,7 +66,7 @@ TEST_CASE("DecorationList") { } SECTION("HasCorrectCurrentValue") { - const int value = 55; + constexpr int value = 55; decol->SetCurrentValue(value); REQUIRE(value == decol->GetCurrentValue()); } @@ -74,9 +74,9 @@ TEST_CASE("DecorationList") { SECTION("ExpandSetValues") { decol->SetCurrentIndicator(indicator); decol->InsertSpace(0, 9); - const int value = 59; - const Sci::Position position = 4; - const Sci::Position fillLength = 3; + constexpr int value = 59; + constexpr Sci::Position position = 4; + constexpr Sci::Position fillLength = 3; auto fr = decol->FillRange(position, value, fillLength); REQUIRE(fr.changed); REQUIRE(fr.position == 4); @@ -85,7 +85,7 @@ TEST_CASE("DecorationList") { REQUIRE(decol->AllOnFor(5) == (1 << indicator)); REQUIRE(decol->Start(indicator, 5) == 4); REQUIRE(decol->End(indicator, 5) == 7); - const int indicatorB=6; + constexpr int indicatorB=6; decol->SetCurrentIndicator(indicatorB); fr = decol->FillRange(position, value, fillLength); REQUIRE(fr.changed); diff --git a/test/unit/testPartitioning.cxx b/test/unit/testPartitioning.cxx index e28ef318e..b2b7598d8 100644 --- a/test/unit/testPartitioning.cxx +++ b/test/unit/testPartitioning.cxx @@ -22,9 +22,9 @@ using namespace Scintilla::Internal; -const int growSize = 4; +constexpr int growSize = 4; -const int lengthTestArray = 8; +constexpr int lengthTestArray = 8; static const int testArray[lengthTestArray] = {3, 4, 5, 6, 7, 8, 9, 10}; // Test SplitVectorWithRangeAdd. diff --git a/test/unit/testSplitVector.cxx b/test/unit/testSplitVector.cxx index 8320d5bcb..aa855f1b1 100644 --- a/test/unit/testSplitVector.cxx +++ b/test/unit/testSplitVector.cxx @@ -25,7 +25,7 @@ using namespace Scintilla::Internal; struct StringSetHolder { SplitVector sa; - bool Check() { + bool Check() const noexcept { for (int i = 0; i < sa.Length(); i++) { if (sa[i].empty()) { return false; @@ -35,7 +35,7 @@ struct StringSetHolder { } }; -const int lengthTestArray = 4; +constexpr int lengthTestArray = 4; static const int testArray[4] = {3, 4, 5, 6}; TEST_CASE("SplitVector") { @@ -279,7 +279,7 @@ TEST_CASE("SplitVector") { SECTION("ReplaceUp") { // Replace each element by inserting and then deleting the displaced element // This should perform many moves - const int testLength=105; + constexpr int testLength=105; sv.EnsureLength(testLength); for (int i=0; i(s), static_cast(strlen(s))); } -- cgit v1.2.3