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