Merge lp:~carlos-mazieri/ubuntu-filemanager-app/model into lp:ubuntu-filemanager-app/plugin

Proposed by Carlos Jose Mazieri
Status: Merged
Approved by: Carlos Jose Mazieri
Approved revision: 48
Merged at revision: 40
Proposed branch: lp:~carlos-mazieri/ubuntu-filemanager-app/model
Merge into: lp:ubuntu-filemanager-app/plugin
Diff against target: 143 lines (+112/-1)
1 file modified
test_folderlistmodel/regression/tst_folderlistmodel.cpp (+112/-1)
To merge this branch: bzr merge lp:~carlos-mazieri/ubuntu-filemanager-app/model
Reviewer Review Type Date Requested Status
Carlos Jose Mazieri Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+197287@code.launchpad.net

Commit message

added test case TestDirModel::extFsWatcherNoticeChangesWithSameTimestamp()

Description of the change

added test case TestDirModel::extFsWatcherNoticeChangesWithSameTimestamp()

It simulates an external change that could occurs in the same timestamp, like this: "first change -> notification -> second change" where "first change" and "second change" generate files with same last modification timestamps.

The test makes sure ExternalFSWatcher object do not miss the "second change" and emits that change as well.

This test case was proposed in https://code.launchpad.net/~carlos-mazieri/ubuntu-filemanager-app/model/+merge/195968

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Carlos Jose Mazieri (carlos-mazieri) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'test_folderlistmodel/regression/tst_folderlistmodel.cpp'
2--- test_folderlistmodel/regression/tst_folderlistmodel.cpp 2013-11-27 12:04:20 +0000
3+++ test_folderlistmodel/regression/tst_folderlistmodel.cpp 2013-11-30 18:25:33 +0000
4@@ -3,6 +3,9 @@
5 #include "tempfiles.h"
6 #include "externalfswatcher.h"
7 #include <stdio.h>
8+#include <sys/types.h>
9+#include <utime.h>
10+#include <sys/time.h>
11
12 #ifndef DO_NOT_USE_TAG_LIB
13 #include <taglib/attachedpictureframe.h>
14@@ -123,6 +126,7 @@
15 void extFsWatcherModifySamePathManyTimesWithInInterval(); // just one notification
16 void extFsWatcherSetPathAndModifyManyTimesWithInInterval();// just one notification
17 void extFsWatcherChangePathManyTimesModifyManyTimes(); // many notifications
18+ void extFsWatcherNoticeChangesWithSameTimestamp();
19
20 //define TEST_OPENFILES to test QDesktopServices::openUrl() for some files
21 #if defined(TEST_OPENFILES)
22@@ -1956,6 +1960,81 @@
23 QCOMPARE(m_extFSWatcherPathModifiedCounter, 1);
24 }
25
26+/*!
27+ * \brief TestDirModel::extFsWatcherNoticeChangesWithSameTimestamp()
28+ *
29+ * Test if it gets notification from \ref ExternalFSWatcher for a file changed/created that generates the same
30+ * timestamp as the last modification which had generated previous notification.
31+ *
32+ * \note To do this the "last modification time" is forced with utimes(2) system call.
33+ */
34+void TestDirModel::extFsWatcherNoticeChangesWithSameTimestamp()
35+{
36+ bool updateAndSetModificationTime(const QString& filename, QDateTime& desiredTime);
37+
38+ connect( m_dirModel_01->mExtFSWatcher, SIGNAL(pathModified()),
39+ this, SLOT(slotExtFsWatcherPathModified()));
40+
41+ QString dirName("extFsWatcher_generate_fileswithsameTimeStamp");
42+ m_deepDir_01 = new DeepDir(dirName,0);
43+ //create 2 files
44+ TempFiles tmp1, tmp2;
45+ tmp1.addSubDirLevel(dirName);
46+ tmp2.addSubDirLevel(dirName);
47+ tmp1.create(QLatin1String("first"), 1);
48+ tmp2.create(QLatin1String("second"), 1);
49+ QString firstPathName = tmp1.createdList().at(0);
50+ QString secondPathName = tmp2.createdList().at(0);
51+
52+ m_dirModel_01->setPath(m_deepDir_01->path());
53+ QTest::qWait(TIME_TO_REFRESH_DIR);
54+ //make sure model has 2 files
55+ QCOMPARE(m_dirModel_01->rowCount(), 2) ;
56+
57+ QDateTime timeStamp = QDateTime::currentDateTime();
58+ QTime time = timeStamp.time();
59+ //set msecs to 0
60+ time.setHMS(time.hour(), time.minute(), time.second());
61+ timeStamp.setTime(time);
62+
63+ //wait some time to have a different timestamp
64+ QTest::qWait(2200);
65+
66+ //update first time and set its modification time to timeStamp
67+ bool ret = updateAndSetModificationTime(firstPathName, timeStamp);
68+ QCOMPARE(ret, true);
69+ QFileInfo firstFile(firstPathName);
70+ QCOMPARE(firstFile.lastModified(), timeStamp);
71+
72+ const int maxWait = m_dirModel_01->mExtFSWatcher->getIntervalToNotifyChanges() + 10;
73+ int counter = 0;
74+
75+ //make sure ExternalFSWatcher has not notified any change
76+ QCOMPARE(m_extFSWatcherPathModifiedCounter, 0);
77+ //wait for notification on first file
78+ for (counter = 0; m_extFSWatcherPathModifiedCounter == 0 && counter < maxWait; ++counter)
79+ {
80+ QTest::qWait(1);
81+ }
82+ //make sure as notification was sent, it must be one
83+ QCOMPARE(m_extFSWatcherPathModifiedCounter, 1);
84+
85+ //now update the second file and set the mofication time the same as the first file
86+ //this second file is one what matters because the first change has just been notified
87+ ret = updateAndSetModificationTime(secondPathName, timeStamp);
88+ QCOMPARE(ret, true);
89+ QFileInfo secondFile(secondPathName);
90+ QCOMPARE(secondFile.lastModified(), timeStamp);
91+ for (counter = 0; m_extFSWatcherPathModifiedCounter == 1 && counter < maxWait; ++counter)
92+ {
93+ QTest::qWait(1);
94+ }
95+ //make sure as notification was sent, it must be 2
96+ QCOMPARE(m_extFSWatcherPathModifiedCounter, 2);
97+
98+ //this comparation is not necessary since both last modification files were compared to timeStamp
99+ QCOMPARE(secondFile.lastModified(), firstFile.lastModified());
100+}
101
102
103 int main(int argc, char *argv[])
104@@ -2015,6 +2094,38 @@
105 return ret;
106 }
107
108-
109+/*!
110+ * \brief updateAndSetModificationTime()
111+ * updates the file content and sets its last modification time to another time
112+ * \param filename
113+ * \param desiredTime some time less than current time
114+ * \return true if it could be performed, false otherwise
115+ */
116+bool updateAndSetModificationTime(const QString& filename, QDateTime& desiredTime)
117+{
118+ bool ret = false;
119+ QFile f(filename);
120+ if (f.open(QFile::Append))
121+ {
122+ QByteArray data("1234");
123+ if (f.write(data) == (qint64)data.size())
124+ {
125+ f.close();
126+ struct timeval times[2] =
127+ {
128+ {(long)desiredTime.toTime_t(), (long)desiredTime.time().msec()},
129+ {(long)desiredTime.toTime_t(), (long)desiredTime.time().msec()}
130+ };
131+ QFileInfo info(filename);
132+ qDebug() << "last modification of" << info.fileName() << info.lastModified()
133+ << "forcing it to" << desiredTime;
134+ if (utimes(filename.toLatin1().constData(), times) == 0)
135+ {
136+ ret = true;
137+ }
138+ }
139+ }
140+ return ret;
141+}
142
143 #include "tst_folderlistmodel.moc"

Subscribers

People subscribed via source and target branches