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

List:       kde-commits
Subject:    [nepomuk-core/testLibrary] /: Initial import from svn
From:       Vishesh Handa <handa.vish () gmail ! com>
Date:       2012-07-03 12:25:24
Message-ID: 20120703122525.0012DA60A6 () git ! kde ! org
[Download RAW message or body]

Git commit ae2ef381782ecf7abd5f1a8801ed645588b9e040 by Vishesh Handa.
Committed on 16/02/2012 at 12:00.
Pushed by vhanda into branch 'testLibrary'.

Initial import from svn

from the nepomuk playgroudn

A  +48   -0    CMakeLists.txt
A  +17   -0    README
A  +67   -0    lib/CMakeLists.txt
A  +8    -0    lib/NepomukTestLibMacros.cmake.in
A  +51   -0    lib/nepomukserverrc.in
A  +43   -0    lib/nepomuktest_export.h     [License: LGPL (v2+)]
A  +183  -0    lib/testbase.cpp     [License: LGPL (v2.1+)]
A  +88   -0    lib/testbase.h     [License: LGPL (v2.1+)]
A  +40   -0    test/CMakeLists.txt
A  +39   -0    test/filewatch/CMakeLists.txt
A  +1    -0    test/filewatch/Testing/Temporary/CTestCostData.txt
A  +3    -0    test/filewatch/Testing/Temporary/LastTest.log
A  +193  -0    test/filewatch/filewatch.cpp     [License: GPL (v3+)]
A  +41   -0    test/filewatch/filewatch.h     [License: GPL (v3+)]
A  +55   -0    test/identificationtest.cpp     [License: GPL (v3+)]
A  +34   -0    test/identificationtest.h     [License: GPL (v3+)]
A  +31   -0    tools/CMakeLists.txt
A  +4    -0    tools/runNepomukTest.sh.in
A  +8    -0    tools/run_in_new_dbus_session.sh
A  +71   -0    tools/with-nepomuk-sandbox.sh.in

