|
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: |
|
15 * |
|
16 */ |
|
17 #include "unittest_commandlineparser.h" |
|
18 |
|
19 #include <QtTest/QtTest> |
|
20 #include <QVariant> |
|
21 #include <QString> |
|
22 #include <QStringList> |
|
23 |
|
24 #include "afactivities_global.h" |
|
25 #include "afcommandlineparser.h" |
|
26 |
|
27 void TestCommandLineParser::testActivityUriParsingAllOk() |
|
28 { |
|
29 QStringList commandLine; |
|
30 commandLine << "Appname" << "-activity" << QString("appto://DEADBEEF?%1=TestActivity1").arg(Af::KActivityUriNameKey); |
|
31 |
|
32 QVariantHash activityParams = QVariantHash(); |
|
33 QString name = QString(); |
|
34 Af::ActivationReason reason = Af::ActivationReasonNormal; |
|
35 |
|
36 AfCommandLineParser::parseCommandLine(commandLine, reason, name, activityParams); |
|
37 |
|
38 QCOMPARE(activityParams.count(), 1); |
|
39 QVERIFY(activityParams.contains(Af::KActivityUriNameKey)); |
|
40 QCOMPARE(activityParams.value(Af::KActivityUriNameKey), QVariant("TestActivity1")); |
|
41 QCOMPARE(name, QString("TestActivity1")); |
|
42 QCOMPARE(reason, Af::ActivationReasonActivity); |
|
43 } |
|
44 |
|
45 void TestCommandLineParser::testActivityUriParsingEmptyActivityName() |
|
46 { |
|
47 QStringList commandLine; |
|
48 commandLine << "Appname" << "-activity" << QString("appto://DEADBEEF?%1=&someKey=someValue").arg(Af::KActivityUriNameKey); |
|
49 |
|
50 QVariantHash activityParams = QVariantHash(); |
|
51 QString name = QString(); |
|
52 Af::ActivationReason reason = Af::ActivationReasonNormal; |
|
53 |
|
54 AfCommandLineParser::parseCommandLine(commandLine, reason, name, activityParams); |
|
55 |
|
56 QCOMPARE(activityParams.count(), 0); |
|
57 QVERIFY(name.isEmpty()); |
|
58 QCOMPARE(reason, Af::ActivationReasonNormal); |
|
59 } |
|
60 |
|
61 void TestCommandLineParser::testActivityUriParsingNoActivityName() |
|
62 { |
|
63 QStringList commandLine; |
|
64 commandLine << "Appname" << "-activity" << "appto://DEADBEEF?someKey=someValue"; |
|
65 |
|
66 QVariantHash activityParams = QVariantHash(); |
|
67 QString name = QString(); |
|
68 Af::ActivationReason reason = Af::ActivationReasonNormal; |
|
69 |
|
70 AfCommandLineParser::parseCommandLine(commandLine, reason, name, activityParams); |
|
71 |
|
72 QCOMPARE(activityParams.count(), 0); |
|
73 QVERIFY(name.isEmpty()); |
|
74 QCOMPARE(reason, Af::ActivationReasonNormal); |
|
75 } |
|
76 |
|
77 void TestCommandLineParser::testActivityUriParsingNoArgumentAfterMarker() |
|
78 { |
|
79 QStringList commandLine; |
|
80 commandLine << "Appname" << "-activity"; |
|
81 |
|
82 QVariantHash activityParams = QVariantHash(); |
|
83 QString name = QString(); |
|
84 Af::ActivationReason reason = Af::ActivationReasonNormal; |
|
85 |
|
86 AfCommandLineParser::parseCommandLine(commandLine, reason, name, activityParams); |
|
87 |
|
88 QCOMPARE(activityParams.count(), 0); |
|
89 QVERIFY(name.isEmpty()); |
|
90 QCOMPARE(reason, Af::ActivationReasonNormal); |
|
91 } |
|
92 |
|
93 void TestCommandLineParser::testActivityUriParsingNoMarker() |
|
94 { |
|
95 QStringList commandLine; |
|
96 commandLine << "Appname"; |
|
97 |
|
98 QVariantHash activityParams = QVariantHash(); |
|
99 QString name = QString(); |
|
100 Af::ActivationReason reason = Af::ActivationReasonNormal; |
|
101 |
|
102 AfCommandLineParser::parseCommandLine(commandLine, reason, name, activityParams); |
|
103 |
|
104 QCOMPARE(activityParams.count(), 0); |
|
105 QVERIFY(name.isEmpty()); |
|
106 QCOMPARE(reason, Af::ActivationReasonNormal); |
|
107 } |
|
108 |
|
109 void TestCommandLineParser::testActivityUriParsingNoUriAfterMarker() |
|
110 { |
|
111 QStringList commandLine; |
|
112 commandLine << "Appname"<< "-activity" << "adsasdasd"; |
|
113 |
|
114 QVariantHash activityParams = QVariantHash(); |
|
115 QString name = QString(); |
|
116 Af::ActivationReason reason = Af::ActivationReasonNormal; |
|
117 |
|
118 AfCommandLineParser::parseCommandLine(commandLine, reason, name, activityParams); |
|
119 |
|
120 QCOMPARE(activityParams.count(), 0); |
|
121 QVERIFY(name.isEmpty()); |
|
122 QCOMPARE(reason, Af::ActivationReasonNormal); |
|
123 } |
|
124 |
|
125 void TestCommandLineParser::testNormalStartParsingEmpty() |
|
126 { |
|
127 QStringList commandLine; |
|
128 commandLine << "Appname"; |
|
129 |
|
130 QVariantHash activityParams = QVariantHash(); |
|
131 QString name = QString(); |
|
132 Af::ActivationReason reason = Af::ActivationReasonNormal; |
|
133 |
|
134 AfCommandLineParser::parseCommandLine(commandLine, reason, name, activityParams); |
|
135 |
|
136 QCOMPARE(activityParams.count(), 0); |
|
137 QVERIFY(name.isEmpty()); |
|
138 QCOMPARE(reason, Af::ActivationReasonNormal); |
|
139 } |
|
140 |
|
141 void TestCommandLineParser::testNormalStartParsingSomeParameters() |
|
142 { |
|
143 QStringList commandLine; |
|
144 commandLine << "Appname" << "test1" << "test2"; |
|
145 |
|
146 QVariantHash activityParams = QVariantHash(); |
|
147 QString name = QString(); |
|
148 Af::ActivationReason reason = Af::ActivationReasonNormal; |
|
149 |
|
150 AfCommandLineParser::parseCommandLine(commandLine, reason, name, activityParams); |
|
151 |
|
152 QCOMPARE(activityParams.count(), 0); |
|
153 QVERIFY(name.isEmpty()); |
|
154 QCOMPARE(reason, Af::ActivationReasonNormal); |
|
155 } |
|
156 |
|
157 void TestCommandLineParser::testNormalStartParsingOneParameter() |
|
158 { |
|
159 QStringList commandLine; |
|
160 commandLine << "Appname" << "test1%&^test2"; |
|
161 |
|
162 QVariantHash activityParams = QVariantHash(); |
|
163 QString name = QString(); |
|
164 Af::ActivationReason reason = Af::ActivationReasonNormal; |
|
165 |
|
166 AfCommandLineParser::parseCommandLine(commandLine, reason, name, activityParams); |
|
167 |
|
168 QCOMPARE(activityParams.count(), 0); |
|
169 QVERIFY(name.isEmpty()); |
|
170 QCOMPARE(reason, Af::ActivationReasonNormal); |
|
171 } |
|
172 |
|
173 void TestCommandLineParser::testServiceParsing() |
|
174 { |
|
175 QStringList commandLine; |
|
176 commandLine << "Appname " << "service=yes" << "intf=IntName" << "oper=Operation"; |
|
177 |
|
178 QVariantHash activityParams = QVariantHash(); |
|
179 QString name = QString(); |
|
180 Af::ActivationReason reason = Af::ActivationReasonNormal; |
|
181 |
|
182 AfCommandLineParser::parseCommandLine(commandLine, reason, name, activityParams); |
|
183 |
|
184 QCOMPARE(activityParams.count(), 2); |
|
185 QCOMPARE(activityParams.value("oper"), QVariant("Operation")); |
|
186 QCOMPARE(name, QString("IntName")); |
|
187 QCOMPARE(reason, Af::ActivationReasonService); |
|
188 } |
|
189 |
|
190 void TestCommandLineParser::testServiceParsingEmbedded() |
|
191 { |
|
192 QStringList commandLine; |
|
193 commandLine << "Appname " << "embedded=yes" << "service=yes" << "intf=IntName" << "oper=Operation"; |
|
194 |
|
195 QVariantHash activityParams = QVariantHash(); |
|
196 QString name = QString(); |
|
197 Af::ActivationReason reason = Af::ActivationReasonNormal; |
|
198 |
|
199 AfCommandLineParser::parseCommandLine(commandLine, reason, name, activityParams); |
|
200 |
|
201 QCOMPARE(activityParams.count(), 3); |
|
202 QCOMPARE(activityParams.value("oper"), QVariant("Operation")); |
|
203 QCOMPARE(activityParams.value("embedded"), QVariant(true)); |
|
204 QCOMPARE(name, QString("IntName")); |
|
205 QCOMPARE(reason, Af::ActivationReasonService); |
|
206 } |