@@ -1,177 +1,262 | |||||
1 | #include <Variable/Variable.h> |
|
1 | #include <Variable/Variable.h> | |
2 |
|
2 | |||
|
3 | #include <Data/ScalarSeries.h> | |||
|
4 | ||||
3 | #include <QObject> |
|
5 | #include <QObject> | |
4 | #include <QtTest> |
|
6 | #include <QtTest> | |
5 |
|
7 | |||
6 | #include <memory> |
|
8 | #include <memory> | |
7 |
|
9 | |||
|
10 | Q_DECLARE_METATYPE(std::shared_ptr<ScalarSeries>) | |||
|
11 | ||||
8 | class TestVariable : public QObject { |
|
12 | class TestVariable : public QObject { | |
9 | Q_OBJECT |
|
13 | Q_OBJECT | |
10 |
|
14 | |||
11 | private slots: |
|
15 | private slots: | |
12 |
void test |
|
16 | void testClone_data(); | |
|
17 | void testClone(); | |||
13 |
|
18 | |||
|
19 | void testNotInCacheRangeList(); | |||
14 | void testInCacheRangeList(); |
|
20 | void testInCacheRangeList(); | |
15 | }; |
|
21 | }; | |
16 |
|
22 | |||
|
23 | void TestVariable::testClone_data() | |||
|
24 | { | |||
|
25 | // ////////////// // | |||
|
26 | // Test structure // | |||
|
27 | // ////////////// // | |||
|
28 | ||||
|
29 | QTest::addColumn<QString>("name"); | |||
|
30 | QTest::addColumn<QVariantHash>("metadata"); | |||
|
31 | QTest::addColumn<SqpRange>("range"); | |||
|
32 | QTest::addColumn<SqpRange>("cacheRange"); | |||
|
33 | QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries"); | |||
|
34 | ||||
|
35 | // ////////// // | |||
|
36 | // Test cases // | |||
|
37 | // ////////// // | |||
|
38 | ||||
|
39 | /// Generates a date in double | |||
|
40 | auto date = [](int year, int month, int day, int hours, int minutes, int seconds) { | |||
|
41 | return DateUtils::secondsSinceEpoch( | |||
|
42 | QDateTime{{year, month, day}, {hours, minutes, seconds}, Qt::UTC}); | |||
|
43 | }; | |||
|
44 | ||||
|
45 | /// Generates a data series for a range | |||
|
46 | auto dataSeries = [](const SqpRange &range) { | |||
|
47 | auto xAxisData = std::vector<double>{}; | |||
|
48 | auto valuesData = std::vector<double>{}; | |||
|
49 | ||||
|
50 | auto value = 0; | |||
|
51 | for (auto x = range.m_TStart; x < range.m_TEnd; ++x, ++value) { | |||
|
52 | xAxisData.push_back(x); | |||
|
53 | valuesData.push_back(value); | |||
|
54 | } | |||
|
55 | ||||
|
56 | return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData), Unit{}, | |||
|
57 | Unit{}); | |||
|
58 | }; | |||
|
59 | ||||
|
60 | auto cacheRange = SqpRange{date(2017, 1, 1, 12, 0, 0), date(2017, 1, 1, 13, 0, 0)}; | |||
|
61 | QTest::newRow("clone1") << QStringLiteral("var1") | |||
|
62 | << QVariantHash{{"data1", 1}, {"data2", "abc"}} | |||
|
63 | << SqpRange{date(2017, 1, 1, 12, 30, 0), (date(2017, 1, 1, 12, 45, 0))} | |||
|
64 | << cacheRange << dataSeries(cacheRange); | |||
|
65 | } | |||
|
66 | ||||
|
67 | void TestVariable::testClone() | |||
|
68 | { | |||
|
69 | // Creates variable | |||
|
70 | QFETCH(QString, name); | |||
|
71 | QFETCH(QVariantHash, metadata); | |||
|
72 | QFETCH(SqpRange, range); | |||
|
73 | QFETCH(SqpRange, cacheRange); | |||
|
74 | QFETCH(std::shared_ptr<ScalarSeries>, dataSeries); | |||
|
75 | ||||
|
76 | Variable variable{name, metadata}; | |||
|
77 | variable.setRange(range); | |||
|
78 | variable.setCacheRange(cacheRange); | |||
|
79 | variable.mergeDataSeries(dataSeries); | |||
|
80 | ||||
|
81 | // Clones variable | |||
|
82 | auto clone = variable.clone(); | |||
|
83 | ||||
|
84 | // Checks cloned variable's state | |||
|
85 | QCOMPARE(clone->name(), name); | |||
|
86 | QCOMPARE(clone->metadata(), metadata); | |||
|
87 | QCOMPARE(clone->range(), range); | |||
|
88 | QCOMPARE(clone->cacheRange(), cacheRange); | |||
|
89 | ||||
|
90 | // Compares data series | |||
|
91 | if (dataSeries != nullptr) { | |||
|
92 | QVERIFY(clone->dataSeries() != nullptr); | |||
|
93 | QVERIFY(std::equal(dataSeries->cbegin(), dataSeries->cend(), clone->dataSeries()->cbegin(), | |||
|
94 | clone->dataSeries()->cend(), [](const auto &it1, const auto &it2) { | |||
|
95 | return it1.x() == it2.x() && it1.value() == it2.value(); | |||
|
96 | })); | |||
|
97 | } | |||
|
98 | else { | |||
|
99 | QVERIFY(clone->dataSeries() == nullptr); | |||
|
100 | } | |||
|
101 | } | |||
17 |
|
102 | |||
18 | void TestVariable::testNotInCacheRangeList() |
|
103 | void TestVariable::testNotInCacheRangeList() | |
19 | { |
|
104 | { | |
20 | auto varRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; |
|
105 | auto varRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; | |
21 | auto varRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 40, 0}}; |
|
106 | auto varRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 40, 0}}; | |
22 |
|
107 | |||
23 | auto sqpR = SqpRange{DateUtils::secondsSinceEpoch(varRS), DateUtils::secondsSinceEpoch(varRE)}; |
|
108 | auto sqpR = SqpRange{DateUtils::secondsSinceEpoch(varRS), DateUtils::secondsSinceEpoch(varRE)}; | |
24 |
|
109 | |||
25 | auto varCRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}}; |
|
110 | auto varCRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}}; | |
26 | auto varCRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; |
|
111 | auto varCRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; | |
27 |
|
112 | |||
28 | auto sqpCR |
|
113 | auto sqpCR | |
29 | = SqpRange{DateUtils::secondsSinceEpoch(varCRS), DateUtils::secondsSinceEpoch(varCRE)}; |
|
114 | = SqpRange{DateUtils::secondsSinceEpoch(varCRS), DateUtils::secondsSinceEpoch(varCRE)}; | |
30 |
|
115 | |||
31 | Variable var{"Var test"}; |
|
116 | Variable var{"Var test"}; | |
32 | var.setRange(sqpR); |
|
117 | var.setRange(sqpR); | |
33 | var.setCacheRange(sqpCR); |
|
118 | var.setCacheRange(sqpCR); | |
34 |
|
119 | |||
35 | // 1: [ts,te] < varTS |
|
120 | // 1: [ts,te] < varTS | |
36 | auto ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; |
|
121 | auto ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | |
37 | auto te = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}}; |
|
122 | auto te = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}}; | |
38 | auto sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
123 | auto sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
39 |
|
124 | |||
40 | auto notInCach = var.provideNotInCacheRangeList(sqp); |
|
125 | auto notInCach = var.provideNotInCacheRangeList(sqp); | |
41 |
|
126 | |||
42 | QCOMPARE(notInCach.size(), 1); |
|
127 | QCOMPARE(notInCach.size(), 1); | |
43 |
|
128 | |||
44 | auto notInCachRange = notInCach.first(); |
|
129 | auto notInCachRange = notInCach.first(); | |
45 |
|
130 | |||
46 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts)); |
|
131 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts)); | |
47 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te)); |
|
132 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te)); | |
48 |
|
133 | |||
49 | // 2: ts < varTS < te < varTE |
|
134 | // 2: ts < varTS < te < varTE | |
50 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; |
|
135 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | |
51 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; |
|
136 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; | |
52 | sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
137 | sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
53 | notInCach = var.provideNotInCacheRangeList(sqp); |
|
138 | notInCach = var.provideNotInCacheRangeList(sqp); | |
54 | QCOMPARE(notInCach.size(), 1); |
|
139 | QCOMPARE(notInCach.size(), 1); | |
55 | notInCachRange = notInCach.first(); |
|
140 | notInCachRange = notInCach.first(); | |
56 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts)); |
|
141 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts)); | |
57 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(varCRS)); |
|
142 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(varCRS)); | |
58 |
|
143 | |||
59 | // 3: varTS < ts < te < varTE |
|
144 | // 3: varTS < ts < te < varTE | |
60 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; |
|
145 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; | |
61 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; |
|
146 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; | |
62 | sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
147 | sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
63 | notInCach = var.provideNotInCacheRangeList(sqp); |
|
148 | notInCach = var.provideNotInCacheRangeList(sqp); | |
64 | QCOMPARE(notInCach.size(), 0); |
|
149 | QCOMPARE(notInCach.size(), 0); | |
65 |
|
150 | |||
66 |
|
151 | |||
67 | // 4: varTS < ts < varTE < te |
|
152 | // 4: varTS < ts < varTE < te | |
68 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; |
|
153 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; | |
69 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; |
|
154 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |
70 | sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
155 | sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
71 | notInCach = var.provideNotInCacheRangeList(sqp); |
|
156 | notInCach = var.provideNotInCacheRangeList(sqp); | |
72 | QCOMPARE(notInCach.size(), 1); |
|
157 | QCOMPARE(notInCach.size(), 1); | |
73 | notInCachRange = notInCach.first(); |
|
158 | notInCachRange = notInCach.first(); | |
74 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(varCRE)); |
|
159 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(varCRE)); | |
75 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te)); |
|
160 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te)); | |
76 |
|
161 | |||
77 | // 5: varTS < varTE < ts < te |
|
162 | // 5: varTS < varTE < ts < te | |
78 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 20, 0}}; |
|
163 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 20, 0}}; | |
79 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; |
|
164 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |
80 | sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
165 | sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
81 | notInCach = var.provideNotInCacheRangeList(sqp); |
|
166 | notInCach = var.provideNotInCacheRangeList(sqp); | |
82 | QCOMPARE(notInCach.size(), 1); |
|
167 | QCOMPARE(notInCach.size(), 1); | |
83 | notInCachRange = notInCach.first(); |
|
168 | notInCachRange = notInCach.first(); | |
84 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts)); |
|
169 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts)); | |
85 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te)); |
|
170 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te)); | |
86 |
|
171 | |||
87 | // 6: ts <varTS < varTE < te |
|
172 | // 6: ts <varTS < varTE < te | |
88 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}}; |
|
173 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}}; | |
89 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; |
|
174 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |
90 | sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
175 | sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
91 | notInCach = var.provideNotInCacheRangeList(sqp); |
|
176 | notInCach = var.provideNotInCacheRangeList(sqp); | |
92 | QCOMPARE(notInCach.size(), 2); |
|
177 | QCOMPARE(notInCach.size(), 2); | |
93 | notInCachRange = notInCach.first(); |
|
178 | notInCachRange = notInCach.first(); | |
94 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts)); |
|
179 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts)); | |
95 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(varCRS)); |
|
180 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(varCRS)); | |
96 | notInCachRange = notInCach[1]; |
|
181 | notInCachRange = notInCach[1]; | |
97 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(varCRE)); |
|
182 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(varCRE)); | |
98 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te)); |
|
183 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te)); | |
99 | } |
|
184 | } | |
100 |
|
185 | |||
101 |
|
186 | |||
102 | void TestVariable::testInCacheRangeList() |
|
187 | void TestVariable::testInCacheRangeList() | |
103 | { |
|
188 | { | |
104 | auto varRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; |
|
189 | auto varRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; | |
105 | auto varRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 40, 0}}; |
|
190 | auto varRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 40, 0}}; | |
106 |
|
191 | |||
107 | auto sqpR = SqpRange{DateUtils::secondsSinceEpoch(varRS), DateUtils::secondsSinceEpoch(varRE)}; |
|
192 | auto sqpR = SqpRange{DateUtils::secondsSinceEpoch(varRS), DateUtils::secondsSinceEpoch(varRE)}; | |
108 |
|
193 | |||
109 | auto varCRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}}; |
|
194 | auto varCRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}}; | |
110 | auto varCRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; |
|
195 | auto varCRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; | |
111 | auto sqpCR |
|
196 | auto sqpCR | |
112 | = SqpRange{DateUtils::secondsSinceEpoch(varCRS), DateUtils::secondsSinceEpoch(varCRE)}; |
|
197 | = SqpRange{DateUtils::secondsSinceEpoch(varCRS), DateUtils::secondsSinceEpoch(varCRE)}; | |
113 |
|
198 | |||
114 | Variable var{"Var test"}; |
|
199 | Variable var{"Var test"}; | |
115 | var.setRange(sqpR); |
|
200 | var.setRange(sqpR); | |
116 | var.setCacheRange(sqpCR); |
|
201 | var.setCacheRange(sqpCR); | |
117 |
|
202 | |||
118 | // 1: [ts,te] < varTS |
|
203 | // 1: [ts,te] < varTS | |
119 | auto ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; |
|
204 | auto ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | |
120 | auto te = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}}; |
|
205 | auto te = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}}; | |
121 | auto sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
206 | auto sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
122 |
|
207 | |||
123 | auto notInCach = var.provideInCacheRangeList(sqp); |
|
208 | auto notInCach = var.provideInCacheRangeList(sqp); | |
124 |
|
209 | |||
125 | QCOMPARE(notInCach.size(), 0); |
|
210 | QCOMPARE(notInCach.size(), 0); | |
126 |
|
211 | |||
127 | // 2: ts < varTS < te < varTE |
|
212 | // 2: ts < varTS < te < varTE | |
128 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; |
|
213 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | |
129 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; |
|
214 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; | |
130 | sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
215 | sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
131 | notInCach = var.provideInCacheRangeList(sqp); |
|
216 | notInCach = var.provideInCacheRangeList(sqp); | |
132 | QCOMPARE(notInCach.size(), 1); |
|
217 | QCOMPARE(notInCach.size(), 1); | |
133 | auto notInCachRange = notInCach.first(); |
|
218 | auto notInCachRange = notInCach.first(); | |
134 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(varCRS)); |
|
219 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(varCRS)); | |
135 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te)); |
|
220 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te)); | |
136 |
|
221 | |||
137 | // 3: varTS < ts < te < varTE |
|
222 | // 3: varTS < ts < te < varTE | |
138 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; |
|
223 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; | |
139 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; |
|
224 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; | |
140 | sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
225 | sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
141 | notInCach = var.provideInCacheRangeList(sqp); |
|
226 | notInCach = var.provideInCacheRangeList(sqp); | |
142 | QCOMPARE(notInCach.size(), 1); |
|
227 | QCOMPARE(notInCach.size(), 1); | |
143 | notInCachRange = notInCach.first(); |
|
228 | notInCachRange = notInCach.first(); | |
144 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts)); |
|
229 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts)); | |
145 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te)); |
|
230 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te)); | |
146 |
|
231 | |||
147 | // 4: varTS < ts < varTE < te |
|
232 | // 4: varTS < ts < varTE < te | |
148 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; |
|
233 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; | |
149 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; |
|
234 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |
150 | sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
235 | sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
151 | notInCach = var.provideInCacheRangeList(sqp); |
|
236 | notInCach = var.provideInCacheRangeList(sqp); | |
152 | QCOMPARE(notInCach.size(), 1); |
|
237 | QCOMPARE(notInCach.size(), 1); | |
153 | notInCachRange = notInCach.first(); |
|
238 | notInCachRange = notInCach.first(); | |
154 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts)); |
|
239 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts)); | |
155 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(varCRE)); |
|
240 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(varCRE)); | |
156 |
|
241 | |||
157 | // 5: varTS < varTE < ts < te |
|
242 | // 5: varTS < varTE < ts < te | |
158 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 20, 0}}; |
|
243 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 20, 0}}; | |
159 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; |
|
244 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |
160 | sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
245 | sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
161 | notInCach = var.provideInCacheRangeList(sqp); |
|
246 | notInCach = var.provideInCacheRangeList(sqp); | |
162 | QCOMPARE(notInCach.size(), 0); |
|
247 | QCOMPARE(notInCach.size(), 0); | |
163 |
|
248 | |||
164 | // 6: ts <varTS < varTE < te |
|
249 | // 6: ts <varTS < varTE < te | |
165 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}}; |
|
250 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}}; | |
166 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; |
|
251 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |
167 | sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
252 | sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
168 | notInCach = var.provideInCacheRangeList(sqp); |
|
253 | notInCach = var.provideInCacheRangeList(sqp); | |
169 | QCOMPARE(notInCach.size(), 1); |
|
254 | QCOMPARE(notInCach.size(), 1); | |
170 | notInCachRange = notInCach.first(); |
|
255 | notInCachRange = notInCach.first(); | |
171 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(varCRS)); |
|
256 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(varCRS)); | |
172 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(varCRE)); |
|
257 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(varCRE)); | |
173 | } |
|
258 | } | |
174 |
|
259 | |||
175 |
|
260 | |||
176 | QTEST_MAIN(TestVariable) |
|
261 | QTEST_MAIN(TestVariable) | |
177 | #include "TestVariable.moc" |
|
262 | #include "TestVariable.moc" |
General Comments 0
You need to be logged in to leave comments.
Login now