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
Plasma
libksysguard
Commits
bb1070aa
Commit
bb1070aa
authored
Mar 01, 2021
by
Arjen Hiemstra
Browse files
Fix SensorDataModel and SensorTreeModel tests
Now they use the right service and sensor names
parent
60a3457f
Changes
2
Hide whitespace changes
Inline
Side-by-side
autotests/sensordatamodeltest.cpp
View file @
bb1070aa
...
...
@@ -34,62 +34,65 @@ class SensorDataModelTest : public QObject
private
Q_SLOTS
:
void
initTestCase
()
{
QDBusInterface
interface
{
QStringLiteral
(
"org.kde.kstats"
),
QStringLiteral
(
"/"
)};
QDBusInterface
interface
{
QStringLiteral
(
"org.kde.ks
ystems
tats"
),
QStringLiteral
(
"/"
)};
if
(
!
interface
.
isValid
())
{
QSKIP
(
"KStats Deamon is not running"
);
QSKIP
(
"KS
ystemS
tats Deamon is not running"
);
}
}
void
testModel
()
{
auto
model
=
new
KSysGuard
::
SensorDataModel
();
auto
tester
=
new
QAbstractItemModelTester
(
model
);
KSysGuard
::
SensorDataModel
model
;
QAbstractItemModelTester
tester
{
&
model
};
Q_UNUSED
(
tester
)
QVERIFY
(
model
->
columnCount
()
==
0
);
QVERIFY
(
model
.
columnCount
()
==
0
);
model
->
setSensors
({
qs
(
"cpu/
system/TotalLoad
"
),
qs
(
"mem/physical/
allocat
ed"
),
qs
(
"network/all/
sentDataRate
"
),
qs
(
"
partitions
/all/used
space
"
)
model
.
setSensors
({
qs
(
"cpu/
all/usage
"
),
qs
(
"mem
ory
/physical/
us
ed"
),
qs
(
"network/all/
download
"
),
qs
(
"
disk
/all/used"
)
});
QT
est
::
qWait
(
500
);
// Allow the model to communicate with the daemon.
QT
RY_VERIFY
(
model
.
isReady
());
QCOMPARE
(
model
->
columnCount
(),
4
);
QCOMPARE
(
model
.
columnCount
(),
4
);
auto
id
=
KSysGuard
::
SensorDataModel
::
SensorId
;
auto
unit
=
KSysGuard
::
SensorDataModel
::
Unit
;
QCOMPARE
(
model
->
headerData
(
0
,
Qt
::
Horizontal
,
id
).
toString
(),
qs
(
"cpu/
system/TotalLoad
"
));
QCOMPARE
(
model
->
headerData
(
1
,
Qt
::
Horizontal
,
id
).
toString
(),
qs
(
"mem/physical/
allocat
ed"
));
QCOMPARE
(
model
->
headerData
(
2
,
Qt
::
Horizontal
,
id
).
toString
(),
qs
(
"network/all/
sentDataRate
"
));
QCOMPARE
(
model
->
headerData
(
3
,
Qt
::
Horizontal
,
id
).
toString
(),
qs
(
"
partitions
/all/used
space
"
));
QCOMPARE
(
model
.
headerData
(
0
,
Qt
::
Horizontal
,
id
).
toString
(),
qs
(
"cpu/
all/usage
"
));
QCOMPARE
(
model
.
headerData
(
1
,
Qt
::
Horizontal
,
id
).
toString
(),
qs
(
"mem
ory
/physical/
us
ed"
));
QCOMPARE
(
model
.
headerData
(
2
,
Qt
::
Horizontal
,
id
).
toString
(),
qs
(
"network/all/
download
"
));
QCOMPARE
(
model
.
headerData
(
3
,
Qt
::
Horizontal
,
id
).
toString
(),
qs
(
"
disk
/all/used"
));
// Verify that metadata is also loaded correctly. Not using names to sidestep translation issues.
QCOMPARE
(
model
->
headerData
(
0
,
Qt
::
Horizontal
,
unit
).
toInt
(),
KSysGuard
::
UnitPercent
);
QCOMPARE
(
model
->
headerData
(
1
,
Qt
::
Horizontal
,
unit
).
toInt
(),
KSysGuard
::
Unit
Kilo
Byte
);
QCOMPARE
(
model
->
headerData
(
2
,
Qt
::
Horizontal
,
unit
).
toInt
(),
KSysGuard
::
Unit
Kilo
ByteRate
);
QCOMPARE
(
model
->
headerData
(
3
,
Qt
::
Horizontal
,
unit
).
toInt
(),
KSysGuard
::
Unit
Kilo
Byte
);
model
->
setSensors
({
qs
(
"
partitions
/all/used
space
"
),
qs
(
"network/all/
sentDataRate
"
),
qs
(
"cpu/
system/TotalLoad
"
)
QCOMPARE
(
model
.
headerData
(
0
,
Qt
::
Horizontal
,
unit
).
value
<
KSysGuard
::
Unit
>
(),
KSysGuard
::
UnitPercent
);
QCOMPARE
(
model
.
headerData
(
1
,
Qt
::
Horizontal
,
unit
).
value
<
KSysGuard
::
Unit
>
(),
KSysGuard
::
UnitByte
);
QCOMPARE
(
model
.
headerData
(
2
,
Qt
::
Horizontal
,
unit
).
value
<
KSysGuard
::
Unit
>
(),
KSysGuard
::
UnitByteRate
);
QCOMPARE
(
model
.
headerData
(
3
,
Qt
::
Horizontal
,
unit
).
value
<
KSysGuard
::
Unit
>
(),
KSysGuard
::
UnitByte
);
model
.
setSensors
({
qs
(
"
disk
/all/used"
),
qs
(
"network/all/
download
"
),
qs
(
"cpu/
all/usage
"
)
});
Q
Test
::
qWait
(
500
);
// As above, give some time for communication.
Q
VERIFY
(
!
model
.
isReady
());
Q
COMPARE
(
model
->
columnCount
(),
3
);
Q
TRY_VERIFY
(
model
.
isReady
()
);
QCOMPARE
(
model
->
headerData
(
0
,
Qt
::
Horizontal
,
id
).
toString
(),
qs
(
"partitions/all/usedspace"
));
QCOMPARE
(
model
->
headerData
(
1
,
Qt
::
Horizontal
,
id
).
toString
(),
qs
(
"network/all/sentDataRate"
));
QCOMPARE
(
model
->
headerData
(
2
,
Qt
::
Horizontal
,
id
).
toString
(),
qs
(
"cpu/system/TotalLoad"
));
QCOMPARE
(
model
.
columnCount
(),
3
);
QCOMPARE
(
model
.
headerData
(
0
,
Qt
::
Horizontal
,
id
).
toString
(),
qs
(
"disk/all/used"
));
QCOMPARE
(
model
.
headerData
(
1
,
Qt
::
Horizontal
,
id
).
toString
(),
qs
(
"network/all/download"
));
QCOMPARE
(
model
.
headerData
(
2
,
Qt
::
Horizontal
,
id
).
toString
(),
qs
(
"cpu/all/usage"
));
// Verify that metadata is also loaded correctly. Not using names to sidestep translation issues.
QCOMPARE
(
model
->
headerData
(
0
,
Qt
::
Horizontal
,
unit
).
toInt
(),
KSysGuard
::
Unit
Kilo
Byte
);
QCOMPARE
(
model
->
headerData
(
1
,
Qt
::
Horizontal
,
unit
).
toInt
(),
KSysGuard
::
Unit
Kilo
ByteRate
);
QCOMPARE
(
model
->
headerData
(
2
,
Qt
::
Horizontal
,
unit
).
toInt
(),
KSysGuard
::
UnitPercent
);
QCOMPARE
(
model
.
headerData
(
0
,
Qt
::
Horizontal
,
unit
).
value
<
KSysGuard
::
Unit
>
(),
KSysGuard
::
UnitByte
);
QCOMPARE
(
model
.
headerData
(
1
,
Qt
::
Horizontal
,
unit
).
value
<
KSysGuard
::
Unit
>
(),
KSysGuard
::
UnitByteRate
);
QCOMPARE
(
model
.
headerData
(
2
,
Qt
::
Horizontal
,
unit
).
value
<
KSysGuard
::
Unit
>
(),
KSysGuard
::
UnitPercent
);
}
};
...
...
autotests/sensortreemodeltest.cpp
View file @
bb1070aa
...
...
@@ -31,22 +31,21 @@ class SensorTreeModelTest : public QObject
private
Q_SLOTS
:
void
initTestCase
()
{
QDBusInterface
interface
{
QStringLiteral
(
"org.kde.kstats"
),
QStringLiteral
(
"/"
)};
QDBusInterface
interface
{
QStringLiteral
(
"org.kde.ks
ystems
tats"
),
QStringLiteral
(
"/"
)};
if
(
!
interface
.
isValid
())
{
QSKIP
(
"KStats Deamon is not running"
);
QSKIP
(
"KS
ystemS
tats Deamon is not running"
);
}
}
void
testModel
()
{
auto
model
=
new
KSysGuard
::
SensorTreeModel
();
auto
tester
=
new
QAbstractItemModelTester
(
model
);
KSysGuard
::
SensorTreeModel
model
;
QAbstractItemModelTester
tester
(
&
model
);
Q_UNUSED
(
tester
)
QVERIFY
(
model
->
rowCount
()
==
0
);
QVERIFY
(
model
.
rowCount
()
==
0
);
QTest
::
qWait
(
500
);
QVERIFY
(
model
->
rowCount
()
>
0
);
QTRY_VERIFY
(
model
.
rowCount
()
>
0
);
}
};
...
...
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