summaryrefslogtreecommitdiff
path: root/cpp/test/include
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2012-07-13 00:18:06 +0200
committerJose <jose@zeroc.com>2012-07-13 00:18:06 +0200
commit70802b63320582f0afa8229659ea9fe4a21d02ec (patch)
treeeb455947cc774cc558f96b8d7c78373d2a6f1c2b /cpp/test/include
parentICE-4839 - Glacier2 sessionHelper IceSSL plug-in (diff)
downloadice-70802b63320582f0afa8229659ea9fe4a21d02ec.tar.bz2
ice-70802b63320582f0afa8229659ea9fe4a21d02ec.tar.xz
ice-70802b63320582f0afa8229659ea9fe4a21d02ec.zip
WinRT support
Diffstat (limited to 'cpp/test/include')
-rw-r--r--cpp/test/include/TestCommon.h218
1 files changed, 217 insertions, 1 deletions
diff --git a/cpp/test/include/TestCommon.h b/cpp/test/include/TestCommon.h
index d68029b4ac9..02d2adba199 100644
--- a/cpp/test/include/TestCommon.h
+++ b/cpp/test/include/TestCommon.h
@@ -10,13 +10,33 @@
#ifndef TEST_COMMON_H
#define TEST_COMMON_H
-#include <IceUtil/Config.h>
+#include <IceUtil/IceUtil.h>
+#ifdef ICE_OS_WINRT
+# include <Ice/Initialize.h>
+# include <Ice/Logger.h>
+# include <Ice/LocalException.h>
+#endif
+
#include <cstdlib>
#ifdef __BCPLUSPLUS__
#include <stdlib.h>
#endif
+void
+inline print(const std::string& msg)
+{
+ std::cout << msg << std::flush;
+}
+
+void
+inline println(const std::string& msg)
+{
+ std::cout << msg << std::endl;
+}
+
+#ifndef ICE_OS_WINRT
+
void
inline testFailed(const char* expr, const char* file, unsigned int line)
{
@@ -25,6 +45,202 @@ inline testFailed(const char* expr, const char* file, unsigned int line)
abort();
}
+#define DEFINE_TEST(name)
+#define TEST_READY
+
+#else
+
+namespace Test
+{
+
+class MainHelper : public std::streambuf
+{
+public:
+
+ MainHelper()
+ {
+ setp(&data[0], &data[sizeof(data) - 1]);
+ }
+
+ virtual void serverReady() = 0;
+
+ virtual void shutdown() = 0;
+
+ virtual void waitForCompleted() = 0;
+
+ virtual bool redirect() = 0;
+
+ virtual void print(const std::string& msg) = 0;
+
+ virtual void
+ flush()
+ {
+ }
+
+ virtual void
+ newLine()
+ {
+ print("\n");
+ }
+
+private:
+
+ //
+ // streambuf redirection implementation
+ //
+
+ int sync()
+ {
+ std::streamsize n = pptr() - pbase();
+ print(std::string(pbase(), static_cast<int>(n)));
+ pbump(-static_cast<int>(pptr() - pbase()));
+ return 0;
+ }
+
+ int overflow(int ch)
+ {
+ sync();
+ if(ch != EOF)
+ {
+ assert(pptr() != epptr());
+ sputc(ch);
+ }
+ return 0;
+ }
+
+ int sputc(char c)
+ {
+ if(c == '\n')
+ {
+ pubsync();
+ }
+ return std::streambuf::sputc(c);
+ }
+
+ char data[1024];
+};
+
+extern MainHelper* helper;
+
+class MainHelperInit
+{
+public:
+
+ MainHelperInit(MainHelper* r, const std::string& name, bool redirect)
+ {
+ helper = r;
+
+ if(redirect)
+ {
+ _previousLogger = Ice::getProcessLogger();
+ Ice::setProcessLogger(Ice::getProcessLogger()->cloneWithPrefix(name));
+
+ _previousCoutBuffer = std::cout.rdbuf();
+ std::cout.rdbuf(r);
+
+ _previousCerrBuffer = std::cerr.rdbuf();
+ std::cerr.rdbuf(r);
+ }
+ }
+
+ ~MainHelperInit()
+ {
+ if(_previousLogger)
+ {
+ Ice::setProcessLogger(_previousLogger);
+ std::cout.rdbuf(_previousCoutBuffer);
+ std::cerr.rdbuf(_previousCerrBuffer);
+ }
+ }
+
+private:
+
+ Ice::LoggerPtr _previousLogger;
+ std::streambuf* _previousCoutBuffer;
+ std::streambuf* _previousCerrBuffer;
+};
+
+//
+// Redefine main as Test::mainEntryPoint
+//
+#define main Test::mainEntryPoint
+int mainEntryPoint(int, char**);
+
+}
+
+class TestFailedException : public ::Ice::LocalException
+{
+public:
+
+ TestFailedException(const char* file, int line) :
+ LocalException(file, line)
+ {
+ }
+
+ TestFailedException(const char* file, int line, const ::std::string& r) :
+ LocalException(file, line),
+ reason(r)
+ {
+ }
+
+ virtual ~TestFailedException() throw()
+ {
+ }
+
+ virtual ::std::string ice_name() const
+ {
+ return "::TestFailedException";
+ }
+
+ virtual ::Ice::Exception* ice_clone() const
+ {
+ return new TestFailedException(*this);
+ }
+
+ virtual void ice_throw() const
+ {
+ throw *this;
+ }
+
+ ::std::string reason;
+};
+
+void
+inline testFailed(const char* expr, const char* file, unsigned int line)
+{
+ std::cout << "failed!" << std::endl;
+ std::cout << file << ':' << line << ": assertion `" << expr << "' failed" << std::endl;
+ throw TestFailedException(__FILE__, __LINE__, "Test Failed");
+}
+
+#define DEFINE_TEST(name) \
+ Test::MainHelper* Test::helper; \
+ Ice::CommunicatorPtr communicatorInstance; \
+ extern "C" { \
+ _declspec(dllexport) void dllTestShutdown(); \
+ void dllTestShutdown() \
+ { \
+ try \
+ { \
+ communicatorInstance->destroy(); \
+ } \
+ catch(const Ice::LocalException&) \
+ { \
+ } \
+ } \
+ int dllMain(int argc, char** argv, Test::MainHelper* helper) \
+ { \
+ Test::MainHelperInit init(helper, name, helper->redirect()); \
+ return Test::mainEntryPoint(argc, argv); \
+ } \
+ }
+
+#define TEST_READY Test::helper->serverReady(); \
+ communicatorInstance = communicator;
+
+#endif
+
#define test(ex) ((ex) ? ((void)0) : testFailed(#ex, __FILE__, __LINE__))
#endif
+