summaryrefslogtreecommitdiff
path: root/cpp/test/Ice/stringConverter/Client.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/test/Ice/stringConverter/Client.cpp')
-rw-r--r--cpp/test/Ice/stringConverter/Client.cpp190
1 files changed, 117 insertions, 73 deletions
diff --git a/cpp/test/Ice/stringConverter/Client.cpp b/cpp/test/Ice/stringConverter/Client.cpp
index 395f8044849..10bc539c28b 100644
--- a/cpp/test/Ice/stringConverter/Client.cpp
+++ b/cpp/test/Ice/stringConverter/Client.cpp
@@ -16,13 +16,6 @@
using namespace std;
-class Client : public Ice::Application
-{
-public:
-
- virtual int run(int, char*[]);
-};
-
static bool useLocale = false;
static bool useIconv = true;
@@ -31,100 +24,148 @@ main(int argc, char* argv[])
{
#ifdef ICE_STATIC_LIBS
Ice::registerIceSSL();
+ Ice::registerIceStringConverter();
#endif
- Client app;
+ Ice::InitializationData initData = getTestInitData(argc, argv);
+
+ string narrowEncoding;
+ string wideEncoding;
-#ifndef _WIN32
+#ifdef _WIN32
+ useIconv = false;
+#else
//
// Switch to French locale
// (we just used the codeset for as default internal code for
// stringConverter below)
//
-
- useLocale = (setlocale(LC_ALL, "fr_FR.ISO8859-15") != 0
- || setlocale(LC_ALL, "fr_FR.iso885915@euro") != 0);
+ useLocale = (setlocale(LC_ALL, "fr_FR.ISO8859-15") != 0 || setlocale(LC_ALL, "fr_FR.iso885915@euro") != 0);
#endif
-#if defined(_WIN32)
- //
- // 28605 == ISO 8859-15 codepage
- //
- IceUtil::setProcessStringConverter(new IceUtil::WindowsStringConverter(28605));
- useIconv = false;
-
-#elif defined(__hpux)
- if(useLocale)
- {
- IceUtil::setProcessStringConverter(new IceUtil::IconvStringConverter<char>);
- }
- else
+ if(useIconv)
{
- IceUtil::setProcessStringConverter(new IceUtil::IconvStringConverter<char>("iso815"));
- }
- IceUtil::setProcessWstringConverter(new IceUtil::IconvStringConverter<wchar_t>("ucs4"));
-
+
+#if defined(__hpux)
+ narrowEncoding = "iso815";
+ wideEncoding = "ucs4";
+
#elif defined(_AIX)
-
- // Always big-endian
-
- if(useLocale)
- {
- IceUtil::setProcessStringConverter(new IceUtil::IconvStringConverter<char>());
- }
- else
- {
- IceUtil::setProcessStringConverter(new IceUtil::IconvStringConverter<char>("ISO8859-15"));
- }
- if(sizeof(wchar_t) == 4)
- {
- IceUtil::setProcessWstringConverter(new IceUtil::IconvStringConverter<wchar_t>("UTF-32"));
- }
- else
- {
- IceUtil::setProcessWstringConverter(new IceUtil::IconvStringConverter<wchar_t>("UTF-16"));
- }
+ // Always big-endian
+ narrowEncoding = "ISO8859-15";
+
+ if(sizeof(wchar_t) == 4)
+ {
+ wideEncoding = "UTF-32";
+ }
+ else
+ {
+ wideEncoding = "UTF-16";
+ }
#else
- if(useLocale)
- {
- IceUtil::setProcessStringConverter(new IceUtil::IconvStringConverter<char>());
- }
- else
- {
- IceUtil::setProcessStringConverter(new IceUtil::IconvStringConverter<char>("ISO8859-15"));
- }
+ narrowEncoding = "ISO8859-15";
- if(sizeof(wchar_t) == 4)
- {
+ if(sizeof(wchar_t) == 4)
+ {
# ifdef ICE_BIG_ENDIAN
- IceUtil::setProcessWstringConverter(new IceUtil::IconvStringConverter<wchar_t>("UTF-32BE"));
+ wideEncoding = "UTF-32BE";
# else
- IceUtil::setProcessWstringConverter(new IceUtil::IconvStringConverter<wchar_t>("UTF-32LE"));
+ wideEncoding = "UTF-32LE";
# endif
- }
- else
- {
+ }
+ else
+ {
# ifdef ICE_BIG_ENDIAN
- IceUtil::setProcessWstringConverter(new IceUtil::IconvStringConverter<wchar_t>("UTF-16BE"));
+ wideEncoding = "UTF-16BE";
# else
- IceUtil::setProcessWstringConverter(new IceUtil::IconvStringConverter<wchar_t>("UTF-16LE"));
+ wideEncoding = "UTF-16LE";
# endif
+ }
+#endif
}
+
+ {
+#ifdef _WIN32
+ //
+ // 28605 == ISO 8859-15 codepage
+ //
+ setProcessStringConverter(Ice::createWindowsStringConverter(28605));
+#else
+ if(useLocale)
+ {
+ setProcessStringConverter(Ice::createIconvStringConverter<char>(""));
+ }
+ else
+ {
+ setProcessStringConverter(Ice::createIconvStringConverter<char>(narrowEncoding));
+ }
+
+ setProcessWstringConverter(Ice::createIconvStringConverter<wchar_t>(wideEncoding));
+
#endif
- return app.main(argc, argv);
-}
-int
-Client::run(int, char*[])
-{
- Test::MyObjectPrx proxy =
- Test::MyObjectPrx::uncheckedCast(communicator()->stringToProxy("test:default -p 12010"));
+ Ice::CommunicatorPtr communicator = Ice::initialize(initData);
+ Test::MyObjectPrxPtr proxy =
+ ICE_UNCHECKED_CAST(Test::MyObjectPrx,
+ communicator->stringToProxy("test:" + getTestEndpoint(communicator, 0)));
+
+ char oe = char(0xBD); // A single character in ISO Latin 9
+ string msg = string("tu me fends le c") + oe + "ur!";
+ cout << "testing string converter";
+ if(useLocale)
+ {
+ cout << " (using locale)";
+ }
+ if(useIconv)
+ {
+ cout << " (using iconv)";
+ }
+ cout << "... " << flush;
+ wstring wmsg = proxy->widen(msg);
+ test(proxy->narrow(wmsg) == msg);
+ test(wmsg.size() == msg.size());
+
+ // Test stringToIdentity and identityToString
+
+ string identStr = "cat/" + msg;
+ Ice::Identity ident = Ice::stringToIdentity(identStr);
+ test(ident.name == msg);
+ test(ident.category == "cat");
+ test(identityToString(ident, Ice::ICE_ENUM(ToStringMode, Unicode)) == identStr);
+
+ identStr = identityToString(ident, Ice::ICE_ENUM(ToStringMode, ASCII));
+ test(identStr == "cat/tu me fends le c\\u0153ur!");
+ test(Ice::stringToIdentity(identStr) == ident);
+ identStr = identityToString(ident, Ice::ICE_ENUM(ToStringMode, Compat));
+ test(identStr == "cat/tu me fends le c\\305\\223ur!");
+ test(Ice::stringToIdentity(identStr) == ident);
+
+ communicator->destroy();
+ cout << "ok" << endl;
+ }
+
+ Ice::setProcessStringConverter(ICE_NULLPTR);
+ Ice::setProcessWstringConverter(Ice::createUnicodeWstringConverter());
+
+ string propValue = "Ice:createStringConverter";
+ if(useIconv && !useLocale)
+ {
+ propValue += " iconv=" + narrowEncoding + "," + wideEncoding;
+ }
+ propValue += " windows=28605";
+
+ initData.properties->setProperty("Ice.Plugin.IceStringConverter", propValue);
+
+ Ice::CommunicatorPtr communicator = Ice::initialize(initData);
+ Test::MyObjectPrxPtr proxy =
+ ICE_UNCHECKED_CAST(Test::MyObjectPrx,
+ communicator->stringToProxy("test:" + getTestEndpoint(communicator, 0)));
char oe = char(0xBD); // A single character in ISO Latin 9
string msg = string("tu me fends le c") + oe + "ur!";
- cout << "testing string converter";
+ cout << "testing string converter plug-in";
if(useLocale)
{
cout << " (using locale)";
@@ -138,6 +179,9 @@ Client::run(int, char*[])
test(proxy->narrow(wmsg) == msg);
test(wmsg.size() == msg.size());
cout << "ok" << endl;
+
proxy->shutdown();
+ communicator->destroy();
+
return EXIT_SUCCESS;
}