|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Java Captain extension plugin for Comms Module tests |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <string> |
|
19 #include <iostream> |
|
20 #include <unistd.h> |
|
21 |
|
22 #include "comms.h" |
|
23 #include "logger.h" |
|
24 #include "coreinterface.h" |
|
25 #include "javacommonutils.h" |
|
26 #include "exceptionbase.h" |
|
27 |
|
28 #include "commsextensionplugin.h" |
|
29 |
|
30 using namespace std; |
|
31 |
|
32 const int MODULE_ID_A = 900; |
|
33 const int MODULE_ID_B = 901; |
|
34 const int MODULE_ID_DATA_CHECK = 902; |
|
35 const int MODULE_ID_NO_REPLY = 903; |
|
36 const int MODULE_ID_SLEEP_1S = 1000; |
|
37 const int MODULE_ID_SLEEP_5S = 5000; |
|
38 const int MODULE_ID_SLEEP_10S = 10000; |
|
39 |
|
40 #ifdef __SYMBIAN32__ |
|
41 java::captain::ExtensionPluginInterface* getExtensionPlugin() |
|
42 { |
|
43 #else |
|
44 extern "C" java::captain::ExtensionPluginInterface* getExtensionPlugin() |
|
45 { |
|
46 #endif |
|
47 return new java::comms::CommsExtensionPlugin(); |
|
48 } |
|
49 |
|
50 namespace java |
|
51 { |
|
52 namespace comms |
|
53 { |
|
54 // helper method for conversion |
|
55 std::string wstringToUtf8(const std::wstring& str) |
|
56 { |
|
57 string result; |
|
58 try |
|
59 { |
|
60 char* utf8 = java::util::JavaCommonUtils::wstringToUtf8(str); |
|
61 result.assign(utf8); |
|
62 delete[] utf8; |
|
63 } |
|
64 catch (java::util::ExceptionBase& e) |
|
65 { |
|
66 ELOG1(EJavaComms, "wstringToUtf8 failed: %s", e.toString().c_str()); |
|
67 } |
|
68 return result; |
|
69 } |
|
70 |
|
71 CommsExtensionPlugin::CommsExtensionPlugin() : mCore(0), mComms(0) |
|
72 { |
|
73 JELOG2(EJavaComms); |
|
74 } |
|
75 |
|
76 CommsExtensionPlugin::~CommsExtensionPlugin() |
|
77 { |
|
78 JELOG2(EJavaComms); |
|
79 } |
|
80 |
|
81 void CommsExtensionPlugin::startPlugin(CoreInterface* core) |
|
82 { |
|
83 JELOG2(EJavaComms); |
|
84 mCore = core; |
|
85 mComms = core->getComms(); |
|
86 |
|
87 mComms->registerListener(PLUGIN_ID_JAVACAPTAIN_COMMS_TESTER_C, this); |
|
88 |
|
89 mComms->registerListener(MODULE_ID_A, this); |
|
90 mComms->registerListener(MODULE_ID_B, this); |
|
91 mComms->registerListener(MODULE_ID_DATA_CHECK, this); |
|
92 mComms->registerListener(MODULE_ID_NO_REPLY, this); |
|
93 mComms->registerListener(MODULE_ID_SLEEP_1S, this); |
|
94 mComms->registerListener(MODULE_ID_SLEEP_5S, this); |
|
95 mComms->registerListener(MODULE_ID_SLEEP_10S, this); |
|
96 } |
|
97 |
|
98 void CommsExtensionPlugin::stopPlugin() |
|
99 { |
|
100 JELOG2(EJavaComms); |
|
101 mComms->unregisterListener(PLUGIN_ID_JAVACAPTAIN_COMMS_TESTER_C, this); |
|
102 |
|
103 mComms->unregisterListener(MODULE_ID_A, this); |
|
104 mComms->unregisterListener(MODULE_ID_B, this); |
|
105 mComms->unregisterListener(MODULE_ID_DATA_CHECK, this); |
|
106 mComms->unregisterListener(MODULE_ID_NO_REPLY, this); |
|
107 mComms->unregisterListener(MODULE_ID_SLEEP_1S, this); |
|
108 mComms->unregisterListener(MODULE_ID_SLEEP_5S, this); |
|
109 mComms->unregisterListener(MODULE_ID_SLEEP_10S, this); |
|
110 |
|
111 mCore = 0; |
|
112 mComms = 0; |
|
113 } |
|
114 |
|
115 void CommsExtensionPlugin::processMessage(CommsMessage& aMessage) |
|
116 { |
|
117 /* |
|
118 LOG1(EJavaComms, EInfo, "processMessage, sender = %d", aMessage.getSender()); |
|
119 LOG1(EJavaComms, EInfo, "processMessage, messageId = %d", aMessage.getMessageId()); |
|
120 LOG1(EJavaComms, EInfo, "processMessage, moduleId = %d", aMessage.getModuleId()); |
|
121 LOG1(EJavaComms, EInfo, "processMessage, messageRef= %d", aMessage.getMessageRef()); |
|
122 */ |
|
123 switch (aMessage.getModuleId()) |
|
124 { |
|
125 case MODULE_ID_DATA_CHECK: |
|
126 { |
|
127 // keep this in sync with java side test case |
|
128 |
|
129 const string str("abcdefghijklmnopqrstyvwxyz"); |
|
130 int num = 0xCAFEBABE; |
|
131 // latin small letter a with diaeresis, latin small letter a with ring above, latin small letter o with diaeresis |
|
132 const string utf8("\xC3\xA4 \xC3\xA5 \xC3\xB6 \xE2\x82\xAC"); // ä å ö € |
|
133 const wstring utf16(L"\u00E4 \u00E5 \u00F6 \u20AC"); |
|
134 |
|
135 // Japanese Yen symbol, Roman AE with acute accent, Greek Capital Alpha, Greek Capital Omega, |
|
136 // Euro symbol, Rupee symbol, Cyrillic capital letter DZHE, Arabic letter TEH |
|
137 const wstring symbols = L"\u00a5\u01FC\u0391\u03A9\u20ac\u20a8\u040F\u062A"; |
|
138 const string symbols_utf8 = wstringToUtf8(symbols); |
|
139 |
|
140 // devanagari letter a, tibetan digit zero, katakana letter ya |
|
141 const wstring letters = L"\u0905 \u0F20 \u30E4"; |
|
142 const string letters_utf8_manually("\xE0\xA4\x85 \xE0\xBC\xA0 \xE3\x83\xA4"); |
|
143 const string letters_utf8 = wstringToUtf8(letters); |
|
144 |
|
145 // array of all 8-bit values |
|
146 const int len = 0xff; |
|
147 char bytes[len]; |
|
148 for (int i=0; i < len; i++) |
|
149 { |
|
150 bytes[i] = i; |
|
151 } |
|
152 |
|
153 string s, u, sym, let, sbytes; |
|
154 wstring w, wsym, wlet; |
|
155 int i, zero, one, max; |
|
156 aMessage >> s >> i >> zero >> one >> max >> u >> w >> wsym >> sym; |
|
157 aMessage >> let >> wlet; // read in 'wrong' order |
|
158 aMessage >> sbytes; |
|
159 |
|
160 const char* bytes_out = sbytes.data(); |
|
161 |
|
162 if (str.compare(s)!=0 || num != i || zero != 0 || one != 1 || max != 0xFFFFFFFF || |
|
163 utf8.compare(u)!=0 || utf16.compare(w)!=0 || symbols.compare(wsym)!=0 || symbols_utf8.compare(sym)!=0 || |
|
164 letters_utf8.compare(let)!=0 || letters_utf8_manually.compare(let)!=0 || letters.compare(wlet)!=0 || |
|
165 memcmp(bytes, bytes_out, len) != 0) |
|
166 { |
|
167 ELOG(EJavaComms, "Data does not match - test will fail !!!!!!!!!"); |
|
168 mReply = aMessage; |
|
169 mReply.setReceiver(aMessage.getSender()); |
|
170 mComms->send(mReply); |
|
171 } |
|
172 else |
|
173 { |
|
174 CommsMessage reply; |
|
175 reply.setReceiver(aMessage.getSender()); |
|
176 reply.setMessageId(aMessage.getMessageId()); |
|
177 reply.setMessageRef(aMessage.getMessageRef()); |
|
178 |
|
179 const string input("ABCDEFGHIJKLMNOPQRSTYWXYZ"); |
|
180 int j = 0xDEADBEEF; |
|
181 |
|
182 reply << input << j << 0 << 1 << (int)0xFFFFFFFF << letters_utf8_manually; |
|
183 reply << symbols << utf16 << utf8 << sbytes; |
|
184 mComms->send(reply); |
|
185 } |
|
186 } |
|
187 break; |
|
188 |
|
189 case MODULE_ID_NO_REPLY: |
|
190 break; |
|
191 |
|
192 case MODULE_ID_SLEEP_1S: |
|
193 case MODULE_ID_SLEEP_5S: |
|
194 case MODULE_ID_SLEEP_10S: |
|
195 usleep(1000*aMessage.getModuleId()); |
|
196 // fall through |
|
197 #ifdef __SYMBIAN32__ |
|
198 break; |
|
199 #endif |
|
200 default: |
|
201 mReply = aMessage; |
|
202 mReply.setReceiver(aMessage.getSender()); |
|
203 mComms->send(mReply); |
|
204 break; |
|
205 } |
|
206 } |
|
207 |
|
208 |
|
209 } // namespace comms |
|
210 } // namespace java |
|
211 |
|
212 |