##// END OF EJS Templates
Inits unit tests for merge
Alexandre Leroux -
r1039:2a1ef173f7ed
parent child
Show More
@@ -0,0 +1,72
1 #include <DataSource/DataSourceItem.h>
2
3 #include <QObject>
4 #include <QtTest>
5
6 #include <iostream>
7
8 namespace {
9
10 void printItem(std::ostream &out, const DataSourceItem &item, int level = 0)
11 {
12 for (auto i = 0; i < level; ++i) {
13 out << " ";
14 }
15
16 out << item.name().toStdString() << "\n";
17
18 for (auto i = 0, count = item.childCount(); i < count; ++i) {
19 printItem(out, *item.child(i), level + 1);
20 }
21 }
22
23 std::ostream &operator<<(std::ostream &out, const DataSourceItem &item)
24 {
25 printItem(out, item, 0);
26 return out;
27 }
28
29 } // namespace
30
31 Q_DECLARE_METATYPE(std::shared_ptr<DataSourceItem>)
32
33 class TestDataSourceItem : public QObject {
34 Q_OBJECT
35 private slots:
36 void testMerge_data();
37 void testMerge();
38 };
39
40 void TestDataSourceItem::testMerge_data()
41 {
42 QTest::addColumn<std::shared_ptr<DataSourceItem> >("source");
43 QTest::addColumn<std::shared_ptr<DataSourceItem> >("dest");
44 QTest::addColumn<std::shared_ptr<DataSourceItem> >("expectedResult");
45
46 /// @todo ALX: adds test cases
47 }
48
49 void TestDataSourceItem::testMerge()
50 {
51 QFETCH(std::shared_ptr<DataSourceItem>, source);
52 QFETCH(std::shared_ptr<DataSourceItem>, dest);
53 QFETCH(std::shared_ptr<DataSourceItem>, expectedResult);
54
55 // Uncomment to print trees
56 // std::cout << "source: \n" << *source << "\n";
57 // std::cout << "dest: \n" << *dest << "\n";
58
59 // Merges source in dest (not taking source root)
60 for (auto i = 0, count = source->childCount(); i < count; ++i) {
61 dest->merge(*source->child(i));
62 }
63
64 // Uncomment to print trees
65 // std::cout << "dest after merge: \n" << *dest << "\n";
66
67 // Checks merge result
68 QVERIFY(*dest == *expectedResult);
69 }
70
71 QTEST_MAIN(TestDataSourceItem)
72 #include "TestDataSourceItem.moc"
@@ -10,6 +10,7 tests = [
10 [['Data/TestTwoDimArrayData.cpp'],'test_2d','Two Dim Array test'],
10 [['Data/TestTwoDimArrayData.cpp'],'test_2d','Two Dim Array test'],
11 [['Data/TestDataSeriesUtils.cpp'],'test_dataseries_util','Data series utils test'],
11 [['Data/TestDataSeriesUtils.cpp'],'test_dataseries_util','Data series utils test'],
12 [['DataSource/TestDataSourceController.cpp'],'test_data_source','DataSourceController test'],
12 [['DataSource/TestDataSourceController.cpp'],'test_data_source','DataSourceController test'],
13 [['DataSource/TestDataSourceItem.cpp'],'test_data_source_item','DataSourceItem test'],
13 [['Variable/TestVariableCacheController.cpp'],'test_variable_cache','VariableCacheController test'],
14 [['Variable/TestVariableCacheController.cpp'],'test_variable_cache','VariableCacheController test'],
14 [['Variable/TestVariable.cpp'],'test_variable','Variable test'],
15 [['Variable/TestVariable.cpp'],'test_variable','Variable test'],
15 [['Variable/TestVariableSync.cpp'],'test_variable_sync','Variable synchronization test']
16 [['Variable/TestVariableSync.cpp'],'test_variable_sync','Variable synchronization test']
General Comments 0
You need to be logged in to leave comments. Login now