Add a common function to generate a long string to test.

This commit is contained in:
Tsuda Kageyu 2016-10-31 19:53:17 +09:00
parent dcab8ed90e
commit e6a69e24bc
8 changed files with 38 additions and 25 deletions

View 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());
}

View 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);
}

View 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);
}
{

View 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());

View 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());

View 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());

View 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());

View 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: