Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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,
6  Division of Medical and Biological Informatics.
7  All rights reserved.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without
10  even the implied warranty of MERCHANTABILITY or FITNESS FOR
11  A PARTICULAR PURPOSE.
12 
13  See LICENSE.txt or http://www.mitk.org for details.
14 
15  ===================================================================*/
16 
17 #include "mitkStateMachineAction.h"
19 #include "mitkStateMachineState.h"
21 #include "mitkTestingMacros.h"
22 #include <string>
23 
24 int mitkStateMachineContainerTest(int /*argc*/, char * /*argv*/ [])
25 {
26  MITK_TEST_BEGIN("StateMachineContainer")
27 
28  /*
29  * Loads a test StateMachine and checks if it is build up correctly.
30  */
31 
33 
34  MITK_TEST_CONDITION_REQUIRED(smc->LoadBehavior("Tests/StatemachineTest.xml") == true,
35  "01 Check if file can be loaded");
36 
37  std::string sname = smc->GetStartState()->GetName();
38 
39  MITK_TEST_CONDITION_REQUIRED(sname == "STATE1", "02 Check if start state is correct");
40 
41  /*
42  * Follow transitions and check if all actions have been loaded.
43  */
45  smc->GetStartState()->GetTransition("MouseMoveEvent", "no1"); // transition exists
47  smc->GetStartState()->GetTransition("StdMouseNotMove", "no1"); // transition does not exist
48  mitk::StateMachineState::Pointer st2 = s1->GetNextState();
50  st2->GetTransition("MouseMoveEvent", "no1"); // transition from state2 to state3
51  typedef std::vector<mitk::StateMachineAction::Pointer> ActionCollectionType;
52  ActionCollectionType actions = s3->GetActions();
53 
54  ActionCollectionType::iterator it = actions.begin();
55  std::string action1 = (*it)->GetActionName();
56  ++it;
57  std::string action2 = (*it)->GetActionName();
58  ++it; // this should now point to the end of the vector, since only two actions are given
59 
60  MITK_INFO << s2.IsNull();
61 
63  s1.IsNotNull() && s2.IsNull() && st2->GetName() == "STATE2" && action1 == "doaction7" && action2 == "doaction2" &&
64  (it == actions.end()),
65  "03 Check if transitions and Action identifier work. \n Expected STATE2 , doaction7, doction2 got:\n"
66  << st2->GetName()
67  << ","
68  << action1
69  << ","
70  << action2);
71 
72  // always end with this!
74 }
bool LoadBehavior(const std::string &fileName, const us::Module *module)
Loads XML resource.
#define MITK_INFO
Definition: mitkLogMacros.h:22
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
int mitkStateMachineContainerTest(int, char *[])
StateMachineState::Pointer GetStartState() const
Returns the StartState of the StateMachine.
static StateMachineContainer * New()
and MITK_TEST_END()