summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2018-06-13 17:23:57 +0200
committerJose <jose@zeroc.com>2018-06-13 17:24:20 +0200
commit360817896b3db5087a4cfde16f0eb5acf25eb24b (patch)
tree5ea8aa85dbe1efaec1eb1f6b80170d0728bca9f0
parentBumped wait time for controller to register (necessary for slow Android emula... (diff)
downloadice-360817896b3db5087a4cfde16f0eb5acf25eb24b.tar.bz2
ice-360817896b3db5087a4cfde16f0eb5acf25eb24b.tar.xz
ice-360817896b3db5087a4cfde16f0eb5acf25eb24b.zip
C++ TestHelper simplications
-rw-r--r--cpp/test/Common/TestHelper.cpp76
-rw-r--r--cpp/test/include/TestHelper.h19
2 files changed, 34 insertions, 61 deletions
diff --git a/cpp/test/Common/TestHelper.cpp b/cpp/test/Common/TestHelper.cpp
index 765686bdcc4..415c0c93e8e 100644
--- a/cpp/test/Common/TestHelper.cpp
+++ b/cpp/test/Common/TestHelper.cpp
@@ -1,3 +1,11 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2018 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
#include <TestHelper.h>
#include <Ice/RegisterPlugins.h>
@@ -9,50 +17,29 @@ using namespace Test;
namespace
{
-IceUtil::Mutex* globalMutex = 0;
#if !defined(ICE_OS_UWP) && (!defined(__APPLE__) || TARGET_OS_IPHONE == 0)
Test::TestHelper* instance = 0;
-IceUtil::CtrlCHandler* ctrlCHandler = 0;
-#endif
-class Init
+void
+shutdownOnInterruptCallback(int)
{
-public:
-
- Init()
+ if(instance)
{
- globalMutex = new IceUtil::Mutex;
+ instance->shutdown();
}
+}
- ~Init()
- {
- delete globalMutex;
- globalMutex = 0;
-#if !defined(ICE_OS_UWP) && (!defined(__APPLE__) || TARGET_OS_IPHONE == 0)
- if(ctrlCHandler)
- {
- delete ctrlCHandler;
- ctrlCHandler = 0;
- }
#endif
- }
-};
-
-Init init;
}
Test::TestHelper::TestHelper(bool registerPlugins)
+#if !defined(ICE_OS_UWP) && (!defined(__APPLE__) || TARGET_OS_IPHONE == 0)
+ : _ctrlCHandler(0)
+#endif
{
#if !defined(ICE_OS_UWP) && (!defined(__APPLE__) || TARGET_OS_IPHONE == 0)
- {
- IceUtilInternal::MutexPtrLock<IceUtil::Mutex> lock(globalMutex);
- if(instance != 0)
- {
- throw runtime_error("only one instance of the Test::TestHelper class can be used");
- }
- instance = this;
- }
+ instance = this;
#endif
if(registerPlugins)
@@ -83,6 +70,13 @@ Test::TestHelper::TestHelper(bool registerPlugins)
Test::TestHelper::~TestHelper()
{
+#if !defined(ICE_OS_UWP) && (!defined(__APPLE__) || TARGET_OS_IPHONE == 0)
+ if(_ctrlCHandler)
+ {
+ delete _ctrlCHandler;
+ _ctrlCHandler = 0;
+ }
+#endif
}
void
@@ -215,7 +209,6 @@ Test::TestHelper::initialize(int& argc, char* argv[], const Ice::PropertiesPtr&
Ice::CommunicatorPtr
Test::TestHelper::initialize(int& argc, char* argv[], Ice::InitializationData initData)
{
- IceUtil::Mutex::Lock lock(_mutex);
_communicator = Ice::initialize(argc, argv, initData);
return _communicator;
}
@@ -238,7 +231,6 @@ Test::TestHelper::serverReady()
void
Test::TestHelper::shutdown()
{
- IceUtil::Mutex::Lock lock(_mutex);
if(_communicator)
{
_communicator->shutdown();
@@ -252,25 +244,13 @@ Test::TestHelper::shutdownOnInterrupt()
}
#else
void
-Test::TestHelper::shutdownOnInterruptCallback(int)
-{
- if(instance)
- {
- instance->shutdown();
- }
-}
-
-void
Test::TestHelper::shutdownOnInterrupt()
{
+ assert(!_ctrlCHandler);
+ if(_ctrlCHandler == 0)
{
- IceUtilInternal::MutexPtrLock<IceUtil::Mutex> lock(globalMutex);
- assert(!ctrlCHandler);
- if(ctrlCHandler == 0)
- {
- ctrlCHandler = new IceUtil::CtrlCHandler();
- }
+ _ctrlCHandler = new IceUtil::CtrlCHandler();
}
- ctrlCHandler->setCallback(shutdownOnInterruptCallback);
+ _ctrlCHandler->setCallback(shutdownOnInterruptCallback);
}
#endif
diff --git a/cpp/test/include/TestHelper.h b/cpp/test/include/TestHelper.h
index 0fe70986285..ee711ff617b 100644
--- a/cpp/test/include/TestHelper.h
+++ b/cpp/test/include/TestHelper.h
@@ -24,16 +24,8 @@
#include <Ice/CommunicatorF.h>
#include <Ice/ProxyF.h>
#include <Ice/Initialize.h>
-
-#if defined(ICE_OS_UWP) || (TARGET_OS_IPHONE != 0)
-# include <Ice/Logger.h>
-# include <Ice/LocalException.h>
-
-# include <cassert>
-# include <cstdlib>
-# include <string>
-# include <iostream>
-#endif
+#include <Ice/Logger.h>
+#include <Ice/LocalException.h>
#include <IceUtil/IceUtil.h>
@@ -189,8 +181,7 @@ public:
void serverReady();
void shutdown();
- static void shutdownOnInterrupt();
- static void shutdownOnInterruptCallback(int);
+ void shutdownOnInterrupt();
virtual void run(int argc, char* argv[]) = 0;
@@ -198,7 +189,9 @@ private:
ControllerHelper* _controllerHelper;
Ice::CommunicatorPtr _communicator;
- IceUtil::Mutex _mutex;
+#if !defined(ICE_OS_UWP) && (!defined(__APPLE__) || TARGET_OS_IPHONE == 0)
+ IceUtil::CtrlCHandler* _ctrlCHandler;
+#endif
};
#if defined(ICE_OS_UWP) || (TARGET_OS_IPHONE != 0)