Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[nemo-qml-plugin-contacts] Fix unit tests. Contributes to JB#52635
  • Loading branch information
chriadam committed Jan 12, 2021
1 parent 70d7da9 commit 697e40b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
7 changes: 7 additions & 0 deletions tests/run_test.sh
@@ -0,0 +1,7 @@
#!/bin/sh

export BASENAME=$1
export TESTCASE=$2
export DEVICEUSER=$(getent passwd $(grep '^UID_MIN' /etc/login.defs | tr -s ' ' | cut -d ' ' -f2) | sed 's/:.*//')
export LIBCONTACTS_TEST_MODE=1
/usr/sbin/run-blts-root /bin/su -g privileged -c "/opt/tests/$BASENAME/contacts/$TESTCASE" "$DEVICEUSER"
4 changes: 3 additions & 1 deletion tests/tests.pro
Expand Up @@ -9,6 +9,8 @@ SUBDIRS = \
tst_seasidefilteredmodel \
tst_seasidestringlistcompressor

OTHER_FILES += $$PWD/tests.xml.in $$PWD/run_test.sh

tests_xml.target = tests.xml
tests_xml.depends = $$PWD/tests.xml.in
tests_xml.commands = sed -e "s:@BASENAME@:$${BASENAME}:g" $< > $@
Expand All @@ -19,7 +21,7 @@ QMAKE_CLEAN += $$tests_xml.target
PRE_TARGETDEPS += $$tests_xml.target

tests_install.path = /opt/tests/$${BASENAME}/contacts/
tests_install.files = $$tests_xml.target
tests_install.files = $$tests_xml.target $$PWD/run_test.sh
tests_install.depends = tests_xml
tests_install.CONFIG += no_check_exist

Expand Down
13 changes: 8 additions & 5 deletions tests/tests.xml.in
Expand Up @@ -5,13 +5,16 @@
<set name="contactcache-test0" feature="Contacts">
<description>Contact cache automatic tests</description>
<case manual="false" name="synchronizelists">
<step>LIBCONTACTS_TEST_MODE=1 /usr/sbin/run-blts-root /bin/su -g privileged -c '/opt/tests/@PACKAGENAME@/tst_synchronizelists' nemo</step>
<step>/opt/tests/@BASENAME@/contacts/run_test.sh @BASENAME@ tst_synchronizelists</step>
</case>
<case manual="false" name="seasideimport">
<step>LIBCONTACTS_TEST_MODE=1 /usr/sbin/run-blts-root /bin/su -g privileged -c '/opt/tests/@PACKAGENAME@/tst_seasideimport' nemo</step>
<step>/opt/tests/@BASENAME@/contacts/run_test.sh @BASENAME@ tst_seasideimport</step>
</case>
<case manual="false" name="resolve">
<step>LIBCONTACTS_TEST_MODE=1 /usr/sbin/run-blts-root /bin/su -g privileged -c '/opt/tests/@PACKAGENAME@/tst_resolve' nemo</step>
<step>/opt/tests/@BASENAME@/contacts/run_test.sh @BASENAME@ tst_resolve</step>
</case>
<case manual="false" name="seasidestringlistcompressor">
<step>/opt/tests/@BASENAME@/contacts/run_test.sh @BASENAME@ tst_seasidestringlistcompressor</step>
</case>
</set>
</suite>
Expand All @@ -20,10 +23,10 @@
<set name="@BASENAME@-contacts-test0" feature="QML Contacts">
<description>Contacts QML plugin automatic tests</description>
<case manual="false" name="seasideperson" timeout="600">
<step>/opt/tests/@BASENAME@/contacts/tst_seasideperson</step>
<step>/opt/tests/@BASENAME@/contacts/run_test.sh @BASENAME@ tst_seasideperson</step>
</case>
<case manual="false" name="seasidefilteredmodel">
<step>/opt/tests/@BASENAME@/contacts/tst_seasidefilteredmodel</step>
<step>/opt/tests/@BASENAME@/contacts/run_test.sh @BASENAME@ tst_seasidefilteredmodel</step>
</case>
</set>
</suite>
Expand Down
10 changes: 6 additions & 4 deletions tests/tst_seasidefilteredmodel/tst_seasidefilteredmodel.cpp
Expand Up @@ -547,21 +547,23 @@ void tst_SeasideFilteredModel::filterCharacters()
QSKIP("Character matching is not testable with unknown locale");
}

// 1 2 3 4
// 1 2 3 4 5 - note that Ælvis will match due to NameDetails.Contains match rule with diacritic decomposition
model.setFilterPattern("Elvis");
QCOMPARE(model.rowCount(), 4);
QCOMPARE(model.rowCount(), 5);
QCOMPARE(model.index(QModelIndex(), 0, 0).data(SeasideFilteredModel::ContactIdRole).toInt(), 1);
QCOMPARE(model.index(QModelIndex(), 1, 0).data(SeasideFilteredModel::ContactIdRole).toInt(), 2);
QCOMPARE(model.index(QModelIndex(), 2, 0).data(SeasideFilteredModel::ContactIdRole).toInt(), 3);
QCOMPARE(model.index(QModelIndex(), 3, 0).data(SeasideFilteredModel::ContactIdRole).toInt(), 4);
QCOMPARE(model.index(QModelIndex(), 4, 0).data(SeasideFilteredModel::ContactIdRole).toInt(), 5);

// 1 2 3 4
// 1 2 3 4 5 - note that Ælvis will match due to NameDetails.Contains match rule with diacritic decomposition
model.setFilterPattern("elvis");
QCOMPARE(model.rowCount(), 4);
QCOMPARE(model.rowCount(), 5);
QCOMPARE(model.index(QModelIndex(), 0, 0).data(SeasideFilteredModel::ContactIdRole).toInt(), 1);
QCOMPARE(model.index(QModelIndex(), 1, 0).data(SeasideFilteredModel::ContactIdRole).toInt(), 2);
QCOMPARE(model.index(QModelIndex(), 2, 0).data(SeasideFilteredModel::ContactIdRole).toInt(), 3);
QCOMPARE(model.index(QModelIndex(), 3, 0).data(SeasideFilteredModel::ContactIdRole).toInt(), 4);
QCOMPARE(model.index(QModelIndex(), 4, 0).data(SeasideFilteredModel::ContactIdRole).toInt(), 5);

// 3
model.setFilterPattern(QString::fromUtf8(u8"\u00CBlvis")); // 'Ëlvis'
Expand Down
5 changes: 4 additions & 1 deletion tests/tst_seasideperson/tst_seasideperson.cpp
Expand Up @@ -160,7 +160,10 @@ void tst_SeasidePerson::sectionBucket()
QSignalSpy spy(person.data(), SIGNAL(displayLabelChanged()));
QCOMPARE(person->displayLabel(), SeasidePerson::placeholderDisplayLabel());
QCOMPARE(spy.count(), 0);
QCOMPARE(person->sectionBucket(), QString());
// ignore the placeholder id if necessary. unit tests don't load translation catalogues.
if (person->displayLabel() != QStringLiteral("nemo_contacts-la-placeholder_display_label")) {
QCOMPARE(person->sectionBucket(), QString());
}

// set first
person->setLastName("Test");
Expand Down

0 comments on commit 697e40b

Please sign in to comment.