Added test cases for clean_file_name() function.

This commit is contained in:
LoRd_MuldeR 2016-12-15 22:42:22 +01:00
parent a0bd22a152
commit 79e9f85fae

View File

@ -33,73 +33,72 @@
#define ASSERT_QSTR(X,Y) ASSERT_EQ((X).compare(QLatin1String(Y)), 0); #define ASSERT_QSTR(X,Y) ASSERT_EQ((X).compare(QLatin1String(Y)), 0);
//=========================================================================== //===========================================================================
// Trim String // GLOBAL
//=========================================================================== //===========================================================================
//-----------------------------------------------------------------
// Trim String
//-----------------------------------------------------------------
#define TEST_TRIM_STR(X,Y,Z) do \
{ \
{ \
QString test((Y)); \
MUtils::trim_##X(test); \
ASSERT_QSTR(test, (Z)); \
} \
{ \
const QString test((Y)); \
ASSERT_QSTR(MUtils::trim_##X(test), (Z)); \
} \
} \
while(0)
TEST(Global, TrimStringLeft) TEST(Global, TrimStringLeft)
{ {
{ TEST_TRIM_STR(left, "", "");
QString test(""); TEST_TRIM_STR(left, " ", "");
MUtils::trim_left(test); TEST_TRIM_STR(left, "! test !", "! test !");
ASSERT_QSTR(test, ""); TEST_TRIM_STR(left, " test ", "test ");
} TEST_TRIM_STR(left, " ! test ! ", "! test ! ");
{
QString test(" ");
MUtils::trim_left(test);
ASSERT_QSTR(test, "");
}
{
QString test("! test !");
MUtils::trim_left(test);
ASSERT_QSTR(test, "! test !");
}
{
QString test(" test ");
MUtils::trim_left(test);
ASSERT_QSTR(test, "test ");
}
{
QString test(" ! test ! ");
MUtils::trim_left(test);
ASSERT_QSTR(test, "! test ! ");
}
{
const QString test(" test ");
ASSERT_QSTR(MUtils::trim_left(test), "test ");
}
} }
TEST(Global, TrimStringRight) TEST(Global, TrimStringRight)
{ {
{ TEST_TRIM_STR(right, "", "");
QString test(""); TEST_TRIM_STR(right, " ", "");
MUtils::trim_right(test); TEST_TRIM_STR(right, "! test !", "! test !");
ASSERT_QSTR(test, ""); TEST_TRIM_STR(right, " test ", " test");
} TEST_TRIM_STR(right, " ! test ! ", " ! test !");
{ }
QString test(" ");
MUtils::trim_right(test); #undef TEST_TRIM_STR
ASSERT_QSTR(test, "");
} //-----------------------------------------------------------------
{ // Clean File Path
QString test("! test !"); //-----------------------------------------------------------------
MUtils::trim_right(test);
ASSERT_QSTR(test, "! test !"); #define TEST_CLEAN_FILE(X,Y,Z) do \
} { \
{ ASSERT_QSTR(MUtils::clean_file_##X((Y)), (Z)); \
QString test(" test "); } \
MUtils::trim_right(test); while(0)
ASSERT_QSTR(test, " test");
} TEST(Global, CleanFileName)
{ {
QString test(" ! test ! "); static const char *const VALID_CHARS = "!#$%&'()+,-.0123456789;=@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{}~";
MUtils::trim_right(test); TEST_CLEAN_FILE(name, "", "");
ASSERT_QSTR(test, " ! test !"); TEST_CLEAN_FILE(name, VALID_CHARS, VALID_CHARS);
} TEST_CLEAN_FILE(name, "example.txt", "example.txt");
{ TEST_CLEAN_FILE(name, " example.txt", " example.txt");
const QString test(" test "); TEST_CLEAN_FILE(name, "example.txt ", "example.txt");
ASSERT_QSTR(MUtils::trim_right(test), " test"); TEST_CLEAN_FILE(name, ".example.txt", ".example.txt");
} TEST_CLEAN_FILE(name, "example.txt.", "example.txt");
TEST_CLEAN_FILE(name, "foo<>:\"/\\|?*\t\r\n.bar", "foo____________.bar");
TEST_CLEAN_FILE(name, "NUL", "___");
TEST_CLEAN_FILE(name, "NUL.txt", "___.txt");
TEST_CLEAN_FILE(name, "NULx.txt", "NULx.txt");
TEST_CLEAN_FILE(name, "xNUL.txt", "xNUL.txt");
} }
//=========================================================================== //===========================================================================