leptris 1.9.352.0-arm-linux → 1.9.353.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 +14 -0
- data/Rakefile +1 -1
- data/lib/leptris/version.rb +1 -1
- data/lib/leptris/xml/element.rb +56 -0
- data/lib/leptris/xml/ffi.rb +9 -0
- data/lib/libleptris.so +0 -0
- data/vendor-src/README.md +1 -1
- data/vendor-src/libleptris/CHANGELOG.md +45 -0
- data/vendor-src/libleptris/CMakeLists.txt +1 -1
- data/vendor-src/libleptris/scripts/gen_xsd_manifest.py +88 -0
- data/vendor-src/libleptris/src/include/leptris.h +44 -0
- data/vendor-src/libleptris/src/leptris/dom/element_query.c +100 -0
- data/vendor-src/libleptris/src/leptris/xsd/compile.c +147 -56
- data/vendor-src/libleptris/test/dom/test_dom.cpp +140 -0
- data/vendor-src/libleptris/test/xsd/libxml2-cases/MANIFEST.tsv +1058 -0
- data/vendor-src/libleptris/test/xsd/test_xsd_compile.cpp +91 -4
- data/vendor-src/libleptris/vcpkg.json +1 -1
- metadata +3 -1
|
@@ -454,6 +454,56 @@ static XsdSimple* xsd_capture_simple(LeptrisElement st) {
|
|
|
454
454
|
/* Depth-capped local-base resolution with a cycle guard: the
|
|
455
455
|
* restriction chain walks to its built-in, facets of EVERY hop
|
|
456
456
|
* apply (XSD semantics). */
|
|
457
|
+
/* ---- the reference-resolution chokepoint (the #440 family) --------
|
|
458
|
+
*
|
|
459
|
+
* Every declaration table lookup rides ONE generated ladder instead
|
|
460
|
+
* of a per-table copy of the same three loops. The ladder, in order:
|
|
461
|
+
* 1. exact (declaring targetNamespace, name)
|
|
462
|
+
* 2. unstamped entries (unknown-namespace declarations)
|
|
463
|
+
* 3. name-only across the merged table — ONLY when the policy
|
|
464
|
+
* allows it (allow_name_only)
|
|
465
|
+
* Policy: STRICT (allow_name_only = 0) for compile-side derivation
|
|
466
|
+
* lookups — extension bases and group refs are same-namespace by
|
|
467
|
+
* XSD rules, and a foreign same-name decl must never win
|
|
468
|
+
* (leptris-ruby#440). LADDER (allow_name_only = 1) for instance-
|
|
469
|
+
* side type references — OOXML types wp:/pic: particles with
|
|
470
|
+
* a:-prefixed main-namespace types, and prefix-stripped names
|
|
471
|
+
* legitimately cross namespaces (#1687). */
|
|
472
|
+
#define XSD_DEFINE_NS_LADDER(ret_type, fn_name, list_field, name_field, \
|
|
473
|
+
ns_field) \
|
|
474
|
+
static ret_type fn_name(struct leptris_xsd_schema* s, const char* name, \
|
|
475
|
+
const char* uri, int allow_name_only) { \
|
|
476
|
+
if (!s || !name) \
|
|
477
|
+
return NULL; \
|
|
478
|
+
if (uri && uri[0]) { \
|
|
479
|
+
for (ret_type t = s->list_field; t; t = t->next) \
|
|
480
|
+
if (t->ns_field && strcmp(t->name_field, name) == 0 && \
|
|
481
|
+
strcmp(t->ns_field, uri) == 0) \
|
|
482
|
+
return t; \
|
|
483
|
+
for (ret_type t = s->list_field; t; t = t->next) \
|
|
484
|
+
if (!t->ns_field && strcmp(t->name_field, name) == 0) \
|
|
485
|
+
return t; \
|
|
486
|
+
if (!allow_name_only) \
|
|
487
|
+
return NULL; \
|
|
488
|
+
for (ret_type t = s->list_field; t; t = t->next) \
|
|
489
|
+
if (strcmp(t->name_field, name) == 0) \
|
|
490
|
+
return t; \
|
|
491
|
+
return NULL; \
|
|
492
|
+
} \
|
|
493
|
+
for (ret_type t = s->list_field; t; t = t->next) \
|
|
494
|
+
if (strcmp(t->name_field, name) == 0) \
|
|
495
|
+
return t; \
|
|
496
|
+
return NULL; \
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
XSD_DEFINE_NS_LADDER(const XsdElementDecl*, xsd_ladder_element, elements,
|
|
500
|
+
name, ns)
|
|
501
|
+
XSD_DEFINE_NS_LADDER(XsdCm*, xsd_ladder_complex, complex_types, name, ns)
|
|
502
|
+
XSD_DEFINE_NS_LADDER(const XsdSimple*, xsd_ladder_simple, simple_types,
|
|
503
|
+
name, ns)
|
|
504
|
+
XSD_DEFINE_NS_LADDER(const XsdTypeAttrs*, xsd_ladder_type_attrs,
|
|
505
|
+
type_attrs, type_name, ns)
|
|
506
|
+
|
|
457
507
|
static const XsdSimple* xsd_find_simple(struct leptris_xsd_schema* s,
|
|
458
508
|
const char* name) {
|
|
459
509
|
for (XsdSimple* t = s->simple_types; t; t = t->next)
|
|
@@ -471,19 +521,9 @@ static const XsdSimple* xsd_find_simple(struct leptris_xsd_schema* s,
|
|
|
471
521
|
* name-only match remains the last resort. */
|
|
472
522
|
const XsdSimple* xsd_find_simple_ns_pub(
|
|
473
523
|
struct leptris_xsd_schema* s, const char* name, const char* uri) {
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
if (t->ns && strcmp(t->name, name) == 0 &&
|
|
478
|
-
strcmp(t->ns, uri) == 0)
|
|
479
|
-
return t;
|
|
480
|
-
for (XsdSimple* t = s->simple_types; t; t = t->next)
|
|
481
|
-
if (!t->ns && strcmp(t->name, name) == 0)
|
|
482
|
-
return t;
|
|
483
|
-
/* cross-namespace reference: any spelling of the name */
|
|
484
|
-
return xsd_find_simple(s, name);
|
|
485
|
-
}
|
|
486
|
-
return xsd_find_simple(s, name);
|
|
524
|
+
/* LADDER: prefix-stripped type names legitimately cross
|
|
525
|
+
* namespaces (sharedTypes' ST_TwipsMeasure under a math prefix). */
|
|
526
|
+
return xsd_ladder_simple(s, name, uri, 1);
|
|
487
527
|
}
|
|
488
528
|
|
|
489
529
|
extern int xsd_builtin_valid(const char* type, const char* v);
|
|
@@ -675,6 +715,86 @@ LEPTRIS_API LeptrisXsdSchema leptris_xsd_compile_file(
|
|
|
675
715
|
return s;
|
|
676
716
|
}
|
|
677
717
|
|
|
718
|
+
/* Numeric attribute value (atoi semantics); 1 when it parsed. */
|
|
719
|
+
static int xsd_uint_attr(LeptrisElement e, const char* name, int* out) {
|
|
720
|
+
const char* v = leptris_element_attribute(e, name);
|
|
721
|
+
if (!v || !v[0]) return 0;
|
|
722
|
+
char* end = NULL;
|
|
723
|
+
long n = strtol(v, &end, 10);
|
|
724
|
+
if (end == v || n < 0) return 0;
|
|
725
|
+
*out = (int)n;
|
|
726
|
+
return 1;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
/* Schema-structure constraints (the conformance lane's schema-error
|
|
730
|
+
* class, #1691): the xs:-vocabulary rules the oracle enforces at
|
|
731
|
+
* load. First violation wins; the message names the rule. */
|
|
732
|
+
static int xsd_check_structure(struct leptris_xsd_schema* s,
|
|
733
|
+
LeptrisElement e) {
|
|
734
|
+
if (!e) return 0;
|
|
735
|
+
for (LeptrisNodeRef n = leptris_node_first_child(leptris_element_as_node(e));
|
|
736
|
+
n; n = leptris_node_next_sibling(n)) {
|
|
737
|
+
if (leptris_node_get_type(n) != LEPTRIS_NODE_TYPE_ELEMENT)
|
|
738
|
+
continue;
|
|
739
|
+
LeptrisElement c = (LeptrisElement)n;
|
|
740
|
+
const char* local = NULL;
|
|
741
|
+
const char* prefix = NULL;
|
|
742
|
+
const char* uri = NULL;
|
|
743
|
+
leptris_element_expanded_name(c, &local, &prefix, &uri);
|
|
744
|
+
if (!local || !uri || strcmp(uri, XSD_NS) != 0) {
|
|
745
|
+
/* foreign-namespace content: recurse only */
|
|
746
|
+
if (xsd_check_structure(s, c) != 0) return -1;
|
|
747
|
+
continue;
|
|
748
|
+
}
|
|
749
|
+
if (strcmp(local, "attribute") == 0 ||
|
|
750
|
+
strcmp(local, "element") == 0) {
|
|
751
|
+
const char* nm = leptris_element_attribute(c, "name");
|
|
752
|
+
const char* ref = leptris_element_attribute(c, "ref");
|
|
753
|
+
if ((nm && nm[0]) && (ref && ref[0])) {
|
|
754
|
+
char msg[160];
|
|
755
|
+
snprintf(msg, sizeof(msg),
|
|
756
|
+
"src-attribute.1: xs:%s cannot carry both "
|
|
757
|
+
"'name' and 'ref'",
|
|
758
|
+
local);
|
|
759
|
+
xsd_set_error(s, msg);
|
|
760
|
+
return -1;
|
|
761
|
+
}
|
|
762
|
+
if ((!nm || !nm[0]) && (!ref || !ref[0])) {
|
|
763
|
+
char msg[160];
|
|
764
|
+
snprintf(msg, sizeof(msg),
|
|
765
|
+
"src-attribute.1: xs:%s requires 'name' or "
|
|
766
|
+
"'ref'",
|
|
767
|
+
local);
|
|
768
|
+
xsd_set_error(s, msg);
|
|
769
|
+
return -1;
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
if (strcmp(local, "element") == 0 ||
|
|
773
|
+
strcmp(local, "sequence") == 0 ||
|
|
774
|
+
strcmp(local, "choice") == 0 ||
|
|
775
|
+
strcmp(local, "all") == 0) {
|
|
776
|
+
int mn = -1, mx = -1;
|
|
777
|
+
int has_mn = xsd_uint_attr(c, "minOccurs", &mn);
|
|
778
|
+
int has_mx = xsd_uint_attr(c, "maxOccurs", &mx);
|
|
779
|
+
const char* mx_raw =
|
|
780
|
+
leptris_element_attribute(c, "maxOccurs");
|
|
781
|
+
int unbounded =
|
|
782
|
+
(mx_raw && strcmp(mx_raw, "unbounded") == 0);
|
|
783
|
+
if (has_mn && has_mx && !unbounded && mn > mx) {
|
|
784
|
+
char msg[160];
|
|
785
|
+
snprintf(msg, sizeof(msg),
|
|
786
|
+
"occurrence: xs:%s minOccurs (%d) exceeds "
|
|
787
|
+
"maxOccurs (%d)",
|
|
788
|
+
local, mn, mx);
|
|
789
|
+
xsd_set_error(s, msg);
|
|
790
|
+
return -1;
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
if (xsd_check_structure(s, c) != 0) return -1;
|
|
794
|
+
}
|
|
795
|
+
return 0;
|
|
796
|
+
}
|
|
797
|
+
|
|
678
798
|
static LeptrisXsdSchema xsd_compile_impl(const char* xsd_text,
|
|
679
799
|
size_t len,
|
|
680
800
|
const char* base_dir,
|
|
@@ -727,6 +847,13 @@ static LeptrisXsdSchema xsd_compile_impl(const char* xsd_text,
|
|
|
727
847
|
goto fail;
|
|
728
848
|
}
|
|
729
849
|
|
|
850
|
+
/* Schema-structure constraints (#1691 schema-error class):
|
|
851
|
+
* required/allowed attributes on the xs: vocabulary and
|
|
852
|
+
* occurrence ordering, checked at the document level exactly
|
|
853
|
+
* where the oracle raises them — before capture. */
|
|
854
|
+
if (xsd_check_structure(s, root) != 0)
|
|
855
|
+
goto fail;
|
|
856
|
+
|
|
730
857
|
xsd_capture_root(s, root);
|
|
731
858
|
xsd_resolve_extension_bases(s);
|
|
732
859
|
|
|
@@ -1993,18 +2120,7 @@ const XsdElementDecl* xsd_find_element(struct leptris_xsd_schema* s,
|
|
|
1993
2120
|
/* leptris-ruby#440: prefer (ns, name); fall back to any match. */
|
|
1994
2121
|
const XsdElementDecl* xsd_find_element_ns(
|
|
1995
2122
|
struct leptris_xsd_schema* s, const char* name, const char* uri) {
|
|
1996
|
-
|
|
1997
|
-
if (uri && uri[0]) {
|
|
1998
|
-
for (XsdElementDecl* d = s->elements; d; d = d->next)
|
|
1999
|
-
if (d->ns && strcmp(d->name, name) == 0 &&
|
|
2000
|
-
strcmp(d->ns, uri) == 0)
|
|
2001
|
-
return d;
|
|
2002
|
-
for (XsdElementDecl* d = s->elements; d; d = d->next)
|
|
2003
|
-
if (!d->ns && strcmp(d->name, name) == 0)
|
|
2004
|
-
return d;
|
|
2005
|
-
return NULL;
|
|
2006
|
-
}
|
|
2007
|
-
return xsd_find_element(s, name);
|
|
2123
|
+
return xsd_ladder_element(s, name, uri, 0);
|
|
2008
2124
|
}
|
|
2009
2125
|
|
|
2010
2126
|
XsdCm* xsd_find_complex(struct leptris_xsd_schema* s,
|
|
@@ -2021,22 +2137,8 @@ XsdCm* xsd_find_complex(struct leptris_xsd_schema* s,
|
|
|
2021
2137
|
* and unresolvable contexts keep working). */
|
|
2022
2138
|
XsdCm* xsd_find_complex_ns(struct leptris_xsd_schema* s,
|
|
2023
2139
|
const char* type_name, const char* uri) {
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
for (XsdCm* c = s->complex_types; c; c = c->next)
|
|
2027
|
-
if (c->ns && strcmp(c->name, type_name) == 0 &&
|
|
2028
|
-
strcmp(c->ns, uri) == 0)
|
|
2029
|
-
return c;
|
|
2030
|
-
/* A resolving namespace is in hand: a DIFFERENT
|
|
2031
|
-
* namespace's same-name decl must NOT win (wml CT_TcPr vs
|
|
2032
|
-
* dml CT_TcPr — leptris-ruby#440). Only an unstamped
|
|
2033
|
-
* (unknown-ns) entry may serve as the fallback. */
|
|
2034
|
-
for (XsdCm* c = s->complex_types; c; c = c->next)
|
|
2035
|
-
if (!c->ns && strcmp(c->name, type_name) == 0)
|
|
2036
|
-
return c;
|
|
2037
|
-
return NULL;
|
|
2038
|
-
}
|
|
2039
|
-
return xsd_find_complex(s, type_name);
|
|
2140
|
+
/* STRICT: derivation is same-namespace by XSD rules. */
|
|
2141
|
+
return xsd_ladder_complex(s, type_name, uri, 0);
|
|
2040
2142
|
}
|
|
2041
2143
|
|
|
2042
2144
|
/* leptris-ruby#440 (follow-up): a TYPE REFERENCE on an instance
|
|
@@ -2053,9 +2155,9 @@ XsdCm* xsd_find_complex_ns(struct leptris_xsd_schema* s,
|
|
|
2053
2155
|
* same-namespace by XSD rules. */
|
|
2054
2156
|
XsdCm* xsd_find_complex_ref(struct leptris_xsd_schema* s,
|
|
2055
2157
|
const char* type_name, const char* uri) {
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
return
|
|
2158
|
+
/* LADDER: instance-side type references cross namespaces
|
|
2159
|
+
* (wp:extent -> a:CT_PositiveSize2D — #1687). */
|
|
2160
|
+
return xsd_ladder_complex(s, type_name, uri, 1);
|
|
2059
2161
|
}
|
|
2060
2162
|
|
|
2061
2163
|
const XsdSimple* xsd_find_simple_pub(struct leptris_xsd_schema* s,
|
|
@@ -2078,18 +2180,7 @@ const XsdTypeAttrs* xsd_find_type_attrs(struct leptris_xsd_schema* s,
|
|
|
2078
2180
|
const XsdTypeAttrs* xsd_find_type_attrs_ns(
|
|
2079
2181
|
struct leptris_xsd_schema* s, const char* type_name,
|
|
2080
2182
|
const char* uri) {
|
|
2081
|
-
|
|
2082
|
-
if (uri && uri[0]) {
|
|
2083
|
-
for (XsdTypeAttrs* t = s->type_attrs; t; t = t->next)
|
|
2084
|
-
if (t->ns && strcmp(t->type_name, type_name) == 0 &&
|
|
2085
|
-
strcmp(t->ns, uri) == 0)
|
|
2086
|
-
return t;
|
|
2087
|
-
for (XsdTypeAttrs* t = s->type_attrs; t; t = t->next)
|
|
2088
|
-
if (!t->ns && strcmp(t->type_name, type_name) == 0)
|
|
2089
|
-
return t;
|
|
2090
|
-
return NULL;
|
|
2091
|
-
}
|
|
2092
|
-
return xsd_find_type_attrs(s, type_name);
|
|
2183
|
+
return xsd_ladder_type_attrs(s, type_name, uri, 0);
|
|
2093
2184
|
}
|
|
2094
2185
|
|
|
2095
2186
|
/* ---- slice 4: instance validation (validate.c engine) ------------ */
|
|
@@ -3101,3 +3101,143 @@ TEST(DomAbsorbSurvival, CopyAttachSurvivesSourceFree) {
|
|
|
3101
3101
|
ReadAllViews(droot);
|
|
3102
3102
|
leptris_document_free(dst);
|
|
3103
3103
|
}
|
|
3104
|
+
|
|
3105
|
+
/* ---- #1689: element-attribute batch face ------------------------- */
|
|
3106
|
+
|
|
3107
|
+
#ifndef _WIN32
|
|
3108
|
+
#include <vector>
|
|
3109
|
+
#endif
|
|
3110
|
+
|
|
3111
|
+
/* One crossing per element: names, values, and the ns lanes come
|
|
3112
|
+
* back in parallel NUL-terminated entries sized by the two-phase
|
|
3113
|
+
* contract (the #1670 plan-value template, element face). */
|
|
3114
|
+
TEST(DomBasics, AttributesSnapshotOneCrossingPerElement) {
|
|
3115
|
+
const char xml[] =
|
|
3116
|
+
"<e a='1' b='two' ns:p='3' xmlns:ns='urn:n'/>";
|
|
3117
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
3118
|
+
LeptrisDocument doc = leptris_parse_string(xml, std::strlen(xml), &st);
|
|
3119
|
+
ASSERT_NE(doc, nullptr);
|
|
3120
|
+
LeptrisElement root = leptris_document_root(doc);
|
|
3121
|
+
ASSERT_NE(root, nullptr);
|
|
3122
|
+
ASSERT_EQ(leptris_element_attribute_count(root), 3u);
|
|
3123
|
+
|
|
3124
|
+
/* Sizing call: all blobs NULL -> required per-lane capacity. */
|
|
3125
|
+
size_t need = leptris_element_attributes_snapshot(
|
|
3126
|
+
root, NULL, 0, NULL, NULL, 0, NULL, NULL, 0, NULL, NULL, 0, NULL);
|
|
3127
|
+
EXPECT_GT(need, 0u);
|
|
3128
|
+
|
|
3129
|
+
std::vector<char> names(need), values(need), prefs(need), uris(need);
|
|
3130
|
+
std::vector<size_t> no(4), vo(4), po(4), uo(4);
|
|
3131
|
+
ASSERT_EQ(leptris_element_attributes_snapshot(
|
|
3132
|
+
root, names.data(), need, no.data(), values.data(), need,
|
|
3133
|
+
vo.data(), prefs.data(), need, po.data(), uris.data(),
|
|
3134
|
+
need, uo.data()),
|
|
3135
|
+
0u)
|
|
3136
|
+
<< "snapshot failed at capacity " << need;
|
|
3137
|
+
|
|
3138
|
+
for (size_t i = 0; i < 3; i++) {
|
|
3139
|
+
const char* name = names.data() + no[i];
|
|
3140
|
+
const char* value = values.data() + vo[i];
|
|
3141
|
+
EXPECT_STREQ(value, leptris_element_attribute(root, name))
|
|
3142
|
+
<< "value mismatch for " << name;
|
|
3143
|
+
}
|
|
3144
|
+
|
|
3145
|
+
/* No-namespace attributes mark their ns-lane entries SIZE_MAX;
|
|
3146
|
+
* ns:p carries prefix ns resolved to urn:n. */
|
|
3147
|
+
for (size_t i = 0; i < 3; i++) {
|
|
3148
|
+
const char* name = names.data() + no[i];
|
|
3149
|
+
if (std::strcmp(name, "ns:p") == 0) {
|
|
3150
|
+
EXPECT_STREQ(prefs.data() + po[i], "ns");
|
|
3151
|
+
EXPECT_STREQ(uris.data() + uo[i], "urn:n");
|
|
3152
|
+
} else {
|
|
3153
|
+
EXPECT_EQ(po[i], (size_t)-1);
|
|
3154
|
+
EXPECT_EQ(uo[i], (size_t)-1);
|
|
3155
|
+
}
|
|
3156
|
+
}
|
|
3157
|
+
/* Totals ride the +1 offset slots: the total is the last
|
|
3158
|
+
* entry's offset + its length + 1 (the NUL). */
|
|
3159
|
+
EXPECT_EQ(no[3], no[2] + strlen(names.data() + no[2]) + 1);
|
|
3160
|
+
EXPECT_EQ(vo[3], vo[2] + strlen(values.data() + vo[2]) + 1);
|
|
3161
|
+
|
|
3162
|
+
leptris_document_free(doc);
|
|
3163
|
+
}
|
|
3164
|
+
|
|
3165
|
+
TEST(DomBasics, AttributesSnapshotTooSmallLaneRetries) {
|
|
3166
|
+
const char xml[] = "<e alpha='1111111111' beta='2222222222'/>";
|
|
3167
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
3168
|
+
LeptrisDocument doc = leptris_parse_string(xml, std::strlen(xml), &st);
|
|
3169
|
+
ASSERT_NE(doc, nullptr);
|
|
3170
|
+
LeptrisElement root = leptris_document_root(doc);
|
|
3171
|
+
ASSERT_NE(root, nullptr);
|
|
3172
|
+
|
|
3173
|
+
size_t need = leptris_element_attributes_snapshot(
|
|
3174
|
+
root, NULL, 0, NULL, NULL, 0, NULL, NULL, 0, NULL, NULL, 0, NULL);
|
|
3175
|
+
EXPECT_GT(need, 0u);
|
|
3176
|
+
|
|
3177
|
+
std::vector<char> names(4), values(need);
|
|
3178
|
+
std::vector<size_t> no(3), vo(3);
|
|
3179
|
+
EXPECT_EQ(leptris_element_attributes_snapshot(
|
|
3180
|
+
root, names.data(), names.size(), no.data(),
|
|
3181
|
+
values.data(), need, vo.data(), NULL, 0, NULL, NULL, 0,
|
|
3182
|
+
NULL),
|
|
3183
|
+
(size_t)-1);
|
|
3184
|
+
|
|
3185
|
+
names.resize(need);
|
|
3186
|
+
EXPECT_EQ(leptris_element_attributes_snapshot(
|
|
3187
|
+
root, names.data(), need, no.data(), values.data(), need,
|
|
3188
|
+
vo.data(), NULL, 0, NULL, NULL, 0, NULL),
|
|
3189
|
+
0u);
|
|
3190
|
+
|
|
3191
|
+
leptris_document_free(doc);
|
|
3192
|
+
}
|
|
3193
|
+
|
|
3194
|
+
TEST(DomBasics, AttributesSnapshotNullNsLanesSkip) {
|
|
3195
|
+
const char xml[] = "<e ns:x='1' xmlns:ns='urn:n'/>";
|
|
3196
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
3197
|
+
LeptrisDocument doc = leptris_parse_string(xml, std::strlen(xml), &st);
|
|
3198
|
+
ASSERT_NE(doc, nullptr);
|
|
3199
|
+
LeptrisElement root = leptris_document_root(doc);
|
|
3200
|
+
ASSERT_NE(root, nullptr);
|
|
3201
|
+
|
|
3202
|
+
size_t need = leptris_element_attributes_snapshot(
|
|
3203
|
+
root, NULL, 0, NULL, NULL, 0, NULL, NULL, 0, NULL, NULL, 0, NULL);
|
|
3204
|
+
std::vector<char> names(need), values(need);
|
|
3205
|
+
std::vector<size_t> no(2), vo(2);
|
|
3206
|
+
EXPECT_EQ(leptris_element_attributes_snapshot(
|
|
3207
|
+
root, names.data(), need, no.data(), values.data(), need,
|
|
3208
|
+
vo.data(), NULL, 0, NULL, NULL, 0, NULL),
|
|
3209
|
+
0u);
|
|
3210
|
+
EXPECT_STREQ(names.data() + no[0], "ns:x");
|
|
3211
|
+
EXPECT_STREQ(values.data() + vo[0], "1");
|
|
3212
|
+
|
|
3213
|
+
leptris_document_free(doc);
|
|
3214
|
+
}
|
|
3215
|
+
|
|
3216
|
+
TEST(DomBasics, AttributesSnapshotEmptyAndNullContracts) {
|
|
3217
|
+
const char xml[] = "<e/>";
|
|
3218
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
3219
|
+
LeptrisDocument doc = leptris_parse_string(xml, std::strlen(xml), &st);
|
|
3220
|
+
ASSERT_NE(doc, nullptr);
|
|
3221
|
+
LeptrisElement root = leptris_document_root(doc);
|
|
3222
|
+
ASSERT_NE(root, nullptr);
|
|
3223
|
+
|
|
3224
|
+
EXPECT_EQ(leptris_element_attributes_snapshot(
|
|
3225
|
+
root, NULL, 0, NULL, NULL, 0, NULL, NULL, 0, NULL, NULL,
|
|
3226
|
+
0, NULL),
|
|
3227
|
+
0u);
|
|
3228
|
+
char blob[16] = {0};
|
|
3229
|
+
size_t off[1] = {7};
|
|
3230
|
+
EXPECT_EQ(leptris_element_attributes_snapshot(
|
|
3231
|
+
root, blob, sizeof(blob), off, blob, sizeof(blob), off,
|
|
3232
|
+
NULL, 0, NULL, NULL, 0, NULL),
|
|
3233
|
+
0u);
|
|
3234
|
+
/* count == 0: the only offset slot is the total, and it is 0. */
|
|
3235
|
+
EXPECT_EQ(off[0], 0u);
|
|
3236
|
+
|
|
3237
|
+
EXPECT_EQ(leptris_element_attributes_snapshot(
|
|
3238
|
+
NULL, NULL, 0, NULL, NULL, 0, NULL, NULL, 0, NULL, NULL,
|
|
3239
|
+
0, NULL),
|
|
3240
|
+
0u);
|
|
3241
|
+
|
|
3242
|
+
leptris_document_free(doc);
|
|
3243
|
+
}
|