]> granicus.if.org Git - taglib/commitdiff
Add a common function to generate a long string to test.
authorTsuda Kageyu <tsuda.kageyu@gmail.com>
Mon, 31 Oct 2016 10:53:17 +0000 (19:53 +0900)
committerTsuda Kageyu <tsuda.kageyu@gmail.com>
Mon, 31 Oct 2016 11:01:52 +0000 (20:01 +0900)
tests/test_asf.cpp
tests/test_flac.cpp
tests/test_id3v2.cpp
tests/test_ogg.cpp
tests/test_oggflac.cpp
tests/test_opus.cpp
tests/test_speex.cpp
tests/utils.h

index f0d8853d36c964197f012ad0d4c977a811928b92..3f0eff63d1284b05143926717d7acd5c229a81c4 100644 (file)
@@ -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());
     }
index e3b43ab924a8137c4122dc409b0b5df2a2472d3f..6a306981b04f2763e3d74d3cb54ac371168fa350 100644 (file)
@@ -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);
     }
index 4f58bdd6b7fe215cb28a2c3a8ee67b4474633b73..ec452a55c4bb18e98d77c533ebe842ca4df90d98 100644 (file)
@@ -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);
     }
     {
index aa0ee4215a1f69ba9a7f04f228624dac55e36448..af2d5b9447c7e2c252872943f562a851b9bdc0c2 100644 (file)
@@ -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<wchar_t>(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());
index 3b78629e7e2cf9c10344ef7959c4d62e8425b275..1d00d1231d38593cbdf443954f7e1ea2fa1845c9 100644 (file)
@@ -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<wchar_t>(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());
index 0ca6007fb6c94f6d49b537e59646509bd8572b75..9d14df23b382f4c20d0dae2b223ca1e3345558a4 100644 (file)
@@ -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<wchar_t>(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());
index 7789a19724351e29be8a085903381fd0907b0faf..7c0f9dc7920629de41d9d7653d7e7bfdd4087510 100644 (file)
@@ -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<wchar_t>(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());
index 30afaf3b0435c4f72fcb3fffc9379a0e9eb06a3d..51d8862b5fe1a053bafc65b26c8b52d5ac31721a 100644 (file)
@@ -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: