diff options
author | Dwayne Boone <dwayne@zeroc.com> | 2006-05-01 18:31:55 +0000 |
---|---|---|
committer | Dwayne Boone <dwayne@zeroc.com> | 2006-05-01 18:31:55 +0000 |
commit | 75ae8f6e9822d23c83c5e1efec31a82d27a0047b (patch) | |
tree | 59e538a9a7e601768574e3179390a73fbb0b933b /cpp/test | |
parent | removing redundant 'Client' portion from filter property names (diff) | |
download | ice-75ae8f6e9822d23c83c5e1efec31a82d27a0047b.tar.bz2 ice-75ae8f6e9822d23c83c5e1efec31a82d27a0047b.tar.xz ice-75ae8f6e9822d23c83c5e1efec31a82d27a0047b.zip |
Added ability to configure string converters
Diffstat (limited to 'cpp/test')
-rw-r--r-- | cpp/test/Ice/custom/Client.cpp | 6 | ||||
-rw-r--r-- | cpp/test/Ice/custom/Collocated.cpp | 11 | ||||
-rw-r--r-- | cpp/test/Ice/custom/Makefile | 12 | ||||
-rw-r--r-- | cpp/test/Ice/custom/Server.cpp | 11 | ||||
-rw-r--r-- | cpp/test/Ice/custom/ServerAMD.cpp | 11 | ||||
-rw-r--r-- | cpp/test/Ice/custom/StringConverterI.cpp | 102 | ||||
-rw-r--r-- | cpp/test/Ice/custom/StringConverterI.h | 43 |
7 files changed, 179 insertions, 17 deletions
diff --git a/cpp/test/Ice/custom/Client.cpp b/cpp/test/Ice/custom/Client.cpp index 510eaa37d10..6bd9210dc90 100644 --- a/cpp/test/Ice/custom/Client.cpp +++ b/cpp/test/Ice/custom/Client.cpp @@ -10,6 +10,7 @@ #include <Ice/Ice.h> #include <TestCommon.h> #include <Test.h> +#include <StringConverterI.h> using namespace std; @@ -31,7 +32,10 @@ main(int argc, char** argv) try { - communicator = Ice::initialize(argc, argv); + Ice::InitializationData initData; + initData.stringConverter = new Test::StringConverterI(); + initData.wstringConverter = new Test::WstringConverterI(); + communicator = Ice::initialize(argc, argv, initData); status = run(argc, argv, communicator); } catch(const Ice::Exception& ex) diff --git a/cpp/test/Ice/custom/Collocated.cpp b/cpp/test/Ice/custom/Collocated.cpp index fc60bbaeae7..084a7999ec6 100644 --- a/cpp/test/Ice/custom/Collocated.cpp +++ b/cpp/test/Ice/custom/Collocated.cpp @@ -11,6 +11,7 @@ #include <TestCommon.h> #include <TestI.h> #include <WstringI.h> +#include <StringConverterI.h> using namespace std; @@ -37,10 +38,12 @@ main(int argc, char** argv) try { - Ice::PropertiesPtr properties = Ice::getDefaultProperties(argc, argv); - properties->setProperty("TestAdapter.Endpoints", "default -p 12010 -t 10000"); - - communicator = Ice::initialize(argc, argv); + Ice::InitializationData initData; + initData.properties = Ice::getDefaultProperties(argc, argv); + initData.properties->setProperty("TestAdapter.Endpoints", "default -p 12010 -t 10000"); + initData.stringConverter = new Test::StringConverterI(); + initData.wstringConverter = new Test::WstringConverterI(); + communicator = Ice::initialize(argc, argv, initData); status = run(argc, argv, communicator); } catch(const Ice::Exception& ex) diff --git a/cpp/test/Ice/custom/Makefile b/cpp/test/Ice/custom/Makefile index 72e5202de8e..dada88e4294 100644 --- a/cpp/test/Ice/custom/Makefile +++ b/cpp/test/Ice/custom/Makefile @@ -20,21 +20,24 @@ COBJS = Test.o \ Wstring.o \ Client.o \ AllTests.o \ - MyByteSeq.o + MyByteSeq.o \ + StringConverterI.o SOBJS = Test.o \ Wstring.o \ TestI.o \ WstringI.o \ Server.o \ - MyByteSeq.o + MyByteSeq.o \ + StringConverterI.o SAMDOBJS = TestAMD.o \ TestAMDI.o \ WstringAMD.o \ WstringAMDI.o \ ServerAMD.o \ - MyByteSeq.o + MyByteSeq.o \ + StringConverterI.o COLOBJS = Test.o \ Wstring.o \ @@ -42,7 +45,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/cpp/test/Ice/custom/Server.cpp b/cpp/test/Ice/custom/Server.cpp index 5bb712444b6..92188346034 100644 --- a/cpp/test/Ice/custom/Server.cpp +++ b/cpp/test/Ice/custom/Server.cpp @@ -11,6 +11,7 @@ #include <TestCommon.h> #include <TestI.h> #include <WstringI.h> +#include <StringConverterI.h> using namespace std; @@ -36,10 +37,12 @@ main(int argc, char** argv) try { - Ice::PropertiesPtr properties = Ice::getDefaultProperties(argc, argv); - properties->setProperty("TestAdapter.Endpoints", "default -p 12010 -t 10000"); - - communicator = Ice::initialize(argc, argv); + Ice::InitializationData initData; + initData.properties = Ice::getDefaultProperties(argc, argv); + initData.properties->setProperty("TestAdapter.Endpoints", "default -p 12010 -t 10000"); + initData.stringConverter = new Test::StringConverterI(); + initData.wstringConverter = new Test::WstringConverterI(); + communicator = Ice::initialize(argc, argv, initData); status = run(argc, argv, communicator); } catch(const Ice::Exception& ex) diff --git a/cpp/test/Ice/custom/ServerAMD.cpp b/cpp/test/Ice/custom/ServerAMD.cpp index 21608202898..b3561cf14aa 100644 --- a/cpp/test/Ice/custom/ServerAMD.cpp +++ b/cpp/test/Ice/custom/ServerAMD.cpp @@ -11,6 +11,7 @@ #include <TestCommon.h> #include <TestAMDI.h> #include <WstringAMDI.h> +#include <StringConverterI.h> using namespace std; @@ -36,10 +37,12 @@ main(int argc, char** argv) try { - Ice::PropertiesPtr properties = Ice::getDefaultProperties(argc, argv); - properties->setProperty("TestAdapter.Endpoints", "default -p 12010 -t 10000"); - - communicator = Ice::initialize(argc, argv); + Ice::InitializationData initData; + initData.properties = Ice::getDefaultProperties(argc, argv); + initData.properties->setProperty("TestAdapter.Endpoints", "default -p 12010 -t 10000"); + initData.stringConverter = new Test::StringConverterI(); + initData.wstringConverter = new Test::WstringConverterI(); + communicator = Ice::initialize(argc, argv, initData); status = run(argc, argv, communicator); } catch(const Ice::Exception& ex) diff --git a/cpp/test/Ice/custom/StringConverterI.cpp b/cpp/test/Ice/custom/StringConverterI.cpp new file mode 100644 index 00000000000..7187194249b --- /dev/null +++ b/cpp/test/Ice/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 <IceUtil/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/cpp/test/Ice/custom/StringConverterI.h b/cpp/test/Ice/custom/StringConverterI.h new file mode 100644 index 00000000000..48eae68b3be --- /dev/null +++ b/cpp/test/Ice/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 <Ice/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 |