summaryrefslogtreecommitdiff
path: root/cppe/test
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2006-05-01 18:31:55 +0000
committerDwayne Boone <dwayne@zeroc.com>2006-05-01 18:31:55 +0000
commit75ae8f6e9822d23c83c5e1efec31a82d27a0047b (patch)
tree59e538a9a7e601768574e3179390a73fbb0b933b /cppe/test
parentremoving redundant 'Client' portion from filter property names (diff)
downloadice-75ae8f6e9822d23c83c5e1efec31a82d27a0047b.tar.bz2
ice-75ae8f6e9822d23c83c5e1efec31a82d27a0047b.tar.xz
ice-75ae8f6e9822d23c83c5e1efec31a82d27a0047b.zip
Added ability to configure string converters
Diffstat (limited to 'cppe/test')
-rw-r--r--cppe/test/IceE/custom/Client.cpp3
-rw-r--r--cppe/test/IceE/custom/Collocated.cpp3
-rw-r--r--cppe/test/IceE/custom/Makefile9
-rw-r--r--cppe/test/IceE/custom/Server.cpp3
-rw-r--r--cppe/test/IceE/custom/StringConverterI.cpp102
-rw-r--r--cppe/test/IceE/custom/StringConverterI.h43
6 files changed, 160 insertions, 3 deletions
diff --git a/cppe/test/IceE/custom/Client.cpp b/cppe/test/IceE/custom/Client.cpp
index c80c581c5c4..2f90fa23ee4 100644
--- a/cppe/test/IceE/custom/Client.cpp
+++ b/cppe/test/IceE/custom/Client.cpp
@@ -11,6 +11,7 @@
#include <TestCommon.h>
#include <TestApplication.h>
#include <Test.h>
+#include <StringConverterI.h>
using namespace std;
@@ -28,6 +29,8 @@ public:
{
Ice::InitializationData initData;
initData.properties = Ice::createProperties();
+ initData.stringConverter = new Test::StringConverterI();
+ initData.wstringConverter = new Test::WstringConverterI();
loadConfig(initData.properties);
initData.logger = getLogger();
diff --git a/cppe/test/IceE/custom/Collocated.cpp b/cppe/test/IceE/custom/Collocated.cpp
index 7b440949847..33c128799e1 100644
--- a/cppe/test/IceE/custom/Collocated.cpp
+++ b/cppe/test/IceE/custom/Collocated.cpp
@@ -12,6 +12,7 @@
#include <TestApplication.h>
#include <TestI.h>
#include <WstringI.h>
+#include <StringConverterI.h>
using namespace std;
@@ -29,6 +30,8 @@ public:
{
Ice::InitializationData initData;
initData.properties = Ice::createProperties();
+ initData.stringConverter = new Test::StringConverterI();
+ initData.wstringConverter = new Test::WstringConverterI();
initData.properties->setProperty("TestAdapter.Endpoints", "default -p 12010 -t 10000");
//initData.properties->setProperty("Ice.Trace.Network", "5");
diff --git a/cppe/test/IceE/custom/Makefile b/cppe/test/IceE/custom/Makefile
index bb9b1ec76dc..e6d1e41d07e 100644
--- a/cppe/test/IceE/custom/Makefile
+++ b/cppe/test/IceE/custom/Makefile
@@ -19,14 +19,16 @@ COBJS = Test.o \
Wstring.o \
Client.o \
AllTests.o \
- MyByteSeq.o
+ MyByteSeq.o \
+ StringConverterI.o
SOBJS = Test.o \
TestI.o \
Wstring.o \
WstringI.o \
Server.o \
- MyByteSeq.o
+ MyByteSeq.o \
+ StringConverterI.o
COLOBJS = Test.o \
TestI.o \
@@ -34,7 +36,8 @@ COLOBJS = Test.o \
WstringI.o \
Collocated.o \
AllTests.o \
- MyByteSeq.o
+ MyByteSeq.o \
+ StringConverterI.o
SRCS = $(COBJS:.o=.cpp) \
$(SOBJS:.o=.cpp) \
diff --git a/cppe/test/IceE/custom/Server.cpp b/cppe/test/IceE/custom/Server.cpp
index ba435f5310b..1672d2eda42 100644
--- a/cppe/test/IceE/custom/Server.cpp
+++ b/cppe/test/IceE/custom/Server.cpp
@@ -12,6 +12,7 @@
#include <TestApplication.h>
#include <TestI.h>
#include <WstringI.h>
+#include <StringConverterI.h>
using namespace std;
@@ -29,6 +30,8 @@ public:
{
Ice::InitializationData initData;
initData.properties = Ice::createProperties();
+ initData.stringConverter = new Test::StringConverterI();
+ initData.wstringConverter = new Test::WstringConverterI();
initData.properties->setProperty("TestAdapter.Endpoints", "default -p 12010 -t 10000");
//initData.properties->setProperty("Ice.Trace.Network", "5");
diff --git a/cppe/test/IceE/custom/StringConverterI.cpp b/cppe/test/IceE/custom/StringConverterI.cpp
new file mode 100644
index 00000000000..118f8cd43ba
--- /dev/null
+++ b/cppe/test/IceE/custom/StringConverterI.cpp
@@ -0,0 +1,102 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2006 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 <StringConverterI.h>
+#include <IceE/Unicode.h>
+
+Ice::Byte*
+Test::StringConverterI::toUTF8(const char* sourceStart, const char* sourceEnd, Ice::UTF8Buffer& buffer) const
+{
+ size_t size = static_cast<size_t>(sourceEnd - sourceStart);
+ Ice::Byte* targetStart = buffer.getMoreBytes(size, 0);
+ Ice::Byte* targetEnd = targetStart + size;
+
+ char* p = const_cast<char*>(sourceEnd);
+ for(unsigned int i = 0; i < size; ++i)
+ {
+ targetStart[i] = *(--p);
+ }
+ return targetEnd;
+}
+
+void
+Test::StringConverterI::fromUTF8(const Ice::Byte* sourceStart, const Ice::Byte* sourceEnd,
+ const char*& targetStart, const char*& targetEnd) const
+{
+ size_t size = static_cast<size_t>(sourceEnd - sourceStart);
+ char* buf = new char[size];
+
+ Ice::Byte* p = const_cast<Ice::Byte*>(sourceEnd);
+ for(unsigned int i = 0; i < size; ++i)
+ {
+ buf[i] = *(--p);
+ }
+
+ targetStart = buf;
+ targetEnd = targetStart + size;
+}
+
+void
+Test::StringConverterI::freeTarget(const char* target) const
+{
+ delete[] target;
+}
+
+Ice::Byte*
+Test::WstringConverterI::toUTF8(const wchar_t* sourceStart, const wchar_t* sourceEnd, Ice::UTF8Buffer& buffer) const
+{
+ std::wstring ws(sourceStart, sourceEnd);
+ std::string s = IceUtil::wstringToString(ws);
+
+ size_t size = s.size();
+ Ice::Byte* targetStart = buffer.getMoreBytes(size, 0);
+ Ice::Byte* targetEnd = targetStart + size;
+
+ char* p = const_cast<char*>(s.c_str() + size);
+ for(unsigned int i = 0; i < size; ++i)
+ {
+ targetStart[i] = static_cast<Ice::Byte>(*(--p));
+ }
+ return targetEnd;
+}
+
+void
+Test::WstringConverterI::fromUTF8(const Ice::Byte* sourceStart, const Ice::Byte* sourceEnd,
+ const wchar_t*& targetStart, const wchar_t*& targetEnd) const
+{
+ size_t size = static_cast<size_t>(sourceEnd - sourceStart);
+ std::string s(sourceStart, sourceEnd);
+
+ Ice::Byte* p = const_cast<Ice::Byte*>(sourceEnd);
+ for(unsigned int i = 0; i < size; ++i)
+ {
+ s[i] = *(--p);
+ }
+
+ std::wstring ws = IceUtil::stringToWstring(s);
+ size = ws.size();
+ wchar_t* buf = new wchar_t[size];
+ for(unsigned int i = 0; i < size; ++i)
+ {
+ buf[i] = ws[i];
+ }
+
+ targetStart = buf;
+ targetEnd = targetStart + size;
+}
+
+void
+Test::WstringConverterI::freeTarget(const wchar_t* target) const
+{
+#if defined(_MSC_VER) && _MSC_VER < 1300
+ delete[] const_cast<wchar_t*>(target);
+#else
+ delete[] target;
+#endif
+}
diff --git a/cppe/test/IceE/custom/StringConverterI.h b/cppe/test/IceE/custom/StringConverterI.h
new file mode 100644
index 00000000000..f30489e5cc0
--- /dev/null
+++ b/cppe/test/IceE/custom/StringConverterI.h
@@ -0,0 +1,43 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2006 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.
+//
+// **********************************************************************
+
+#ifndef STRING_CONVERTER_I_H
+#define STRING_CONVERTER_I_H
+
+#include <IceE/StringConverter.h>
+
+//
+// Simple contrived string converters which simply reverse the order of the
+// characters being sent.
+//
+
+namespace Test
+{
+
+class StringConverterI : public Ice::StringConverter
+{
+public:
+
+ virtual Ice::Byte* toUTF8(const char*, const char*, Ice::UTF8Buffer&) const;
+ virtual void fromUTF8(const Ice::Byte*, const Ice::Byte*, const char*&, const char*&) const;
+ virtual void freeTarget(const char*) const;
+};
+
+class WstringConverterI : public Ice::WstringConverter
+{
+public:
+
+ virtual Ice::Byte* toUTF8(const wchar_t*, const wchar_t*, Ice::UTF8Buffer&) const;
+ virtual void fromUTF8(const Ice::Byte*, const Ice::Byte*, const wchar_t*&, const wchar_t*&) const;
+ virtual void freeTarget(const wchar_t*) const;
+};
+
+}
+
+#endif