-
-
Notifications
You must be signed in to change notification settings - Fork 803
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
285 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* Copyright (c) 2013-2022 Jeffrey Pfau | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
#include "suite.h" | ||
#include "platform/qt/library/LibraryModel.h" | ||
|
||
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) | ||
#include <QAbstractItemModelTester> | ||
#endif | ||
|
||
#include <QtDebug> | ||
#include <QSignalSpy> | ||
|
||
using namespace QGBA; | ||
|
||
class LibraryModelTest : public QObject { | ||
Q_OBJECT | ||
|
||
private: | ||
LibraryModel* model = nullptr; | ||
|
||
LibraryEntry makeGBA(const QString& base, const QString& name, uint32_t crc) { | ||
LibraryEntry entry; | ||
entry.base = base; | ||
entry.filename = name + ".gba"; | ||
entry.fullpath = base + "/" + entry.filename; | ||
entry.title = name; | ||
entry.internalTitle = name.toUpper().toUtf8(); | ||
entry.internalCode = entry.internalTitle.replace(" ", "").left(4); | ||
entry.platform = mPLATFORM_GBA; | ||
entry.filesize = entry.fullpath.size() * 4; | ||
entry.crc32 = crc; | ||
return entry; | ||
} | ||
|
||
LibraryEntry makeGB(const QString& base, const QString& name, uint32_t crc) { | ||
LibraryEntry entry = makeGBA(base, name, crc); | ||
entry.filename = name + ".gb"; | ||
entry.fullpath = base + "/" + entry.filename; | ||
entry.platform = mPLATFORM_GB; | ||
entry.filesize /= 4;; | ||
return entry; | ||
} | ||
|
||
void addTestGames1() { | ||
model->addEntries({ | ||
makeGBA("/gba", "Test Game", 0x12345678), | ||
makeGBA("/gba", "Another", 0x23456789), | ||
makeGB("/gb", "Old Game", 0x87654321), | ||
}); | ||
} | ||
|
||
private slots: | ||
void init() { | ||
model = new LibraryModel(); | ||
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) | ||
new QAbstractItemModelTester(model, QAbstractItemModelTester::FailureReportingMode::QtTest, model); | ||
#endif | ||
} | ||
|
||
void cleanup() { | ||
delete model; | ||
model = nullptr; | ||
} | ||
|
||
void initList() { | ||
addTestGames1(); | ||
QCOMPARE(model->rowCount(), 3); | ||
} | ||
|
||
void initTree() { | ||
QSignalSpy resetSpy(model, SIGNAL(modelReset())); | ||
model->setTreeMode(true); | ||
QVERIFY(resetSpy.count()); | ||
addTestGames1(); | ||
int gbRow = 0, gbaRow = 1; | ||
if (model->index(0, 0).data() == "gba") { | ||
gbaRow = 0; | ||
gbRow = 1; | ||
} | ||
QCOMPARE(model->rowCount(), 2); | ||
QCOMPARE(model->rowCount(model->index(gbRow, 0)), 1); | ||
QCOMPARE(model->rowCount(model->index(gbaRow, 0)), 2); | ||
} | ||
}; | ||
|
||
M_REGISTER_QT_TEST(LibraryModelTest) | ||
#include "library.moc" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* Copyright (c) 2013-2022 Jeffrey Pfau | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
#include "suite.h" | ||
|
||
QList<TestRegistrar*> registeredTests; | ||
|
||
int main(int argc, char** argv) { | ||
int err = 0; | ||
for (TestRegistrar* test : registeredTests) { | ||
int result = test->main(argc, argv); | ||
if (result && !err) { | ||
err = result; | ||
} | ||
} | ||
return err; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* Copyright (c) 2013-2022 Jeffrey Pfau | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
#include "suite.h" | ||
#include "platform/qt/utils.h" | ||
|
||
#include <QtDebug> | ||
|
||
using namespace QGBA; | ||
|
||
class SpanSetTest : public QObject { | ||
Q_OBJECT | ||
|
||
private: | ||
void debugSpans(const SpanSet& spanSet) { | ||
QStringList debug; | ||
for (auto span : spanSet.spans) { | ||
debug << QStringLiteral("[%1, %2]").arg(span.left).arg(span.right); | ||
} | ||
qDebug() << QStringLiteral("SpanSet{%1}").arg(debug.join(", ")); | ||
} | ||
|
||
private slots: | ||
void oneSpan() { | ||
SpanSet spanSet; | ||
spanSet.add(1); | ||
spanSet.add(2); | ||
spanSet.add(3); | ||
QCOMPARE(spanSet.spans.size(), 1); | ||
spanSet.merge(); | ||
QCOMPARE(spanSet.spans.size(), 1); | ||
} | ||
|
||
void twoSpans() { | ||
SpanSet spanSet; | ||
spanSet.add(1); | ||
spanSet.add(2); | ||
spanSet.add(4); | ||
QCOMPARE(spanSet.spans.size(), 2); | ||
spanSet.merge(); | ||
QCOMPARE(spanSet.spans.size(), 2); | ||
} | ||
|
||
void mergeSpans() { | ||
SpanSet spanSet; | ||
spanSet.add(1); | ||
spanSet.add(3); | ||
spanSet.add(2); | ||
spanSet.add(5); | ||
spanSet.add(4); | ||
spanSet.add(7); | ||
spanSet.add(8); | ||
QCOMPARE(spanSet.spans.size(), 4); | ||
spanSet.merge(); | ||
QCOMPARE(spanSet.spans.size(), 2); | ||
} | ||
}; | ||
|
||
M_REGISTER_QT_TEST(SpanSetTest) | ||
#include "spanset.moc" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* Copyright (c) 2013-2022 Jeffrey Pfau | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
#pragma once | ||
|
||
#define QT_NO_OPENGL | ||
|
||
#include <QtTest> | ||
#include <QList> | ||
|
||
struct TestRegistrar { | ||
virtual int main(int argc, char** argv) = 0; | ||
}; | ||
|
||
extern QList<TestRegistrar*> registeredTests; | ||
|
||
#define M_REGISTER_QT_TEST(Class) \ | ||
static struct Class ## Registrar : TestRegistrar { \ | ||
QTEST_MAIN(Class) \ | ||
Class ## Registrar() { registeredTests << this; } \ | ||
} registrar_ ## Class; |
Oops, something went wrong.