1
0
Fork 0
forked from len0rd/rockbox

rbutil: Add data tags to data driven unit tests.

Make tests implemented as data driven tests show a sensible test data
tag value, so test can get identified more easily.

Change-Id: Ifeb42ed11ce9a8efc6491b2c3b9fe31802a67d33
This commit is contained in:
Dominik Riebeling 2021-12-28 17:47:59 +01:00
parent 0c8f539182
commit c055b5e933
2 changed files with 72 additions and 59 deletions

View file

@ -35,62 +35,63 @@ class TestVersionCompare : public QObject
struct { struct {
const char* first; const char* name; // dataset name
const char* second; const char* first; // first comparison value
const int expected; const char* second; // second comparison value
const int expected; // expected result
} const compdata[] = } const compdata[] =
{ {
{ "1.2.3", "1.2.3 ", 0 }, { "trailing-whitespace", "1.2.3", "1.2.3 ", 0 },
{ "1.2.3", " 1.2.3", 0 }, { "identical", "1.2.3", "1.2.3", 0 },
{ "1.2.3", "1.2.4", 1 }, { "leading-whitespace", "1.2.3", " 1.2.3", 0 },
{ "1.2.3", "1.3.0", 1 }, { "last-digit-greater", "1.2.3", "1.2.4", 1 },
{ "1.2.3", "2.0.0", 1 }, { "last-digit-less", "1.2.3", "1.3.0", 1 },
{ "10.22.33", "10.22.33", 0 }, { "all-digits-differ", "1.2.3", "2.0.0", 1 },
{ "10.22.33", "10.23.0", 1 }, { "multidigit-numbers-identical", "10.22.33", "10.22.33", 0 },
{ "10.22.33", "11.0.0", 1 }, { "multidigit-last-differs", "10.22.33", "10.23.0", 1 },
{ "1.2.3", "1.2.3.1", 1 }, { "multidigit-next-to-last-differs", "10.22.33", "11.0.0", 1 },
{ "1.2.3", "1.2.3-1", 1 }, { "last-additional-digit-with-dot", "1.2.3", "1.2.3.1", 1 },
{ "1.2.3-1", "1.2.3.1", 1 }, { "last-additional-digit-with-hyphen", "1.2.3", "1.2.3-1", 1 },
{ "1.2.3-10", "1.2.3.0", 1 }, { "first-additional-digit-with-hyphen", "1.2.3-1", "1.2.3.1", 1 },
{ "1.2.3-1", "1.2.3.10", 1 }, { "first-additional-multidigit-with-hyphen", "1.2.3-10", "1.2.3.0", 1 },
{ "1.2.3-1", "1.2.3a", 1 }, { "first-additional-with-hyphen-last-dot", "1.2.3-1", "1.2.3.10", 1 },
{ "1.2.3", "1.2.3a", 1 }, { "first-additional-hyphen-last-charsuffix", "1.2.3-1", "1.2.3a", 1 },
{ "1.2.3a", "1.2.3b", 1 }, { "last-with-char-suffix", "1.2.3", "1.2.3a", 1 },
{ "1.2.3", "1.2.3b", 1 }, { "first-and-last-with-char-suffix", "1.2.3a", "1.2.3b", 1 },
{ "1.2.3.0", "2.0.0", 1 }, { "last-with-char-suffix", "1.2.3", "1.2.3b", 1 },
{ "1.2.3b", "2.0.0", 1 }, { "greater-has-less-digits", "1.2.3.0", "2.0.0", 1 },
{ "1.2.3", "2.0.0.1", 1 }, { "less-has-char-suffix-greater-has-less-digits", "1.2.3b", "2.0.0", 1 },
{ "test-1.2.3", "test-1.2.3.tar.gz", 0 }, { "greater-has-more-digits", "1.2.3", "2.0.0.1", 1 },
{ "1.2.3", "test-1.2.3.tar.bz2", 0 }, { "identidal-with-differing-prefix-suffix", "test-1.2.3", "test-1.2.3.tar.gz", 0 },
{ "test-1.2.3.tar.gz", "test-1.2.3.tar.bz2", 0 }, { "identical-with-filename", "1.2.3", "test-1.2.3.tar.bz2", 0 },
{ "test-1.2.3.tar.gz", "program-1.2.3.1.tar.bz2", 1 }, { "identical-with-different-filesuffixes", "test-1.2.3.tar.gz", "test-1.2.3.tar.bz2", 0 },
{ "program-1.2.3.zip", "program-1.2.3a.zip", 1 }, { "identical-with-different-filenames", "test-1.2.3.tar.gz", "program-1.2.3.1.tar.bz2", 1 },
{ "program-1.2.3.tar.bz2", "2.0.0", 1 }, { "last-additional-char-suffix-with-filename", "program-1.2.3.zip", "program-1.2.3a.zip", 1 },
{ "prog-1.2-64bit.tar.bz2", "prog-1.2.3.tar.bz2", 1 }, { "less-has-filename", "program-1.2.3.tar.bz2", "2.0.0", 1 },
{ "prog-1.2-64bit.tar.bz2", "prog-1.2-64bit.tar.bz2", 0 }, { "filename-64bit-vs-additional-number", "prog-1.2-64bit.tar.bz2", "prog-1.2.3.tar.bz2", 1 },
{ "prog-1.2-64bit.tar.bz2", "prog-1.2.3-64bit.tar.bz2", 1 }, { "filename-64bit-identical", "prog-1.2-64bit.tar.bz2", "prog-1.2-64bit.tar.bz2", 0 },
{ "prog-1.2a-64bit.tar.bz2","prog-1.2b-64bit.tar.bz2", 1 }, { "filename-64bit-additional-number", "prog-1.2-64bit.tar.bz2", "prog-1.2.3-64bit.tar.bz2", 1 },
{ "prog-1.2-64bit.tar.bz2", "prog-1.2.3a-64bit.tar.bz2", 1 }, { "filename-64bit-different-char-suffixes", "prog-1.2a-64bit.tar.bz2","prog-1.2b-64bit.tar.bz2", 1 },
{ "prog-1.2a-64bit.tar.bz2","prog-1.2.3-64bit.tar.bz2", 1 }, { "filename-64bit-extra-number-and-char-suffix", "prog-1.2-64bit.tar.bz2", "prog-1.2.3a-64bit.tar.bz2", 1 },
{ "filename-64bit-char-suffix-vs-extra-number", "prog-1.2a-64bit.tar.bz2","prog-1.2.3-64bit.tar.bz2", 1 },
}; };
struct { struct {
const char* input; const char* name; // dataset name
const QString expected; const char* input; // input string
const QString expected; // output string
} const trimdata[] = } const trimdata[] =
{ {
{ "prog-1.2-64bit.tar.bz2", "1.2" }, { "full-filename-with-64bit", "prog-1.2-64bit.tar.bz2", "1.2" },
{ "prog-1.2.tar.bz2", "1.2" }, { "full-filename", "prog-1.2.tar.bz2", "1.2" },
{ "1.2.3", "1.2.3" }, { "version-only", "1.2.3", "1.2.3" },
{ " 1.2.3", "1.2.3" }, { "version-with-leading-whitespace", " 1.2.3", "1.2.3" },
{ "1.2.3 ", "1.2.3" }, { "version-with-trailing-whitespace", "1.2.3 ", "1.2.3" },
{ "10.22.33", "10.22.33" }, { "multidigit-version", "10.22.33", "10.22.33" },
{ "test-1.2.3", "1.2.3" }, { "name-version", "test-1.2.3", "1.2.3" },
{ "1.2.3", "1.2.3" }, { "name-version-suffix", "test-1.2.3.tar.gz", "1.2.3" },
{ "test-1.2.3.tar.gz", "1.2.3" }, { "name-version-increment-suffix", "prog-1.2a.tar.bz2", "1.2a" },
{ "prog-1.2-64bit.tar.bz2", "1.2" }, { "name-version-increment-64bit", "prog-1.2a-64bit.tar.bz2","1.2a" },
{ "prog-1.2a.tar.bz2", "1.2a" },
{ "prog-1.2a-64bit.tar.bz2","1.2a" },
}; };
@ -100,7 +101,8 @@ void TestVersionCompare::testCompare_data()
QTest::addColumn<QString>("second"); QTest::addColumn<QString>("second");
QTest::addColumn<int>("expected"); QTest::addColumn<int>("expected");
for(size_t i = 0; i < sizeof(compdata) / sizeof(compdata[0]); i++) { for(size_t i = 0; i < sizeof(compdata) / sizeof(compdata[0]); i++) {
QTest::newRow("") << compdata[i].first << compdata[i].second << compdata[i].expected; QTest::newRow(compdata[i].name)
<< compdata[i].first << compdata[i].second << compdata[i].expected;
} }
} }
@ -123,7 +125,8 @@ void TestVersionCompare::testTrim_data()
QTest::addColumn<QString>("input"); QTest::addColumn<QString>("input");
QTest::addColumn<QString>("expected"); QTest::addColumn<QString>("expected");
for(size_t i = 0; i < sizeof(trimdata) / sizeof(trimdata[0]); i++) { for(size_t i = 0; i < sizeof(trimdata) / sizeof(trimdata[0]); i++) {
QTest::newRow("") << trimdata[i].input << trimdata[i].expected; QTest::newRow(trimdata[i].name)
<< trimdata[i].input << trimdata[i].expected;
} }
} }

