|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Unit test for mpenginefactory |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QSignalSpy> |
|
19 |
|
20 #include "unittest_mpenginefactory.h" |
|
21 |
|
22 // Do this so we can access all member variables. |
|
23 #define private public |
|
24 #include "mpenginefactory.h" |
|
25 #undef private |
|
26 |
|
27 /*! |
|
28 Make our test case a stand-alone executable that runs all the test functions. |
|
29 */ |
|
30 int main(int argc, char *argv[]) |
|
31 { |
|
32 QApplication app(argc, argv); |
|
33 |
|
34 TestMpEngineFactory tv; |
|
35 |
|
36 if ( argc > 1 ) { |
|
37 return QTest::qExec( &tv, argc, argv); |
|
38 } |
|
39 else { |
|
40 char *pass[3]; |
|
41 pass[0] = argv[0]; |
|
42 pass[1] = "-o"; |
|
43 pass[2] = "c:\\data\\unittest_mpenginefactory.txt"; |
|
44 |
|
45 return QTest::qExec(&tv, 3, pass); |
|
46 } |
|
47 } |
|
48 |
|
49 TestMpEngineFactory::TestMpEngineFactory() |
|
50 : mTest(0) |
|
51 { |
|
52 } |
|
53 |
|
54 TestMpEngineFactory::~TestMpEngineFactory() |
|
55 { |
|
56 } |
|
57 |
|
58 /*! |
|
59 Called before the first testfunction is executed. |
|
60 */ |
|
61 void TestMpEngineFactory::initTestCase() |
|
62 { |
|
63 } |
|
64 |
|
65 /*! |
|
66 Called after the last testfunction was executed. |
|
67 */ |
|
68 void TestMpEngineFactory::cleanupTestCase() |
|
69 { |
|
70 } |
|
71 |
|
72 /*! |
|
73 Called before each testfunction is executed. |
|
74 */ |
|
75 void TestMpEngineFactory::init() |
|
76 { |
|
77 |
|
78 } |
|
79 |
|
80 /*! |
|
81 Called after every testfunction. |
|
82 */ |
|
83 void TestMpEngineFactory::cleanup() |
|
84 { |
|
85 |
|
86 } |
|
87 |
|
88 |
|
89 void TestMpEngineFactory::testInstance() |
|
90 { |
|
91 mTest = MpEngineFactory::instance(); |
|
92 QVERIFY( mTest != 0 ); |
|
93 MpEngineFactory *factory = MpEngineFactory::instance(); |
|
94 QVERIFY( mTest == factory ); |
|
95 } |
|
96 |
|
97 |
|
98 void TestMpEngineFactory::testCreateSharedEngine() |
|
99 { |
|
100 MpEngine *sharedEngine = MpEngineFactory::createSharedEngine(); |
|
101 QVERIFY( sharedEngine != 0 ); |
|
102 MpEngine *engine = MpEngineFactory::createSharedEngine(); |
|
103 QVERIFY( sharedEngine == engine ); |
|
104 |
|
105 delete MpEngineFactory::instance()->mSharedEngine; |
|
106 MpEngineFactory::instance()->mSharedEngine = 0; |
|
107 } |
|
108 |
|
109 void TestMpEngineFactory::testCreateIsolatedEngine() |
|
110 { |
|
111 MpEngine *engineOne = MpEngineFactory::createIsolatedEngine( MpEngine::StandAlone ); |
|
112 QVERIFY( engineOne != 0 ); |
|
113 MpEngine *engineTwo = MpEngineFactory::createIsolatedEngine( MpEngine::StandAlone ); |
|
114 QVERIFY( engineTwo != 0 ); |
|
115 QVERIFY( engineOne != engineTwo ); |
|
116 QVERIFY( MpEngineFactory::instance()->mEngines.count() == 2 ); |
|
117 |
|
118 MpEngine *ptr; |
|
119 foreach ( ptr, MpEngineFactory::instance()->mEngines ) { |
|
120 delete ptr; |
|
121 ptr = 0; |
|
122 } |
|
123 // This might be a potential bug in MpEngineFactory, need to call clear in close() function |
|
124 MpEngineFactory::instance()->mEngines.clear(); |
|
125 } |
|
126 |
|
127 void TestMpEngineFactory::testSharedEngine() |
|
128 { |
|
129 MpEngine *sharedEngine = MpEngineFactory::createSharedEngine(); |
|
130 QVERIFY( sharedEngine != 0 ); |
|
131 MpEngine *engine = MpEngineFactory::sharedEngine(); |
|
132 QVERIFY( sharedEngine == engine ); |
|
133 } |
|
134 |
|
135 void TestMpEngineFactory::testClose() |
|
136 { |
|
137 MpEngine *sharedEngine = MpEngineFactory::createSharedEngine(); |
|
138 MpEngine *engineOne = MpEngineFactory::createIsolatedEngine( MpEngine::StandAlone ); |
|
139 MpEngine *engineTwo = MpEngineFactory::createIsolatedEngine( MpEngine::StandAlone ); |
|
140 |
|
141 MpEngineFactory::close(); |
|
142 MpEngineFactory::instance()->mEngines.clear(); |
|
143 QVERIFY( MpEngineFactory::instance()->mSharedEngine == 0 ); |
|
144 } |
|
145 |
|
146 |
|
147 // End of file |