@@ -0,0 +1,73 | |||
|
1 | #include "DataSourceItemBuilder.h" | |
|
2 | ||
|
3 | DataSourceItemBuilder &DataSourceItemBuilder::root(const QString &name) | |
|
4 | { | |
|
5 | m_Root = std::make_shared<DataSourceItem>(DataSourceItemType::NODE, name); | |
|
6 | m_Items.push(m_Root.get()); | |
|
7 | return *this; | |
|
8 | } | |
|
9 | ||
|
10 | DataSourceItemBuilder &DataSourceItemBuilder::root(QVariantHash data) | |
|
11 | { | |
|
12 | m_Root = std::make_shared<DataSourceItem>(DataSourceItemType::NODE, data); | |
|
13 | m_Items.push(m_Root.get()); | |
|
14 | return *this; | |
|
15 | } | |
|
16 | ||
|
17 | DataSourceItemBuilder &DataSourceItemBuilder::node(const QString &name) | |
|
18 | { | |
|
19 | return append(DataSourceItemType::NODE, name); | |
|
20 | } | |
|
21 | ||
|
22 | DataSourceItemBuilder &DataSourceItemBuilder::node(QVariantHash data) | |
|
23 | { | |
|
24 | return append(DataSourceItemType::NODE, std::move(data)); | |
|
25 | } | |
|
26 | ||
|
27 | DataSourceItemBuilder &DataSourceItemBuilder::product(const QString &name) | |
|
28 | { | |
|
29 | return append(DataSourceItemType::PRODUCT, name); | |
|
30 | } | |
|
31 | ||
|
32 | DataSourceItemBuilder &DataSourceItemBuilder::product(QVariantHash data) | |
|
33 | { | |
|
34 | return append(DataSourceItemType::PRODUCT, std::move(data)); | |
|
35 | } | |
|
36 | ||
|
37 | DataSourceItemBuilder &DataSourceItemBuilder::component(const QString &name) | |
|
38 | { | |
|
39 | return append(DataSourceItemType::COMPONENT, name); | |
|
40 | } | |
|
41 | ||
|
42 | DataSourceItemBuilder &DataSourceItemBuilder::component(QVariantHash data) | |
|
43 | { | |
|
44 | return append(DataSourceItemType::COMPONENT, std::move(data)); | |
|
45 | } | |
|
46 | ||
|
47 | DataSourceItemBuilder &DataSourceItemBuilder::end() | |
|
48 | { | |
|
49 | m_Items.pop(); | |
|
50 | return *this; | |
|
51 | } | |
|
52 | ||
|
53 | std::shared_ptr<DataSourceItem> DataSourceItemBuilder::build() | |
|
54 | { | |
|
55 | return m_Root; | |
|
56 | } | |
|
57 | ||
|
58 | DataSourceItemBuilder &DataSourceItemBuilder::append(DataSourceItemType type, const QString &name) | |
|
59 | { | |
|
60 | append(type, QVariantHash{{DataSourceItem::NAME_DATA_KEY, name}}); | |
|
61 | return *this; | |
|
62 | } | |
|
63 | ||
|
64 | DataSourceItemBuilder &DataSourceItemBuilder::append(DataSourceItemType type, QVariantHash data) | |
|
65 | { | |
|
66 | auto parentItem = m_Items.top(); | |
|
67 | ||
|
68 | auto insertIndex = parentItem->childCount(); | |
|
69 | parentItem->appendChild(std::make_unique<DataSourceItem>(type, std::move(data))); | |
|
70 | ||
|
71 | m_Items.push(parentItem->child(insertIndex)); | |
|
72 | return *this; | |
|
73 | } |
@@ -0,0 +1,45 | |||
|
1 | #ifndef SCIQLOP_DATASOURCEITEMBUILDER_H | |
|
2 | #define SCIQLOP_DATASOURCEITEMBUILDER_H | |
|
3 | ||
|
4 | #include <DataSource/DataSourceItem.h> | |
|
5 | ||
|
6 | #include <memory> | |
|
7 | #include <stack> | |
|
8 | ||
|
9 | /** | |
|
10 | * @brief The DataSourceItemBuilder class aims to facilitate the creation of a DataSourceItem for unit tests | |
|
11 | * @sa DataSourceItem | |
|
12 | */ | |
|
13 | class DataSourceItemBuilder { | |
|
14 | public: | |
|
15 | /// Inits root item | |
|
16 | DataSourceItemBuilder & root(const QString &name); | |
|
17 | DataSourceItemBuilder & root(QVariantHash data); | |
|
18 | ||
|
19 | /// Adds node into the current item | |
|
20 | DataSourceItemBuilder & node(const QString &name); | |
|
21 | DataSourceItemBuilder & node(QVariantHash data); | |
|
22 | ||
|
23 | /// Adds product into the current item | |
|
24 | DataSourceItemBuilder & product(const QString &name); | |
|
25 | DataSourceItemBuilder & product(QVariantHash data); | |
|
26 | ||
|
27 | /// Adds component into the current item | |
|
28 | DataSourceItemBuilder & component(const QString &name); | |
|
29 | DataSourceItemBuilder & component(QVariantHash data); | |
|
30 | ||
|
31 | /// Closes the build of the current item | |
|
32 | DataSourceItemBuilder& end(); | |
|
33 | ||
|
34 | /// Creates the DataSourceItem | |
|
35 | std::shared_ptr<DataSourceItem> build(); | |
|
36 | ||
|
37 | private: | |
|
38 | DataSourceItemBuilder& append(DataSourceItemType type, const QString &name); | |
|
39 | DataSourceItemBuilder& append(DataSourceItemType type, QVariantHash data); | |
|
40 | ||
|
41 | std::shared_ptr<DataSourceItem> m_Root{nullptr}; | |
|
42 | std::stack<DataSourceItem*> m_Items; | |
|
43 | }; | |
|
44 | ||
|
45 | #endif // SCIQLOP_DATASOURCEITEMBUILDER_H |
@@ -1,34 +1,36 | |||
|
1 | 1 | |
|
2 | 2 | |
|
3 | 3 | tests = [ |
|
4 | 4 | [['Common/TestStringUtils.cpp'],'test_string_utils','StringUtils test'], |
|
5 | 5 | [['Data/TestScalarSeries.cpp'],'test_scalar','ScalarSeries test'], |
|
6 | 6 | [['Data/TestSpectrogramSeries.cpp'],'test_spectrogram','SpectrogramSeries test'], |
|
7 | 7 | [['Data/TestVectorSeries.cpp'],'test_vector','VectorSeries test'], |
|
8 | 8 | [['Data/TestOneDimArrayData.cpp'],'test_1d','One Dim Array test'], |
|
9 | 9 | [['Data/TestOptionalAxis.cpp'],'test_optional_axis','OptionalAxis test'], |
|
10 | 10 | [['Data/TestTwoDimArrayData.cpp'],'test_2d','Two Dim Array test'], |
|
11 | 11 | [['Data/TestDataSeriesUtils.cpp'],'test_dataseries_util','Data series utils test'], |
|
12 | 12 | [['DataSource/TestDataSourceController.cpp'],'test_data_source','DataSourceController test'], |
|
13 | 13 | [['DataSource/TestDataSourceItem.cpp'],'test_data_source_item','DataSourceItem test'], |
|
14 | 14 | [['Variable/TestVariableCacheController.cpp'],'test_variable_cache','VariableCacheController test'], |
|
15 | 15 | [['Variable/TestVariable.cpp'],'test_variable','Variable test'], |
|
16 | 16 | [['Variable/TestVariableSync.cpp'],'test_variable_sync','Variable synchronization test'] |
|
17 | 17 | ] |
|
18 | 18 | |
|
19 | 19 | amdatest_sources = [ |
|
20 | 20 | 'Data/DataSeriesBuilders.h', |
|
21 | 21 | 'Data/DataSeriesBuilders.cpp', |
|
22 | 22 | 'Data/DataSeriesTestsUtils.h', |
|
23 | 'Data/DataSeriesTestsUtils.cpp' | |
|
23 | 'Data/DataSeriesTestsUtils.cpp', | |
|
24 | 'DataSource/DataSourceItemBuilder.h', | |
|
25 | 'DataSource/DataSourceItemBuilder.cpp' | |
|
24 | 26 | ] |
|
25 | 27 | |
|
26 | 28 | foreach unit_test : tests |
|
27 | 29 | test_moc_files = qt5.preprocess(moc_sources : unit_test[0]) |
|
28 | 30 | test_exe = executable(unit_test[1],unit_test[0] , test_moc_files, |
|
29 | 31 | dependencies : [sciqlop_core, qt5test], |
|
30 | 32 | cpp_args : ['-DCORE_TESTS_RESOURCES_DIR="'+meson.current_source_dir()+'/../tests-resources"'], |
|
31 | 33 | sources : [amdatest_sources]) |
|
32 | 34 | test(unit_test[2], test_exe, args: ['-teamcity', '-o', '@0@.teamcity.txt'.format(unit_test[1])]) |
|
33 | 35 | endforeach |
|
34 | 36 |
General Comments 0
You need to be logged in to leave comments.
Login now