Merge lp:~zorba-coders/zorba/bug924987 into lp:zorba

Proposed by Till Westmann
Status: Superseded
Proposed branch: lp:~zorba-coders/zorba/bug924987
Merge into: lp:zorba
Diff against target: 811 lines (+563/-31)
13 files modified
include/zorba/identtypes.h (+16/-2)
include/zorba/typeident.h (+34/-1)
src/api/CMakeLists.txt (+1/-0)
src/api/identtypesimpl.cpp (+60/-0)
src/api/typeidentimpl.cpp (+116/-5)
src/types/typemanagerimpl.cpp (+32/-0)
src/types/typeops.cpp (+55/-22)
src/types/typeops.h (+2/-1)
test/unit/CMakeLists.txt (+4/-0)
test/unit/module5.xq (+20/-0)
test/unit/module6.xq (+38/-0)
test/unit/schema1.xsd (+21/-0)
test/unit/staticcollectionmanager.cpp (+164/-0)
To merge this branch: bzr merge lp:~zorba-coders/zorba/bug924987
Reviewer Review Type Date Requested Status
Markos Zaharioudakis Needs Fixing
Till Westmann Approve
Review via email: mp+91144@code.launchpad.net

This proposal has been superseded by a proposal from 2012-03-06.

Commit message

fixes bug 924987
- extended TypeIdentifier to also support schema-element, schema-attribute
  and namespace-node sequence types
- fixed TypeOps::get_type_identifier
- added a test to the staticcollectionmanager unit test
- added operator<< for TypeIdentifier

Description of the change

fixes bug 924987
- extended TypeIdentifier to also support schema-element, schema-attribute
  and namespace-node sequence types
- fixed TypeOps::get_type_identifier
- added a test to the staticcollectionmanager unit test
- added operator<< for TypeIdentifier

To post a comment you must log in.
Revision history for this message
Till Westmann (tillw) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job bug924987-2012-02-01T22-33-57.831Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1. Got: 1 Approve, 2 Pending.

Revision history for this message
Markos Zaharioudakis (markos-za) wrote :

1. Zorba does not support the (optional) namespace nodes and associated sequence types. So, the releted code should be removed.

2. Why do the createSchemaElementType and createSchemaAttributeType have a contentType param? This is not according to the sequence type syntax and should be removed.

3. Just curious: why doesn't the emit() method print out the type using the w3c sequence type syntax?

4. An XQType of USER_DEFINED_KIND (i.e., an instance of the UserDefinedXQType class) represents a sequence type only if the type is atomic. So, in TypeOps::get_type_identifier(), a TypeIdentifier should be created only is the type is atomic; otherwise an error should be thrown (or an assertion triggered).

5. To be complete, the TypeManagerImpl::create_type(const TypeIdentifier& ident) method should also be fixed. It's up to you whether you want to do it or not.

Revision history for this message
Markos Zaharioudakis (markos-za) :
review: Needs Fixing
Revision history for this message
Till Westmann (tillw) wrote :

1. ok

