Sync with 5.2.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, // strVal
40 AdditionalProperties, OmitAsNull, // boolVal
41 Default, // strVal or boolVal
42 Enum, NumericValues, Required, FieldOrder, // strArrayVal
43 Items, // typeVal
44 AnyOf, // typeArrayVal
45 Properties // fieldSetVal
46 }
47
48 type union ElemValue {
49 charstring strVal,
50 boolean boolVal,
51 record of charstring strArrayVal,
52 TypeSchema typeVal,
53 record of TypeSchema typeArrayVal,
54 set of FieldValue fieldSetVal
55 }
56
57 type record FieldValue {
58 charstring fieldName,
59 TypeSchema schema
60 }
61
62 // references/functions section:
63 type set of RefSchema RefSchemas;
64
65 type record RefSchema {
66 charstring ref,
67 EncDecData enc optional,
68 EncDecData dec optional
69 }
70
71 type record EncDecData {
72 PrototypeData prototype,
73 ErrorBehaviorData eb optional,
74 charstring printing optional
75 }
76
77 type record of charstring PrototypeData;
78
79 type record of ErrorBehaviorElem ErrorBehaviorData;
80
81 type record ErrorBehaviorElem {
82 charstring errorType,
83 charstring errorBehavior
84 }
85
86 //////////////////////////////////
87 // Import and compare functions //
88 //////////////////////////////////
89
90 // Imports a JSON schema from the given file and stores it in the specified container.
91 // Throws a Dynamic Testcase Error if the file cannot be read or does not have the correct format.
92 // The resulting JsonSchema should not have any unbound fields.
93 external function f_ext_import_schema(in charstring file, out JsonSchema schema);
94
95 // Compares the two schemas found in the files specified by the parameters.
96 // Returns true if they are equal.
97 function f_compare_schemas(in charstring schema_file1, in charstring schema_file2) return boolean
98 {
99 // read the schemas from the files
100 var JsonSchema schema1;
101 f_ext_import_schema(schema_file1, schema1);
102 var JsonSchema schema2;
103 f_ext_import_schema(schema_file2, schema2);
104
105 // log both schemas (good luck digging through these...)
106 //log("Generated (", schema_file1, "): ", schema1);
107 //log("Expected (", schema_file2, "): ", schema2);
108
109 // set the verdict depending on their equality
110 if (match(schema1, schema2)) {
111 return true;
112 }
113 log(match(schema1, schema2));
114 return false;
115 }
116
117 }
This page took 0.071634 seconds and 5 git commands to generate.