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
berryUITestCase.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 "berryUITestCase.h"
18 
19 #include <berryPlatformUI.h>
20 #include <berryUIException.h>
21 
23 
24 #ifdef BLUEBERRY_DEBUG_SMARTPOINTER
25 #include <berryDebugUtil.h>
26 #endif
27 
28 namespace berry
29 {
30 
32 {
33  return 0;
34 }
35 
36 UITestCase::UITestCase(const QString& testName) :
37  TestCase(testName)
38 {
39  // ErrorDialog.NO_UI = true;
41 }
42 
43 void UITestCase::failexc(const QString& message, const std::exception& e,
44  long /*lineNumber*/, const QString& /*fileName*/)
45 {
46  //TODO IStatus
47  // If the exception is a CoreException with a multistatus
48  // then print out the multistatus so we can see all the info.
49  // if (e instanceof CoreException) {
50  // IStatus status = ((CoreException) e).getStatus();
51  // write(status, 0);
52  // } else
53  // e.printStackTrace();
54  CPPUNIT_FAIL(message.toStdString() + ": " + e.what());
55 }
56 
58 {
60 }
61 
63  const QString& perspectiveId)
64 {
65  try
66  {
68  perspectiveId, GetPageInput());
69  WaitOnShell(window->GetShell());
70  return window;
71  } catch (const WorkbenchException& e)
72  {
73  CPPUNIT_FAIL(e.what());
74  return IWorkbenchWindow::Pointer(0);
75  }
76 }
77 
79 {
80  while (!testWindows.empty())
81  {
82  testWindows.back()->Close();
83  testWindows.pop_back();
84  }
85 }
86 
88 {
89  // IWorkbenchPage[] pages = openTestPage(win, 1);
90  // if (pages != null)
91  // return pages[0];
92  // else
93  return IWorkbenchPage::Pointer(0);
94 }
95 
96 QList<IWorkbenchPage::Pointer> UITestCase::OpenTestPage(
97  const IWorkbenchWindow::Pointer& /*win*/, int /*pageTotal*/)
98 {
99  // try {
100  // IWorkbenchPage[] pages = new IWorkbenchPage[pageTotal];
101  // IAdaptable input = getPageInput();
102  //
103  // for (int i = 0; i < pageTotal; i++) {
104  // pages[i] = win.openPage(EmptyPerspective.PERSP_ID, input);
105  // }
106  // return pages;
107  // } catch (WorkbenchException e) {
108  // fail();
109  // return null;
110  // }
111  return QList<IWorkbenchPage::Pointer>();
112 }
113 
115 {
116  // IWorkbenchPage[] pages = window.getPages();
117  // for (int i = 0; i < pages.length; i++)
118  // pages[i].close();
119 }
120 
121 void UITestCase::Trace(const QString& msg)
122 {
123  qDebug() << msg;
124 }
125 
127 {
128  QString name = QString::fromStdString(this->getName());
129  Trace("----- " + name);
130  Trace(name + ": setUp...");
131  AddWindowListener();
133 }
134 
136 {
137  // do nothing.
138 }
139 
141 {
142  Trace(QString::fromStdString(this->getName()) + ": tearDown...\n");
143  RemoveWindowListener();
145 }
146 
148 {
149  ProcessEvents();
151  ProcessEvents();
152 }
153 
155 {
156  // Display display = PlatformUI.getWorkbench().getDisplay();
157  // if (display != null)
158  // while (display.readAndDispatch())
159  // ;
160 }
161 
162 void UITestCase::ManageWindows(bool manage)
163 {
164  windowListener->SetEnabled(manage);
165 }
166 
168 {
169  return fWorkbench;
170 }
171 
173  QList<IWorkbenchWindow::Pointer>& testWindows)
174  : enabled(true), testWindows(testWindows)
175 {
176 }
177 
179 {
180  this->enabled = enabled;
181 }
182 
184  const IWorkbenchWindow::Pointer& /*window*/)
185 {
186  // do nothing
187 }
188 
190  const IWorkbenchWindow::Pointer& /*window*/)
191 {
192  // do nothing
193 }
194 
196  const IWorkbenchWindow::Pointer& window)
197 {
198  if (enabled)
199  testWindows.removeAll(window);
200 }
201 
203  const IWorkbenchWindow::Pointer& window)
204 {
205  if (enabled)
206  testWindows.push_back(window);
207 }
208 
209 void UITestCase::Indent(std::ostream& output, unsigned int indent)
210 {
211  for (unsigned int i = 0; i < indent; i++)
212  output << " ";
213 }
214 
215 // void UITestCase::Write(IStatus status, unsigned int indent) {
216 // PrintStream output = System.out;
217 // indent(output, indent);
218 // output.println("Severity: " + status.getSeverity());
219 //
220 // indent(output, indent);
221 // output.println("Plugin ID: " + status.getPlugin());
222 //
223 // indent(output, indent);
224 // output.println("Code: " + status.getCode());
225 //
226 // indent(output, indent);
227 // output.println("Message: " + status.getMessage());
228 //
229 // if (status.getException() != null) {
230 // indent(output, indent);
231 // output.print("Exception: ");
232 // status.getException().printStackTrace(output);
233 // }
234 //
235 // if (status.isMultiStatus()) {
236 // IStatus[] children = status.getChildren();
237 // for (int i = 0; i < children.length; i++)
238 // write(children[i], indent + 1);
239 // }
240 // }
241 
242 void UITestCase::AddWindowListener()
243 {
244  windowListener.reset(new TestWindowListener(testWindows));
245  fWorkbench->AddWindowListener(windowListener.data());
246 }
247 
248 void UITestCase::RemoveWindowListener()
249 {
250  if (windowListener)
251  {
252  fWorkbench->RemoveWindowListener(windowListener.data());
253  }
254 }
255 
256 void UITestCase::WaitOnShell(Shell::Pointer /*shell*/)
257 {
258 
259  ProcessEvents();
260  // long endTime = System.currentTimeMillis() + 5000;
261  //
262  // while (shell.getDisplay().getActiveShell() != shell
263  // && System.currentTimeMillis() < endTime) {
264  // processEvents();
265  // }
266 }
267 
268 }
void WindowDeactivated(const IWorkbenchWindow::Pointer &window)
UITestCase(const QString &testName)
static void ProcessEvents()
void WindowOpened(const IWorkbenchWindow::Pointer &window)
void ManageWindows(bool manage)
virtual void RemoveWindowListener(IWindowListener *listener)=0
IWorkbenchWindow::Pointer OpenTestWindow()
IWorkbenchPage::Pointer OpenTestPage(const IWorkbenchWindow::Pointer &win)
void Trace(const QString &msg)
IWorkbench * GetWorkbench()
berry::SmartPointer< Self > Pointer
Definition: berryObject.h:88
void failexc(const QString &message, const std::exception &e, long lineNumber=-1, const QString &fileName="unknown")
static const QString PERSP_ID
virtual IWorkbenchWindow::Pointer OpenWorkbenchWindow(const QString &perspectiveId, IAdaptable *input)=0
static IWorkbench * GetWorkbench()
static IAdaptable * GetPageInput()
virtual void DoTearDown()
virtual void AddWindowListener(IWindowListener *listener)=0
IWorkbench * fWorkbench
void WindowActivated(const IWorkbenchWindow::Pointer &window)
void CloseAllPages(const IWorkbenchWindow::Pointer &window)
virtual void DoSetUp()
void WindowClosed(const IWorkbenchWindow::Pointer &window)
TestWindowListener(QList< IWorkbenchWindow::Pointer > &testWindows)