@@ -1,219 +1,219 | |||||
1 | #ifndef SCIQLOP_DATETIMERANGE_H |
|
1 | #ifndef SCIQLOP_DATETIMERANGE_H | |
2 | #define SCIQLOP_DATETIMERANGE_H |
|
2 | #define SCIQLOP_DATETIMERANGE_H | |
3 |
|
3 | |||
4 | #include <cmath> |
|
4 | #include <cmath> | |
5 | #include <QObject> |
|
5 | #include <QObject> | |
6 |
|
6 | |||
7 | #include <QDebug> |
|
7 | #include <QDebug> | |
8 |
|
8 | |||
9 | #include <opaque/numeric_typedef.hpp> |
|
9 | #include <opaque/numeric_typedef.hpp> | |
10 | #include <Common/DateUtils.h> |
|
10 | #include <Common/DateUtils.h> | |
11 | #include <Common/MetaTypes.h> |
|
11 | #include <Common/MetaTypes.h> | |
12 | #include <Common/Numeric.h> |
|
12 | #include <Common/Numeric.h> | |
13 |
|
13 | |||
14 |
|
14 | |||
15 | template <typename T> |
|
15 | template <typename T> | |
16 | struct Seconds : opaque::numeric_typedef<T, Seconds<T>> , |
|
16 | struct Seconds : opaque::numeric_typedef<T, Seconds<T>> , | |
17 | opaque::binop::multipliable <Seconds<T>, true , Seconds<T>, T, T>, |
|
17 | opaque::binop::multipliable <Seconds<T>, true , Seconds<T>, T, T>, | |
18 | opaque::binop::dividable <Seconds<T>, true , Seconds<T>, T, T>, |
|
18 | opaque::binop::dividable <Seconds<T>, true , Seconds<T>, T, T>, | |
19 | opaque::binop::addable <Seconds<T>, true , Seconds<T>, T, T>, |
|
19 | opaque::binop::addable <Seconds<T>, true , Seconds<T>, T, T>, | |
20 | opaque::binop::subtractable <Seconds<T>, true , Seconds<T>, T, T> |
|
20 | opaque::binop::subtractable <Seconds<T>, true , Seconds<T>, T, T> | |
21 |
|
21 | |||
22 | { |
|
22 | { | |
23 | using base = opaque::numeric_typedef<T, Seconds<T>>; |
|
23 | using base = opaque::numeric_typedef<T, Seconds<T>>; | |
24 | using base::base; |
|
24 | using base::base; | |
25 | operator T () const {return this->value;} |
|
25 | operator T () const {return this->value;} | |
26 | }; |
|
26 | }; | |
27 |
|
27 | |||
28 | struct InvalidDateTimeRangeTransformation{}; |
|
28 | struct InvalidDateTimeRangeTransformation{}; | |
29 |
|
29 | |||
30 | struct DateTimeRangeTransformation |
|
30 | struct DateTimeRangeTransformation | |
31 | { |
|
31 | { | |
32 | double zoom; |
|
32 | double zoom; | |
33 | Seconds<double> shift; |
|
33 | Seconds<double> shift; | |
34 | bool operator==(const DateTimeRangeTransformation& other) const |
|
34 | bool operator==(const DateTimeRangeTransformation& other) const | |
35 | { |
|
35 | { | |
36 | return SciQLop::numeric::almost_equal(zoom, other.zoom, 1) && |
|
36 | return SciQLop::numeric::almost_equal(zoom, other.zoom, 1) && | |
37 | SciQLop::numeric::almost_equal<double>(shift, other.shift, 1); |
|
37 | SciQLop::numeric::almost_equal<double>(shift, other.shift, 1); | |
38 | } |
|
38 | } | |
39 | }; |
|
39 | }; | |
40 |
|
40 | |||
41 | /** |
|
41 | /** | |
42 | * @brief The SqpRange struct holds the information of time parameters |
|
42 | * @brief The SqpRange struct holds the information of time parameters | |
43 | */ |
|
43 | */ | |
44 | struct DateTimeRange { |
|
44 | struct DateTimeRange { | |
45 | DateTimeRange() |
|
45 | DateTimeRange() | |
46 | :m_TStart(std::nan("")), m_TEnd(std::nan("")) |
|
46 | :m_TStart(std::nan("")), m_TEnd(std::nan("")) | |
47 | {} |
|
47 | {} | |
48 | DateTimeRange(double TStart, double TEnd) |
|
48 | DateTimeRange(double TStart, double TEnd) | |
49 | :m_TStart(TStart), m_TEnd(TEnd) |
|
49 | :m_TStart(TStart), m_TEnd(TEnd) | |
50 | {} |
|
50 | {} | |
51 | /// Creates SqpRange from dates and times |
|
51 | /// Creates SqpRange from dates and times | |
52 | static DateTimeRange fromDateTime(const QDate &startDate, const QTime &startTime, |
|
52 | static DateTimeRange fromDateTime(const QDate &startDate, const QTime &startTime, | |
53 | const QDate &endDate, const QTime &endTime) |
|
53 | const QDate &endDate, const QTime &endTime) | |
54 | { |
|
54 | { | |
55 | return {DateUtils::secondsSinceEpoch(QDateTime{startDate, startTime, Qt::UTC}), |
|
55 | return {DateUtils::secondsSinceEpoch(QDateTime{startDate, startTime, Qt::UTC}), | |
56 | DateUtils::secondsSinceEpoch(QDateTime{endDate, endTime, Qt::UTC})}; |
|
56 | DateUtils::secondsSinceEpoch(QDateTime{endDate, endTime, Qt::UTC})}; | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | static DateTimeRange fromDateTime(const QDateTime &start, const QDateTime &end) |
|
59 | static DateTimeRange fromDateTime(const QDateTime &start, const QDateTime &end) | |
60 | { |
|
60 | { | |
61 | return {DateUtils::secondsSinceEpoch(start), |
|
61 | return {DateUtils::secondsSinceEpoch(start), | |
62 | DateUtils::secondsSinceEpoch(end)}; |
|
62 | DateUtils::secondsSinceEpoch(end)}; | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | /// Start time (UTC) |
|
65 | /// Start time (UTC) | |
66 | double m_TStart; |
|
66 | double m_TStart; | |
67 | /// End time (UTC) |
|
67 | /// End time (UTC) | |
68 | double m_TEnd; |
|
68 | double m_TEnd; | |
69 |
|
69 | |||
70 | Seconds<double> delta()const noexcept{return Seconds<double>{this->m_TEnd - this->m_TStart};} |
|
70 | Seconds<double> delta()const noexcept{return Seconds<double>{this->m_TEnd - this->m_TStart};} | |
71 |
|
71 | |||
72 | bool contains(const DateTimeRange &dateTime) const noexcept |
|
72 | bool contains(const DateTimeRange &dateTime) const noexcept | |
73 | { |
|
73 | { | |
74 | return (m_TStart <= dateTime.m_TStart && m_TEnd >= dateTime.m_TEnd); |
|
74 | return (m_TStart <= dateTime.m_TStart && m_TEnd >= dateTime.m_TEnd); | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | Seconds<double> center() const noexcept |
|
77 | Seconds<double> center() const noexcept | |
78 | { |
|
78 | { | |
79 | return Seconds<double>((m_TStart + m_TEnd) / 2.); |
|
79 | return Seconds<double>((m_TStart + m_TEnd) / 2.); | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | bool intersect(const DateTimeRange &dateTime) const noexcept |
|
82 | bool intersect(const DateTimeRange &dateTime) const noexcept | |
83 | { |
|
83 | { | |
84 | return (m_TEnd >= dateTime.m_TStart && m_TStart <= dateTime.m_TEnd); |
|
84 | return (m_TEnd >= dateTime.m_TStart && m_TStart <= dateTime.m_TEnd); | |
85 | } |
|
85 | } | |
86 |
|
86 | |||
87 | inline DateTimeRange transform(const DateTimeRangeTransformation& tr)const noexcept; |
|
87 | inline DateTimeRange transform(const DateTimeRangeTransformation& tr)const noexcept; | |
88 |
|
88 | |||
89 | bool operator==(const DateTimeRange &other) const |
|
89 | bool operator==(const DateTimeRange &other) const | |
90 | { |
|
90 | { | |
91 | return SciQLop::numeric::almost_equal(m_TStart, other.m_TStart, 1) && |
|
91 | return SciQLop::numeric::almost_equal(m_TStart, other.m_TStart, 1) && | |
92 | SciQLop::numeric::almost_equal(m_TEnd, other.m_TEnd, 1); |
|
92 | SciQLop::numeric::almost_equal(m_TEnd, other.m_TEnd, 1); | |
93 | } |
|
93 | } | |
94 |
|
94 | |||
95 | bool operator!=(const DateTimeRange &other) const { return !(*this == other); } |
|
95 | bool operator!=(const DateTimeRange &other) const { return !(*this == other); } | |
96 |
|
96 | |||
97 | void grow(double factor)noexcept |
|
97 | void grow(double factor)noexcept | |
98 | { |
|
98 | { | |
99 | double grow_v{delta()*(factor - 1.)/2.}; |
|
99 | double grow_v{delta()*(factor - 1.)/2.}; | |
100 | m_TStart -= grow_v; |
|
100 | m_TStart -= grow_v; | |
101 | m_TEnd += grow_v; |
|
101 | m_TEnd += grow_v; | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | void shrink(double factor)noexcept |
|
104 | void shrink(double factor)noexcept | |
105 | { |
|
105 | { | |
106 | double shrink_v{this->delta()*(1. - factor)/2.}; |
|
106 | double shrink_v{this->delta()*(1. - factor)/2.}; | |
107 | m_TStart += shrink_v; |
|
107 | m_TStart += shrink_v; | |
108 | m_TEnd -= shrink_v; |
|
108 | m_TEnd -= shrink_v; | |
109 | } |
|
109 | } | |
110 |
|
110 | |||
111 | DateTimeRange& operator*=(double k) |
|
111 | DateTimeRange& operator*=(double k) | |
112 | { |
|
112 | { | |
113 | this->grow(k); |
|
113 | this->grow(k); | |
114 | return *this; |
|
114 | return *this; | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | DateTimeRange& operator/=(double k) |
|
117 | DateTimeRange& operator/=(double k) | |
118 | { |
|
118 | { | |
119 | this->shrink(k); |
|
119 | this->shrink(k); | |
120 | return *this; |
|
120 | return *this; | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 | // compute set difference |
|
123 | // compute set difference | |
124 | std::vector<DateTimeRange> operator-(const DateTimeRange& other)const |
|
124 | std::vector<DateTimeRange> operator-(const DateTimeRange& other)const | |
125 | { |
|
125 | { | |
126 | std::vector<DateTimeRange> result; |
|
126 | std::vector<DateTimeRange> result; | |
127 | if(std::isnan(other.m_TStart)||std::isnan(other.m_TEnd)||!this->intersect(other)) |
|
127 | if(std::isnan(other.m_TStart)||std::isnan(other.m_TEnd)||!this->intersect(other)) | |
128 | { |
|
128 | { | |
129 |
result. |
|
129 | result.emplace_back(m_TStart, m_TEnd); | |
130 | } |
|
130 | } | |
131 | else |
|
131 | else | |
132 | { |
|
132 | { | |
133 | if(this->m_TStart<other.m_TStart) |
|
133 | if(this->m_TStart<other.m_TStart) | |
134 | { |
|
134 | { | |
135 |
result. |
|
135 | result.emplace_back(this->m_TStart, other.m_TStart); | |
136 | } |
|
136 | } | |
137 | if(this->m_TEnd>other.m_TEnd) |
|
137 | if(this->m_TEnd>other.m_TEnd) | |
138 | { |
|
138 | { | |
139 |
result. |
|
139 | result.emplace_back(this->m_TEnd, other.m_TEnd); | |
140 | } |
|
140 | } | |
141 | } |
|
141 | } | |
142 | return result; |
|
142 | return result; | |
143 | } |
|
143 | } | |
144 |
|
144 | |||
145 | }; |
|
145 | }; | |
146 |
|
146 | |||
147 | template <class T> |
|
147 | template <class T> | |
148 | DateTimeRange& operator+=(DateTimeRange&r, Seconds<T> offset) |
|
148 | DateTimeRange& operator+=(DateTimeRange&r, Seconds<T> offset) | |
149 | { |
|
149 | { | |
150 | shift(r,offset); |
|
150 | shift(r,offset); | |
151 | return r; |
|
151 | return r; | |
152 | } |
|
152 | } | |
153 |
|
153 | |||
154 | template <class T> |
|
154 | template <class T> | |
155 | DateTimeRange& operator-=(DateTimeRange&r, Seconds<T> offset) |
|
155 | DateTimeRange& operator-=(DateTimeRange&r, Seconds<T> offset) | |
156 | { |
|
156 | { | |
157 | shift(r,-offset); |
|
157 | shift(r,-offset); | |
158 | } |
|
158 | } | |
159 |
|
159 | |||
160 | template <class T> |
|
160 | template <class T> | |
161 | void shift(DateTimeRange& r, Seconds<T> offset) |
|
161 | void shift(DateTimeRange& r, Seconds<T> offset) | |
162 | { |
|
162 | { | |
163 | r.m_TEnd+=static_cast<double>(offset); |
|
163 | r.m_TEnd+=static_cast<double>(offset); | |
164 | r.m_TStart+=static_cast<double>(offset); |
|
164 | r.m_TStart+=static_cast<double>(offset); | |
165 | } |
|
165 | } | |
166 |
|
166 | |||
167 | inline DateTimeRange operator*(const DateTimeRange& r, double k) |
|
167 | inline DateTimeRange operator*(const DateTimeRange& r, double k) | |
168 | { |
|
168 | { | |
169 | DateTimeRange result{r}; |
|
169 | DateTimeRange result{r}; | |
170 | result.grow(k); |
|
170 | result.grow(k); | |
171 | return result; |
|
171 | return result; | |
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 | inline DateTimeRange operator/(const DateTimeRange& r, double k) |
|
174 | inline DateTimeRange operator/(const DateTimeRange& r, double k) | |
175 | { |
|
175 | { | |
176 | DateTimeRange result{r}; |
|
176 | DateTimeRange result{r}; | |
177 | result.shrink(k); |
|
177 | result.shrink(k); | |
178 | return result; |
|
178 | return result; | |
179 | } |
|
179 | } | |
180 |
|
180 | |||
181 | template<class T> |
|
181 | template<class T> | |
182 | DateTimeRange operator+(const DateTimeRange& r, Seconds<T> offset) |
|
182 | DateTimeRange operator+(const DateTimeRange& r, Seconds<T> offset) | |
183 | { |
|
183 | { | |
184 | DateTimeRange result{r}; |
|
184 | DateTimeRange result{r}; | |
185 | shift(result,offset); |
|
185 | shift(result,offset); | |
186 | return result; |
|
186 | return result; | |
187 | } |
|
187 | } | |
188 |
|
188 | |||
189 | template<class T> |
|
189 | template<class T> | |
190 | DateTimeRange operator-(const DateTimeRange& r, Seconds<T> offset) |
|
190 | DateTimeRange operator-(const DateTimeRange& r, Seconds<T> offset) | |
191 | { |
|
191 | { | |
192 | DateTimeRange result{r}; |
|
192 | DateTimeRange result{r}; | |
193 | shift(result,-offset); |
|
193 | shift(result,-offset); | |
194 | return result; |
|
194 | return result; | |
195 | } |
|
195 | } | |
196 |
|
196 | |||
197 | const auto INVALID_RANGE |
|
197 | const auto INVALID_RANGE | |
198 | = DateTimeRange{std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN()}; |
|
198 | = DateTimeRange{std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN()}; | |
199 |
|
199 | |||
200 | inline QDebug operator<<(QDebug d, DateTimeRange obj) |
|
200 | inline QDebug operator<<(QDebug d, DateTimeRange obj) | |
201 | { |
|
201 | { | |
202 | auto tendDateTimeStart = DateUtils::dateTime(obj.m_TStart); |
|
202 | auto tendDateTimeStart = DateUtils::dateTime(obj.m_TStart); | |
203 | auto tendDateTimeEnd = DateUtils::dateTime(obj.m_TEnd); |
|
203 | auto tendDateTimeEnd = DateUtils::dateTime(obj.m_TEnd); | |
204 |
|
204 | |||
205 | d << "ts: " << tendDateTimeStart << " te: " << tendDateTimeEnd; |
|
205 | d << "ts: " << tendDateTimeStart << " te: " << tendDateTimeEnd; | |
206 | return d; |
|
206 | return d; | |
207 | } |
|
207 | } | |
208 |
|
208 | |||
209 |
|
209 | |||
210 |
|
210 | |||
211 | DateTimeRange DateTimeRange::transform(const DateTimeRangeTransformation &tr) const noexcept |
|
211 | DateTimeRange DateTimeRange::transform(const DateTimeRangeTransformation &tr) const noexcept | |
212 | { |
|
212 | { | |
213 | return DateTimeRange{*this} * tr.zoom + tr.shift; |
|
213 | return DateTimeRange{*this} * tr.zoom + tr.shift; | |
214 | } |
|
214 | } | |
215 |
|
215 | |||
216 | // Required for using shared_ptr in signals/slots |
|
216 | // Required for using shared_ptr in signals/slots | |
217 | SCIQLOP_REGISTER_META_TYPE(SQPRANGE_REGISTRY, DateTimeRange) |
|
217 | SCIQLOP_REGISTER_META_TYPE(SQPRANGE_REGISTRY, DateTimeRange) | |
218 |
|
218 | |||
219 | #endif // SCIQLOP_DATETIMERANGE_H |
|
219 | #endif // SCIQLOP_DATETIMERANGE_H |
@@ -1,62 +1,62 | |||||
1 | #ifndef SCIQLOP_DATETIMERANGEHELPER_H |
|
1 | #ifndef SCIQLOP_DATETIMERANGEHELPER_H | |
2 | #define SCIQLOP_DATETIMERANGEHELPER_H |
|
2 | #define SCIQLOP_DATETIMERANGEHELPER_H | |
3 |
|
3 | |||
4 | #include <cmath> |
|
4 | #include <cmath> | |
5 | #include <variant> |
|
5 | #include <variant> | |
6 | #include <QObject> |
|
6 | #include <QObject> | |
7 |
|
7 | |||
8 | #include <QDebug> |
|
8 | #include <QDebug> | |
9 |
|
9 | |||
10 | #include <opaque/numeric_typedef.hpp> |
|
10 | #include <opaque/numeric_typedef.hpp> | |
11 | #include <Common/DateUtils.h> |
|
11 | #include <Common/DateUtils.h> | |
12 | #include <Common/MetaTypes.h> |
|
12 | #include <Common/MetaTypes.h> | |
13 | #include <Common/Numeric.h> |
|
13 | #include <Common/Numeric.h> | |
14 | #include <Data/DateTimeRange.h> |
|
14 | #include <Data/DateTimeRange.h> | |
15 |
|
15 | |||
16 | namespace DateTimeRangeHelper { |
|
16 | namespace DateTimeRangeHelper { | |
17 |
|
17 | |||
18 |
|
18 | |||
19 | bool isnan(const DateTimeRange& range) |
|
19 | inline bool isnan(const DateTimeRange& range) | |
20 | { |
|
20 | { | |
21 | return std::isnan(range.m_TStart) && std::isnan(range.m_TEnd); |
|
21 | return std::isnan(range.m_TStart) && std::isnan(range.m_TEnd); | |
22 | } |
|
22 | } | |
23 |
|
23 | |||
24 | bool hasnan(const DateTimeRange& range) |
|
24 | inline bool hasnan(const DateTimeRange& range) | |
25 | { |
|
25 | { | |
26 | return std::isnan(range.m_TStart) || std::isnan(range.m_TEnd); |
|
26 | return std::isnan(range.m_TStart) || std::isnan(range.m_TEnd); | |
27 | } |
|
27 | } | |
28 |
|
28 | |||
29 | bool isPureShift(const DateTimeRange& range1, const DateTimeRange& range2) |
|
29 | inline bool isPureShift(const DateTimeRange& range1, const DateTimeRange& range2) | |
30 | { |
|
30 | { | |
31 | return SciQLop::numeric::almost_equal<double>(range1.delta(), range2.delta(), 1) |
|
31 | return SciQLop::numeric::almost_equal<double>(range1.delta(), range2.delta(), 1) | |
32 | && !SciQLop::numeric::almost_equal(range1.m_TStart, range2.m_TStart, 1); |
|
32 | && !SciQLop::numeric::almost_equal(range1.m_TStart, range2.m_TStart, 1); | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | bool isPureZoom(const DateTimeRange& range1, const DateTimeRange& range2) |
|
35 | inline bool isPureZoom(const DateTimeRange& range1, const DateTimeRange& range2) | |
36 | { |
|
36 | { | |
37 | return !SciQLop::numeric::almost_equal<double>(range1.delta(),range2.delta(),1)&& |
|
37 | return !SciQLop::numeric::almost_equal<double>(range1.delta(),range2.delta(),1)&& | |
38 | SciQLop::numeric::almost_equal<double>(range1.center(), range2.center(),1); |
|
38 | SciQLop::numeric::almost_equal<double>(range1.center(), range2.center(),1); | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | /** |
|
41 | /** | |
42 | * @brief computeTransformation such as range2 = zoom*range1 + shift |
|
42 | * @brief computeTransformation such as range2 = zoom*range1 + shift | |
43 | * @param range1 |
|
43 | * @param range1 | |
44 | * @param range2 |
|
44 | * @param range2 | |
45 | * @return trnaformation applied to range1 to get range2 or an object of type |
|
45 | * @return trnaformation applied to range1 to get range2 or an object of type | |
46 | * InvalidDateTimeRangeTransformation if the transformation has NaN or forbiden values |
|
46 | * InvalidDateTimeRangeTransformation if the transformation has NaN or forbiden values | |
47 | */ |
|
47 | */ | |
48 | std::variant<DateTimeRangeTransformation, InvalidDateTimeRangeTransformation> |
|
48 | inline std::variant<DateTimeRangeTransformation, InvalidDateTimeRangeTransformation> | |
49 | computeTransformation(const DateTimeRange& range1, const DateTimeRange& range2) |
|
49 | computeTransformation(const DateTimeRange& range1, const DateTimeRange& range2) | |
50 | { |
|
50 | { | |
51 | double zoom = range2.delta()/range1.delta(); |
|
51 | double zoom = range2.delta()/range1.delta(); | |
52 | Seconds<double> shift = range2.center() - (range1*zoom).center(); |
|
52 | Seconds<double> shift = range2.center() - (range1*zoom).center(); | |
53 | bool zoomValid = zoom!=0. && !std::isnan(zoom) && !std::isinf(zoom); |
|
53 | bool zoomValid = zoom!=0. && !std::isnan(zoom) && !std::isinf(zoom); | |
54 | bool shiftValid = !std::isnan(shift.value) && !std::isinf(shift.value); |
|
54 | bool shiftValid = !std::isnan(shift.value) && !std::isinf(shift.value); | |
55 | if(zoomValid && shiftValid) |
|
55 | if(zoomValid && shiftValid) | |
56 | return DateTimeRangeTransformation{zoom, shift}; |
|
56 | return DateTimeRangeTransformation{zoom, shift}; | |
57 | return InvalidDateTimeRangeTransformation{}; |
|
57 | return InvalidDateTimeRangeTransformation{}; | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | #endif // SCIQLOP_DATETIMERANGEHELPER_H |
|
62 | #endif // SCIQLOP_DATETIMERANGEHELPER_H |
@@ -1,39 +1,40 | |||||
1 | #include <memory> |
|
1 | #include <memory> | |
2 | #include <vector> |
|
2 | #include <vector> | |
3 | #include <QHash> |
|
3 | #include <QHash> | |
4 | #include <QObject> |
|
4 | #include <QObject> | |
5 | #include <QMutexLocker> |
|
5 | #include <QMutexLocker> | |
6 | #include <QUuid> |
|
6 | #include <QUuid> | |
7 | #include <QItemSelectionModel> |
|
7 | #include <QItemSelectionModel> | |
8 | #include <Common/spimpl.h> |
|
8 | #include <Common/spimpl.h> | |
9 | #include <Variable/Variable.h> |
|
9 | #include <Variable/Variable.h> | |
10 | #include <Variable/VariableSynchronizationGroup.h> |
|
10 | #include <Variable/VariableSynchronizationGroup.h> | |
11 | #include <Variable/VariableModel.h> |
|
11 | #include <Variable/VariableModel.h> | |
12 | #include <Data/IDataProvider.h> |
|
12 | #include <Data/IDataProvider.h> | |
13 | #include "Data/DateTimeRange.h" |
|
13 | #include "Data/DateTimeRange.h" | |
14 |
|
14 | |||
15 | class VariableController2: public QObject |
|
15 | class VariableController2: public QObject | |
16 | { |
|
16 | { | |
17 | class VariableController2Private; |
|
17 | class VariableController2Private; | |
18 | Q_OBJECT |
|
18 | Q_OBJECT | |
19 |
|
19 | |||
20 | spimpl::unique_impl_ptr<VariableController2Private> impl; |
|
20 | spimpl::unique_impl_ptr<VariableController2Private> impl; | |
21 |
|
21 | |||
22 | public: |
|
22 | public: | |
23 | explicit VariableController2(); |
|
23 | explicit VariableController2(); | |
24 | std::shared_ptr<Variable> createVariable(const QString &name, const QVariantHash &metadata, |
|
24 | std::shared_ptr<Variable> createVariable(const QString &name, const QVariantHash &metadata, | |
25 |
std::shared_ptr<IDataProvider> provider, |
|
25 | const std::shared_ptr<IDataProvider>& provider, | |
|
26 | const DateTimeRange &range); | |||
26 |
|
27 | |||
27 | void deleteVariable(std::shared_ptr<Variable> variable); |
|
28 | void deleteVariable(const std::shared_ptr<Variable>& variable); | |
28 | void changeRange(std::shared_ptr<Variable> variable, DateTimeRange r); |
|
29 | void changeRange(const std::shared_ptr<Variable>& variable, const DateTimeRange& r); | |
29 | void asyncChangeRange(std::shared_ptr<Variable> variable, DateTimeRange r); |
|
30 | void asyncChangeRange(const std::shared_ptr<Variable>& variable, const DateTimeRange& r); | |
30 | const std::set<std::shared_ptr<Variable>> variables(); |
|
31 | const std::set<std::shared_ptr<Variable>> variables(); | |
31 |
|
32 | |||
32 |
void synchronize(st |
|
33 | void synchronize(const std::shared_ptr<Variable>& var, const std::shared_ptr<Variable>& with); | |
33 |
|
34 | |||
34 |
|
35 | |||
35 | signals: |
|
36 | signals: | |
36 | void variableAdded(std::shared_ptr<Variable>); |
|
37 | void variableAdded(const std::shared_ptr<Variable>&); | |
37 | void variableDeleted(std::shared_ptr<Variable>); |
|
38 | void variableDeleted(const std::shared_ptr<Variable>&); | |
38 |
|
39 | |||
39 | }; |
|
40 | }; |
@@ -1,190 +1,190 | |||||
1 | #include "Variable/VariableController2.h" |
|
1 | #include "Variable/VariableController2.h" | |
2 | #include "Variable/VariableSynchronizationGroup2.h" |
|
2 | #include "Variable/VariableSynchronizationGroup2.h" | |
3 | #include <Common/containers.h> |
|
3 | #include <Common/containers.h> | |
4 | #include <Common/debug.h> |
|
4 | #include <Common/debug.h> | |
5 | #include <Data/DataProviderParameters.h> |
|
5 | #include <Data/DataProviderParameters.h> | |
6 | #include <Data/DateTimeRangeHelper.h> |
|
6 | #include <Data/DateTimeRangeHelper.h> | |
7 | #include <Variable/VariableCacheStrategyFactory.h> |
|
7 | #include <Variable/VariableCacheStrategyFactory.h> | |
8 |
|
8 | |||
9 | class VariableController2::VariableController2Private |
|
9 | class VariableController2::VariableController2Private | |
10 | { |
|
10 | { | |
11 | QMap<QUuid,std::shared_ptr<Variable>> _variables; |
|
11 | QMap<QUuid,std::shared_ptr<Variable>> _variables; | |
12 | QMap<QUuid,std::shared_ptr<IDataProvider>> _providers; |
|
12 | QMap<QUuid,std::shared_ptr<IDataProvider>> _providers; | |
13 | QMap<QUuid,std::shared_ptr<VariableSynchronizationGroup2>> _synchronizationGroups; |
|
13 | QMap<QUuid,std::shared_ptr<VariableSynchronizationGroup2>> _synchronizationGroups; | |
14 | std::unique_ptr<VariableCacheStrategy> _cacheStrategy; |
|
14 | std::unique_ptr<VariableCacheStrategy> _cacheStrategy; | |
15 | bool p_contains(std::shared_ptr<Variable> variable) |
|
15 | bool p_contains(const std::shared_ptr<Variable>& variable) | |
16 | { |
|
16 | { | |
17 | return _providers.contains(variable->ID()); |
|
17 | return _providers.contains(variable->ID()); | |
18 | } |
|
18 | } | |
19 | bool v_contains(std::shared_ptr<Variable> variable) |
|
19 | bool v_contains(const std::shared_ptr<Variable>& variable) | |
20 | { |
|
20 | { | |
21 | return SciQLop::containers::contains(this->_variables, variable); |
|
21 | return SciQLop::containers::contains(this->_variables, variable); | |
22 | } |
|
22 | } | |
23 | bool sg_contains(std::shared_ptr<Variable> variable) |
|
23 | bool sg_contains(const std::shared_ptr<Variable>& variable) | |
24 | { |
|
24 | { | |
25 | return _synchronizationGroups.contains(variable->ID()); |
|
25 | return _synchronizationGroups.contains(variable->ID()); | |
26 | } |
|
26 | } | |
27 |
|
27 | |||
28 | void _changeRange(std::shared_ptr<Variable> var, DateTimeRange r) |
|
28 | void _changeRange(const std::shared_ptr<Variable>& var, DateTimeRange r) | |
29 | { |
|
29 | { | |
30 | auto provider = _providers[var->ID()]; |
|
30 | auto provider = _providers[var->ID()]; | |
31 | DateTimeRange newCacheRange; |
|
31 | DateTimeRange newCacheRange; | |
32 | std::vector<DateTimeRange> missingRanges; |
|
32 | std::vector<DateTimeRange> missingRanges; | |
33 | if(DateTimeRangeHelper::hasnan(var->cacheRange())) |
|
33 | if(DateTimeRangeHelper::hasnan(var->cacheRange())) | |
34 | { |
|
34 | { | |
35 | newCacheRange = _cacheStrategy->computeRange(r,r); |
|
35 | newCacheRange = _cacheStrategy->computeRange(r,r); | |
36 | missingRanges = {newCacheRange}; |
|
36 | missingRanges = {newCacheRange}; | |
37 | } |
|
37 | } | |
38 | else |
|
38 | else | |
39 | { |
|
39 | { | |
40 | newCacheRange = _cacheStrategy->computeRange(var->cacheRange(),r); |
|
40 | newCacheRange = _cacheStrategy->computeRange(var->cacheRange(),r); | |
41 | missingRanges = newCacheRange - var->cacheRange(); |
|
41 | missingRanges = newCacheRange - var->cacheRange(); | |
42 | } |
|
42 | } | |
43 | for(auto range:missingRanges) |
|
43 | for(auto range:missingRanges) | |
44 | { |
|
44 | { | |
45 | auto data = provider->getData(DataProviderParameters{{range},var->metadata()}); |
|
45 | auto data = provider->getData(DataProviderParameters{{range},var->metadata()}); | |
46 | var->mergeDataSeries(data); |
|
46 | var->mergeDataSeries(data); | |
47 | } |
|
47 | } | |
48 | var->setCacheRange(newCacheRange); |
|
48 | var->setCacheRange(newCacheRange); | |
49 | var->setRange(r); |
|
49 | var->setRange(r); | |
50 | } |
|
50 | } | |
51 | public: |
|
51 | public: | |
52 | VariableController2Private(QObject* parent=Q_NULLPTR) |
|
52 | VariableController2Private(QObject* parent=Q_NULLPTR) | |
53 | :_cacheStrategy(VariableCacheStrategyFactory::createCacheStrategy(CacheStrategy::SingleThreshold)) |
|
53 | :_cacheStrategy(VariableCacheStrategyFactory::createCacheStrategy(CacheStrategy::SingleThreshold)) | |
54 | { |
|
54 | { | |
55 | Q_UNUSED(parent); |
|
55 | Q_UNUSED(parent); | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | ~VariableController2Private() = default; |
|
58 | ~VariableController2Private() = default; | |
59 |
|
59 | |||
60 | std::shared_ptr<Variable> createVariable(const QString &name, const QVariantHash &metadata, std::shared_ptr<IDataProvider> provider) |
|
60 | std::shared_ptr<Variable> createVariable(const QString &name, const QVariantHash &metadata, std::shared_ptr<IDataProvider> provider) | |
61 | { |
|
61 | { | |
62 | auto newVar = std::make_shared<Variable>(name,metadata); |
|
62 | auto newVar = std::make_shared<Variable>(name,metadata); | |
63 | this->_variables[newVar->ID()] = newVar; |
|
63 | this->_variables[newVar->ID()] = newVar; | |
64 | this->_providers[newVar->ID()] = provider; |
|
64 | this->_providers[newVar->ID()] = std::move(provider); | |
65 | this->_synchronizationGroups[newVar->ID()] = std::make_shared<VariableSynchronizationGroup2>(newVar->ID()); |
|
65 | this->_synchronizationGroups[newVar->ID()] = std::make_shared<VariableSynchronizationGroup2>(newVar->ID()); | |
66 | return newVar; |
|
66 | return newVar; | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | void deleteVariable(std::shared_ptr<Variable> variable) |
|
69 | void deleteVariable(const std::shared_ptr<Variable>& variable) | |
70 | { |
|
70 | { | |
71 | /* |
|
71 | /* | |
72 | * Removing twice a var is ok but a var without provider has to be a hard error |
|
72 | * Removing twice a var is ok but a var without provider has to be a hard error | |
73 | * this means we got the var controller in an inconsistent state |
|
73 | * this means we got the var controller in an inconsistent state | |
74 | */ |
|
74 | */ | |
75 | if(v_contains(variable)) |
|
75 | if(v_contains(variable)) | |
76 | this->_variables.remove(variable->ID()); |
|
76 | this->_variables.remove(variable->ID()); | |
77 | if(p_contains(variable)) |
|
77 | if(p_contains(variable)) | |
78 | this->_providers.remove(variable->ID()); |
|
78 | this->_providers.remove(variable->ID()); | |
79 | else |
|
79 | else | |
80 | SCIQLOP_ERROR(VariableController2Private, "No provider found for given variable"); |
|
80 | SCIQLOP_ERROR(VariableController2Private, "No provider found for given variable"); | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | void changeRange(std::shared_ptr<Variable> variable, DateTimeRange r) |
|
83 | void changeRange(const std::shared_ptr<Variable>& variable, DateTimeRange r) | |
84 | { |
|
84 | { | |
85 | if(p_contains(variable)) |
|
85 | if(p_contains(variable)) | |
86 | { |
|
86 | { | |
87 | if(!DateTimeRangeHelper::hasnan(r)) |
|
87 | if(!DateTimeRangeHelper::hasnan(r)) | |
88 | { |
|
88 | { | |
89 | auto transformation = DateTimeRangeHelper::computeTransformation(variable->range(),r); |
|
89 | auto transformation = DateTimeRangeHelper::computeTransformation(variable->range(),r); | |
90 | auto group = _synchronizationGroups[variable->ID()]; |
|
90 | auto group = _synchronizationGroups[variable->ID()]; | |
91 | if(std::holds_alternative<DateTimeRangeTransformation>(transformation)) |
|
91 | if(std::holds_alternative<DateTimeRangeTransformation>(transformation)) | |
92 | { |
|
92 | { | |
93 | for(auto varId:group->variables()) |
|
93 | for(auto varId:group->variables()) | |
94 | { |
|
94 | { | |
95 | auto var = _variables[varId]; |
|
95 | auto var = _variables[varId]; | |
96 | auto newRange = var->range().transform(std::get<DateTimeRangeTransformation>(transformation)); |
|
96 | auto newRange = var->range().transform(std::get<DateTimeRangeTransformation>(transformation)); | |
97 | _changeRange(var,newRange); |
|
97 | _changeRange(var,newRange); | |
98 | } |
|
98 | } | |
99 | } |
|
99 | } | |
100 | else // force new range to all variables -> may be weird if more than one var in the group |
|
100 | else // force new range to all variables -> may be weird if more than one var in the group | |
101 | // @TODO ensure that there is no side effects |
|
101 | // @TODO ensure that there is no side effects | |
102 | { |
|
102 | { | |
103 | for(auto varId:group->variables()) |
|
103 | for(auto varId:group->variables()) | |
104 | { |
|
104 | { | |
105 | auto var = _variables[varId]; |
|
105 | auto var = _variables[varId]; | |
106 | _changeRange(var,r); |
|
106 | _changeRange(var,r); | |
107 | } |
|
107 | } | |
108 | } |
|
108 | } | |
109 | } |
|
109 | } | |
110 | else |
|
110 | else | |
111 | { |
|
111 | { | |
112 | SCIQLOP_ERROR(VariableController2Private, "Invalid range containing NaN"); |
|
112 | SCIQLOP_ERROR(VariableController2Private, "Invalid range containing NaN"); | |
113 | } |
|
113 | } | |
114 | } |
|
114 | } | |
115 | else |
|
115 | else | |
116 | { |
|
116 | { | |
117 | SCIQLOP_ERROR(VariableController2Private, "No provider found for given variable"); |
|
117 | SCIQLOP_ERROR(VariableController2Private, "No provider found for given variable"); | |
118 | } |
|
118 | } | |
119 | } |
|
119 | } | |
120 |
|
120 | |||
121 |
void synchronize(st |
|
121 | void synchronize(const std::shared_ptr<Variable>& var, const std::shared_ptr<Variable>& with) | |
122 | { |
|
122 | { | |
123 | if(v_contains(var) && v_contains(with)) |
|
123 | if(v_contains(var) && v_contains(with)) | |
124 | { |
|
124 | { | |
125 | if(sg_contains(var) && sg_contains(with)) |
|
125 | if(sg_contains(var) && sg_contains(with)) | |
126 | { |
|
126 | { | |
127 |
|
127 | |||
128 | auto dest_group = this->_synchronizationGroups[with->ID()]; |
|
128 | auto dest_group = this->_synchronizationGroups[with->ID()]; | |
129 | this->_synchronizationGroups[var->ID()] = dest_group; |
|
129 | this->_synchronizationGroups[var->ID()] = dest_group; | |
130 | dest_group->addVariable(var->ID()); |
|
130 | dest_group->addVariable(var->ID()); | |
131 | } |
|
131 | } | |
132 | else |
|
132 | else | |
133 | { |
|
133 | { | |
134 | SCIQLOP_ERROR(VariableController2Private, "At least one of the given variables isn't in a sync group"); |
|
134 | SCIQLOP_ERROR(VariableController2Private, "At least one of the given variables isn't in a sync group"); | |
135 | } |
|
135 | } | |
136 | } |
|
136 | } | |
137 | else |
|
137 | else | |
138 | { |
|
138 | { | |
139 | SCIQLOP_ERROR(VariableController2Private, "At least one of the given variables is not found"); |
|
139 | SCIQLOP_ERROR(VariableController2Private, "At least one of the given variables is not found"); | |
140 | } |
|
140 | } | |
141 | } |
|
141 | } | |
142 |
|
142 | |||
143 | const std::set<std::shared_ptr<Variable>> variables() |
|
143 | const std::set<std::shared_ptr<Variable>> variables() | |
144 | { |
|
144 | { | |
145 | std::set<std::shared_ptr<Variable>> vars; |
|
145 | std::set<std::shared_ptr<Variable>> vars; | |
146 |
for(auto var:_variables |
|
146 | for(const auto &var:_variables) | |
147 | { |
|
147 | { | |
148 | vars.insert(var); |
|
148 | vars.insert(var); | |
149 | } |
|
149 | } | |
150 | return vars; |
|
150 | return vars; | |
151 | } |
|
151 | } | |
152 |
|
152 | |||
153 | }; |
|
153 | }; | |
154 |
|
154 | |||
155 | VariableController2::VariableController2() |
|
155 | VariableController2::VariableController2() | |
156 | :impl{spimpl::make_unique_impl<VariableController2Private>()} |
|
156 | :impl{spimpl::make_unique_impl<VariableController2Private>()} | |
157 | {} |
|
157 | {} | |
158 |
|
158 | |||
159 | std::shared_ptr<Variable> VariableController2::createVariable(const QString &name, const QVariantHash &metadata, std::shared_ptr<IDataProvider> provider, const DateTimeRange &range) |
|
159 | std::shared_ptr<Variable> VariableController2::createVariable(const QString &name, const QVariantHash &metadata, const std::shared_ptr<IDataProvider>& provider, const DateTimeRange &range) | |
160 | { |
|
160 | { | |
161 | auto var = impl->createVariable(name, metadata, provider); |
|
161 | auto var = impl->createVariable(name, metadata, provider); | |
162 | emit variableAdded(var); |
|
162 | emit variableAdded(var); | |
163 | if(!DateTimeRangeHelper::hasnan(range)) |
|
163 | if(!DateTimeRangeHelper::hasnan(range)) | |
164 | impl->changeRange(var,range); |
|
164 | impl->changeRange(var,range); | |
165 | else |
|
165 | else | |
166 | SCIQLOP_ERROR(VariableController2, "Creating a variable with default constructed DateTimeRange is an error"); |
|
166 | SCIQLOP_ERROR(VariableController2, "Creating a variable with default constructed DateTimeRange is an error"); | |
167 | return var; |
|
167 | return var; | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | void VariableController2::deleteVariable(std::shared_ptr<Variable> variable) |
|
170 | void VariableController2::deleteVariable(const std::shared_ptr<Variable>& variable) | |
171 | { |
|
171 | { | |
172 | impl->deleteVariable(variable); |
|
172 | impl->deleteVariable(variable); | |
173 | emit variableDeleted(variable); |
|
173 | emit variableDeleted(variable); | |
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | void VariableController2::changeRange(std::shared_ptr<Variable> variable, DateTimeRange r) |
|
176 | void VariableController2::changeRange(const std::shared_ptr<Variable>& variable, const DateTimeRange& r) | |
177 | { |
|
177 | { | |
178 | impl->changeRange(variable, r); |
|
178 | impl->changeRange(variable, r); | |
179 | } |
|
179 | } | |
180 |
|
180 | |||
181 | const std::set<std::shared_ptr<Variable> > VariableController2::variables() |
|
181 | const std::set<std::shared_ptr<Variable> > VariableController2::variables() | |
182 | { |
|
182 | { | |
183 | return impl->variables(); |
|
183 | return impl->variables(); | |
184 | } |
|
184 | } | |
185 |
|
185 | |||
186 |
void VariableController2::synchronize(st |
|
186 | void VariableController2::synchronize(const std::shared_ptr<Variable> &var, const std::shared_ptr<Variable> &with) | |
187 | { |
|
187 | { | |
188 | impl->synchronize(var, with); |
|
188 | impl->synchronize(var, with); | |
189 | } |
|
189 | } | |
190 |
|
190 |
@@ -1,409 +1,410 | |||||
1 | #include <Variable/Variable.h> |
|
1 | #include <Variable/Variable.h> | |
2 |
|
2 | |||
3 | #include <Data/ScalarSeries.h> |
|
3 | #include <Data/ScalarSeries.h> | |
4 |
|
4 | |||
5 | #include <QObject> |
|
5 | #include <QObject> | |
6 | #include <QtTest> |
|
6 | #include <QtTest> | |
7 |
|
7 | |||
8 | #include <memory> |
|
8 | #include <memory> | |
9 |
|
9 | |||
10 | namespace { |
|
10 | namespace { | |
11 |
|
11 | |||
12 | /// Generates a date in double |
|
12 | /// Generates a date in double | |
13 | auto date = [](int year, int month, int day, int hours, int minutes, int seconds) { |
|
13 | auto date = [](int year, int month, int day, int hours, int minutes, int seconds) { | |
14 | return DateUtils::secondsSinceEpoch( |
|
14 | return DateUtils::secondsSinceEpoch( | |
15 | QDateTime{{year, month, day}, {hours, minutes, seconds}, Qt::UTC}); |
|
15 | QDateTime{{year, month, day}, {hours, minutes, seconds}, Qt::UTC}); | |
16 | }; |
|
16 | }; | |
17 |
|
17 | |||
18 | /// Generates a series of test data for a range |
|
18 | /// Generates a series of test data for a range | |
19 | std::shared_ptr<ScalarSeries> dataSeries(const DateTimeRange &range) |
|
19 | std::shared_ptr<ScalarSeries> dataSeries(const DateTimeRange &range) | |
20 | { |
|
20 | { | |
21 | auto xAxisData = std::vector<double>{}; |
|
21 | auto xAxisData = std::vector<double>{}; | |
22 | auto valuesData = std::vector<double>{}; |
|
22 | auto valuesData = std::vector<double>{}; | |
23 |
|
23 | |||
24 | auto value = 0; |
|
24 | auto value = 0; | |
25 | for (auto x = range.m_TStart; x <= range.m_TEnd; ++x, ++value) { |
|
25 | for (auto x = range.m_TStart; x <= range.m_TEnd; ++x, ++value) { | |
26 | xAxisData.push_back(x); |
|
26 | xAxisData.push_back(x); | |
27 | valuesData.push_back(value); |
|
27 | valuesData.push_back(value); | |
28 | } |
|
28 | } | |
29 |
|
29 | |||
30 | return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData), Unit{}, |
|
30 | return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData), Unit{}, | |
31 | Unit{}); |
|
31 | Unit{}); | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | } // namespace |
|
34 | } // namespace | |
35 |
|
35 | |||
36 | Q_DECLARE_METATYPE(std::shared_ptr<ScalarSeries>) |
|
36 | Q_DECLARE_METATYPE(std::shared_ptr<ScalarSeries>) | |
37 |
|
37 | |||
38 | class TestVariable : public QObject { |
|
38 | class TestVariable : public QObject { | |
39 | Q_OBJECT |
|
39 | Q_OBJECT | |
40 |
|
40 | |||
41 | private slots: |
|
41 | private slots: | |
|
42 | void initTestCase() { QSKIP("Skip it"); } | |||
42 | void testClone_data(); |
|
43 | void testClone_data(); | |
43 | void testClone(); |
|
44 | void testClone(); | |
44 |
|
45 | |||
45 | void testNotInCacheRangeList(); |
|
46 | void testNotInCacheRangeList(); | |
46 | void testInCacheRangeList(); |
|
47 | void testInCacheRangeList(); | |
47 |
|
48 | |||
48 | void testNbPoints_data(); |
|
49 | void testNbPoints_data(); | |
49 | void testNbPoints(); |
|
50 | void testNbPoints(); | |
50 |
|
51 | |||
51 | void testRealRange_data(); |
|
52 | void testRealRange_data(); | |
52 | void testRealRange(); |
|
53 | void testRealRange(); | |
53 | }; |
|
54 | }; | |
54 |
|
55 | |||
55 | void TestVariable::testClone_data() |
|
56 | void TestVariable::testClone_data() | |
56 | { |
|
57 | { | |
57 | // ////////////// // |
|
58 | // ////////////// // | |
58 | // Test structure // |
|
59 | // Test structure // | |
59 | // ////////////// // |
|
60 | // ////////////// // | |
60 |
|
61 | |||
61 | QTest::addColumn<QString>("name"); |
|
62 | QTest::addColumn<QString>("name"); | |
62 | QTest::addColumn<QVariantHash>("metadata"); |
|
63 | QTest::addColumn<QVariantHash>("metadata"); | |
63 | QTest::addColumn<DateTimeRange>("range"); |
|
64 | QTest::addColumn<DateTimeRange>("range"); | |
64 | QTest::addColumn<DateTimeRange>("cacheRange"); |
|
65 | QTest::addColumn<DateTimeRange>("cacheRange"); | |
65 | QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries"); |
|
66 | QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries"); | |
66 |
|
67 | |||
67 | // ////////// // |
|
68 | // ////////// // | |
68 | // Test cases // |
|
69 | // Test cases // | |
69 | // ////////// // |
|
70 | // ////////// // | |
70 |
|
71 | |||
71 | auto cacheRange = DateTimeRange{date(2017, 1, 1, 12, 0, 0), date(2017, 1, 1, 13, 0, 0)}; |
|
72 | auto cacheRange = DateTimeRange{date(2017, 1, 1, 12, 0, 0), date(2017, 1, 1, 13, 0, 0)}; | |
72 | QTest::newRow("clone1") << QStringLiteral("var1") |
|
73 | QTest::newRow("clone1") << QStringLiteral("var1") | |
73 | << QVariantHash{{"data1", 1}, {"data2", "abc"}} |
|
74 | << QVariantHash{{"data1", 1}, {"data2", "abc"}} | |
74 | << DateTimeRange{date(2017, 1, 1, 12, 30, 0), (date(2017, 1, 1, 12, 45, 0))} |
|
75 | << DateTimeRange{date(2017, 1, 1, 12, 30, 0), (date(2017, 1, 1, 12, 45, 0))} | |
75 | << cacheRange << dataSeries(cacheRange); |
|
76 | << cacheRange << dataSeries(cacheRange); | |
76 | } |
|
77 | } | |
77 |
|
78 | |||
78 | void TestVariable::testClone() |
|
79 | void TestVariable::testClone() | |
79 | { |
|
80 | { | |
80 | // Creates variable |
|
81 | // Creates variable | |
81 | QFETCH(QString, name); |
|
82 | QFETCH(QString, name); | |
82 | QFETCH(QVariantHash, metadata); |
|
83 | QFETCH(QVariantHash, metadata); | |
83 | QFETCH(DateTimeRange, range); |
|
84 | QFETCH(DateTimeRange, range); | |
84 | QFETCH(DateTimeRange, cacheRange); |
|
85 | QFETCH(DateTimeRange, cacheRange); | |
85 | QFETCH(std::shared_ptr<ScalarSeries>, dataSeries); |
|
86 | QFETCH(std::shared_ptr<ScalarSeries>, dataSeries); | |
86 |
|
87 | |||
87 | Variable variable{name, metadata}; |
|
88 | Variable variable{name, metadata}; | |
88 | variable.setRange(range); |
|
89 | variable.setRange(range); | |
89 | variable.setCacheRange(cacheRange); |
|
90 | variable.setCacheRange(cacheRange); | |
90 | variable.mergeDataSeries(dataSeries); |
|
91 | variable.mergeDataSeries(dataSeries); | |
91 |
|
92 | |||
92 | // Clones variable |
|
93 | // Clones variable | |
93 | auto clone = variable.clone(); |
|
94 | auto clone = variable.clone(); | |
94 |
|
95 | |||
95 | // Checks cloned variable's state |
|
96 | // Checks cloned variable's state | |
96 | QCOMPARE(clone->name(), name); |
|
97 | QCOMPARE(clone->name(), name); | |
97 | QCOMPARE(clone->metadata(), metadata); |
|
98 | QCOMPARE(clone->metadata(), metadata); | |
98 | QCOMPARE(clone->range(), range); |
|
99 | QCOMPARE(clone->range(), range); | |
99 | QCOMPARE(clone->cacheRange(), cacheRange); |
|
100 | QCOMPARE(clone->cacheRange(), cacheRange); | |
100 |
|
101 | |||
101 | // Compares data series |
|
102 | // Compares data series | |
102 | if (dataSeries != nullptr) { |
|
103 | if (dataSeries != nullptr) { | |
103 | QVERIFY(clone->dataSeries() != nullptr); |
|
104 | QVERIFY(clone->dataSeries() != nullptr); | |
104 | QVERIFY(std::equal(dataSeries->cbegin(), dataSeries->cend(), clone->dataSeries()->cbegin(), |
|
105 | QVERIFY(std::equal(dataSeries->cbegin(), dataSeries->cend(), clone->dataSeries()->cbegin(), | |
105 | clone->dataSeries()->cend(), [](const auto &it1, const auto &it2) { |
|
106 | clone->dataSeries()->cend(), [](const auto &it1, const auto &it2) { | |
106 | return it1.x() == it2.x() && it1.value() == it2.value(); |
|
107 | return it1.x() == it2.x() && it1.value() == it2.value(); | |
107 | })); |
|
108 | })); | |
108 | } |
|
109 | } | |
109 | else { |
|
110 | else { | |
110 | QVERIFY(clone->dataSeries() == nullptr); |
|
111 | QVERIFY(clone->dataSeries() == nullptr); | |
111 | } |
|
112 | } | |
112 | } |
|
113 | } | |
113 |
|
114 | |||
114 | void TestVariable::testNotInCacheRangeList() |
|
115 | void TestVariable::testNotInCacheRangeList() | |
115 | { |
|
116 | { | |
116 | auto varRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; |
|
117 | auto varRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; | |
117 | auto varRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 40, 0}}; |
|
118 | auto varRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 40, 0}}; | |
118 |
|
119 | |||
119 | auto sqpR = DateTimeRange{DateUtils::secondsSinceEpoch(varRS), DateUtils::secondsSinceEpoch(varRE)}; |
|
120 | auto sqpR = DateTimeRange{DateUtils::secondsSinceEpoch(varRS), DateUtils::secondsSinceEpoch(varRE)}; | |
120 |
|
121 | |||
121 | auto varCRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}}; |
|
122 | auto varCRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}}; | |
122 | auto varCRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; |
|
123 | auto varCRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; | |
123 |
|
124 | |||
124 | auto sqpCR |
|
125 | auto sqpCR | |
125 | = DateTimeRange{DateUtils::secondsSinceEpoch(varCRS), DateUtils::secondsSinceEpoch(varCRE)}; |
|
126 | = DateTimeRange{DateUtils::secondsSinceEpoch(varCRS), DateUtils::secondsSinceEpoch(varCRE)}; | |
126 |
|
127 | |||
127 | Variable var{"Var test"}; |
|
128 | Variable var{"Var test"}; | |
128 | var.setRange(sqpR); |
|
129 | var.setRange(sqpR); | |
129 | var.setCacheRange(sqpCR); |
|
130 | var.setCacheRange(sqpCR); | |
130 |
|
131 | |||
131 | // 1: [ts,te] < varTS |
|
132 | // 1: [ts,te] < varTS | |
132 | auto ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; |
|
133 | auto ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | |
133 | auto te = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}}; |
|
134 | auto te = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}}; | |
134 | auto sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
135 | auto sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
135 |
|
136 | |||
136 | auto notInCach = var.provideNotInCacheRangeList(sqp); |
|
137 | auto notInCach = var.provideNotInCacheRangeList(sqp); | |
137 |
|
138 | |||
138 | QCOMPARE(notInCach.size(), 1); |
|
139 | QCOMPARE(notInCach.size(), 1); | |
139 |
|
140 | |||
140 | auto notInCachRange = notInCach.first(); |
|
141 | auto notInCachRange = notInCach.first(); | |
141 |
|
142 | |||
142 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts)); |
|
143 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts)); | |
143 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te)); |
|
144 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te)); | |
144 |
|
145 | |||
145 | // 2: ts < varTS < te < varTE |
|
146 | // 2: ts < varTS < te < varTE | |
146 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; |
|
147 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | |
147 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; |
|
148 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; | |
148 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
149 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
149 | notInCach = var.provideNotInCacheRangeList(sqp); |
|
150 | notInCach = var.provideNotInCacheRangeList(sqp); | |
150 | QCOMPARE(notInCach.size(), 1); |
|
151 | QCOMPARE(notInCach.size(), 1); | |
151 | notInCachRange = notInCach.first(); |
|
152 | notInCachRange = notInCach.first(); | |
152 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts)); |
|
153 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts)); | |
153 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(varCRS)); |
|
154 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(varCRS)); | |
154 |
|
155 | |||
155 | // 3: varTS < ts < te < varTE |
|
156 | // 3: varTS < ts < te < varTE | |
156 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; |
|
157 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; | |
157 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; |
|
158 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; | |
158 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
159 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
159 | notInCach = var.provideNotInCacheRangeList(sqp); |
|
160 | notInCach = var.provideNotInCacheRangeList(sqp); | |
160 | QCOMPARE(notInCach.size(), 0); |
|
161 | QCOMPARE(notInCach.size(), 0); | |
161 |
|
162 | |||
162 |
|
163 | |||
163 | // 4: varTS < ts < varTE < te |
|
164 | // 4: varTS < ts < varTE < te | |
164 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; |
|
165 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; | |
165 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; |
|
166 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |
166 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
167 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
167 | notInCach = var.provideNotInCacheRangeList(sqp); |
|
168 | notInCach = var.provideNotInCacheRangeList(sqp); | |
168 | QCOMPARE(notInCach.size(), 1); |
|
169 | QCOMPARE(notInCach.size(), 1); | |
169 | notInCachRange = notInCach.first(); |
|
170 | notInCachRange = notInCach.first(); | |
170 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(varCRE)); |
|
171 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(varCRE)); | |
171 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te)); |
|
172 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te)); | |
172 |
|
173 | |||
173 | // 5: varTS < varTE < ts < te |
|
174 | // 5: varTS < varTE < ts < te | |
174 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 20, 0}}; |
|
175 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 20, 0}}; | |
175 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; |
|
176 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |
176 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
177 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
177 | notInCach = var.provideNotInCacheRangeList(sqp); |
|
178 | notInCach = var.provideNotInCacheRangeList(sqp); | |
178 | QCOMPARE(notInCach.size(), 1); |
|
179 | QCOMPARE(notInCach.size(), 1); | |
179 | notInCachRange = notInCach.first(); |
|
180 | notInCachRange = notInCach.first(); | |
180 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts)); |
|
181 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts)); | |
181 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te)); |
|
182 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te)); | |
182 |
|
183 | |||
183 | // 6: ts <varTS < varTE < te |
|
184 | // 6: ts <varTS < varTE < te | |
184 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}}; |
|
185 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}}; | |
185 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; |
|
186 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |
186 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
187 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
187 | notInCach = var.provideNotInCacheRangeList(sqp); |
|
188 | notInCach = var.provideNotInCacheRangeList(sqp); | |
188 | QCOMPARE(notInCach.size(), 2); |
|
189 | QCOMPARE(notInCach.size(), 2); | |
189 | notInCachRange = notInCach.first(); |
|
190 | notInCachRange = notInCach.first(); | |
190 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts)); |
|
191 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts)); | |
191 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(varCRS)); |
|
192 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(varCRS)); | |
192 | notInCachRange = notInCach[1]; |
|
193 | notInCachRange = notInCach[1]; | |
193 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(varCRE)); |
|
194 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(varCRE)); | |
194 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te)); |
|
195 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te)); | |
195 | } |
|
196 | } | |
196 |
|
197 | |||
197 |
|
198 | |||
198 | void TestVariable::testInCacheRangeList() |
|
199 | void TestVariable::testInCacheRangeList() | |
199 | { |
|
200 | { | |
200 | auto varRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; |
|
201 | auto varRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; | |
201 | auto varRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 40, 0}}; |
|
202 | auto varRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 40, 0}}; | |
202 |
|
203 | |||
203 | auto sqpR = DateTimeRange{DateUtils::secondsSinceEpoch(varRS), DateUtils::secondsSinceEpoch(varRE)}; |
|
204 | auto sqpR = DateTimeRange{DateUtils::secondsSinceEpoch(varRS), DateUtils::secondsSinceEpoch(varRE)}; | |
204 |
|
205 | |||
205 | auto varCRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}}; |
|
206 | auto varCRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}}; | |
206 | auto varCRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; |
|
207 | auto varCRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; | |
207 | auto sqpCR |
|
208 | auto sqpCR | |
208 | = DateTimeRange{DateUtils::secondsSinceEpoch(varCRS), DateUtils::secondsSinceEpoch(varCRE)}; |
|
209 | = DateTimeRange{DateUtils::secondsSinceEpoch(varCRS), DateUtils::secondsSinceEpoch(varCRE)}; | |
209 |
|
210 | |||
210 | Variable var{"Var test"}; |
|
211 | Variable var{"Var test"}; | |
211 | var.setRange(sqpR); |
|
212 | var.setRange(sqpR); | |
212 | var.setCacheRange(sqpCR); |
|
213 | var.setCacheRange(sqpCR); | |
213 |
|
214 | |||
214 | // 1: [ts,te] < varTS |
|
215 | // 1: [ts,te] < varTS | |
215 | auto ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; |
|
216 | auto ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | |
216 | auto te = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}}; |
|
217 | auto te = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}}; | |
217 | auto sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
218 | auto sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
218 |
|
219 | |||
219 | auto notInCach = var.provideInCacheRangeList(sqp); |
|
220 | auto notInCach = var.provideInCacheRangeList(sqp); | |
220 |
|
221 | |||
221 | QCOMPARE(notInCach.size(), 0); |
|
222 | QCOMPARE(notInCach.size(), 0); | |
222 |
|
223 | |||
223 | // 2: ts < varTS < te < varTE |
|
224 | // 2: ts < varTS < te < varTE | |
224 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; |
|
225 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | |
225 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; |
|
226 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; | |
226 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
227 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
227 | notInCach = var.provideInCacheRangeList(sqp); |
|
228 | notInCach = var.provideInCacheRangeList(sqp); | |
228 | QCOMPARE(notInCach.size(), 1); |
|
229 | QCOMPARE(notInCach.size(), 1); | |
229 | auto notInCachRange = notInCach.first(); |
|
230 | auto notInCachRange = notInCach.first(); | |
230 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(varCRS)); |
|
231 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(varCRS)); | |
231 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te)); |
|
232 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te)); | |
232 |
|
233 | |||
233 | // 3: varTS < ts < te < varTE |
|
234 | // 3: varTS < ts < te < varTE | |
234 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; |
|
235 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; | |
235 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; |
|
236 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; | |
236 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
237 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
237 | notInCach = var.provideInCacheRangeList(sqp); |
|
238 | notInCach = var.provideInCacheRangeList(sqp); | |
238 | QCOMPARE(notInCach.size(), 1); |
|
239 | QCOMPARE(notInCach.size(), 1); | |
239 | notInCachRange = notInCach.first(); |
|
240 | notInCachRange = notInCach.first(); | |
240 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts)); |
|
241 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts)); | |
241 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te)); |
|
242 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te)); | |
242 |
|
243 | |||
243 | // 4: varTS < ts < varTE < te |
|
244 | // 4: varTS < ts < varTE < te | |
244 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; |
|
245 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; | |
245 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; |
|
246 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |
246 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
247 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
247 | notInCach = var.provideInCacheRangeList(sqp); |
|
248 | notInCach = var.provideInCacheRangeList(sqp); | |
248 | QCOMPARE(notInCach.size(), 1); |
|
249 | QCOMPARE(notInCach.size(), 1); | |
249 | notInCachRange = notInCach.first(); |
|
250 | notInCachRange = notInCach.first(); | |
250 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts)); |
|
251 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts)); | |
251 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(varCRE)); |
|
252 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(varCRE)); | |
252 |
|
253 | |||
253 | // 5: varTS < varTE < ts < te |
|
254 | // 5: varTS < varTE < ts < te | |
254 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 20, 0}}; |
|
255 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 20, 0}}; | |
255 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; |
|
256 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |
256 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
257 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
257 | notInCach = var.provideInCacheRangeList(sqp); |
|
258 | notInCach = var.provideInCacheRangeList(sqp); | |
258 | QCOMPARE(notInCach.size(), 0); |
|
259 | QCOMPARE(notInCach.size(), 0); | |
259 |
|
260 | |||
260 | // 6: ts <varTS < varTE < te |
|
261 | // 6: ts <varTS < varTE < te | |
261 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}}; |
|
262 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}}; | |
262 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; |
|
263 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |
263 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
264 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
264 | notInCach = var.provideInCacheRangeList(sqp); |
|
265 | notInCach = var.provideInCacheRangeList(sqp); | |
265 | QCOMPARE(notInCach.size(), 1); |
|
266 | QCOMPARE(notInCach.size(), 1); | |
266 | notInCachRange = notInCach.first(); |
|
267 | notInCachRange = notInCach.first(); | |
267 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(varCRS)); |
|
268 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(varCRS)); | |
268 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(varCRE)); |
|
269 | QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(varCRE)); | |
269 | } |
|
270 | } | |
270 |
|
271 | |||
271 | namespace { |
|
272 | namespace { | |
272 |
|
273 | |||
273 | /// Struct used to represent an operation for @sa TestVariable::testNbPoints() |
|
274 | /// Struct used to represent an operation for @sa TestVariable::testNbPoints() | |
274 | struct NbPointsOperation { |
|
275 | struct NbPointsOperation { | |
275 | DateTimeRange m_CacheRange; /// Range to set for the variable |
|
276 | DateTimeRange m_CacheRange; /// Range to set for the variable | |
276 | std::shared_ptr<ScalarSeries> m_DataSeries; /// Series to merge in the variable |
|
277 | std::shared_ptr<ScalarSeries> m_DataSeries; /// Series to merge in the variable | |
277 | int m_ExpectedNbPoints; /// Number of points in the variable expected after operation |
|
278 | int m_ExpectedNbPoints; /// Number of points in the variable expected after operation | |
278 | }; |
|
279 | }; | |
279 |
|
280 | |||
280 | using NbPointsOperations = std::vector<NbPointsOperation>; |
|
281 | using NbPointsOperations = std::vector<NbPointsOperation>; | |
281 |
|
282 | |||
282 | } // namespace |
|
283 | } // namespace | |
283 |
|
284 | |||
284 | Q_DECLARE_METATYPE(NbPointsOperations) |
|
285 | Q_DECLARE_METATYPE(NbPointsOperations) | |
285 |
|
286 | |||
286 | void TestVariable::testNbPoints_data() |
|
287 | void TestVariable::testNbPoints_data() | |
287 | { |
|
288 | { | |
288 | // ////////////// // |
|
289 | // ////////////// // | |
289 | // Test structure // |
|
290 | // Test structure // | |
290 | // ////////////// // |
|
291 | // ////////////// // | |
291 |
|
292 | |||
292 | QTest::addColumn<NbPointsOperations>("operations"); |
|
293 | QTest::addColumn<NbPointsOperations>("operations"); | |
293 |
|
294 | |||
294 | // ////////// // |
|
295 | // ////////// // | |
295 | // Test cases // |
|
296 | // Test cases // | |
296 | // ////////// // |
|
297 | // ////////// // | |
297 | NbPointsOperations operations{}; |
|
298 | NbPointsOperations operations{}; | |
298 |
|
299 | |||
299 | // Sets cache range (expected nb points = values data) |
|
300 | // Sets cache range (expected nb points = values data) | |
300 | auto cacheRange = DateTimeRange{date(2017, 1, 1, 12, 0, 0), date(2017, 1, 1, 12, 0, 9)}; |
|
301 | auto cacheRange = DateTimeRange{date(2017, 1, 1, 12, 0, 0), date(2017, 1, 1, 12, 0, 9)}; | |
301 | operations.push_back({cacheRange, dataSeries(cacheRange), 10}); |
|
302 | operations.push_back({cacheRange, dataSeries(cacheRange), 10}); | |
302 |
|
303 | |||
303 | // Doubles cache but don't add data series (expected nb points don't change) |
|
304 | // Doubles cache but don't add data series (expected nb points don't change) | |
304 | cacheRange = DateTimeRange{date(2017, 1, 1, 12, 0, 0), date(2017, 1, 1, 12, 0, 19)}; |
|
305 | cacheRange = DateTimeRange{date(2017, 1, 1, 12, 0, 0), date(2017, 1, 1, 12, 0, 19)}; | |
305 | operations.push_back({cacheRange, dataSeries(INVALID_RANGE), 10}); |
|
306 | operations.push_back({cacheRange, dataSeries(INVALID_RANGE), 10}); | |
306 |
|
307 | |||
307 | // Doubles cache and data series (expected nb points change) |
|
308 | // Doubles cache and data series (expected nb points change) | |
308 | cacheRange = DateTimeRange{date(2017, 1, 1, 12, 0, 0), date(2017, 1, 1, 12, 0, 19)}; |
|
309 | cacheRange = DateTimeRange{date(2017, 1, 1, 12, 0, 0), date(2017, 1, 1, 12, 0, 19)}; | |
309 | operations.push_back({cacheRange, dataSeries(cacheRange), 20}); |
|
310 | operations.push_back({cacheRange, dataSeries(cacheRange), 20}); | |
310 |
|
311 | |||
311 | // Decreases cache (expected nb points decreases as the series is purged) |
|
312 | // Decreases cache (expected nb points decreases as the series is purged) | |
312 | cacheRange = DateTimeRange{date(2017, 1, 1, 12, 0, 5), date(2017, 1, 1, 12, 0, 9)}; |
|
313 | cacheRange = DateTimeRange{date(2017, 1, 1, 12, 0, 5), date(2017, 1, 1, 12, 0, 9)}; | |
313 | operations.push_back({cacheRange, dataSeries(INVALID_RANGE), 5}); |
|
314 | operations.push_back({cacheRange, dataSeries(INVALID_RANGE), 5}); | |
314 |
|
315 | |||
315 | QTest::newRow("nbPoints1") << operations; |
|
316 | QTest::newRow("nbPoints1") << operations; | |
316 | } |
|
317 | } | |
317 |
|
318 | |||
318 | void TestVariable::testNbPoints() |
|
319 | void TestVariable::testNbPoints() | |
319 | { |
|
320 | { | |
320 | // Creates variable |
|
321 | // Creates variable | |
321 | Variable variable{"var"}; |
|
322 | Variable variable{"var"}; | |
322 | QCOMPARE(variable.nbPoints(), 0); |
|
323 | QCOMPARE(variable.nbPoints(), 0); | |
323 |
|
324 | |||
324 | QFETCH(NbPointsOperations, operations); |
|
325 | QFETCH(NbPointsOperations, operations); | |
325 | for (const auto &operation : operations) { |
|
326 | for (const auto &operation : operations) { | |
326 | // Sets cache range and merge data series |
|
327 | // Sets cache range and merge data series | |
327 | variable.setCacheRange(operation.m_CacheRange); |
|
328 | variable.setCacheRange(operation.m_CacheRange); | |
328 | if (operation.m_DataSeries != nullptr) { |
|
329 | if (operation.m_DataSeries != nullptr) { | |
329 | variable.mergeDataSeries(operation.m_DataSeries); |
|
330 | variable.mergeDataSeries(operation.m_DataSeries); | |
330 | } |
|
331 | } | |
331 |
|
332 | |||
332 | // Checks nb points |
|
333 | // Checks nb points | |
333 | QCOMPARE(variable.nbPoints(), operation.m_ExpectedNbPoints); |
|
334 | QCOMPARE(variable.nbPoints(), operation.m_ExpectedNbPoints); | |
334 | } |
|
335 | } | |
335 | } |
|
336 | } | |
336 |
|
337 | |||
337 | namespace { |
|
338 | namespace { | |
338 |
|
339 | |||
339 | /// Struct used to represent a range operation on a variable |
|
340 | /// Struct used to represent a range operation on a variable | |
340 | /// @sa TestVariable::testRealRange() |
|
341 | /// @sa TestVariable::testRealRange() | |
341 | struct RangeOperation { |
|
342 | struct RangeOperation { | |
342 | DateTimeRange m_CacheRange; /// Range to set for the variable |
|
343 | DateTimeRange m_CacheRange; /// Range to set for the variable | |
343 | std::shared_ptr<ScalarSeries> m_DataSeries; /// Series to merge in the variable |
|
344 | std::shared_ptr<ScalarSeries> m_DataSeries; /// Series to merge in the variable | |
344 | DateTimeRange m_ExpectedRealRange; /// Real Range expected after operation on the variable |
|
345 | DateTimeRange m_ExpectedRealRange; /// Real Range expected after operation on the variable | |
345 | }; |
|
346 | }; | |
346 |
|
347 | |||
347 | using RangeOperations = std::vector<RangeOperation>; |
|
348 | using RangeOperations = std::vector<RangeOperation>; | |
348 |
|
349 | |||
349 | } // namespace |
|
350 | } // namespace | |
350 |
|
351 | |||
351 | Q_DECLARE_METATYPE(RangeOperations) |
|
352 | Q_DECLARE_METATYPE(RangeOperations) | |
352 |
|
353 | |||
353 | void TestVariable::testRealRange_data() |
|
354 | void TestVariable::testRealRange_data() | |
354 | { |
|
355 | { | |
355 | // ////////////// // |
|
356 | // ////////////// // | |
356 | // Test structure // |
|
357 | // Test structure // | |
357 | // ////////////// // |
|
358 | // ////////////// // | |
358 |
|
359 | |||
359 | QTest::addColumn<RangeOperations>("operations"); |
|
360 | QTest::addColumn<RangeOperations>("operations"); | |
360 |
|
361 | |||
361 | // ////////// // |
|
362 | // ////////// // | |
362 | // Test cases // |
|
363 | // Test cases // | |
363 | // ////////// // |
|
364 | // ////////// // | |
364 | RangeOperations operations{}; |
|
365 | RangeOperations operations{}; | |
365 |
|
366 | |||
366 | // Inits cache range and data series (expected real range = cache range) |
|
367 | // Inits cache range and data series (expected real range = cache range) | |
367 | auto cacheRange = DateTimeRange{date(2017, 1, 1, 12, 0, 0), date(2017, 1, 1, 13, 0, 0)}; |
|
368 | auto cacheRange = DateTimeRange{date(2017, 1, 1, 12, 0, 0), date(2017, 1, 1, 13, 0, 0)}; | |
368 | operations.push_back({cacheRange, dataSeries(cacheRange), cacheRange}); |
|
369 | operations.push_back({cacheRange, dataSeries(cacheRange), cacheRange}); | |
369 |
|
370 | |||
370 | // Changes cache range and updates data series (expected real range = cache range) |
|
371 | // Changes cache range and updates data series (expected real range = cache range) | |
371 | cacheRange = DateTimeRange{date(2017, 1, 1, 14, 0, 0), date(2017, 1, 1, 15, 0, 0)}; |
|
372 | cacheRange = DateTimeRange{date(2017, 1, 1, 14, 0, 0), date(2017, 1, 1, 15, 0, 0)}; | |
372 | operations.push_back({cacheRange, dataSeries(cacheRange), cacheRange}); |
|
373 | operations.push_back({cacheRange, dataSeries(cacheRange), cacheRange}); | |
373 |
|
374 | |||
374 | // Changes cache range and update data series but with a lower range (expected real range = |
|
375 | // Changes cache range and update data series but with a lower range (expected real range = | |
375 | // data series range) |
|
376 | // data series range) | |
376 | cacheRange = DateTimeRange{date(2017, 1, 1, 12, 0, 0), date(2017, 1, 1, 16, 0, 0)}; |
|
377 | cacheRange = DateTimeRange{date(2017, 1, 1, 12, 0, 0), date(2017, 1, 1, 16, 0, 0)}; | |
377 | auto dataSeriesRange = DateTimeRange{date(2017, 1, 1, 14, 0, 0), date(2017, 1, 1, 15, 0, 0)}; |
|
378 | auto dataSeriesRange = DateTimeRange{date(2017, 1, 1, 14, 0, 0), date(2017, 1, 1, 15, 0, 0)}; | |
378 | operations.push_back({cacheRange, dataSeries(dataSeriesRange), dataSeriesRange}); |
|
379 | operations.push_back({cacheRange, dataSeries(dataSeriesRange), dataSeriesRange}); | |
379 |
|
380 | |||
380 | // Changes cache range but DON'T update data series (expected real range = cache range |
|
381 | // Changes cache range but DON'T update data series (expected real range = cache range | |
381 | // before operation) |
|
382 | // before operation) | |
382 | cacheRange = DateTimeRange{date(2017, 1, 1, 10, 0, 0), date(2017, 1, 1, 17, 0, 0)}; |
|
383 | cacheRange = DateTimeRange{date(2017, 1, 1, 10, 0, 0), date(2017, 1, 1, 17, 0, 0)}; | |
383 | operations.push_back({cacheRange, nullptr, dataSeriesRange}); |
|
384 | operations.push_back({cacheRange, nullptr, dataSeriesRange}); | |
384 |
|
385 | |||
385 | QTest::newRow("realRange1") << operations; |
|
386 | QTest::newRow("realRange1") << operations; | |
386 | } |
|
387 | } | |
387 |
|
388 | |||
388 | void TestVariable::testRealRange() |
|
389 | void TestVariable::testRealRange() | |
389 | { |
|
390 | { | |
390 | // Creates variable (real range is invalid) |
|
391 | // Creates variable (real range is invalid) | |
391 | Variable variable{"var"}; |
|
392 | Variable variable{"var"}; | |
392 | QCOMPARE(variable.realRange(), INVALID_RANGE); |
|
393 | QCOMPARE(variable.realRange(), INVALID_RANGE); | |
393 |
|
394 | |||
394 | QFETCH(RangeOperations, operations); |
|
395 | QFETCH(RangeOperations, operations); | |
395 | for (const auto &operation : operations) { |
|
396 | for (const auto &operation : operations) { | |
396 | // Sets cache range and merge data series |
|
397 | // Sets cache range and merge data series | |
397 | variable.setCacheRange(operation.m_CacheRange); |
|
398 | variable.setCacheRange(operation.m_CacheRange); | |
398 | if (operation.m_DataSeries != nullptr) { |
|
399 | if (operation.m_DataSeries != nullptr) { | |
399 | variable.mergeDataSeries(operation.m_DataSeries); |
|
400 | variable.mergeDataSeries(operation.m_DataSeries); | |
400 | } |
|
401 | } | |
401 |
|
402 | |||
402 | // Checks real range |
|
403 | // Checks real range | |
403 | QCOMPARE(variable.realRange(), operation.m_ExpectedRealRange); |
|
404 | QCOMPARE(variable.realRange(), operation.m_ExpectedRealRange); | |
404 | } |
|
405 | } | |
405 | } |
|
406 | } | |
406 |
|
407 | |||
407 |
|
408 | |||
408 | QTEST_MAIN(TestVariable) |
|
409 | QTEST_MAIN(TestVariable) | |
409 | #include "TestVariable.moc" |
|
410 | #include "TestVariable.moc" |
@@ -1,333 +1,335 | |||||
1 | #include <Variable/Variable.h> |
|
1 | #include <Variable/Variable.h> | |
2 | #include <Variable/VariableCacheController.h> |
|
2 | #include <Variable/VariableCacheController.h> | |
3 |
|
3 | |||
4 | #include <QObject> |
|
4 | #include <QObject> | |
5 | #include <QtTest> |
|
5 | #include <QtTest> | |
6 |
|
6 | |||
7 | #include <memory> |
|
7 | #include <memory> | |
8 |
|
8 | |||
9 | class TestVariableCacheController : public QObject { |
|
9 | class TestVariableCacheController : public QObject { | |
10 | Q_OBJECT |
|
10 | Q_OBJECT | |
11 |
|
11 | |||
12 | private slots: |
|
12 | private slots: | |
|
13 | void initTestCase() { QSKIP("Skip it"); } | |||
|
14 | ||||
13 | void testProvideNotInCacheDateTimeList(); |
|
15 | void testProvideNotInCacheDateTimeList(); | |
14 |
|
16 | |||
15 | void testAddDateTime(); |
|
17 | void testAddDateTime(); | |
16 | }; |
|
18 | }; | |
17 |
|
19 | |||
18 |
|
20 | |||
19 | void TestVariableCacheController::testProvideNotInCacheDateTimeList() |
|
21 | void TestVariableCacheController::testProvideNotInCacheDateTimeList() | |
20 | { |
|
22 | { | |
21 | VariableCacheController variableCacheController{}; |
|
23 | VariableCacheController variableCacheController{}; | |
22 |
|
24 | |||
23 | auto ts0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}}; |
|
25 | auto ts0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}}; | |
24 | auto te0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; |
|
26 | auto te0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; | |
25 | auto sqp0 = DateTimeRange{DateUtils::secondsSinceEpoch(ts0), DateUtils::secondsSinceEpoch(te0)}; |
|
27 | auto sqp0 = DateTimeRange{DateUtils::secondsSinceEpoch(ts0), DateUtils::secondsSinceEpoch(te0)}; | |
26 |
|
28 | |||
27 | auto ts1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 6, 0, 0}}; |
|
29 | auto ts1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 6, 0, 0}}; | |
28 | auto te1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 8, 0, 0}}; |
|
30 | auto te1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 8, 0, 0}}; | |
29 | auto sqp1 = DateTimeRange{DateUtils::secondsSinceEpoch(ts1), DateUtils::secondsSinceEpoch(te1)}; |
|
31 | auto sqp1 = DateTimeRange{DateUtils::secondsSinceEpoch(ts1), DateUtils::secondsSinceEpoch(te1)}; | |
30 |
|
32 | |||
31 | auto ts2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 18, 0, 0}}; |
|
33 | auto ts2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 18, 0, 0}}; | |
32 | auto te2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 20, 0, 0}}; |
|
34 | auto te2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 20, 0, 0}}; | |
33 | auto sqp2 = DateTimeRange{DateUtils::secondsSinceEpoch(ts2), DateUtils::secondsSinceEpoch(te2)}; |
|
35 | auto sqp2 = DateTimeRange{DateUtils::secondsSinceEpoch(ts2), DateUtils::secondsSinceEpoch(te2)}; | |
34 |
|
36 | |||
35 | auto var0 = std::make_shared<Variable>(""); |
|
37 | auto var0 = std::make_shared<Variable>(""); | |
36 | var0->setRange(sqp0); |
|
38 | var0->setRange(sqp0); | |
37 |
|
39 | |||
38 | variableCacheController.addDateTime(var0, sqp0); |
|
40 | variableCacheController.addDateTime(var0, sqp0); | |
39 | variableCacheController.addDateTime(var0, sqp1); |
|
41 | variableCacheController.addDateTime(var0, sqp1); | |
40 | variableCacheController.addDateTime(var0, sqp2); |
|
42 | variableCacheController.addDateTime(var0, sqp2); | |
41 |
|
43 | |||
42 | // first case [ts,te] < ts0 |
|
44 | // first case [ts,te] < ts0 | |
43 | auto ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; |
|
45 | auto ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | |
44 | auto te = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}}; |
|
46 | auto te = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}}; | |
45 | auto sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
47 | auto sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
46 |
|
48 | |||
47 |
|
49 | |||
48 | auto notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
50 | auto notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
49 |
|
51 | |||
50 | QCOMPARE(notInCach.size(), 1); |
|
52 | QCOMPARE(notInCach.size(), 1); | |
51 | auto notInCacheSqp = notInCach.first(); |
|
53 | auto notInCacheSqp = notInCach.first(); | |
52 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(ts)); |
|
54 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(ts)); | |
53 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(te)); |
|
55 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(te)); | |
54 |
|
56 | |||
55 |
|
57 | |||
56 | // second case ts < ts0 && ts0 < te <= te0 |
|
58 | // second case ts < ts0 && ts0 < te <= te0 | |
57 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; |
|
59 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | |
58 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; |
|
60 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; | |
59 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
61 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
60 |
|
62 | |||
61 |
|
63 | |||
62 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
64 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
63 |
|
65 | |||
64 | QCOMPARE(notInCach.size(), 1); |
|
66 | QCOMPARE(notInCach.size(), 1); | |
65 | notInCacheSqp = notInCach.first(); |
|
67 | notInCacheSqp = notInCach.first(); | |
66 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(ts)); |
|
68 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(ts)); | |
67 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(ts0)); |
|
69 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(ts0)); | |
68 |
|
70 | |||
69 | // 3th case ts < ts0 && te0 < te <= ts1 |
|
71 | // 3th case ts < ts0 && te0 < te <= ts1 | |
70 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; |
|
72 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | |
71 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; |
|
73 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |
72 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
74 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
73 |
|
75 | |||
74 |
|
76 | |||
75 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
77 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
76 |
|
78 | |||
77 | QCOMPARE(notInCach.size(), 2); |
|
79 | QCOMPARE(notInCach.size(), 2); | |
78 | notInCacheSqp = notInCach.first(); |
|
80 | notInCacheSqp = notInCach.first(); | |
79 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(ts)); |
|
81 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(ts)); | |
80 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(ts0)); |
|
82 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(ts0)); | |
81 |
|
83 | |||
82 | notInCacheSqp = notInCach.at(1); |
|
84 | notInCacheSqp = notInCach.at(1); | |
83 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(te0)); |
|
85 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(te0)); | |
84 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(te)); |
|
86 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(te)); | |
85 |
|
87 | |||
86 | // 4th case ts < ts0 && ts1 < te <= te1 |
|
88 | // 4th case ts < ts0 && ts1 < te <= te1 | |
87 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; |
|
89 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | |
88 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 7, 0, 0}}; |
|
90 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 7, 0, 0}}; | |
89 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
91 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
90 |
|
92 | |||
91 |
|
93 | |||
92 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
94 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
93 |
|
95 | |||
94 | QCOMPARE(notInCach.size(), 2); |
|
96 | QCOMPARE(notInCach.size(), 2); | |
95 | notInCacheSqp = notInCach.first(); |
|
97 | notInCacheSqp = notInCach.first(); | |
96 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(ts)); |
|
98 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(ts)); | |
97 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(ts0)); |
|
99 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(ts0)); | |
98 |
|
100 | |||
99 | notInCacheSqp = notInCach.at(1); |
|
101 | notInCacheSqp = notInCach.at(1); | |
100 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(te0)); |
|
102 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(te0)); | |
101 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(ts1)); |
|
103 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(ts1)); | |
102 |
|
104 | |||
103 | // 5th case ts < ts0 && te3 < te |
|
105 | // 5th case ts < ts0 && te3 < te | |
104 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; |
|
106 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | |
105 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 22, 0, 0}}; |
|
107 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 22, 0, 0}}; | |
106 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
108 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
107 |
|
109 | |||
108 |
|
110 | |||
109 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
111 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
110 |
|
112 | |||
111 | QCOMPARE(notInCach.size(), 4); |
|
113 | QCOMPARE(notInCach.size(), 4); | |
112 | notInCacheSqp = notInCach.first(); |
|
114 | notInCacheSqp = notInCach.first(); | |
113 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(ts)); |
|
115 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(ts)); | |
114 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(ts0)); |
|
116 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(ts0)); | |
115 |
|
117 | |||
116 | notInCacheSqp = notInCach.at(1); |
|
118 | notInCacheSqp = notInCach.at(1); | |
117 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(te0)); |
|
119 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(te0)); | |
118 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(ts1)); |
|
120 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(ts1)); | |
119 |
|
121 | |||
120 | notInCacheSqp = notInCach.at(2); |
|
122 | notInCacheSqp = notInCach.at(2); | |
121 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(te1)); |
|
123 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(te1)); | |
122 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(ts2)); |
|
124 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(ts2)); | |
123 |
|
125 | |||
124 | notInCacheSqp = notInCach.at(3); |
|
126 | notInCacheSqp = notInCach.at(3); | |
125 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(te2)); |
|
127 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(te2)); | |
126 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(te)); |
|
128 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(te)); | |
127 |
|
129 | |||
128 |
|
130 | |||
129 | // 6th case ts2 < ts |
|
131 | // 6th case ts2 < ts | |
130 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 45, 0, 0}}; |
|
132 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 45, 0, 0}}; | |
131 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 47, 0, 0}}; |
|
133 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 47, 0, 0}}; | |
132 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
134 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
133 |
|
135 | |||
134 |
|
136 | |||
135 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
137 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
136 |
|
138 | |||
137 | QCOMPARE(notInCach.size(), 1); |
|
139 | QCOMPARE(notInCach.size(), 1); | |
138 | notInCacheSqp = notInCach.first(); |
|
140 | notInCacheSqp = notInCach.first(); | |
139 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(ts)); |
|
141 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(ts)); | |
140 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(te)); |
|
142 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(te)); | |
141 |
|
143 | |||
142 | // 7th case ts = te0 && te < ts1 |
|
144 | // 7th case ts = te0 && te < ts1 | |
143 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; |
|
145 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; | |
144 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; |
|
146 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |
145 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
147 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
146 |
|
148 | |||
147 |
|
149 | |||
148 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
150 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
149 |
|
151 | |||
150 | QCOMPARE(notInCach.size(), 1); |
|
152 | QCOMPARE(notInCach.size(), 1); | |
151 | notInCacheSqp = notInCach.first(); |
|
153 | notInCacheSqp = notInCach.first(); | |
152 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(te0)); |
|
154 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(te0)); | |
153 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(te)); |
|
155 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(te)); | |
154 |
|
156 | |||
155 | // 8th case ts0 < ts < te0 && te < ts1 |
|
157 | // 8th case ts0 < ts < te0 && te < ts1 | |
156 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; |
|
158 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; | |
157 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; |
|
159 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |
158 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
160 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
159 |
|
161 | |||
160 |
|
162 | |||
161 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
163 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
162 |
|
164 | |||
163 | QCOMPARE(notInCach.size(), 1); |
|
165 | QCOMPARE(notInCach.size(), 1); | |
164 | notInCacheSqp = notInCach.first(); |
|
166 | notInCacheSqp = notInCach.first(); | |
165 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(te0)); |
|
167 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(te0)); | |
166 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(te)); |
|
168 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(te)); | |
167 |
|
169 | |||
168 | // 9th case ts0 < ts < te0 && ts1 < te < te1 |
|
170 | // 9th case ts0 < ts < te0 && ts1 < te < te1 | |
169 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; |
|
171 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; | |
170 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 7, 0, 0}}; |
|
172 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 7, 0, 0}}; | |
171 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
173 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
172 |
|
174 | |||
173 |
|
175 | |||
174 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
176 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
175 |
|
177 | |||
176 | QCOMPARE(notInCach.size(), 1); |
|
178 | QCOMPARE(notInCach.size(), 1); | |
177 | notInCacheSqp = notInCach.first(); |
|
179 | notInCacheSqp = notInCach.first(); | |
178 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(te0)); |
|
180 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(te0)); | |
179 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(ts1)); |
|
181 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(ts1)); | |
180 |
|
182 | |||
181 | // 10th case te1 < ts < te < ts2 |
|
183 | // 10th case te1 < ts < te < ts2 | |
182 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 9, 0, 0}}; |
|
184 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 9, 0, 0}}; | |
183 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 10, 0, 0}}; |
|
185 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 10, 0, 0}}; | |
184 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
186 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
185 |
|
187 | |||
186 |
|
188 | |||
187 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
189 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
188 |
|
190 | |||
189 | QCOMPARE(notInCach.size(), 1); |
|
191 | QCOMPARE(notInCach.size(), 1); | |
190 | notInCacheSqp = notInCach.first(); |
|
192 | notInCacheSqp = notInCach.first(); | |
191 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(ts)); |
|
193 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(ts)); | |
192 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(te)); |
|
194 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(te)); | |
193 |
|
195 | |||
194 | // 11th case te0 < ts < ts1 && te3 < te |
|
196 | // 11th case te0 < ts < ts1 && te3 < te | |
195 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; |
|
197 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |
196 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 47, 0, 0}}; |
|
198 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 47, 0, 0}}; | |
197 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
199 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
198 |
|
200 | |||
199 |
|
201 | |||
200 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
202 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
201 |
|
203 | |||
202 | QCOMPARE(notInCach.size(), 3); |
|
204 | QCOMPARE(notInCach.size(), 3); | |
203 | notInCacheSqp = notInCach.first(); |
|
205 | notInCacheSqp = notInCach.first(); | |
204 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(ts)); |
|
206 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(ts)); | |
205 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(ts1)); |
|
207 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(ts1)); | |
206 |
|
208 | |||
207 | notInCacheSqp = notInCach.at(1); |
|
209 | notInCacheSqp = notInCach.at(1); | |
208 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(te1)); |
|
210 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(te1)); | |
209 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(ts2)); |
|
211 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(ts2)); | |
210 |
|
212 | |||
211 | notInCacheSqp = notInCach.at(2); |
|
213 | notInCacheSqp = notInCach.at(2); | |
212 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(te2)); |
|
214 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(te2)); | |
213 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(te)); |
|
215 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(te)); | |
214 |
|
216 | |||
215 | // 12th case te0 < ts < ts1 && te3 < te |
|
217 | // 12th case te0 < ts < ts1 && te3 < te | |
216 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; |
|
218 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |
217 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 10, 0, 0}}; |
|
219 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 10, 0, 0}}; | |
218 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
220 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
219 |
|
221 | |||
220 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
222 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
221 |
|
223 | |||
222 | QCOMPARE(notInCach.size(), 2); |
|
224 | QCOMPARE(notInCach.size(), 2); | |
223 | notInCacheSqp = notInCach.first(); |
|
225 | notInCacheSqp = notInCach.first(); | |
224 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(ts)); |
|
226 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(ts)); | |
225 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(ts1)); |
|
227 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(ts1)); | |
226 |
|
228 | |||
227 | notInCacheSqp = notInCach.at(1); |
|
229 | notInCacheSqp = notInCach.at(1); | |
228 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(te1)); |
|
230 | QCOMPARE(notInCacheSqp.m_TStart, DateUtils::secondsSinceEpoch(te1)); | |
229 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(te)); |
|
231 | QCOMPARE(notInCacheSqp.m_TEnd, DateUtils::secondsSinceEpoch(te)); | |
230 |
|
232 | |||
231 |
|
233 | |||
232 | // 12th case ts0 < ts < te0 |
|
234 | // 12th case ts0 < ts < te0 | |
233 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 10, 0}}; |
|
235 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 10, 0}}; | |
234 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 50, 0}}; |
|
236 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 50, 0}}; | |
235 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; |
|
237 | sqp = DateTimeRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |
236 |
|
238 | |||
237 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
239 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
238 | QCOMPARE(notInCach.size(), 0); |
|
240 | QCOMPARE(notInCach.size(), 0); | |
239 | } |
|
241 | } | |
240 |
|
242 | |||
241 |
|
243 | |||
242 | void TestVariableCacheController::testAddDateTime() |
|
244 | void TestVariableCacheController::testAddDateTime() | |
243 | { |
|
245 | { | |
244 | VariableCacheController variableCacheController{}; |
|
246 | VariableCacheController variableCacheController{}; | |
245 |
|
247 | |||
246 | auto ts0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}}; |
|
248 | auto ts0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}}; | |
247 | auto te0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; |
|
249 | auto te0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; | |
248 | auto sqp0 = DateTimeRange{DateUtils::secondsSinceEpoch(ts0), DateUtils::secondsSinceEpoch(te0)}; |
|
250 | auto sqp0 = DateTimeRange{DateUtils::secondsSinceEpoch(ts0), DateUtils::secondsSinceEpoch(te0)}; | |
249 |
|
251 | |||
250 | auto ts1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 6, 0, 0}}; |
|
252 | auto ts1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 6, 0, 0}}; | |
251 | auto te1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 8, 0, 0}}; |
|
253 | auto te1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 8, 0, 0}}; | |
252 | auto sqp1 = DateTimeRange{DateUtils::secondsSinceEpoch(ts1), DateUtils::secondsSinceEpoch(te1)}; |
|
254 | auto sqp1 = DateTimeRange{DateUtils::secondsSinceEpoch(ts1), DateUtils::secondsSinceEpoch(te1)}; | |
253 |
|
255 | |||
254 | auto ts2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 18, 0, 0}}; |
|
256 | auto ts2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 18, 0, 0}}; | |
255 | auto te2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 20, 0, 0}}; |
|
257 | auto te2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 20, 0, 0}}; | |
256 | auto sqp2 = DateTimeRange{DateUtils::secondsSinceEpoch(ts2), DateUtils::secondsSinceEpoch(te2)}; |
|
258 | auto sqp2 = DateTimeRange{DateUtils::secondsSinceEpoch(ts2), DateUtils::secondsSinceEpoch(te2)}; | |
257 |
|
259 | |||
258 | auto ts01 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; |
|
260 | auto ts01 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; | |
259 | auto te01 = QDateTime{QDate{2017, 01, 01}, QTime{2, 6, 0, 0}}; |
|
261 | auto te01 = QDateTime{QDate{2017, 01, 01}, QTime{2, 6, 0, 0}}; | |
260 | auto sqp01 = DateTimeRange{DateUtils::secondsSinceEpoch(ts01), DateUtils::secondsSinceEpoch(te01)}; |
|
262 | auto sqp01 = DateTimeRange{DateUtils::secondsSinceEpoch(ts01), DateUtils::secondsSinceEpoch(te01)}; | |
261 |
|
263 | |||
262 | auto ts3 = QDateTime{QDate{2017, 01, 01}, QTime{2, 14, 0, 0}}; |
|
264 | auto ts3 = QDateTime{QDate{2017, 01, 01}, QTime{2, 14, 0, 0}}; | |
263 | auto te3 = QDateTime{QDate{2017, 01, 01}, QTime{2, 16, 0, 0}}; |
|
265 | auto te3 = QDateTime{QDate{2017, 01, 01}, QTime{2, 16, 0, 0}}; | |
264 | auto sqp3 = DateTimeRange{DateUtils::secondsSinceEpoch(ts3), DateUtils::secondsSinceEpoch(te3)}; |
|
266 | auto sqp3 = DateTimeRange{DateUtils::secondsSinceEpoch(ts3), DateUtils::secondsSinceEpoch(te3)}; | |
265 |
|
267 | |||
266 | auto ts03 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; |
|
268 | auto ts03 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; | |
267 | auto te03 = QDateTime{QDate{2017, 01, 01}, QTime{2, 22, 0, 0}}; |
|
269 | auto te03 = QDateTime{QDate{2017, 01, 01}, QTime{2, 22, 0, 0}}; | |
268 | auto sqp03 = DateTimeRange{DateUtils::secondsSinceEpoch(ts03), DateUtils::secondsSinceEpoch(te03)}; |
|
270 | auto sqp03 = DateTimeRange{DateUtils::secondsSinceEpoch(ts03), DateUtils::secondsSinceEpoch(te03)}; | |
269 |
|
271 | |||
270 |
|
272 | |||
271 | auto var0 = std::make_shared<Variable>(""); |
|
273 | auto var0 = std::make_shared<Variable>(""); | |
272 | var0->setRange(sqp0); |
|
274 | var0->setRange(sqp0); | |
273 |
|
275 | |||
274 |
|
276 | |||
275 | // First case: add the first interval to the variable :sqp0 |
|
277 | // First case: add the first interval to the variable :sqp0 | |
276 | variableCacheController.addDateTime(var0, sqp0); |
|
278 | variableCacheController.addDateTime(var0, sqp0); | |
277 | auto dateCacheList = variableCacheController.dateCacheList(var0); |
|
279 | auto dateCacheList = variableCacheController.dateCacheList(var0); | |
278 | QCOMPARE(dateCacheList.count(), 1); |
|
280 | QCOMPARE(dateCacheList.count(), 1); | |
279 | auto dateCache = dateCacheList.at(0); |
|
281 | auto dateCache = dateCacheList.at(0); | |
280 | QCOMPARE(dateCache.m_TStart, DateUtils::secondsSinceEpoch(ts0)); |
|
282 | QCOMPARE(dateCache.m_TStart, DateUtils::secondsSinceEpoch(ts0)); | |
281 | QCOMPARE(dateCache.m_TEnd, DateUtils::secondsSinceEpoch(te0)); |
|
283 | QCOMPARE(dateCache.m_TEnd, DateUtils::secondsSinceEpoch(te0)); | |
282 |
|
284 | |||
283 | // 2nd case: add a second interval : sqp1 > sqp0 |
|
285 | // 2nd case: add a second interval : sqp1 > sqp0 | |
284 | variableCacheController.addDateTime(var0, sqp1); |
|
286 | variableCacheController.addDateTime(var0, sqp1); | |
285 | dateCacheList = variableCacheController.dateCacheList(var0); |
|
287 | dateCacheList = variableCacheController.dateCacheList(var0); | |
286 | QCOMPARE(dateCacheList.count(), 2); |
|
288 | QCOMPARE(dateCacheList.count(), 2); | |
287 | dateCache = dateCacheList.at(0); |
|
289 | dateCache = dateCacheList.at(0); | |
288 | QCOMPARE(dateCache.m_TStart, DateUtils::secondsSinceEpoch(ts0)); |
|
290 | QCOMPARE(dateCache.m_TStart, DateUtils::secondsSinceEpoch(ts0)); | |
289 | QCOMPARE(dateCache.m_TEnd, DateUtils::secondsSinceEpoch(te0)); |
|
291 | QCOMPARE(dateCache.m_TEnd, DateUtils::secondsSinceEpoch(te0)); | |
290 |
|
292 | |||
291 | dateCache = dateCacheList.at(1); |
|
293 | dateCache = dateCacheList.at(1); | |
292 | QCOMPARE(dateCache.m_TStart, DateUtils::secondsSinceEpoch(ts1)); |
|
294 | QCOMPARE(dateCache.m_TStart, DateUtils::secondsSinceEpoch(ts1)); | |
293 | QCOMPARE(dateCache.m_TEnd, DateUtils::secondsSinceEpoch(te1)); |
|
295 | QCOMPARE(dateCache.m_TEnd, DateUtils::secondsSinceEpoch(te1)); | |
294 |
|
296 | |||
295 | // 3th case: merge sqp0 & sqp1 with sqp01 |
|
297 | // 3th case: merge sqp0 & sqp1 with sqp01 | |
296 | variableCacheController.addDateTime(var0, sqp01); |
|
298 | variableCacheController.addDateTime(var0, sqp01); | |
297 | dateCacheList = variableCacheController.dateCacheList(var0); |
|
299 | dateCacheList = variableCacheController.dateCacheList(var0); | |
298 | QCOMPARE(dateCacheList.count(), 1); |
|
300 | QCOMPARE(dateCacheList.count(), 1); | |
299 | dateCache = dateCacheList.at(0); |
|
301 | dateCache = dateCacheList.at(0); | |
300 | QCOMPARE(dateCache.m_TStart, DateUtils::secondsSinceEpoch(ts0)); |
|
302 | QCOMPARE(dateCache.m_TStart, DateUtils::secondsSinceEpoch(ts0)); | |
301 | QCOMPARE(dateCache.m_TEnd, DateUtils::secondsSinceEpoch(te1)); |
|
303 | QCOMPARE(dateCache.m_TEnd, DateUtils::secondsSinceEpoch(te1)); | |
302 |
|
304 | |||
303 |
|
305 | |||
304 | // 4th case: add a second interval : sqp1 > sqp0 |
|
306 | // 4th case: add a second interval : sqp1 > sqp0 | |
305 | variableCacheController.addDateTime(var0, sqp2); |
|
307 | variableCacheController.addDateTime(var0, sqp2); | |
306 | variableCacheController.addDateTime(var0, sqp3); |
|
308 | variableCacheController.addDateTime(var0, sqp3); | |
307 | dateCacheList = variableCacheController.dateCacheList(var0); |
|
309 | dateCacheList = variableCacheController.dateCacheList(var0); | |
308 | QCOMPARE(dateCacheList.count(), 3); |
|
310 | QCOMPARE(dateCacheList.count(), 3); | |
309 | dateCache = dateCacheList.at(0); |
|
311 | dateCache = dateCacheList.at(0); | |
310 | QCOMPARE(dateCache.m_TStart, DateUtils::secondsSinceEpoch(ts0)); |
|
312 | QCOMPARE(dateCache.m_TStart, DateUtils::secondsSinceEpoch(ts0)); | |
311 | QCOMPARE(dateCache.m_TEnd, DateUtils::secondsSinceEpoch(te1)); |
|
313 | QCOMPARE(dateCache.m_TEnd, DateUtils::secondsSinceEpoch(te1)); | |
312 |
|
314 | |||
313 | dateCache = dateCacheList.at(1); |
|
315 | dateCache = dateCacheList.at(1); | |
314 | QCOMPARE(dateCache.m_TStart, DateUtils::secondsSinceEpoch(ts3)); |
|
316 | QCOMPARE(dateCache.m_TStart, DateUtils::secondsSinceEpoch(ts3)); | |
315 | QCOMPARE(dateCache.m_TEnd, DateUtils::secondsSinceEpoch(te3)); |
|
317 | QCOMPARE(dateCache.m_TEnd, DateUtils::secondsSinceEpoch(te3)); | |
316 |
|
318 | |||
317 | dateCache = dateCacheList.at(2); |
|
319 | dateCache = dateCacheList.at(2); | |
318 | QCOMPARE(dateCache.m_TStart, DateUtils::secondsSinceEpoch(ts2)); |
|
320 | QCOMPARE(dateCache.m_TStart, DateUtils::secondsSinceEpoch(ts2)); | |
319 | QCOMPARE(dateCache.m_TEnd, DateUtils::secondsSinceEpoch(te2)); |
|
321 | QCOMPARE(dateCache.m_TEnd, DateUtils::secondsSinceEpoch(te2)); | |
320 |
|
322 | |||
321 |
|
323 | |||
322 | // 5th case: merge all interval |
|
324 | // 5th case: merge all interval | |
323 | variableCacheController.addDateTime(var0, sqp03); |
|
325 | variableCacheController.addDateTime(var0, sqp03); | |
324 | dateCacheList = variableCacheController.dateCacheList(var0); |
|
326 | dateCacheList = variableCacheController.dateCacheList(var0); | |
325 | QCOMPARE(dateCacheList.count(), 1); |
|
327 | QCOMPARE(dateCacheList.count(), 1); | |
326 | dateCache = dateCacheList.at(0); |
|
328 | dateCache = dateCacheList.at(0); | |
327 | QCOMPARE(dateCache.m_TStart, DateUtils::secondsSinceEpoch(ts0)); |
|
329 | QCOMPARE(dateCache.m_TStart, DateUtils::secondsSinceEpoch(ts0)); | |
328 | QCOMPARE(dateCache.m_TEnd, DateUtils::secondsSinceEpoch(te03)); |
|
330 | QCOMPARE(dateCache.m_TEnd, DateUtils::secondsSinceEpoch(te03)); | |
329 | } |
|
331 | } | |
330 |
|
332 | |||
331 |
|
333 | |||
332 | QTEST_MAIN(TestVariableCacheController) |
|
334 | QTEST_MAIN(TestVariableCacheController) | |
333 | #include "TestVariableCacheController.moc" |
|
335 | #include "TestVariableCacheController.moc" |
@@ -1,74 +1,76 | |||||
1 | #include <QObject> |
|
1 | #include <QObject> | |
2 | #include <QtTest> |
|
2 | #include <QtTest> | |
3 |
|
3 | |||
4 | #include <Data/IDataProvider.h> |
|
4 | #include <Data/IDataProvider.h> | |
5 | #include <Time/TimeController.h> |
|
5 | #include <Time/TimeController.h> | |
6 | #include <Variable/Variable.h> |
|
6 | #include <Variable/Variable.h> | |
7 | #include <Variable/VariableController.h> |
|
7 | #include <Variable/VariableController.h> | |
8 |
|
8 | |||
9 | #include <memory> |
|
9 | #include <memory> | |
10 |
|
10 | |||
11 | namespace { |
|
11 | namespace { | |
12 |
|
12 | |||
13 | /// Provider used for the tests |
|
13 | /// Provider used for the tests | |
14 | class TestProvider : public IDataProvider { |
|
14 | class TestProvider : public IDataProvider { | |
15 | std::shared_ptr<IDataProvider> clone() const { return std::make_shared<TestProvider>(); } |
|
15 | std::shared_ptr<IDataProvider> clone() const { return std::make_shared<TestProvider>(); } | |
16 |
|
16 | |||
17 | void requestDataLoading(QUuid acqIdentifier, const DataProviderParameters ¶meters) override |
|
17 | void requestDataLoading(QUuid acqIdentifier, const DataProviderParameters ¶meters) override | |
18 | { |
|
18 | { | |
19 | // Does nothing |
|
19 | // Does nothing | |
20 | } |
|
20 | } | |
21 |
|
21 | |||
22 | void requestDataAborting(QUuid acqIdentifier) override |
|
22 | void requestDataAborting(QUuid acqIdentifier) override | |
23 | { |
|
23 | { | |
24 | // Does nothing |
|
24 | // Does nothing | |
25 | } |
|
25 | } | |
26 | }; |
|
26 | }; | |
27 |
|
27 | |||
28 | /// Generates a time controller for the tests |
|
28 | /// Generates a time controller for the tests | |
29 | std::unique_ptr<TimeController> defaultTimeController() |
|
29 | std::unique_ptr<TimeController> defaultTimeController() | |
30 | { |
|
30 | { | |
31 | auto timeController = std::make_unique<TimeController>(); |
|
31 | auto timeController = std::make_unique<TimeController>(); | |
32 |
|
32 | |||
33 | QDateTime start{QDate{2017, 01, 01}, QTime{0, 0, 0, 0}}; |
|
33 | QDateTime start{QDate{2017, 01, 01}, QTime{0, 0, 0, 0}}; | |
34 | QDateTime end{QDate{2017, 01, 02}, QTime{0, 0, 0, 0}}; |
|
34 | QDateTime end{QDate{2017, 01, 02}, QTime{0, 0, 0, 0}}; | |
35 | timeController->setDateTimeRange( |
|
35 | timeController->setDateTimeRange( | |
36 | DateTimeRange{DateUtils::secondsSinceEpoch(start), DateUtils::secondsSinceEpoch(end)}); |
|
36 | DateTimeRange{DateUtils::secondsSinceEpoch(start), DateUtils::secondsSinceEpoch(end)}); | |
37 |
|
37 | |||
38 | return timeController; |
|
38 | return timeController; | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | } // namespace |
|
41 | } // namespace | |
42 |
|
42 | |||
43 | class TestVariableController : public QObject { |
|
43 | class TestVariableController : public QObject { | |
44 | Q_OBJECT |
|
44 | Q_OBJECT | |
45 |
|
45 | |||
46 | private slots: |
|
46 | private slots: | |
|
47 | void initTestCase() { QSKIP("Skip it"); } | |||
|
48 | ||||
47 | /// Test removes variable from controller |
|
49 | /// Test removes variable from controller | |
48 | void testDeleteVariable(); |
|
50 | void testDeleteVariable(); | |
49 | }; |
|
51 | }; | |
50 |
|
52 | |||
51 | void TestVariableController::testDeleteVariable() |
|
53 | void TestVariableController::testDeleteVariable() | |
52 | { |
|
54 | { | |
53 | // Creates variable controller |
|
55 | // Creates variable controller | |
54 | auto timeController = defaultTimeController(); |
|
56 | auto timeController = defaultTimeController(); | |
55 | VariableController variableController{}; |
|
57 | VariableController variableController{}; | |
56 | //variableController.setTimeController(timeController.get()); |
|
58 | //variableController.setTimeController(timeController.get()); | |
57 |
|
59 | |||
58 | // Creates a variable from the controller |
|
60 | // Creates a variable from the controller | |
59 | auto variable |
|
61 | auto variable | |
60 | = variableController.createVariable("variable", {}, std::make_shared<TestProvider>(), timeController->dateTime()); |
|
62 | = variableController.createVariable("variable", {}, std::make_shared<TestProvider>(), timeController->dateTime()); | |
61 |
|
63 | |||
62 | qDebug() << QString::number(variable.use_count()); |
|
64 | qDebug() << QString::number(variable.use_count()); | |
63 |
|
65 | |||
64 | // Removes the variable from the controller |
|
66 | // Removes the variable from the controller | |
65 | variableController.deleteVariable(variable); |
|
67 | variableController.deleteVariable(variable); | |
66 |
|
68 | |||
67 | // Verifies that the variable has been deleted: this implies that the number of shared_ptr |
|
69 | // Verifies that the variable has been deleted: this implies that the number of shared_ptr | |
68 | // objects referring to the variable is 1 (the reference of this scope). Otherwise, the deletion |
|
70 | // objects referring to the variable is 1 (the reference of this scope). Otherwise, the deletion | |
69 | // is considered invalid since the variable is still referenced in the controller |
|
71 | // is considered invalid since the variable is still referenced in the controller | |
70 | QVERIFY(variable.use_count() == 1); |
|
72 | QVERIFY(variable.use_count() == 1); | |
71 | } |
|
73 | } | |
72 |
|
74 | |||
73 | QTEST_MAIN(TestVariableController) |
|
75 | QTEST_MAIN(TestVariableController) | |
74 | #include "TestVariableController.moc" |
|
76 | #include "TestVariableController.moc" |
General Comments 0
You need to be logged in to leave comments.
Login now