Merge lp:~zorba-coders/zorba/bug-919438 into lp:zorba

Proposed by Till Westmann
Status: Merged
Approved by: Till Westmann
Approved revision: 10626
Merged at revision: 10659
Proposed branch: lp:~zorba-coders/zorba/bug-919438
Merge into: lp:zorba
Diff against target: 133 lines (+78/-13)
3 files modified
test/unit/CMakeLists.txt (+1/-0)
test/unit/mini_http.xq (+40/-0)
test/unit/plan_serializer.cpp (+37/-13)
To merge this branch: bzr merge lp:~zorba-coders/zorba/bug-919438
Reviewer Review Type Date Requested Status
Matthias Brantner Approve
Till Westmann Approve
Review via email: mp+93093@code.launchpad.net

Commit message

added a new unit test for the plan serializer

Description of the change

added a new unit test for the plan serializer

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
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job bug-919438-2012-02-14T22-22-55.863Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'test/unit/CMakeLists.txt'
2--- test/unit/CMakeLists.txt 2012-02-02 09:56:52 +0000
3+++ test/unit/CMakeLists.txt 2012-02-14 22:20:26 +0000
4@@ -14,6 +14,7 @@
5 # create the testing file and list of tests
6
7 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/guestbook_main.xq ${CMAKE_CURRENT_BINARY_DIR}/guestbook_main.xq)
8+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/mini_http.xq ${CMAKE_CURRENT_BINARY_DIR}/mini_http.xq)
9 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/guestbook.xq ${CMAKE_CURRENT_BINARY_DIR}/guestbook.xq)
10
11 #belongs to test cxx_api_changes.cpp
12
13=== added file 'test/unit/mini_http.xq'
14--- test/unit/mini_http.xq 1970-01-01 00:00:00 +0000
15+++ test/unit/mini_http.xq 2012-02-14 22:20:26 +0000
16@@ -0,0 +1,40 @@
17+declare namespace http = "http://www.28msec.com/modules/http";
18+
19+declare namespace ann = "http://www.zorba-xquery.com/annotations";
20+
21+declare variable $http:var := "";
22+
23+declare %ann:sequential function http:set-header(
24+ $name as xs:string,
25+ $value as xs:string)
26+as xs:string?
27+{
28+ let $lc-name := fn:lower-case($name)
29+ return
30+ if ($lc-name eq "status" or
31+ $lc-name eq "set-cookie" or
32+ $lc-name eq "content-type")
33+ then
34+ fn:error(
35+ xs:QName("http:invalid-header-name"),
36+ concat($name, ": invalid header name")
37+ )
38+ else
39+ http:set-header-impl($name, $value)
40+};
41+
42+(:~
43+ : <p>Set a HTTP header in the response.</p>
44+ :
45+ : <p>
46+ :`
47+ : @return The empty-sequence is returned.
48+ :)
49+declare %fn:private %ann:sequential function http:set-header-impl(
50+ $name as xs:string,
51+ $value as xs:string)
52+as xs:string? {
53+ $http:var := "val";
54+};
55+
56+http:set-header("foo", "bar")
57
58=== modified file 'test/unit/plan_serializer.cpp'
59--- test/unit/plan_serializer.cpp 2011-06-14 17:26:33 +0000
60+++ test/unit/plan_serializer.cpp 2012-02-14 22:20:26 +0000
61@@ -26,35 +26,59 @@
62
63 using namespace zorba;
64
65-
66-int
67-plan_serializer(int argc, char* argv[])
68+bool
69+save_and_load(Zorba* aZorba, const char* aQueryFile)
70 {
71- void* lStore = zorba::StoreManager::getStore();
72- Zorba* lZorba = Zorba::getInstance(lStore);
73-
74 try {
75- std::ifstream lIn("guestbook_main.xq");
76+ std::ifstream lIn(aQueryFile);
77 std::ostringstream lOut;
78
79 {
80- StaticContext_t lSctx = lZorba->createStaticContext();
81-
82- XQuery_t lQuery = lZorba->compileQuery(lIn, lSctx);
83+ StaticContext_t lSctx = aZorba->createStaticContext();
84+ XQuery_t lQuery = aZorba->compileQuery(lIn, lSctx);
85 lQuery->saveExecutionPlan(lOut, ZORBA_USE_BINARY_ARCHIVE, SAVE_UNUSED_FUNCTIONS);
86 }
87
88-
89 {
90 std::istringstream lIn(lOut.str());
91- XQuery_t lQuery = lZorba->createQuery();
92+ XQuery_t lQuery = aZorba->createQuery();
93 lQuery->loadExecutionPlan(lIn);
94 std::cout << lQuery << std::endl;
95 }
96+ return true;
97 } catch (ZorbaException& e) {
98 std::cerr << e << std::endl;
99+ return false;
100+ }
101+}
102+
103+bool
104+plan_serializer1(Zorba* aZorba)
105+{
106+ return save_and_load(aZorba, "guestbook_main.xq");
107+}
108+
109+bool
110+plan_serializer2(Zorba* aZorba)
111+{
112+ return save_and_load(aZorba, "mini_http.xq");
113+}
114+
115+int
116+plan_serializer(int argc, char* argv[])
117+{
118+ void* lStore = zorba::StoreManager::getStore();
119+ Zorba* lZorba = Zorba::getInstance(lStore);
120+
121+ std::cout << "executing test 1" << std::endl;
122+ if (!plan_serializer1(lZorba))
123 return 1;
124- }
125+ std::cout << std::endl;
126+
127+ std::cout << "executing test 2" << std::endl;
128+ if (!plan_serializer2(lZorba))
129+ return 2;
130+ std::cout << std::endl;
131
132 lZorba->shutdown();
133 zorba::StoreManager::shutdownStore(lStore);

Subscribers

People subscribed via source and target branches