Skip to content

Commit 149032e

Browse files
committed
b-169: added test for startup.
1 parent 1803094 commit 149032e

8 files changed

+201
-58
lines changed

src/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ int internalMain(int argc, char *argv[])
130130
Utils::TODO_THIS_RELEASE("spostare in classe apposita");
131131
if(!handleCommandLineArguments(app, startParams)) {
132132
Utils::TODO_THIS_RELEASE("controlla e rimuovi");
133-
StartActionsEngine startActionsEngine(&app, &appData);
133+
StartActionsEngine startActionsEngine(&appData, &app);
134134
startActionsEngine.execute(startParams);
135135
/*
136136
MainWindow *mainWindow = new MainWindow(false, &appData);

src/mainwindow.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -3461,7 +3461,8 @@ void MainWindow::taskChooseDetail()
34613461
{
34623462
Utils::TODO_THIS_RELEASE("controlla equivalenza");
34633463
Utils::TODO_THIS_RELEASE("spostare in application");
3464-
QXmlEditApplication::taskChooseDetail();
3464+
Utils::TODO_THIS_RELEASE("fare il routing dei comandi");
3465+
//QXmlEditApplication::taskChooseDetail();
34653466
/*ChooseStyleDialog dlg(this);
34663467
dlg.setModal(true);
34673468
dlg.setWindowModality(Qt::ApplicationModal);

src/modules/services/startactionsengine.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
#include "utils.h"
2727

2828
//------------------------------------------------------------------------
29-
StartAtcionsExecutor::StartAtcionsExecutor()
29+
StartActionsExecutor::StartActionsExecutor()
3030
{
3131
//
3232
}
3333

34-
StartAtcionsExecutor::~StartAtcionsExecutor()
34+
StartActionsExecutor::~StartActionsExecutor()
3535
{
3636
//
3737
}
@@ -53,8 +53,8 @@ StartActionsEngine::~StartActionsEngine()
5353
*/
5454
bool StartActionsEngine::execute(StartParams &startParams)
5555
{
56-
if( (NULL == _executor) || ( NULL == _data ) ) {
57-
Utils::error( NULL, tr(""));
56+
if((NULL == _executor) || (NULL == _data)) {
57+
Utils::error(NULL, tr(""));
5858
return false;
5959
}
6060
if(_data->isUserFirstAccess()) {

src/modules/services/startactionsengine.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,16 @@
2828
class ApplicationData;
2929
class StartParams;
3030

31-
class StartActionsExecutor {
31+
class StartActionsExecutor
32+
{
3233

3334
public:
3435
StartActionsExecutor();
3536
virtual ~StartActionsExecutor();
3637

3738
virtual void startActionShowUserTypePanel() = 0 ;
3839
virtual bool startActionShowGuidedOperationsPanel() = 0 ;
39-
virtual void startActionSetupFirstAccessForPreferences() =0 ;
40+
virtual void startActionSetupFirstAccessForPreferences() = 0 ;
4041
virtual void startActionTriggersWelcomeDialog() = 0 ;
4142
virtual void startActionLoadFile(const QString &fileName) = 0 ;
4243
};

src/qxmleditapplication.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "modules/help/firstaccessdialog.h"
3737
#include "modules/help/guidedoperationsdialog.h"
3838
#include "modules/help/guidedvalidationdialog.h"
39+
#include "modules/style/choosestyledialog.h"
3940

4041
const QString QXmlEditApplication::ServerName("__qxmledit__server__");
4142

src/qxmleditapplication.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class MainWindow;
3636
class GuidedOperationsDialog;
3737
class GuidedValidationDialog;
3838

39-
class QXmlEditApplication : public QApplication, StartActionsExecutor
39+
class QXmlEditApplication : public QApplication, public StartActionsExecutor
4040
{
4141
Q_OBJECT
4242
private:

test/teststartupandbehavior.cpp

+174-49
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,31 @@
2222

2323
#include "teststartupandbehavior.h"
2424
#include "modules/services/startactionsengine.h"
25+
#include "app.h"
26+
#include "StartParams.h"
2527

2628
//--------
2729
struct TestStartInvocationData {
2830
public:
29-
_userType;
3031
//--
31-
bool firstAccessCalled;
32+
bool askUserTypePanel;
33+
bool openGuidedPanel;
34+
bool askVisDetailsTypePanel ;
35+
bool showWelcome ;
36+
bool openFile;
37+
ApplicationData::EUserType panelUserType;
3238
TestStartInvocationData();
3339
~TestStartInvocationData();
3440
};
3541

3642
TestStartInvocationData::TestStartInvocationData()
3743
{
38-
firstAccessCalled = false ;
44+
askUserTypePanel = false ;
45+
openGuidedPanel = false ;
46+
askVisDetailsTypePanel = false ;
47+
showWelcome = false ;
48+
openFile = false ;
49+
panelUserType = ApplicationData::UserTypeExpert;
3950
}
4051

4152
TestStartInvocationData::~TestStartInvocationData()
@@ -48,7 +59,8 @@ class FakeStartActionsExecutor : public StartActionsExecutor {
4859

4960
public:
5061
TestStartInvocationData _data;
51-
FakeStartActionsExecutor();
62+
ApplicationData *_appData ;
63+
FakeStartActionsExecutor(ApplicationData *appData);
5264
virtual ~FakeStartActionsExecutor();
5365

5466
virtual void startActionShowUserTypePanel();
@@ -58,8 +70,9 @@ class FakeStartActionsExecutor : public StartActionsExecutor {
5870
virtual void startActionLoadFile(const QString &fileName);
5971
};
6072

61-
FakeStartActionsExecutor::FakeStartActionsExecutor()
73+
FakeStartActionsExecutor::FakeStartActionsExecutor(ApplicationData *appData)
6274
{
75+
_appData = appData ;
6376
}
6477

6578
FakeStartActionsExecutor::~FakeStartActionsExecutor()
@@ -68,92 +81,204 @@ FakeStartActionsExecutor::~FakeStartActionsExecutor()
6881

6982
void FakeStartActionsExecutor::startActionShowUserTypePanel()
7083
{
71-
_data.firstAccessCalled = true ;
84+
_data.askUserTypePanel = true;
85+
_appData->setUserType(_data.panelUserType);
7286
}
87+
7388
bool FakeStartActionsExecutor::startActionShowGuidedOperationsPanel()
7489
{
75-
a
90+
_data.openGuidedPanel = true ;
91+
return true ;
7692
}
93+
7794
void FakeStartActionsExecutor::startActionSetupFirstAccessForPreferences()
7895
{
79-
s
96+
_data.askVisDetailsTypePanel = true ;
8097
}
98+
8199
void FakeStartActionsExecutor::startActionTriggersWelcomeDialog()
82100
{
83-
s
101+
_data.showWelcome = true ;
84102
}
85-
void FakeStartActionsExecutor::startActionLoadFile(const QString &fileName)
103+
104+
void FakeStartActionsExecutor::startActionLoadFile(const QString & /*fileName*/)
86105
{
87-
s
106+
_data.openFile = true ;
88107
}
89108

90109
//-------
91110

92111
TestStartupAndBehavior::TestStartupAndBehavior()
93112
{
94-
113+
//
95114
}
96115

97116

98117
TestStartupAndBehavior::~TestStartupAndBehavior()
99118
{
100-
119+
//
101120
}
102121

103122
bool TestStartupAndBehavior::testFast()
104123
{
105124
return testUnit();
106125
}
107126

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+
*/
108138
bool TestStartupAndBehavior::testUnit()
109139
{
110140
_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 ;
124182
}
125183

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 )
128194
{
195+
_subTestName = id ;
129196
App app;
130-
if(!app.initWitooutWIndow() ) {
197+
if(!app.initNoWindow() ) {
131198
return error("Init");
132199
}
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+
137206
//----
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 ;
139240
//----
140-
StartActionsEngine engine(app.data());
241+
FakeStartActionsExecutor executor(app.data());
242+
StartActionsEngine engine( app.data(), &executor);
141243
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;
143264
}
144265

145-
bool TestStartupAndBehavior::checkStartup(TestStartInvocationData *obj, TestStartInvocationData *expected)
266+
bool TestStartupAndBehavior::checkExpectedStartupResults(TestStartInvocationData *obj, TestStartInvocationData *expected)
146267
{
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 ;
159284
}

0 commit comments

Comments
 (0)