View file

@ -82,10 +82,10 @@ Q_DECLARE_METATYPE(PlayerBuildInfo::BuildType);
Q_DECLARE_METATYPE(PlayerBuildInfo::DeviceInfo); Q_DECLARE_METATYPE(PlayerBuildInfo::DeviceInfo);
struct { struct {
QString target; const char* target;
PlayerBuildInfo::BuildInfo item; PlayerBuildInfo::BuildInfo item;
PlayerBuildInfo::BuildType type; PlayerBuildInfo::BuildType type;
QString expected; const char* expected;
} testdataBuild[] = } testdataBuild[] =
{ {
// release builds // release builds
@ -132,9 +132,9 @@ struct {
}; };
struct { struct {
QString target; const char* target;
PlayerBuildInfo::DeviceInfo item; PlayerBuildInfo::DeviceInfo item;
QString expected; const char* expected;
} testdataPlayer[] = } testdataPlayer[] =
{ {
{ "archosfmrecorder", PlayerBuildInfo::BuildStatus, "3" }, { "archosfmrecorder", PlayerBuildInfo::BuildStatus, "3" },
@ -166,8 +166,13 @@ void TestPlayerBuildInfo::testBuildInfo_data()
QTest::addColumn<PlayerBuildInfo::BuildType>("type"); QTest::addColumn<PlayerBuildInfo::BuildType>("type");
QTest::addColumn<QString>("expected"); QTest::addColumn<QString>("expected");
for (size_t i = 0; i < sizeof(testdataBuild) / sizeof(testdataBuild[0]); i++) for (size_t i = 0; i < sizeof(testdataBuild) / sizeof(testdataBuild[0]); i++)
QTest::newRow("") << testdataBuild[i].target << testdataBuild[i].item {
<< testdataBuild[i].type << testdataBuild[i].expected; char tag[30];
snprintf(tag, sizeof(tag), "%s-%i-%i",
testdataBuild[i].target, testdataBuild[i].item, testdataBuild[i].type);
QTest::newRow(tag) << testdataBuild[i].target << testdataBuild[i].item
<< testdataBuild[i].type << testdataBuild[i].expected;
}
} }
@ -204,8 +209,13 @@ void TestPlayerBuildInfo::testPlayerInfo_data()
QTest::addColumn<PlayerBuildInfo::DeviceInfo>("item"); QTest::addColumn<PlayerBuildInfo::DeviceInfo>("item");
QTest::addColumn<QString>("expected"); QTest::addColumn<QString>("expected");
for (size_t i = 0; i < sizeof(testdataPlayer) / sizeof(testdataPlayer[0]); i++) for (size_t i = 0; i < sizeof(testdataPlayer) / sizeof(testdataPlayer[0]); i++)
QTest::newRow("") << testdataPlayer[i].target << testdataPlayer[i].item {
<< testdataPlayer[i].expected; char tag[30];
snprintf(tag, sizeof(tag), "%s-%i",
testdataPlayer[i].target, testdataPlayer[i].item);
QTest::newRow(tag) << testdataPlayer[i].target << testdataPlayer[i].item
<< testdataPlayer[i].expected;
}
} }
void TestPlayerBuildInfo::testPlayerInfo() void TestPlayerBuildInfo::testPlayerInfo()