[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/devtools/kdevelop4-extra-plugins/coverage
From:       Daniel Calviño Sánchez <danxuliu () gmail ! com>
Date:       2011-09-07 1:02:53
Message-ID: 20110907010253.530A7AC87D () svn ! kde ! org
[Download RAW message or body]

SVN commit 1251903 by danxuliu:

Add KDevelop::IStatus support to the remove gcda files job.

 M  +1 -0      CMakeLists.txt  
 M  +19 -0     removegcdafilesjob.cpp  
 M  +9 -0      removegcdafilesjob.h  
 AM            removegcdafilesjobprogress.cpp   [License: GPL (v2+)]
 AM            removegcdafilesjobprogress.h   [License: GPL (v2+)]
 M  +2 -0      tests/CMakeLists.txt  
 AM            tests/removegcdafilesjobprogresstest.cpp   [License: GPL (v2+)]
 AM            tests/removegcdafilesjobprogresstest.h   [License: GPL (v2+)]
 M  +61 -0     tests/removegcdafilesjobtest.cpp  
 M  +2 -0      tests/removegcdafilesjobtest.h  


--- trunk/playground/devtools/kdevelop4-extra-plugins/coverage/CMakeLists.txt \
#1251902:1251903 @@ -40,6 +40,7 @@
     gradientcolorrange.cpp
     buildpathselection.cpp
     removegcdafilesjob.cpp
+    removegcdafilesjobprogress.cpp
     tests/viewstub.cpp
     tests/pluginstub.cpp)
 
--- trunk/playground/devtools/kdevelop4-extra-plugins/coverage/removegcdafilesjob.cpp \
#1251902:1251903 @@ -19,13 +19,21 @@
 
 #include "removegcdafilesjob.h"
 
+#include "removegcdafilesjobprogress.h"
+
 #include <QDir>
 #include <QtConcurrentRun>
 #include <QFuture>
 
 #include <KLocale>
 
+#include <interfaces/icore.h>
+#include <interfaces/iuicontroller.h>
+
+using KDevelop::ICore;
+
 using Veritas::RemoveGcdaFilesJob;
+using Veritas::RemoveGcdaFilesJobProgress;
 
 RemoveGcdaFilesJob::RemoveGcdaFilesJob(const KUrl& rootPath, QObject* parent):
         KJob(parent),
@@ -34,9 +42,14 @@
 
     setCapabilities(Killable);
     setObjectName(i18nc("@action:inmenu", "Remove coverage data from \
<filename>%1</filename> directory", rootPath.toLocalFile())); +
+    mRemoveGcdaFilesJobProgress = new RemoveGcdaFilesJobProgress(this);
+    ICore::self()->uiController()->registerStatus(mRemoveGcdaFilesJobProgress);
 }
 
 void RemoveGcdaFilesJob::start() {
+    mRemoveGcdaFilesJobProgress->start();
+
     mDoWorkWatcher = new QFutureWatcher<void>(this);
     connect(mDoWorkWatcher, SIGNAL(finished()), this, SLOT(jobDone()));
 
@@ -53,14 +66,20 @@
 }
 
 void RemoveGcdaFilesJob::jobDone() {
+    mRemoveGcdaFilesJobProgress->finish();
+
     emitResult();
 }
 
 void RemoveGcdaFilesJob::doWork() const {
     QFileInfoList gcdaFileInfos = findGcdaFilesIn(QDir(mRootPath.toLocalFile()));
 
+    mRemoveGcdaFilesJobProgress->setNumberOfFilesFound(gcdaFileInfos.count());
+
     QListIterator<QFileInfo> it(gcdaFileInfos);
     while (it.hasNext() && !mKillRequested) {
+        mRemoveGcdaFilesJobProgress->fileAboutToBeRemoved();
+
         QFile(it.next().absoluteFilePath()).remove();
     }
 }
--- trunk/playground/devtools/kdevelop4-extra-plugins/coverage/removegcdafilesjob.h \
#1251902:1251903 @@ -31,7 +31,11 @@
 class QDir;
 
 namespace Veritas {
+class RemoveGcdaFilesJobProgress;
+}
 
