From 2a1ef173f7ed25e31a2f91d27b802be74c023893 2017-11-28 13:37:13 From: Alexandre Leroux Date: 2017-11-28 13:37:13 Subject: [PATCH] Inits unit tests for merge --- diff --git a/core/tests/DataSource/TestDataSourceItem.cpp b/core/tests/DataSource/TestDataSourceItem.cpp new file mode 100644 index 0000000..c40fb4e --- /dev/null +++ b/core/tests/DataSource/TestDataSourceItem.cpp @@ -0,0 +1,72 @@ +#include + +#include +#include + +#include + +namespace { + +void printItem(std::ostream &out, const DataSourceItem &item, int level = 0) +{ + for (auto i = 0; i < level; ++i) { + out << " "; + } + + out << item.name().toStdString() << "\n"; + + for (auto i = 0, count = item.childCount(); i < count; ++i) { + printItem(out, *item.child(i), level + 1); + } +} + +std::ostream &operator<<(std::ostream &out, const DataSourceItem &item) +{ + printItem(out, item, 0); + return out; +} + +} // namespace + +Q_DECLARE_METATYPE(std::shared_ptr) + +class TestDataSourceItem : public QObject { + Q_OBJECT +private slots: + void testMerge_data(); + void testMerge(); +}; + +void TestDataSourceItem::testMerge_data() +{ + QTest::addColumn >("source"); + QTest::addColumn >("dest"); + QTest::addColumn >("expectedResult"); + + /// @todo ALX: adds test cases +} + +void TestDataSourceItem::testMerge() +{ + QFETCH(std::shared_ptr, source); + QFETCH(std::shared_ptr, dest); + QFETCH(std::shared_ptr, expectedResult); + + // Uncomment to print trees + // std::cout << "source: \n" << *source << "\n"; + // std::cout << "dest: \n" << *dest << "\n"; + + // Merges source in dest (not taking source root) + for (auto i = 0, count = source->childCount(); i < count; ++i) { + dest->merge(*source->child(i)); + } + + // Uncomment to print trees + // std::cout << "dest after merge: \n" << *dest << "\n"; + + // Checks merge result + QVERIFY(*dest == *expectedResult); +} + +QTEST_MAIN(TestDataSourceItem) +#include "TestDataSourceItem.moc" diff --git a/core/tests/meson.build b/core/tests/meson.build index 8a23801..e03a89d 100644 --- a/core/tests/meson.build +++ b/core/tests/meson.build @@ -10,6 +10,7 @@ tests = [ [['Data/TestTwoDimArrayData.cpp'],'test_2d','Two Dim Array test'], [['Data/TestDataSeriesUtils.cpp'],'test_dataseries_util','Data series utils test'], [['DataSource/TestDataSourceController.cpp'],'test_data_source','DataSourceController test'], + [['DataSource/TestDataSourceItem.cpp'],'test_data_source_item','DataSourceItem test'], [['Variable/TestVariableCacheController.cpp'],'test_variable_cache','VariableCacheController test'], [['Variable/TestVariable.cpp'],'test_variable','Variable test'], [['Variable/TestVariableSync.cpp'],'test_variable_sync','Variable synchronization test']