diff --git a/tests/kded/serializerdata/corruptConfig.json b/tests/kded/serializerdata/corruptConfig.json new file mode 100644 --- /dev/null +++ b/tests/kded/serializerdata/corruptConfig.json @@ -0,0 +1,35 @@ +[ + { + "enabled": true, + "id": "OUTPUT-1", + "metadata": { + "name": "OUTPUT-1" + }, + "mode": { + "refresh": 60.0, + "size": { + "height": 1080, + "width": 1920 + } + }, + "pos": { + "x": 0, + "y": 0 + }, + "primary": true, + "rotation": 1 + }, + { + "enabled": true, + "id": "OUTPUT-2", + "metadata": { + "name": "OUTPUT-2" + }, + "mode": { + "refresh": 60, + "size": { + "height": 1024, + "width": 1280 + } + }, + "po \ No newline at end of file diff --git a/tests/kded/serializerdata/corruptEmptyConfig.json b/tests/kded/serializerdata/corruptEmptyConfig.json new file mode 100644 --- /dev/null +++ b/tests/kded/serializerdata/corruptEmptyConfig.json @@ -0,0 +1,2 @@ +[ +] diff --git a/tests/kded/serializerdata/corruptUselessConfig.json b/tests/kded/serializerdata/corruptUselessConfig.json new file mode 100644 --- /dev/null +++ b/tests/kded/serializerdata/corruptUselessConfig.json @@ -0,0 +1,31 @@ +[ + { + "enabled": true, + "pos": { + "x": 0, + "y": 0 + }, + "primary": true, + "rotation": 1 + }, + { + "enabled": true, + "id": "OUTPUT-2", + "metadata": { + "name": "OUTPUT-2" + }, + "mode": { + "refresh": 60, + "size": { + "height": 1024, + "width": 1280 + } + }, + "pos": { + "x": 1920, + "y": 0 + }, + "primary": false, + "rotation": 1 + } +] diff --git a/tests/kded/serializertest.cpp b/tests/kded/serializertest.cpp --- a/tests/kded/serializertest.cpp +++ b/tests/kded/serializertest.cpp @@ -39,6 +39,10 @@ void testTwoScreenConfig(); void testRotatedScreenConfig(); void testDisabledScreenConfig(); + void testConfig404(); + void testCorruptConfig(); + void testCorruptEmptyConfig(); + void testCorruptUselessConfig(); private: KScreen::ConfigPtr createConfig(bool output1Connected, bool output2Conected); @@ -201,6 +205,41 @@ QCOMPARE(screen->currentSize(), QSize(1920, 1280)); } +void TestSerializer::testConfig404() +{ + KScreen::ConfigPtr config = createConfig(true, true); + config = Serializer::config(config, QStringLiteral("filenotfoundConfig.json")); + QVERIFY(!config); + QVERIFY(config.isNull()); +} + +void TestSerializer::testCorruptConfig() +{ + KScreen::ConfigPtr config = createConfig(true, true); + config = Serializer::config(config, QStringLiteral("corruptConfig.json")); + QVERIFY(config); + QCOMPARE(config->outputs().count(), 2); + QVERIFY(config->isValid()); +} + +void TestSerializer::testCorruptEmptyConfig() +{ + KScreen::ConfigPtr config = createConfig(true, true); + config = Serializer::config(config, QStringLiteral("corruptEmptyConfig.json")); + QVERIFY(config); + QCOMPARE(config->outputs().count(), 2); + QVERIFY(config->isValid()); +} + +void TestSerializer::testCorruptUselessConfig() +{ + KScreen::ConfigPtr config = createConfig(true, true); + config = Serializer::config(config, QStringLiteral("corruptUselessConfig.json")); + QVERIFY(config); + QCOMPARE(config->outputs().count(), 2); + QVERIFY(config->isValid()); +} + QTEST_MAIN(TestSerializer) #include "serializertest.moc" \ No newline at end of file