summaryrefslogtreecommitdiff
path: root/lib/orber/test/iop_ior_10_SUITE.erl
blob: 58dd1b5dba81733119edee6f0384e060308f854f (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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 1999-2011. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
%% compliance with the License. You should have received a copy of the
%% Erlang Public License along with this software. If not, it can be
%% retrieved online at http://www.erlang.org/.
%%
%% Software distributed under the License is distributed on an "AS IS"
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
%% the License for the specific language governing rights and limitations
%% under the License.
%%
%% %CopyrightEnd%
%%
%%
%%-----------------------------------------------------------------
%%
%% Description:
%% Test suite for the IOR functions
%%
%%-----------------------------------------------------------------
-module(iop_ior_10_SUITE).

-include_lib("test_server/include/test_server.hrl").
-include_lib("orber/src/orber_iiop.hrl").

-define(default_timeout, ?t:minutes(3)).

%%-----------------------------------------------------------------
%% External exports
%%-----------------------------------------------------------------
-export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, 
	 init_per_group/2,end_per_group/2]).

%%-----------------------------------------------------------------
%% Internal exports
%%-----------------------------------------------------------------
-export([]).
-compile(export_all).

%%-----------------------------------------------------------------
%% Func: all/1
%% Args: 
%% Returns: 
%%-----------------------------------------------------------------
suite() -> [{ct_hooks,[ts_install_cth]}].

all() -> 
    [encoding, create_and_get_ops].

groups() -> 
    [].

init_per_suite(Config) ->
    Config.

end_per_suite(_Config) ->
    ok.

init_per_group(_GroupName, Config) ->
    Config.

end_per_group(_GroupName, Config) ->
    Config.


%%-----------------------------------------------------------------
%% Init and cleanup functions.
%%-----------------------------------------------------------------

init_per_testcase(_Case, Config) ->
    ?line Dog=test_server:timetrap(?default_timeout),
    [{watchdog, Dog}|Config].


end_per_testcase(_Case, Config) ->
    Dog = ?config(watchdog, Config),
    test_server:timetrap_cancel(Dog),
    ok.

%%-----------------------------------------------------------------
%% Test Case: IOR encoding test
%% Description: Just testing the string_encoding function because the
%%              other encodings is called from them.
%%-----------------------------------------------------------------
encoding(doc) -> ["Description", "more description"];
encoding(suite) -> [];
encoding(_) ->
    V = #'IIOP_Version'{major=1,minor=0},
    M0 = 'Module_Interface',
    T0 = "IDL:Module/Interface:1.0",
    H0 = "my.hostname.org",
    P0 = 4040,
    N0 = 'name',
    ?line O0 = corba_fake_mk_objkey(M0, registered, N0),
    PB0 = #'IIOP_ProfileBody_1_0'{iiop_version=V, host=H0, port=P0, object_key=O0},
    TP0 = #'IOP_TaggedProfile'{tag=?TAG_INTERNET_IOP, profile_data=PB0},
    S0 = #'IOP_IOR'{type_id=T0, profiles=[TP0]},
    N1 = list_to_pid("<0.100.0>"),
    ?line O1 = corba_fake_mk_objkey(M0, key, N1),
    PB1 = #'IIOP_ProfileBody_1_0'{iiop_version=V, host=H0, port=P0, object_key=O1},
    TP1 = #'IOP_TaggedProfile'{tag=?TAG_INTERNET_IOP, profile_data=PB1},
    S1 = #'IOP_IOR'{type_id=T0, profiles=[TP1]},
    O2 = "This is an external objectkey",
    PB2 = #'IIOP_ProfileBody_1_0'{iiop_version=V, host=H0, port=P0, object_key=O2},
    TP2 = #'IOP_TaggedProfile'{tag=?TAG_INTERNET_IOP, profile_data=PB2},
    S2 = #'IOP_IOR'{type_id=T0, profiles=[TP2]},
    ?line C0 = iop_ior:string_code(S0),
    ?line {S0, <<>>, _} = iop_ior:string_decode(C0),
    ?line C1 = iop_ior:string_code(S1),
    ?line {S1, <<>>, _} = iop_ior:string_decode(C1),
    ?line C2 = iop_ior:string_code(S2),
    ?line {S2, <<>>, _} = iop_ior:string_decode(C2),
    ok.


