1%% 2%% %CopyrightBegin% 3%% 4%% Copyright Ericsson AB 1999-2016. All Rights Reserved. 5%% 6%% Licensed under the Apache License, Version 2.0 (the "License"); 7%% you may not use this file except in compliance with the License. 8%% You may obtain a copy of the License at 9%% 10%% http://www.apache.org/licenses/LICENSE-2.0 11%% 12%% Unless required by applicable law or agreed to in writing, software 13%% distributed under the License is distributed on an "AS IS" BASIS, 14%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15%% See the License for the specific language governing permissions and 16%% limitations under the License. 17%% 18%% %CopyrightEnd% 19%% 20%% 21%%----------------------------------------------------------------- 22%% 23%% Description: 24%% Test suite for the CDR encode/decode functions 25%% 26%%----------------------------------------------------------------- 27-module(cdrcoding_10_SUITE). 28 29-include("idl_output/Module.hrl"). 30-include_lib("common_test/include/ct.hrl"). 31-include_lib("orber/include/corba.hrl"). 32-include_lib("orber/src/orber_iiop.hrl"). 33 34-define(default_timeout, test_server:minutes(20)). 35 36%%----------------------------------------------------------------- 37%% External exports 38%%----------------------------------------------------------------- 39-export([all/0, suite/0,groups/0,init_per_group/2,end_per_group/2]). 40 41%%----------------------------------------------------------------- 42%% Internal exports 43%%----------------------------------------------------------------- 44-compile(export_all). 45 46%%----------------------------------------------------------------- 47%% Func: all/1 48%% Args: 49%% Returns: 50%%----------------------------------------------------------------- 51suite() -> [{ct_hooks,[ts_install_cth]}]. 52 53all() -> 54 cases(). 55 56groups() -> 57 [{types, [], 58 [do_register, null_type, void_type, principal_type, 59 objref_type, struct_type, union_type, string_type, 60 array_type, any_type, typecode_type, alias_type, 61 exception_type, do_unregister]}]. 62 63init_per_group(_GroupName, Config) -> 64 Config. 65 66end_per_group(_GroupName, Config) -> 67 Config. 68 69 70cases() -> 71 [{group, types}, reply, cancel_request, 72 close_connection, message_error]. 73%% request, locate_request, locate_reply]. 74 75%%----------------------------------------------------------------- 76%% Init and cleanup functions. 77%%----------------------------------------------------------------- 78 79init_per_testcase(_Case, Config) -> 80 Path = code:which(?MODULE), 81 code:add_pathz(filename:join(filename:dirname(Path), "idl_output")), 82 Dog=test_server:timetrap(?default_timeout), 83 [{watchdog, Dog}|Config]. 84 85 86end_per_testcase(_Case, Config) -> 87 Path = code:which(?MODULE), 88 code:del_path(filename:join(filename:dirname(Path), "idl_output")), 89 Dog = proplists:get_value(watchdog, Config), 90 test_server:timetrap_cancel(Dog), 91 ok. 92 93init_per_suite(Config) when is_list(Config) -> 94 orber:jump_start(0), 95 if 96 is_list(Config) -> 97 Config; 98 true -> 99 exit("Config not a list") 100 end. 101 102end_per_suite(Config) when is_list(Config) -> 103 orber:jump_stop(), 104 Config. 105 106%%----------------------------------------------------------------- 107%% Test Case: type encoding tests 108%% Description: Just testing the complex types, the others are 109%% tested in the cdrlib SUITE. 110%%----------------------------------------------------------------- 111%types(Config) when list(Config) -> 112% 'oe_orber_test':'oe_register'(), 113% null_type(), 114% void_type(), 115% principal_type(), 116% objref_type(), 117% struct_type(), 118% union_type(), 119% string_type(), 120% array_type(), 121% any_type(), 122% typecode_type(), 123% alias_type(), 124% exception_type(), 125% 'oe_orber_test':'oe_unregister'(), 126% ok. 127 128do_register(Config) when is_list(Config) -> 129 io:format("Pwd: ~p, mod: ~p~n",[c:pwd(), c:m('oe_orber_test')]), 130 'oe_orber_test':'oe_register'(), 131 ok. 132 133do_unregister(Config) when is_list(Config) -> 134 'oe_orber_test':'oe_unregister'(), 135 ok. 136%%----------------------------------------------------------------- 137%% Encode/decode test of type: null 138%%----------------------------------------------------------------- 139null_type(Config) when is_list(Config) -> 140 B = cdr_encode:enc_type(#giop_env{version = {1, 0}}, 'tk_null', 'null'), 141 {'null', <<>>, _} = cdr_decode:dec_type('tk_null', {1, 0}, B, 0, big), 142 ok. 143 144%%----------------------------------------------------------------- 145%% Encode/decode test of type: void 146%%----------------------------------------------------------------- 147void_type(Config) when is_list(Config) -> 148 B = cdr_encode:enc_type(#giop_env{version = {1, 0}}, 'tk_void', 'ok'), 149 {'ok', <<>>, _} = cdr_decode:dec_type('tk_void', {1, 0}, B, 0, big), 150 ok. 151 152%%----------------------------------------------------------------- 153%% Encode/decode test of type: principal 154%%----------------------------------------------------------------- 155principal_type(Config) when is_list(Config) -> 156 B0 = cdr_encode:enc_type(#giop_env{version = {1, 0}}, 'tk_Principal', "principal"), 157 {"principal", <<>>, _} = cdr_decode:dec_type('tk_Principal', {1, 0}, B0, 0, big), 158 B1 = cdr_encode:enc_type(#giop_env{version = {1, 0}}, 'tk_Principal', ""), 159 {"", <<>>, _} = cdr_decode:dec_type('tk_Principal', {1, 0}, B1, 0, big), 160 B2 = cdr_encode:enc_type(#giop_env{version = {1, 0}}, 'tk_Principal', "principal"), 161 {"principal", <<>>, _} = 162 cdr_decode:dec_type('tk_Principal', {1, 0}, B2, 0, big), 163 ok. 164 165%%----------------------------------------------------------------- 166%% Encode/decode test of type: object reference 167%%----------------------------------------------------------------- 168version() -> #'IIOP_Version'{major=1,minor=0}. 169 170objref(0) -> 171 PB = #'IIOP_ProfileBody_1_0'{iiop_version=version(), 172 host="my.hostname.org", 173 port=4040, 174 object_key="ExternalKey: which is an arbitary octet sequence"}, 175 TP = #'IOP_TaggedProfile'{tag=?TAG_INTERNET_IOP, profile_data=PB}, 176 #'IOP_IOR'{type_id="IDL:Module/Interface:1.0", profiles=[TP]}; 177objref(1) -> 178 K = corba_fake_mk_objkey("IDL:Module/Interface:1.0", key, 179 list_to_pid("<0.100.0>")), 180 PB = #'IIOP_ProfileBody_1_0'{iiop_version=version(), 181 host="my.hostname.org", 182 port=4040, 183 object_key=K}, 184 TP = #'IOP_TaggedProfile'{tag=?TAG_INTERNET_IOP, profile_data=PB}, 185 #'IOP_IOR'{type_id="IDL:Module/Interface:1.0", profiles=[TP]}; 186objref(2) -> 187 K = corba_fake_mk_objkey("IDL:Module/Interface:1.0", registered, 188 list_to_atom("orber_nameservice")), 189 PB = #'IIOP_ProfileBody_1_0'{iiop_version=version(), 190 host="my.hostname.org", 191 port=4040, 192 object_key=K}, 193 TP = #'IOP_TaggedProfile'{tag=?TAG_INTERNET_IOP, profile_data=PB}, 194 #'IOP_IOR'{type_id="IDL:Module/Interface:1.0", profiles=[TP]}. 195 196objref_type(Config) when is_list(Config) -> 197 T = {'tk_objref', "IDL:Module/Interface:1.0", "Interface"}, 198 Objref0 = objref(0), 199 B0 = cdr_encode:enc_type(#giop_env{version = {1, 0}}, T, Objref0), 200 {Objref0, <<>>, _} = cdr_decode:dec_type(T, {1, 0}, B0, 0, big), 201 Objref1 = objref(1), 202 B1 = cdr_encode:enc_type(#giop_env{version = {1, 0}}, T, Objref1), 203 {Objref1, <<>>, _} = cdr_decode:dec_type(T, {1, 0}, B1, 0, big), 204 Objref2 = objref(2), 205 B2 = cdr_encode:enc_type(#giop_env{version = {1, 0}}, T, Objref2), 206 {Objref2, <<>>, _} = cdr_decode:dec_type(T, {1, 0}, B2, 0, big), 207 ok. 208 209 210 211%%----------------------------------------------------------------- 212%% Encode/decode test of type: struct 213%%----------------------------------------------------------------- 214struct_type(Config) when is_list(Config) -> 215 T0 = {'tk_struct',"IDL:Module/Struct0:1.0", "Module_Struct0", 216 [{"long", 'tk_long'}, {"short", 'tk_short'}, {"character", 'tk_char'}]}, 217 S0 = #'Module_Struct0'{l=-4711, s=17, c=$a}, 218 B0 = cdr_encode:enc_type({1, 0}, T0, S0), 219 {S0, <<>>, _} = cdr_decode:dec_type(T0, {1, 0}, B0, 0, big), 220 221 T1 = {'tk_struct', "IDL:Module/Struct1:1.0", "Module_Struct1", 222 [{"string", {'tk_string', 0}}, {"ushort", 'tk_ushort'}, {"ulong", 'tk_ulong'}]}, 223 S1 = #'Module_Struct1'{s="Hi !!!!", us=17, ul=4711}, 224 B1 = cdr_encode:enc_type({1, 0}, T1, S1), 225 {S1, <<>>, _} = cdr_decode:dec_type(T1, {1, 0}, B1, 0, big), 226 227 T2 = {'tk_struct', "IDL:Module/Struct2:1.0", "Module_Struct2", 228 [{"long_sequence", {'tk_sequence', 'tk_long', 0}}, 229 {"enum", {'tk_enum', "IDL:Module/Enum:1.0", "Module_Enum", ["horse", "pig", "cow"]}}, 230 {"octet", 'tk_octet'}]}, 231 S2 = #'Module_Struct2'{long_sequence=[4711, 350000, 0, -3030, -600000], e=cow, o=$X}, 232 B2 = cdr_encode:enc_type({1, 0}, T2, S2), 233 {S2, <<>>, _} = cdr_decode:dec_type(T2, {1, 0}, B2, 0, big), 234 ok. 235 236%%----------------------------------------------------------------- 237%% Encode/decode test of type: union 238%%----------------------------------------------------------------- 239union_type(Config) when is_list(Config) -> 240 T0 = {'tk_union', "IDL:Module/Union:1.0", "Union", 'tk_short', 2, 241 [{0, "First", 'tk_short'}, 242 {1, "Second", {'tk_string', 0}}, 243 {2, "Third", 'tk_char'}]}, 244 S0 = #'Module_Union'{label=1, value="Foo Bar !"}, 245 B0 = cdr_encode:enc_type({1, 0}, T0, S0), 246 {S0, <<>>, _} = cdr_decode:dec_type(T0, {1, 0}, B0, 0, big), 247 S1 = #'Module_Union'{label=0, value=-17}, 248 B1 = cdr_encode:enc_type({1, 0}, T0, S1), 249 {S1, <<>>, _} = cdr_decode:dec_type(T0, {1, 0}, B1, 0, big), 250 S2 = #'Module_Union'{label=2, value=$X}, 251 B2 = cdr_encode:enc_type({1, 0}, T0, S2), 252 {S2, <<>>, _} = cdr_decode:dec_type(T0, {1, 0}, B2, 0, big), 253 T1 = {'tk_union', "IDL:Module/Union1:1.0", "Union1", 254 {'tk_enum', "IDL:Module/Enum:1.0", 255 "Module_Enum", ["horse", "pig", "cow"]}, "pig", 256 [{"horse", "First", 'tk_ushort'}, 257 {"pig", "Second", {'tk_sequence', {'tk_string', 0}, 0}}, 258 {"cow", "Third", {'tk_enum', "IDL:Module/Enum1:1.0", 259 "Module_Enum1", ["orange", "banana", "apple"]}}]}, 260 S3 = #'Module_Union1'{label=pig, value=["Foo", "Bar", "!"]}, 261 B3 = cdr_encode:enc_type({1, 0}, T1, S3), 262 {S3, <<>>, _} = cdr_decode:dec_type(T1, {1, 0}, B3, 0, big), 263 S4 = #'Module_Union1'{label=cow, value=apple}, 264 B4 = cdr_encode:enc_type({1, 0}, T1, S4), 265 {S4, <<>>, _} = cdr_decode:dec_type(T1, {1, 0}, B4, 0, big), 266 S5 = #'Module_Union1'{label=horse, value=17}, 267 B5 = cdr_encode:enc_type({1, 0}, T1, S5), 268 {S5, <<>>, _} = cdr_decode:dec_type(T1, {1, 0}, B5, 0, big), 269 T2 = {'tk_union', "IDL:Module/Union2:1.0", "Union2", 270 {'tk_enum', "IDL:Module/Enum:1.0", 271 "Module_Enum", ["horse", "pig", "cow"]}, "pig", 272 [{"horse", "First", {'tk_array', 'tk_long', 3}}, 273 {"pig", "Second", 274 {'tk_union', "IDL:Module/Union:1.0", "Union", 'tk_short', 2, 275 [{0, "First", 'tk_short'}, 276 {1, "Second", {'tk_string', 0}}, 277 {2, "Third", 'tk_char'}]}}, 278 {"cow", "Third", {'tk_union', "IDL:Module/Union1:1.0", "Union1", 279 {'tk_enum', "IDL:Module/Enum:1.0", 280 "Module_Enum", ["horse", "pig", "cow"]}, "pig", 281 [{"horse", "First", 'tk_ushort'}, 282 {"pig", "Second", {'tk_sequence', 283 {'tk_string', 0}, 0}}, 284 {"cow", "Third", {'tk_enum', 285 "IDL:Module/Enum1:1.0", 286 "Module_Enum1", 287 ["orange", "banana", 288 "apple"]}}]}}]}, 289 S6 = #'Module_Union2'{label=pig, value=#'Module_Union'{label=0, value=-17}}, 290 B6 = cdr_encode:enc_type({1, 0}, T2, S6), 291 {S6, <<>>, _} = cdr_decode:dec_type(T2, {1, 0}, B6, 0, big), 292 S7 = #'Module_Union2'{label=cow, value=#'Module_Union1'{label=pig, 293 value=["Foo", "Bar", "!"]}}, 294 B7 = cdr_encode:enc_type({1, 0}, T2, S7), 295 {S7, <<>>, _} = cdr_decode:dec_type(T2, {1, 0}, B7, 0, big), 296 S8 = #'Module_Union2'{label=horse, value={-17, 1234567890, -987654321}}, 297 B8 = cdr_encode:enc_type({1, 0}, T2, S8), 298 {S8, <<>>, _} = cdr_decode:dec_type(T2, {1, 0}, B8, 0, big), 299 ok. 300 301%%----------------------------------------------------------------- 302%% Encode/decode test of type: string 303%%----------------------------------------------------------------- 304string_type(Config) when is_list(Config) -> 305 S0 = "Foo Bar ???", 306 B0 = cdr_encode:enc_type({1, 0}, {'tk_string', 0}, S0), 307 {S0, <<>>, _} = cdr_decode:dec_type({'tk_string', 0}, {1, 0}, B0, 0, big), 308 S1 = "Yes, Foo Bar !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! more than 5000 characters", 309 B1 = cdr_encode:enc_type({1, 0}, {'tk_string', 0}, S1), 310 {S1, <<>>, _} = cdr_decode:dec_type({'tk_string', 0}, {1, 0}, B1, 0, big), 311 S2 = "", 312 B2 = cdr_encode:enc_type({1, 0}, {'tk_string', 0}, S2), 313 {S2, <<>>, _} = cdr_decode:dec_type({'tk_string', 0}, {1, 0}, B2, 0, big), 314 S3 = "\0", 315 B3 = cdr_encode:enc_type({1, 0}, {'tk_string', 0}, S3), 316 {S3, <<>>, _} = cdr_decode:dec_type({'tk_string', 0}, {1, 0}, B3, 0, big), 317 S4 = "~n", 318 B4 = cdr_encode:enc_type({1, 0}, {'tk_string', 0}, S4), 319 {S4, <<>>, _} = cdr_decode:dec_type({'tk_string', 0}, {1, 0}, B4, 0, big), 320 ok. 321 322%%----------------------------------------------------------------- 323%% Encode/decode test of type: array 324%%----------------------------------------------------------------- 325array_type(Config) when is_list(Config) -> 326 T0 = {'tk_array', 'tk_long', 5}, 327 S0 = {-100, 0, 30000, -900100900, 123456789}, 328 B0 = cdr_encode:enc_type(#giop_env{version = {1, 0}}, T0, S0), 329 {S0, <<>>, _} = cdr_decode:dec_type(T0, {1, 0}, B0, 0, big), 330 T1 = {'tk_array', {'tk_enum', "IDL:Module/Enum:1.0", "Module_Enum", ["horse", "pig", "cow"]}, 2}, 331 S1 = {pig, cow}, 332 B1 = cdr_encode:enc_type(#giop_env{version = {1, 0}}, T1, S1), 333 {S1, <<>>, _} = cdr_decode:dec_type(T1, {1, 0}, B1, 0, big), 334 T2 = {'tk_array', {'tk_union', "IDL:Module/Union:1.0", "Union", 335 {'tk_enum', "IDL:Module/Enum:1.0", "Module_Enum", ["horse", "pig", "cow"]}, "pig", 336 [{"horse", "First", 'tk_ushort'}, 337 {"pig", "Second", {'tk_sequence', {'tk_string', 0}, 0}}, 338 {"cow", "Third", {'tk_enum', "IDL:Module/Enum1:1.0", 339 "Module_Enum1", ["orange", "banana", "apple"]}}]}, 2}, 340 S2 = {#'Module_Union'{label=cow, value=banana}, #'Module_Union'{label=pig, value=["This", "is", "a", "test", ""]}}, 341 B2 = cdr_encode:enc_type(#giop_env{version = {1, 0}}, T2, S2), 342 {S2, <<>>, _} = cdr_decode:dec_type(T2, {1, 0}, B2, 0, big), 343 T3 = {'tk_array', {'tk_objref', "IDL:Module/Interface:1.0", "Interface"}, 3}, 344 S3 = {objref(0), objref(1), objref(2)}, 345 B3 = cdr_encode:enc_type(#giop_env{version = {1, 0}}, T3, S3), 346 {S3, <<>>, _} = cdr_decode:dec_type(T3, {1, 0}, B3, 0, big), 347 ok. 348%%----------------------------------------------------------------- 349%% Encode/decode test of type: TypeCode 350%%----------------------------------------------------------------- 351any_type(Config) when is_list(Config) -> 352 T = 'tk_any', 353 TC = {'tk_struct', "IDL:Module/Struct2:1.0", "Module_Struct2", 354 [{"long_sequence", {'tk_sequence', 'tk_long', 0}}, 355 {"enum", {'tk_enum', "IDL:Module/Enum:1.0", "Module_Enum", 356 ["horse", "pig", "cow"]}}, 357 {"octet", 'tk_octet'}]}, 358 S = #'Module_Struct2'{long_sequence=[4711, 350000, 0, -3030, -600000], 359 e=cow, o=$X}, 360 Any = #any{typecode=TC,value=S}, 361 B = cdr_encode:enc_type(#giop_env{version = {1, 0}}, T,Any), 362 {Any, <<>>, _} = cdr_decode:dec_type(T, {1, 0}, B, 0, big), 363 TC1 = {'tk_array', {'tk_union', "IDL:Module/Union:1.0", "Union", 364 {'tk_enum', "IDL:Module/Enum:1.0", "Module_Enum", 365 ["horse", "pig", "cow"]}, 1, 366 [{"horse", "First", 'tk_ushort'}, 367 {"pig", "Second", {'tk_sequence', {'tk_string', 0}, 0}}, 368 {"cow", "Third", {'tk_enum', "IDL:Module/Enum1:1.0", 369 "Module_Enum1", ["orange", "banana", 370 "apple"]}}]},2}, 371 S1 = {#'Module_Union'{label=cow, value=banana}, #'Module_Union'{label=pig, value=["This", "is", "a", "test", ""]}}, 372 Any1 = #any{typecode=TC1,value=S1}, 373 B1 = cdr_encode:enc_type(#giop_env{version = {1, 0}}, T,Any1), 374 {Any1, <<>>, _} = cdr_decode:dec_type(T, {1, 0}, B1, 0, big), 375 ok. 376 377 378%%----------------------------------------------------------------- 379%% Encode/decode test of type: TypeCode 380%%----------------------------------------------------------------- 381typecode_type(Config) when is_list(Config) -> 382 T = 'tk_TypeCode', 383 TC = {'tk_array', {'tk_union', "IDL:Module/Union:1.0", "Union", 384 {'tk_enum', "IDL:Module/Enum:1.0", "Module_Enum", 385 ["horse", "pig", "cow"]}, 1, 386 [{"horse", "First", 'tk_ushort'}, 387 {"pig", "Second", {'tk_sequence', {'tk_string', 0}, 0}}, 388 {"cow", "Third", {'tk_enum', "IDL:Module/Enum1:1.0", 389 "Module_Enum1", ["orange", "banana", 390 "apple"]}}]}, 10}, 391 B = cdr_encode:enc_type(#giop_env{version = {1, 0}}, T,TC), 392 {TC, <<>>, _} = cdr_decode:dec_type(T, {1, 0}, B, 0, big), 393 TC1 = {'tk_union', "IDL:Module/Union2:1.0", "Union2", 394 {'tk_enum', "IDL:Module/Enum:1.0", 395 "Module_Enum", ["horse", "pig", "cow"]}, 2, 396 [{"horse", "First", 'tk_long'}, 397 {"pig", "Second", 398 {'tk_union', "IDL:Module/Union:1.0", "Union", 'tk_short', 2, 399 [{0, "First", 'tk_short'}, 400 {1, "Second", {'tk_string', 0}}, 401 {2, "Third", 'tk_char'}]}}, 402 {"cow", "Third", {'tk_union', "IDL:Module/Union1:1.0", "Union1", 403 {'tk_enum', "IDL:Module/Enum:1.0", 404 "Module_Enum", ["horse", "pig", "cow"]}, 2, 405 [{"horse", "First", 'tk_ushort'}, 406 {"pig", "Second", {'tk_sequence', 407 {'tk_string', 0}, 0}}, 408 {"cow", "Third", {'tk_enum', 409 "IDL:Module/Enum1:1.0", 410 "Module_Enum1", 411 ["orange", "banana", 412 "apple"]}}]}}]}, 413 B1 = cdr_encode:enc_type(#giop_env{version = {1, 0}}, T, TC1), 414 {TC1, <<>>, _} = cdr_decode:dec_type(T, {1, 0}, B1, 0, big), 415 ok. 416 417%%----------------------------------------------------------------- 418%% Encode/decode test of type: TypeCode 419%%----------------------------------------------------------------- 420alias_type(Config) when is_list(Config) -> 421 T = {'tk_alias', "IDL:Module/Alias:1.0", "Alias", 422 {'tk_struct', "IDL:Module/Struct2:1.0", "Module_Struct2", 423 [{"long_sequence", {'tk_sequence', 'tk_long', 0}}, 424 {"enum", {'tk_enum', "IDL:Module/Enum:1.0", "Module_Enum", 425 ["horse", "pig", "cow"]}}, 426 {"octet", 'tk_octet'}]}}, 427 S = #'Module_Struct2'{long_sequence=[4711, 350000, 0, -3030, -600000], 428 e=cow, o=$X}, 429 B = cdr_encode:enc_type(#giop_env{version = {1, 0}}, T,S), 430 {S, <<>>, _} = cdr_decode:dec_type(T, {1, 0}, B, 0, big), 431 T1 = {'tk_alias', "IDL:Module/Alias1:1.0", "Alias1", 432 {'tk_sequence', {'tk_union', "IDL:Module/Union:1.0", "Union", 433 {'tk_enum', "IDL:Module/Enum:1.0", "Module_Enum", 434 ["horse", "pig", "cow"]}, 2, 435 [{"horse", "First", 'tk_ushort'}, 436 {"pig", "Second", {'tk_sequence', {'tk_string', 0}, 0}}, 437 {"cow", "Third", {'tk_enum', "IDL:Module/Enum1:1.0", 438 "Module_Enum1", ["orange", "banana", 439 "apple"]}}]},0}}, 440 S1 = [#'Module_Union'{label=cow, value=banana}, #'Module_Union'{label=pig, value=["This", "is", "a", "test", ""]}], 441 B1 = cdr_encode:enc_type(#giop_env{version = {1, 0}}, T1, S1), 442 {S1, <<>>, _} = cdr_decode:dec_type(T1, {1, 0}, B1, 0, big), 443 ok. 444 445%%----------------------------------------------------------------- 446%% Encode/decode test of type: exception 447%%----------------------------------------------------------------- 448exception_type(Config) when is_list(Config) -> 449 system_exceptions(), 450 user_exceptions(), 451 ok. 452 453system_exceptions() -> 454 E = #'UNKNOWN'{completion_status=?COMPLETED_YES}, 455 {system_exception, T, E} = orber_exceptions:get_def(E), 456 B = cdr_encode:enc_type(#giop_env{version = {1, 0}}, T,E), 457 {E, _} = cdr_decode:dec_system_exception({1, 0}, B, 0, big), 458 E1 = #'INV_OBJREF'{completion_status=?COMPLETED_NO}, 459 {system_exception, T1, E1} = orber_exceptions:get_def(E1), 460 B1 = cdr_encode:enc_type(#giop_env{version = {1, 0}}, T1,E1), 461 {E1, _} = cdr_decode:dec_system_exception({1, 0}, B1, 0, big), 462 E2 = #'BAD_OPERATION'{completion_status=?COMPLETED_NO}, 463 {system_exception, T2, E2} = orber_exceptions:get_def(E2), 464 B2 = cdr_encode:enc_type(#giop_env{version = {1, 0}}, T2,E2), 465 {E2, _} = cdr_decode:dec_system_exception({1, 0}, B2, 0, big), 466 E3 = #'INTF_REPOS'{completion_status=?COMPLETED_MAYBE}, 467 {system_exception, T3, E3} = orber_exceptions:get_def(E3), 468 B3 = cdr_encode:enc_type(#giop_env{version = {1, 0}}, T3,E3), 469 {E3, _} = cdr_decode:dec_system_exception({1, 0}, B3, 0, big), 470 ok. 471 472user_exceptions() -> 473 E = #'Module_Except1'{rest_of_name=["I","am","testing","exceptions"], why="Error"}, 474 {user_exception, T, E} = orber_exceptions:get_def(E), 475 B = cdr_encode:enc_type(#giop_env{version = {1, 0}}, T, E), 476 {E, _} = cdr_decode:dec_user_exception({1, 0}, B, 0, big), 477 E1 = #'Module_Except2'{e=banana, 478 s=#'Module_Struct2'{long_sequence=[12,-4040, 479 1234567898], 480 e=horse, 481 o=$a}}, 482 {user_exception, T1, E1} = orber_exceptions:get_def(E1), 483 B1 = cdr_encode:enc_type(#giop_env{version = {1, 0}}, T1, E1), 484 {E1, _} = cdr_decode:dec_user_exception({1, 0}, B1, 0, big), 485 E2 = #'Module_Except3'{u=#'Module_Union1'{label=pig,value=["high","and","low"]},s=1313, o=objref(0)}, 486 {user_exception, T2, E2} = orber_exceptions:get_def(E2), 487 B2 = cdr_encode:enc_type(#giop_env{version = {1, 0}}, T2, E2), 488 {E2, _} = cdr_decode:dec_user_exception({1, 0}, B2, 0, big), 489 E3 = #'Module_Except4'{}, 490 {user_exception, T3, E3} = orber_exceptions:get_def(E3), 491 B3 = cdr_encode:enc_type(#giop_env{version = {1, 0}}, T3, E3), 492 {E3, _} = cdr_decode:dec_user_exception({1, 0}, B3, 0, big), 493 ok. 494 495%%----------------------------------------------------------------- 496%% Test Case: request encoding test 497%% Description: Precondition the stack must be started so the 498%% objectkey is valid. 499%%----------------------------------------------------------------- 500%request(_) -> 501% exit(not_implemented). 502 503%%----------------------------------------------------------------- 504%% Test Case: reply encoding test 505%% Description: 506%%----------------------------------------------------------------- 507reply(Config) when is_list(Config) -> 508 R = #reply_header{service_context=[], request_id=1, 509 reply_status='no_exception'}, 510 B = cdr_encode:enc_reply( 511 #giop_env{version = {1, 0}, request_id = 1, 512 reply_status = 'no_exception', 513 tc = {'tk_long', [], [{'tk_sequence', 514 {'tk_string', 0}, 0}]}, 515 result = 1200, parameters = [["foo","Bar"]], 516 ctx = []}), 517 {R, 1200, [["foo","Bar"]]} = 518 cdr_decode:dec_message({'tk_long', [], [{'tk_sequence', {'tk_string', 0},0}]}, 519 B), 520 ok. 521 522%%----------------------------------------------------------------- 523%% Test Case: cancel_request encoding test 524%% Description: 525%%----------------------------------------------------------------- 526cancel_request(Config) when is_list(Config) -> 527 R = #cancel_request_header{request_id=1}, 528 B = cdr_encode:enc_cancel_request(#giop_env{version = {1, 0}, 529 request_id = 1}), 530 R = cdr_decode:dec_message([], B), 531 ok. 532 533%%----------------------------------------------------------------- 534%% Test Case: locate_request encoding test 535%% Description: 536%%----------------------------------------------------------------- 537locate_request(Config) when is_list(Config) -> 538 io:format("Function not imlpemented yet"), 539 exit(not_implemented). 540 541%%----------------------------------------------------------------- 542%% Test Case: locate_reply encoding test 543%% Description: 544%%----------------------------------------------------------------- 545locate_reply(Config) when is_list(Config) -> 546 io:format("Function not imlpemented yet"), 547 exit(not_implemented). 548 549%%----------------------------------------------------------------- 550%% Test Case: close_connection encoding test 551%% Description: 552%%----------------------------------------------------------------- 553close_connection(Config) when is_list(Config) -> 554 B = cdr_encode:enc_close_connection(#giop_env{version = {1, 0}}), 555 'close_connection' = cdr_decode:dec_message([], B), 556 ok. 557 558%%----------------------------------------------------------------- 559%% Test Case: message_error encoding test 560%% Description: 561%%----------------------------------------------------------------- 562message_error(Config) when is_list(Config) -> 563 B = cdr_encode:enc_message_error(#giop_env{version = {1, 0}}), 564 'message_error' = cdr_decode:dec_message([], B), 565 ok. 566 567 568 569%%----------------------------------------------------------------- 570%% Internal functions 571%%----------------------------------------------------------------- 572corba_fake_mk_objkey(Id, 'key', Pid) when is_pid(Pid) -> 573 Key = make_objkey(), 574 {list_to_binary(Id), 'key', Key, term_to_binary(undefined), 575 term_to_binary(undefined), term_to_binary(undefined)}; 576corba_fake_mk_objkey(Id, 'key', RegName) when is_atom(RegName) -> 577 Key = term_to_binary(RegName), 578 {list_to_binary(Id), 'key', Key, term_to_binary(undefined), 579 term_to_binary(undefined), term_to_binary(undefined)}; 580corba_fake_mk_objkey(Id, 'registered', RegName) when is_atom(RegName) -> 581 {list_to_binary(Id), 'registered', RegName, term_to_binary(undefined), 582 term_to_binary(undefined), term_to_binary(undefined)}. 583 584make_objkey() -> 585 term_to_binary({{erlang:system_time(), 586 erlang:unique_integer()}, 587 node()}). 588