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