Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkStateMachineContainerTest.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "mitkStateMachineAction.h"
15 #include "mitkStateMachineState.h"
17 #include "mitkTestingMacros.h"
18 #include <string>
19 
20 int mitkStateMachineContainerTest(int /*argc*/, char * /*argv*/ [])
21 {
22  MITK_TEST_BEGIN("StateMachineContainer")
23 
24  /*
25  * Loads a test StateMachine and checks if it is build up correctly.
26  */
27 
29 
30  MITK_TEST_CONDITION_REQUIRED(smc->LoadBehavior("Tests/StatemachineTest.xml") == true,
31  "01 Check if file can be loaded");
32 
33  std::string sname = smc->GetStartState()->GetName();
34 
35  MITK_TEST_CONDITION_REQUIRED(sname == "STATE1", "02 Check if start state is correct");
36 
37  /*
38  * Follow transitions and check if all actions have been loaded.
39  */
41  smc->GetStartState()->GetTransition("MouseMoveEvent", "no1"); // transition exists
43  smc->GetStartState()->GetTransition("StdMouseNotMove", "no1"); // transition does not exist
44  mitk::StateMachineState::Pointer st2 = s1->GetNextState();
46  st2->GetTransition("MouseMoveEvent", "no1"); // transition from state2 to state3
47  typedef std::vector<mitk::StateMachineAction::Pointer> ActionCollectionType;
48  ActionCollectionType actions = s3->GetActions();
49 
50  ActionCollectionType::iterator it = actions.begin();
51  std::string action1 = (*it)->GetActionName();
52  ++it;
53  std::string action2 = (*it)->GetActionName();
54  ++it; // this should now point to the end of the vector, since only two actions are given
55 
56  MITK_INFO << s2.IsNull();
57 
59  s1.IsNotNull() && s2.IsNull() && st2->GetName() == "STATE2" && action1 == "doaction7" && action2 == "doaction2" &&
60  (it == actions.end()),
61  "03 Check if transitions and Action identifier work. \n Expected STATE2 , doaction7, doction2 got:\n"
62  << st2->GetName()
63  << ","
64  << action1
65  << ","
66  << action2);
67 
68  // always end with this!
70 }
bool LoadBehavior(const std::string &fileName, const us::Module *module)
Loads XML resource.
#define MITK_INFO
Definition: mitkLogMacros.h:18
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
int mitkStateMachineContainerTest(int, char *[])
static StateMachineContainer * New()
StateMachineState::Pointer GetStartState() const
Returns the StartState of the StateMachine.
and MITK_TEST_END()