leptris 1.9.324.0-arm-linux → 1.9.331.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.
@@ -130,11 +130,10 @@ TEST(XsdCompile, NullTolerant) {
130
130
  TEST(Libxml2Corpus, EveryFixtureCompilesOrFailsCleanly) {
131
131
  size_t ok = 0, failed = 0;
132
132
  for (const std::string& path : fixture_dir(".")) {
133
- std::string text = slurp(path.c_str());
134
- ASSERT_FALSE(text.empty()) << path;
135
133
  LeptrisStatus st = (LeptrisStatus)0;
136
- LeptrisXsdSchema s =
137
- leptris_xsd_compile(text.data(), text.size(), &st);
134
+ /* compile_file: xs:include/xs:import schemaLocations
135
+ * resolve against the fixture's own directory */
136
+ LeptrisXsdSchema s = leptris_xsd_compile_file(path.c_str(), &st);
138
137
  ASSERT_NE(s, (LeptrisXsdSchema)0) << path;
139
138
  if (st == LEPTRIS_OK)
140
139
  ok++;
@@ -724,3 +723,399 @@ TEST(XsdIc, KeyRequiresFieldValues) {
724
723
  }
725
724
 
726
725
  } // namespace
726
+
727
+ // ---- local particle declarations -----------------------------------
728
+ namespace {
729
+
730
+ /* item is declared ONLY as a particle of orderT — no global
731
+ * xs:element named item exists — so its attributes and children
732
+ * must validate against itemT's rows through the particle's type. */
733
+ const char* k_local_schema =
734
+ "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
735
+ "<xs:complexType name=\"itemT\">"
736
+ "<xs:sequence>"
737
+ "<xs:element name=\"sku\" type=\"xs:token\"/>"
738
+ "<xs:element name=\"qty\" type=\"xs:integer\"/>"
739
+ "</xs:sequence>"
740
+ "<xs:attribute name=\"id\" type=\"xs:integer\" use=\"required\"/>"
741
+ "</xs:complexType>"
742
+ "<xs:complexType name=\"orderT\">"
743
+ "<xs:sequence>"
744
+ "<xs:element name=\"item\" type=\"itemT\" maxOccurs=\"unbounded\"/>"
745
+ "</xs:sequence>"
746
+ "<xs:attribute name=\"ref\" type=\"xs:string\"/>"
747
+ "</xs:complexType>"
748
+ "<xs:element name=\"order\" type=\"orderT\"/>"
749
+ "</xs:schema>";
750
+
751
+ TEST(XsdLocal, LocalChildAttributesValidate) {
752
+ EXPECT_EQ(validate_doc(k_local_schema,
753
+ "<order><item id=\"5\"><sku>a</sku>"
754
+ "<qty>2</qty></item></order>"), 1);
755
+ EXPECT_EQ(validate_doc(k_local_schema,
756
+ "<order><item id=\"nan\"><sku>a</sku>"
757
+ "<qty>2</qty></item></order>"), 0);
758
+ EXPECT_EQ(validate_doc(k_local_schema,
759
+ "<order><item><sku>a</sku>"
760
+ "<qty>2</qty></item></order>"), 0);
761
+ }
762
+
763
+ TEST(XsdLocal, LocalChildContentModelValidates) {
764
+ EXPECT_EQ(validate_doc(k_local_schema,
765
+ "<order><item id=\"5\"><qty>2</qty>"
766
+ "<sku>a</sku></item></order>"), 0);
767
+ EXPECT_EQ(validate_doc(k_local_schema,
768
+ "<order><item id=\"5\"><sku>a</sku>"
769
+ "<qty>nan</qty></item></order>"), 0);
770
+ }
771
+
772
+ } // namespace
773
+
774
+ // ---- tier-1 charter: union / list simple-type derivation -----------
775
+ namespace {
776
+
777
+ const char* k_ul_schema =
778
+ "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
779
+ "<xs:simpleType name=\"ints\">"
780
+ "<xs:list itemType=\"xs:integer\"/>"
781
+ "</xs:simpleType>"
782
+ "<xs:simpleType name=\"alpha\">"
783
+ "<xs:restriction base=\"xs:string\">"
784
+ "<xs:pattern value=\"[a-z]+\"/>"
785
+ "</xs:restriction>"
786
+ "</xs:simpleType>"
787
+ "<xs:simpleType name=\"code\">"
788
+ "<xs:union memberTypes=\"xs:integer alpha\"/>"
789
+ "</xs:simpleType>"
790
+ "<xs:element name=\"vals\" type=\"ints\"/>"
791
+ "<xs:element name=\"c\" type=\"code\"/>"
792
+ "</xs:schema>";
793
+
794
+ TEST(XsdDatatypes, ListDerivationValidatesEveryItem) {
795
+ LeptrisStatus st = LEPTRIS_OK;
796
+ LeptrisXsdSchema s =
797
+ leptris_xsd_compile(k_ul_schema, strlen(k_ul_schema), &st);
798
+ ASSERT_NE(s, (LeptrisXsdSchema)0);
799
+ EXPECT_EQ(leptris_xsd_simple_valid(s, "ints", "1 2 3"), 1);
800
+ EXPECT_EQ(leptris_xsd_simple_valid(s, "ints", "1 x 3"), 0);
801
+ leptris_xsd_free(s);
802
+ }
803
+
804
+ TEST(XsdDatatypes, UnionDerivationAcceptsAnyMember) {
805
+ LeptrisStatus st = LEPTRIS_OK;
806
+ LeptrisXsdSchema s =
807
+ leptris_xsd_compile(k_ul_schema, strlen(k_ul_schema), &st);
808
+ ASSERT_NE(s, (LeptrisXsdSchema)0);
809
+ EXPECT_EQ(leptris_xsd_simple_valid(s, "code", "42"), 1);
810
+ EXPECT_EQ(leptris_xsd_simple_valid(s, "code", "abc"), 1);
811
+ EXPECT_EQ(leptris_xsd_simple_valid(s, "code", "42x"), 0);
812
+ leptris_xsd_free(s);
813
+ }
814
+
815
+ TEST(XsdValidate, UnionAndListValidateInDocuments) {
816
+ EXPECT_EQ(validate_doc(k_ul_schema, "<vals>1 2 3</vals>"), 1);
817
+ EXPECT_EQ(validate_doc(k_ul_schema, "<vals>1 x</vals>"), 0);
818
+ EXPECT_EQ(validate_doc(k_ul_schema, "<c>abc</c>"), 1);
819
+ EXPECT_EQ(validate_doc(k_ul_schema, "<c>99</c>"), 1);
820
+ EXPECT_EQ(validate_doc(k_ul_schema, "<c>1.5</c>"), 0);
821
+ }
822
+
823
+ /* inline anonymous union member (no memberTypes for it) */
824
+ TEST(XsdDatatypes, UnionInlineAnonymousMember) {
825
+ const char* x =
826
+ "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
827
+ "<xs:simpleType name=\"combo\">"
828
+ "<xs:union memberTypes=\"xs:integer\">"
829
+ "<xs:simpleType><xs:restriction base=\"xs:string\">"
830
+ "<xs:enumeration value=\"yes\"/>"
831
+ "<xs:enumeration value=\"no\"/>"
832
+ "</xs:restriction></xs:simpleType>"
833
+ "</xs:union>"
834
+ "</xs:simpleType>"
835
+ "<xs:element name=\"q\" type=\"combo\"/>"
836
+ "</xs:schema>";
837
+ EXPECT_EQ(validate_doc(x, "<q>3</q>"), 1);
838
+ EXPECT_EQ(validate_doc(x, "<q>yes</q>"), 1);
839
+ EXPECT_EQ(validate_doc(x, "<q>maybe</q>"), 0);
840
+ }
841
+
842
+
843
+ } // namespace
844
+
845
+ // ---- tier-1 charter: named groups + attribute groups + attr refs --
846
+ namespace {
847
+
848
+ const char* k_grp_schema =
849
+ "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
850
+ "<xs:group name=\"meta\">"
851
+ "<xs:sequence>"
852
+ "<xs:element name=\"title\" type=\"xs:token\"/>"
853
+ "<xs:element name=\"date\" type=\"xs:date\"/>"
854
+ "</xs:sequence>"
855
+ "</xs:group>"
856
+ "<xs:attribute name=\"rev\" type=\"xs:integer\"/>"
857
+ "<xs:attributeGroup name=\"common\">"
858
+ "<xs:attribute name=\"id\" type=\"xs:integer\" use=\"required\"/>"
859
+ "<xs:attribute name=\"lang\" type=\"xs:string\"/>"
860
+ "</xs:attributeGroup>"
861
+ "<xs:complexType name=\"docT\">"
862
+ "<xs:sequence>"
863
+ "<xs:group ref=\"meta\"/>"
864
+ "<xs:element name=\"body\" type=\"xs:string\"/>"
865
+ "</xs:sequence>"
866
+ "<xs:attributeGroup ref=\"common\"/>"
867
+ "<xs:attribute ref=\"rev\"/>"
868
+ "</xs:complexType>"
869
+ "<xs:element name=\"doc\" type=\"docT\"/>"
870
+ "</xs:schema>";
871
+
872
+ TEST(XsdContent, NamedModelGroupSplices) {
873
+ EXPECT_EQ(validate_doc(k_grp_schema,
874
+ "<doc id=\"1\" lang=\"en\" rev=\"2\">"
875
+ "<title>t</title><date>2026-01-01</date>"
876
+ "<body>b</body></doc>"), 1);
877
+ /* body before the spliced group content */
878
+ EXPECT_EQ(validate_doc(k_grp_schema,
879
+ "<doc id=\"1\"><body>b</body>"
880
+ "<title>t</title><date>2026-01-01</date>"
881
+ "</doc>"), 0);
882
+ /* missing a group member */
883
+ EXPECT_EQ(validate_doc(k_grp_schema,
884
+ "<doc id=\"1\"><title>t</title>"
885
+ "<body>b</body></doc>"), 0);
886
+ /* group member text types ride the splice */
887
+ EXPECT_EQ(validate_doc(k_grp_schema,
888
+ "<doc id=\"1\"><title>t</title>"
889
+ "<date>not-a-date</date><body>b</body>"
890
+ "</doc>"), 0);
891
+ }
892
+
893
+ TEST(XsdValidate, AttributeGroupRowsApply) {
894
+ EXPECT_EQ(validate_doc(k_grp_schema,
895
+ "<doc><title>t</title>"
896
+ "<date>2026-01-01</date><body>b</body></doc>"), 0);
897
+ EXPECT_EQ(validate_doc(k_grp_schema,
898
+ "<doc id=\"x\"><title>t</title>"
899
+ "<date>2026-01-01</date><body>b</body></doc>"),
900
+ 0);
901
+ /* the referenced top-level attribute enforces its type */
902
+ EXPECT_EQ(validate_doc(k_grp_schema,
903
+ "<doc id=\"1\" rev=\"x\"><title>t</title>"
904
+ "<date>2026-01-01</date><body>b</body></doc>"),
905
+ 0);
906
+ }
907
+
908
+ } // namespace
909
+
910
+ // ---- tier-1 charter: complexContent / simpleContent derivation -----
911
+ namespace {
912
+
913
+ const char* k_deriv_schema =
914
+ "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
915
+ "<xs:complexType name=\"baseT\">"
916
+ "<xs:sequence>"
917
+ "<xs:element name=\"a\" type=\"xs:token\"/>"
918
+ "<xs:element name=\"b\" type=\"xs:token\"/>"
919
+ "</xs:sequence>"
920
+ "<xs:attribute name=\"x\" type=\"xs:integer\"/>"
921
+ "</xs:complexType>"
922
+ "<xs:complexType name=\"extT\">"
923
+ "<xs:complexContent>"
924
+ "<xs:extension base=\"baseT\">"
925
+ "<xs:sequence>"
926
+ "<xs:element name=\"c\" type=\"xs:integer\"/>"
927
+ "</xs:sequence>"
928
+ "<xs:attribute name=\"y\" type=\"xs:string\"/>"
929
+ "</xs:extension>"
930
+ "</xs:complexContent>"
931
+ "</xs:complexType>"
932
+ "<xs:complexType name=\"rstrT\">"
933
+ "<xs:complexContent>"
934
+ "<xs:restriction base=\"baseT\">"
935
+ "<xs:sequence>"
936
+ "<xs:element name=\"a\" type=\"xs:token\"/>"
937
+ "</xs:sequence>"
938
+ "</xs:restriction>"
939
+ "</xs:complexContent>"
940
+ "</xs:complexType>"
941
+ "<xs:complexType name=\"labelT\">"
942
+ "<xs:simpleContent>"
943
+ "<xs:extension base=\"xs:string\">"
944
+ "<xs:attribute name=\"lang\" type=\"xs:string\" use=\"required\"/>"
945
+ "</xs:extension>"
946
+ "</xs:simpleContent>"
947
+ "</xs:complexType>"
948
+ "<xs:element name=\"e\" type=\"extT\"/>"
949
+ "<xs:element name=\"r\" type=\"rstrT\"/>"
950
+ "<xs:element name=\"l\" type=\"labelT\"/>"
951
+ "</xs:schema>";
952
+
953
+ TEST(XsdValidate, ExtensionSplicesBaseContentAndAttrs) {
954
+ EXPECT_EQ(validate_doc(k_deriv_schema,
955
+ "<e x=\"1\" y=\"s\"><a>t</a><b>u</b>"
956
+ "<c>3</c></e>"), 1);
957
+ /* base child still required after extension */
958
+ EXPECT_EQ(validate_doc(k_deriv_schema,
959
+ "<e x=\"1\" y=\"s\"><a>t</a>"
960
+ "<c>3</c></e>"), 0);
961
+ /* derived child appends after the base sequence */
962
+ EXPECT_EQ(validate_doc(k_deriv_schema,
963
+ "<e x=\"1\" y=\"s\"><c>3</c><a>t</a>"
964
+ "<b>u</b></e>"), 0);
965
+ /* base attribute rows ride the derivation */
966
+ EXPECT_EQ(validate_doc(k_deriv_schema,
967
+ "<e x=\"z\" y=\"s\"><a>t</a><b>u</b>"
968
+ "<c>3</c></e>"), 0);
969
+ /* derived-only attribute optional */
970
+ EXPECT_EQ(validate_doc(k_deriv_schema,
971
+ "<e x=\"1\"><a>t</a><b>u</b>"
972
+ "<c>3</c></e>"), 1);
973
+ }
974
+
975
+ TEST(XsdValidate, RestrictionReplacesContentModel) {
976
+ EXPECT_EQ(validate_doc(k_deriv_schema,
977
+ "<r x=\"1\"><a>t</a></r>"), 1);
978
+ /* the restricted-away child is no longer allowed */
979
+ EXPECT_EQ(validate_doc(k_deriv_schema,
980
+ "<r x=\"1\"><a>t</a><b>u</b></r>"), 0);
981
+ }
982
+
983
+ TEST(XsdValidate, SimpleContentTextAndAttrs) {
984
+ EXPECT_EQ(validate_doc(k_deriv_schema,
985
+ "<l lang=\"en\">hello</l>"), 1);
986
+ EXPECT_EQ(validate_doc(k_deriv_schema,
987
+ "<l>hello</l>"), 0);
988
+ EXPECT_EQ(validate_doc(k_deriv_schema,
989
+ "<l lang=\"en\">42</l>"), 1);
990
+ }
991
+
992
+ } // namespace
993
+
994
+
995
+ // ---- tier-1 charter: fixed/default + substitutionGroup -------------
996
+ namespace {
997
+
998
+ const char* k_fd_schema =
999
+ "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
1000
+ "<xs:complexType name=\"orderT\">"
1001
+ "<xs:sequence>"
1002
+ "<xs:element name=\"item\" type=\"xs:token\"/>"
1003
+ "</xs:sequence>"
1004
+ "<xs:attribute name=\"country\" type=\"xs:string\" fixed=\"US\"/>"
1005
+ "<xs:attribute name=\"prio\" type=\"xs:integer\" default=\"2\"/>"
1006
+ "</xs:complexType>"
1007
+ "<xs:element name=\"order\" type=\"orderT\"/>"
1008
+ "<xs:element name=\"ship\" type=\"xs:string\" fixed=\"air\"/>"
1009
+ "</xs:schema>";
1010
+
1011
+ TEST(XsdValidate, FixedAttributeValueEnforced) {
1012
+ EXPECT_EQ(validate_doc(k_fd_schema,
1013
+ "<order country=\"US\"><item>x</item>"
1014
+ "</order>"), 1);
1015
+ EXPECT_EQ(validate_doc(k_fd_schema,
1016
+ "<order country=\"US\" prio=\"7\">"
1017
+ "<item>x</item></order>"), 1);
1018
+ EXPECT_EQ(validate_doc(k_fd_schema,
1019
+ "<order country=\"DE\"><item>x</item>"
1020
+ "</order>"), 0);
1021
+ EXPECT_EQ(validate_doc(k_fd_schema,
1022
+ "<order><item>x</item></order>"), 1);
1023
+ }
1024
+
1025
+ TEST(XsdValidate, FixedElementTextEnforced) {
1026
+ EXPECT_EQ(validate_doc(k_fd_schema, "<ship>air</ship>"), 1);
1027
+ EXPECT_EQ(validate_doc(k_fd_schema, "<ship>sea</ship>"), 0);
1028
+ }
1029
+
1030
+ const char* k_subst_schema =
1031
+ "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
1032
+ "<xs:complexType name=\"boxT\">"
1033
+ "<xs:sequence>"
1034
+ "<xs:element name=\"head\" type=\"xs:token\"/>"
1035
+ "</xs:sequence>"
1036
+ "</xs:complexType>"
1037
+ "<xs:element name=\"head\" type=\"xs:token\"/>"
1038
+ "<xs:element name=\"alt\" type=\"xs:token\" substitutionGroup=\"head\"/>"
1039
+ "<xs:element name=\"box\" type=\"boxT\"/>"
1040
+ "</xs:schema>";
1041
+
1042
+ TEST(XsdValidate, SubstitutionGroupMembersBind) {
1043
+ EXPECT_EQ(validate_doc(k_subst_schema,
1044
+ "<box><head>x</head></box>"), 1);
1045
+ EXPECT_EQ(validate_doc(k_subst_schema,
1046
+ "<box><alt>y</alt></box>"), 1);
1047
+ EXPECT_EQ(validate_doc(k_subst_schema,
1048
+ "<box><other>z</other></box>"), 0);
1049
+ }
1050
+
1051
+ } // namespace
1052
+
1053
+ // ---- tier-1 charter: include/import via compile_file ---------------
1054
+ namespace {
1055
+
1056
+ TEST(XsdCompileFile, IncludeResolvesRelativeSchemaLocation) {
1057
+ std::string dir = ::testing::TempDir();
1058
+ std::string common = dir + "xsdcommon.xsd";
1059
+ std::string main = dir + "xsdmain.xsd";
1060
+ FILE* f1 = fopen(common.c_str(), "wb");
1061
+ ASSERT_NE(f1, nullptr);
1062
+ const char* common_text =
1063
+ "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
1064
+ "<xs:complexType name=\"itemT\">"
1065
+ "<xs:sequence>"
1066
+ "<xs:element name=\"sku\" type=\"xs:token\"/>"
1067
+ "</xs:sequence>"
1068
+ "<xs:attribute name=\"id\" type=\"xs:integer\" use=\"required\"/>"
1069
+ "</xs:complexType>"
1070
+ "</xs:schema>";
1071
+ fwrite(common_text, 1, strlen(common_text), f1);
1072
+ fclose(f1);
1073
+ FILE* f2 = fopen(main.c_str(), "wb");
1074
+ ASSERT_NE(f2, nullptr);
1075
+ const char* main_text =
1076
+ "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
1077
+ "<xs:include schemaLocation=\"xsdcommon.xsd\"/>"
1078
+ "<xs:complexType name=\"listT\">"
1079
+ "<xs:sequence>"
1080
+ "<xs:element name=\"item\" type=\"itemT\""
1081
+ " maxOccurs=\"unbounded\"/>"
1082
+ "</xs:sequence>"
1083
+ "</xs:complexType>"
1084
+ "<xs:element name=\"list\" type=\"listT\"/>"
1085
+ "</xs:schema>";
1086
+ fwrite(main_text, 1, strlen(main_text), f2);
1087
+ fclose(f2);
1088
+
1089
+ LeptrisStatus st = LEPTRIS_OK;
1090
+ LeptrisXsdSchema s = leptris_xsd_compile_file(main.c_str(), &st);
1091
+ ASSERT_NE(s, (LeptrisXsdSchema)0);
1092
+ /* the included declaration participates: itemT's rows type the
1093
+ * particle's attributes and its content model applies */
1094
+ const char* good =
1095
+ "<list><item id=\"5\"><sku>a</sku></item></list>";
1096
+ LeptrisDocument d =
1097
+ leptris_parse_string(good, strlen(good), &st);
1098
+ ASSERT_NE(d, nullptr);
1099
+ EXPECT_EQ(leptris_xsd_validate(s, d), 1);
1100
+ const char* badx =
1101
+ "<list><item id=\"x\"><sku>a</sku></item></list>";
1102
+ LeptrisDocument bad =
1103
+ leptris_parse_string(badx, strlen(badx), &st);
1104
+ ASSERT_NE(bad, nullptr);
1105
+ EXPECT_EQ(leptris_xsd_validate(s, bad), 0);
1106
+ leptris_document_free(d);
1107
+ leptris_document_free(bad);
1108
+ leptris_xsd_free(s);
1109
+ remove(common.c_str());
1110
+ remove(main.c_str());
1111
+ }
1112
+
1113
+ TEST(XsdCompileFile, MissingFileIsNullWithStatus) {
1114
+ LeptrisStatus st = LEPTRIS_OK;
1115
+ EXPECT_EQ(leptris_xsd_compile_file("/no/such/schema.xsd", &st),
1116
+ (LeptrisXsdSchema)0);
1117
+ EXPECT_NE(st, LEPTRIS_OK);
1118
+ EXPECT_EQ(leptris_xsd_compile_file(NULL, &st), (LeptrisXsdSchema)0);
1119
+ }
1120
+
1121
+ } // namespace
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json",
3
3
  "name": "leptris",
4
- "version": "1.9.324",
4
+ "version": "1.9.331",
5
5
  "description": "High-performance XML parser and XPath 1.0 engine in C (libleptris)",
6
6
  "homepage": "https://github.com/leptris/leptris",
7
7
  "license": "MIT",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leptris
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.324.0
4
+ version: 1.9.331.0
5
5
  platform: arm-linux
6
6
  authors:
7
7
  - Ribose Inc.