%%-----------------------------------------------------------------
%% Test Case: IOR creation test
%% Description: 
%%-----------------------------------------------------------------
create_and_get_ops(doc) -> ["Description", "more description"];
create_and_get_ops(suite) -> [];
create_and_get_ops(_) ->
    V = #'IIOP_Version'{major=1,minor=0},
    M0 = 'Module_Interface',
    T0 = "IDL:Module/Interface:1.0",
    H0 = "my.hostname.org",
    P0 = 4040,
    N0 = 'name',
    ?line O0 = corba_fake_mk_objkey(M0, registered, N0),
    PB0 = #'IIOP_ProfileBody_1_0'{iiop_version=V, host=H0, port=P0, object_key=O0},
    TP0 = #'IOP_TaggedProfile'{tag=?TAG_INTERNET_IOP, profile_data=PB0},
    S0 = #'IOP_IOR'{type_id=T0, profiles=[TP0]},
    ?line S0 = iop_ior:create({1, 0}, T0, [H0], P0, -1, O0, [], 0, 0),
    N1 = list_to_pid("<0.100.0>"),
    ?line O1 = corba_fake_mk_objkey(M0, key, N1),
    {_,_,K1,_,_,_} = O1,
    PB1 = #'IIOP_ProfileBody_1_0'{iiop_version=V, host=H0, port=P0, object_key=O1},
    TP1 = #'IOP_TaggedProfile'{tag=?TAG_INTERNET_IOP, profile_data=PB1},
    S1 = #'IOP_IOR'{type_id=T0, profiles=[TP1]},
    ?line S1 = iop_ior:create({1, 0}, T0, [H0], P0, -1, O1, [], 0, 0),
    O2 = "This is an external objectkey",
    PB2 = #'IIOP_ProfileBody_1_0'{iiop_version=V, host=H0, port=P0, object_key=O2},
    TP2 = #'IOP_TaggedProfile'{tag=?TAG_INTERNET_IOP, profile_data=PB2},
    S2 = #'IOP_IOR'{type_id=T0, profiles=[TP2]},
    ?line {'internal_registered', N0, _, _, M0} = iop_ior:get_key(S0),
    ?line {'internal', K1, _, _, M0} = iop_ior:get_key(S1),
    ?line {'external', {H0, P0, O2, _,_,
			#host_data{protocol = normal,
				   ssl_data = undefined,
				   version  = {1,0},
				   csiv2_mech = undefined,
				   csiv2_statefull = false,
				   charset = 65537,
				   wcharset = 65801,
				   ft_heartbeat = false,
				   ft_primary = false,
				   ft_group = undefined,
				   csiv2_addresses = []}}} 
	= iop_ior:get_key(S2),
    ?line T0 = iop_ior:get_typeID(S0),
    ?line O0 = iop_ior:get_objkey(S0),
    ?line O1 = iop_ior:get_objkey(S1),
    ?line O2 = iop_ior:get_objkey(S2),
    ok.

%%-----------------------------------------------------------------
%% Internal functions
%%-----------------------------------------------------------------
corba_fake_mk_objkey(Id, 'key', Pid) when is_pid(Pid) ->
    Key = make_objkey(),
    {Id, 'key', Key, term_to_binary(undefined), 0, 0};
corba_fake_mk_objkey(Id, 'key', RegName) when is_atom(RegName) ->
    Key = term_to_binary(RegName),
    {Id, 'key', Key, term_to_binary(undefined), 0, 0};
corba_fake_mk_objkey(Id, 'registered', RegName) when is_atom(RegName) ->
    {Id, 'registered', RegName, term_to_binary(undefined), 0, 0}.
     

make_objkey() ->
    term_to_binary({now(), node()}).