Sync with 5.4.0
[deliverable/titan.core.git] / regression_test / ttcn2json / CompareSchemas.ttcn
1 /******************************************************************************
2 * Copyright (c) 2000-2015 Ericsson Telecom AB
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 ******************************************************************************/
8
9 // This module compares two JSON schemas generated by the TITAN compiler
10 module CompareSchemas {
11
12 //////////////////////////////////////
13 // JSON schema container data types //
14 //////////////////////////////////////
15
16 // top level object
17 type record JsonSchema {
18 DefSchemas defs,
19 RefSchemas refs
20 }
21
22 // definitions section:
23 type set of DefSchema DefSchemas;
24
25 type record DefSchema {
26 charstring moduleName,
27 charstring typeName,
28 TypeSchema schema
29 }
30
31 type set of TypeSchemaElement TypeSchema;
32
33 type record TypeSchemaElement {
34 ElemKey key,
35 ElemValue val
36 }
37
38 type enumerated ElemKey {
39 Ref, Type, SubType, Pattern, OriginalName, UnusedAlias, MinItems, MaxItems, MinLength, MaxLength, Minimum, Maximum, // strVal
40 AdditionalProperties, OmitAsNull, exclusiveMinimum, exclusiveMaximum, // boolVal
41 Default, // strVal or boolVal
42 NumericValues, Required, FieldOrder, // strArrayVal
43 Enum, // arrayVal
44 Items, // typeVal
45 AnyOf, AllOf, // typeArrayVal
46 Properties, // fieldSetVal
47 Extension // extVal
48 }
49
50 type union ElemValue {
51 charstring strVal,
52 boolean boolVal,
53 record of charstring strArrayVal,
54 TypeSchema typeVal,
55 record of TypeSchema typeArrayVal,
56 set of FieldValue fieldSetVal,
57 ExtensionValue extVal,
58 ArrayValue arrayVal
59 }
60
61 type record FieldValue {
62 charstring fieldName,
63 TypeSchema schema
64 }
65
66 type record ExtensionValue {
67 charstring key,
68 charstring val
69 }
70
71 type union AnyValue {
72 charstring strVal, // number, string or null
73 boolean boolVal,
74 ObjectValue objectVal,
75 ArrayValue arrayVal
76 }
77
78 type record ObjectSegment {
79 charstring key,
80 AnyValue val
81 }
82
83 type set of ObjectSegment ObjectValue;
84
85 type record of AnyValue ArrayValue;
86
87 // references/functions section:
88 type set of RefSchema RefSchemas;
89
90 type record RefSchema {
91 charstring ref,
92 EncDecData enc optional,
93 EncDecData dec optional
94 }
95
96 type record EncDecData {
97 PrototypeData prototype,
98 ErrorBehaviorData eb optional,
99 charstring printing optional
100 }
101
102 type record of charstring PrototypeData;
103
104 type record of ErrorBehaviorElem ErrorBehaviorData;
105
106 type record ErrorBehaviorElem {
107 charstring errorType,
108 charstring errorBehavior
109 }
110
111 //////////////////////////////////
112 // Import and compare functions //
113 //////////////////////////////////
114
115 // Imports a JSON schema from the given file and stores it in the specified container.
116 // Throws a Dynamic Testcase Error if the file cannot be read or does not have the correct format.
117 // The resulting JsonSchema should not have any unbound fields.
118 external function f_ext_import_schema(in charstring file, out JsonSchema schema);
119
120 // Compares the two schemas found in the files specified by the parameters.
121 // Returns true if they are equal.
122 function f_compare_schemas(in charstring schema_file1, in charstring schema_file2) return boolean
123 {
124 // read the schemas from the files
125 var JsonSchema schema1;
126 f_ext_import_schema(schema_file1, schema1);
127 var JsonSchema schema2;
128 f_ext_import_schema(schema_file2, schema2);
129
130 // log both schemas (good luck digging through these...)
131 //log("Generated (", schema_file1, "): ", schema1);
132 //log("Expected (", schema_file2, "): ", schema2);
133
134 // set the verdict depending on their equality
135 if (match(schema1, schema2)) {
136 return true;
137 }
138 log(match(schema1, schema2));
139 return false;
140 }
141
142 }
This page took 0.065646 seconds and 5 git commands to generate.