2. I see your point, but I think that I need information about the content type. Is there a way to get that from the public API? (I looked over the public static context and didn't see something obvious.)

3. Good question. Actually, the type doesn't really reflect the structure of a sequence type. But as it is, it is an extension of the existing on and thus probably compatible.

4. That's interesting. It seems that the schema types also end up there. At least that's how I used it. I had a "as schema-element(...)" declaration and the content type of the ELEMENT_KIND was a USER_DEFINED_KIND.

5. I'll look at that, but first we need to make sure that points 2-4 are clarified.

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

lp:~zorba-coders/zorba/bug924987 updated
10646. By Markos Zaharioudakis

TypeManagerImpl::create_type() method

10647. By Markos Zaharioudakis

fix in TypeIdentifier::emitItemType() method + cosmetic

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'include/zorba/identtypes.h'
--- include/zorba/identtypes.h 2011-09-21 14:49:55 +0000
+++ include/zorba/identtypes.h 2012-03-06 03:27:34 +0000
@@ -17,6 +17,7 @@
17#define ZORBA_TYPEIDENT_TYPES_API_H17#define ZORBA_TYPEIDENT_TYPES_API_H
1818
19#include <zorba/config.h>19#include <zorba/config.h>
20#include <iostream>
2021
21namespace zorba {22namespace zorba {
22class ZORBA_DLL_PUBLIC IdentTypes {23class ZORBA_DLL_PUBLIC IdentTypes {
@@ -32,17 +33,30 @@
32 ANY_NODE_TYPE, // node()33 ANY_NODE_TYPE, // node()
33 ITEM_TYPE, // item()34 ITEM_TYPE, // item()
34 EMPTY_TYPE, // empty-sequence()35 EMPTY_TYPE, // empty-sequence()
35 INVALID_TYPE,36 SCHEMA_ELEMENT_TYPE,
37 SCHEMA_ATTRIBUTE_TYPE,
38 INVALID_TYPE
36 } kind_t;39 } kind_t;
40
41 static char const *const kind_string_of[];
3742
38 typedef enum {43 typedef enum {
39 QUANT_ONE,44 QUANT_ONE,
40 QUANT_QUESTION,45 QUANT_QUESTION,
41 QUANT_PLUS,46 QUANT_PLUS,
42 QUANT_STAR,47 QUANT_STAR
43 } quantifier_t;48 } quantifier_t;
49
50 static char const *const quantifier_string_of[];
44};51};
45}52}
4653
54namespace std {
55
56ZORBA_DLL_PUBLIC ostream& operator<<(ostream& o, const zorba::IdentTypes::kind_t ik);
57ZORBA_DLL_PUBLIC ostream& operator<<(ostream& o, const zorba::IdentTypes::quantifier_t iq);
58
59}
60
47#endif61#endif
48/* vim:set et sw=2 ts=2: */62/* vim:set et sw=2 ts=2: */
4963
=== modified file 'include/zorba/typeident.h'
--- include/zorba/typeident.h 2011-06-14 17:26:33 +0000
+++ include/zorba/typeident.h 2012-03-06 03:27:34 +0000
@@ -20,6 +20,7 @@
20#include <zorba/api_shared_types.h>20#include <zorba/api_shared_types.h>
21#include <zorba/identtypes.h>21#include <zorba/identtypes.h>
22#include <zorba/zorba_string.h>22#include <zorba/zorba_string.h>
23#include <iostream>
2324
24namespace zorba {25namespace zorba {
2526
@@ -61,7 +62,7 @@
61 createAttributeType(62 createAttributeType(
62 const String& uri,63 const String& uri,
63 bool uriWildcard,64 bool uriWildcard,
64 const String& localNameName,65 const String& localName,
65 bool localNameWildcard,66 bool localNameWildcard,
66 TypeIdentifier_t contentType,67 TypeIdentifier_t contentType,
67 IdentTypes::quantifier_t quantifier = IdentTypes::QUANT_ONE68 IdentTypes::quantifier_t quantifier = IdentTypes::QUANT_ONE
@@ -108,6 +109,22 @@
108 TypeIdentifier_t109 TypeIdentifier_t
109 createEmptyType();110 createEmptyType();
110111
112 static
113 TypeIdentifier_t
114 createSchemaElementType(
115 const String& uri,
116 const String& localName,
117 IdentTypes::quantifier_t quantifier = IdentTypes::QUANT_ONE
118 );
119
120 static
121 TypeIdentifier_t
122 createSchemaAttributeType(
123 const String& uri,
124 const String& localName,
125 IdentTypes::quantifier_t quantifier = IdentTypes::QUANT_ONE
126 );
127
111 IdentTypes::kind_t128 IdentTypes::kind_t
112 getKind() const;129 getKind() const;
113130
@@ -129,9 +146,18 @@
129 TypeIdentifier_t146 TypeIdentifier_t
130 getContentType() const;147 getContentType() const;
131148
149 std::ostream&
150 emit(std::ostream&) const;
151
132 private:152 private:
133 TypeIdentifier();153 TypeIdentifier();
134154
155 std::ostream&
156 emitItemType(std::ostream&) const;
157
158 std::ostream&
159 emitName(std::ostream&) const;
160
135 IdentTypes::kind_t m_kind;161 IdentTypes::kind_t m_kind;
136 IdentTypes::quantifier_t m_quantifier;162 IdentTypes::quantifier_t m_quantifier;
137 String m_uri;163 String m_uri;
@@ -148,5 +174,12 @@
148174
149} /* namespace zorba */175} /* namespace zorba */
150176
177namespace std {
178
179ZORBA_DLL_PUBLIC ostream& operator<<(ostream& o, const zorba::TypeIdentifier& ti);
180ZORBA_DLL_PUBLIC ostream& operator<<(ostream& o, const zorba::TypeIdentifier_t ti);
181
182}
183
151#endif /* ZORBA_TYPES_TYPEIDENT_H */184#endif /* ZORBA_TYPES_TYPEIDENT_H */
152/* vim:set et sw=2 ts=2: */185/* vim:set et sw=2 ts=2: */
153186
=== modified file 'src/api/CMakeLists.txt'
--- src/api/CMakeLists.txt 2012-02-16 14:11:02 +0000
+++ src/api/CMakeLists.txt 2012-03-06 03:27:34 +0000
@@ -27,6 +27,7 @@
27 zorba_string.cpp27 zorba_string.cpp
28 itemfactoryimpl.cpp28 itemfactoryimpl.cpp
29 item.cpp29 item.cpp
30 identtypesimpl.cpp
30 typeidentimpl.cpp31 typeidentimpl.cpp
31 unmarshaller.cpp32 unmarshaller.cpp
32 xmldatamanagerimpl.cpp33 xmldatamanagerimpl.cpp
3334
=== added file 'src/api/identtypesimpl.cpp'
--- src/api/identtypesimpl.cpp 1970-01-01 00:00:00 +0000
+++ src/api/identtypesimpl.cpp 2012-03-06 03:27:34 +0000
@@ -0,0 +1,60 @@
1/*
2 * Copyright 2006-2008 The FLWOR Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <zorba/identtypes.h>
18
19namespace zorba {
20
21char const *const IdentTypes::kind_string_of[] = {
22 "NAMED",
23 "element",
24 "attribute",
25 "document-node",
26 "processing-instruction",
27 "text",
28 "comment",
29 "node",
30 "item",
31 "empty-sequence",
32 "schema-element",
33 "schema-attribute",
34 "INVALID",
35 0
36};
37
38char const *const IdentTypes::quantifier_string_of[] = {
39 "",
40 "?",
41 "+",
42 "*",
43 0
44};
45
46}
47
48namespace std {
49
50ostream& operator<<(ostream& o, const zorba::IdentTypes::kind_t ik) {
51 return o << zorba::IdentTypes::kind_string_of[ik];
52}
53
54ostream& operator<<(ostream& o, const zorba::IdentTypes::quantifier_t iq) {
55 return o << zorba::IdentTypes::quantifier_string_of[iq];
56}
57
58}
59
60/* vim:set et sw=2 ts=2: */
061
=== modified file 'src/api/typeidentimpl.cpp'
--- src/api/typeidentimpl.cpp 2011-09-15 11:46:01 +0000
+++ src/api/typeidentimpl.cpp 2012-03-06 03:27:34 +0000
@@ -20,6 +20,8 @@
2020
21#include <zorba/typeident.h>21#include <zorba/typeident.h>
2222
23#include "diagnostics/assert.h"
24
23namespace zorba {25namespace zorba {
2426
25TypeIdentifier::TypeIdentifier()27TypeIdentifier::TypeIdentifier()
@@ -101,6 +103,9 @@
101 TypeIdentifier_t contentType,103 TypeIdentifier_t contentType,
102 IdentTypes::quantifier_t quantifier)104 IdentTypes::quantifier_t quantifier)
103{105{
106 // not sure why those were 2 different flags, we maintain 2 flags for
107 // compatibility, but they always need to be the same
108 ZORBA_ASSERT(uriWildcard == localNameWildcard);
104 TypeIdentifier_t ti(new TypeIdentifier());109 TypeIdentifier_t ti(new TypeIdentifier());
105 ti->m_kind = IdentTypes::ELEMENT_TYPE;110 ti->m_kind = IdentTypes::ELEMENT_TYPE;
106 ti->m_quantifier = quantifier;111 ti->m_quantifier = quantifier;
@@ -122,6 +127,9 @@
122 TypeIdentifier_t contentType,127 TypeIdentifier_t contentType,
123 IdentTypes::quantifier_t quantifier)128 IdentTypes::quantifier_t quantifier)
124{129{
130 // not sure why those were 2 different flags, we maintain 2 flags for
131 // compatibility, but they always need to be the same
132 ZORBA_ASSERT(uriWildcard == localNameWildcard);
125 TypeIdentifier_t ti(new TypeIdentifier());133 TypeIdentifier_t ti(new TypeIdentifier());
126 ti->m_kind = IdentTypes::ATTRIBUTE_TYPE;134 ti->m_kind = IdentTypes::ATTRIBUTE_TYPE;
127 ti->m_quantifier = quantifier;135 ti->m_quantifier = quantifier;
@@ -202,11 +210,114 @@
202{210{
203 TypeIdentifier_t ti(new TypeIdentifier());211 TypeIdentifier_t ti(new TypeIdentifier());
204 ti->m_kind = IdentTypes::EMPTY_TYPE;212 ti->m_kind = IdentTypes::EMPTY_TYPE;
205213 ti->m_quantifier = IdentTypes::QUANT_ONE;
206 return ti;214
207}215 return ti;
208216}
209}217
218TypeIdentifier_t TypeIdentifier::createSchemaElementType(
219 const String& uri,
220 const String& localName,
221 IdentTypes::quantifier_t quantifier)
222{
223 TypeIdentifier_t ti(new TypeIdentifier());
224 ti->m_kind = IdentTypes::SCHEMA_ELEMENT_TYPE;
225 ti->m_quantifier = quantifier;
226 ti->m_uri = uri;
227 ti->m_uriWildcard = false;
228 ti->m_localName = localName;
229 ti->m_localNameWildcard = false;
230
231 return ti;
232}
233
234
235TypeIdentifier_t TypeIdentifier::createSchemaAttributeType(
236 const String& uri,
237 const String& localName,
238 IdentTypes::quantifier_t quantifier)
239{
240 TypeIdentifier_t ti(new TypeIdentifier());
241 ti->m_kind = IdentTypes::SCHEMA_ATTRIBUTE_TYPE;
242 ti->m_quantifier = quantifier;
243 ti->m_uri = uri;
244 ti->m_uriWildcard = false;
245 ti->m_localName = localName;
246 ti->m_localNameWildcard = false;
247
248 return ti;
249}
250
251
252std::ostream& TypeIdentifier::emit(std::ostream& os) const {
253 emitItemType(os);
254 return os << m_quantifier;
255}
256
257
258std::ostream& TypeIdentifier::emitItemType(std::ostream& os) const {
259 if (m_kind == IdentTypes::NAMED_TYPE) {
260 return emitName(os);
261 }
262 os << m_kind;
263 switch (m_kind) {
264 case IdentTypes::DOCUMENT_TYPE:
265 return os << "(" << m_contentType << ")";
266
267 case IdentTypes::ELEMENT_TYPE:
268 case IdentTypes::ATTRIBUTE_TYPE:
269 os << "(";
270 if (m_uriWildcard) {
271 os << "*";
272 } else {
273 emitName(os);
274 }
275 if (! m_contentType.isNull()) {
276 os << "," << m_contentType;
277 }
278 return os << ")";
279
280 case IdentTypes::SCHEMA_ELEMENT_TYPE:
281 case IdentTypes::SCHEMA_ATTRIBUTE_TYPE:
282 os << "(";
283 emitName(os);
284 return os << ")";
285
286 case IdentTypes::ANY_NODE_TYPE:
287 case IdentTypes::COMMENT_TYPE:
288 case IdentTypes::EMPTY_TYPE:
289 case IdentTypes::ITEM_TYPE:
290 case IdentTypes::PI_TYPE:
291 case IdentTypes::TEXT_TYPE:
292 return os << "()";
293
294 case IdentTypes::INVALID_TYPE:
295 return os;
296
297 case IdentTypes::NAMED_TYPE:
298 default:
299 ZORBA_ASSERT(false);
300 }
301}
302
303std::ostream& TypeIdentifier::emitName(std::ostream& os) const {
304 return os << "{" << m_uri << "}" << m_localName;
305}
306
307}
308
309namespace std {
310
311ostream& operator<<(ostream& o, const zorba::TypeIdentifier& ti) {
312 return ti.emit(o);
313}
314
315ostream& operator<<(ostream& o, const zorba::TypeIdentifier_t ti) {
316 return ti->emit(o);
317}
318
319}
320
210321
211#endif322#endif
212/* vim:set et sw=2 ts=2: */323/* vim:set et sw=2 ts=2: */
213324
=== modified file 'src/types/typemanagerimpl.cpp'
--- src/types/typemanagerimpl.cpp 2012-01-26 19:56:14 +0000
+++ src/types/typemanagerimpl.cpp 2012-03-06 03:27:34 +0000
@@ -1045,6 +1045,38 @@
1045 case IdentTypes::EMPTY_TYPE:1045 case IdentTypes::EMPTY_TYPE:
1046 return create_empty_type();1046 return create_empty_type();
10471047
1048 case IdentTypes::SCHEMA_ELEMENT_TYPE:
1049 {
1050 store::Item_t ename;
1051 GENV_ITEMFACTORY->createQName(ename,
1052 ident.getUri().c_str(),
1053 NULL,
1054 ident.getLocalName().c_str());
1055
1056 return create_node_type(store::StoreConsts::elementNode,
1057 ename.getp(),
1058 0,
1059 q,
1060 false,
1061 true);
1062 }
1063
1064 case IdentTypes::SCHEMA_ATTRIBUTE_TYPE:
1065 {
1066 store::Item_t aname;
1067 GENV_ITEMFACTORY->createQName(aname,
1068 ident.getUri().c_str(),
1069 NULL,
1070 ident.getLocalName().c_str());
1071
1072 return create_node_type(store::StoreConsts::attributeNode,
1073 aname.getp(),
1074 0,
1075 q,
1076 false,
1077 true);
1078 }
1079
1048 default:1080 default:
1049 break;1081 break;
1050 }1082 }
10511083
=== modified file 'src/types/typeops.cpp'
--- src/types/typeops.cpp 2012-01-30 15:23:21 +0000
+++ src/types/typeops.cpp 2012-03-06 03:27:34 +0000
@@ -1179,7 +1179,8 @@
1179********************************************************************************/1179********************************************************************************/
1180type_ident_ref_t TypeOps::get_type_identifier(1180type_ident_ref_t TypeOps::get_type_identifier(
1181 const TypeManager* tm,1181 const TypeManager* tm,
1182 const XQType& type)1182 const XQType& type,
1183 bool nested)
1183{1184{
1184 RootTypeManager& rtm = GENV_TYPESYSTEM;1185 RootTypeManager& rtm = GENV_TYPESYSTEM;
11851186
@@ -1201,7 +1202,7 @@
1201 const NodeXQType& nt = static_cast<const NodeXQType&>(type);1202 const NodeXQType& nt = static_cast<const NodeXQType&>(type);
12021203
1203 type_ident_ref_t content_type = (nt.get_content_type() != NULL ?1204 type_ident_ref_t content_type = (nt.get_content_type() != NULL ?
1204 get_type_identifier(tm, *nt.get_content_type()) :1205 get_type_identifier(tm, *nt.get_content_type(), true) :
1205 type_ident_ref_t());1206 type_ident_ref_t());
12061207
1207 const store::Item* nodeName = nt.get_node_name();1208 const store::Item* nodeName = nt.get_node_name();
@@ -1224,29 +1225,53 @@
1224 return TypeIdentifier::createDocumentType(content_type, q);1225 return TypeIdentifier::createDocumentType(content_type, q);
12251226
1226 case store::StoreConsts::elementNode:1227 case store::StoreConsts::elementNode:
1227 {1228 if (nt.is_schema_test())
1228 String uri( Unmarshaller::newString( nodeName->getNamespace() ) );1229 {
1229 String local( Unmarshaller::newString( nodeName->getLocalName() ) );1230 ZORBA_ASSERT(nodeName);
12301231 String uri( Unmarshaller::newString( nodeName->getNamespace() ) );
1231 return TypeIdentifier::createElementType(uri,1232 String local( Unmarshaller::newString( nodeName->getLocalName() ) );
1232 nodeName == NULL,1233 return TypeIdentifier::createSchemaElementType(uri, local, q);
1233 local,1234 }
1234 nodeName == NULL,1235 else
1235 content_type,1236 {
1236 q);1237 String uri;
1237 } 1238 String local;
1238 case store::StoreConsts::attributeNode:1239 if (nodeName)
1239 {1240 {
1240 String uri( Unmarshaller::newString( nodeName->getNamespace() ) );1241 uri = nodeName->getNamespace().c_str();
1241 String local( Unmarshaller::newString( nodeName->getLocalName() ) );1242 local = nodeName->getLocalName().c_str();
12421243 }
1243 return TypeIdentifier::createAttributeType(uri,1244 return TypeIdentifier::createElementType(uri,
1244 nodeName == NULL,1245 nodeName == NULL,
1245 local,1246 local,
1246 nodeName == NULL,1247 nodeName == NULL,
1247 content_type,1248 content_type,
1248 q);1249 q);
1249 }1250 }
1251 case store::StoreConsts::attributeNode:
1252 if (nt.is_schema_test())
1253 {
1254 ZORBA_ASSERT(nodeName);
1255 String uri( Unmarshaller::newString( nodeName->getNamespace() ) );
1256 String local( Unmarshaller::newString( nodeName->getLocalName() ) );
1257 return TypeIdentifier::createSchemaAttributeType(uri, local, q);
1258 }
1259 else
1260 {
1261 String uri;
1262 String local;
1263 if (nodeName)
1264 {
1265 uri = nodeName->getNamespace().c_str();
1266 local = nodeName->getLocalName().c_str();
1267 }
1268 return TypeIdentifier::createAttributeType(uri,
1269 nodeName == NULL,
1270 local,
1271 nodeName == NULL,
1272 content_type,
1273 q);
1274 }
1250 default:1275 default:
1251 // cannot happen1276 // cannot happen
1252 ZORBA_ASSERT(false);1277 ZORBA_ASSERT(false);
@@ -1281,7 +1306,15 @@
1281 return TypeIdentifier::createEmptyType();1306 return TypeIdentifier::createEmptyType();
12821307
1283 case XQType::USER_DEFINED_KIND:1308 case XQType::USER_DEFINED_KIND:
1284 //TODO for Vinayak return type identifier1309 {
1310 ZORBA_ASSERT(nested || is_atomic(tm, type));
1311 store::Item* lQname = type.get_qname().getp();
1312 return TypeIdentifier::createNamedType(
1313 Unmarshaller::newString( lQname->getNamespace() ),
1314 Unmarshaller::newString( lQname->getLocalName() ),
1315 q
1316 );
1317 }
1285 default:1318 default:
1286 break;1319 break;
1287 }1320 }
12881321
=== modified file 'src/types/typeops.h'
--- src/types/typeops.h 2012-01-11 10:30:49 +0000
+++ src/types/typeops.h 2012-03-06 03:27:34 +0000
@@ -256,7 +256,8 @@
256 */256 */
257 static type_ident_ref_t get_type_identifier(257 static type_ident_ref_t get_type_identifier(
258 const TypeManager* tm,258 const TypeManager* tm,
259 const XQType& type);259 const XQType& type,
260 bool nested = false);
260261
261 /*262 /*
262 * Writes a textual representation of the given type to the output stream.263 * Writes a textual representation of the given type to the output stream.
263264
=== modified file 'test/unit/CMakeLists.txt'
--- test/unit/CMakeLists.txt 2012-02-27 14:46:27 +0000
+++ test/unit/CMakeLists.txt 2012-03-06 03:27:34 +0000
@@ -71,6 +71,10 @@
71CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/module2.xq ${CMAKE_CURRENT_BINARY_DIR}/module2.xq)71CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/module2.xq ${CMAKE_CURRENT_BINARY_DIR}/module2.xq)
72CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/module3.xq ${CMAKE_CURRENT_BINARY_DIR}/module3.xq)72CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/module3.xq ${CMAKE_CURRENT_BINARY_DIR}/module3.xq)
73CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/module4.xq ${CMAKE_CURRENT_BINARY_DIR}/module4.xq)73CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/module4.xq ${CMAKE_CURRENT_BINARY_DIR}/module4.xq)
74CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/module5.xq ${CMAKE_CURRENT_BINARY_DIR}/module5.xq)
75CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/module6.xq ${CMAKE_CURRENT_BINARY_DIR}/module6.xq)
76
77CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/schema1.xsd ${CMAKE_CURRENT_BINARY_DIR}/schema1.xsd)
7478
75SET(UNIT_TESTS_SRCS79SET(UNIT_TESTS_SRCS
76 path_resolver.cpp80 path_resolver.cpp
7781
=== added file 'test/unit/module5.xq'
--- test/unit/module5.xq 1970-01-01 00:00:00 +0000
+++ test/unit/module5.xq 2012-03-06 03:27:34 +0000
@@ -0,0 +1,20 @@
1(:
2 : Copyright 2006-2009 The FLWOR Foundation.
3 :
4 : Licensed under the Apache License, Version 2.0 (the "License");
5 : you may not use this file except in compliance with the License.
6 : You may obtain a copy of the License at
7 :
8 : http://www.apache.org/licenses/LICENSE-2.0
9 :
10 : Unless required by applicable law or agreed to in writing, software
11 : distributed under the License is distributed on an "AS IS" BASIS,
12 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 : See the License for the specific language governing permissions and
14 : limitations under the License.
15:)
16
17import module namespace mod6 = "http://www.mod6.com/" at "file:///${CMAKE_CURRENT_BINARY_DIR}/module6.xq";
18
191+1
20
021
=== added file 'test/unit/module6.xq'
--- test/unit/module6.xq 1970-01-01 00:00:00 +0000
+++ test/unit/module6.xq 2012-03-06 03:27:34 +0000
@@ -0,0 +1,38 @@
1(:
2 : Copyright 2006-2009 The FLWOR Foundation.
3 :
4 : Licensed under the Apache License, Version 2.0 (the "License");
5 : you may not use this file except in compliance with the License.
6 : You may obtain a copy of the License at
7 :
8 : http://www.apache.org/licenses/LICENSE-2.0
9 :
10 : Unless required by applicable law or agreed to in writing, software
11 : distributed under the License is distributed on an "AS IS" BASIS,
12 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 : See the License for the specific language governing permissions and
14 : limitations under the License.
15:)
16
17module namespace mod6 = "http://www.mod6.com/";
18
19declare namespace ann = "http://www.zorba-xquery.com/annotations";
20
21import schema namespace s = "http://www.zorba-xquery.com/schemas/simple" at "file:///${CMAKE_CURRENT_BINARY_DIR}/schema1.xsd";
22
23declare collection mod6:coll01 as document-node(element(s:product))*;
24declare collection mod6:coll02 as document-node(element(*, s:ProductType))*;
25declare collection mod6:coll03 as document-node(schema-element(s:product))*;
26
27declare collection mod6:coll04 as element(s:product)*;
28declare collection mod6:coll05 as element(*, s:ProductType)*;
29declare collection mod6:coll06 as schema-element(s:product)*;
30
31declare collection mod6:coll07 as attribute(s:zip-code)*;
32declare collection mod6:coll08 as attribute(*, s:ZipType)*;
33declare collection mod6:coll09 as schema-attribute(s:zip-code)*;
34
35declare collection mod6:coll10 as comment();
36declare collection mod6:coll11 as processing-instruction()?;
37declare collection mod6:coll12 as text()+;
38declare collection mod6:coll13 as node()*;
039
=== added file 'test/unit/schema1.xsd'
--- test/unit/schema1.xsd 1970-01-01 00:00:00 +0000
+++ test/unit/schema1.xsd 2012-03-06 03:27:34 +0000
@@ -0,0 +1,21 @@
1<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
2 targetNamespace="http://www.zorba-xquery.com/schemas/simple"
3 xmlns="http://www.zorba-xquery.com/schemas/simple"
4 elementFormDefault="qualified">
5
6 <xs:element name="product" type="ProductType"/>
7
8 <xs:complexType name="ProductType">
9 <xs:attribute name="data" type="xs:base64Binary"/>
10 <xs:attribute name="string" type="xs:string"/>
11 </xs:complexType>
12
13 <xs:attribute name="zip-code" type="ZipType"/>
14
15 <xs:simpleType name="ZipType">
16 <xs:restriction base="xs:string">
17 <xs:pattern value="[0-9][0-9][0-9][0-9][0-9]"/>
18 </xs:restriction>
19 </xs:simpleType>
20
21</xs:schema>
0\ No newline at end of file22\ No newline at end of file
123
=== modified file 'test/unit/staticcollectionmanager.cpp'
--- test/unit/staticcollectionmanager.cpp 2012-01-11 17:30:25 +0000
+++ test/unit/staticcollectionmanager.cpp 2012-03-06 03:27:34 +0000
@@ -259,6 +259,165 @@
259 return i == 1;259 return i == 1;
260}260}
261261
262bool
263check_types(StaticCollectionManager* aColMgr,
264 ItemFactory* aFac,
265 const char* const aCollName,
266 int aDepth,
267 IdentTypes::kind_t someKinds[],
268 IdentTypes::quantifier_t someQuantifiers[])
269{
270 Item lCollName = aFac->createQName("http://www.mod6.com/", aCollName);
271 if (! aColMgr->isDeclaredCollection(lCollName)) {
272 std::cout << "no collection "
273 << lCollName.getStringValue().c_str()
274 << std::endl;
275 return false;
276 }
277 aColMgr->createCollection(lCollName);
278 Collection_t lCollection = aColMgr->getCollection(lCollName);
279 zorba::TypeIdentifier_t lType = lCollection->getType();
280 std::cout << lType << std::endl;
281
282 for (int i = 0; i < aDepth; ++i) {
283 if (lType->getKind() != someKinds[i]) {
284 std::cout << lType << std::endl;
285 return false;
286 }
287 if (lType->getQuantifier() != someQuantifiers[i]) {
288 std::cout << lType << std::endl;
289 return false;
290 }
291 lType = lType->getContentType();
292 }
293 assert(lType.isNull());
294
295 aColMgr->deleteCollection(lCollName);
296 return true;
297}
298
299bool
300staticcollectionamanger5(zorba::Zorba* z)
301{
302 std::ifstream lIn("module5.xq");
303 zorba::XQuery_t lQuery = z->createQuery();
304
305 try {
306 Zorba_CompilerHints lHints;
307 lQuery->compile(lIn, lHints);
308 } catch (zorba::XQueryException &e) {
309 std::cout << e << std::endl;
310 return false;
311 } catch (...) {
312 std::cout << "compilation failed" << std::endl;
313 return false;
314 }
315
316 StaticCollectionManager* lColMgr = lQuery->getStaticCollectionManager();
317 ItemFactory* lFac = z->getItemFactory();
318
319 IdentTypes::kind_t lC01Kinds[] = { IdentTypes::DOCUMENT_TYPE,
320 IdentTypes::ELEMENT_TYPE,
321 IdentTypes::NAMED_TYPE };
322 IdentTypes::quantifier_t lC01Quants[] = { IdentTypes::QUANT_STAR,
323 IdentTypes::QUANT_ONE,
324 // this '*' is probably a bug
325 IdentTypes::QUANT_STAR };
326 if (!check_types(lColMgr, lFac, "coll01", 3, lC01Kinds, lC01Quants)) {
327 return false;
328 }
329
330 IdentTypes::kind_t lC02Kinds[] = { IdentTypes::DOCUMENT_TYPE,
331 IdentTypes::ELEMENT_TYPE,
332 IdentTypes::NAMED_TYPE };
333 IdentTypes::quantifier_t lC02Quants[] = { IdentTypes::QUANT_STAR,
334 IdentTypes::QUANT_ONE,
335 IdentTypes::QUANT_ONE };
336 if (!check_types(lColMgr, lFac, "coll02", 3, lC02Kinds, lC02Quants)) {
337 return false;
338 }
339
340 IdentTypes::kind_t lC03Kinds[] = { IdentTypes::DOCUMENT_TYPE,
341 IdentTypes::SCHEMA_ELEMENT_TYPE };
342 IdentTypes::quantifier_t lC03Quants[] = { IdentTypes::QUANT_STAR,
343 IdentTypes::QUANT_ONE };
344 if (!check_types(lColMgr, lFac, "coll03", 2, lC03Kinds, lC03Quants)) {
345 return false;
346 }
347
348 IdentTypes::kind_t lC04Kinds[] = { IdentTypes::ELEMENT_TYPE,
349 IdentTypes::NAMED_TYPE };
350 IdentTypes::quantifier_t lC04Quants[] = { IdentTypes::QUANT_STAR,
351 // this '*' is probably a bug
352 IdentTypes::QUANT_STAR };
353 if (!check_types(lColMgr, lFac, "coll04", 2, lC04Kinds, lC04Quants)) {
354 return false;
355 }
356
357 IdentTypes::kind_t lC05Kinds[] = { IdentTypes::ELEMENT_TYPE,
358 IdentTypes::NAMED_TYPE };
359 IdentTypes::quantifier_t lC05Quants[] = { IdentTypes::QUANT_STAR,
360 IdentTypes::QUANT_ONE };
361 if (!check_types(lColMgr, lFac, "coll05", 2, lC05Kinds, lC05Quants)) {
362 return false;
363 }
364
365 IdentTypes::kind_t lC06Kinds[] = { IdentTypes::SCHEMA_ELEMENT_TYPE };
366 IdentTypes::quantifier_t lC06Quants[] = { IdentTypes::QUANT_STAR };
367 if (!check_types(lColMgr, lFac, "coll06", 1, lC06Kinds, lC06Quants)) {
368 return false;
369 }
370
371 IdentTypes::kind_t lC07Kinds[] = { IdentTypes::ATTRIBUTE_TYPE,
372 IdentTypes::NAMED_TYPE };
373 IdentTypes::quantifier_t lC07Quants[] = { IdentTypes::QUANT_STAR,
374 // this '*' is probably a bug
375 IdentTypes::QUANT_STAR };
376 if (!check_types(lColMgr, lFac, "coll07", 2, lC07Kinds, lC07Quants)) {
377 return false;
378 }
379
380 IdentTypes::kind_t lC08Kinds[] = { IdentTypes::ATTRIBUTE_TYPE,
381 IdentTypes::NAMED_TYPE };
382 IdentTypes::quantifier_t lC08Quants[] = { IdentTypes::QUANT_STAR,
383 IdentTypes::QUANT_ONE };
384 if (!check_types(lColMgr, lFac, "coll08", 2, lC08Kinds, lC08Quants)) {
385 return false;
386 }
387
388 IdentTypes::kind_t lC09Kinds[] = { IdentTypes::SCHEMA_ATTRIBUTE_TYPE };
389 IdentTypes::quantifier_t lC09Quants[] = { IdentTypes::QUANT_STAR };
390 if (!check_types(lColMgr, lFac, "coll09", 1, lC09Kinds, lC09Quants)) {
391 return false;
392 }
393
394 IdentTypes::kind_t lC10Kinds[] = { IdentTypes::COMMENT_TYPE };
395 IdentTypes::quantifier_t lC10Quants[] = { IdentTypes::QUANT_ONE };
396 if (!check_types(lColMgr, lFac, "coll10", 1, lC10Kinds, lC10Quants)) {
397 return false;
398 }
399
400 IdentTypes::kind_t lC11Kinds[] = { IdentTypes::PI_TYPE };
401 IdentTypes::quantifier_t lC11Quants[] = { IdentTypes::QUANT_QUESTION };
402 if (!check_types(lColMgr, lFac, "coll11", 1, lC11Kinds, lC11Quants)) {
403 return false;
404 }
405
406 IdentTypes::kind_t lC12Kinds[] = { IdentTypes::TEXT_TYPE };
407 IdentTypes::quantifier_t lC12Quants[] = { IdentTypes::QUANT_PLUS };
408 if (!check_types(lColMgr, lFac, "coll12", 1, lC12Kinds, lC12Quants)) {
409 return false;
410 }
411
412 IdentTypes::kind_t lC13Kinds[] = { IdentTypes::ANY_NODE_TYPE };
413 IdentTypes::quantifier_t lC13Quants[] = { IdentTypes::QUANT_STAR };
414 if (!check_types(lColMgr, lFac, "coll13", 1, lC13Kinds, lC13Quants)) {
415 return false;
416 }
417
418 return true;
419}
420
262int421int
263staticcollectionmanager(int argc, char* argv[])422staticcollectionmanager(int argc, char* argv[])
264{423{
@@ -287,6 +446,11 @@
287 return 4;446 return 4;
288 std::cout << std::endl;447 std::cout << std::endl;
289448
449 std::cout << "executing example 5" << std::endl;
450 if (!staticcollectionamanger5(z))
451 return 5;
452 std::cout << std::endl;
453
290 return 0;454 return 0;
291}455}
292456

Subscribers

People subscribed via source and target branches