From e6a69e24bcefdb7356139641a588c981c1952bc5 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Mon, 31 Oct 2016 19:53:17 +0900 Subject: [PATCH] Add a common function to generate a long string to test. --- tests/test_asf.cpp | 4 ++-- tests/test_flac.cpp | 4 ++-- tests/test_id3v2.cpp | 2 +- tests/test_ogg.cpp | 8 +++----- tests/test_oggflac.cpp | 8 +++----- tests/test_opus.cpp | 8 +++----- tests/test_speex.cpp | 8 +++----- tests/utils.h | 21 +++++++++++++++++++++ 8 files changed, 38 insertions(+), 25 deletions(-) diff --git a/tests/test_asf.cpp b/tests/test_asf.cpp index f0d8853d..3f0eff63 100644 --- a/tests/test_asf.cpp +++ b/tests/test_asf.cpp @@ -310,10 +310,10 @@ public: { ASF::File f(copy.fileName().c_str()); - f.tag()->setTitle(std::string(128 * 1024, 'X').c_str()); + f.tag()->setTitle(longText(128 * 1024)); f.save(); CPPUNIT_ASSERT_EQUAL(297578L, f.length()); - f.tag()->setTitle(std::string(16 * 1024, 'X').c_str()); + f.tag()->setTitle(longText(16 * 1024)); f.save(); CPPUNIT_ASSERT_EQUAL(68202L, f.length()); } diff --git a/tests/test_flac.cpp b/tests/test_flac.cpp index e3b43ab9..6a306981 100644 --- a/tests/test_flac.cpp +++ b/tests/test_flac.cpp @@ -259,7 +259,7 @@ public: ScopedFileCopy copy("no-tags", ".flac"); FLAC::File f(copy.fileName().c_str()); - f.xiphComment()->setTitle(std::string(8 * 1024, 'X').c_str()); + f.xiphComment()->setTitle(longText(8 * 1024)); f.save(); CPPUNIT_ASSERT_EQUAL(12862L, f.length()); f.save(); @@ -372,7 +372,7 @@ public: { FLAC::File f(copy.fileName().c_str()); - f.xiphComment()->setTitle(std::wstring(128 * 1024, L'X').c_str()); + f.xiphComment()->setTitle(longText(128 * 1024)); f.save(); CPPUNIT_ASSERT(f.length() > 128 * 1024); } diff --git a/tests/test_id3v2.cpp b/tests/test_id3v2.cpp index 4f58bdd6..ec452a55 100644 --- a/tests/test_id3v2.cpp +++ b/tests/test_id3v2.cpp @@ -1136,7 +1136,7 @@ public: { MPEG::File f(newname.c_str()); - f.ID3v2Tag()->setTitle(std::wstring(64 * 1024, L'X').c_str()); + f.ID3v2Tag()->setTitle(longText(64 * 1024)); f.save(MPEG::File::ID3v2, true); } { diff --git a/tests/test_ogg.cpp b/tests/test_ogg.cpp index aa0ee421..af2d5b94 100644 --- a/tests/test_ogg.cpp +++ b/tests/test_ogg.cpp @@ -72,13 +72,11 @@ public: ScopedFileCopy copy("empty", ".ogg"); string newname = copy.fileName(); - String longText(std::string(128 * 1024, ' ').c_str()); - for (size_t i = 0; i < longText.length(); ++i) - longText[i] = static_cast(L'A' + (i % 26)); + const String text = longText(128 * 1024, true); { Vorbis::File f(newname.c_str()); - f.tag()->setTitle(longText); + f.tag()->setTitle(text); f.save(); } { @@ -89,7 +87,7 @@ public: CPPUNIT_ASSERT_EQUAL(30U, f.packet(0).size()); CPPUNIT_ASSERT_EQUAL(131127U, f.packet(1).size()); CPPUNIT_ASSERT_EQUAL(3832U, f.packet(2).size()); - CPPUNIT_ASSERT_EQUAL(longText, f.tag()->title()); + CPPUNIT_ASSERT_EQUAL(text, f.tag()->title()); CPPUNIT_ASSERT(f.audioProperties()); CPPUNIT_ASSERT_EQUAL(3685, f.audioProperties()->lengthInMilliseconds()); diff --git a/tests/test_oggflac.cpp b/tests/test_oggflac.cpp index 3b78629e..1d00d123 100644 --- a/tests/test_oggflac.cpp +++ b/tests/test_oggflac.cpp @@ -77,13 +77,11 @@ public: ScopedFileCopy copy("empty_flac", ".oga"); string newname = copy.fileName(); - String longText(std::string(128 * 1024, ' ').c_str()); - for(size_t i = 0; i < longText.length(); ++i) - longText[i] = static_cast(L'A' + (i % 26)); + const String text = longText(128 * 1024, true); { Ogg::FLAC::File f(newname.c_str()); - f.tag()->setTitle(longText); + f.tag()->setTitle(text); f.save(); } { @@ -95,7 +93,7 @@ public: CPPUNIT_ASSERT_EQUAL(131126U, f.packet(1).size()); CPPUNIT_ASSERT_EQUAL(22U, f.packet(2).size()); CPPUNIT_ASSERT_EQUAL(8196U, f.packet(3).size()); - CPPUNIT_ASSERT_EQUAL(longText, f.tag()->title()); + CPPUNIT_ASSERT_EQUAL(text, f.tag()->title()); CPPUNIT_ASSERT(f.audioProperties()); CPPUNIT_ASSERT_EQUAL(3705, f.audioProperties()->lengthInMilliseconds()); diff --git a/tests/test_opus.cpp b/tests/test_opus.cpp index 0ca6007f..9d14df23 100644 --- a/tests/test_opus.cpp +++ b/tests/test_opus.cpp @@ -93,13 +93,11 @@ public: ScopedFileCopy copy("correctness_gain_silent_output", ".opus"); string newname = copy.fileName(); - String longText(std::string(128 * 1024, ' ').c_str()); - for(size_t i = 0; i < longText.length(); ++i) - longText[i] = static_cast(L'A' + (i % 26)); + const String text = longText(128 * 1024, true); { Ogg::Opus::File f(newname.c_str()); - f.tag()->setTitle(longText); + f.tag()->setTitle(text); f.save(); } { @@ -111,7 +109,7 @@ public: CPPUNIT_ASSERT_EQUAL(131380U, f.packet(1).size()); CPPUNIT_ASSERT_EQUAL(5U, f.packet(2).size()); CPPUNIT_ASSERT_EQUAL(5U, f.packet(3).size()); - CPPUNIT_ASSERT_EQUAL(longText, f.tag()->title()); + CPPUNIT_ASSERT_EQUAL(text, f.tag()->title()); CPPUNIT_ASSERT(f.audioProperties()); CPPUNIT_ASSERT_EQUAL(7737, f.audioProperties()->lengthInMilliseconds()); diff --git a/tests/test_speex.cpp b/tests/test_speex.cpp index 7789a197..7c0f9dc7 100644 --- a/tests/test_speex.cpp +++ b/tests/test_speex.cpp @@ -58,13 +58,11 @@ public: ScopedFileCopy copy("empty", ".spx"); string newname = copy.fileName(); - String longText(std::string(128 * 1024, ' ').c_str()); - for (size_t i = 0; i < longText.length(); ++i) - longText[i] = static_cast(L'A' + (i % 26)); + const String text = longText(128 * 1024, true); { Ogg::Speex::File f(newname.c_str()); - f.tag()->setTitle(longText); + f.tag()->setTitle(text); f.save(); } { @@ -76,7 +74,7 @@ public: CPPUNIT_ASSERT_EQUAL(131116U, f.packet(1).size()); CPPUNIT_ASSERT_EQUAL(93U, f.packet(2).size()); CPPUNIT_ASSERT_EQUAL(93U, f.packet(3).size()); - CPPUNIT_ASSERT_EQUAL(longText, f.tag()->title()); + CPPUNIT_ASSERT_EQUAL(text, f.tag()->title()); CPPUNIT_ASSERT(f.audioProperties()); CPPUNIT_ASSERT_EQUAL(3685, f.audioProperties()->lengthInMilliseconds()); diff --git a/tests/utils.h b/tests/utils.h index 30afaf3b..51d8862b 100644 --- a/tests/utils.h +++ b/tests/utils.h @@ -103,6 +103,27 @@ inline bool fileEqual(const string &filename1, const string &filename2) return stream1.good() == stream2.good(); } +#ifdef TAGLIB_STRING_H + +namespace TagLib { + + inline String longText(size_t length, bool random = false) + { + const wchar_t chars[] = L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_"; + + std::wstring text(length, L'X'); + + if(random) { + for(size_t i = 0; i < length; ++i) + text[i] = chars[rand() % 53]; + } + + return String(text); + } +} + +#endif + class ScopedFileCopy { public: -- 2.40.0