File: XsdSchemaTest.vala

package info (click to toggle)
gxml 0.20.4%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,364 kB
  • sloc: xml: 131,277; ansic: 786; javascript: 328; python: 88; makefile: 35; sh: 11
file content (89 lines) | stat: -rw-r--r-- 3,030 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
/* GomSchema.vala
 *
 * Copyright (C) 2017  Daniel Espinosa <esodan@gmail.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
 *
 * Authors:
 *      Daniel Espinosa <esodan@gmail.com>
 */

using GXml;

class GomSchemaTest : GLib.Object  {
	public static int main (string[] args) {
		Test.init (ref args);
		Test.add_func ("/gxml/gom-schema/read", () => {
			try {
				var f = GLib.File.new_for_path (GXmlTestConfig.TEST_DIR+"/schema-test.xsd");
				assert (f.query_exists ());
				var sch = new XsdSchema ();
#if DEBUG
				message ("XSD Empty: "+sch.write_string ());
				message ("XSD node name: "+sch.node_name);
#endif
				assert (sch.local_name == "schema");
				sch.read_from_file (f);
#if DEBUG
				message ("XSD: "+sch.write_string ());
#endif
				assert (sch.simple_type_definitions != null);
				var st = sch.simple_type_definitions.get_item (0) as XsdSimpleType;
				assert (st != null);
				assert (st.restriction != null);
				assert (st.restriction.base != null);
				assert (st.restriction.base == "xs:string");
				assert (st.restriction.enumerations != null);
				assert (st.restriction.enumerations.length == 20);
				var enumt1 = st.restriction.enumerations.get_item (0) as XsdTypeRestrictionEnumeration;
				assert (enumt1 != null);
				assert (enumt1.value != null);
				assert (enumt1.value == "01");
				var enumt20 = st.restriction.enumerations.get_item (19) as XsdTypeRestrictionEnumeration;
				assert (enumt20 != null);
				assert (enumt20.value != null);
				assert (enumt20.value == "99");
			} catch (GLib.Error e) {
				GLib.message ("Error: "+e.message);
				assert_not_reached ();
			}
		});
		Test.add_func ("/gxml/xsd-array-string/attribute-enumeration", () => {
			try {
				var f = GLib.File.new_for_path (GXmlTestConfig.TEST_DIR+"/schema-test.xsd");
				assert (f.query_exists ());
				var ars = new GXml.XsdArrayString ();
				ars.simple_type = "MethodCode";
				ars.source = f;
				ars.load ();
				assert (ars.search ("01"));
				assert (ars.search ("02"));
				assert (ars.search ("03"));
				assert (ars.search ("04"));
				assert (ars.search ("05"));
				assert (ars.search ("06"));
				assert (!ars.search ("07"));
				assert (ars.search ("99"));
			} catch (GLib.Error e) {
				GLib.message ("Error: "+e.message);
				assert_not_reached ();
			}
		});

		Test.run ();

		return 0;
	}
}