1: %%
    2: %% %CopyrightBegin%
    3: %% 
    4: %% Copyright Ericsson AB 1998-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: %% File: ic_pragma_SUITE.erl
   22: %% 
   23: %% Description:
   24: %% Test suite for the IFR object registration when
   25: %% pragmas are engaged
   26: %%
   27: %%-----------------------------------------------------------------
   28: -module(ic_pragma_SUITE).
   29: 
   30: -include_lib("test_server/include/test_server.hrl").
   31: -include_lib("orber/include/corba.hrl").
   32: %%-----------------------------------------------------------------
   33: %% External exports
   34: %%-----------------------------------------------------------------
   35: -export([all/0, suite/0,groups/0,init_per_group/2,end_per_group/2, 
   36: 	 init_per_suite/1, end_per_suite/1]).
   37: -export([ifr_pragma_reg/1, pragma_error/1, uggly_pragmas/1]).
   38: 
   39: 
   40: %%-----------------------------------------------------------------
   41: %% Macros
   42: %%-----------------------------------------------------------------
   43: -define(REMAP_EXCEPT(F), case catch F of
   44: 			     {'EXCEPTION', E} -> exit(E);
   45: 			     R -> R
   46: 			 end).
   47: %% Standard options to the ic compiler, NOTE unholy use of OutDir
   48: 
   49: -define(OUT(X), filename:join([?config(priv_dir, Config), gen, to_list(X)])).
   50: 
   51: 
   52: %%-----------------------------------------------------------------
   53: %% Func: all/1
   54: %% Args: 
   55: %% Returns: 
   56: %%-----------------------------------------------------------------
   57: suite() -> [{ct_hooks,[ts_install_cth]}].
   58: 
   59: all() -> 
   60:     cases().
   61: 
   62: groups() -> 
   63:     [].
   64: 
   65: init_per_group(_GroupName, Config) ->
   66:     Config.
   67: 
   68: end_per_group(_GroupName, Config) ->
   69:     Config.
   70: 
   71: 
   72: cases() -> 
   73:     [ifr_pragma_reg, pragma_error, uggly_pragmas].
   74: 
   75: %%-----------------------------------------------------------------
   76: %% Init and cleanup functions.
   77: %%-----------------------------------------------------------------
   78: init_per_suite(Config) ->
   79:     io:format("Setting up.....~n"),
   80:     mnesia:stop(),
   81:     mnesia:delete_schema([node()]),
   82:     mnesia:create_schema([node()]),
   83:     mnesia:start(),
   84:     orber:install([node()]),
   85:     orber:start(),
   86:     if
   87: 	is_list(Config) ->
   88: 	    Config;
   89: 	true ->
   90: 	    exit("Config not a list")
   91:     end.
   92: 
   93: end_per_suite(Config) ->
   94:     io:format("Setting down.....~n"),
   95:     orber:stop(),
   96:     orber:uninstall(),
   97:     mnesia:stop(),
   98:     mnesia:delete_schema([node()]),
   99:     Config.
  100: 
  101: 
  102: 
  103: 
  104: %%-----------------------------------------------------------------
  105: %% Test Case: IFR registration with pragmas
  106: %%-----------------------------------------------------------------
  107: ifr_pragma_reg(doc) ->
  108:     ["Checks that IFR object is correctly registered under pragma engagement."];
  109: ifr_pragma_reg(suite) -> [];
  110: ifr_pragma_reg(Config) when is_list(Config) ->
  111:     ?REMAP_EXCEPT(ifr_pragma_reg_run(Config)).
  112: 
  113: ifr_pragma_reg_run(Config) ->
  114:     DataDir = ?config(data_dir, Config),
  115:     OutDir = ?OUT(ifr_pragma_reg),
  116:     File0 = filename:join(DataDir, reg_m0),
  117:     ?line ok = ic:gen(File0, stdopts(OutDir)++[{preproc_flags,
  118: 						"-I" ++ DataDir}]),
  119:     ?line ok = compile(OutDir, ifr_pragma_files()),
  120:     code:add_pathz(OutDir),
  121: 
  122:     %% OE_register for all files
  123:     ?line ok = 'oe_reg_m0':'oe_register'(),
  124:     
  125:     %% Pragma registration test
  126:     OE_IFR = orber_ifr:find_repository(),
  127:     io:format("~n##### Starting the test case #####~n"), 
  128:     check_pragma_effect(OE_IFR,"IDL:M1/T1:1.0"),
  129:     check_pragma_effect(OE_IFR,"DCE:d62207a2-011e-11ce-88b4-0800090b5d3e:3"),
  130:     check_pragma_effect(OE_IFR,"IDL:P2/T3:1.0"),
  131:     check_pragma_effect(OE_IFR,"IDL:P1/M2/T4:2.4"),
  132:     
  133:     %% OE_unregister for all files
  134:     ?line ok = 'oe_reg_m0':'oe_unregister'(),
  135:     code:del_path(OutDir),
  136:     ok.
  137: 
  138: 
  139: ifr_pragma_files() -> ['oe_reg_m0'].
  140: 
  141: 
  142: check_pragma_effect(OE_IFR,ID) ->
  143:     io:format("Checking for existance of : ~s~n",[ID]),
  144:     case orber_ifr:lookup_id(OE_IFR,ID) of
  145:         [] ->
  146: 	    test_server:fail(ID ++ " does not exist"),
  147: 	    false;
  148: 	{Def,_} ->
  149: 	    io:format("Id refers to = {~p,#Bin}~n",[Def]),
  150: 	    true
  151:     end.
  152: 
  153: 
  154: 
  155: 
  156: %%-----------------------------------------------------------------
  157: %% Test Case: Syntactical / Semantical error pragma definitions 
  158: %%-----------------------------------------------------------------
  159: pragma_error(doc) ->
  160:     ["Finds errornous pragma definitions under compilation."];
  161: pragma_error(suite) -> [];
  162: pragma_error(Config) when is_list(Config) ->
  163:     ?REMAP_EXCEPT(pragma_error_run(Config)).
  164: 
  165: pragma_error_run(Config) ->
  166:     DataDir = ?config(data_dir, Config),
  167:     OutDir = ?OUT(pragma_error),
  168:     File1 = filename:join(DataDir, reg_m1),
  169:     File2 = filename:join(DataDir, reg_m2),
  170:     File3 = filename:join(DataDir, reg_m3),
  171:     File4 = filename:join(DataDir, reg_m4),
  172:     File5 = filename:join(DataDir, reg_m5),
  173:     File6 = filename:join(DataDir, reg_m6),
  174: 
  175:     ?line error = ic:gen(File1, stdopts(OutDir)++[{preproc_flags,
  176: 						   "-I" ++ DataDir}] ),
  177:     
  178:     ?line error = ic:gen(File2, stdopts(OutDir)++[{preproc_flags,
  179: 						   "-I" ++ DataDir}] ),
  180:     
  181:     ?line error = ic:gen(File3, stdopts(OutDir)++[{preproc_flags,
  182: 						   "-I" ++ DataDir}] ),
  183:     
  184:     ?line ok = ic:gen(File4, stdopts(OutDir)++[{preproc_flags,
  185: 						"-I" ++ DataDir}] ),
  186:     
  187:     ?line error = ic:gen(File5, stdopts(OutDir)++[{preproc_flags,
  188: 						   "-I" ++ DataDir}] ),
  189:     
  190:     ?line error = ic:gen(File6, stdopts(OutDir)++[{preproc_flags,
  191: 						   "-I" ++ DataDir}] ),
  192:     ok.
  193: 
  194: 
  195: 
  196: 
  197: %%-----------------------------------------------------------------
  198: %% Test Case: IFR registration with realy uggly placed pragmas
  199: %%-----------------------------------------------------------------
  200: uggly_pragmas(doc) ->
  201:     ["Checks that IFR object is correctly registered under really uggly pragma engagement."];
  202: uggly_pragmas(suite) -> [];
  203: uggly_pragmas(Config) when is_list(Config) ->
  204:     ?REMAP_EXCEPT(uggly_pragmas_run(Config)).
  205: 
  206: uggly_pragmas_run(Config) ->
  207:     DataDir = ?config(data_dir, Config),
  208:     OutDir = ?OUT(ifr_pragma_reg),
  209:     File0 = filename:join(DataDir, uggly),
  210: 
  211:     ?line ok = ic:gen(File0, stdopts(OutDir)++[{preproc_flags,
  212: 						"-I" ++ DataDir}]),
  213: 
  214:     ?line ok = compile(OutDir, uggly_pragma_files()),
  215:     code:add_pathz(OutDir),
  216: 
  217:     %% OE_register for all files
  218:     ?line ok = 'oe_uggly':'oe_register'(),
  219:     
  220:     %% Pragma registration test
  221:     OE_IFR = orber_ifr:find_repository(),
  222:     io:format("~n##### Starting the test case #####~n"),
  223:  
  224:     check_pragma_effect(OE_IFR, "IDL:M:1.0"),
  225:     check_pragma_effect(OE_IFR, "LOCAL:SomeLocalId:10"),
  226:     check_pragma_effect(OE_IFR, "LOCAL:SomeLocalId:11"),
  227:     check_pragma_effect(OE_IFR, "LOCAL:SomeLocalId:17"),
  228:     check_pragma_effect(OE_IFR, "LOCAL:SomeLocalId:34"),
  229:     check_pragma_effect(OE_IFR, "IDL:Exc1:2.2"),
  230:     check_pragma_effect(OE_IFR, "IDL:Exc2:2.2"),
  231:     check_pragma_effect(OE_IFR, "IDL:S:1.0"),
  232:     check_pragma_effect(OE_IFR, "IDL:U:1.0"),
  233:     check_pragma_effect(OE_IFR, "LOCAL:SomeLocalId:23"),
  234:     
  235:     %% OE_unregister for all files
  236:     ?line ok = 'oe_uggly':'oe_unregister'(),
  237: 
  238:     code:del_path(OutDir),
  239:     ok.
  240: 
  241: 
  242: uggly_pragma_files() -> ['oe_uggly'].
  243: 
  244: 
  245: 
  246: 
  247: %%----------------------------
  248: 
  249: 
  250: stdopts(OutDir) ->
  251:     [{outdir, OutDir}, {maxerrs, infinity}].
  252: 
  253: 
  254: compile(Dir, Files) ->
  255:     compile(Dir, Files, []).
  256: 
  257: compile(Dir, Files, Opts) ->
  258:     {ok, Cwd} = file:get_cwd(),
  259:     file:set_cwd(Dir),
  260:     io:format("Changing to ~p~n", [Dir]),
  261:     case catch do_compile(Files, Opts) of
  262: 	ok ->
  263: 	    file:set_cwd(Cwd);
  264: 	Err ->
  265: 	    file:set_cwd(Cwd),
  266: 	    test_server:fail(Err)
  267:     end.
  268: 
  269: do_compile([], _Opts) -> ok;
  270: do_compile([F | Fs], Opts) ->
  271:     io:format("Compiling ~p", [F]),
  272:     case compile:file(F, Opts) of
  273: 	ok ->
  274: 	    io:format(" ok~n", []),
  275: 	    do_load(F, Opts),
  276: 	    do_compile(Fs, Opts);
  277: 	{ok, _} ->
  278: 	    io:format(" ok~n", []),
  279: 	    do_load(F, Opts),
  280: 	    do_compile(Fs, Opts);
  281: 	{ok, _, _} ->
  282: 	    io:format(" ok~n", []),
  283: 	    do_load(F, Opts),
  284: 	    do_compile(Fs, Opts);
  285: 	Err -> 
  286: 	    io:format(" error: ~p~n", [Err]),
  287: 	    Err
  288:     end.
  289: 
  290: do_load(File, Opts) ->
  291:     case lists:member(load, Opts) of
  292: 	true ->
  293: 	    io:format("Loading file ~p", [File]),
  294: 	    code:purge(File),
  295: 	    R = code:load_abs(File),
  296: 	    io:format("Loaded: ~p", [R]);
  297: 	false ->
  298: 	    ok
  299:     end.
  300: 
  301: 
  302: to_list(X) when is_atom(X) -> atom_to_list(X);
  303: to_list(X) -> X.
  304: 
  305: 
  306: