author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 11:15:19 +0300 | |
branch | RCL_3 |
changeset 11 | 25a739ee40f4 |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
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 |
#include <QtTest/QtTest> |
|
42 |
||
43 |
#ifndef QT_NO_BUILD_TOOLS |
|
44 |
||
45 |
#include <QtCore/QFileInfo> |
|
46 |
#include <QtSql/QSqlDatabase> |
|
47 |
#include <QtSql/QSqlQuery> |
|
48 |
||
49 |
#include <QtHelp/private/qhelpgenerator_p.h> |
|
50 |
#include <QtHelp/private/qhelpprojectdata_p.h> |
|
51 |
||
52 |
class tst_QHelpGenerator : public QObject |
|
53 |
{ |
|
54 |
Q_OBJECT |
|
55 |
||
56 |
private slots: |
|
57 |
void initTestCase(); |
|
58 |
void generateHelp(); |
|
59 |
||
60 |
private: |
|
61 |
void checkNamespace(); |
|
62 |
void checkFilters(); |
|
63 |
void checkIndices(); |
|
64 |
void checkFiles(); |
|
65 |
void checkMetaData(); |
|
66 |
||
67 |
QString m_outputFile; |
|
68 |
QSqlQuery *m_query; |
|
69 |
}; |
|
70 |
||
71 |
void tst_QHelpGenerator::initTestCase() |
|
72 |
{ |
|
73 |
QString path = QLatin1String(SRCDIR); |
|
74 |
m_outputFile = path + QLatin1String("/data/test.qch"); |
|
75 |
if (QFile::exists(m_outputFile)) { |
|
76 |
QDir d; |
|
77 |
if (!d.remove(m_outputFile)) |
|
78 |
QFAIL("Cannot remove old output file!"); |
|
79 |
} |
|
80 |
} |
|
81 |
||
82 |
void tst_QHelpGenerator::generateHelp() |
|
83 |
{ |
|
84 |
// defined in profile |
|
85 |
QString path = QLatin1String(SRCDIR); |
|
86 |
||
87 |
QString inputFile(path + "/data/test.qhp"); |
|
88 |
QHelpProjectData data; |
|
89 |
if (!data.readData(inputFile)) |
|
90 |
QFAIL("Cannot read qthp file!"); |
|
91 |
||
92 |
QHelpGenerator generator; |
|
93 |
QCOMPARE(generator.generate(&data, m_outputFile), true); |
|
94 |
||
95 |
{ |
|
96 |
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", "testdb"); |
|
97 |
db.setDatabaseName(m_outputFile); |
|
98 |
if (!db.open()) { |
|
99 |
QSqlDatabase::removeDatabase("testdb"); |
|
100 |
QFAIL("Created database seems to be corrupt!"); |
|
101 |
} |
|
102 |
m_query = new QSqlQuery(db); |
|
103 |
checkNamespace(); |
|
104 |
checkFilters(); |
|
105 |
checkIndices(); |
|
106 |
checkFiles(); |
|
107 |
checkMetaData(); |
|
108 |
||
109 |
m_query->clear(); |
|
110 |
delete m_query; |
|
111 |
} |
|
112 |
QSqlDatabase::removeDatabase("testdb"); |
|
113 |
||
114 |
// check if db is still in use... |
|
115 |
initTestCase(); |
|
116 |
} |
|
117 |
||
118 |
void tst_QHelpGenerator::checkNamespace() |
|
119 |
{ |
|
120 |
m_query->exec("SELECT Id, Name FROM NamespaceTable"); |
|
121 |
if (m_query->next() |
|
122 |
&& m_query->value(1).toString() == QLatin1String("trolltech.com.1_0_0.test")) |
|
123 |
return; |
|
124 |
QFAIL("Namespace Error!"); |
|
125 |
} |
|
126 |
||
127 |
void tst_QHelpGenerator::checkFilters() |
|
128 |
{ |
|
129 |
m_query->exec("SELECT COUNT(Id) FROM FilterAttributeTable"); |
|
130 |
if (!m_query->next() || m_query->value(0).toInt() != 3) |
|
131 |
QFAIL("FilterAttribute Error!"); |
|
132 |
||
133 |
m_query->exec("SELECT a.Name FROM FilterAttributeTable a, FilterTable b, " |
|
134 |
"FilterNameTable c WHERE c.Id=b.NameId AND b.FilterAttributeID=a.Id " |
|
135 |
"AND c.Name=\'Custom Filter 2\'"); |
|
136 |
QStringList lst; |
|
137 |
while (m_query->next()) |
|
138 |
lst.append(m_query->value(0).toString()); |
|
139 |
if (!lst.contains("test") || !lst.contains("filter2")) |
|
140 |
QFAIL("FilterAttribute Error!"); |
|
141 |
} |
|
142 |
||
143 |
void tst_QHelpGenerator::checkIndices() |
|
144 |
{ |
|
145 |
m_query->exec("SELECT a.Name, b.Anchor FROM FileNameTable a, " |
|
146 |
"IndexTable b, IndexFilterTable c, FilterAttributeTable d " |
|
147 |
"WHERE a.FileID=b.FileId AND b.Id=c.IndexId " |
|
148 |
"AND c.FilterAttributeId=d.Id AND d.Name=\'filter1\' AND b.Name=\'foo\'"); |
|
149 |
if (!m_query->next() || m_query->value(0).toString() != QLatin1String("test.html") |
|
150 |
|| m_query->value(1).toString() != QLatin1String("foo")) |
|
151 |
QFAIL("Index Error!"); |
|
152 |
||
153 |
/* |
|
154 |
m_query->exec("SELECT COUNT(DISTINCT Id) FROM IndexItemTable"); |
|
155 |
if (!m_query->next() || m_query->value(0).toInt() != 7) |
|
156 |
QFAIL("Index Error!"); |
|
157 |
*/ |
|
158 |
||
159 |
m_query->exec("SELECT COUNT(a.Id) FROM IndexTable a, " |
|
160 |
"IndexFilterTable b, FilterAttributeTable c WHERE a.Id=b.IndexId " |
|
161 |
"AND b.FilterAttributeId=c.Id AND c.Name=\'filter2\'"); |
|
162 |
if (!m_query->next() || m_query->value(0).toInt() != 3) |
|
163 |
QFAIL("Index Error!"); |
|
164 |
} |
|
165 |
||
166 |
void tst_QHelpGenerator::checkFiles() |
|
167 |
{ |
|
168 |
m_query->exec("SELECT COUNT(a.FileId) FROM FileNameTable a, FolderTable b " |
|
169 |
"WHERE a.FolderId=b.Id AND b.Name=\'testFolder\'"); |
|
170 |
if (!m_query->next() || m_query->value(0).toInt() != 6) |
|
171 |
QFAIL("File Error!"); |
|
172 |
||
173 |
QStringList lst; |
|
174 |
lst << "classic.css" << "test.html" << "people.html" << "sub/about.html"; |
|
175 |
m_query->exec("SELECT a.Name FROM FileNameTable a, FileFilterTable b, " |
|
176 |
"FilterAttributeTable c WHERE c.Id=b.FilterAttributeId " |
|
177 |
"AND b.FileId=a.FileID AND c.Name=\'filter1\'"); |
|
178 |
while (m_query->next()) |
|
179 |
lst.removeAll(m_query->value(0).toString()); |
|
180 |
QCOMPARE(lst.count(), 0); |
|
181 |
||
182 |
QMap<int, QStringList> fileAtts; |
|
183 |
m_query->exec("SELECT a.Id, b.Name FROM FileAttributeSetTable a, " |
|
184 |
"FilterAttributeTable b WHERE a.FilterAttributeId=b.Id"); |
|
185 |
while (m_query->next()) { |
|
186 |
int id = m_query->value(0).toInt(); |
|
187 |
if (!fileAtts.contains(id)) |
|
188 |
fileAtts.insert(id, QStringList()); |
|
189 |
fileAtts[id].append(m_query->value(1).toString()); |
|
190 |
} |
|
191 |
QCOMPARE(fileAtts.count(), 2); |
|
192 |
QCOMPARE((bool)fileAtts.value(1).contains("test"), true); |
|
193 |
QCOMPARE((bool)fileAtts.value(1).contains("filter1"), true); |
|
194 |
QCOMPARE((bool)fileAtts.value(1).contains("filter2"), false); |
|
195 |
QCOMPARE((bool)fileAtts.value(2).contains("test"), true); |
|
196 |
QCOMPARE((bool)fileAtts.value(2).contains("filter2"), true); |
|
197 |
} |
|
198 |
||
199 |
void tst_QHelpGenerator::checkMetaData() |
|
200 |
{ |
|
201 |
m_query->exec("SELECT COUNT(Value) FROM MetaDataTable"); |
|
202 |
if (!m_query->next()) |
|
203 |
QFAIL("Meta Data Error"); |
|
204 |
QCOMPARE(m_query->value(0).toInt(), 4); |
|
205 |
||
206 |
m_query->exec("SELECT Value FROM MetaDataTable WHERE Name=\'author\'"); |
|
207 |
if (!m_query->next()) |
|
208 |
QFAIL("Meta Data Error"); |
|
209 |
QCOMPARE(m_query->value(0).toString(), QString("Nokia Corporation and/or its subsidiary(-ies)")); |
|
210 |
} |
|
211 |
||
212 |
QTEST_MAIN(tst_QHelpGenerator) |
|
213 |
#include "tst_qhelpgenerator.moc" |
|
214 |
||
215 |
#else // QT_NO_BUILD_TOOLS |
|
216 |
QTEST_NOOP_MAIN |
|
217 |
#endif |
|
218 |