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
berryCallHistory.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 BlueBerry Platform
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 "berryCallHistory.h"
18 
19 #include <algorithm>
20 
21 namespace berry
22 {
23 
24 CallHistory::CallHistory(/*Object target*/)
25 {
26  // classType = target.getClass();
27 }
28 
29 void CallHistory::Add(const std::string& methodName)
30 {
31  TestMethodName(methodName);
32  methodList.push_back(methodName);
33 }
34 
36 {
37  methodList.clear();
38 }
39 
40 bool CallHistory::VerifyOrder(const std::vector<std::string>& testNames) const
41 throw(Poco::InvalidArgumentException)
42 {
43  std::size_t testIndex = 0;
44  std::size_t testLength = testNames.size();
45  if (testLength == 0)
46  return true;
47  for (std::size_t nX = 0; nX < methodList.size(); nX++)
48  {
49  const std::string& methodName = methodList[nX];
50  const std::string& testName = testNames[testIndex];
51  TestMethodName(testName);
52  if (testName == methodName)
53  ++testIndex;
54  if (testIndex >= testLength)
55  return true;
56  }
57  return false;
58 }
59 
60 bool CallHistory::Contains(const std::string& methodName) const
61 {
62  TestMethodName(methodName);
63  return std::find(methodList.begin(), methodList.end(), methodName) != methodList.end();
64 }
65 
66 bool CallHistory::Contains(const std::vector<std::string>& methodNames) const
67 {
68  for (std::size_t i = 0; i < methodNames.size(); i++)
69  {
70  TestMethodName(methodNames[i]);
71  if (std::find(methodList.begin(), methodList.end(), methodNames[i]) == methodList.end())
72  return false;
73  }
74  return true;
75 }
76 
78 {
79  return methodList.empty();
80 }
81 
82 void CallHistory::PrintTo(std::ostream& out) const
83 {
84  for (std::size_t i = 0; i < methodList.size(); i++)
85  out << methodList[i] << std::endl;
86 }
87 
88 void CallHistory::TestMethodName(const std::string&) const
89 throw(Poco::InvalidArgumentException)
90 {
91 // Method[] methods = classType.getMethods();
92 // for (int i = 0; i < methods.length; i++)
93 // if (methods[i].getName().equals(methodName))
94 // return;
95 // throw new IllegalArgumentException("Target class (" + classType.getName()
96 // + ") does not contain method: " + methodName);
97 }
98 
99 }
bool VerifyOrder(const std::vector< std::string > &testNames) const
bool Contains(const std::string &methodName) const
void PrintTo(std::ostream &out) const
void Add(const std::string &methodName)