1%%
2%% %CopyrightBegin%
3%%
4%% Copyright Ericsson AB 2009-2016. 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-module(group_require_1_SUITE).
21
22-compile(export_all).
23
24-include_lib("common_test/include/ct.hrl").
25
26
27%%%-----------------------------------------------------------------
28%%% CONFIG FUNCS
29%%%-----------------------------------------------------------------
30
31init_per_suite(Config) ->
32    ct:comment(io_lib:format("init( ~w ): ~p", [?MODULE, suite()])),
33    Config.
34
35end_per_suite(_Config) ->
36    ok.
37
38init_per_group(G, Config) ->
39    GrProps = proplists:get_value(tc_group_properties, Config),
40    _GrProps1 = proplists:delete(name, GrProps),
41    Info = case catch group(G) of {'EXIT',_} -> []; I -> I end,
42    ct:comment(io_lib:format("init( ~w ): ~p", [G, Info])),
43    if Info /= [] -> verify_cfg(G); true -> ok end,
44    Config.
45
46end_per_group(G, Config) ->
47    GrProps = proplists:get_value(tc_group_properties, Config),
48    _GrProps1 = proplists:delete(name, GrProps),
49    Info = case catch group(G) of {'EXIT',_} -> []; I -> I end,
50    ct:comment(io_lib:format("end( ~w )", [G])),
51    if Info /= [] -> verify_cfg(G); true -> ok end,
52    ok.
53
54init_per_testcase(t101, Config) ->
55    Config;
56init_per_testcase(t111, Config) ->
57    Config;
58init_per_testcase(TestCase, Config) ->
59    GrProps = proplists:get_value(tc_group_properties, Config),
60    GrProps1 = if GrProps == undefined  -> []; true -> GrProps end,
61    verify_cfg(proplists:get_value(name, GrProps1)),
62    if TestCase == t72 -> verify_cfg(TestCase); true -> ok end,
63    Info = case catch apply(?MODULE,TestCase,[]) of
64	       {'EXIT',_} -> [];
65	       I -> I
66	   end,
67    ct:comment(io_lib:format("init( ~w ): ~p", [TestCase, Info])),
68    Config.
69
70end_per_testcase(t101, Config) ->
71    ok;
72end_per_testcase(t111, Config) ->
73    ok;
74end_per_testcase(TestCase, Config) ->
75    GrProps = proplists:get_value(tc_group_properties, Config),
76    GrProps1 = if GrProps == undefined  -> []; true -> GrProps end,
77    verify_cfg(proplists:get_value(name, GrProps1)),
78    if TestCase == t72 -> verify_cfg(TestCase); true -> ok end,
79    ok.
80
81verify_cfg(undefined) ->
82    ok;
83verify_cfg(Name) ->
84    Key = list_to_atom(atom_to_list(Name) ++ "_cfg"),
85    Alias = list_to_atom(atom_to_list(Name) ++ "_cfg_alias"),
86    Val = list_to_atom(atom_to_list(Name) ++ "_cfg_val"),
87    ct:pal("Reading ~p & ~p. Expecting ~p.", [Key,Alias,Val]),
88    Val = ct:get_config(Key),
89    Val = ct:get_config(Alias),
90    suite_cfg_val = ct:get_config(suite_cfg),
91    suite_cfg_val = ct:get_config(suite_cfg_alias).
92
93
94
95%%%------------------------------------------------------------------
96%%% TEST DECLARATIONS
97%%%------------------------------------------------------------------
98
99groups() ->
100    [{g1,[],[t11]},
101     {g2,[],[t21]},
102     {g3,[],[t31]},
103     {g4,[],[t41]},
104
105     {g5,[],[{group,g6},t51,{group,g7}]},
106
107       {g6,[],[t61]},
108       {g7,[],[t71,t72]},
109
110     {g8,[],[t81]},
111     {g9,[],[t91]},
112     {g10,[],[t101]},
113     {g11,[],[t111]}
114    ].
115
116
117all() ->
118    [t1,
119     {group,g1},
120     {group,g2},
121     {group,g3},
122     {group,g4},
123     {group,g5},
124     {group,g8},
125     {group,g9},
126     {group,g10},
127     {group,g11}
128    ].
129
130%%%-----------------------------------------------------------------
131%%% INFO FUNCS
132%%%-----------------------------------------------------------------
133
134suite() -> [{require,suite_cfg},
135	    {require,suite_cfg_alias,suite_cfg},
136	    {require,common1},
137	    {default_config,suite_cfg,suite_cfg_val},
138	    {default_config,common1,common1_val}].
139
140group(g1) -> [{require,g1_cfg},
141	      {require,g1_cfg_alias,g1_cfg},
142	      {default_config,g1_cfg,g1_cfg_val}];
143
144group(g2) -> [{require,g2_cfg},
145	      {require,g2_cfg_alias,g2_cfg},
146	      {require,common1},
147	      {require,common2},
148	      {default_config,g2_cfg,g2_cfg_val},
149	      {default_config,common1,common1_val},
150	      {default_config,common2,common2_val}];
151
152group(g3) -> [{require,g3_cfg},
153	      {require,g3_cfg_alias,g3_cfg},
154	      {require,common2},
155	      {require,common2_alias,common2},
156	      {default_config,g3_cfg,g3_cfg_val},
157	      {default_config,common2,common2_val}];
158
159group(g4) -> [{require,g4_cfg},
160	      {require,g4_cfg_alias,g4_cfg},
161	      {require,common2_alias,common3},
162	      {default_config,g4_cfg,g4_cfg_val}];
163
164group(g5) -> [{require,g5_cfg},
165	      {require,g5_cfg_alias,g5_cfg},
166	      {default_config,g5_cfg,g5_cfg_val}];
167
168group(g6) -> [{require,g6_cfg},
169	      {require,g6_cfg_alias,g6_cfg},
170	      {default_config,g6_cfg,g6_cfg_val}];
171
172group(g7) -> [{require,g7_cfg},
173	      {require,g7_cfg_alias,g7_cfg},
174	      {default_config,g7_cfg,g7_cfg_val}];
175
176group(g8) -> [{require,non_existing}];
177
178group(g9) -> [{require,g9_cfg},
179	      {require,g9_cfg_alias,g9_cfg},
180	      {default_config,g9_cfg,g9_cfg_val}];
181
182group(G) when G /= g11 -> [].
183
184t72() -> [{require,t72_cfg},
185	  {require,t72_cfg_alias,t72_cfg},
186	  {default_config,t72_cfg,t72_cfg_val}].
187
188t91() -> [{require,non_existing}].
189
190
191%%%------------------------------------------------------------------
192%%% TEST CASES
193%%%------------------------------------------------------------------
194
195t1(_) ->
196    suite_cfg_val = ct:get_config(suite_cfg).
197
198t11(_) ->
199    suite_cfg_val = ct:get_config(suite_cfg),
200    suite_cfg_val = ct:get_config(suite_cfg_alias),
201    g1_cfg_val = ct:get_config(g1_cfg),
202    g1_cfg_val = ct:get_config(g1_cfg_alias).
203
204t21(_) ->
205    suite_cfg_val = ct:get_config(suite_cfg),
206    g2_cfg_val = ct:get_config(g2_cfg),
207    g2_cfg_val = ct:get_config(g2_cfg_alias),
208    common1_val = ct:get_config(common1),
209    common2_val = ct:get_config(common2).
210
211t31(_) ->
212    suite_cfg_val = ct:get_config(suite_cfg),
213    g3_cfg_val = ct:get_config(g3_cfg),
214    g3_cfg_val = ct:get_config(g3_cfg_alias),
215    common2_val = ct:get_config(common2),
216    common2_val = ct:get_config(common2_alias).
217
218t41(_) ->
219    exit(should_be_skipped).
220
221t51(_) ->
222    suite_cfg_val = ct:get_config(suite_cfg),
223    g5_cfg_val = ct:get_config(g5_cfg),
224    g5_cfg_val = ct:get_config(g5_cfg_alias).
225
226t61(_) ->
227    suite_cfg_val = ct:get_config(suite_cfg),
228    g5_cfg_val = ct:get_config(g5_cfg),
229    g5_cfg_val = ct:get_config(g5_cfg_alias),
230    g6_cfg_val = ct:get_config(g6_cfg),
231    g6_cfg_val = ct:get_config(g6_cfg_alias).
232
233t71(_) ->
234    suite_cfg_val = ct:get_config(suite_cfg),
235    g5_cfg_val = ct:get_config(g5_cfg),
236    g5_cfg_val = ct:get_config(g5_cfg_alias),
237    g7_cfg_val = ct:get_config(g7_cfg),
238    g7_cfg_val = ct:get_config(g7_cfg_alias).
239
240t72(_) ->
241    suite_cfg_val = ct:get_config(suite_cfg),
242    g5_cfg_val = ct:get_config(g5_cfg),
243    g5_cfg_val = ct:get_config(g5_cfg_alias),
244    g7_cfg_val = ct:get_config(g7_cfg),
245    g7_cfg_val = ct:get_config(g7_cfg_alias),
246    t72_cfg_val = ct:get_config(t72_cfg).
247
248t81(_) ->
249    exit(should_be_skipped).
250
251t91(_) ->
252    exit(should_be_skipped).
253
254t101(_) ->
255    suite_cfg_val = ct:get_config(suite_cfg).
256
257t111(_) ->
258    suite_cfg_val = ct:get_config(suite_cfg).
259
260
261