From e037c36f351e7aad85ad852b8415cd3023868af6 Mon Sep 17 00:00:00 2001 From: upstream svn Date: Fri, 22 Jul 2016 20:48:03 +0000 Subject: [PATCH] Fixes to the unittests The unittest suite should now compile and run without giving any errors. - remove questionable test from PathTest - fix unicode conversion related issues - fix type mismatches in wxString::Format() - fix unittest compilation with wxWidgets-3.0.2 --- .svn-revision | 2 +- unittests/muleunit/test.h | 40 +++++++++++++++++++------------------- unittests/muleunit/testcase.cpp | 2 +- unittests/tests/CTagTest.cpp | 11 ++++++----- unittests/tests/FileDataIOTest.cpp | 10 +++++----- unittests/tests/PathTest.cpp | 14 ++++++++++++- unittests/tests/TextFileTest.cpp | 7 +++---- 7 files changed, 49 insertions(+), 37 deletions(-) diff --git a/.svn-revision b/.svn-revision index 29396055..4ecbe004 100644 --- a/.svn-revision +++ b/.svn-revision @@ -1 +1 @@ -10937 +10938 diff --git a/unittests/muleunit/test.h b/unittests/muleunit/test.h index 8b09af78..ac90825c 100644 --- a/unittests/muleunit/test.h +++ b/unittests/muleunit/test.h @@ -129,6 +129,26 @@ public: /** + * Helperfunction that converts basic types to strings. + */ +template +wxString StringFrom(const TYPE& value) +{ + return wxString() << value; +} + +inline wxString StringFrom(unsigned long long value) +{ + return wxString::Format(wxT("%") wxLongLongFmtSpec wxT("u"), value); +} + +inline wxString StringFrom(signed long long value) +{ + return wxString::Format(wxT("%") wxLongLongFmtSpec wxT("i"), value); +} + + +/** * Test class containing all macros to do unit testing. * A test object represents a test that will be executed. Once it has been * executed, it reports all failures in the testPartResult linked list. @@ -208,26 +228,6 @@ protected: }; -/** - * Helperfunction that converts basic types to strings. - */ -template -wxString StringFrom(const TYPE& value) -{ - return wxString() << value; -} - -inline wxString StringFrom(unsigned long long value) -{ - return wxString::Format(wxT("%") wxLongLongFmtSpec wxT("u"), value); -} - -inline wxString StringFrom(signed long long value) -{ - return wxString::Format(wxT("%") wxLongLongFmtSpec wxT("i"), value); -} - - #define THROW_TEST_FAILURE(message) \ throw CTestFailureException(message, wxT(__FILE__), __LINE__) diff --git a/unittests/muleunit/testcase.cpp b/unittests/muleunit/testcase.cpp index 0d6f47a9..9f4b0387 100644 --- a/unittests/muleunit/testcase.cpp +++ b/unittests/muleunit/testcase.cpp @@ -60,7 +60,7 @@ const wxString& TestCase::getName() const bool TestCase::run() { - Print(wxT("\nRunning test-collection \"") + m_name + wxString::Format(wxT("\" with %u test-cases:"), m_tests.size())); + Print(wxT("\nRunning test-collection \"") + m_name + wxString::Format(wxT("\" with %u test-cases:"), static_cast(m_tests.size()))); bool failures = false; diff --git a/unittests/tests/CTagTest.cpp b/unittests/tests/CTagTest.cpp index b8e50bc8..058fe539 100644 --- a/unittests/tests/CTagTest.cpp +++ b/unittests/tests/CTagTest.cpp @@ -275,7 +275,7 @@ void test_taglist_serialization(TagPtrList& taglist, byte* packet, uint64 packet } for (uint64 i = 0; i < packet_len; i++) { - CONTEXT(wxString::Format(wxT("Comparing serialized byte #%d"), i)); + CONTEXT(wxString::Format(wxT("Comparing serialized byte #%") wxLongLongFmtSpec wxT("u"), i)); ASSERT_EQUALS(packet[i], buf[i]); } @@ -391,7 +391,7 @@ TEST_M(CTag, CMD4Hash, wxT("Kad: Read/Write CMD4Hash")) TagPtrList::iterator it = taglist.begin(); CMD4Hash hash; - ASSERT_TRUE(hash.Decode("000102030405060708090A0B0C0D0E0F")); + ASSERT_TRUE(hash.Decode(std::string("000102030405060708090A0B0C0D0E0F"))); CheckTagData(*it++, TAG_SOURCETYPE, valid_tag_value(hash)); @@ -421,7 +421,7 @@ void check_single_kad_tag(byte* packet, size_t packet_len, T tagName, V tagValue newbuf.Seek(0, wxFromStart); for (size_t i = 0; i < packet_len; i++) { - CONTEXT(wxString::Format(wxT("Comparing byte #%d"), i)); + CONTEXT(wxString::Format(wxT("Comparing byte #%d"), static_cast(i))); ASSERT_EQUALS(packet[i], newbuf.ReadUInt8()); } @@ -576,7 +576,8 @@ TEST_M(CTag, KadTagNames, wxT("Kad: Test Kad tags (name=string) - write/read eve buf.WriteUInt8(0x01); // single char string buf.WriteUInt8(0x00); // - buf.WriteUInt8(it_name->first.GetChar(0)); // Write string first char + wxCharBuffer b = wxConvISO8859_1.cWC2MB(it_name->first); + buf.WriteUInt8(((const char *)b)[0]); // Write string first char buf.WriteUInt8(counter++); // write tag value } @@ -664,7 +665,7 @@ TEST_M(CTag, ED2kTagNames, wxT("Ed2k: Test ed2k tags (name=id) - write/read ever counter = 0; for (TagNamesByInt::iterator it_name = tagNames.begin(); it_name != tagNames.end(); ++it_name) { - CONTEXT(wxString::Format(wxT("Reading tag#%d"), counter)); + CONTEXT(wxString::Format(wxT("Reading tag#%") wxLongLongFmtSpec wxT("u"), counter)); CTag* newtag = new CTag(buf, true); CheckTagName(it_name->first, newtag); CheckTagValue( valid_tag_value( counter ), newtag); diff --git a/unittests/tests/FileDataIOTest.cpp b/unittests/tests/FileDataIOTest.cpp index 6d69b73b..cdb24c65 100644 --- a/unittests/tests/FileDataIOTest.cpp +++ b/unittests/tests/FileDataIOTest.cpp @@ -335,13 +335,13 @@ public: void run() { const unsigned char CanaryData = 170; - const char canaryBlock[] = { CanaryData }; + const unsigned char canaryBlock[] = { CanaryData }; CFileDataIO* file = this->m_predefFile; for (size_t j = 0; j < TEST_LENGTH + 1 - SIZE; ++j) { // Clear before, after and at the target byte(s) - for (int t = -SIZE; t < (int)(2*SIZE); ++t) { + for (int t = -static_cast(SIZE); t < (int)(2*SIZE); ++t) { if ((j + t) < TEST_LENGTH && ((int)j + t) >= 0) { file->Seek(j + t, wxFromStart); ASSERT_EQUALS(j + t, file->GetPosition()); @@ -362,7 +362,7 @@ public: ASSERT_EQUALS(j + SIZE, file->GetPosition()); // Check before, after and at the target byte - for (int t = -SIZE; t < (int)(2*SIZE); ++t) { + for (int t = -static_cast(SIZE); t < (int)(2*SIZE); ++t) { if ((j + t) < TEST_LENGTH && ((int)j + t) >= 0) { if (t) { if (t < 0 || t >= (int)SIZE) { @@ -534,7 +534,7 @@ public: CONTEXT(wxString(wxT("Testing string: '")) << testData[str].str << wxT("'")); for (size_t enc = 0; enc < ArraySize(encodings); ++enc) { - CONTEXT(wxString::Format(wxT("Testing encoding: %i"), encodings[enc])); + CONTEXT(wxString::Format(wxT("Testing encoding: %i"), encodings[enc].id)); const wxChar* curStr = testData[str].str; size_t strLen = testData[str].lengths[(encodings[enc].id == utf8strNone) ? 0 : 1]; @@ -577,7 +577,7 @@ public: CAssertOff silence; for (size_t enc = 0; enc < ArraySize(encodings); ++enc) { - CONTEXT(wxString::Format(wxT("Testing encoding against poisoning: %i"), encodings[enc])); + CONTEXT(wxString::Format(wxT("Testing encoding against poisoning: %i"), encodings[enc].id)); ////////////////////////////////////////////// // Check if we guard against "poisoning". diff --git a/unittests/tests/PathTest.cpp b/unittests/tests/PathTest.cpp index 7c7412b3..1bd2a01a 100644 --- a/unittests/tests/PathTest.cpp +++ b/unittests/tests/PathTest.cpp @@ -7,6 +7,12 @@ using namespace muleunit; +#if 0 +/* + * The validity of this test is at least questionable. The result depends on + * - the current system locale and character encoding used, and + * - the way wxConvFileName reports error conditions and its fallback behaviour. + struct STestStr { //! Specifies the "source" of the string (user/fs) @@ -56,7 +62,8 @@ wxString GetExpectedString(const wxString& src) return src; } } - +*/ +#endif wxString StringFrom(const CPath& prt) { @@ -113,6 +120,9 @@ TEST(CPath, PathConstructor) ASSERT_EQUALS(tmp, CPath()); } +#if 0 +/* + * See the note above for (size_t i = 0; i < ArraySize(g_fromFSTests); ++i) { const wxString input = g_fromFSTests[i].input; @@ -132,6 +142,8 @@ TEST(CPath, PathConstructor) ASSERT_EQUALS(tmp.GetFullName(), tmp); ASSERT_EQUALS(tmp.GetPath(), CPath()); } +*/ +#endif } diff --git a/unittests/tests/TextFileTest.cpp b/unittests/tests/TextFileTest.cpp index 179565d9..4fed34a2 100644 --- a/unittests/tests/TextFileTest.cpp +++ b/unittests/tests/TextFileTest.cpp @@ -191,7 +191,7 @@ public: ASSERT_TRUE(file.Open(wxT("testfile.txt"), CTextFile::write)); for (size_t i = 0; i < ArraySize(lines); ++i) { - CONTEXT(wxString::Format(wxT("Writing the %i'th line."), i)); + CONTEXT(wxString::Format(wxT("Writing the %i'th line."), static_cast(i))); ASSERT_TRUE(file.WriteLine(lines[i])); } @@ -205,7 +205,7 @@ public: ASSERT_FALSE(file.Eof()); for (size_t i = 0; i < ArraySize(lines); ++i) { - CONTEXT(wxString::Format(wxT("Reading the %i'th line."), i)); + CONTEXT(wxString::Format(wxT("Reading the %i'th line."), static_cast(i))); ASSERT_EQUALS(lines[i], file.GetNextLine()); } @@ -232,7 +232,7 @@ public: ASSERT_FALSE(file.Eof()); for (size_t i = 0; i < ArraySize(lines); ++i) { - CONTEXT(wxString::Format(wxT("Reading the %i'th line."), i)); + CONTEXT(wxString::Format(wxT("Reading the %i'th line."), static_cast(i))); ASSERT_EQUALS(lines[i], file.GetNextLine()); } @@ -241,4 +241,3 @@ public: } } } testInstance; - -- 2.11.4.GIT