Browse Source

Unit test added for CTKXNATCore

Miklos Espak 11 years ago
parent
commit
5c3e8f94d0

+ 4 - 7
Libs/XNAT/Core/CMakeLists.txt

@@ -54,10 +54,7 @@ ctkMacroBuildLib(
   LIBRARY_TYPE ${CTK_LIBRARY_MODE}
   )
 
-## Testing
-#if(BUILD_TESTING)
-#  add_subdirectory(Testing)
-#
-#  # Compile source code snippets
-#  add_subdirectory(Documentation/Snippets)
-#endif()
+# Testing
+if(BUILD_TESTING)
+  add_subdirectory(Testing)
+endif()

+ 24 - 0
Libs/XNAT/Core/Testing/CMakeLists.txt

@@ -0,0 +1,24 @@
+set(KIT ${PROJECT_NAME})
+
+set(KITTests_SRCS
+  ctkXnatConnectionTest.cpp
+  )
+
+create_test_sourcelist(Tests ${KIT}CppTests.cpp
+  ${KITTests_SRCS}
+  )
+
+set(KITTests_MOC_SRCS
+  ctkXnatConnectionTest.h
+  )
+
+QT4_WRAP_CPP(KITTests_MOC_CPP ${KITTests_MOC_SRCS})
+
+add_executable(${KIT}Tests ${Tests} ${KITTests_SRCS} ${KITTests_MOC_SRCS} ${KITTests_MOC_CPP})
+target_link_libraries(${KIT}Tests ${LIBRARY_NAME} ${CTK_BASE_LIBRARIES})
+
+macro(SIMPLE_TEST TESTNAME)
+  add_test(NAME ${TESTNAME} COMMAND ${KIT}Tests ${TESTNAME})
+endmacro()
+
+SIMPLE_TEST(ctkXnatConnectionTest)

+ 105 - 0
Libs/XNAT/Core/Testing/ctkXnatConnectionTest.cpp

@@ -0,0 +1,105 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) 2013 University College London, Centre for Medical Image Computing
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0.txt
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+#include "ctkXnatConnectionTest.h"
+
+#include <QCoreApplication>
+#include <QDebug>
+#include <QDir>
+#include <QSignalSpy>
+#include <QStringList>
+#include <QTest>
+#include <QTime>
+#include <QTimer>
+#include <QUrl>
+#include <QUuid>
+
+#include <ctkXnatConnection.h>
+#include <ctkXnatConnectionFactory.h>
+#include <ctkXnatProject.h>
+#include <ctkXnatServer.h>
+
+class ctkXnatConnectionTestCasePrivate
+{
+public:
+  ctkXnatConnectionFactory* ConnectionFactory;
+  ctkXnatConnection* Connection;
+
+  QString ServerUri;
+  QString UserName;
+  QString Password;
+
+  QString Project;
+  QString Subject;
+  QString Experiment;
+};
+
+// --------------------------------------------------------------------------
+ctkXnatConnectionTestCase::ctkXnatConnectionTestCase()
+: d_ptr(new ctkXnatConnectionTestCasePrivate())
+{
+}
+
+// --------------------------------------------------------------------------
+ctkXnatConnectionTestCase::~ctkXnatConnectionTestCase()
+{
+}
+
+// --------------------------------------------------------------------------
+void ctkXnatConnectionTestCase::initTestCase()
+{
+  Q_D(ctkXnatConnectionTestCase);
+
+  d->ServerUri = "https://central.xnat.org";
+  d->UserName = "ctk";
+  d->Password = "ctk";
+
+  d->ConnectionFactory = new ctkXnatConnectionFactory();
+  d->Connection = d->ConnectionFactory->makeConnection(d->ServerUri, d->UserName, d->Password);
+  d->Connection->setProfileName("ctk");
+}
+
+void ctkXnatConnectionTestCase::cleanupTestCase()
+{
+  Q_D(ctkXnatConnectionTestCase);
+
+  delete d->ConnectionFactory;
+}
+
+void ctkXnatConnectionTestCase::testProjectList()
+{
+  Q_D(ctkXnatConnectionTestCase);
+
+  ctkXnatServer::Pointer server = d->Connection->server();
+  server->fetch();
+
+  QList<ctkXnatObject::Pointer> projects = server->children();
+
+  QVERIFY(projects.size() > 0);
+}
+
+
+// --------------------------------------------------------------------------
+int ctkXnatConnectionTest(int argc, char* argv[])
+{
+  QCoreApplication app(argc, argv);
+  ctkXnatConnectionTestCase test;
+  return QTest::qExec(&test, argc, argv);
+}

+ 57 - 0
Libs/XNAT/Core/Testing/ctkXnatConnectionTest.h

@@ -0,0 +1,57 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) 2013 University College London, Centre for Medical Image Computing
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0.txt
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+#ifndef __ctkXnatConnectionTest_h
+#define __ctkXnatConnectionTest_h
+
+#include <QObject>
+
+class ctkXnatConnectionTestCasePrivate;
+
+class ctkXnatConnectionTestCase: public QObject
+{
+  Q_OBJECT
+
+  void wait(int msec);
+
+public:
+
+  explicit ctkXnatConnectionTestCase();
+  virtual ~ctkXnatConnectionTestCase();
+
+private slots:
+
+  void initTestCase();
+
+  void cleanupTestCase();
+
+  void testProjectList();
+
+private:
+  QScopedPointer<ctkXnatConnectionTestCasePrivate> d_ptr;
+
+  Q_DECLARE_PRIVATE(ctkXnatConnectionTestCase);
+  Q_DISABLE_COPY(ctkXnatConnectionTestCase);
+};
+
+// --------------------------------------------------------------------------
+int ctkXnatConnectionTest(int argc, char* argv[]);
+
+#endif