Sync with 5.4.0
[deliverable/titan.core.git] / regression_test / ttcn2json / CompareSchemas.ttcn
CommitLineData
af710487 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
10module CompareSchemas {
11
12//////////////////////////////////////
13// JSON schema container data types //
14//////////////////////////////////////
15
16// top level object
17type record JsonSchema {
18 DefSchemas defs,
19 RefSchemas refs
20}
21
22// definitions section:
23type set of DefSchema DefSchemas;
24
25type record DefSchema {
26 charstring moduleName,
27 charstring typeName,
28 TypeSchema schema
29}
30
31type set of TypeSchemaElement TypeSchema;
32
33type record TypeSchemaElement {
34 ElemKey key,
35 ElemValue val
36}
37
38type enumerated ElemKey {
3abe9331 39 Ref, Type, SubType, Pattern, OriginalName, UnusedAlias, MinItems, MaxItems, MinLength, MaxLength, Minimum, Maximum, // strVal
40 AdditionalProperties, OmitAsNull, exclusiveMinimum, exclusiveMaximum, // boolVal
af710487 41 Default, // strVal or boolVal
3abe9331 42 NumericValues, Required, FieldOrder, // strArrayVal
43 Enum, // arrayVal
af710487 44 Items, // typeVal
3abe9331 45 AnyOf, AllOf, // typeArrayVal
46 Properties, // fieldSetVal
47 Extension // extVal
af710487 48}
49
50type union ElemValue {
51 charstring strVal,
52 boolean boolVal,
53 record of charstring strArrayVal,
54 TypeSchema typeVal,
55 record of TypeSchema typeArrayVal,
3abe9331 56 set of FieldValue fieldSetVal,
57 ExtensionValue extVal,
58 ArrayValue arrayVal
af710487 59}
60
61type record FieldValue {
62 charstring fieldName,
63 TypeSchema schema
64}
65
3abe9331 66type record ExtensionValue {
67 charstring key,
68 charstring val
69}
70
71type union AnyValue {
72 charstring strVal, // number, string or null
73 boolean boolVal,
74 ObjectValue objectVal,
75 ArrayValue arrayVal
76}
77
78type record ObjectSegment {
79 charstring key,
80 AnyValue val
81}
82
83type set of ObjectSegment ObjectValue;
84
85type record of AnyValue ArrayValue;
86
af710487 87// references/functions section:
88type set of RefSchema RefSchemas;
89
90type record RefSchema {
91 charstring ref,
92 EncDecData enc optional,
93 EncDecData dec optional
94}
95
96type record EncDecData {
97 PrototypeData prototype,
98 ErrorBehaviorData eb optional,
99 charstring printing optional
100}
101
102type record of charstring PrototypeData;
103
104type record of ErrorBehaviorElem ErrorBehaviorData;
105
106type 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.
118external 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.
122function 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.065276 seconds and 5 git commands to generate.