TestVariable.cpp
174 lines
| 7.2 KiB
| text/x-c
|
CppLexer
r552 | #include <Variable/Variable.h> | |||
#include <QObject> | ||||
#include <QtTest> | ||||
#include <memory> | ||||
class TestVariable : public QObject { | ||||
Q_OBJECT | ||||
private slots: | ||||
void testNotInCacheRangeList(); | ||||
void testInCacheRangeList(); | ||||
}; | ||||
void TestVariable::testNotInCacheRangeList() | ||||
{ | ||||
auto varRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; | ||||
auto varRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 40, 0}}; | ||||
r556 | auto sqpR = SqpRange{DateUtils::secondsSinceEpoch(varRS), DateUtils::secondsSinceEpoch(varRE)}; | |||
r552 | ||||
auto varCRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}}; | ||||
auto varCRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; | ||||
r556 | auto sqpCR | |||
= SqpRange{DateUtils::secondsSinceEpoch(varCRS), DateUtils::secondsSinceEpoch(varCRE)}; | ||||
r552 | ||||
Variable var{"Var test", sqpR}; | ||||
var.setCacheRange(sqpCR); | ||||
// 1: [ts,te] < varTS | ||||
auto ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | ||||
auto te = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}}; | ||||
r556 | auto sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |||
r552 | ||||
auto notInCach = var.provideNotInCacheRangeList(sqp); | ||||
QCOMPARE(notInCach.size(), 1); | ||||
auto notInCachRange = notInCach.first(); | ||||
r556 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts)); | |||
QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te)); | ||||
r552 | ||||
// 2: ts < varTS < te < varTE | ||||
ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | ||||
te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; | ||||
r556 | sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |||
r552 | notInCach = var.provideNotInCacheRangeList(sqp); | |||
QCOMPARE(notInCach.size(), 1); | ||||
notInCachRange = notInCach.first(); | ||||
r556 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts)); | |||
QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(varCRS)); | ||||
r552 | ||||
// 3: varTS < ts < te < varTE | ||||
ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; | ||||
te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; | ||||
r556 | sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |||
r552 | notInCach = var.provideNotInCacheRangeList(sqp); | |||
QCOMPARE(notInCach.size(), 0); | ||||
// 4: varTS < ts < varTE < te | ||||
ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; | ||||
te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | ||||
r556 | sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |||
r552 | notInCach = var.provideNotInCacheRangeList(sqp); | |||
QCOMPARE(notInCach.size(), 1); | ||||
notInCachRange = notInCach.first(); | ||||
r556 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(varCRE)); | |||
QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te)); | ||||
r552 | ||||
// 5: varTS < varTE < ts < te | ||||
ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 20, 0}}; | ||||
te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | ||||
r556 | sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |||
r552 | notInCach = var.provideNotInCacheRangeList(sqp); | |||
QCOMPARE(notInCach.size(), 1); | ||||
notInCachRange = notInCach.first(); | ||||
r556 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts)); | |||
QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te)); | ||||
r552 | ||||
// 6: ts <varTS < varTE < te | ||||
ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}}; | ||||
te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | ||||
r556 | sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |||
r552 | notInCach = var.provideNotInCacheRangeList(sqp); | |||
QCOMPARE(notInCach.size(), 2); | ||||
notInCachRange = notInCach.first(); | ||||
r556 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts)); | |||
QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(varCRS)); | ||||
r552 | notInCachRange = notInCach[1]; | |||
r556 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(varCRE)); | |||
QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te)); | ||||
r552 | } | |||
void TestVariable::testInCacheRangeList() | ||||
{ | ||||
auto varRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; | ||||
auto varRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 40, 0}}; | ||||
r556 | auto sqpR = SqpRange{DateUtils::secondsSinceEpoch(varRS), DateUtils::secondsSinceEpoch(varRE)}; | |||
r552 | ||||
auto varCRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}}; | ||||
auto varCRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; | ||||
r556 | auto sqpCR | |||
= SqpRange{DateUtils::secondsSinceEpoch(varCRS), DateUtils::secondsSinceEpoch(varCRE)}; | ||||
r552 | ||||
Variable var{"Var test", sqpR}; | ||||
var.setCacheRange(sqpCR); | ||||
// 1: [ts,te] < varTS | ||||
auto ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | ||||
auto te = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}}; | ||||
r556 | auto sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |||
r552 | ||||
auto notInCach = var.provideInCacheRangeList(sqp); | ||||
QCOMPARE(notInCach.size(), 0); | ||||
// 2: ts < varTS < te < varTE | ||||
ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | ||||
te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; | ||||
r556 | sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |||
r552 | notInCach = var.provideInCacheRangeList(sqp); | |||
QCOMPARE(notInCach.size(), 1); | ||||
auto notInCachRange = notInCach.first(); | ||||
r556 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(varCRS)); | |||
QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te)); | ||||
r552 | ||||
// 3: varTS < ts < te < varTE | ||||
ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; | ||||
te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; | ||||
r556 | sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |||
r552 | notInCach = var.provideInCacheRangeList(sqp); | |||
QCOMPARE(notInCach.size(), 1); | ||||
notInCachRange = notInCach.first(); | ||||
r556 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts)); | |||
QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(te)); | ||||
r552 | ||||
// 4: varTS < ts < varTE < te | ||||
ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; | ||||
te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | ||||
r556 | sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |||
r552 | notInCach = var.provideInCacheRangeList(sqp); | |||
QCOMPARE(notInCach.size(), 1); | ||||
notInCachRange = notInCach.first(); | ||||
r556 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(ts)); | |||
QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(varCRE)); | ||||
r552 | ||||
// 5: varTS < varTE < ts < te | ||||
ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 20, 0}}; | ||||
te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | ||||
r556 | sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |||
r552 | notInCach = var.provideInCacheRangeList(sqp); | |||
QCOMPARE(notInCach.size(), 0); | ||||
// 6: ts <varTS < varTE < te | ||||
ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}}; | ||||
te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | ||||
r556 | sqp = SqpRange{DateUtils::secondsSinceEpoch(ts), DateUtils::secondsSinceEpoch(te)}; | |||
r552 | notInCach = var.provideInCacheRangeList(sqp); | |||
QCOMPARE(notInCach.size(), 1); | ||||
notInCachRange = notInCach.first(); | ||||
r556 | QCOMPARE(notInCachRange.m_TStart, DateUtils::secondsSinceEpoch(varCRS)); | |||
QCOMPARE(notInCachRange.m_TEnd, DateUtils::secondsSinceEpoch(varCRE)); | ||||
r552 | } | |||
QTEST_MAIN(TestVariable) | ||||
#include "TestVariable.moc" | ||||