|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include <QtTest/QtTest> |
|
43 #include "../../../tools/icheck/ichecklib.h" |
|
44 #include <qmobilityglobal.h> |
|
45 #include <QDir> |
|
46 #include <QFile> |
|
47 #include <QFileInfo> |
|
48 #include <QProcess> |
|
49 #include <QString> |
|
50 #include <QStringList> |
|
51 #include <QDomDocument> |
|
52 #include <QDebug> |
|
53 |
|
54 #if defined(Q_OS_SYMBIAN) |
|
55 # define TESTDATA_DIR "." |
|
56 #endif |
|
57 |
|
58 //TESTED_CLASS= |
|
59 //TESTED_FILES= |
|
60 extern QStringList getQTIncludePath(); |
|
61 |
|
62 QString getTestFileFolder() |
|
63 { |
|
64 QString ret; |
|
65 ret = TESTDATA_DIR; |
|
66 ret += "/testdata"; |
|
67 QDir qdir(ret); |
|
68 if(!qdir.exists()) |
|
69 ret = ""; |
|
70 return ret; |
|
71 } |
|
72 |
|
73 //---- Test case class ---- |
|
74 class TestCase |
|
75 { |
|
76 public: |
|
77 TestCase(QDomNode& xmlnode); |
|
78 bool run(); |
|
79 QString getErrorMsg() { return errorMsg; } |
|
80 QString getTestName() { return testName; } |
|
81 private: |
|
82 bool loadXmlInformation(); |
|
83 private: |
|
84 QDomNode xmlNode; |
|
85 QString errorMsg; |
|
86 QString testName; |
|
87 QString iheader; |
|
88 QString header; |
|
89 QStringList expectedResult; |
|
90 }; |
|
91 |
|
92 TestCase::TestCase(QDomNode& xmlnode) |
|
93 : xmlNode(xmlnode) |
|
94 , errorMsg("") |
|
95 , testName("") |
|
96 , iheader("") |
|
97 , header("") |
|
98 { |
|
99 expectedResult.clear(); |
|
100 } |
|
101 |
|
102 bool TestCase::loadXmlInformation() |
|
103 { |
|
104 QDomNodeList nodeList = xmlNode.childNodes(); |
|
105 for(int i = 0; i < nodeList.count(); i++){ |
|
106 QDomNode nd = nodeList.at(i); |
|
107 if(nd.childNodes().count() > 0){ |
|
108 if(nd.nodeName() == "Name") |
|
109 testName = nd.firstChild().nodeValue(); |
|
110 else if(nd.nodeName() == "InterfaceHeader") |
|
111 iheader = getTestFileFolder() + "/" + nd.firstChild().nodeValue(); |
|
112 else if(nd.nodeName() == "CompareHeader") |
|
113 header = getTestFileFolder() + "/" + nd.firstChild().nodeValue(); |
|
114 else if(nd.nodeName() == "ExpectedResult"){ |
|
115 QDomNodeList chnodeList = nd.childNodes(); |
|
116 for(int b = 0; b < chnodeList.count(); b++){ |
|
117 QDomNode chnd = chnodeList.at(b); |
|
118 if(chnd.childNodes().size() > 0) |
|
119 expectedResult << chnd.firstChild().nodeValue(); |
|
120 } |
|
121 } |
|
122 } |
|
123 } |
|
124 |
|
125 // check if we have all informations |
|
126 QTextStream out(&errorMsg); |
|
127 if(testName.size() <= 0) |
|
128 out << "No test name defined. Error in Test.xml file!" << endl; |
|
129 if(iheader.size() <= 0) |
|
130 out << "No interface header defined. Error in Test.xml file!" << endl; |
|
131 if(header.size() <= 0) |
|
132 out << "No compare header defined. Error in Test.xml file!" << endl; |
|
133 if(errorMsg.size() > 0) |
|
134 return false; |
|
135 |
|
136 //check if the headers are available |
|
137 QFile ichfile(iheader); |
|
138 if (!ichfile.exists()){ |
|
139 out << iheader << " file not found on drive." << endl; |
|
140 } |
|
141 QFile chfile(header); |
|
142 if (!chfile.exists()){ |
|
143 out << header << " file not found on drive." << endl; |
|
144 } |
|
145 if(errorMsg.size() > 0) |
|
146 return false; |
|
147 |
|
148 return true; |
|
149 } |
|
150 |
|
151 bool TestCase::run() |
|
152 { |
|
153 QTextStream out(&errorMsg); |
|
154 if(loadXmlInformation()){ |
|
155 qDebug() << "Start: " << testName; |
|
156 //Start the test |
|
157 QString curpath = getTestFileFolder(); |
|
158 //Create FileInfos for the header files |
|
159 QFileInfo iFileInfo(iheader); |
|
160 QFileInfo chFileInfo(header); |
|
161 |
|
162 //Now create a list of the include path |
|
163 QString chIncludepath = chFileInfo.absolutePath(); |
|
164 QStringList chIncludepathlist; |
|
165 chIncludepathlist << chIncludepath; |
|
166 chIncludepathlist << getQTIncludePath(); |
|
167 |
|
168 QString iIncludepath = iFileInfo.absolutePath(); |
|
169 QStringList iIncludepathlist; |
|
170 iIncludepathlist << iIncludepath; |
|
171 |
|
172 //Create a list of all the soucre files they need to be parsed. |
|
173 //In our case it is just the header file |
|
174 QStringList chFilelist; |
|
175 chFilelist << chFileInfo.filePath(); |
|
176 |
|
177 QStringList iFilelist; |
|
178 iFilelist << iFileInfo.filePath(); |
|
179 |
|
180 ICheckLib i_ichecklib; |
|
181 i_ichecklib.ParseHeader(iIncludepathlist, iFilelist); |
|
182 |
|
183 ICheckLib ichecklib; |
|
184 ichecklib.ParseHeader(chIncludepathlist, chFilelist); |
|
185 |
|
186 ichecklib.check(i_ichecklib, ""); |
|
187 QStringList result = ichecklib.getErrorMsg(); |
|
188 if(result.count() != expectedResult.count()){ |
|
189 out << testName << " failed. Expected result line count doesn't equals to the result line count." << endl; |
|
190 return false; |
|
191 } |
|
192 bool ret = true; |
|
193 for(int i = 0; i < result.count(); i++){ |
|
194 QString leftcp = result[i].replace(" ",""); |
|
195 QString rightcp = expectedResult[i].replace(" ",""); |
|
196 if(leftcp != rightcp){ |
|
197 out << endl << "--- " << testName << " ---" << endl << " failed. Expected result line[" << (i + 1) << "] count doesn't equals to the result line count." << endl; |
|
198 ret = false; |
|
199 } |
|
200 } |
|
201 return ret; |
|
202 } |
|
203 return false; |
|
204 } |
|
205 //---- end Test case class ---- |
|
206 |
|
207 class tst_ICheck: public QObject |
|
208 { |
|
209 Q_OBJECT |
|
210 |
|
211 public: |
|
212 tst_ICheck(); |
|
213 virtual ~tst_ICheck(); |
|
214 |
|
215 private slots: |
|
216 void doTests(); |
|
217 void initTestCase(); |
|
218 }; |
|
219 |
|
220 tst_ICheck::tst_ICheck() |
|
221 { |
|
222 } |
|
223 |
|
224 tst_ICheck::~tst_ICheck() |
|
225 { |
|
226 } |
|
227 |
|
228 void tst_ICheck::initTestCase() |
|
229 { |
|
230 } |
|
231 |
|
232 void tst_ICheck::doTests() |
|
233 { |
|
234 QString msg; |
|
235 QString xmltestfile = getTestFileFolder(); |
|
236 xmltestfile += "/Test.xml"; |
|
237 QFile xmlfile(xmltestfile); |
|
238 bool failed = false; |
|
239 if (xmlfile.exists()){ |
|
240 QDomDocument document; |
|
241 if (document.setContent(&xmlfile)) { |
|
242 QDomElement rootnd = document.documentElement(); |
|
243 if(rootnd.isElement()){ |
|
244 QDomNodeList nodeList = rootnd.childNodes(); |
|
245 for(int i = 0; i < nodeList.count(); i++){ |
|
246 QDomNode nd = nodeList.at(i); |
|
247 TestCase test(nd); |
|
248 if(!test.run()){ |
|
249 QWARN(test.getErrorMsg().toLatin1()); |
|
250 failed = true; |
|
251 } |
|
252 } |
|
253 } |
|
254 } |
|
255 } |
|
256 else { |
|
257 QFAIL ( QString(xmltestfile + " file not found").toLatin1() ); |
|
258 } |
|
259 if(failed) |
|
260 QFAIL ( "Test failed, please read warnings!" ); |
|
261 } |
|
262 |
|
263 QTEST_MAIN(tst_ICheck) |
|
264 #include "tst_icheck.moc" |