+namespace Veritas {
+
 /**
  * Job to remove the .gcda files from the given directory and, recursively, its
  * subdirectories.
@@ -91,6 +95,11 @@
     QFutureWatcher<void>* mDoWorkWatcher;
 
     /**
+     * The status updater for this job.
+     */
+    RemoveGcdaFilesJobProgress* mRemoveGcdaFilesJobProgress;
+
+    /**
      * Finds and removes the .gcda files in the root path and its
      * subdirectories.
      */
--- trunk/playground/devtools/kdevelop4-extra-plugins/coverage/tests/CMakeLists.txt \
#1251902:1251903 @@ -31,6 +31,7 @@
 kdev_add_test(unit-discretecolorrange discretecolorrangetest.cpp)
 kdev_add_test(unit-gradientcolorrange gradientcolorrangetest.cpp)
 kdev_add_test(unit-removegcdafilesjob removegcdafilesjobtest.cpp)
+kdev_add_test(unit-removegcdafilesjobprogress removegcdafilesjobprogresstest.cpp)
 kdev_add_test(unit-reportmodel reportmodeltest.cpp)
 kdev_add_test(unit-reportitems reportitemstest.cpp)
 kdev_add_test(unit-reportfileitem reportfileitemtest.cpp)
@@ -53,6 +54,7 @@
 coverage_add_mem_test(discretecolorrange unit)
 coverage_add_mem_test(gradientcolorrange unit)
 coverage_add_mem_test(removegcdafilesjob unit)
+coverage_add_mem_test(removegcdafilesjobprogress unit)
 coverage_add_mem_test(reportmodel unit)
 coverage_add_mem_test(reportitems unit)
 coverage_add_mem_test(reportfileitem unit)
--- trunk/playground/devtools/kdevelop4-extra-plugins/coverage/tests/removegcdafilesjobtest.cpp \
#1251902:1251903 @@ -23,13 +23,27 @@
 #include "../removegcdafilesjob.h"
 #undef private
 #undef protected
+#include "../removegcdafilesjobprogress.h"
 #include "testutils.h"
 
 #include <KStandardDirs>
 
+#include <tests/autotestshell.h>
+#include <tests/testcore.h>
+
+using KDevelop::AutoTestShell;
+using KDevelop::Core;
+using KDevelop::TestCore;
+
 using Veritas::RemoveGcdaFilesJob;
+using Veritas::RemoveGcdaFilesJobProgress;
 using Veritas::RemoveGcdaFilesJobTest;
 
+void RemoveGcdaFilesJobTest::initTestCase() {
+    AutoTestShell::init();
+    TestCore::initialize(Core::NoUi);
+}
+
 void RemoveGcdaFilesJobTest::init() {
     m_testPath = KStandardDirs().saveLocation("tmp", "removeGcdaFilesJobTest/");
 
@@ -82,8 +96,21 @@
     deleteDirectory(m_testPath);
 }
 
+void RemoveGcdaFilesJobTest::cleanupTestCase() {
+    TestCore::shutdown();
+}
+
 void RemoveGcdaFilesJobTest::testRemoveFilesInSingleDirectory() {
     RemoveGcdaFilesJob* job = new RemoveGcdaFilesJob(m_testPath + \
"/parentDir/dir1"); +
+    RemoveGcdaFilesJobProgress* progress = \
job->findChild<RemoveGcdaFilesJobProgress*>(); +
+    QVERIFY(progress);
+
+    //KDevelop::IStatus* must be registered in order to be used with QSignalSpy
+    qRegisterMetaType<KDevelop::IStatus*>("KDevelop::IStatus*");
+    QSignalSpy showProgressSpy(progress, SIGNAL(showProgress(KDevelop::IStatus*, \
int, int, int))); +
     job->start();
 
     QTest::kWaitForSignal(job, SIGNAL(destroyed(QObject*)));
@@ -101,6 +128,23 @@
     QVERIFY(QFile::exists(m_testPath + "/parentDir/file2"));
     QVERIFY(QFile::exists(m_testPath + "/parentDir/file2.gcda"));
     QVERIFY(QFile::exists(m_testPath + "/parentDir/file2.gcda.bak"));
+
+    QCOMPARE(showProgressSpy.count(), 5);
+    QCOMPARE(showProgressSpy.at(0).at(1).toInt(), 0);
+    QCOMPARE(showProgressSpy.at(0).at(2).toInt(), 1);
+    QCOMPARE(showProgressSpy.at(0).at(3).toInt(), 0);
+    QCOMPARE(showProgressSpy.at(1).at(1).toInt(), 0);
+    QCOMPARE(showProgressSpy.at(1).at(2).toInt(), 2);
+    QCOMPARE(showProgressSpy.at(1).at(3).toInt(), 1);
+    QCOMPARE(showProgressSpy.at(2).at(1).toInt(), 0);
+    QCOMPARE(showProgressSpy.at(2).at(2).toInt(), 100);
+    QCOMPARE(showProgressSpy.at(2).at(3).toInt(), 50);
+    QCOMPARE(showProgressSpy.at(3).at(1).toInt(), 0);
+    QCOMPARE(showProgressSpy.at(3).at(2).toInt(), 100);
+    QCOMPARE(showProgressSpy.at(3).at(3).toInt(), 75);
+    QCOMPARE(showProgressSpy.at(4).at(1).toInt(), 0);
+    QCOMPARE(showProgressSpy.at(4).at(2).toInt(), 1);
+    QCOMPARE(showProgressSpy.at(4).at(3).toInt(), 1);
 }
 
 void RemoveGcdaFilesJobTest::testRemoveFilesInComplexDirectory() {
@@ -142,6 +186,15 @@
 
 void RemoveGcdaFilesJobTest::testStopJob() {
     QPointer<RemoveGcdaFilesJob> job = new RemoveGcdaFilesJob(m_testPath + \
"/parentDir/"); +
+    RemoveGcdaFilesJobProgress* progress = \
job->findChild<RemoveGcdaFilesJobProgress*>(); +
+    QVERIFY(progress);
+
+    //KDevelop::IStatus* must be registered in order to be used with QSignalSpy
+    qRegisterMetaType<KDevelop::IStatus*>("KDevelop::IStatus*");
+    QSignalSpy showProgressSpy(progress, SIGNAL(showProgress(KDevelop::IStatus*, \
int, int, int))); +
     job->start();
 
     job->kill();
@@ -161,6 +214,14 @@
             QFile::exists(m_testPath + "/parentDir/dir2/childDir/file.gcda") ||
             QFile::exists(m_testPath + "/parentDir/dir3/file.gcda") ||
             QFile::exists(m_testPath + "/parentDir/dir3/childDir/file.gcda"));
+
+    QVERIFY(showProgressSpy.count() >= 2);
+    QCOMPARE(showProgressSpy.at(0).at(1).toInt(), 0);
+    QCOMPARE(showProgressSpy.at(0).at(2).toInt(), 1);
+    QCOMPARE(showProgressSpy.at(0).at(3).toInt(), 0);
+    QCOMPARE(showProgressSpy.last().at(1).toInt(), 0);
+    QCOMPARE(showProgressSpy.last().at(2).toInt(), 1);
+    QCOMPARE(showProgressSpy.last().at(3).toInt(), 1);
 }
 
 /////////////////////////////////// Helpers ////////////////////////////////////
--- trunk/playground/devtools/kdevelop4-extra-plugins/coverage/tests/removegcdafilesjobtest.h \
#1251902:1251903 @@ -28,8 +28,10 @@
 Q_OBJECT
 private slots:
 
+    void initTestCase();
     void init();
     void cleanup();
+    void cleanupTestCase();
 
     void testRemoveFilesInSingleDirectory();
     void testRemoveFilesInComplexDirectory();


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic