1%%
2%% %CopyrightBegin%
3%%
4%% Copyright Ericsson AB 1997-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 IOR functions
25%%
26%%-----------------------------------------------------------------
27-module(iop_ior_11_SUITE).
28
29-include_lib("common_test/include/ct.hrl").
30-include_lib("orber/src/orber_iiop.hrl").
31
32-define(default_timeout, test_server:minutes(3)).
33
34%%-----------------------------------------------------------------
35%% External exports
36%%-----------------------------------------------------------------
37-export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1,
38	 init_per_group/2,end_per_group/2]).
39
40%%-----------------------------------------------------------------
41%% Internal exports
42%%-----------------------------------------------------------------
43-export([]).
44-compile(export_all).
45
46%%-----------------------------------------------------------------
47%% Func: all/1
48%% Args:
49%% Returns:
50%%-----------------------------------------------------------------
51suite() -> [{ct_hooks,[ts_install_cth]}].
52
53all() ->
54    [encoding, create_and_get_ops].
55
56groups() ->
57    [].
58
59init_per_suite(Config) ->
60    Config.
61
62end_per_suite(_Config) ->
63    ok.
64
65init_per_group(_GroupName, Config) ->
66    Config.
67
68end_per_group(_GroupName, Config) ->
69    Config.
70
71
72%%-----------------------------------------------------------------
73%% Init and cleanup functions.
74%%-----------------------------------------------------------------
75
76init_per_testcase(_Case, Config) ->
77     Dog=test_server:timetrap(?default_timeout),
78    [{watchdog, Dog}|Config].
79
80
81end_per_testcase(_Case, Config) ->
82    Dog = proplists:get_value(watchdog, Config),
83    test_server:timetrap_cancel(Dog),
84    ok.
85
86%%-----------------------------------------------------------------
87%% Test Case: IOR encoding test
88%% Description: Just testing the string_encoding function because the
89%%              other encodings is called from them.
90%%-----------------------------------------------------------------
91encoding(_) ->
92    V = #'IIOP_Version'{major=1,minor=1},
93    M0 = 'Module_Interface',
94    T0 = "IDL:Module/Interface:1.0",
95    H0 = "my.hostname.org",
96    P0 = 4040,
97    N0 = 'name',
98    Components = case orber:iiop_ssl_port() of
99		     -1 ->
100			 [];
101		     SSLPort ->
102			 [#'IOP_TaggedComponent'{tag=?TAG_SSL_SEC_TRANS,
103						 component_data=[0 |
104								 cdrlib:enc_unsigned_short(2,
105								 cdrlib:enc_unsigned_short(2,
106								 cdrlib:enc_unsigned_short(SSLPort, [])))]}]
107		 end,
108    O0 = corba_fake_mk_objkey(M0, registered, N0),
109    PB0 = #'IIOP_ProfileBody_1_1'{iiop_version=V, host=H0, port=P0, object_key=O0,
110				 components=Components},
111    TP0 = #'IOP_TaggedProfile'{tag=?TAG_INTERNET_IOP, profile_data=PB0},
112    S0 = #'IOP_IOR'{type_id=T0, profiles=[TP0]},
113    N1 = list_to_pid("<0.100.0>"),
114     O1 = corba_fake_mk_objkey(M0, key, N1),
115    PB1 = #'IIOP_ProfileBody_1_1'{iiop_version=V, host=H0, port=P0, object_key=O1,
116				 components=[]},
117    TP1 = #'IOP_TaggedProfile'{tag=?TAG_INTERNET_IOP, profile_data=PB1},
118    S1 = #'IOP_IOR'{type_id=T0, profiles=[TP1]},
119    O2 = "This is an external objectkey",
120    PB2 = #'IIOP_ProfileBody_1_1'{iiop_version=V, host=H0, port=P0, object_key=O2,
121				 components=[]},
122    TP2 = #'IOP_TaggedProfile'{tag=?TAG_INTERNET_IOP, profile_data=PB2},
123    S2 = #'IOP_IOR'{type_id=T0, profiles=[TP2]},
124    C0 = iop_ior:string_code(S0),
125    {S0, <<>>, _} = iop_ior:string_decode(C0),
126    C1 = iop_ior:string_code(S1),
127    {S1, <<>>, _} = iop_ior:string_decode(C1),
128    C2 = iop_ior:string_code(S2),
129    {S2, <<>>, _} = iop_ior:string_decode(C2),
130    ok.
131
132
133%%-----------------------------------------------------------------
134%% Test Case: IOR creation test
135%% Description:
136%%-----------------------------------------------------------------
137create_and_get_ops(_) ->
138    V = #'IIOP_Version'{major=1,minor=1},
139    CSC = #'IOP_TaggedComponent'{tag=?TAG_CODE_SETS,
140				 component_data=?DEFAULT_CODESETS},
141    M0 = 'Module_Interface',
142    T0 = "IDL:Module/Interface:1.0",
143    H0 = "my.hostname.org",
144    P0 = 4040,
145    N0 = 'name',
146    O0 = corba_fake_mk_objkey(M0, registered, N0),
147    PB0 = #'IIOP_ProfileBody_1_1'
148      {iiop_version=V, host=H0, port=P0, object_key=O0,
149       components=[CSC]},
150    TP0 = #'IOP_TaggedProfile'{tag=?TAG_INTERNET_IOP, profile_data=PB0},
151    S0 = #'IOP_IOR'{type_id=T0, profiles=[TP0]},
152    S0 = iop_ior:create({1, 1}, T0, [H0], P0, -1, O0, [CSC], 0, 0),
153    N1 = list_to_pid("<0.100.0>"),
154    O1 = corba_fake_mk_objkey(M0, key, N1),
155    {_,_,K1,_,_,_} = O1,
156    PB1 = #'IIOP_ProfileBody_1_1'
157      {iiop_version=V, host=H0, port=P0, object_key=O1,
158       components=[CSC]},
159    TP1 = #'IOP_TaggedProfile'{tag=?TAG_INTERNET_IOP, profile_data=PB1},
160    S1 = #'IOP_IOR'{type_id=T0, profiles=[TP1]},
161    S1 = iop_ior:create({1, 1}, T0, [H0], P0, -1, O1, [CSC], 0, 0),
162    O2 = "This is an external objectkey",
163    PB2 = #'IIOP_ProfileBody_1_1'{iiop_version=V, host=H0, port=P0, object_key=O2,
164				  components=[]},
165    TP2 = #'IOP_TaggedProfile'{tag=?TAG_INTERNET_IOP, profile_data=PB2},
166    S2 = #'IOP_IOR'{type_id=T0, profiles=[TP2]},
167    {'internal_registered', N0, _, _, M0} = iop_ior:get_key(S0),
168    {'internal', K1, _, _, M0} = iop_ior:get_key(S1),
169    {'external', {H0, P0, O2, _,_,
170		  #host_data{protocol = normal,
171			     ssl_data = undefined,
172			     version  = {1,1},
173			     csiv2_mech = undefined,
174			     csiv2_statefull = false,
175			     charset = 65537,
176			     wcharset = 65801,
177			     ft_heartbeat = false,
178			     ft_primary = false,
179			     ft_group = undefined,
180			     csiv2_addresses = []}}} =
181	iop_ior:get_key(S2),
182    T0 = iop_ior:get_typeID(S0),
183    O0 = iop_ior:get_objkey(S0),
184    O1 = iop_ior:get_objkey(S1),
185    O2 = iop_ior:get_objkey(S2),
186    ok.
187
188%%-----------------------------------------------------------------
189%% Internal functions
190%%-----------------------------------------------------------------
191corba_fake_mk_objkey(Id, 'key', Pid) when is_pid(Pid) ->
192    Key = make_objkey(),
193    {Id, 'key', Key, term_to_binary(undefined), 0, 0};
194corba_fake_mk_objkey(Id, 'key', RegName) when is_atom(RegName) ->
195    Key = term_to_binary(RegName),
196    {Id, 'key', Key, term_to_binary(undefined), 0, 0};
197corba_fake_mk_objkey(Id, 'registered', RegName) when is_atom(RegName) ->
198    {Id, 'registered', RegName, term_to_binary(undefined), 0, 0}.
199
200make_objkey() ->
201    term_to_binary({{erlang:system_time(),
202		     erlang:unique_integer()},
203		    node()}).
204