blob: 67767701e80a3194354818f8db480af4d38f56d3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
// **********************************************************************
//
// Copyright (c) 2003-2007 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 <Ice/Ice.h>
#include <TestCommon.h>
#include <Test.h>
#include <Ice/IconvStringConverter.h>
#include <iostream>
#include <locale.h>
using namespace std;
class Client : public Ice::Application
{
public:
virtual int run(int, char*[]);
};
//
// Server side is pure unicode
//
class MyObjectI : public Test::MyObject
{
public:
virtual wstring widen(const string& msg, const Ice::Current&)
{
const Ice::Byte* cmsg = reinterpret_cast<const Ice::Byte*>(msg.c_str());
if(!IceUtil::isLegalUTF8Sequence(cmsg, cmsg + msg.size()))
{
throw Test::BadEncodingException();
}
return IceUtil::stringToWstring(msg);
}
virtual string narrow(const wstring& wmsg, const Ice::Current&)
{
return IceUtil::wstringToString(wmsg);
}
};
int
main(int argc, char* argv[])
{
Client app;
//
// Switch to French locale
// (we just used the codeset for as default internal code for
// initData.stringConverter below)
//
setlocale(LC_ALL, "fr_FR.ISO8859-15");
Ice::InitializationData initData;
#if defined(__hpux)
initData.stringConverter = new Ice::IconvStringConverter<char>("iso815");
initData.wstringConverter = new Ice::IconvStringConverter<wchar_t>("ucs4");
#else
#ifdef _WIN32
initData.stringConverter = new Ice::IconvStringConverter<char>("ISO8859-15");
#else
initData.stringConverter = new Ice::IconvStringConverter<char>;
#endif
if(sizeof(wchar_t) == 4)
{
#ifdef ICE_BIG_ENDIAN
initData.wstringConverter = new Ice::IconvStringConverter<wchar_t>("UTF-32BE");
#else
initData.wstringConverter = new Ice::IconvStringConverter<wchar_t>("UTF-32LE");
#endif
}
else
{
#ifdef ICE_BIG_ENDIAN
initData.wstringConverter = new Ice::IconvStringConverter<wchar_t>("UTF-16BE");
#else
initData.wstringConverter = new Ice::IconvStringConverter<wchar_t>("UTF-16LE");
#endif
}
#endif
return app.main(argc, argv, initData);
}
int
Client::run(int, char*[])
{
//
// Create server communicator and OA
//
Ice::CommunicatorPtr serverCommunicator = Ice::initialize();
Ice::ObjectAdapterPtr oa = serverCommunicator->createObjectAdapterWithEndpoints("MyOA", "tcp -h localhost");
Ice::ObjectPtr servant = new MyObjectI;
Test::MyObjectPrx serverPrx = Test::MyObjectPrx::uncheckedCast(oa->addWithUUID(servant));
oa->activate();
//
// Get a prx in the client's communicator
//
Test::MyObjectPrx clientPrx =
Test::MyObjectPrx::uncheckedCast(communicator()->stringToProxy(serverPrx->ice_toString()));
char oe = char(0xBD); // A single character in ISO Latin 9
string msg = string("tu me fends le c") + oe + "ur!";
cout << "testing iconv string converter..." << flush;
wstring wmsg = clientPrx->widen(msg);
test(clientPrx->narrow(wmsg) == msg);
test(wmsg.size() == msg.size());
cout << "ok" << endl;
//
// destroy server communicator
//
serverCommunicator->destroy();
return EXIT_SUCCESS;
}
|