File indexing completed on 2024-05-19 04:01:09
0001 /* 0002 SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: MIT 0005 */ 0006 0007 #include <console/core/aggregation.h> 0008 #include <console/core/product.h> 0009 0010 #include <QDebug> 0011 #include <QtTest/qtest.h> 0012 #include <QObject> 0013 #include <QStandardPaths> 0014 0015 using namespace KUserFeedback::Console; 0016 0017 class ProductTest : public QObject 0018 { 0019 Q_OBJECT 0020 private Q_SLOTS: 0021 void initTestCase() 0022 { 0023 QStandardPaths::setTestModeEnabled(true); 0024 } 0025 0026 void testFromJson() 0027 { 0028 const auto ps = Product::fromJson(R"({ 0029 "name": "org.kde.TestProduct", 0030 "schema": [{ 0031 "name": "entry1", 0032 "type": "scalar", 0033 "elements": [{ "name": "elem11", "type": "string" }] 0034 }, { 0035 "name": "entry2", 0036 "type": "list", 0037 "elements": [{ "name": "elem21", "type": "number" }] 0038 }], 0039 "aggregation": [{ 0040 "type": "ratio_set", 0041 "elements": [{ "type": "value", "schemaEntry": "entry1", "schemaEntryElement": "elem11" }] 0042 }, { 0043 "type": "numeric", 0044 "elements": [{ "type": "size", "schemaEntry": "entry2" }] 0045 }] 0046 })"); 0047 0048 QCOMPARE(ps.size(), 1); 0049 0050 const auto p = ps.at(0); 0051 QCOMPARE(p.name(), QLatin1String("org.kde.TestProduct")); 0052 0053 QCOMPARE(p.schema().size(), 2); 0054 0055 const auto aggrs = p.aggregations(); 0056 QCOMPARE(aggrs.size(), 2); 0057 { 0058 const auto a1 = aggrs.at(0); 0059 QCOMPARE(a1.type(), Aggregation::RatioSet); 0060 const auto a1elems = a1.elements(); 0061 QCOMPARE(a1elems.size(), 1); 0062 QCOMPARE(a1elems.at(0).type(), AggregationElement::Value); 0063 QCOMPARE(a1elems.at(0).schemaEntry().name(), QLatin1String("entry1")); 0064 QCOMPARE(a1elems.at(0).schemaEntry().dataType(), SchemaEntry::Scalar); 0065 QCOMPARE(a1elems.at(0).schemaEntryElement().name(), QLatin1String("elem11")); 0066 } 0067 0068 { 0069 const auto a2 = aggrs.at(1); 0070 QCOMPARE(a2.type(), Aggregation::Numeric); 0071 const auto a2elems = a2.elements(); 0072 QCOMPARE(a2elems.size(), 1); 0073 QCOMPARE(a2elems.at(0).type(), AggregationElement::Size); 0074 QCOMPARE(a2elems.at(0).schemaEntry().name(), QLatin1String("entry2")); 0075 QCOMPARE(a2elems.at(0).schemaEntry().dataType(), SchemaEntry::List); 0076 QVERIFY(a2elems.at(0).schemaEntryElement().name().isEmpty()); 0077 } 0078 } 0079 0080 }; 0081 0082 QTEST_MAIN(ProductTest) 0083 0084 #include "producttest.moc"