zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #02949
[Merge] lp:~zorba-coders/zorba/markos-scratch into lp:zorba
Markos Zaharioudakis has proposed merging lp:~zorba-coders/zorba/markos-scratch into lp:zorba.
Requested reviews:
Markos Zaharioudakis (markos-za)
For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/86551
Fix for bug #905050 (setting and getting the context item type)
--
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/86551
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'ChangeLog'
--- ChangeLog 2011-12-20 21:45:23 +0000
+++ ChangeLog 2011-12-21 12:13:40 +0000
@@ -7,8 +7,13 @@
* Added index management function to the C++ api's StaticCollectionManager.
* Fixed bug #905041 (allow for the default element and function namespaces to be
set multiple times via the c++ api).
+<<<<<<< TREE
* Added createDayTimeDuration, createYearMonthDuration, createDocumentNode, createCommentNode, createPiNode to api's ItemFactory.
+=======
+ * Fixed bug #905050 (setting and getting the context item type via the c++ api)
+
+>>>>>>> MERGE-SOURCE
version 2.1
New Features:
=== modified file 'src/api/staticcontextimpl.cpp'
--- src/api/staticcontextimpl.cpp 2011-12-20 11:50:23 +0000
+++ src/api/staticcontextimpl.cpp 2011-12-21 12:13:40 +0000
@@ -848,7 +848,8 @@
StaticContextImpl::setContextItemStaticType(TypeIdentifier_t type)
{
xqtref_t xqType = NULL;
- if (type != NULL) {
+ if (type != NULL)
+ {
xqType = theCtx->get_typemanager()->create_type(*type);
}
theCtx->set_context_item_type(xqType);
=== modified file 'src/api/xqueryimpl.cpp'
--- src/api/xqueryimpl.cpp 2011-12-20 09:04:58 +0000
+++ src/api/xqueryimpl.cpp 2011-12-21 12:13:40 +0000
@@ -806,7 +806,7 @@
if(var == NULL)
throw XQUERY_EXCEPTION(zerr::ZAPI0011_ELEMENT_NOT_DECLARED,
- ERROR_PARAMS(BUILD_STRING('{', qname->getNamespace(), '}', qname->getLocalName()), ZED(Variable)));
+ ERROR_PARAMS(BUILD_STRING('{', qname->getNamespace(), '}', qname->getLocalName()), ZED(Variable)));
if (var->hasInitializer())
return true;
=== modified file 'src/compiler/translator/translator.cpp'
--- src/compiler/translator/translator.cpp 2011-12-20 18:30:39 +0000
+++ src/compiler/translator/translator.cpp 2011-12-21 12:13:40 +0000
@@ -442,6 +442,9 @@
theHaveSequentialExitExprs :
----------------------------
+ theHaveContextItemDecl :
+ ------------------------
+
theAssignedVars :
-------------------
@@ -576,6 +579,8 @@
bool theHaveSequentialExitExprs;
+ bool theHaveContextItemDecl;
+
std::vector<std::vector<var_expr*> > theAssignedVars;
int theTempVarCounter;
@@ -654,6 +659,7 @@
thePrologGraph(rootSctx),
theHaveUpdatingExitExprs(false),
theHaveSequentialExitExprs(false),
+ theHaveContextItemDecl(false),
theTempVarCounter(1),
theIsInIndexDomain(false),
hadBSpaceDecl(false),
@@ -696,10 +702,12 @@
}
}
-~TranslatorImpl() {
+
+~TranslatorImpl()
+{
#ifndef ZORBA_NO_FULL_TEXT
- while ( !theFTNodeStack.empty() )
- delete ztd::pop_stack( theFTNodeStack );
+ while (!theFTNodeStack.empty())
+ delete ztd::pop_stack(theFTNodeStack);
#endif
}
@@ -2223,8 +2231,7 @@
var_expr_t var = bind_var(loc,
DOT_VARNAME,
var_expr::prolog_var,
- GENV_TYPESYSTEM.ITEM_TYPE_ONE);
- //var->set_external(true);
+ theSctx->get_context_item_type());
var->set_unique_id(1);
//GlobalBinding b(var, NULL, true);
@@ -2241,6 +2248,17 @@
assert(theCCB->theIsEval || !program->is_updating());
+ // If an appliaction set a type for the context item via the c++ api, then
+ // create a full declaration for it in order to enforce that type.
+ if (!theHaveContextItemDecl &&
+ theSctx->get_context_item_type() != theRTM.ITEM_TYPE_ONE.getp())
+ {
+ var_expr* var = lookup_ctx_var(DOT_VARNAME, loc);
+ var->set_external(true);
+ GlobalBinding b(var, NULL, true);
+ declare_var(b, theModulesInfo->theInitExprs);
+ }
+
// the main module debug iterator has no location otherwise
// this would take precedence over a child debug iterator
// starting in the same line
@@ -3856,13 +3874,10 @@
TRACE_VISIT();
if (theSctx->xquery_version() <= StaticContextConsts::xquery_version_1_0)
- throw XQUERY_EXCEPTION(
- err::XPST0003,
- ERROR_PARAMS(
- ZED( XQueryVersionAtLeast10_2 ), theSctx->xquery_version()
- ),
- ERROR_LOC( loc )
- );
+ RAISE_ERROR(err::XPST0003, loc,
+ ERROR_PARAMS(ZED(XQueryVersionAtLeast10_2), theSctx->xquery_version()));
+
+ theHaveContextItemDecl = true;
return no_state;
}
@@ -3875,9 +3890,18 @@
if (v.get_expr() != NULL)
initExpr = pop_nodestack();
- xqtref_t type = GENV_TYPESYSTEM.ITEM_TYPE_ONE;
+ xqtref_t type;
+
if (v.get_type() != NULL)
+ {
type = pop_tstack();
+ theSctx->set_context_item_type(type);
+ }
+ else
+ {
+ type = theSctx->get_context_item_type();
+ assert(type != NULL);
+ }
var_expr_t var;
=== modified file 'src/context/root_static_context.cpp'
--- src/context/root_static_context.cpp 2011-12-20 18:30:39 +0000
+++ src/context/root_static_context.cpp 2011-12-21 12:13:40 +0000
@@ -35,14 +35,11 @@
{
-root_static_context::root_static_context() : static_context()
-{
- theTypemgr = new RootTypeManager();
-}
-
#ifdef WIN32
-static void append_to_path(std::vector<zstring>& aPath, zstring& zorba_root,
- zstring& relpath)
+static void append_to_path(
+ std::vector<zstring>& aPath,
+ zstring& zorba_root,
+ zstring& relpath)
{
ascii::replace_all(relpath, '/', '\\');
zstring full_path(zorba_root);
@@ -52,6 +49,16 @@
}
#endif
+
+
+root_static_context::root_static_context()
+ :
+ static_context()
+{
+ theTypeManager = &GENV_TYPESYSTEM;
+}
+
+
void root_static_context::init()
{
QueryLoc loc;
@@ -125,18 +132,29 @@
// compute the relative path to zorba_simplestore.dll (this dll)
WCHAR wdll_path[1024];
DWORD dll_path_size;
- dll_path_size = GetModuleFileNameW(NULL, wdll_path, sizeof(wdll_path)/sizeof(wdll_path[0]));
+ dll_path_size = GetModuleFileNameW(NULL,
+ wdll_path,
+ sizeof(wdll_path)/sizeof(wdll_path[0]));
if(dll_path_size)
{
wdll_path[dll_path_size] = 0;
char dll_path[1024];
- WideCharToMultiByte(CP_UTF8, 0, wdll_path, -1, dll_path, sizeof(dll_path), NULL, NULL);
+ WideCharToMultiByte(CP_UTF8,
+ 0,
+ wdll_path,
+ -1,
+ dll_path,
+ sizeof(dll_path),
+ NULL,
+ NULL);
+
char *last_slash = strrchr(dll_path, '\\');
if(last_slash)
{
last_slash[0] = 0;
last_slash = strrchr (dll_path, '\\');
- if (last_slash) {
+ if (last_slash)
+ {
last_slash[1] = 0;
zstring zorba_root_dir(dll_path);
=== modified file 'src/context/static_context.cpp'
--- src/context/static_context.cpp 2011-12-20 11:50:23 +0000
+++ src/context/static_context.cpp 2011-12-21 12:13:40 +0000
@@ -497,6 +497,7 @@
theNamespaceBindings(NULL),
theHaveDefaultElementNamespace(false),
theHaveDefaultFunctionNamespace(false),
+ theContextItemType(GENV_TYPESYSTEM.ITEM_TYPE_ONE),
theVariablesMap(NULL),
theImportedPrivateVariablesMap(NULL),
theFunctionMap(NULL),
@@ -544,6 +545,7 @@
theNamespaceBindings(NULL),
theHaveDefaultElementNamespace(false),
theHaveDefaultFunctionNamespace(false),
+ theContextItemType(GENV_TYPESYSTEM.ITEM_TYPE_ONE),
theVariablesMap(NULL),
theImportedPrivateVariablesMap(NULL),
theFunctionMap(NULL),
@@ -596,6 +598,7 @@
theNamespaceBindings(NULL),
theHaveDefaultElementNamespace(false),
theHaveDefaultFunctionNamespace(false),
+ theContextItemType(GENV_TYPESYSTEM.ITEM_TYPE_ONE),
theVariablesMap(NULL),
theImportedPrivateVariablesMap(NULL),
theFunctionMap(NULL),
@@ -893,7 +896,7 @@
ar & theOptionMap;
ar & theExternalModulesMap;
- SERIALIZE_TYPEMANAGER_RCHANDLE(TypeManager, theTypemgr);
+ SERIALIZE_TYPEMANAGER_RCHANDLE(TypeManager, theTypeManager);
ar & theNamespaceBindings;
ar & theDefaultElementNamespace;
@@ -901,7 +904,7 @@
ar & theDefaultFunctionNamespace;
ar & theHaveDefaultFunctionNamespace;
- ar & theCtxItemType;
+ ar & theContextItemType;
ar & theVariablesMap;
ar & theImportedPrivateVariablesMap;
@@ -1743,13 +1746,13 @@
********************************************************************************/
void static_context::set_typemanager(rchandle<TypeManager> typemgr)
{
- theTypemgr = typemgr;
+ theTypeManager = typemgr;
}
TypeManager* static_context::get_typemanager() const
{
- TypeManager* tm = theTypemgr.getp();
+ TypeManager* tm = theTypeManager.getp();
if (tm != NULL)
{
return tm;
@@ -1760,7 +1763,7 @@
TypeManager* static_context::get_local_typemanager() const
{
- return theTypemgr.getp();
+ return theTypeManager.getp();
}
@@ -2152,9 +2155,9 @@
/***************************************************************************//**
********************************************************************************/
-void static_context::set_context_item_type(xqtref_t& t)
+void static_context::set_context_item_type(const xqtref_t& t)
{
- theCtxItemType = t;
+ theContextItemType = t;
}
@@ -2166,8 +2169,8 @@
const static_context* sctx = this;
while (sctx != NULL)
{
- if (theCtxItemType != NULL)
- return theCtxItemType.getp();
+ if (theContextItemType != NULL)
+ return theContextItemType.getp();
sctx = sctx->theParent;
}
=== modified file 'src/context/static_context.h'
--- src/context/static_context.h 2011-12-20 11:50:23 +0000
+++ src/context/static_context.h 2011-12-21 12:13:40 +0000
@@ -273,9 +273,9 @@
theExternalModulesMap :
-----------------------
- theTypemgr :
- ------------
- If non NULL, then "this" is the root sctx of a module, and theTypemgr stores
+ theTypeMnager :
+ ---------------
+ If non NULL, then "this" is the root sctx of a module, and theTypeManager stores
the schemas that are imported by the associated module (in-scope element
declarations, in-scope attribute declarations and in-scope type declarations).
@@ -291,8 +291,8 @@
-----------------------------
The namespace URI to be used for function qnames whose prefix is empty.
- theCtxItemType :
- ----------------
+ theContextItemType :
+ --------------------
theVariablesMap :
-----------------
@@ -504,7 +504,7 @@
ExternalModuleMap * theExternalModulesMap;
- rchandle<TypeManager> theTypemgr;
+ rchandle<TypeManager> theTypeManager;
NamespaceBindings * theNamespaceBindings;
@@ -514,7 +514,7 @@
zstring theDefaultFunctionNamespace;
bool theHaveDefaultFunctionNamespace;
- xqtref_t theCtxItemType;
+ xqtref_t theContextItemType;
VariableMap * theVariablesMap;
@@ -791,7 +791,7 @@
bool returnPrivateVars = false,
bool externalVarsOnly = false) const;
- void set_context_item_type(xqtref_t& t);
+ void set_context_item_type(const xqtref_t& t);
const XQType* get_context_item_type() const;
=== modified file 'src/system/globalenv.cpp'
--- src/system/globalenv.cpp 2011-12-20 09:04:58 +0000
+++ src/system/globalenv.cpp 2011-12-21 12:13:40 +0000
@@ -60,7 +60,9 @@
GlobalEnvironment * GlobalEnvironment::m_globalEnv = 0;
+/*******************************************************************************
+********************************************************************************/
void GlobalEnvironment::init(store::Store* store)
{
// initialize Xerces-C lib
@@ -74,11 +76,14 @@
m_globalEnv->m_store = store;
- m_globalEnv->m_rootStaticContext = new root_static_context();
- m_globalEnv->m_rootStaticContext->init();
- RCHelper::addReference(m_globalEnv->m_rootStaticContext);
-
- BuiltinFunctionLibrary::create(m_globalEnv->m_rootStaticContext);
+ m_globalEnv->theRootTypeManager = new RootTypeManager;
+ RCHelper::addReference(m_globalEnv->theRootTypeManager);
+
+ m_globalEnv->theRootStaticContext = new root_static_context();
+ RCHelper::addReference(m_globalEnv->theRootStaticContext);
+ m_globalEnv->theRootStaticContext->init();
+
+ BuiltinFunctionLibrary::create(m_globalEnv->theRootStaticContext);
AnnotationInternal::createBuiltIn();
@@ -104,6 +109,9 @@
}
+/*******************************************************************************
+
+********************************************************************************/
// destroy all components that were initialized in init
// note: destruction must be done in reverse initialization order
void GlobalEnvironment::destroy()
@@ -125,8 +133,11 @@
delete m_globalEnv->xqueryx_convertor;
#endif
- RCHelper::removeReference(m_globalEnv->m_rootStaticContext);
- m_globalEnv->m_rootStaticContext = 0;
+ RCHelper::removeReference(m_globalEnv->theRootStaticContext);
+ m_globalEnv->theRootStaticContext = 0;
+
+ RCHelper::removeReference(m_globalEnv->theRootTypeManager);
+ m_globalEnv->theRootTypeManager = 0;
AnnotationInternal::destroyBuiltIn();
@@ -152,6 +163,10 @@
}
+
+/*******************************************************************************
+
+********************************************************************************/
void GlobalEnvironment::destroyStatics()
{
// release resources aquired by the mapm library
@@ -161,20 +176,31 @@
}
+/*******************************************************************************
+
+********************************************************************************/
GlobalEnvironment::GlobalEnvironment()
:
m_store(0),
- m_rootStaticContext(0),
+ theRootTypeManager(NULL),
+ theRootStaticContext(0),
m_compilerSubSys(0)
{
}
+
+/*******************************************************************************
+
+********************************************************************************/
GlobalEnvironment::~GlobalEnvironment()
{
}
+/*******************************************************************************
+
+********************************************************************************/
void GlobalEnvironment::init_icu()
{
// initialize the icu library
@@ -239,21 +265,23 @@
}
-static_context& GlobalEnvironment::getRootStaticContext()
-{
- return *m_rootStaticContext;
-}
-
-
-RootTypeManager& GlobalEnvironment::getRootTypeManager()
-{
- return *(static_cast<RootTypeManager *>(m_rootStaticContext->get_typemanager()));
-}
-
-bool GlobalEnvironment::isRootStaticContextInitialized()
-{
- return m_rootStaticContext != NULL;
-}
+RootTypeManager& GlobalEnvironment::getRootTypeManager() const
+{
+ return *theRootTypeManager;
+}
+
+
+static_context& GlobalEnvironment::getRootStaticContext() const
+{
+ return *theRootStaticContext;
+}
+
+
+bool GlobalEnvironment::isRootStaticContextInitialized() const
+{
+ return theRootStaticContext != NULL;
+}
+
store::Store& GlobalEnvironment::getStore()
{
=== modified file 'src/system/globalenv.h'
--- src/system/globalenv.h 2011-12-20 09:04:58 +0000
+++ src/system/globalenv.h 2011-12-21 12:13:40 +0000
@@ -48,17 +48,19 @@
{
private:
- static GlobalEnvironment * m_globalEnv;
+ static GlobalEnvironment * m_globalEnv;
private:
- store::Store * m_store;
-
- root_static_context * m_rootStaticContext;
-
- XQueryCompilerSubsystem * m_compilerSubSys;
+ store::Store * m_store;
+
+ RootTypeManager * theRootTypeManager;
+
+ root_static_context * theRootStaticContext;
+
+ XQueryCompilerSubsystem * m_compilerSubSys;
#ifdef ZORBA_XQUERYX
- XQueryXConvertor * xqueryx_convertor;
+ XQueryXConvertor * xqueryx_convertor;
#endif
internal::HTTPURLResolver * m_http_resolver;
@@ -68,7 +70,7 @@
internal::ThesaurusURLResolver * m_thesaurus_resolver;
#endif /* ZORBA_NO_FULL_TEXT */
- mutable DynamicLoader * m_dynamic_loader;
+ mutable DynamicLoader * m_dynamic_loader;
public:
@@ -87,11 +89,11 @@
public:
~GlobalEnvironment();
- RootTypeManager& getRootTypeManager();
-
- static_context& getRootStaticContext();
-
- bool isRootStaticContextInitialized();
+ RootTypeManager& getRootTypeManager() const;
+
+ static_context& getRootStaticContext() const;
+
+ bool isRootStaticContextInitialized() const;
XQueryCompilerSubsystem& getCompilerSubsystem();
@@ -123,9 +125,9 @@
void init_icu();
void cleanup_icu();
-
};
+
#define GENV GlobalEnvironment::getInstance()
#define GENV_TYPESYSTEM GlobalEnvironment::getInstance().getRootTypeManager()
=== modified file 'src/types/root_typemanager.h'
--- src/types/root_typemanager.h 2011-06-14 17:26:33 +0000
+++ src/types/root_typemanager.h 2011-12-21 12:13:40 +0000
@@ -33,7 +33,7 @@
********************************************************************************/
class RootTypeManager : public TypeManagerImpl
{
- friend class root_static_context;
+ friend class GlobalEnvironment;
friend class TypeOps;
friend class TypeManagerImpl;
friend class AtomicXQType;
=== modified file 'src/types/typemanager.h'
--- src/types/typemanager.h 2011-06-14 17:26:33 +0000
+++ src/types/typemanager.h 2011-12-21 12:13:40 +0000
@@ -59,7 +59,7 @@
public:
SERIALIZABLE_ABSTRACT_CLASS(TypeManager)
SERIALIZABLE_CLASS_CONSTRUCTOR2(TypeManager, SimpleRCObject)
- void serialize(::zorba::serialization::Archiver &ar)
+ void serialize(::zorba::serialization::Archiver& ar)
{
//serialize_baseclass(ar, (SimpleRCObject*)this);
ar & m_level;
=== modified file 'test/unit/CMakeLists.txt'
--- test/unit/CMakeLists.txt 2011-12-20 09:04:58 +0000
+++ test/unit/CMakeLists.txt 2011-12-21 12:13:40 +0000
@@ -51,6 +51,10 @@
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/main_sequential.xq ${CMAKE_CURRENT_BINARY_DIR}/main_sequential.xq)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/main_sequential.xqlib ${CMAKE_CURRENT_BINARY_DIR}/main_sequential.xqlib)
+#belongs to test context_item
+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/context_item1.xq ${CMAKE_CURRENT_BINARY_DIR}/context_item1.xq)
+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/context_item2.xq ${CMAKE_CURRENT_BINARY_DIR}/context_item2.xq)
+
#belongs to streamable_string
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/streamable_string_query_1.xq ${CMAKE_CURRENT_BINARY_DIR}/streamable_string_query_1.xq)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/streamable_string_query_2.xq ${CMAKE_CURRENT_BINARY_DIR}/streamable_string_query_2.xq)
@@ -78,6 +82,7 @@
string_test.cpp
unique_ptr.cpp
main_sequential.cpp
+ context_item.cpp
datetime.cpp
invoke.cpp
xquery_functions.cpp
=== added file 'test/unit/context_item.cpp'
--- test/unit/context_item.cpp 1970-01-01 00:00:00 +0000
+++ test/unit/context_item.cpp 2011-12-21 12:13:40 +0000
@@ -0,0 +1,152 @@
+/*
+ * Copyright 2006-2010 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <fstream>
+#include <iostream>
+#include <cassert>
+
+#include <zorba/zorba.h>
+#include <zorba/store_manager.h>
+#include <zorba/typeident.h>
+#include <zorba/static_context.h>
+#include <zorba/xquery_exception.h>
+#include <zorba/diagnostic_list.h>
+#include <zorba/options.h>
+#include <zorba/item_factory.h>
+
+#include "system/properties.h"
+
+
+int test_1(zorba::Zorba* zorba)
+{
+ try
+ {
+ std::ifstream queryStream("context_item1.xq");
+ assert(queryStream.good());
+ std::ostringstream resultStream;
+
+ {
+ zorba::TypeIdentifier_t type =
+ zorba::TypeIdentifier::createNamedType("http://www.w3.org/2001/XMLSchema",
+ "integer");
+
+ zorba::Item ctxValue = zorba->getItemFactory()->createString("foo");
+
+ zorba::StaticContext_t sctx = zorba->createStaticContext();
+ sctx->setContextItemStaticType(type);
+
+ zorba::XQuery_t query = zorba->compileQuery(queryStream, sctx);
+
+ Zorba_SerializerOptions serOptions;
+ serOptions.omit_xml_declaration = ZORBA_OMIT_XML_DECLARATION_YES;
+
+ zorba::DynamicContext* dctx = query->getDynamicContext();
+ dctx->setContextItem(ctxValue);
+
+ query->execute(resultStream, &serOptions);
+ }
+ }
+ catch (zorba::XQueryException& qe)
+ {
+ if (qe.diagnostic() != zorba::err::XPTY0004)
+ {
+ std::cerr << qe << std::endl;
+ return 3;
+ }
+
+ return 0;
+ }
+ catch (zorba::ZorbaException& e)
+ {
+ std::cerr << e << std::endl;
+ return 1;
+ }
+ catch (...)
+ {
+ return 2;
+ }
+
+ return 4;
+}
+
+
+int test_2(zorba::Zorba* zorba)
+{
+ try
+ {
+ std::ifstream queryStream("context_item2.xq");
+ assert(queryStream.good());
+ std::ostringstream resultStream;
+
+ {
+ zorba::TypeIdentifier_t type =
+ zorba::TypeIdentifier::createNamedType("http://www.w3.org/2001/XMLSchema",
+ "integer");
+
+ zorba::Item ctxValue = zorba->getItemFactory()->createString("foo");
+
+ zorba::StaticContext_t sctx = zorba->createStaticContext();
+ sctx->setContextItemStaticType(type);
+
+ zorba::XQuery_t query = zorba->compileQuery(queryStream, sctx);
+
+ Zorba_SerializerOptions serOptions;
+ serOptions.omit_xml_declaration = ZORBA_OMIT_XML_DECLARATION_YES;
+
+ zorba::DynamicContext* dctx = query->getDynamicContext();
+ dctx->setContextItem(ctxValue);
+
+ query->execute(resultStream, &serOptions);
+
+ if (resultStream.str() != "foo")
+ return 5;
+ }
+ }
+ catch (zorba::XQueryException& qe)
+ {
+ std::cerr << qe << std::endl;
+ return 3;
+ }
+ catch (zorba::ZorbaException& e)
+ {
+ std::cerr << e << std::endl;
+ return 1;
+ }
+ catch (...)
+ {
+ return 2;
+ }
+
+ return 0;
+}
+
+
+int context_item(int argc, char* argv[])
+{
+ void* store = zorba::StoreManager::getStore();
+ zorba::Zorba* zorba = zorba::Zorba::getInstance(store);
+
+ zorba::Properties::load(0, NULL);
+
+ int result1 = test_1(zorba);
+
+ int result2 = test_2(zorba);
+
+ zorba->shutdown();
+ zorba::StoreManager::shutdownStore(store);
+ return result1 + result2;
+}
+
+/* vim:set et sw=2 ts=2: */
=== added file 'test/unit/context_item1.xq'
--- test/unit/context_item1.xq 1970-01-01 00:00:00 +0000
+++ test/unit/context_item1.xq 2011-12-21 12:13:40 +0000
@@ -0,0 +1,4 @@
+
+for $i in (1, 2, 3, 4)
+where $i > .
+return $i
=== added file 'test/unit/context_item2.xq'
--- test/unit/context_item2.xq 1970-01-01 00:00:00 +0000
+++ test/unit/context_item2.xq 2011-12-21 12:13:40 +0000
@@ -0,0 +1,6 @@
+
+declare context item as xs:string external;
+
+for $i in ("foo", "boo")
+where $i eq .
+return $i
Follow ups