http://commits.kde.org/nepomuk-core/ae2ef381782ecf7abd5f1a8801ed645588b9e040

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..63947a2
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,48 @@
+project (nepomuktestlib)
+
+# Set minimum versions of packages we need
+set (KDE_MIN_VERSION "4.4.75")
+set (SDO_MIN_VERSION "0.3.60")
+
+# Find all the required packages
+find_package (KDE4 ${KDE_MIN_VERSION} REQUIRED)
+find_package (Nepomuk REQUIRED)
+find_package (Soprano REQUIRED)
+find_package (SharedDesktopOntologies ${SDO_MIN_VERSION} REQUIRED)
+
+# Include some stuff
+include (KDE4Defaults)
+include (MacroLibrary)
+
+# Add some misc definitions
+add_definitions (${KDE4_DEFINITIONS}
+                 -DDISABLE_NEPOMUK_LEGACY
+                # -DQT_NO_CAST_FROM_ASCII
+                # -DQT_NO_KEYWORDS
+                # -fPIC
+)
+
+# Set the basic include directories
+include_directories (${KDE4_INCLUDES}
+                     ${NEPOMUK_INCLUDES}
+                     ${CMAKE_SOURCE_DIR}
+                     ${CMAKE_BINARY_DIR}
+                     ${CMAKE_CURRENT_SOURCE_DIR}
+                     ${CMAKE_CURRENT_BINARY_DIR}
+)
+
+# Set variables for some special install directories
+set (NEPOMUK_TESTLIB_DATA_INSTALL_DIR
+     "${DATA_INSTALL_DIR}/Nepomuk/TestLib"
+)
+
+set (NEPOMUK_TESTLIB_TOOLS_INSTALL_DIR
+     "${NEPOMUK_TESTLIB_DATA_INSTALL_DIR}/tools"
+)
+
+set (NEPOMUK_TESTLIB_CMAKE_INSTALL_DIR
+     "${DATA_INSTALL_DIR}/cmake/modules"
+)
+
+add_subdirectory( tools )
+add_subdirectory( lib )
diff --git a/README b/README
new file mode 100644
index 0000000..e3292ac
--- /dev/null
+++ b/README
@@ -0,0 +1,17 @@
+Nepomuk-test is a static library for building unit tests of KDE/Nepomuk components.
+
+It allows complicated unit tests which make use of a Private DBus Session Bus and a \
virtuoso +sandbox to avoid making a mess of the nepomuk/dbus installations running on \
the +system where the tests are run.
+
+When running Nepomuk unit tests please make sure the services you require are \
running. If they +are not running they can be started via the \
Nepomuk::TestBase::startService function. All tests +should be derived from the \
Nepomuk::TestBase class. +
+By default only 3 services are started -
+* Storage
+* Ontology Loader
+* Query Service
+ 
+This code is based on the Telepathy Testlib which can be found - \
https://projects.kde.org/projects/playground/network/telepathy/telepathy-testlib +
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
new file mode 100644
index 0000000..04b7a8f
--- /dev/null
+++ b/lib/CMakeLists.txt
@@ -0,0 +1,67 @@
+#
+# nepomukserverrc config file
+#
+configure_file ("${CMAKE_CURRENT_SOURCE_DIR}/nepomukserverrc.in"
+                "${CMAKE_CURRENT_BINARY_DIR}/nepomukserverrc"
+                IMMEDIATE @ONLY
+)
+
+install (FILES "${CMAKE_CURRENT_BINARY_DIR}/nepomukserverrc"
+         DESTINATION ${NEPOMUK_TESTLIB_DATA_INSTALL_DIR}
+         COMPONENT Devel
+)
+
+#
+# CMake Macros
+#
+
+configure_file ("${CMAKE_CURRENT_SOURCE_DIR}/NepomukTestLibMacros.cmake.in"
+                "${CMAKE_CURRENT_BINARY_DIR}/NepomukTestLibMacros.cmake"
+                IMMEDIATE @ONLY
+)
+
+install (FILES "${CMAKE_CURRENT_BINARY_DIR}/NepomukTestLibMacros.cmake"
+         DESTINATION ${NEPOMUK_TESTLIB_CMAKE_INSTALL_DIR}
+         COMPONENT Devel
+)
+
+#
+# Source code
+#
+
+set (nepomuk_testlib_SRCS
+    testbase.cpp
+)
+
+qt4_add_dbus_interface(nepomuk_testlib_SRCS \
${DBUS_INTERFACES_INSTALL_DIR}/org.kde.nepomuk.ServiceManager.xml \
nepomukservicemanagerinterface) +
+kde4_add_library (nepomuktest
+                  STATIC
+                  ${nepomuk_testlib_SRCS}
+)
+
+target_link_libraries (nepomuktest
+                       ${QT_QTCORE_LIBRARY}
+                       ${QT_QTDBUS_LIBRARY}
+                        #TODO: Add more!
+)
+
+set_target_properties (nepomuktest PROPERTIES
+                       VERSION ${GENERIC_LIB_VERSION}
+                       SOVERSION ${GENERIC_LIB_SOVERSION}
+)
+
+install (TARGETS nepomuktest
+         ${INSTALL_TARGETS_DEFAULT_ARGS}
+         COMPONENT Devel
+)
+
+set( nepomuk_testlib_HEADERS
+     testbase.h
+     nepomuktest_export.h
+)
+
+install (FILES ${nepomuk_testlib_HEADERS}
+         DESTINATION ${INCLUDE_INSTALL_DIR}/Nepomuk
+         COMPONENT Devel
+)
\ No newline at end of file
diff --git a/lib/NepomukTestLibMacros.cmake.in b/lib/NepomukTestLibMacros.cmake.in
new file mode 100644
index 0000000..ffbf9f1
--- /dev/null
+++ b/lib/NepomukTestLibMacros.cmake.in
@@ -0,0 +1,8 @@
+# Add a Nepomuk unit test, which is executed when running 'make test' or 'ctest'
+# The executable should be created using kde4_add_executable and the appropriate \
libraries +# should be linked using target_link_libraries 
+function(add_nepomuk_test fancyName executable)
+    find_program(SH sh)
+    add_test(${fancyName} ${SH} \
@NEPOMUK_TESTLIB_TOOLS_INSTALL_DIR@/runNepomukTest.sh ${executable}) \
+endfunction(add_nepomuk_test fancyName executable) +
diff --git a/lib/nepomukserverrc.in b/lib/nepomukserverrc.in
new file mode 100644
index 0000000..6b31551
--- /dev/null
+++ b/lib/nepomukserverrc.in
@@ -0,0 +1,51 @@
+[Basic Settings]
+Configured repositories=main
+Soprano Backend=virtuosobackend
+Start Nepomuk=true
+
+[Service-nepomukmigration1]
+autostart=false
+
+[Service-nepomukstrigiservice]
+autostart=false
+
+[Service-nepomukremovablestorageservice]
+autostart=false
+
+[Service-nepomukfilesystemmanagementservice]
+autostart=false
+
+[Service-nepomukmigrationservice]
+autostart=false
+
+[Service-nepomukusercontextservice]
+autostart=false
+
+[Service-nepomukpimoservice]
+autostart=false
+
+[Service-nepomukstorage]
+autostart=true
+
+[Service-nepomukontologyloader]
+autostart=true
+
+[Service-nepomukfileannotationservice]
+autostart=false
+
+[Service-nepomukqueryservice]
+autostart=true
+
+[Service-nepomukfilewatch]
+autostart=false
+
+[Service-nepomukactivitiesservice]
+autostart=false
+
+[Service-nepomuktelepathyservice]
+autostart=false
+
+[main Settings]
+Maximum memory=50
+Storage Dir=
+Used Soprano Backend=virtuosobackend
diff --git a/lib/nepomuktest_export.h b/lib/nepomuktest_export.h
new file mode 100644
index 0000000..bd75e97
--- /dev/null
+++ b/lib/nepomuktest_export.h
@@ -0,0 +1,43 @@
+/*  This file is part of the KDE project
+    Copyright (C) 2007 David Faure <faure@kde.org>
+
+    This library 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 library 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 Library General Public License
+    along with this library; see the file COPYING.LIB.  If not, write to
+    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+    Boston, MA 02110-1301, USA.
+*/
+
+#ifndef NEPOMUKTEST_EXPORT_H
+#define NEPOMUKTEST_EXPORT_H
+
+/* needed for KDE_EXPORT and KDE_IMPORT macros */
+#include <kdemacros.h>
+
+#ifndef NEPOMUKTEST_EXPORT
+# if defined(KDELIBS_STATIC_LIBS)
+/* No export/import for static libraries */
+#  define NEPOMUKTEST_EXPORT
+# elif defined(MAKE_NEPOMUKSYNC_LIB)
+/* We are building this library */
+#  define NEPOMUKTEST_EXPORT KDE_EXPORT
+# else
+/* We are using this library */
+#  define NEPOMUKTEST_EXPORT KDE_IMPORT
+# endif
+#endif
+
+# ifndef NEPOMUKTEST_EXPORT_DEPRECATED
+#  define NEPOMUKTEST_EXPORT_DEPRECATED KDE_DEPRECATED NEPOMUKTEST_EXPORT
+# endif
+
+#endif
\ No newline at end of file
diff --git a/lib/testbase.cpp b/lib/testbase.cpp
new file mode 100644
index 0000000..8395b02
--- /dev/null
+++ b/lib/testbase.cpp
@@ -0,0 +1,183 @@
+/*
+ * This file is part of nepomuk-testlib
+ *
+ * Copyright (C) 2010 Vishesh Handa <handa.vish@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+
+#include "testbase.h"
+#include "nepomukservicemanagerinterface.h"
+
+#include <QtCore/QFile>
+#include <QtCore/QDir>
+
+#include <QtDBus/QDBusConnection>
+#include <QtTest>
+
+#include <KStandardDirs>
+#include <KTempDir>
+#include <KDebug>
+
+#include <Nepomuk/ResourceManager>
+
+#include <Soprano/Model>
+#include <Soprano/QueryResultIterator>
+#include <Soprano/NodeIterator>
+
+
+class Nepomuk::TestBase::Private {
+public:
+    org::kde::nepomuk::ServiceManager* m_serviceManager;
+    QString m_repoLocation;
+    KTempDir m_tempDir;
+};
+
+Nepomuk::TestBase::TestBase(QObject* parent)
+    : QObject( parent ),
+      d( new Nepomuk::TestBase::Private )
+{
+    d->m_serviceManager = new org::kde::nepomuk::ServiceManager( \
"org.kde.NepomukServer", "/servicemanager", QDBusConnection::sessionBus() ); +
+    d->m_repoLocation = KStandardDirs::locateLocal( "data", "nepomuk/repository/" );
+
+    // Stop all the other servies
+    QSet<QString> services = runningServices().toSet();
+    kDebug() << "Running Services : " << services;
+    services.remove( "nepomukstorage" );
+    services.remove( "nepomukontologyloader" );
+    services.remove( "nepomukqueryservice" );
+
+    Q_FOREACH( const QString & service, services )
+        stopService( service );
+}
+
+Nepomuk::TestBase::~TestBase()
+{
+    delete d;
+}
+
+
+
+void Nepomuk::TestBase::initTestCase()
+{
+}
+
+void Nepomuk::TestBase::cleanupTestCase()
+{
+}
+
+void Nepomuk::TestBase::resetRepository()
+{
+    kDebug() << "Reseting the repository ..";
+    QString query = "select ?r where { graph ?g { ?r ?p ?o. } . ?g a \
nrl:InstanceBase . }"; +    Soprano::Model * model = \
Nepomuk::ResourceManager::instance()->mainModel(); +    
+    Soprano::QueryResultIterator it = model->executeQuery( query, \
Soprano::Query::QueryLanguageSparql ); +    QList<Soprano::Node> resources = \
it.iterateBindings( 0 ).allNodes(); +
+    foreach( const Soprano::Node & node, resources ) {
+        model->removeAllStatements( node, Soprano::Node(), Soprano::Node() );
+    }
+}
+
+
+void Nepomuk::TestBase::waitForServiceInitialization(const QString& service)
+{
+    while( !isServiceRunning( service ) ) {
+        QTest::qSleep( 100 );
+    }
+    
+    while( !isServiceInitialized( service ) ) {
+        QTest::qSleep( 200 );
+        kDebug() << runningServices();
+    }
+}
+
+
+void Nepomuk::TestBase::startServiceAndWait(const QString& service)
+{
+    if( isServiceRunning( service ) )
+        return;
+
+    kDebug() << "Starting " << service << " ...";
+    startService( service );
+    kDebug() << "Waiting ...";
+    waitForServiceInitialization( service );
+}
+
+
+
+//
+// Service Manager
+//
+
+QStringList Nepomuk::TestBase::availableServices()
+{
+    QDBusPendingReply< QStringList > reply = \
d->m_serviceManager->availableServices(); +    reply.waitForFinished();
+    return reply.value();
+}
+
+bool Nepomuk::TestBase::isServiceAutostarted(const QString& service)
+{
+    QDBusPendingReply< bool > reply = d->m_serviceManager->isServiceAutostarted( \
service ); +    reply.waitForFinished();
+    return reply.value();
+    
+}
+
+bool Nepomuk::TestBase::isServiceInitialized(const QString& name)
+{
+    QDBusPendingReply< bool > reply = d->m_serviceManager->isServiceInitialized( \
name ); +    reply.waitForFinished();
+    return reply.value();
+}
+
+bool Nepomuk::TestBase::isServiceRunning(const QString& name)
+{
+    QDBusPendingReply< bool > reply = d->m_serviceManager->isServiceRunning( name );
+    reply.waitForFinished();
+    return reply.value();
+}
+
+QStringList Nepomuk::TestBase::runningServices()
+{
+    QDBusPendingReply< QStringList > reply = d->m_serviceManager->runningServices();
+    reply.waitForFinished();
+    return reply.value();
+}
+
+void Nepomuk::TestBase::setServiceAutostarted(const QString& service, bool \
autostart) +{
+    d->m_serviceManager->setServiceAutostarted( service, autostart );
+}
+
+bool Nepomuk::TestBase::startService(const QString& name)
+{
+    QDBusPendingReply< bool > reply = d->m_serviceManager->startService( name );
+    reply.waitForFinished();
+    return reply.value();
+}
+
+bool Nepomuk::TestBase::stopService(const QString& name)
+{
+    QDBusPendingReply< bool > reply = d->m_serviceManager->stopService( name );
+    reply.waitForFinished();
+    return reply.value();
+}
+
+#include "testbase.moc"
\ No newline at end of file
diff --git a/lib/testbase.h b/lib/testbase.h
new file mode 100644
index 0000000..9296806
--- /dev/null
+++ b/lib/testbase.h
@@ -0,0 +1,88 @@
+/*
+ * This file is part of nepomuk-testlib
+ *
+ * Copyright (C) 2010 Vishesh Handa <handa.vish@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+
+#ifndef NEPOMUK_TESTBASE_H
+#define NEPOMUK_TESTBASE_H
+
+#include <QtCore/QObject>
+
+#include "nepomuktest_export.h"
+
+namespace Nepomuk {
+
+    /**
+     * \class TestBase testbase.h Nepomuk/TestBase
+     *
+     * All Nepomuk unit tests are to be derived from this class. It provides
+     * an interface to manage the services.
+     *
+     * By default only these services are started -
+     *  - nepomukstorage
+     *  - nepomukontologyloader
+     *  - nepomukqueryservice
+     *
+     * This class aditionally provides a mechanism to reeset the nepomuk
+     * repository to its original form.
+     * 
+     * \author Vishesh Handa <handa.vish@gmail.com>
+     */
+    class NEPOMUKTEST_EXPORT TestBase : public QObject
+    {
+        Q_OBJECT
+    public:
+
+        TestBase(QObject* parent = 0);
+        virtual ~TestBase();
+
+
+    private Q_SLOTS:
+        void initTestCase();
+        void cleanupTestCase();
+
+    protected:
+        void resetRepository();
+        
+    public Q_SLOTS:
+        QStringList availableServices();
+        QStringList runningServices();
+        
+        bool isServiceAutostarted(const QString &service);
+        bool isServiceInitialized(const QString &name);
+        bool isServiceRunning(const QString &name);
+        void setServiceAutostarted(const QString &service, bool autostart);
+
+        bool startService(const QString &name);
+        bool stopService(const QString &name);
+
+        void waitForServiceInitialization( const QString & service );
+        void startServiceAndWait( const QString & service );
+
+    Q_SIGNALS: 
+        void serviceInitialized(const QString &name);
+
+    private:
+        class Private;
+        Private * d;
+    };
+
+}
+
+#endif // NEPOMUK_TESTBASE_H
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100644
index 0000000..29807c2
--- /dev/null
+++ b/test/CMakeLists.txt
@@ -0,0 +1,40 @@
+project(nepomuksync_tests)
+
+find_package(KDE4 REQUIRED)
+find_package(Nepomuk REQUIRED)
+
+include( NepomukTestLibMacros )
+
+include_directories(
+  ${QT_INCLUDES}
+  ${KDE4_INCLUDES}
+  ${SOPRANO_INCLUDE_DIR}
+  ${CMAKE_SOURCE_DIR}
+  ${NEPOMUK_INCLUDE_DIR}
+  ${libnepomuksync_SOURCE_DIR}
+)
+
+include (KDE4Defaults)
+
+set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} )
+
+add_definitions(-DDISABLE_NEPOMUK_LEGACY=1)
+
+set(nepomuksynctests_SRCS identificationtest.cpp )
+
+kde4_add_executable( nepomuksynctest ${nepomuksynctests_SRCS} )
+add_nepomuk_test(nepomuksynctest ${CMAKE_CURRENT_BINARY_DIR}/nepomuksynctest)
+
+target_link_libraries(nepomuksynctest
+  ${QT_QTCORE_LIBRARY}
+  ${QT_QTDBUS_LIBRARY}
+  ${QT_QTTEST_LIBRARY}
+  ${QT_QTGUI_LIBRARY}
+  ${SOPRANO_LIBRARIES}
+  kdecore
+  nepomuktest
+  nepomuk
+)
+
+
+
diff --git a/test/filewatch/CMakeLists.txt b/test/filewatch/CMakeLists.txt
new file mode 100644
index 0000000..8b8206d
--- /dev/null
+++ b/test/filewatch/CMakeLists.txt
@@ -0,0 +1,39 @@
+project(filewatch_tests)
+
+find_package(KDE4 REQUIRED)
+find_package(Nepomuk REQUIRED)
+
+include( NepomukTestLibMacros )
+
+include_directories(
+  ${QT_INCLUDES}
+  ${KDE4_INCLUDES}
+  ${CMAKE_SOURCE_DIR}
+  ${SOPRANO_INCLUDE_DIR}
+  ${NEPOMUK_INCLUDE_DIR}
+)
+
+include (KDE4Defaults)
+
+set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} )
+
+add_definitions(-DDISABLE_NEPOMUK_LEGACY=1)
+
+set(filewatch_tests_SRCS filewatch.cpp )
+
+kde4_add_executable( filewatch_tests ${filewatch_tests_SRCS} )
+add_nepomuk_test(filewatch_tests ${CMAKE_CURRENT_BINARY_DIR}/filewatch_tests)
+
+target_link_libraries(filewatch_tests
+  ${QT_QTCORE_LIBRARY}
+  ${QT_QTDBUS_LIBRARY}
+  ${QT_QTTEST_LIBRARY}
+  ${QT_QTGUI_LIBRARY}
+  ${SOPRANO_LIBRARIES}
+  kdecore
+  nepomuk
+  nepomuktest
+)
+
+
+
diff --git a/test/filewatch/Testing/Temporary/CTestCostData.txt \
b/test/filewatch/Testing/Temporary/CTestCostData.txt new file mode 100644
index 0000000..ed97d53
--- /dev/null
+++ b/test/filewatch/Testing/Temporary/CTestCostData.txt
@@ -0,0 +1 @@
+---
diff --git a/test/filewatch/Testing/Temporary/LastTest.log \
b/test/filewatch/Testing/Temporary/LastTest.log new file mode 100644
index 0000000..43e6636
--- /dev/null
+++ b/test/filewatch/Testing/Temporary/LastTest.log
@@ -0,0 +1,3 @@
+Start testing: Nov 04 23:03 IST
+----------------------------------------------------------
+End testing: Nov 04 23:03 IST
diff --git a/test/filewatch/filewatch.cpp b/test/filewatch/filewatch.cpp
new file mode 100644
index 0000000..29516ca
--- /dev/null
+++ b/test/filewatch/filewatch.cpp
@@ -0,0 +1,193 @@
+/*
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 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 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 "filewatch.h"
+
+#include <KDebug>
+
+#include <kdebug.h>
+#include <ktemporaryfile.h>
+#include <qtest_kde.h>
+
+#include <KTempDir>
+#include <KTemporaryFile>
+
+#include <Nepomuk/Resource>
+#include <Nepomuk/ResourceManager>
+#include <Nepomuk/Tag>
+#include <Soprano/Model>
+#include <Soprano/StatementIterator>
+
+#include <QtCore/QDir>
+#include <QtCore/QFile>
+
+#include <Nepomuk/Vocabulary/NIE>
+#include <Nepomuk/Variant>
+
+FileWatchTest::FileWatchTest(QObject* parent)
+: TestBase(parent)
+{
+    startServiceAndWait("nepomukfilewatch");
+}
+
+
+namespace {
+    // It's hard to believe that Qt doesn't provide its own copy folder function
+    void copyFolder(QString sourceFolder, QString destFolder)
+    {
+        
+        QDir sourceDir(sourceFolder);
+        if(!sourceDir.exists()) {
+            kDebug() << sourceFolder << " doesn't exist!";
+            return;
+        }
+        
+        QDir destDir(destFolder);
+        if(!destDir.exists()) {
+            kDebug() << destFolder << " doesn't exist! Creating it!";
+            destDir.mkdir(destFolder);
+        }
+        
+        QStringList files = sourceDir.entryList(QDir::Files);
+        for(int i = 0; i< files.count(); i++) {
+            QString srcName = sourceFolder + QDir::separator() + files[i];
+            QString destName = destFolder + QDir::separator() + files[i];
+            kDebug() << srcName << " --> " << destName;
+            QFile::copy(srcName, destName);
+        }
+        files.clear();
+        
+        QStringList directories = sourceDir.entryList(QDir::AllDirs | \
QDir::NoDotAndDotDot); +        for(int i = 0; i< directories.count(); i++) {
+            QString srcName = sourceFolder + QDir::separator() + directories[i];
+            QString destName = destFolder + QDir::separator() + directories[i];
+            copyFolder(srcName, destName);
+        }
+    }
+    
+    bool removeDir(const QString &dirName)
+    {
+        bool result = true;
+        QDir dir(dirName);
+        
+        if (dir.exists(dirName)) {
+            QFileInfoList list =  dir.entryInfoList(QDir::NoDotAndDotDot | \
QDir::System | QDir::Hidden  | QDir::AllDirs | QDir::Files, QDir::DirsFirst); +       \
Q_FOREACH(QFileInfo info, list) { +                if (info.isDir()) {
+                    result = removeDir(info.absoluteFilePath());
+                }
+                else {
+                    result = QFile::remove(info.absoluteFilePath());
+                }
+                
+                if (!result) {
+                    return result;
+                }
+            }
+            result = dir.rmdir(dirName);
+        }
+        return result;
+    }
+
+    void touch( const QString & filePath ) {
+        QFile f1( filePath );
+        f1.open( QIODevice::ReadWrite );
+        f1.write("blah!");
+        f1.close();
+    }
+}
+
+void FileWatchTest::moveTest()
+{
+    QString path = createTempDir();
+    
+    QString f1Path = path + "/1";
+    touch( f1Path );
+    
+    Nepomuk::Resource res1( f1Path );
+    res1.setRating( 6 );
+
+    QString f1NewPath = path + "/new-1";
+
+    QFile::remove( f1NewPath ); // Just in case
+    QVERIFY( QFile::rename( f1Path, f1NewPath ) );
+    QVERIFY( !QFile::exists( f1Path ) );
+    QVERIFY( QFile::exists( f1NewPath ) );
+
+    // Sleep for 4 seconds as the filewatcher is not synchronous
+    QTest::qSleep( 4000 );
+    
+    Nepomuk::Resource res2( f1NewPath );
+    kDebug() << res1.resourceUri();
+    kDebug() << res2.resourceUri();
+
+    kDebug() << res1.property( Nepomuk::Vocabulary::NIE::url() ).toUrl();
+    QVERIFY( res1.resourceUri() == res2.resourceUri() );
+    QVERIFY( res2.rating() == 6 );
+
+    QFile::remove( f1Path );
+    QFile::remove( f1NewPath );
+
+    removeTempDir();
+}
+
+void FileWatchTest::deletionTest()
+{
+    QString path = createTempDir();
+    
+    QString filePath = path + "/1";
+    touch( filePath );
+
+    QUrl resUri;
+    {
+        Nepomuk::Resource res1( filePath );
+        res1.setRating( 5 );
+        resUri = res1.resourceUri();
+        QVERIFY( res1.exists() );
+    }
+
+    QVERIFY( QFile::remove( filePath ) );
+    QVERIFY( !QFile::exists( filePath ) );
+    
+    QTest::qSleep( 4000 );
+    
+    Soprano::Model * model = Nepomuk::ResourceManager::instance()->mainModel();
+    QVERIFY( model->containsAnyStatement( resUri, Soprano::Node(), Soprano::Node() ) \
); +    
+    removeTempDir();
+}
+
+QString FileWatchTest::createTempDir()
+{
+    // We need to use the home directory because the filewatcher doesn't track
+    // anyhting in /tmp/, which is where KTempDir would create a directory
+    QDir home = QDir::home();
+    home.mkdir("nepomuk-filewatch-test");
+    
+    QDir dir( QDir::homePath() + QDir::separator() + "nepomuk-filewatch-test" );
+    return dir.absolutePath();
+}
+
+void FileWatchTest::removeTempDir()
+{
+    removeDir( QDir::homePath() + QDir::separator() + "nepomuk-filewatch-test" );
+}
+
+
+QTEST_KDEMAIN(FileWatchTest, NoGUI)
\ No newline at end of file
diff --git a/test/filewatch/filewatch.h b/test/filewatch/filewatch.h
new file mode 100644
index 0000000..c97b4e9
--- /dev/null
+++ b/test/filewatch/filewatch.h
@@ -0,0 +1,41 @@
+/*
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 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 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/>.
+*/
+
+
+#ifndef FILEWATCHTEST_H
+#define FILEWATCHTEST_H
+
+#include <QtCore/QObject>
+#include <Nepomuk/testbase.h>
+
+class FileWatchTest : public Nepomuk::TestBase
+{
+    Q_OBJECT
+public:
+    FileWatchTest(QObject* parent = 0);
+    
+private Q_SLOTS:
+    void moveTest();
+    void deletionTest();
+
+private :
+    QString createTempDir();
+    void removeTempDir();
+};
+
+#endif // FILEWATCHTEST_H
diff --git a/test/identificationtest.cpp b/test/identificationtest.cpp
new file mode 100644
index 0000000..9f021c7
--- /dev/null
+++ b/test/identificationtest.cpp
@@ -0,0 +1,55 @@
+/*
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 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 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 "identificationtest.h"
+
+#include <KDebug>
+
+#include <kdebug.h>
+#include <ktemporaryfile.h>
+#include <qtest_kde.h>
+
+#include <KTempDir>
+#include <KTemporaryFile>
+
+#include <Nepomuk/Resource>
+#include <Nepomuk/ResourceManager>
+#include <Nepomuk/Tag>
+#include <Soprano/Model>
+#include <Soprano/StatementIterator>
+
+void NepomukSyncTests::basicIdentification()
+{
+    KTemporaryFile file;
+    file.open();
+    
+    Nepomuk::Resource r( file.fileName() );
+    r.setRating( 5 );
+    kDebug() << "Exists : " << r.exists();
+    kDebug() << "Orig rating : " << r.rating();
+
+    resetRepository();
+
+    kDebug() << "Exists : " << r.exists();
+    kDebug() << "Orig rating : " << r.rating();
+
+    QVERIFY( !r.exists() );
+}
+
+QTEST_KDEMAIN(NepomukSyncTests, NoGUI)
\ No newline at end of file
diff --git a/test/identificationtest.h b/test/identificationtest.h
new file mode 100644
index 0000000..d813d67
--- /dev/null
+++ b/test/identificationtest.h
@@ -0,0 +1,34 @@
+/*
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 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 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/>.
+*/
+
+
+#ifndef IDENTIFICATIONTEST_H
+#define IDENTIFICATIONTEST_H
+
+#include <QtCore/QObject>
+#include <Nepomuk/testbase.h>
+
+class NepomukSyncTests : public Nepomuk::TestBase
+{
+    Q_OBJECT
+    
+private Q_SLOTS:
+    void basicIdentification();
+};
+
+#endif // IDENTIFICATIONTEST_H
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
new file mode 100644
index 0000000..74ee6f6
--- /dev/null
+++ b/tools/CMakeLists.txt
@@ -0,0 +1,31 @@
+
+#
+# Scripts
+#
+
+# Configure the scripts
+configure_file ("${CMAKE_CURRENT_SOURCE_DIR}/with-nepomuk-sandbox.sh.in"
+                "${CMAKE_CURRENT_BINARY_DIR}/with-nepomuk-sandbox.sh"
+                IMMEDIATE @ONLY
+)
+
+configure_file ("${CMAKE_CURRENT_SOURCE_DIR}/runNepomukTest.sh.in"
+                "${CMAKE_CURRENT_BINARY_DIR}/runNepomukTest.sh"
+                IMMEDIATE @ONLY
+)
+
+# Install the script
+install (FILES "${CMAKE_CURRENT_SOURCE_DIR}/run_in_new_dbus_session.sh"
+         DESTINATION "${NEPOMUK_TESTLIB_TOOLS_INSTALL_DIR}"
+         COMPONENT Devel
+)
+
+install (FILES "${CMAKE_CURRENT_BINARY_DIR}/with-nepomuk-sandbox.sh"
+         DESTINATION "${NEPOMUK_TESTLIB_TOOLS_INSTALL_DIR}"
+         COMPONENT Devel
+)
+
+install (FILES "${CMAKE_CURRENT_BINARY_DIR}/runNepomukTest.sh"
+         DESTINATION "${NEPOMUK_TESTLIB_TOOLS_INSTALL_DIR}"
+         COMPONENT Devel
+)
diff --git a/tools/runNepomukTest.sh.in b/tools/runNepomukTest.sh.in
new file mode 100644
index 0000000..2812e18
--- /dev/null
+++ b/tools/runNepomukTest.sh.in
@@ -0,0 +1,4 @@
+#!/bin/bash
+
+bash @NEPOMUK_TESTLIB_TOOLS_INSTALL_DIR@/run_in_new_dbus_session.sh bash \
@NEPOMUK_TESTLIB_TOOLS_INSTALL_DIR@/with-nepomuk-sandbox.sh $@ +                
\ No newline at end of file
diff --git a/tools/run_in_new_dbus_session.sh b/tools/run_in_new_dbus_session.sh
new file mode 100644
index 0000000..7e12c11
--- /dev/null
+++ b/tools/run_in_new_dbus_session.sh
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+# start the new dbus session bus and export the env variables it creates
+echo "Starting new DBus session..."
+eval `dbus-launch --sh-syntax --exit-with-session`
+
+# start the process that is to be run in this new session
+eval $@
diff --git a/tools/with-nepomuk-sandbox.sh.in b/tools/with-nepomuk-sandbox.sh.in
new file mode 100644
index 0000000..5763efe
--- /dev/null
+++ b/tools/with-nepomuk-sandbox.sh.in
@@ -0,0 +1,71 @@
+#!/bin/sh
+
+# create a new random kde home
+CNT=0
+KDEHOME=/tmp/kde_test_home_$CNT
+while [ -e $KDEHOME ]
+  do
+  let "CNT += 1"
+  KDEHOME=/tmp/kde_test_home_$CNT
+done
+
+export KDEHOME
+export KDETMP=$KDEHOME/tmp
+export KDEVARTMP=$KDEHOME/vartmp
+export KDESYCOCA=$KDETMP/ksycoca-test
+mkdir -p $KDEHOME
+mkdir -p $KDETMP
+mkdir -p $KDEVARTMP
+
+# Copy the nepomukserverrc into place
+mkdir -p $KDEHOME/share/config
+cp @NEPOMUK_TESTLIB_DATA_INSTALL_DIR@/nepomukserverrc $KDEHOME/share/config/
+
+# start kde basics
+echo "Starting new KDE session in $KDEHOME..."
+kbuildsycoca4 2> /dev/null
+kdeinit4 2> /dev/null
+qdbus org.kde.kded /kded org.kde.kded.loadSecondPhase 2> /dev/null
+echo "Started..."
+
+# Start the nepomuk server (which will automatically start other nepomuk services
+echo "Starting nepomukserver"
+nepomukserver 2> /dev/null
+
+function wait-for-nepomuk-service() {
+    echo "Waiting for $1 service to be initialized (this may take some time)..."
+    while [ ! `qdbus $1 /servicecontrol org.kde.nepomuk.ServiceControl.isInitialized \
2> /dev/null` ] +    do
+        sleep 1
+    done
+
+    while [ false = `qdbus $1 /servicecontrol \
org.kde.nepomuk.ServiceControl.isInitialized 2> /dev/null` ] +    do
+        sleep 1
+    done
+}
+
+wait-for-nepomuk-service "org.kde.NepomukStorage" 
+wait-for-nepomuk-service "org.kde.nepomuk.services.nepomukqueryservice" 
+# If you need to wait for other services to be ready before starting the test case, \
do that here. +
+# start the actual test
+echo "Starting test case..."
+eval $@
+
+# Shutdown the nepomuk server
+echo "Telling nepomukserver to quit (this may take some time)"
+qdbus org.kde.NepomukServer /nepomukserver org.kde.NepomukServer.quit > /dev/null
+
+# Wait for the nepomuk server to finish shutting down
+while [ `qdbus org.kde.NepomukServer /nepomukserver \
org.kde.nepomuk.NepomukServer.isNepomukEnabled 2> /dev/null` ] +do
+  sleep 1
+done
+
+# shutdown KDE
+echo "Shutting down KDE session..."
+kdeinit4_shutdown
+
+echo "Cleaning up temporary KDEHOME $KDEHOME"
+#rm -rf $KDEHOME


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

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