/usr/include/akonadi/qtest_akonadi.h is in kdepimlibs5-dev 4:4.13.0-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | /* This file is based on qtest_kde.h from kdelibs
Copyright (C) 2006 David Faure <faure@kde.org>
Copyright (C) 2009 Volker Krause <vkrause@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 version 2 as published by the Free Software Foundation.
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 QTEST_AKONADI_H
#define QTEST_AKONADI_H
#include <qtest_kde.h>
#include <akonadi/agentinstance.h>
#include <akonadi/agentmanager.h>
#include <klocale.h>
/**
* \short Akonadi Replacement for QTEST_MAIN from QTestLib
*
* This macro should be used for classes that run inside the Akonadi Testrunner.
* So instead of writing QTEST_MAIN( TestClass ) you write
* QTEST_AKONADIMAIN( TestClass, GUI ).
*
* \param TestObject The class you use for testing.
* \param flags one of KDEMainFlag. This is passed to the QApplication constructor.
*
* \see KDEMainFlag
* \see QTestLib
* \see QTEST_KDEMAIN
*/
#define QTEST_AKONADIMAIN(TestObject, flags) \
int main(int argc, char *argv[]) \
{ \
setenv( "LC_ALL", "C", 1); \
unsetenv( "KDE_COLOR_DEBUG" ); \
KAboutData aboutData( QByteArray( "qttest" ), QByteArray(), ki18n( "KDE Test Program" ), QByteArray( "version" ) ); \
KDEMainFlags mainFlags = flags; \
KComponentData cData(&aboutData); \
QApplication app( argc, argv, (mainFlags & GUI) != 0 ); \
app.setApplicationName( QLatin1String( "qttest" ) ); \
qRegisterMetaType<KUrl>(); /*as done by kapplication*/ \
qRegisterMetaType<KUrl::List>(); \
TestObject tc; \
KGlobal::ref(); /* don't quit qeventloop after closing a mainwindow */ \
return QTest::qExec( &tc, argc, argv ); \
}
namespace AkonadiTest {
/**
* Checks that the test is running in the proper test environment
*/
void checkTestIsIsolated() {
Q_ASSERT_X( !qgetenv( "TESTRUNNER_DB_ENVIRONMENT" ).isEmpty(),
"AkonadiTest::checkTestIsIsolated",
"This test must be run using ctest, in order to use the testrunner environment. Aborting, to avoid messing up your real akonadi" );
}
/**
* Switch all resources offline to reduce interference from them
*/
void setAllResourcesOffline() {
// switch all resources offline to reduce interference from them
foreach ( Akonadi::AgentInstance agent, Akonadi::AgentManager::self()->instances() ) //krazy:exclude=foreach
agent.setIsOnline( false );
}
} // namespace
/**
* Runs an Akonadi::Job synchronously and aborts if the job failed.
* Similar to QVERIFY( job->exec() ) but includes the job error message
* in the output in case of a failure.
*/
#define AKVERIFYEXEC( job ) \
QVERIFY2( job->exec(), job->errorString().toUtf8().constData() )
// Taken from Qt 5:
#if QT_VERSION < 0x050000
// Will try to wait for the expression to become true while allowing event processing
#define QTRY_VERIFY(__expr) \
do { \
const int __step = 50; \
const int __timeout = 5000; \
if ( !( __expr ) ) { \
QTest::qWait( 0 ); \
} \
for ( int __i = 0; __i < __timeout && !( __expr ); __i += __step ) { \
QTest::qWait( __step ); \
} \
QVERIFY( __expr ); \
} while ( 0 )
// Will try to wait for the comparison to become successful while allowing event processing
#define QTRY_COMPARE(__expr, __expected) \
do { \
const int __step = 50; \
const int __timeout = 5000; \
if ( ( __expr ) != ( __expected ) ) { \
QTest::qWait( 0 ); \
} \
for ( int __i = 0; __i < __timeout && ( ( __expr ) != ( __expected ) ); __i += __step ) { \
QTest::qWait( __step ); \
} \
QCOMPARE( __expr, __expected ); \
} while ( 0 )
#endif
#endif
|