leptris 1.9.458.0-arm-linux → 1.9.460.0-arm-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -0
- data/CONTEXT.md +9 -3
- data/README.adoc +28 -17
- data/Rakefile +1 -1
- data/lib/leptris/version.rb +1 -1
- data/lib/leptris/xml/document.rb +75 -48
- data/lib/leptris/xml/ffi.rb +8 -0
- data/lib/libleptris.so +0 -0
- data/vendor-src/README.md +1 -1
- data/vendor-src/libleptris/CHANGELOG.md +42 -0
- data/vendor-src/libleptris/CMakeLists.txt +1 -1
- data/vendor-src/libleptris/README.adoc +19 -0
- data/vendor-src/libleptris/benchmarks/CMakeLists.txt +23 -2
- data/vendor-src/libleptris/benchmarks/README.adoc +15 -0
- data/vendor-src/libleptris/benchmarks/README.md +17 -4
- data/vendor-src/libleptris/benchmarks/comprehensive/benchmark_decomp.cpp +2 -1
- data/vendor-src/libleptris/benchmarks/comprehensive/benchmark_first_access.cpp +2 -1
- data/vendor-src/libleptris/benchmarks/comprehensive/benchmark_many_attrs.cpp +2 -1
- data/vendor-src/libleptris/benchmarks/comprehensive/benchmark_memory.cpp +2 -1
- data/vendor-src/libleptris/benchmarks/comprehensive/benchmark_parse.cpp +2 -2
- data/vendor-src/libleptris/benchmarks/comprehensive/benchmark_parse_ops.cpp +8 -4
- data/vendor-src/libleptris/benchmarks/comprehensive/benchmark_write.cpp +4 -2
- data/vendor-src/libleptris/benchmarks/dom/dom_benchmark_v2.cpp +8 -4
- data/vendor-src/libleptris/benchmarks/fixtures/serialbench_users_medium.xml +13004 -0
- data/vendor-src/libleptris/benchmarks/matrix/bench_matrix.cpp +21 -76
- data/vendor-src/libleptris/benchmarks/matrix/bench_matrix_fused.cpp +31 -0
- data/vendor-src/libleptris/benchmarks/matrix/bench_rows.h +94 -0
- data/vendor-src/libleptris/benchmarks/modification/bench_append_attr_pugixml.cpp +2 -1
- data/vendor-src/libleptris/benchmarks/parse/bench_parse_ab.cpp +2 -1
- data/vendor-src/libleptris/benchmarks/twins/generation_users.sh +49 -0
- data/vendor-src/libleptris/benchmarks/twins/generation_users_fixture.h +78 -0
- data/vendor-src/libleptris/benchmarks/twins/generation_users_leptris.c +122 -0
- data/vendor-src/libleptris/benchmarks/twins/generation_users_pugixml.cpp +231 -0
- data/vendor-src/libleptris/benchmarks/twins/parse_pugixml.cpp +1 -1
- data/vendor-src/libleptris/benchmarks/twins/parse_users_ab.cpp +158 -0
- data/vendor-src/libleptris/benchmarks/workflows/bench_pipeline_shapes.cpp +12 -4
- data/vendor-src/libleptris/benchmarks/xpath/bench_pugixml.cpp +2 -1
- data/vendor-src/libleptris/cli/CLI_ARCHITECTURE.md +9 -1
- data/vendor-src/libleptris/cli/commands/diff.c +26 -28
- data/vendor-src/libleptris/cli/commands/format.c +3 -1
- data/vendor-src/libleptris/cli/commands/parse.c +3 -1
- data/vendor-src/libleptris/cli/commands/validate.c +22 -24
- data/vendor-src/libleptris/cli/commands/xpath.c +9 -1
- data/vendor-src/libleptris/cli/commands/xquery.c +12 -3
- data/vendor-src/libleptris/cli/commands/xslt.c +24 -8
- data/vendor-src/libleptris/cli/error.c +91 -0
- data/vendor-src/libleptris/cli/error.h +84 -0
- data/vendor-src/libleptris/cli/man/leptris-parse.1.adoc +21 -10
- data/vendor-src/libleptris/cli/man/leptris.1.adoc +19 -0
- data/vendor-src/libleptris/cli/output.c +18 -9
- data/vendor-src/libleptris/cli/output.h +17 -0
- data/vendor-src/libleptris/src/CMakeLists.txt +3 -0
- data/vendor-src/libleptris/src/include/leptris/types.h +25 -1
- data/vendor-src/libleptris/src/include/leptris/xquery/xquery.h +9 -1
- data/vendor-src/libleptris/src/include/leptris.h +48 -3
- data/vendor-src/libleptris/src/leptris/common/entities.c +2 -2
- data/vendor-src/libleptris/src/leptris/common/entities.h +8 -2
- data/vendor-src/libleptris/src/leptris/common/port.h +62 -0
- data/vendor-src/libleptris/src/leptris/common/uri_base.c +284 -0
- data/vendor-src/libleptris/src/leptris/common/uri_base.h +62 -0
- data/vendor-src/libleptris/src/leptris/core.c +33 -2
- data/vendor-src/libleptris/src/leptris/dom/compact.h +51 -0
- data/vendor-src/libleptris/src/leptris/dom/element.c +18 -0
- data/vendor-src/libleptris/src/leptris/dom/element.h +201 -12
- data/vendor-src/libleptris/src/leptris/dom/element_modify.c +611 -210
- data/vendor-src/libleptris/src/leptris/dom/element_query.c +72 -1
- data/vendor-src/libleptris/src/leptris/dom/name_intern.c +3 -1
- data/vendor-src/libleptris/src/leptris/dtd/model.c +13 -0
- data/vendor-src/libleptris/src/leptris/dtd/model.h +95 -6
- data/vendor-src/libleptris/src/leptris/dtd/resolver.c +302 -215
- data/vendor-src/libleptris/src/leptris/flat/direct_parse.c +801 -294
- data/vendor-src/libleptris/src/leptris/leptris.c +20 -5
- data/vendor-src/libleptris/src/leptris/leptris_internal.h +68 -22
- data/vendor-src/libleptris/src/leptris/serialize/serialize.c +289 -57
- data/vendor-src/libleptris/src/leptris/xinclude/xinclude.c +14 -125
- data/vendor-src/libleptris/src/leptris/xpath/evaluator.c +3 -0
- data/vendor-src/libleptris/src/leptris/xpath/evaluator_path.c +11 -8
- data/vendor-src/libleptris/src/leptris/xpath/functions_ext31.c +188 -24
- data/vendor-src/libleptris/src/leptris/xpath/vm.c +3 -1
- data/vendor-src/libleptris/src/leptris/xquery/xquery.c +5 -0
- data/vendor-src/libleptris/src/leptris/xsd/compile.c +59 -20
- data/vendor-src/libleptris/src/leptris/xsd/validate.c +291 -168
- data/vendor-src/libleptris/test/CMakeLists.txt +28 -0
- data/vendor-src/libleptris/test/abi/test_public_surface.cpp +37 -0
- data/vendor-src/libleptris/test/cli/test_cli.cpp +228 -0
- data/vendor-src/libleptris/test/common/hang_guard.h +179 -0
- data/vendor-src/libleptris/test/dom/test_compact.cpp +46 -0
- data/vendor-src/libleptris/test/dom/test_mut_append_contracts.cpp +173 -0
- data/vendor-src/libleptris/test/dom/test_mut_set_attr_contracts.cpp +771 -7
- data/vendor-src/libleptris/test/fixtures/entity_limits/good.xml +100 -0
- data/vendor-src/libleptris/test/fixtures/entity_limits/good_attr.xml +100 -0
- data/vendor-src/libleptris/test/fixtures/entity_limits/lol_classic.xml +51 -0
- data/vendor-src/libleptris/test/fixtures/entity_limits/lol_ig_attr.xml +23 -0
- data/vendor-src/libleptris/test/fixtures/entity_limits/lol_ig_content.xml +23 -0
- data/vendor-src/libleptris/test/fixtures/entity_limits/lol_long_name.xml +23 -0
- data/vendor-src/libleptris/test/memory/test_oom_injection.cpp +63 -0
- data/vendor-src/libleptris/test/parser/test_entity_limits.cpp +404 -0
- data/vendor-src/libleptris/test/parser/test_parser.cpp +126 -0
- data/vendor-src/libleptris/test/serializer/test_serialize.cpp +491 -0
- data/vendor-src/libleptris/test/xpath/test_base_uri.cpp +368 -0
- data/vendor-src/libleptris/test/xpath/test_xpath.cpp +86 -0
- data/vendor-src/libleptris/test/xsd/test_xsd11_base_uri.cpp +145 -0
- data/vendor-src/libleptris/test/xsd/test_xsd11_conformance.cpp +23 -5
- data/vendor-src/libleptris/test/xsd/test_xsd11_cta_context.cpp +385 -0
- data/vendor-src/libleptris/test/xsd/xsd11-all/all-restrict.xsd +3 -2
- data/vendor-src/libleptris/test/xsd/xsd11-all/all-wildcard.xsd +3 -2
- data/vendor-src/libleptris/test/xsd/xsd11-cases/MANIFEST.tsv +19 -2
- data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0003.n01.xml +5 -0
- data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0003.v01.xml +4 -0
- data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0003.xsd +46 -0
- data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0006.v01.xml +6 -0
- data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0006.xsd +83 -0
- data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0017.v01.xml +3 -0
- data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0017.xsd +36 -0
- data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0021.n01.xml +3 -0
- data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0021.v01.xml +3 -0
- data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0021.xsd +36 -0
- data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0023.v01.xml +3 -0
- data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0024.xsd +40 -0
- data/vendor-src/libleptris/test/xsd/xsd11-dispositions/README.md +67 -0
- data/vendor-src/libleptris/vcpkg.json +1 -1
- metadata +35 -2
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
// test/xpath/test_base_uri.cpp — #2278: documents carry a base/document
|
|
2
|
+
// URI, and fn:base-uri() / fn:document-uri() / fn:static-base-uri()
|
|
3
|
+
// answer from it instead of the "" constant they used to be.
|
|
4
|
+
//
|
|
5
|
+
// Surfaces:
|
|
6
|
+
// (1) leptris_parse_file stamps the resolved path as the document
|
|
7
|
+
// URI (leptris_document_uri — additive public API); a string
|
|
8
|
+
// parse carries none; leptris_document_set_uri supplies one
|
|
9
|
+
// for the in-memory shape (xmlReadMemory url / Nokogiri
|
|
10
|
+
// Document.parse(string, url)).
|
|
11
|
+
// (2) fn:base-uri(): the document URI resolved through every
|
|
12
|
+
// xml:base on the root-to-node chain (XML Base — a relative
|
|
13
|
+
// xml:base rides the inherited base, an absolute one replaces
|
|
14
|
+
// it); zero-argument form = the context item; an empty
|
|
15
|
+
// argument = the empty sequence.
|
|
16
|
+
// (3) fn:document-uri(): the document's URI, "" when it has none —
|
|
17
|
+
// and NOT the xml:base-adjusted base. fn:static-base-uri(): the
|
|
18
|
+
// XQuery prolog's `declare base-uri` when the query carries one
|
|
19
|
+
// (the XSD lane's schema document URI), else the context
|
|
20
|
+
// document's URI.
|
|
21
|
+
// (4) fn:doc() resolves a relative URI against the static base URI
|
|
22
|
+
// per RFC 3986 §5.2 — a DOCUMENT-URI base yields its directory
|
|
23
|
+
// (the XSD lane now stamps the schema document's own location,
|
|
24
|
+
// cta0024, and assert011's relative doc() must keep resolving).
|
|
25
|
+
//
|
|
26
|
+
// Red-first on main: every XPath expectation below answered "".
|
|
27
|
+
#include <gtest/gtest.h>
|
|
28
|
+
|
|
29
|
+
#include <cstdio>
|
|
30
|
+
#include <cstring>
|
|
31
|
+
#include <string>
|
|
32
|
+
|
|
33
|
+
#include "leptris.h"
|
|
34
|
+
#include "leptris/xquery/xquery.h"
|
|
35
|
+
|
|
36
|
+
#ifdef _WIN32
|
|
37
|
+
#include <direct.h>
|
|
38
|
+
#define leptris_test_chdir(p) _chdir(p)
|
|
39
|
+
#define leptris_test_getcwd(b, n) _getcwd(b, (int)(n))
|
|
40
|
+
#else
|
|
41
|
+
#include <unistd.h>
|
|
42
|
+
#define leptris_test_chdir(p) chdir(p)
|
|
43
|
+
#define leptris_test_getcwd(b, n) getcwd(b, n)
|
|
44
|
+
#endif
|
|
45
|
+
|
|
46
|
+
namespace {
|
|
47
|
+
|
|
48
|
+
/* A temp file with the given body; returns its path. */
|
|
49
|
+
std::string write_temp(const char* name, const char* body) {
|
|
50
|
+
std::string path = std::string(testing::TempDir()) + name;
|
|
51
|
+
FILE* f = fopen(path.c_str(), "wb");
|
|
52
|
+
EXPECT_NE(f, nullptr);
|
|
53
|
+
if (!f) return path;
|
|
54
|
+
fputs(body, f);
|
|
55
|
+
fclose(f);
|
|
56
|
+
return path;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/* Evaluate on the document node's root, as a string (caller frees). */
|
|
60
|
+
char* eval_string(LeptrisDocument doc, LeptrisElement ctx,
|
|
61
|
+
const char* expr) {
|
|
62
|
+
LeptrisXPathResult r = leptris_xpath_eval(doc, ctx, expr);
|
|
63
|
+
if (!r) return nullptr;
|
|
64
|
+
char* s = leptris_xpath_result_string(r);
|
|
65
|
+
leptris_xpath_result_free(r);
|
|
66
|
+
return s;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
std::string eval(LeptrisDocument doc, const char* expr,
|
|
70
|
+
LeptrisElement ctx = nullptr) {
|
|
71
|
+
char* s = eval_string(doc, ctx, expr);
|
|
72
|
+
std::string out = s ? s : "<null>";
|
|
73
|
+
leptris_free_string(s);
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
bool ends_with(const std::string& s, const char* suffix) {
|
|
78
|
+
size_t n = strlen(suffix);
|
|
79
|
+
return s.size() >= n && s.compare(s.size() - n, n, suffix) == 0;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/* ---- (1) the document URI on the public surface ---------------------- */
|
|
83
|
+
|
|
84
|
+
TEST(DocumentUri, ParseFileRecordsTheResolvedPath) {
|
|
85
|
+
std::string path = write_temp("base_uri_doc.xml", "<r><c/></r>");
|
|
86
|
+
LeptrisDocument doc = leptris_parse_file(path.c_str(), nullptr);
|
|
87
|
+
ASSERT_NE(doc, nullptr);
|
|
88
|
+
const char* uri = leptris_document_uri(doc);
|
|
89
|
+
ASSERT_NE(uri, nullptr);
|
|
90
|
+
/* absolute (a temp dir path is absolute on every platform), and
|
|
91
|
+
* the file it was loaded from */
|
|
92
|
+
EXPECT_TRUE(uri[0] == '/' || strchr(uri, ':') != nullptr);
|
|
93
|
+
EXPECT_TRUE(ends_with(uri, "/base_uri_doc.xml"));
|
|
94
|
+
remove(path.c_str());
|
|
95
|
+
leptris_document_free(doc);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
TEST(DocumentUri, ParseFileRelativePathRidesTheWorkingDirectory) {
|
|
99
|
+
std::string path = write_temp("base_uri_rel.xml", "<r/>");
|
|
100
|
+
std::string dir = testing::TempDir();
|
|
101
|
+
char cwd[4096];
|
|
102
|
+
ASSERT_NE(leptris_test_getcwd(cwd, sizeof(cwd)), nullptr);
|
|
103
|
+
ASSERT_EQ(leptris_test_chdir(dir.c_str()), 0);
|
|
104
|
+
LeptrisDocument doc = leptris_parse_file("base_uri_rel.xml", nullptr);
|
|
105
|
+
char here[4096];
|
|
106
|
+
ASSERT_NE(leptris_test_getcwd(here, sizeof(here)), nullptr);
|
|
107
|
+
ASSERT_EQ(leptris_test_chdir(cwd), 0);
|
|
108
|
+
ASSERT_NE(doc, nullptr);
|
|
109
|
+
const char* uri = leptris_document_uri(doc);
|
|
110
|
+
ASSERT_NE(uri, nullptr);
|
|
111
|
+
/* the same document as the absolute-path parse: cwd + the name,
|
|
112
|
+
* separators folded to the URI form */
|
|
113
|
+
std::string expect = std::string(here) + "/base_uri_rel.xml";
|
|
114
|
+
for (char& c : expect)
|
|
115
|
+
if (c == '\\') c = '/';
|
|
116
|
+
EXPECT_EQ(std::string(uri), expect);
|
|
117
|
+
remove(path.c_str());
|
|
118
|
+
leptris_document_free(doc);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
TEST(DocumentUri, StringParseCarriesNoUri) {
|
|
122
|
+
const char xml[] = "<r><c/></r>";
|
|
123
|
+
LeptrisDocument doc =
|
|
124
|
+
leptris_parse_string(xml, strlen(xml), nullptr);
|
|
125
|
+
ASSERT_NE(doc, nullptr);
|
|
126
|
+
EXPECT_EQ(leptris_document_uri(doc), nullptr);
|
|
127
|
+
/* and the XPath surface answers "" — the spec answer for a
|
|
128
|
+
* URI-less document, not a stub */
|
|
129
|
+
EXPECT_EQ(eval(doc, "document-uri(/)"), "");
|
|
130
|
+
EXPECT_EQ(eval(doc, "base-uri(/)"), "");
|
|
131
|
+
EXPECT_EQ(eval(doc, "static-base-uri()"), "");
|
|
132
|
+
leptris_document_free(doc);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
TEST(DocumentUri, SetUriSuppliesTheUrlAndClears) {
|
|
136
|
+
const char xml[] = "<r><c/></r>";
|
|
137
|
+
LeptrisDocument doc =
|
|
138
|
+
leptris_parse_string(xml, strlen(xml), nullptr);
|
|
139
|
+
ASSERT_NE(doc, nullptr);
|
|
140
|
+
/* NULL document is rejected; the URI is copied (the caller's
|
|
141
|
+
* buffer may go) and document-owned */
|
|
142
|
+
EXPECT_EQ(leptris_document_set_uri(
|
|
143
|
+
nullptr, "http://example.org/x.xml"),
|
|
144
|
+
LEPTRIS_ERROR_NULL_ARG);
|
|
145
|
+
char url[] = "http://example.org/dir/x.xml";
|
|
146
|
+
ASSERT_EQ(leptris_document_set_uri(doc, url), LEPTRIS_OK);
|
|
147
|
+
url[0] = 'X';
|
|
148
|
+
EXPECT_STREQ(leptris_document_uri(doc), "http://example.org/dir/x.xml");
|
|
149
|
+
EXPECT_EQ(eval(doc, "document-uri(/)"), "http://example.org/dir/x.xml");
|
|
150
|
+
EXPECT_EQ(eval(doc, "base-uri(.)"), "http://example.org/dir/x.xml");
|
|
151
|
+
/* NULL (and "") clears — back to the URI-less string-parse state */
|
|
152
|
+
ASSERT_EQ(leptris_document_set_uri(doc, nullptr), LEPTRIS_OK);
|
|
153
|
+
EXPECT_EQ(leptris_document_uri(doc), nullptr);
|
|
154
|
+
ASSERT_EQ(leptris_document_set_uri(doc, ""), LEPTRIS_OK);
|
|
155
|
+
EXPECT_EQ(leptris_document_uri(doc), nullptr);
|
|
156
|
+
leptris_document_free(doc);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/* ---- (2) fn:base-uri() ------------------------------------------------ */
|
|
160
|
+
|
|
161
|
+
TEST(BaseUri, ParsedFileAnswersItsPathForEveryNode) {
|
|
162
|
+
std::string path = write_temp("cta0021.v01.xml",
|
|
163
|
+
"<doc><event type=\"date\">"
|
|
164
|
+
"<when>2010-10-16</when></event></doc>");
|
|
165
|
+
LeptrisDocument doc = leptris_parse_file(path.c_str(), nullptr);
|
|
166
|
+
ASSERT_NE(doc, nullptr);
|
|
167
|
+
LeptrisElement root = leptris_document_root(doc);
|
|
168
|
+
ASSERT_NE(root, nullptr);
|
|
169
|
+
/* saxonData/CTA/cta0021's own test: the verdict is decided by the
|
|
170
|
+
* document's base URI — v01 loads from a path ending .v01.xml */
|
|
171
|
+
EXPECT_EQ(eval(doc, "ends-with(base-uri(.), 'cta0021.v01.xml')",
|
|
172
|
+
root),
|
|
173
|
+
"true");
|
|
174
|
+
/* the zero-argument form rides the context item; the document
|
|
175
|
+
* node answers the document URI; a descendant inherits it */
|
|
176
|
+
EXPECT_EQ(eval(doc, "ends-with(base-uri(), 'cta0021.v01.xml')",
|
|
177
|
+
root),
|
|
178
|
+
"true");
|
|
179
|
+
EXPECT_EQ(eval(doc, "ends-with(base-uri(/), 'cta0021.v01.xml')"),
|
|
180
|
+
"true");
|
|
181
|
+
EXPECT_EQ(eval(doc,
|
|
182
|
+
"ends-with(base-uri(/doc/event/when), 'cta0021.v01.xml')"),
|
|
183
|
+
"true");
|
|
184
|
+
/* a text node rides its parent's base (XDM) */
|
|
185
|
+
EXPECT_EQ(eval(doc,
|
|
186
|
+
"ends-with(base-uri(/doc/event/when/text()),"
|
|
187
|
+
" 'cta0021.v01.xml')"),
|
|
188
|
+
"true");
|
|
189
|
+
/* the sibling instance loaded from the other name answers the
|
|
190
|
+
* other URI — the false arm that selects xs:error for n01 */
|
|
191
|
+
EXPECT_EQ(eval(doc, "ends-with(base-uri(.), 'cta0021.n01.xml')",
|
|
192
|
+
root),
|
|
193
|
+
"false");
|
|
194
|
+
remove(path.c_str());
|
|
195
|
+
leptris_document_free(doc);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
TEST(BaseUri, XmlBaseChainResolvesOverTheDocumentUri) {
|
|
199
|
+
const char xml[] =
|
|
200
|
+
"<a xml:base=\"sub/\"><b xml:base=\"more/x.xml\"><c xml:base=\"y/\">"
|
|
201
|
+
"<d/></c></b></a>";
|
|
202
|
+
LeptrisDocument doc =
|
|
203
|
+
leptris_parse_string(xml, strlen(xml), nullptr);
|
|
204
|
+
ASSERT_NE(doc, nullptr);
|
|
205
|
+
ASSERT_EQ(leptris_document_set_uri(
|
|
206
|
+
doc, "http://example.org/dir/doc.xml"),
|
|
207
|
+
LEPTRIS_OK);
|
|
208
|
+
/* each xml:base rides the base inherited from above */
|
|
209
|
+
EXPECT_EQ(eval(doc, "base-uri(/a)"), "http://example.org/dir/sub/");
|
|
210
|
+
EXPECT_EQ(eval(doc, "base-uri(/a/b)"),
|
|
211
|
+
"http://example.org/dir/sub/more/x.xml");
|
|
212
|
+
/* c's relative xml:base resolves against b's, not the document */
|
|
213
|
+
EXPECT_EQ(eval(doc, "base-uri(/a/b/c)"),
|
|
214
|
+
"http://example.org/dir/sub/more/y/");
|
|
215
|
+
/* no xml:base: the nearest ancestor's base */
|
|
216
|
+
EXPECT_EQ(eval(doc, "base-uri(/a/b/c/d)"),
|
|
217
|
+
"http://example.org/dir/sub/more/y/");
|
|
218
|
+
leptris_document_free(doc);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
TEST(BaseUri, AbsoluteXmlBaseReplacesAndRelativeDotSegmentsFold) {
|
|
222
|
+
const char xml[] =
|
|
223
|
+
"<a xml:base=\"http://example.org/dir/doc.xml\">"
|
|
224
|
+
"<b xml:base=\"http://other.org/z.xml\"><c/></b>"
|
|
225
|
+
"<d xml:base=\"../up/q.xml\"><e/></d></a>";
|
|
226
|
+
LeptrisDocument doc =
|
|
227
|
+
leptris_parse_string(xml, strlen(xml), nullptr);
|
|
228
|
+
ASSERT_NE(doc, nullptr);
|
|
229
|
+
/* an absolute xml:base replaces the inherited base wholesale;
|
|
230
|
+
* RFC 3986 §5.2.4 folds the ".." against the inherited dir */
|
|
231
|
+
EXPECT_EQ(eval(doc, "base-uri(/a/b)"), "http://other.org/z.xml");
|
|
232
|
+
EXPECT_EQ(eval(doc, "base-uri(/a/b/c)"), "http://other.org/z.xml");
|
|
233
|
+
EXPECT_EQ(eval(doc, "base-uri(/a/d/e)"),
|
|
234
|
+
"http://example.org/up/q.xml");
|
|
235
|
+
leptris_document_free(doc);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
TEST(BaseUri, XmlBaseOnAFileDocumentRidesTheFilePath) {
|
|
239
|
+
std::string path = write_temp("base_uri_xb.xml",
|
|
240
|
+
"<a xml:base=\"sub/\"><b/></a>");
|
|
241
|
+
LeptrisDocument doc = leptris_parse_file(path.c_str(), nullptr);
|
|
242
|
+
ASSERT_NE(doc, nullptr);
|
|
243
|
+
const char* uri = leptris_document_uri(doc);
|
|
244
|
+
ASSERT_NE(uri, nullptr);
|
|
245
|
+
/* the xml:base resolves against the plain-path document URI the
|
|
246
|
+
* same way it resolves against a URL */
|
|
247
|
+
std::string expect = std::string(uri);
|
|
248
|
+
size_t slash = expect.rfind('/');
|
|
249
|
+
ASSERT_NE(slash, std::string::npos);
|
|
250
|
+
expect = expect.substr(0, slash + 1) + "sub/";
|
|
251
|
+
EXPECT_EQ(eval(doc, "base-uri(/a)"), expect);
|
|
252
|
+
EXPECT_EQ(eval(doc, "base-uri(/a/b)"), expect);
|
|
253
|
+
remove(path.c_str());
|
|
254
|
+
leptris_document_free(doc);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
TEST(BaseUri, EmptyArgumentIsTheEmptySequence) {
|
|
258
|
+
const char xml[] = "<r><c/></r>";
|
|
259
|
+
LeptrisDocument doc =
|
|
260
|
+
leptris_parse_string(xml, strlen(xml), nullptr);
|
|
261
|
+
ASSERT_NE(doc, nullptr);
|
|
262
|
+
ASSERT_EQ(leptris_document_set_uri(doc, "http://e.org/d.xml"),
|
|
263
|
+
LEPTRIS_OK);
|
|
264
|
+
/* base-uri(()) is () — not the context item's base */
|
|
265
|
+
EXPECT_EQ(eval(doc, "count(base-uri(()))"), "0");
|
|
266
|
+
EXPECT_EQ(eval(doc, "count(base-uri(/r/c))"), "1");
|
|
267
|
+
EXPECT_EQ(eval(doc, "count(document-uri(()))"), "0");
|
|
268
|
+
leptris_document_free(doc);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/* ---- (3) fn:document-uri() / fn:static-base-uri() -------------------- */
|
|
272
|
+
|
|
273
|
+
TEST(DocumentUri, FunctionIsTheDocumentUriNotTheXmlBase) {
|
|
274
|
+
const char xml[] = "<a xml:base=\"http://other.org/sub/\"><b/></a>";
|
|
275
|
+
LeptrisDocument doc =
|
|
276
|
+
leptris_parse_string(xml, strlen(xml), nullptr);
|
|
277
|
+
ASSERT_NE(doc, nullptr);
|
|
278
|
+
ASSERT_EQ(leptris_document_set_uri(
|
|
279
|
+
doc, "http://example.org/dir/doc.xml"),
|
|
280
|
+
LEPTRIS_OK);
|
|
281
|
+
/* xml:base moves the BASE, never the document URI */
|
|
282
|
+
EXPECT_EQ(eval(doc, "document-uri(/)"),
|
|
283
|
+
"http://example.org/dir/doc.xml");
|
|
284
|
+
EXPECT_EQ(eval(doc, "document-uri(/a/b)"),
|
|
285
|
+
"http://example.org/dir/doc.xml");
|
|
286
|
+
EXPECT_EQ(eval(doc, "base-uri(/a/b)"), "http://other.org/sub/");
|
|
287
|
+
leptris_document_free(doc);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
TEST(StaticBaseUri, StandaloneEngineDefaultsToTheDocumentUri) {
|
|
291
|
+
std::string path = write_temp("base_uri_sb.xml", "<r/>");
|
|
292
|
+
LeptrisDocument doc = leptris_parse_file(path.c_str(), nullptr);
|
|
293
|
+
ASSERT_NE(doc, nullptr);
|
|
294
|
+
/* the XPath static context's base URI defaults to the document's */
|
|
295
|
+
EXPECT_TRUE(ends_with(eval(doc, "static-base-uri()"),
|
|
296
|
+
"/base_uri_sb.xml"));
|
|
297
|
+
EXPECT_EQ(eval(doc, "static-base-uri() = document-uri(/)"), "true");
|
|
298
|
+
remove(path.c_str());
|
|
299
|
+
leptris_document_free(doc);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/* ---- (4) the static base URI in an XQuery prolog -------------------- */
|
|
303
|
+
|
|
304
|
+
TEST(StaticBaseUri, PrologDeclarationIsTheStaticBaseAndResolvesDoc) {
|
|
305
|
+
const char xml[] = "<r/>";
|
|
306
|
+
LeptrisDocument doc =
|
|
307
|
+
leptris_parse_string(xml, strlen(xml), nullptr);
|
|
308
|
+
ASSERT_NE(doc, nullptr);
|
|
309
|
+
std::string target = write_temp("base_uri_target.xml",
|
|
310
|
+
"<x><y/></x>");
|
|
311
|
+
/* a DOCUMENT-URI base (the XSD lane's schema document location,
|
|
312
|
+
* cta0024's shape): static-base-uri() answers it verbatim, and
|
|
313
|
+
* a relative doc() resolves to its DIRECTORY (RFC 3986 §5.2) */
|
|
314
|
+
std::string dir = testing::TempDir();
|
|
315
|
+
std::string base = dir + "host.xsd";
|
|
316
|
+
for (char& c : base)
|
|
317
|
+
if (c == '\\') c = '/';
|
|
318
|
+
std::string q = "declare base-uri \"" + base + "\"; "
|
|
319
|
+
"static-base-uri()";
|
|
320
|
+
LeptrisXQuery xq = leptris_xquery_parse(q.c_str(), q.size());
|
|
321
|
+
ASSERT_NE(xq, nullptr);
|
|
322
|
+
LeptrisXPathResult r = leptris_xquery_eval(xq, doc, nullptr);
|
|
323
|
+
ASSERT_NE(r, nullptr);
|
|
324
|
+
char* s = leptris_xpath_result_string(r);
|
|
325
|
+
ASSERT_NE(s, nullptr);
|
|
326
|
+
EXPECT_EQ(std::string(s), base);
|
|
327
|
+
leptris_free_string(s);
|
|
328
|
+
leptris_xpath_result_free(r);
|
|
329
|
+
leptris_xquery_free(xq);
|
|
330
|
+
|
|
331
|
+
q = "declare base-uri \"" + base +
|
|
332
|
+
"\"; count(doc('base_uri_target.xml')/x/y)";
|
|
333
|
+
xq = leptris_xquery_parse(q.c_str(), q.size());
|
|
334
|
+
ASSERT_NE(xq, nullptr);
|
|
335
|
+
r = leptris_xquery_eval(xq, doc, nullptr);
|
|
336
|
+
ASSERT_NE(r, nullptr) << "doc() must resolve against the base's directory";
|
|
337
|
+
EXPECT_EQ(leptris_xpath_result_number(r), 1.0);
|
|
338
|
+
leptris_xpath_result_free(r);
|
|
339
|
+
leptris_xquery_free(xq);
|
|
340
|
+
|
|
341
|
+
/* the directory-with-trailing-slash spelling resolves the same */
|
|
342
|
+
q = "declare base-uri \"" + dir +
|
|
343
|
+
"/\"; count(doc('base_uri_target.xml')/x/y)";
|
|
344
|
+
xq = leptris_xquery_parse(q.c_str(), q.size());
|
|
345
|
+
ASSERT_NE(xq, nullptr);
|
|
346
|
+
r = leptris_xquery_eval(xq, doc, nullptr);
|
|
347
|
+
ASSERT_NE(r, nullptr);
|
|
348
|
+
EXPECT_EQ(leptris_xpath_result_number(r), 1.0);
|
|
349
|
+
leptris_xpath_result_free(r);
|
|
350
|
+
leptris_xquery_free(xq);
|
|
351
|
+
|
|
352
|
+
/* and the loaded document names where it came from */
|
|
353
|
+
q = "declare base-uri \"" + base +
|
|
354
|
+
"\"; ends-with(document-uri(doc('base_uri_target.xml')),"
|
|
355
|
+
" 'base_uri_target.xml')";
|
|
356
|
+
xq = leptris_xquery_parse(q.c_str(), q.size());
|
|
357
|
+
ASSERT_NE(xq, nullptr);
|
|
358
|
+
r = leptris_xquery_eval(xq, doc, nullptr);
|
|
359
|
+
ASSERT_NE(r, nullptr);
|
|
360
|
+
EXPECT_EQ(leptris_xpath_result_boolean(r), 1);
|
|
361
|
+
leptris_xpath_result_free(r);
|
|
362
|
+
leptris_xquery_free(xq);
|
|
363
|
+
|
|
364
|
+
remove(target.c_str());
|
|
365
|
+
leptris_document_free(doc);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
} // namespace
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
#include <gtest/gtest.h>
|
|
4
4
|
|
|
5
5
|
#include "leptris.h"
|
|
6
|
+
#include "leptris/xquery/xquery.h" /* LEPTRIS_XQUERY_CONTEXT_IS_ROOT (#2277) */
|
|
6
7
|
|
|
7
8
|
#include <cstring>
|
|
8
9
|
|
|
@@ -2261,6 +2262,17 @@ static bool BoolEval(const char* expr) {
|
|
|
2261
2262
|
return v;
|
|
2262
2263
|
}
|
|
2263
2264
|
|
|
2265
|
+
/* Like BoolEval, with an explicit context node (the caller owns doc). */
|
|
2266
|
+
static bool BoolEvalOn(LeptrisElement context_node, LeptrisDocument doc,
|
|
2267
|
+
const char* expr) {
|
|
2268
|
+
LeptrisXPathResult r = leptris_xpath_eval(doc, context_node, expr);
|
|
2269
|
+
if (!r) return false;
|
|
2270
|
+
bool v = leptris_xpath_result_type(r) == LEPTRIS_XPATH_BOOLEAN &&
|
|
2271
|
+
leptris_xpath_result_boolean(r);
|
|
2272
|
+
leptris_xpath_result_free(r);
|
|
2273
|
+
return v;
|
|
2274
|
+
}
|
|
2275
|
+
|
|
2264
2276
|
static double NumEval(const char* expr) {
|
|
2265
2277
|
LeptrisDocument doc = ParseWith(kBasic);
|
|
2266
2278
|
EXPECT_NE(doc, nullptr);
|
|
@@ -2382,6 +2394,80 @@ TEST(XPath20Ledger, SequenceNodeTail) {
|
|
|
2382
2394
|
}
|
|
2383
2395
|
}
|
|
2384
2396
|
|
|
2397
|
+
/* #2277: fn:root (F&O 14.5, XPath 2.0+) — the root of the tree the
|
|
2398
|
+
* context item (or the argument) belongs to: the engine's '/' (the
|
|
2399
|
+
* document node) on an attached tree. Under the CONTEXT_IS_ROOT eval
|
|
2400
|
+
* flag — the XSD 1.1 §3.12.4 CTA data model, where "the root node of
|
|
2401
|
+
* the instance is necessarily constructed from E" — the context
|
|
2402
|
+
* element is its own root, so `(. is root())` holds there. */
|
|
2403
|
+
TEST(XPath20Ledger, RootFunction) {
|
|
2404
|
+
/* Zero-arg: the context item's root — the same node '/' is. */
|
|
2405
|
+
EXPECT_TRUE(BoolEval("root() is /"));
|
|
2406
|
+
EXPECT_TRUE(BoolEval("count(root()) = 1"));
|
|
2407
|
+
EXPECT_TRUE(BoolEval("count(root()/*) = 1 and name(root()/*) = 'catalog'"));
|
|
2408
|
+
/* Explicit argument: any descendant answers the same root. */
|
|
2409
|
+
EXPECT_TRUE(BoolEval("root(//book[2]) is /"));
|
|
2410
|
+
EXPECT_TRUE(BoolEval("root(//book[2]/title) is /"));
|
|
2411
|
+
EXPECT_TRUE(BoolEval("root(//book[2]/title) is root(//book[3])"));
|
|
2412
|
+
EXPECT_TRUE(BoolEval("name(root(//book[2])/*) = 'catalog'"));
|
|
2413
|
+
EXPECT_EQ(NumEval("count(root(//book))"), 1.0);
|
|
2414
|
+
/* An attribute has no parent edge: it climbs from its owner. */
|
|
2415
|
+
EXPECT_TRUE(BoolEval("root(//book[2]/@id) is /"));
|
|
2416
|
+
/* The empty sequence is the empty sequence. */
|
|
2417
|
+
EXPECT_EQ(NumEval("count(root(()))"), 0.0);
|
|
2418
|
+
/* An atomic argument is a type error, not a silent default. */
|
|
2419
|
+
{
|
|
2420
|
+
LeptrisDocument d = ParseWith(kBasic);
|
|
2421
|
+
ASSERT_NE(d, nullptr);
|
|
2422
|
+
EXPECT_EQ(leptris_xpath_eval(d, nullptr, "root('x')"), nullptr);
|
|
2423
|
+
leptris_document_free(d);
|
|
2424
|
+
}
|
|
2425
|
+
/* From a nested context item the zero-arg form still climbs to
|
|
2426
|
+
* the tree's root. */
|
|
2427
|
+
{
|
|
2428
|
+
LeptrisDocument d = ParseWith(kBasic);
|
|
2429
|
+
ASSERT_NE(d, nullptr);
|
|
2430
|
+
LeptrisElement title = leptris_element_first_child(
|
|
2431
|
+
leptris_element_first_child(leptris_document_root(d), "book"),
|
|
2432
|
+
"title");
|
|
2433
|
+
ASSERT_NE(title, nullptr);
|
|
2434
|
+
EXPECT_TRUE(BoolEvalOn(title, d, "root() is /"));
|
|
2435
|
+
EXPECT_TRUE(BoolEvalOn(title, d, "root() is root(//book[3])"));
|
|
2436
|
+
leptris_document_free(d);
|
|
2437
|
+
}
|
|
2438
|
+
/* The CONTEXT_IS_ROOT shape (XSD 1.1 §3.12.4's data model, the CTA
|
|
2439
|
+
* lane): under the flag the context element is the root node, so
|
|
2440
|
+
* `(. is root())` holds; on the same attached element without the
|
|
2441
|
+
* flag the root is the document node. */
|
|
2442
|
+
{
|
|
2443
|
+
LeptrisDocument d = ParseWith("<when type=\"date\">2010-10-16</when>");
|
|
2444
|
+
ASSERT_NE(d, nullptr);
|
|
2445
|
+
LeptrisElement e = leptris_document_root(d);
|
|
2446
|
+
ASSERT_NE(e, nullptr);
|
|
2447
|
+
EXPECT_FALSE(BoolEvalOn(e, d, ". is root()"));
|
|
2448
|
+
EXPECT_TRUE(BoolEvalOn(e, d, "root() is /"));
|
|
2449
|
+
const char* q_text =
|
|
2450
|
+
". is root() and root() is . and empty(..) and "
|
|
2451
|
+
"empty(root()/..) and count(root()) = 1";
|
|
2452
|
+
LeptrisXQuery q = leptris_xquery_parse(q_text, std::strlen(q_text));
|
|
2453
|
+
ASSERT_NE(q, (LeptrisXQuery)0);
|
|
2454
|
+
LeptrisXPathResult r = leptris_xquery_eval_params_ex(
|
|
2455
|
+
q, d, e, nullptr, nullptr, 0,
|
|
2456
|
+
(unsigned)LEPTRIS_XQUERY_CONTEXT_IS_ROOT);
|
|
2457
|
+
ASSERT_NE(r, nullptr);
|
|
2458
|
+
EXPECT_TRUE(leptris_xpath_result_boolean(r));
|
|
2459
|
+
leptris_xpath_result_free(r);
|
|
2460
|
+
/* the flag carries the semantics: the same query, unflagged,
|
|
2461
|
+
* is false on the same element */
|
|
2462
|
+
r = leptris_xquery_eval_params_ex(q, d, e, nullptr, nullptr, 0, 0);
|
|
2463
|
+
ASSERT_NE(r, nullptr);
|
|
2464
|
+
EXPECT_FALSE(leptris_xpath_result_boolean(r));
|
|
2465
|
+
leptris_xpath_result_free(r);
|
|
2466
|
+
leptris_xquery_free(q);
|
|
2467
|
+
leptris_document_free(d);
|
|
2468
|
+
}
|
|
2469
|
+
}
|
|
2470
|
+
|
|
2385
2471
|
TEST(XPath20Ledger, DocumentUriTail) {
|
|
2386
2472
|
/* In-memory documents carry no base/document URI. */
|
|
2387
2473
|
EXPECT_EQ(StrEval("base-uri(//book[1])"), "");
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// test/xsd/test_xsd11_base_uri.cpp — #2278: the two saxonData/CTA
|
|
2
|
+
// testGroups (version="full-xpath-in-CTA") whose verdicts hinge on
|
|
3
|
+
// the base/document URI. Both were false-invalid on main, where
|
|
4
|
+
// fn:base-uri()/fn:static-base-uri() were "" constants; both ride
|
|
5
|
+
// the conformance manifest now (test_xsd11_conformance.cpp) and this
|
|
6
|
+
// file pins the mechanism behind each flip.
|
|
7
|
+
//
|
|
8
|
+
// cta0021 ("XPath expression sees base URI of element node"):
|
|
9
|
+
// <xs:alternative test="ends-with(base-uri(.), 'cta0021.v01.xml')" .../>
|
|
10
|
+
// The suite ships two BYTE-IDENTICAL instances; the verdict is decided
|
|
11
|
+
// purely by the path each loads from — so the runner must load them
|
|
12
|
+
// from their real paths (leptris_parse_file records the resolved
|
|
13
|
+
// path as the document URI; a string parse legitimately carries
|
|
14
|
+
// none and answers "").
|
|
15
|
+
//
|
|
16
|
+
// cta0024 ("Static context of XPath expression"):
|
|
17
|
+
// <xs:alternative test="ends-with(static-base-uri(), 'cta0024.xsd')" .../>
|
|
18
|
+
// XSD 1.1 §3.13.4.1 maps the {test}'s base URI to "the [base URI] of
|
|
19
|
+
// the host element" — the SCHEMA document's own location, not the
|
|
20
|
+
// instance's. The compile stamps each schema document with its URI
|
|
21
|
+
// and the captured prolog carries it as the static base URI.
|
|
22
|
+
// cta0024.v01's instanceDocument is the suite's own cta0023.v01.xml.
|
|
23
|
+
//
|
|
24
|
+
// Red-first on main: Cta0021.V01IsValid and Cta0024.InstanceIsValid
|
|
25
|
+
// failed (both selected xs:error); the two negative pins held.
|
|
26
|
+
#include <gtest/gtest.h>
|
|
27
|
+
|
|
28
|
+
#include <cstdio>
|
|
29
|
+
#include <string>
|
|
30
|
+
|
|
31
|
+
#include "leptris.h"
|
|
32
|
+
|
|
33
|
+
namespace {
|
|
34
|
+
|
|
35
|
+
std::string cases(const char* rel) {
|
|
36
|
+
return std::string(LEPTRIS_XSD11_CASES_DIR) + "/" + rel;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/* Compile the schema from its FILE (the URI-stamping entry) and
|
|
40
|
+
* validate the instance loaded from its FILE; 1 valid, 0 invalid,
|
|
41
|
+
* -1 schema/instance could not be loaded. Same 1.1 processor dial as
|
|
42
|
+
* the conformance harness. */
|
|
43
|
+
int validate_files(const char* schema, const char* instance) {
|
|
44
|
+
LeptrisXsdSchema s =
|
|
45
|
+
leptris_xsd_compile_file(cases(schema).c_str(), nullptr);
|
|
46
|
+
if (!s) return -1;
|
|
47
|
+
leptris_xsd_set_processor_dialect(s, 1);
|
|
48
|
+
LeptrisDocument d =
|
|
49
|
+
leptris_parse_file(cases(instance).c_str(), nullptr);
|
|
50
|
+
int v = d ? leptris_xsd_validate(s, d) : -1;
|
|
51
|
+
if (d) leptris_document_free(d);
|
|
52
|
+
leptris_xsd_free(s);
|
|
53
|
+
return v;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/* The file's bytes as a string (for the string-parse postures). */
|
|
57
|
+
std::string read_file(const char* rel) {
|
|
58
|
+
FILE* f = fopen(cases(rel).c_str(), "rb");
|
|
59
|
+
EXPECT_NE(f, nullptr);
|
|
60
|
+
if (!f) return "";
|
|
61
|
+
std::string out;
|
|
62
|
+
char buf[4096];
|
|
63
|
+
size_t n;
|
|
64
|
+
while ((n = fread(buf, 1, sizeof(buf), f)) > 0) out.append(buf, n);
|
|
65
|
+
fclose(f);
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/* ---- cta0021: the document URI decides -------------------------------- */
|
|
70
|
+
|
|
71
|
+
TEST(Xsd11BaseUri, Cta0021ValidInstanceIsValid) {
|
|
72
|
+
EXPECT_EQ(validate_files("saxonData/CTA/cta0021.xsd",
|
|
73
|
+
"saxonData/CTA/cta0021.v01.xml"),
|
|
74
|
+
1);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
TEST(Xsd11BaseUri, Cta0021InvalidInstanceIsInvalid) {
|
|
78
|
+
EXPECT_EQ(validate_files("saxonData/CTA/cta0021.xsd",
|
|
79
|
+
"saxonData/CTA/cta0021.n01.xml"),
|
|
80
|
+
0);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
TEST(Xsd11BaseUri, Cta0021InstancesAreByteIdentical) {
|
|
84
|
+
/* The pin that makes the pair a pure base-URI test: nothing in
|
|
85
|
+
* the bytes distinguishes them. */
|
|
86
|
+
EXPECT_EQ(read_file("saxonData/CTA/cta0021.v01.xml"),
|
|
87
|
+
read_file("saxonData/CTA/cta0021.n01.xml"));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
TEST(Xsd11BaseUri, AStringParsedInstanceCarriesNoBaseUri) {
|
|
91
|
+
/* The same bytes parsed from a string have no document URI, so
|
|
92
|
+
* base-uri(.) is "" and the test selects xs:error — spec-correct
|
|
93
|
+
* for a document with no base URI (the runner must load from the
|
|
94
|
+
* real path for the verdict to be decided). */
|
|
95
|
+
LeptrisXsdSchema s = leptris_xsd_compile_file(
|
|
96
|
+
cases("saxonData/CTA/cta0021.xsd").c_str(), nullptr);
|
|
97
|
+
ASSERT_NE(s, nullptr);
|
|
98
|
+
leptris_xsd_set_processor_dialect(s, 1);
|
|
99
|
+
std::string xml = read_file("saxonData/CTA/cta0021.v01.xml");
|
|
100
|
+
LeptrisDocument d =
|
|
101
|
+
leptris_parse_string(xml.data(), xml.size(), nullptr);
|
|
102
|
+
ASSERT_NE(d, nullptr);
|
|
103
|
+
EXPECT_EQ(leptris_document_uri(d), nullptr);
|
|
104
|
+
EXPECT_EQ(leptris_xsd_validate(s, d), 0);
|
|
105
|
+
/* supplying the URL (the xmlReadMemory/Nokogiri shape) flips it
|
|
106
|
+
* back: the test sees the loaded-from name */
|
|
107
|
+
ASSERT_EQ(leptris_document_set_uri(
|
|
108
|
+
d, cases("saxonData/CTA/cta0021.v01.xml").c_str()),
|
|
109
|
+
LEPTRIS_OK);
|
|
110
|
+
EXPECT_EQ(leptris_xsd_validate(s, d), 1);
|
|
111
|
+
leptris_document_free(d);
|
|
112
|
+
leptris_xsd_free(s);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/* ---- cta0024: the static base URI is the SCHEMA document's ----------- */
|
|
116
|
+
|
|
117
|
+
TEST(Xsd11BaseUri, Cta0024InstanceIsValid) {
|
|
118
|
+
EXPECT_EQ(validate_files("saxonData/CTA/cta0024.xsd",
|
|
119
|
+
"saxonData/CTA/cta0023.v01.xml"),
|
|
120
|
+
1);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
TEST(Xsd11BaseUri, AStringCompiledSchemaHasNoStaticBaseUri) {
|
|
124
|
+
/* Compiled from memory with no URL, the schema document carries
|
|
125
|
+
* no URI, static-base-uri() is "", and the chain has no true arm
|
|
126
|
+
* — xs:error. The caller's URL (set on the document is not the
|
|
127
|
+
* schema lane's channel; a file compile is) is what the file
|
|
128
|
+
* face supplies. */
|
|
129
|
+
std::string xsd = read_file("saxonData/CTA/cta0024.xsd");
|
|
130
|
+
LeptrisXsdSchema s =
|
|
131
|
+
leptris_xsd_compile(xsd.data(), xsd.size(), nullptr);
|
|
132
|
+
ASSERT_NE(s, nullptr);
|
|
133
|
+
leptris_xsd_set_processor_dialect(s, 1);
|
|
134
|
+
LeptrisDocument d =
|
|
135
|
+
leptris_parse_file(cases("saxonData/CTA/cta0023.v01.xml").c_str(),
|
|
136
|
+
nullptr);
|
|
137
|
+
ASSERT_NE(d, nullptr);
|
|
138
|
+
/* the INSTANCE's URI is not the static base: the schema's is */
|
|
139
|
+
ASSERT_NE(leptris_document_uri(d), nullptr);
|
|
140
|
+
EXPECT_EQ(leptris_xsd_validate(s, d), 0);
|
|
141
|
+
leptris_document_free(d);
|
|
142
|
+
leptris_xsd_free(s);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
} // namespace
|
|
@@ -136,7 +136,7 @@ TEST(XsdConformance11, ManifestExpectationsMatch) {
|
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
fclose(f);
|
|
139
|
-
EXPECT_EQ(total,
|
|
139
|
+
EXPECT_EQ(total, 2211) << "corpus shrank — regenerate the manifest";
|
|
140
140
|
RecordProperty("pass", std::to_string(pass));
|
|
141
141
|
RecordProperty("fail", std::to_string(fail));
|
|
142
142
|
printf(
|
|
@@ -515,10 +515,28 @@ TEST(XsdConformance11, ManifestExpectationsMatch) {
|
|
|
515
515
|
* content-model particle route (id015.n02's <id>p2</id> against
|
|
516
516
|
* fixed="p1"). **2206/2206 — the suite is GREEN**: 1293 valid /
|
|
517
517
|
* 610 invalid / 303 schema-error (measured 2026-11-29 on the
|
|
518
|
-
* 0e91f5a1 base; the 1.0 corpus held 1046/1056 exactly).
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
518
|
+
* 0e91f5a1 base; the 1.0 corpus held 1046/1056 exactly). Raised by
|
|
519
|
+
* #2278 (documents carry a base/document URI: leptris_parse_file
|
|
520
|
+
* records the resolved path, leptris_document_set_uri supplies one
|
|
521
|
+
* for the in-memory shape, fn:base-uri() resolves the xml:base chain
|
|
522
|
+
* over it, fn:document-uri() answers it, and fn:static-base-uri()
|
|
523
|
+
* answers the XQuery prolog's `declare base-uri` — the XSD lane
|
|
524
|
+
* compiles each {test} with the HOST schema document's URI, XSD 1.1
|
|
525
|
+
* §3.13.4.1): the two saxonData/CTA testGroups on
|
|
526
|
+
* version="full-xpath-in-CTA" whose verdicts hinge on the URI are
|
|
527
|
+
* ADOPTED — 5 hand-added manifest rows (the generator's version=1.1
|
|
528
|
+
* selector skips them as testGroup_not_1_1; see the manifest header):
|
|
529
|
+
* cta0021 (byte-identical instances, the verdict decided by the
|
|
530
|
+
* loaded-from path — v01 valid / n01 invalid), cta0024 (its schema
|
|
531
|
+
* row + instanceTest cta0024.v01 loading cta0023.v01.xml, valid —
|
|
532
|
+
* static-base-uri() ends with 'cta0024.xsd'). Red-first on main:
|
|
533
|
+
* cta0021.v01 and cta0024.v01 were false-invalid (2209/2211 with the
|
|
534
|
+
* rows in). **2211/2211 — GREEN**: 1297 valid / 611 invalid / 303
|
|
535
|
+
* schema-error (measured 2026-12-03 on the 2491f8e5 base). Spec
|
|
536
|
+
* tests test/xsd/test_xsd11_base_uri.cpp + test/xpath/test_base_uri.cpp. */
|
|
537
|
+
EXPECT_GE(pass, 2211) << "conformance floor regressed - re-measure the union";
|
|
538
|
+
EXPECT_GE(pass_valid, 1297);
|
|
539
|
+
EXPECT_GE(pass_invalid, 611);
|
|
522
540
|
EXPECT_GE(pass_schema_error, 303);
|
|
523
541
|
RecordProperty("pass_valid", std::to_string(pass_valid));
|
|
524
542
|
RecordProperty("pass_invalid", std::to_string(pass_invalid));
|