1%%----------------------------------------------------------------- 2%% 3%% %CopyrightBegin% 4%% 5%% Copyright Ericsson AB 2004-2016. All Rights Reserved. 6%% 7%% Licensed under the Apache License, Version 2.0 (the "License"); 8%% you may not use this file except in compliance with the License. 9%% You may obtain a copy of the License at 10%% 11%% http://www.apache.org/licenses/LICENSE-2.0 12%% 13%% Unless required by applicable law or agreed to in writing, software 14%% distributed under the License is distributed on an "AS IS" BASIS, 15%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16%% See the License for the specific language governing permissions and 17%% limitations under the License. 18%% 19%% %CopyrightEnd% 20%% 21%% 22%%----------------------------------------------------------------- 23%% File : interceptors_SUITE.erl 24%% Purpose : 25%%----------------------------------------------------------------- 26 27-module(interceptors_SUITE). 28 29-include_lib("common_test/include/ct.hrl"). 30-include_lib("orber/include/corba.hrl"). 31-include_lib("orber/src/orber_iiop.hrl"). 32 33-define(default_timeout, test_server:minutes(3)). 34 35-define(match(ExpectedRes, Expr), 36 fun() -> 37 AcTuAlReS = (catch (Expr)), 38 case AcTuAlReS of 39 ExpectedRes -> 40 io:format("------ CORRECT RESULT ------~n~p~n", 41 [AcTuAlReS]), 42 AcTuAlReS; 43 _ -> 44 io:format("###### ERROR ERROR ######~n~p~n", 45 [AcTuAlReS]), 46 exit(AcTuAlReS) 47 end 48 end()). 49 50-define(nomatch(Not, Expr), 51 fun() -> 52 AcTuAlReS = (catch (Expr)), 53 case AcTuAlReS of 54 Not -> 55 io:format("###### ERROR ERROR ######~n~p~n", 56 [AcTuAlReS]), 57 exit(AcTuAlReS); 58 _ -> 59 io:format("------ CORRECT RESULT ------~n~p~n", 60 [AcTuAlReS]), 61 AcTuAlReS 62 end 63 end()). 64 65 66%%----------------------------------------------------------------- 67%% External exports 68%%----------------------------------------------------------------- 69-export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, 70 init_per_group/2,end_per_group/2]). 71 72%%----------------------------------------------------------------- 73%% Internal exports 74%%----------------------------------------------------------------- 75-export([in_reply/6, out_request/6]). 76-compile(export_all). 77 78%%----------------------------------------------------------------- 79%% Func: all/1 80%% Args: 81%% Returns: 82%%----------------------------------------------------------------- 83suite() -> [{ct_hooks,[ts_install_cth]}]. 84 85all() -> 86 [local_pseudo, local_default, local_local, local_global]. 87 88groups() -> 89 []. 90 91init_per_suite(Config) -> 92 Config. 93 94end_per_suite(_Config) -> 95 ok. 96 97init_per_group(_GroupName, Config) -> 98 Config. 99 100end_per_group(_GroupName, Config) -> 101 Config. 102 103 104%%----------------------------------------------------------------- 105%% Init and cleanup functions. 106%%----------------------------------------------------------------- 107init_per_testcase(_Case, Config) -> 108 Dog=test_server:timetrap(?default_timeout), 109 Path = code:which(?MODULE), 110 code:add_pathz(filename:join(filename:dirname(Path), "idl_output")), 111 corba:orb_init([{flags, (?ORB_ENV_USE_PI bor ?ORB_ENV_LOCAL_TYPECHECKING)}, 112 {local_interceptors, {native, [?MODULE]}}]), 113 orber:jump_start(2945), 114 oe_orber_test_server:oe_register(), 115 [{watchdog, Dog}|Config]. 116 117 118end_per_testcase(_Case, Config) -> 119 oe_orber_test_server:oe_unregister(), 120 orber:jump_stop(), 121 Path = code:which(?MODULE), 122 code:del_path(filename:join(filename:dirname(Path), "idl_output")), 123 Dog = proplists:get_value(watchdog, Config), 124 test_server:timetrap_cancel(Dog), 125 ok. 126 127%%----------------------------------------------------------------- 128%% Test Case: local_pseudo 129%% Description: 130%%----------------------------------------------------------------- 131local_pseudo(_) -> 132 ?match({native, [?MODULE]}, orber:get_local_interceptors()), 133 %% Global settings 134 Obj1 = orber_test_server:oe_create(state,[{pseudo,true}]), 135 Result11 = orber_test_server:testing_iiop_ushort(Obj1, ?USHORTMAX), 136 ?match([?USHORTMAX], put(out_request, undefined)), 137 ?match(Result11, put(in_reply, undefined)), 138 139 Result12 = ?match({'EXCEPTION',_}, 140 orber_test_server:testing_iiop_ushort(Obj1, ?USHORTMAX+1)), 141 ?match([(?USHORTMAX+1)], put(out_request, undefined)), 142 ?nomatch(Result12, put(in_reply, undefined)), 143 144 Result13 = orber_test_server:testing_iiop_oneway_delay(Obj1, 0), 145 ?match([0], put(out_request, undefined)), 146 ?nomatch(Result13, put(in_reply, undefined)), 147 148 Result14 = ?match({'EXCEPTION', _}, 149 orber_test_server:raise_local_exception(Obj1)), 150 ?match([], put(out_request, undefined)), 151 ?match(Result14, put(in_reply, undefined)), 152 153 Result15 = ?match({'EXCEPTION',_}, orber_test_server:stop_brutal(Obj1)), 154 ?match([], put(out_request, undefined)), 155 ?match(Result15, put(in_reply, undefined)), 156 157 %% Per-object 158 Obj2 = orber_test_server:oe_create(state,[{pseudo,true}, 159 {local_interceptors, false}]), 160 161 Result21 = orber_test_server:testing_iiop_ushort(Obj2, ?USHORTMAX), 162 ?nomatch([?USHORTMAX], put(out_request, undefined)), 163 ?nomatch(Result21, put(in_reply, undefined)), 164 165 Obj3 = orber_test_server:oe_create(state,[{pseudo,true}, 166 {local_interceptors, true}]), 167 168 Result31 = orber_test_server:testing_iiop_ushort(Obj3, ?USHORTMAX), 169 ?match([?USHORTMAX], put(out_request, undefined)), 170 ?match(Result31, put(in_reply, undefined)), 171 172 ok. 173 174%%----------------------------------------------------------------- 175%% Test Case: local_default 176%% Description: 177%%----------------------------------------------------------------- 178local_default(_) -> 179 ?match({native, [?MODULE]}, orber:get_local_interceptors()), 180 %% Global settings 181 Obj1 = orber_test_server:oe_create(state, []), 182 Result11 = orber_test_server:testing_iiop_ushort(Obj1, ?USHORTMAX), 183 ?match([?USHORTMAX], put(out_request, undefined)), 184 ?match(Result11, put(in_reply, undefined)), 185 186 Result12 = ?match({'EXCEPTION',_}, 187 orber_test_server:testing_iiop_ushort(Obj1, ?USHORTMAX+1)), 188 ?match([(?USHORTMAX+1)], put(out_request, undefined)), 189 ?nomatch(Result12, put(in_reply, undefined)), 190 191 Result13 = orber_test_server:testing_iiop_oneway_delay(Obj1, 0), 192 ?match([0], put(out_request, undefined)), 193 ?nomatch(Result13, put(in_reply, undefined)), 194 195 Result14 = ?match({'EXCEPTION', _}, 196 orber_test_server:raise_local_exception(Obj1)), 197 ?match([], put(out_request, undefined)), 198 ?match(Result14, put(in_reply, undefined)), 199 200 Result15 = ?match({'EXCEPTION',_}, orber_test_server:stop_brutal(Obj1)), 201 ?match([], put(out_request, undefined)), 202 ?match(Result15, put(in_reply, undefined)), 203 204 205 %% Per-object 206 Obj2 = orber_test_server:oe_create(state,[{local_interceptors, false}]), 207 208 Result21 = orber_test_server:testing_iiop_ushort(Obj2, ?USHORTMAX), 209 ?nomatch([?USHORTMAX], put(out_request, undefined)), 210 ?nomatch(Result21, put(in_reply, undefined)), 211 corba:dispose(Obj2), 212 213 Obj3 = orber_test_server:oe_create(state,[{local_interceptors, true}]), 214 215 Result31 = orber_test_server:testing_iiop_ushort(Obj3, ?USHORTMAX), 216 ?match([?USHORTMAX], put(out_request, undefined)), 217 ?match(Result31, put(in_reply, undefined)), 218 corba:dispose(Obj3), 219 ok. 220 221%%----------------------------------------------------------------- 222%% Test Case: local_local 223%% Description: 224%%----------------------------------------------------------------- 225local_local(_) -> 226 ?match({native, [?MODULE]}, orber:get_local_interceptors()), 227 %% Global settings 228 Obj1 = orber_test_server:oe_create(state, [{regname, {local, regname}}]), 229 Result11 = orber_test_server:testing_iiop_ushort(Obj1, ?USHORTMAX), 230 ?match([?USHORTMAX], put(out_request, undefined)), 231 ?match(Result11, put(in_reply, undefined)), 232 233 Result12 = ?match({'EXCEPTION',_}, 234 orber_test_server:testing_iiop_ushort(Obj1, ?USHORTMAX+1)), 235 ?match([(?USHORTMAX+1)], put(out_request, undefined)), 236 ?nomatch(Result12, put(in_reply, undefined)), 237 238 Result13 = orber_test_server:testing_iiop_oneway_delay(Obj1, 0), 239 ?match([0], put(out_request, undefined)), 240 ?nomatch(Result13, put(in_reply, undefined)), 241 242 Result14 = ?match({'EXCEPTION', _}, 243 orber_test_server:raise_local_exception(Obj1)), 244 ?match([], put(out_request, undefined)), 245 ?match(Result14, put(in_reply, undefined)), 246 247 Result15 = ?match({'EXCEPTION',_}, orber_test_server:stop_brutal(Obj1)), 248 ?match([], put(out_request, undefined)), 249 ?match(Result15, put(in_reply, undefined)), 250 251 %% Per-object 252 Obj2 = orber_test_server:oe_create(state,[{regname, {local, regname}}, 253 {local_interceptors, false}]), 254 255 Result21 = orber_test_server:testing_iiop_ushort(Obj2, ?USHORTMAX), 256 ?nomatch([?USHORTMAX], put(out_request, undefined)), 257 ?nomatch(Result21, put(in_reply, undefined)), 258 corba:dispose(Obj2), 259 260 Obj3 = orber_test_server:oe_create(state,[{regname, {local, regname}}, 261 {local_interceptors, true}]), 262 263 Result31 = orber_test_server:testing_iiop_ushort(Obj3, ?USHORTMAX), 264 ?match([?USHORTMAX], put(out_request, undefined)), 265 ?match(Result31, put(in_reply, undefined)), 266 corba:dispose(Obj3), 267 ok. 268 269%%----------------------------------------------------------------- 270%% Test Case: local_global 271%% Description: 272%%----------------------------------------------------------------- 273local_global(_) -> 274 ?match({native, [?MODULE]}, orber:get_local_interceptors()), 275 %% Global settings 276 Obj1 = orber_test_server:oe_create(state, [{regname, {global, regname}}]), 277 Result11 = orber_test_server:testing_iiop_ushort(Obj1, ?USHORTMAX), 278 ?match([?USHORTMAX], put(out_request, undefined)), 279 ?match(Result11, put(in_reply, undefined)), 280 281 Result12 = ?match({'EXCEPTION',_}, 282 orber_test_server:testing_iiop_ushort(Obj1, ?USHORTMAX+1)), 283 ?match([(?USHORTMAX+1)], put(out_request, undefined)), 284 ?nomatch(Result12, put(in_reply, undefined)), 285 286 Result13 = orber_test_server:testing_iiop_oneway_delay(Obj1, 0), 287 ?match([0], put(out_request, undefined)), 288 ?nomatch(Result13, put(in_reply, undefined)), 289 290 Result14 = ?match({'EXCEPTION', _}, 291 orber_test_server:raise_local_exception(Obj1)), 292 ?match([], put(out_request, undefined)), 293 ?match(Result14, put(in_reply, undefined)), 294 295 Result15 = ?match({'EXCEPTION',_}, orber_test_server:stop_brutal(Obj1)), 296 ?match([], put(out_request, undefined)), 297 ?match(Result15, put(in_reply, undefined)), 298 299 %% Per-object 300 Obj2 = orber_test_server:oe_create(state,[{regname, {global, regname}}, 301 {local_interceptors, false}]), 302 303 Result21 = orber_test_server:testing_iiop_ushort(Obj2, ?USHORTMAX), 304 ?nomatch([?USHORTMAX], put(out_request, undefined)), 305 ?nomatch(Result21, put(in_reply, undefined)), 306 corba:dispose(Obj2), 307 308 Obj3 = orber_test_server:oe_create(state,[{regname, {global, regname}}, 309 {local_interceptors, true}]), 310 311 Result31 = orber_test_server:testing_iiop_ushort(Obj3, ?USHORTMAX), 312 ?match([?USHORTMAX], put(out_request, undefined)), 313 ?match(Result31, put(in_reply, undefined)), 314 corba:dispose(Obj3), 315 ok. 316 317 318 319 320%%----------------------------------------------------------------- 321%% Local functions 322%%----------------------------------------------------------------- 323%%----------------------------------------------------------------- 324%% function : in_reply 325%%----------------------------------------------------------------- 326in_reply(Ref, _ObjKey, Ctx, Op, Reply, _Args) -> 327 error_logger:info_msg("=============== in_reply ================= 328Connection: ~p 329Operation : ~p 330Reply : ~p 331Context : ~p 332==========================================~n", 333 [Ref, Op, Reply, Ctx]), 334 put(in_reply, Reply), 335 {Reply, "NewArgs"}. 336 337%%----------------------------------------------------------------- 338%% function : out_request 339%%----------------------------------------------------------------- 340out_request(Ref, _ObjKey, Ctx, Op, Params, _Args) -> 341 error_logger:info_msg("=============== out_request ============== 342Connection: ~p 343Operation : ~p 344Parameters: ~p 345Context : ~p 346==========================================~n", 347 [Ref, Op, Params, Ctx]), 348 put(out_request, Params), 349 {Params, "NewArgs"}. 350