1%%
2%% %CopyrightBegin%
3%%
4%% Copyright Ericsson AB 1999-2020. 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%% Purpose: Define common macros for testing
24%%----------------------------------------------------------------------
25
26-ifndef(APPLICATION).
27-define(APPLICATION, megaco).
28-endif.
29
30-define(LIB, megaco_test_lib).
31
32-define(PCALL(F, T, D),      ?LIB:proxy_call(F, T, D)).
33
34-define(APPLY(Proxy, Fun),
35	Proxy ! {apply, Fun}).
36
37-define(LOG(Format, Args),
38	?LIB:log(Format, Args, ?MODULE, ?LINE)).
39
40-define(ERROR(Reason),
41	?LIB:error(Reason, ?MODULE, ?LINE)).
42
43-define(OS_BASED_SKIP(Skippable),
44	?LIB:os_based_skip(Skippable)).
45
46-define(NON_PC_TC_MAYBE_SKIP(Config, Condition),
47	?LIB:non_pc_tc_maybe_skip(Config, Condition, ?MODULE, ?LINE)).
48
49-define(SKIP(Reason),
50	?LIB:skip(Reason, ?MODULE, ?LINE)).
51
52-define(VERIFYL(Expected, Expr),
53	fun(A,B) when list(A), list(B) ->
54		A1 = lists:sort(A),
55		B1 = lists:sort(B),
56		case A1 of
57		    B1 -> ?LOG("Ok, ~p~n", [B]);
58		    _  -> ?ERROR(B)
59		end,
60		B;
61	   (A,A) ->
62		?LOG("Ok, ~p~n", [A]),
63		A;
64	   (A,B) ->
65		?ERROR(B),
66		B
67	end(Expected, (catch Expr))).
68
69-define(VERIFY(Expected, Expr),
70	fun() ->
71		AcTuAlReS = (catch (Expr)),
72		case AcTuAlReS of
73		    Expected -> ?LOG("Ok, ~p~n", [AcTuAlReS]);
74		    _        ->	?ERROR(AcTuAlReS)
75		end,
76		AcTuAlReS
77	end()).
78
79-define(RECEIVE(Expected),
80	?VERIFY(Expected, ?LIB:flush())).
81
82-define(MULTI_RECEIVE(Expected),
83	?VERIFY(lists:sort(Expected), lists:sort(?LIB:flush()))).
84
85-define(TRY_TC(TCN, N, V, PRE, CASE, POST),
86        ?LIB:try_tc(TCN, N, V, PRE, CASE, POST)).
87
88-define(ACQUIRE_NODES(N, Config),
89	?LIB:prepare_test_case([init, {stop_app, megaco}],
90                               N, Config, ?FILE, ?LINE)).
91
92-define(START_NODE(Node, Force),   ?LIB:start_node(Node, Force, ?FILE, ?LINE)).
93-define(START_NODE(Node),          ?START_NODE(Node, false)).
94-define(START_NODES(Nodes, Force), ?LIB:start_nodes(Nodes, Force, ?FILE, ?LINE)).
95-define(START_NODES(Nodes),        ?START_NODES(Nodes, false)).
96-define(STOP_NODE(Node),           ?LIB:stop_node(Node,   ?FILE, ?LINE)).
97-define(STOP_NODES(Nodes),         ?LIB:stop_nodes(Nodes, ?FILE, ?LINE)).
98
99-define(SLEEP(MSEC),    ?LIB:sleep(MSEC)).
100-define(HOURS(T),       ?LIB:hours(T)).
101-define(MINS(T),        ?LIB:minutes(T)).
102-define(MINUTES(T),     ?MINS(T)).
103-define(SECS(T),        ?LIB:seconds(T)).
104-define(SECONDS(T),     ?SECS(T)).
105-define(FTS(),          megaco:format_timestamp(erlang:timestamp())).
106-define(FTS(TS),        megaco:format_timestamp(TS)).
107-define(F(F,A),         lists:flatten(io_lib:format(F, A))).
108
109-define(ANNOUNCE_SUITE_INIT(),
110	io:format(user, "~n*** ~s *** suite ~w init~n~n", [?FTS(), ?MODULE])).
111-define(ANNOUNCE_GROUP_INIT(GR),
112	io:format(user, "~n*** ~s *** group ~w:~w init~n~n",
113		  [?FTS(), ?MODULE, GR])).
114-define(ANNOUNCE_CASE_INIT(C),
115	io:format(user, "~n*** ~s *** case ~w:~w init~n~n",
116		  [?FTS(), ?MODULE, C])).
117
118