1: %%
    2: %% %CopyrightBegin%
    3: %%
    4: %% Copyright Ericsson AB 1999-2011. All Rights Reserved.
    5: %%
    6: %% The contents of this file are subject to the Erlang Public License,
    7: %% Version 1.1, (the "License"); you may not use this file except in
    8: %% compliance with the License. You should have received a copy of the
    9: %% Erlang Public License along with this software. If not, it can be
   10: %% retrieved online at http://www.erlang.org/.
   11: %%
   12: %% Software distributed under the License is distributed on an "AS IS"
   13: %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
   14: %% the License for the specific language governing rights and limitations
   15: %% under the License.
   16: %%
   17: %% %CopyrightEnd%
   18: %%
   19: %%
   20: %%-----------------------------------------------------------------
   21: %%
   22: %% Description:
   23: %% Test suite for the IOR functions
   24: %%
   25: %%-----------------------------------------------------------------
   26: -module(iop_ior_10_SUITE).
   27: 
   28: -include_lib("test_server/include/test_server.hrl").
   29: -include_lib("orber/src/orber_iiop.hrl").
   30: 
   31: -define(default_timeout, ?t:minutes(3)).
   32: 
   33: %%-----------------------------------------------------------------
   34: %% External exports
   35: %%-----------------------------------------------------------------
   36: -export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, 
   37: 	 init_per_group/2,end_per_group/2]).
   38: 
   39: %%-----------------------------------------------------------------
   40: %% Internal exports
   41: %%-----------------------------------------------------------------
   42: -export([]).
   43: -compile(export_all).
   44: 
   45: %%-----------------------------------------------------------------
   46: %% Func: all/1
   47: %% Args: 
   48: %% Returns: 
   49: %%-----------------------------------------------------------------
   50: suite() -> [{ct_hooks,[ts_install_cth]}].
   51: 
   52: all() -> 
   53:     [encoding, create_and_get_ops].
   54: 
   55: groups() -> 
   56:     [].
   57: 
   58: init_per_suite(Config) ->
   59:     Config.
   60: 
   61: end_per_suite(_Config) ->
   62:     ok.
   63: 
   64: init_per_group(_GroupName, Config) ->
   65:     Config.
   66: 
   67: end_per_group(_GroupName, Config) ->
   68:     Config.
   69: 
   70: 
   71: %%-----------------------------------------------------------------
   72: %% Init and cleanup functions.
   73: %%-----------------------------------------------------------------
   74: 
   75: init_per_testcase(_Case, Config) ->
   76:     ?line Dog=test_server:timetrap(?default_timeout),
   77:     [{watchdog, Dog}|Config].
   78: 
   79: 
   80: end_per_testcase(_Case, Config) ->
   81:     Dog = ?config(watchdog, Config),
   82:     test_server:timetrap_cancel(Dog),
   83:     ok.
   84: 
   85: %%-----------------------------------------------------------------
   86: %% Test Case: IOR encoding test
   87: %% Description: Just testing the string_encoding function because the
   88: %%              other encodings is called from them.
   89: %%-----------------------------------------------------------------
   90: encoding(doc) -> ["Description", "more description"];
   91: encoding(suite) -> [];
   92: encoding(_) ->
   93:     V = #'IIOP_Version'{major=1,minor=0},
   94:     M0 = 'Module_Interface',
   95:     T0 = "IDL:Module/Interface:1.0",
   96:     H0 = "my.hostname.org",
   97:     P0 = 4040,
   98:     N0 = 'name',
   99:     ?line O0 = corba_fake_mk_objkey(M0, registered, N0),
  100:     PB0 = #'IIOP_ProfileBody_1_0'{iiop_version=V, host=H0, port=P0, object_key=O0},
  101:     TP0 = #'IOP_TaggedProfile'{tag=?TAG_INTERNET_IOP, profile_data=PB0},
  102:     S0 = #'IOP_IOR'{type_id=T0, profiles=[TP0]},
  103:     N1 = list_to_pid("<0.100.0>"),
  104:     ?line O1 = corba_fake_mk_objkey(M0, key, N1),
  105:     PB1 = #'IIOP_ProfileBody_1_0'{iiop_version=V, host=H0, port=P0, object_key=O1},
  106:     TP1 = #'IOP_TaggedProfile'{tag=?TAG_INTERNET_IOP, profile_data=PB1},
  107:     S1 = #'IOP_IOR'{type_id=T0, profiles=[TP1]},
  108:     O2 = "This is an external objectkey",
  109:     PB2 = #'IIOP_ProfileBody_1_0'{iiop_version=V, host=H0, port=P0, object_key=O2},
  110:     TP2 = #'IOP_TaggedProfile'{tag=?TAG_INTERNET_IOP, profile_data=PB2},
  111:     S2 = #'IOP_IOR'{type_id=T0, profiles=[TP2]},
  112:     ?line C0 = iop_ior:string_code(S0),
  113:     ?line {S0, <<>>, _} = iop_ior:string_decode(C0),
  114:     ?line C1 = iop_ior:string_code(S1),
  115:     ?line {S1, <<>>, _} = iop_ior:string_decode(C1),
  116:     ?line C2 = iop_ior:string_code(S2),
  117:     ?line {S2, <<>>, _} = iop_ior:string_decode(C2),
  118:     ok.
  119: 
  120: 
  121: %%-----------------------------------------------------------------
  122: %% Test Case: IOR creation test
  123: %% Description: 
  124: %%-----------------------------------------------------------------
  125: create_and_get_ops(doc) -> ["Description", "more description"];
  126: create_and_get_ops(suite) -> [];
  127: create_and_get_ops(_) ->
  128:     V = #'IIOP_Version'{major=1,minor=0},
  129:     M0 = 'Module_Interface',
  130:     T0 = "IDL:Module/Interface:1.0",
  131:     H0 = "my.hostname.org",
  132:     P0 = 4040,
  133:     N0 = 'name',
  134:     ?line O0 = corba_fake_mk_objkey(M0, registered, N0),
  135:     PB0 = #'IIOP_ProfileBody_1_0'{iiop_version=V, host=H0, port=P0, object_key=O0},
  136:     TP0 = #'IOP_TaggedProfile'{tag=?TAG_INTERNET_IOP, profile_data=PB0},
  137:     S0 = #'IOP_IOR'{type_id=T0, profiles=[TP0]},
  138:     ?line S0 = iop_ior:create({1, 0}, T0, [H0], P0, -1, O0, [], 0, 0),
  139:     N1 = list_to_pid("<0.100.0>"),
  140:     ?line O1 = corba_fake_mk_objkey(M0, key, N1),
  141:     {_,_,K1,_,_,_} = O1,
  142:     PB1 = #'IIOP_ProfileBody_1_0'{iiop_version=V, host=H0, port=P0, object_key=O1},
  143:     TP1 = #'IOP_TaggedProfile'{tag=?TAG_INTERNET_IOP, profile_data=PB1},
  144:     S1 = #'IOP_IOR'{type_id=T0, profiles=[TP1]},
  145:     ?line S1 = iop_ior:create({1, 0}, T0, [H0], P0, -1, O1, [], 0, 0),
  146:     O2 = "This is an external objectkey",
  147:     PB2 = #'IIOP_ProfileBody_1_0'{iiop_version=V, host=H0, port=P0, object_key=O2},
  148:     TP2 = #'IOP_TaggedProfile'{tag=?TAG_INTERNET_IOP, profile_data=PB2},
  149:     S2 = #'IOP_IOR'{type_id=T0, profiles=[TP2]},
  150:     ?line {'internal_registered', N0, _, _, M0} = iop_ior:get_key(S0),
  151:     ?line {'internal', K1, _, _, M0} = iop_ior:get_key(S1),
  152:     ?line {'external', {H0, P0, O2, _,_,
  153: 			#host_data{protocol = normal,
  154: 				   ssl_data = undefined,
  155: 				   version  = {1,0},
  156: 				   csiv2_mech = undefined,
  157: 				   csiv2_statefull = false,
  158: 				   charset = 65537,
  159: 				   wcharset = 65801,
  160: 				   ft_heartbeat = false,
  161: 				   ft_primary = false,
  162: 				   ft_group = undefined,
  163: 				   csiv2_addresses = []}}} 
  164: 	= iop_ior:get_key(S2),
  165:     ?line T0 = iop_ior:get_typeID(S0),
  166:     ?line O0 = iop_ior:get_objkey(S0),
  167:     ?line O1 = iop_ior:get_objkey(S1),
  168:     ?line O2 = iop_ior:get_objkey(S2),
  169:     ok.
  170: 
  171: %%-----------------------------------------------------------------
  172: %% Internal functions
  173: %%-----------------------------------------------------------------
  174: corba_fake_mk_objkey(Id, 'key', Pid) when is_pid(Pid) ->
  175:     Key = make_objkey(),
  176:     {Id, 'key', Key, term_to_binary(undefined), 0, 0};
  177: corba_fake_mk_objkey(Id, 'key', RegName) when is_atom(RegName) ->
  178:     Key = term_to_binary(RegName),
  179:     {Id, 'key', Key, term_to_binary(undefined), 0, 0};
  180: corba_fake_mk_objkey(Id, 'registered', RegName) when is_atom(RegName) ->
  181:     {Id, 'registered', RegName, term_to_binary(undefined), 0, 0}.
  182:      
  183: 
  184: make_objkey() ->
  185:     term_to_binary({now(), node()}).