4
%% Copyright Ericsson AB 2005-2010. All Rights Reserved.
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/.
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
20
%%----------------------------------------------------------------------
21
%% Purpose: Verify the application specifics of the asn1 application
22
%%----------------------------------------------------------------------
23
-module(asn1_app_test).
27
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30
[fields, modules, exportall, app_depend].
35
init_per_group(_GroupName, Config) ->
38
end_per_group(_GroupName, Config) ->
42
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44
init_per_suite(suite) -> [];
45
init_per_suite(doc) -> [];
46
init_per_suite(Config) when is_list(Config) ->
49
io:format("AppFile: ~n~p~n", [AppFile]),
50
[{app_file, AppFile}|Config];
56
LibDir = code:lib_dir(App),
57
File = filename:join([LibDir, "ebin", atom_to_list(App) ++ ".app"]),
58
case file:consult(File) of
59
{ok, [{application, App, AppFile}]} ->
62
{error, {invalid_format, Error}}
66
end_per_suite(suite) -> [];
67
end_per_suite(doc) -> [];
68
end_per_suite(Config) when is_list(Config) ->
72
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78
fields(Config) when is_list(Config) ->
79
AppFile = key1search(app_file, Config),
80
Fields = [vsn, description, modules, registered, applications],
81
case check_fields(Fields, AppFile, []) of
85
fail({missing_fields, Missing})
88
check_fields([], _AppFile, Missing) ->
90
check_fields([Field|Fields], AppFile, Missing) ->
91
check_fields(Fields, AppFile, check_field(Field, AppFile, Missing)).
93
check_field(Name, AppFile, Missing) ->
94
io:format("checking field: ~p~n", [Name]),
95
case lists:keymember(Name, 1, AppFile) of
103
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109
modules(Config) when is_list(Config) ->
110
AppFile = key1search(app_file, Config),
111
Mods = key1search(modules, AppFile),
112
EbinList = get_ebin_mods(asn1),
113
case missing_modules(Mods, EbinList, []) of
117
throw({error, {missing_modules, Missing}})
119
case extra_modules(Mods, EbinList, []) of
123
check_asn1ct_modules(Extra)
124
% throw({error, {extra_modules, Extra}})
128
get_ebin_mods(App) ->
129
LibDir = code:lib_dir(App),
130
EbinDir = filename:join([LibDir,"ebin"]),
131
{ok, Files0} = file:list_dir(EbinDir),
132
Files1 = [lists:reverse(File) || File <- Files0],
133
[list_to_atom(lists:reverse(Name)) || [$m,$a,$e,$b,$.|Name] <- Files1].
135
check_asn1ct_modules(Extra) ->
136
ASN1CTMods = [asn1ct,asn1ct_check,asn1_db,asn1ct_pretty_format,
137
asn1ct_gen,asn1ct_gen_per,asn1ct_gen_per_rt2ct,
138
asn1ct_name,asn1ct_constructed_per,asn1ct_constructed_ber,
139
asn1ct_gen_ber,asn1ct_constructed_ber_bin_v2,
140
asn1ct_gen_ber_bin_v2,asn1ct_value,
141
asn1ct_tok,asn1ct_parser2],
142
case Extra -- ASN1CTMods of
146
throw({error, {extra_modules, Extra2}})
149
missing_modules([], _Ebins, Missing) ->
151
missing_modules([Mod|Mods], Ebins, Missing) ->
152
case lists:member(Mod, Ebins) of
154
missing_modules(Mods, Ebins, Missing);
156
io:format("missing module: ~p~n", [Mod]),
157
missing_modules(Mods, Ebins, [Mod|Missing])
161
extra_modules(_Mods, [], Extra) ->
163
extra_modules(Mods, [Mod|Ebins], Extra) ->
164
case lists:member(Mod, Mods) of
166
extra_modules(Mods, Ebins, Extra);
168
io:format("supefluous module: ~p~n", [Mod]),
169
extra_modules(Mods, Ebins, [Mod|Extra])
173
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
180
exportall(Config) when is_list(Config) ->
181
AppFile = key1search(app_file, Config),
182
Mods = key1search(modules, AppFile),
183
check_export_all(Mods).
186
check_export_all([]) ->
188
check_export_all([Mod|Mods]) ->
189
case (catch apply(Mod, module_info, [compile])) of
190
{'EXIT', {undef, _}} ->
191
check_export_all(Mods);
193
case lists:keysearch(options, 1, O) of
195
check_export_all(Mods);
196
{value, {options, List}} ->
197
case lists:member(export_all, List) of
199
throw({error, {export_all, Mod}});
201
check_export_all(Mods)
207
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
213
app_depend(Config) when is_list(Config) ->
214
AppFile = key1search(app_file, Config),
215
Apps = key1search(applications, AppFile),
221
check_apps([App|Apps]) ->
226
throw({error, {missing_app, {App, Error}}})
230
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
234
exit({suite_failed, Reason}).
236
key1search(Key, L) ->
237
case lists:keysearch(Key, 1, L) of
239
fail({not_found, Key, L});
240
{value, {Key, Value}} ->