22
22
23
23
#include " teststartupandbehavior.h"
24
24
#include " modules/services/startactionsengine.h"
25
+ #include " app.h"
26
+ #include " StartParams.h"
25
27
26
28
// --------
27
29
struct TestStartInvocationData {
28
30
public:
29
- _userType;
30
31
// --
31
- bool firstAccessCalled;
32
+ bool askUserTypePanel;
33
+ bool openGuidedPanel;
34
+ bool askVisDetailsTypePanel ;
35
+ bool showWelcome ;
36
+ bool openFile;
37
+ ApplicationData::EUserType panelUserType;
32
38
TestStartInvocationData ();
33
39
~TestStartInvocationData ();
34
40
};
35
41
36
42
TestStartInvocationData::TestStartInvocationData ()
37
43
{
38
- firstAccessCalled = false ;
44
+ askUserTypePanel = false ;
45
+ openGuidedPanel = false ;
46
+ askVisDetailsTypePanel = false ;
47
+ showWelcome = false ;
48
+ openFile = false ;
49
+ panelUserType = ApplicationData::UserTypeExpert;
39
50
}
40
51
41
52
TestStartInvocationData::~TestStartInvocationData ()
@@ -48,7 +59,8 @@ class FakeStartActionsExecutor : public StartActionsExecutor {
48
59
49
60
public:
50
61
TestStartInvocationData _data;
51
- FakeStartActionsExecutor ();
62
+ ApplicationData *_appData ;
63
+ FakeStartActionsExecutor (ApplicationData *appData);
52
64
virtual ~FakeStartActionsExecutor ();
53
65
54
66
virtual void startActionShowUserTypePanel ();
@@ -58,8 +70,9 @@ class FakeStartActionsExecutor : public StartActionsExecutor {
58
70
virtual void startActionLoadFile (const QString &fileName);
59
71
};
60
72
61
- FakeStartActionsExecutor::FakeStartActionsExecutor ()
73
+ FakeStartActionsExecutor::FakeStartActionsExecutor (ApplicationData *appData )
62
74
{
75
+ _appData = appData ;
63
76
}
64
77
65
78
FakeStartActionsExecutor::~FakeStartActionsExecutor ()
@@ -68,92 +81,204 @@ FakeStartActionsExecutor::~FakeStartActionsExecutor()
68
81
69
82
void FakeStartActionsExecutor::startActionShowUserTypePanel ()
70
83
{
71
- _data.firstAccessCalled = true ;
84
+ _data.askUserTypePanel = true ;
85
+ _appData->setUserType (_data.panelUserType );
72
86
}
87
+
73
88
bool FakeStartActionsExecutor::startActionShowGuidedOperationsPanel ()
74
89
{
75
- a
90
+ _data.openGuidedPanel = true ;
91
+ return true ;
76
92
}
93
+
77
94
void FakeStartActionsExecutor::startActionSetupFirstAccessForPreferences ()
78
95
{
79
- s
96
+ _data. askVisDetailsTypePanel = true ;
80
97
}
98
+
81
99
void FakeStartActionsExecutor::startActionTriggersWelcomeDialog ()
82
100
{
83
- s
101
+ _data. showWelcome = true ;
84
102
}
85
- void FakeStartActionsExecutor::startActionLoadFile (const QString &fileName)
103
+
104
+ void FakeStartActionsExecutor::startActionLoadFile (const QString & /* fileName*/ )
86
105
{
87
- s
106
+ _data. openFile = true ;
88
107
}
89
108
90
109
// -------
91
110
92
111
TestStartupAndBehavior::TestStartupAndBehavior ()
93
112
{
94
-
113
+ //
95
114
}
96
115
97
116
98
117
TestStartupAndBehavior::~TestStartupAndBehavior ()
99
118
{
100
-
119
+ //
101
120
}
102
121
103
122
bool TestStartupAndBehavior::testFast ()
104
123
{
105
124
return testUnit ();
106
125
}
107
126
127
+ /* *
128
+ Test User Argument Access Ask User TyPanel(s) Run
129
+ 0 Expert *** First Yes View DetailWelcome
130
+ 1 Expert Open File First Yes View DetailOpen File
131
+ 2 Expert *** Following No *** Welcome
132
+ 3 Expert Open File Following No *** Open File
133
+ 4 Basic *** First Yes Operations ***
134
+ 5 Basic Open File First Yes Operations Open File
135
+ 6 Basic *** Following No Operations ***
136
+ 7 Basic Open File Following No Operations Open File
137
+ */
108
138
bool TestStartupAndBehavior::testUnit ()
109
139
{
110
140
_testName = " testUnit" ;
111
- User Argument Access Ask User Type Panel (s) Run
112
-
113
- Expert *** First Yes View Details Welcome
114
- Expert Open File First Yes View Details Open File
115
- Expert *** Following No *** Welcome
116
- Expert Open File Following No *** Open File
117
- Basic *** First Yes Operations ***
118
- Basic Open File First Yes Operations Open File
119
- Basic *** Following No Operations ***
120
- Basic Open File Following No Operations Open File
121
-
122
-
123
- return error (" nyi" );
141
+ if (!checkStartupAction (" 0" , true , false , ApplicationData::UserTypeExpert,
142
+ true , false , true , true , false , ApplicationData::UserTypeExpert,
143
+ ApplicationData::UserTypeExpert )) {
144
+ return false ;
145
+ }
146
+ if (!checkStartupAction (" 1" , true , true , ApplicationData::UserTypeExpert,
147
+ true , false , true , false , true , ApplicationData::UserTypeExpert,
148
+ ApplicationData::UserTypeExpert )) {
149
+ return false ;
150
+ }
151
+ if (!checkStartupAction (" 2" , false , false , ApplicationData::UserTypeExpert,
152
+ false , false , false , false , true , ApplicationData::UserTypeExpert,
153
+ ApplicationData::UserTypeExpert )) {
154
+ return false ;
155
+ }
156
+ if (!checkStartupAction (" 3" , false , true , ApplicationData::UserTypeExpert,
157
+ false , false , false , true , false , ApplicationData::UserTypeExpert,
158
+ ApplicationData::UserTypeExpert )) {
159
+ return false ;
160
+ }
161
+ if (!checkStartupAction (" 4" , true , false , ApplicationData::UserTypeExpert,
162
+ true , true , false , false , false , ApplicationData::UserTypeGuided,
163
+ ApplicationData::UserTypeGuided )) {
164
+ return false ;
165
+ }
166
+ if (!checkStartupAction (" 5" , true , true , ApplicationData::UserTypeExpert,
167
+ true , true , false , false , true , ApplicationData::UserTypeGuided,
168
+ ApplicationData::UserTypeGuided )) {
169
+ return false ;
170
+ }
171
+ if (!checkStartupAction (" 6" , false , false , ApplicationData::UserTypeExpert,
172
+ false , true , false , false , false , ApplicationData::UserTypeGuided,
173
+ ApplicationData::UserTypeGuided )) {
174
+ return false ;
175
+ }
176
+ if (!checkStartupAction (" 7" , false , true , ApplicationData::UserTypeExpert,
177
+ false , true , false , false , true , ApplicationData::UserTypeGuided,
178
+ ApplicationData::UserTypeGuided )) {
179
+ return false ;
180
+ }
181
+ return true ;
124
182
}
125
183
126
- bool TestStartupAndBehavior::checkStartupAction (const bool setFirstAccess,
127
- const bool expectedFirstAccess )
184
+ bool TestStartupAndBehavior::checkStartupAction (
185
+ const QString &id,
186
+ // set values
187
+ const bool setFirstAccess, const bool setOpenFile, const ApplicationData::EUserType setUserType,
188
+ // -- expected
189
+ const bool expectedAskUserTypePanel, const bool expectedOpenGuidedPanel,
190
+ const bool expectedAskVisDetailsTypePanel, const bool expectedShowWelcome,
191
+ const bool expectedOpenFile, const ApplicationData::EUserType panelUserType,
192
+ // final values
193
+ const ApplicationData::EUserType checkFinalUserType )
128
194
{
195
+ _subTestName = id ;
129
196
App app;
130
- if (!app.initWitooutWIndow () ) {
197
+ if (!app.initNoWindow () ) {
131
198
return error (" Init" );
132
199
}
133
- TestStartInvocationData expected;
134
- expected.firstAccessCalled = expectedFirstAccess ;
135
- // ---
136
- FakeStartActionsExecutor executor;
200
+ if (!setFirstAccess){
201
+ app.data ()->fireUserFirstAccess ();
202
+ } else {
203
+ app.data ()->setUserType (setUserType);
204
+ }
205
+
137
206
// ----
138
- StartupParams startupParams;
207
+ StartParams startupParams;
208
+ if (setOpenFile) {
209
+ startupParams.type = StartParams::OpenFile;
210
+ startupParams.fileName = " test" ;
211
+ } else {
212
+ startupParams.type = StartParams::Nothing;
213
+ }
214
+ // ----
215
+ // check set values
216
+ if (!app.data ()->isUserFirstAccess () != setFirstAccess) {
217
+ return error (QString (" id:%1 wrong first access, expected %2" ).arg (id).arg (setFirstAccess));
218
+ }
219
+ if (!setFirstAccess) {
220
+ if (ApplicationData::UserTypeExpert == setUserType) {
221
+ if (app.data ()->isUserGuidedOperation ()) {
222
+ return error (QString (" id:%1 set user expert but not verified" ).arg (id));
223
+ }
224
+ } else if (ApplicationData::UserTypeGuided == setUserType) {
225
+ if (!app.data ()->isUserGuidedOperation ()) {
226
+ return error (QString (" id:%1 set user guided but not verified" ).arg (id));
227
+ }
228
+ } else {
229
+ return error (QString (" id:%1 invalid user type %2" ).arg (id).arg (setUserType));
230
+ }
231
+ }
232
+ // --
233
+ TestStartInvocationData expected;
234
+ expected.askUserTypePanel = expectedAskUserTypePanel;
235
+ expected.openGuidedPanel = expectedOpenGuidedPanel;
236
+ expected.askVisDetailsTypePanel = expectedAskVisDetailsTypePanel;
237
+ expected.showWelcome = expectedShowWelcome ;
238
+ expected.openFile = expectedOpenFile;
239
+ expected.panelUserType = panelUserType ;
139
240
// ----
140
- StartActionsEngine engine (app.data ());
241
+ FakeStartActionsExecutor executor (app.data ());
242
+ StartActionsEngine engine ( app.data (), &executor);
141
243
engine.execute (startupParams);
142
- return checkStartup (executor, expected);
244
+ if (!checkExpectedStartupResults (&executor._data , &expected)) {
245
+ return false ;
246
+ }
247
+ if (app.data ()->isUserFirstAccess ()) {
248
+ return error (QString (" id:%1 still first access" ).arg (id));
249
+ }
250
+
251
+ if (ApplicationData::UserTypeExpert == checkFinalUserType) {
252
+ if (app.data ()->isUserGuidedOperation ()) {
253
+ return error (QString (" id:%1 final expected user expert but not verified" ).arg (id));
254
+ }
255
+ } else if (ApplicationData::UserTypeGuided == checkFinalUserType) {
256
+ if (!app.data ()->isUserGuidedOperation ()) {
257
+ return error (QString (" id:%1 final set user guided but not verified" ).arg (id));
258
+ }
259
+ } else {
260
+ return error (QString (" id:%1 final invalid user type %2" ).arg (id).arg (setUserType));
261
+ }
262
+
263
+ return true ;
143
264
}
144
265
145
- bool TestStartupAndBehavior::checkStartup (TestStartInvocationData *obj, TestStartInvocationData *expected)
266
+ bool TestStartupAndBehavior::checkExpectedStartupResults (TestStartInvocationData *obj, TestStartInvocationData *expected)
146
267
{
147
- if (obj->firstAccessCalled != expected->firstAccessCalled ) {
148
- return error ( QString (" firstAccessCalled expected:%1, found:%2" ).arg (expected->firstAccessCalled ).arg (obj->firstAccessCalled ));
149
- }
150
- Expert *** First Yes View Details Welcome
151
- Expert Open File First Yes View Details Open File
152
- Expert *** Following No *** Welcome
153
- Expert Open File Following No *** Open File
154
- Basic *** First Yes Operations ***
155
- Basic Open File First Yes Operations Open File
156
- Basic *** Following No Operations ***
157
- Basic Open File Following No Operations Open File
158
-
268
+ if (obj->askUserTypePanel != expected->askUserTypePanel ) {
269
+ return error ( QString (" askUserTypePanel expected:%1, found:%2" ).arg (expected->askUserTypePanel ).arg (obj->askUserTypePanel ));
270
+ }
271
+ if (obj->openGuidedPanel != expected->openGuidedPanel ) {
272
+ return error ( QString (" openGuidedPanel expected:%1, found:%2" ).arg (expected->openGuidedPanel ).arg (obj->openGuidedPanel ));
273
+ }
274
+ if (obj->askVisDetailsTypePanel != expected->askVisDetailsTypePanel ) {
275
+ return error ( QString (" askVisDetailsTypePanel expected:%1, found:%2" ).arg (expected->askVisDetailsTypePanel ).arg (obj->askVisDetailsTypePanel ));
276
+ }
277
+ if (obj->showWelcome != expected->showWelcome ) {
278
+ return error ( QString (" showWelcome expected:%1, found:%2" ).arg (expected->showWelcome ).arg (obj->showWelcome ));
279
+ }
280
+ if (obj->openFile != expected->openFile ) {
281
+ return error ( QString (" openFile expected:%1, found:%2" ).arg (expected->openFile ).arg (obj->openFile ));
282
+ }
283
+ return true ;
159
284
}
0 commit comments