aboutsummaryrefslogtreecommitdiffstats
path: root/lib/asn1/test/asn1_SUITE.erl
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2012-12-11 09:12:47 +0100
committerBjörn Gustavsson <[email protected]>2012-12-18 14:46:14 +0100
commit89b47bd53200816ac058eafe0b7d00745183fee4 (patch)
treea96fe6c84ba203620e8247fc7c80ec3b8b6c04fc /lib/asn1/test/asn1_SUITE.erl
parentb82d7370ddef1a91e960486716c8dea3d31c2e3b (diff)
downloadotp-89b47bd53200816ac058eafe0b7d00745183fee4.tar.gz
otp-89b47bd53200816ac058eafe0b7d00745183fee4.tar.bz2
otp-89b47bd53200816ac058eafe0b7d00745183fee4.zip
Add a test case for constraint equivalence
The constraint simplification pass need to be seriously rethought and rewritten. As a starting point, add a test case to test that equivalent ways to write a constraint are reduced to the same simplified constraint. Fix a few obvious bugs to make the test cases to pass.
Diffstat (limited to 'lib/asn1/test/asn1_SUITE.erl')
-rw-r--r--lib/asn1/test/asn1_SUITE.erl31
1 files changed, 30 insertions, 1 deletions
diff --git a/lib/asn1/test/asn1_SUITE.erl b/lib/asn1/test/asn1_SUITE.erl
index f8ef1ac19a..3d3ed65a65 100644
--- a/lib/asn1/test/asn1_SUITE.erl
+++ b/lib/asn1/test/asn1_SUITE.erl
@@ -53,7 +53,8 @@ groups() ->
[{compile, parallel([]),
[c_syntax,
c_string,
- c_implicit_before_choice]},
+ c_implicit_before_choice,
+ constraint_equivalence]},
{ber, parallel([]),
[ber_choiceinseq,
@@ -618,6 +619,34 @@ c_implicit_before_choice(Config, Rule, Opts) ->
{error, _R2} = asn1ct:compile(filename:join(DataDir, "CCSNARG3"),
[Rule, {outdir, CaseDir}|Opts]).
+constraint_equivalence(Config) ->
+ DataDir = ?config(data_dir, Config),
+ CaseDir = ?config(case_dir, Config),
+ Asn1Spec = "ConstraintEquivalence",
+ Asn1Src = filename:join(DataDir, Asn1Spec),
+ ok = asn1ct:compile(Asn1Src, [abs,{outdir,CaseDir}]),
+ AbsFile = filename:join(CaseDir, Asn1Spec++".abs"),
+ {ok,Terms} = file:consult(AbsFile),
+ Cs = [begin
+ 'INTEGER' = element(3, Type), %Assertion.
+ Constraints = element(4, Type),
+ Name1 = atom_to_list(Name0),
+ {Name,_} = lists:splitwith(fun(C) -> C =/= $X end, Name1),
+ {Name,Constraints}
+ end || {typedef,_,_,Name0,Type} <- Terms],
+ R = sofs:relation(Cs, [{name,constraint}]),
+ F0 = sofs:relation_to_family(R),
+ F = sofs:to_external(F0),
+ Diff = [E || {_,L}=E <- F, length(L) > 1],
+ case Diff of
+ [] ->
+ ok;
+ [_|_] ->
+ io:put_chars("Not equivalent:\n"),
+ [io:format("~s: ~p\n", [N,D]) || {N,D} <- Diff],
+ test_server:fail(length(Diff))
+ end.
+
parse(Config) ->
[asn1_test_lib:compile(M, Config, [abs]) || M <- test_modules()].