Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Telemetry
KUserFeedback
Commits
7cfd98fe
Commit
7cfd98fe
authored
Dec 11, 2016
by
Volker Krause
Browse files
Add unit test for the time aggregation model
parent
5a14b0f4
Changes
11
Hide whitespace changes
Inline
Side-by-side
analyzer/CMakeLists.txt
View file @
7cfd98fe
...
...
@@ -15,6 +15,7 @@ set(analyzer_lib_srcs
model/productmodel.cpp
model/schemamodel.cpp
model/surveymodel.cpp
model/timeaggregationmodel.cpp
schemaentrytemplates/schemaentrytemplates.qrc
)
...
...
@@ -32,7 +33,6 @@ set(analyzer_srcs
mainwindow.cpp
numericaggregationmodel.cpp
ratiosetaggregationmodel.cpp
timeaggregationmodel.cpp
analytics/analyticsview.cpp
...
...
analyzer/aggregateddatamodel.cpp
View file @
7cfd98fe
...
...
@@ -16,7 +16,7 @@
*/
#include "aggregateddatamodel.h"
#include
"
timeaggregationmodel.h
"
#include
<model/
timeaggregationmodel.h
>
#include <QDebug>
...
...
analyzer/analytics/analyticsview.cpp
View file @
7cfd98fe
...
...
@@ -23,9 +23,9 @@
#include "chart.h"
#include "numericaggregationmodel.h"
#include "ratiosetaggregationmodel.h"
#include "timeaggregationmodel.h"
#include <model/datamodel.h>
#include <model/timeaggregationmodel.h>
#include <rest/restapi.h>
#include <core/sample.h>
...
...
analyzer/categoryaggregationmodel.cpp
View file @
7cfd98fe
...
...
@@ -16,8 +16,8 @@
*/
#include "categoryaggregationmodel.h"
#include <model/timeaggregationmodel.h>
#include <core/sample.h>
#include "timeaggregationmodel.h"
#include <QDebug>
#include <QSet>
...
...
analyzer/chart.cpp
View file @
7cfd98fe
...
...
@@ -18,7 +18,7 @@
#include "chart.h"
#include "categoryaggregationmodel.h"
#include "numericaggregationmodel.h"
#include
"
timeaggregationmodel.h
"
#include
<model/
timeaggregationmodel.h
>
#include <QtCharts/QAreaSeries>
#include <QtCharts/QBarCategoryAxis>
...
...
analyzer/timeaggregationmodel.cpp
→
analyzer/
model/
timeaggregationmodel.cpp
View file @
7cfd98fe
File moved
analyzer/timeaggregationmodel.h
→
analyzer/
model/
timeaggregationmodel.h
View file @
7cfd98fe
...
...
@@ -55,8 +55,8 @@ public:
AggregationMode
aggregationMode
()
const
;
void
setAggregationMode
(
AggregationMode
mode
);
int
rowCount
(
const
QModelIndex
&
parent
)
const
override
;
int
columnCount
(
const
QModelIndex
&
parent
)
const
override
;
int
rowCount
(
const
QModelIndex
&
parent
=
QModelIndex
()
)
const
override
;
int
columnCount
(
const
QModelIndex
&
parent
=
QModelIndex
()
)
const
override
;
QVariant
data
(
const
QModelIndex
&
index
,
int
role
)
const
override
;
QVariant
headerData
(
int
section
,
Qt
::
Orientation
orientation
,
int
role
)
const
override
;
...
...
analyzer/numericaggregationmodel.cpp
View file @
7cfd98fe
...
...
@@ -16,8 +16,8 @@
*/
#include "numericaggregationmodel.h"
#include <model/timeaggregationmodel.h>
#include <core/sample.h>
#include "timeaggregationmodel.h"
using
namespace
UserFeedback
::
Analyzer
;
...
...
analyzer/ratiosetaggregationmodel.cpp
View file @
7cfd98fe
...
...
@@ -16,9 +16,9 @@
*/
#include "ratiosetaggregationmodel.h"
#include <model/timeaggregationmodel.h>
#include <core/ratioset.h>
#include <core/sample.h>
#include "timeaggregationmodel.h"
#include <QSet>
...
...
tests/auto/CMakeLists.txt
View file @
7cfd98fe
...
...
@@ -37,6 +37,10 @@ add_executable(datamodeltest datamodeltest.cpp)
target_link_libraries
(
datamodeltest UserFeedbackTestUtils Qt5::Test
)
add_test
(
NAME datamodeltest COMMAND datamodeltest
)
add_executable
(
timeaggregationmodeltest timeaggregationmodeltest.cpp
)
target_link_libraries
(
timeaggregationmodeltest UserFeedbackTestUtils Qt5::Test
)
add_test
(
NAME timeaggregationmodeltest COMMAND timeaggregationmodeltest
)
set
(
php_test_srcs
utilstest.php
schemaentrytest.php
...
...
tests/auto/timeaggregationmodeltest.cpp
0 → 100644
View file @
7cfd98fe
/*
Copyright (C) 2016 Volker Krause <vkrause@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <analyzer/core/sample.h>
#include <analyzer/core/schemaentrytemplates.h>
#include <analyzer/model/datamodel.h>
#include <analyzer/model/timeaggregationmodel.h>
#include <3rdparty/qt/modeltest.h>
#include <QDebug>
#include <QtTest/qtest.h>
#include <QObject>
#include <QStandardPaths>
using
namespace
UserFeedback
::
Analyzer
;
class
TimeAggregationModelTest
:
public
QObject
{
Q_OBJECT
private
slots
:
void
initTestCase
()
{
Q_INIT_RESOURCE
(
schemaentrytemplates
);
QStandardPaths
::
setTestModeEnabled
(
true
);
}
void
testEmptyModel
()
{
TimeAggregationModel
model
;
ModelTest
modelTest
(
&
model
);
DataModel
srcModel
;
model
.
setSourceModel
(
&
srcModel
);
srcModel
.
setProduct
({});
QCOMPARE
(
model
.
rowCount
(),
0
);
QCOMPARE
(
model
.
columnCount
(),
2
);
Product
p
;
p
.
setSchema
(
SchemaEntryTemplates
::
availableTemplates
());
p
.
setName
(
QStringLiteral
(
"org.kde.UserFeedback.UnitTest"
));
srcModel
.
setProduct
(
p
);
QCOMPARE
(
model
.
columnCount
(),
2
);
QCOMPARE
(
model
.
rowCount
(),
0
);
}
void
testModelContent
()
{
TimeAggregationModel
model
;
ModelTest
modelTest
(
&
model
);
DataModel
srcModel
;
model
.
setSourceModel
(
&
srcModel
);
Product
p
;
p
.
setSchema
(
SchemaEntryTemplates
::
availableTemplates
());
p
.
setName
(
QStringLiteral
(
"org.kde.UserFeedback.UnitTest"
));
srcModel
.
setProduct
(
p
);
auto
samples
=
Sample
::
fromJson
(
R"([{
"id": 42,
"timestamp": "2016-11-27 16:09:06",
"platform": { "os": "linux", "version": "suse" },
"applicationVersion": { "value": "1.9.84" },
"screens": [ { "width": 1920, "height": 1200 }, { "width": 640, "height": 480 } ],
"newPropertyRatio": { "value1": { "property": 0.55 }, "value2": { "property": 0.45 } }
}, {
"id": 43,
"timestamp": "2016-12-09 12:00:00",
"platform": { "os": "linux", "version": "suse" },
"applicationVersion": { "value": "1.9.84" },
"screens": [ { "width": 1920, "height": 1200 } ],
"newPropertyRatio": { "value1": { "property": 0.1 }, "value2": { "property": 0.9 } }
}])"
,
p
);
QCOMPARE
(
samples
.
size
(),
2
);
srcModel
.
setSamples
(
samples
);
model
.
setAggregationMode
(
TimeAggregationModel
::
AggregateYear
);
QCOMPARE
(
model
.
rowCount
(),
1
);
QCOMPARE
(
model
.
index
(
0
,
0
).
data
(
TimeAggregationModel
::
TimeDisplayRole
).
toString
(),
QLatin1String
(
"2016"
));
QCOMPARE
(
model
.
index
(
0
,
0
).
data
(
TimeAggregationModel
::
DateTimeRole
).
toDate
(),
QDate
(
2016
,
01
,
01
));
QCOMPARE
(
model
.
index
(
0
,
0
).
data
(
TimeAggregationModel
::
SamplesRole
).
value
<
QVector
<
Sample
>>
().
size
(),
2
);
QCOMPARE
(
model
.
index
(
0
,
1
).
data
().
toInt
(),
2
);
model
.
setAggregationMode
(
TimeAggregationModel
::
AggregateMonth
);
QCOMPARE
(
model
.
rowCount
(),
2
);
QCOMPARE
(
model
.
index
(
0
,
0
).
data
(
TimeAggregationModel
::
TimeDisplayRole
).
toString
(),
QLatin1String
(
"2016-11"
));
QCOMPARE
(
model
.
index
(
0
,
0
).
data
(
TimeAggregationModel
::
DateTimeRole
).
toDate
(),
QDate
(
2016
,
11
,
01
));
QCOMPARE
(
model
.
index
(
0
,
1
).
data
().
toInt
(),
1
);
QCOMPARE
(
model
.
index
(
1
,
0
).
data
(
TimeAggregationModel
::
TimeDisplayRole
).
toString
(),
QLatin1String
(
"2016-12"
));
QCOMPARE
(
model
.
index
(
1
,
1
).
data
().
toInt
(),
1
);
model
.
setAggregationMode
(
TimeAggregationModel
::
AggregateWeek
);
QCOMPARE
(
model
.
rowCount
(),
2
);
QCOMPARE
(
model
.
index
(
0
,
0
).
data
(
TimeAggregationModel
::
TimeDisplayRole
).
toString
(),
QLatin1String
(
"2016-w47"
));
QCOMPARE
(
model
.
index
(
0
,
0
).
data
(
TimeAggregationModel
::
DateTimeRole
).
toDate
(),
QDate
(
2016
,
11
,
21
));
QCOMPARE
(
model
.
index
(
0
,
1
).
data
().
toInt
(),
1
);
QCOMPARE
(
model
.
index
(
1
,
0
).
data
(
TimeAggregationModel
::
TimeDisplayRole
).
toString
(),
QLatin1String
(
"2016-w49"
));
QCOMPARE
(
model
.
index
(
1
,
1
).
data
().
toInt
(),
1
);
model
.
setAggregationMode
(
TimeAggregationModel
::
AggregateDay
);
QCOMPARE
(
model
.
rowCount
(),
2
);
QCOMPARE
(
model
.
index
(
0
,
0
).
data
(
TimeAggregationModel
::
TimeDisplayRole
).
toString
(),
QLatin1String
(
"2016-11-27"
));
QCOMPARE
(
model
.
index
(
0
,
0
).
data
(
TimeAggregationModel
::
DateTimeRole
).
toDate
(),
QDate
(
2016
,
11
,
27
));
QCOMPARE
(
model
.
index
(
0
,
1
).
data
().
toInt
(),
1
);
QCOMPARE
(
model
.
index
(
1
,
0
).
data
(
TimeAggregationModel
::
TimeDisplayRole
).
toString
(),
QLatin1String
(
"2016-12-09"
));
QCOMPARE
(
model
.
index
(
0
,
0
).
data
(
TimeAggregationModel
::
SamplesRole
).
value
<
QVector
<
Sample
>>
().
size
(),
1
);
QCOMPARE
(
model
.
index
(
1
,
1
).
data
().
toInt
(),
1
);
}
};
QTEST_MAIN
(
TimeAggregationModelTest
)
#include "timeaggregationmodeltest.moc"
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment