2 #include "tkvsdatabasepool.h"
7 #include <QtTest/QtTest>
8 #include <TAppSettings>
9 #include <TSystemGlobal>
10 #include <TStdErrSystemLogger>
11 #include <TWebApplication>
13 #include "tsqldatabasepool.h"
14 #include <TActionThread>
17 #include <TMultiplexingServer>
21 #define TF_TEST_MAIN(TestObject) TF_TEST_SQL_MAIN(TestObject, true);
23 #if QT_VERSION < 0x060000
26 #define TF_TEST_SQL_MAIN(TestObject, EnableTransactions) \
27 int main(int argc, char *argv[]) \
29 class Thread : public TActionThread { \
31 Thread() : TActionThread(0), returnCode(0) { } \
32 volatile int returnCode; \
37 setTransactionEnabled(EnableTransactions); \
39 returnCode = QTest::qExec(&obj, QCoreApplication::arguments()); \
40 commitTransactions(); \
41 for (QMap<int, TSqlTransaction>::iterator it = sqlDatabases.begin(); it != sqlDatabases.end(); ++it) { \
42 it.value().database().close(); \
44 for (QMap<int, TKvsDatabase>::iterator it = kvsDatabases.begin(); it != kvsDatabases.end(); ++it) { \
47 QEventLoop eventLoop; \
48 while (eventLoop.processEvents()) { \
52 TWebApplication app(argc, argv); \
53 QByteArray codecName = Tf::appSettings()->value(Tf::InternalEncoding).toByteArray(); \
54 QTextCodec *codec = QTextCodec::codecForName(codecName); \
55 QTextCodec::setCodecForLocale(codec); \
56 Tf::setupSystemLogger(new TStdErrSystemLogger); \
57 app.setDatabaseEnvironment("test"); \
58 TUrlRoute::instance(); \
59 TSqlDatabasePool::instance(); \
60 TKvsDatabasePool::instance(); \
61 INIT_MULTIPLEXING_SERVER(); \
65 _exit(thread.returnCode); \
66 return thread.returnCode; \
71 #define TF_TEST_SQL_MAIN(TestObject, EnableTransactions) \
72 int main(int argc, char *argv[]) \
74 class Thread : public TActionThread { \
76 Thread() : TActionThread(0), returnCode(0) { } \
77 volatile int returnCode; \
82 setTransactionEnabled(EnableTransactions); \
84 returnCode = QTest::qExec(&obj, QCoreApplication::arguments()); \
85 commitTransactions(); \
86 for (QMap<int, TSqlTransaction>::iterator it = sqlDatabases.begin(); it != sqlDatabases.end(); ++it) { \
87 it.value().database().close(); \
89 for (QMap<int, TKvsDatabase>::iterator it = kvsDatabases.begin(); it != kvsDatabases.end(); ++it) { \
92 QEventLoop eventLoop; \
93 while (eventLoop.processEvents()) { \
97 TWebApplication app(argc, argv); \
98 Tf::setupSystemLogger(new TStdErrSystemLogger); \
99 app.setDatabaseEnvironment("test"); \
100 TUrlRoute::instance(); \
101 TSqlDatabasePool::instance(); \
102 TKvsDatabasePool::instance(); \
103 INIT_MULTIPLEXING_SERVER(); \
107 _exit(thread.returnCode); \
108 return thread.returnCode; \
113 #if QT_VERSION < 0x060000
115 #define TF_TEST_SQLLESS_MAIN(TestObject) \
116 int main(int argc, char *argv[]) \
118 TWebApplication app(argc, argv); \
119 Tf::setupSystemLogger(new TStdErrSystemLogger); \
120 QByteArray codecName = Tf::appSettings()->value(Tf::InternalEncoding).toByteArray(); \
121 QTextCodec *codec = QTextCodec::codecForName(codecName); \
122 QTextCodec::setCodecForLocale(codec); \
124 return QTest::qExec(&tc, argc, argv); \
129 #define TF_TEST_SQLLESS_MAIN(TestObject) \
130 int main(int argc, char *argv[]) \
132 TWebApplication app(argc, argv); \
133 Tf::setupSystemLogger(new TStdErrSystemLogger); \
135 return QTest::qExec(&tc, argc, argv); \
142 #define INIT_MULTIPLEXING_SERVER() TMultiplexingServer::instantiate(0)
144 #define INIT_MULTIPLEXING_SERVER()