|
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 #include "qsfwtestutil.h" |
|
42 |
|
43 #include <QDir> |
|
44 #include <QFileInfoList> |
|
45 #include <QFile> |
|
46 #include <QSettings> |
|
47 #include <QDebug> |
|
48 #include <QCoreApplication> |
|
49 |
|
50 void QSfwTestUtil::setupTempUserDb() |
|
51 { |
|
52 QSettings::setUserIniPath(tempUserDbDir()); |
|
53 } |
|
54 |
|
55 void QSfwTestUtil::setupTempSystemDb() |
|
56 { |
|
57 QSettings::setSystemIniPath(tempSystemDbDir()); |
|
58 } |
|
59 |
|
60 void QSfwTestUtil::removeTempUserDb() |
|
61 { |
|
62 removeDirectory(tempUserDbDir()); |
|
63 } |
|
64 |
|
65 void QSfwTestUtil::removeTempSystemDb() |
|
66 { |
|
67 removeDirectory(tempSystemDbDir()); |
|
68 } |
|
69 |
|
70 QString QSfwTestUtil::tempUserDbDir() |
|
71 { |
|
72 return tempSettingsPath("__user__"); |
|
73 } |
|
74 |
|
75 QString QSfwTestUtil::tempSystemDbDir() |
|
76 { |
|
77 return tempSettingsPath("__system__"); |
|
78 } |
|
79 |
|
80 QString QSfwTestUtil::userDirectory() |
|
81 { |
|
82 return tempSettingsPath("__user__/"); |
|
83 } |
|
84 |
|
85 QString QSfwTestUtil::systemDirectory() |
|
86 { |
|
87 return tempSettingsPath("__system__/"); |
|
88 } |
|
89 |
|
90 QString QSfwTestUtil::tempSettingsPath(const char *path) |
|
91 { |
|
92 // Temporary path for files that are specified explictly in the constructor. |
|
93 //QString tempPath = QDir::tempPath(); |
|
94 QString tempPath = QCoreApplication::applicationDirPath(); |
|
95 if (tempPath.endsWith("/")) |
|
96 tempPath.truncate(tempPath.size() - 1); |
|
97 return QDir::toNativeSeparators(tempPath + "/QtServiceFramework_tests/" + QLatin1String(path)); |
|
98 } |
|
99 |
|
100 void QSfwTestUtil::removeDirectory(const QString &path) |
|
101 { |
|
102 QDir dir(path); |
|
103 QFileInfoList fileList = dir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllDirs | QDir::Files); |
|
104 foreach(QFileInfo file, fileList) { |
|
105 if(file.isFile()) { |
|
106 QFile::remove (file.canonicalFilePath()); |
|
107 } |
|
108 if(file.isDir()) { |
|
109 QFile::Permissions perms = QFile::permissions(file.canonicalFilePath()); |
|
110 perms = perms | QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner; |
|
111 QFile::setPermissions(file.canonicalFilePath(), perms); |
|
112 removeDirectory(file.canonicalFilePath()); |
|
113 } |
|
114 } |
|
115 dir.rmpath(path); |
|
116 } |
|
117 |
|
118 #if defined(Q_OS_SYMBIAN) |
|
119 #include <e32base.h> |
|
120 void QSfwTestUtil::removeDatabases_symbian() |
|
121 { |
|
122 #if defined(__WINS__) && !defined(SYMBIAN_EMULATOR_SUPPORTS_PERPROCESS_WSD) |
|
123 QDir dir("C:/Data/temp/QtServiceFW"); |
|
124 #else |
|
125 TFindServer findServer(_L("!qsfwdatabasemanagerserver")); |
|
126 TFullName name; |
|
127 if (findServer.Next(name) == KErrNone) |
|
128 { |
|
129 RProcess dbServer; |
|
130 if (dbServer.Open(_L("qsfwdatabasemanagerserver")) == KErrNone) |
|
131 { |
|
132 dbServer.Kill(KErrNone); |
|
133 dbServer.Close(); |
|
134 } |
|
135 } |
|
136 |
|
137 QDir dir("c:/private/2002AC7F"); |
|
138 #endif |
|
139 |
|
140 QString qtVersion(qVersion()); |
|
141 qtVersion = qtVersion.left(qtVersion.size() - 2); //strip off patch version |
|
142 QString dbIdentifier = "_system"; |
|
143 QString dbName = QString("QtServiceFramework_") + qtVersion + dbIdentifier + QLatin1String(".db"); |
|
144 QFile::remove(QDir::toNativeSeparators(dir.path() + QDir::separator() + dbName)); |
|
145 } |
|
146 #endif |