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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
#!/usr/bin/env perl
#
# Run some general tests around the generation of elements. We will
# test seperate components in more detail in other scripts.
use warnings;
use strict;
use lib 'lib','t';
use TestTools;
use XML::Compile::Schema;
use XML::Compile::Tester;
use Test::More tests => 65;
set_compile_defaults
elements_qualified => 'NONE';
my $schema = XML::Compile::Schema->new( <<__SCHEMA__ );
<schema targetNamespace="$TestNS"
xmlns="$SchemaNS"
xmlns:me="$TestNS">
<element name="test1" type="int" />
<element name="test3" type="me:st" />
<simpleType name="st">
<restriction base="int" />
</simpleType>
<element name="test4" type="me:ct" />
<complexType name="ct">
<sequence>
<element name="ct_1" type="int" />
<element name="ct_2" type="int" />
</sequence>
</complexType>
<element name="test5">
<complexType>
<sequence>
<element name="ct_1" type="int" />
<element name="ct_2" type="int" />
</sequence>
</complexType>
</element>
<element name="test6">
<simpleType>
<restriction base="int" />
</simpleType>
</element>
<element name="test7">
<complexType>
<sequence>
<element name="ct_1" type="int" />
<element name="ct_2" type="int" default="42" />
</sequence>
</complexType>
</element>
</schema>
__SCHEMA__
ok(defined $schema);
#
# simple element type
#
test_rw($schema, test1 => <<__XML, 42);
<test1>42</test1>
__XML
test_rw($schema, test1 => <<__XML, -1);
<test1>-1</test1>
__XML
test_rw($schema, test1 => <<__XML, 121);
<test1>
121
</test1>
__XML
#
# the simpleType, less simple type
#
test_rw($schema, test3 => <<__XML, 78);
<test3>78</test3>
__XML
test_rw($schema, test6 => <<__XML, 79);
<test6>79</test6>
__XML
#
# The not so complex complexType
#
test_rw($schema, test4 => <<__XML, {ct_1 => 14, ct_2 => 43});
<test4>
<ct_1>14</ct_1>
<ct_2>43</ct_2>
</test4>
__XML
test_rw($schema, test5 => <<__XML, {ct_1 => 15, ct_2 => 44});
<test5>
<ct_1>15</ct_1>
<ct_2>44</ct_2>
</test5>
__XML
# for test6 see above
#
# Test default: should not be set automatically
#
test_rw($schema, test7 => <<__XML, {ct_1 => 41, ct_2 => 42}, <<__XML, {ct_1 => 41});
<test7><ct_1>41</ct_1></test7>
__XML
<test7><ct_1>41</ct_1></test7>
__XML
|