TreeFrogFramework 2.10
Loading...
Searching...
No Matches
tftest.h
Go to the documentation of this file.
1#pragma once
2#include "tkvsdatabasepool.h"
3#include "turlroute.h"
4#include <QByteArray>
5#include <QEventLoop>
6#include <QObject>
7#include <QtTest/QtTest>
8#include <TAppSettings>
9#include <TSystemGlobal>
10#include <TStdErrSystemLogger>
11#include <TWebApplication>
12#ifdef QT_SQL_LIB
13#include "tsqldatabasepool.h"
14#include <TActionThread>
15#endif
16#ifdef Q_OS_LINUX
17#include <TMultiplexingServer>
18#endif
19
20
21#define TF_TEST_MAIN(TestObject) TF_TEST_SQL_MAIN(TestObject, true);
22
23#define TF_TEST_SQL_MAIN(TestObject, EnableTransactions) \
24 int main(int argc, char *argv[]) \
25 { \
26 class Thread : public TActionThread { \
27 public: \
28 Thread() : TActionThread(0), returnCode(0) { } \
29 volatile int returnCode; \
30 \
31 protected: \
32 virtual void run() \
33 { \
34 setTransactionEnabled(EnableTransactions); \
35 TestObject obj; \
36 returnCode = QTest::qExec(&obj, QCoreApplication::arguments()); \
37 commitTransactions(); \
38 for (QMap<int, TSqlTransaction>::iterator it = sqlDatabases.begin(); it != sqlDatabases.end(); ++it) { \
39 it.value().database().close(); /* close SQL database */ \
40 } \
41 for (QMap<int, TKvsDatabase>::iterator it = kvsDatabases.begin(); it != kvsDatabases.end(); ++it) { \
42 it.value().close(); /* close KVS database */ \
43 } \
44 QEventLoop eventLoop; \
45 while (eventLoop.processEvents()) { \
46 } \
47 } \
48 }; \
49 TWebApplication app(argc, argv); \
50 Tf::setupSystemLogger(new TStdErrSystemLogger); \
51 app.setDatabaseEnvironment("test"); \
52 TUrlRoute::instance(); \
53 TSqlDatabasePool::instance(); \
54 TKvsDatabasePool::instance(); \
55 INIT_MULTIPLEXING_SERVER(); \
56 Thread thread; \
57 thread.start(); \
58 thread.wait(); \
59 _exit(thread.returnCode); \
60 return thread.returnCode; \
61 }
62
63
64#define TF_TEST_SQLLESS_MAIN(TestObject) \
65 int main(int argc, char *argv[]) \
66 { \
67 TWebApplication app(argc, argv); \
68 Tf::setupSystemLogger(new TStdErrSystemLogger); \
69 TestObject tc; \
70 return QTest::qExec(&tc, argc, argv); \
71 }
72
73
74#ifdef Q_OS_LINUX
75#define INIT_MULTIPLEXING_SERVER() TMultiplexingServer::instantiate(0)
76#else
77#define INIT_MULTIPLEXING_SERVER()
78#endif