From fc2234b87f4ce29be0e556c6f3b085b749b7d71b Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 16 Apr 2020 18:15:45 +0300 Subject: Add implementation --- libxerces-c/tests/.gitignore | 3 + libxerces-c/tests/build/.gitignore | 3 + libxerces-c/tests/build/bootstrap.build | 8 + libxerces-c/tests/build/root.build | 23 +++ libxerces-c/tests/buildfile | 4 + libxerces-c/tests/dom-print/DOMPrint | 1 + libxerces-c/tests/dom-print/buildfile | 6 + libxerces-c/tests/dom-print/testscript | 20 +++ libxerces-c/tests/net-accessor/NetAccessorTest.cpp | 167 +++++++++++++++++++++ libxerces-c/tests/net-accessor/buildfile | 11 ++ .../net-accessor/handle-exception-as-error.patch | 35 +++++ libxerces-c/tests/net-accessor/testscript | 34 +++++ libxerces-c/tests/psvi-writer/PSVIWriter | 1 + libxerces-c/tests/psvi-writer/buildfile | 11 ++ libxerces-c/tests/psvi-writer/testscript | 21 +++ libxerces-c/tests/sax-print/SAXPrint | 1 + libxerces-c/tests/sax-print/buildfile | 6 + libxerces-c/tests/sax-print/testscript | 20 +++ libxerces-c/tests/sax2-print/SAX2Print | 1 + libxerces-c/tests/sax2-print/buildfile | 6 + libxerces-c/tests/sax2-print/testscript | 20 +++ 21 files changed, 402 insertions(+) create mode 100644 libxerces-c/tests/.gitignore create mode 100644 libxerces-c/tests/build/.gitignore create mode 100644 libxerces-c/tests/build/bootstrap.build create mode 100644 libxerces-c/tests/build/root.build create mode 100644 libxerces-c/tests/buildfile create mode 120000 libxerces-c/tests/dom-print/DOMPrint create mode 100644 libxerces-c/tests/dom-print/buildfile create mode 100644 libxerces-c/tests/dom-print/testscript create mode 100644 libxerces-c/tests/net-accessor/NetAccessorTest.cpp create mode 100644 libxerces-c/tests/net-accessor/buildfile create mode 100644 libxerces-c/tests/net-accessor/handle-exception-as-error.patch create mode 100644 libxerces-c/tests/net-accessor/testscript create mode 120000 libxerces-c/tests/psvi-writer/PSVIWriter create mode 100644 libxerces-c/tests/psvi-writer/buildfile create mode 100644 libxerces-c/tests/psvi-writer/testscript create mode 120000 libxerces-c/tests/sax-print/SAXPrint create mode 100644 libxerces-c/tests/sax-print/buildfile create mode 100644 libxerces-c/tests/sax-print/testscript create mode 120000 libxerces-c/tests/sax2-print/SAX2Print create mode 100644 libxerces-c/tests/sax2-print/buildfile create mode 100644 libxerces-c/tests/sax2-print/testscript (limited to 'libxerces-c/tests') diff --git a/libxerces-c/tests/.gitignore b/libxerces-c/tests/.gitignore new file mode 100644 index 0000000..2e508a9 --- /dev/null +++ b/libxerces-c/tests/.gitignore @@ -0,0 +1,3 @@ +driver +test/ +test-*/ diff --git a/libxerces-c/tests/build/.gitignore b/libxerces-c/tests/build/.gitignore new file mode 100644 index 0000000..4a730a3 --- /dev/null +++ b/libxerces-c/tests/build/.gitignore @@ -0,0 +1,3 @@ +config.build +root/ +bootstrap/ diff --git a/libxerces-c/tests/build/bootstrap.build b/libxerces-c/tests/build/bootstrap.build new file mode 100644 index 0000000..2a03b3a --- /dev/null +++ b/libxerces-c/tests/build/bootstrap.build @@ -0,0 +1,8 @@ +# file : tests/build/bootstrap.build +# license : Apache License 2.0; see accompanying LICENSE file + +project = # Unnamed subproject. + +using config +using dist +using test diff --git a/libxerces-c/tests/build/root.build b/libxerces-c/tests/build/root.build new file mode 100644 index 0000000..7bf1cba --- /dev/null +++ b/libxerces-c/tests/build/root.build @@ -0,0 +1,23 @@ +# file : tests/build/root.build +# license : Apache License 2.0; see accompanying LICENSE file + +cxx.std = latest + +using cxx + +hxx{*}: extension = hpp +cxx{*}: extension = cpp + +if ($cxx.target.system == 'win32-msvc') + cxx.poptions += -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS + +if ($cxx.class == 'msvc') + cxx.coptions += /wd4251 /wd4275 /wd4800 + +# Every exe{} in this subproject is by default a test. +# +exe{*}: test = true + +# Specify the test target for cross-testing. +# +test.target = $cxx.target diff --git a/libxerces-c/tests/buildfile b/libxerces-c/tests/buildfile new file mode 100644 index 0000000..f1869ed --- /dev/null +++ b/libxerces-c/tests/buildfile @@ -0,0 +1,4 @@ +# file : tests/buildfile +# license : Apache License 2.0; see accompanying LICENSE file + +./: {*/ -build/} diff --git a/libxerces-c/tests/dom-print/DOMPrint b/libxerces-c/tests/dom-print/DOMPrint new file mode 120000 index 0000000..d73574d --- /dev/null +++ b/libxerces-c/tests/dom-print/DOMPrint @@ -0,0 +1 @@ +../../../upstream/samples/src/DOMPrint \ No newline at end of file diff --git a/libxerces-c/tests/dom-print/buildfile b/libxerces-c/tests/dom-print/buildfile new file mode 100644 index 0000000..76619a3 --- /dev/null +++ b/libxerces-c/tests/dom-print/buildfile @@ -0,0 +1,6 @@ +# file : tests/dom-print/buildfile +# license : Apache License 2.0; see accompanying LICENSE file + +import libs = libxerces-c%lib{xerces-c} + +exe{driver}: DOMPrint/{hxx cxx}{*} $libs testscript diff --git a/libxerces-c/tests/dom-print/testscript b/libxerces-c/tests/dom-print/testscript new file mode 100644 index 0000000..f281d3f --- /dev/null +++ b/libxerces-c/tests/dom-print/testscript @@ -0,0 +1,20 @@ +# file : tests/dom-print/testscript +# license : Apache License 2.0; see accompanying LICENSE file + +: utf8 +: +{ + cat <=f; + + + Mitteleuropäische catégorie + + EOI + + $* -wfpp=on f >>~%EOO% + %<\?xml version="1.0" encoding="UTF-8".*\?>% + + Mitteleuropäische catégorie + + EOO +} diff --git a/libxerces-c/tests/net-accessor/NetAccessorTest.cpp b/libxerces-c/tests/net-accessor/NetAccessorTest.cpp new file mode 100644 index 0000000..c2affbd --- /dev/null +++ b/libxerces-c/tests/net-accessor/NetAccessorTest.cpp @@ -0,0 +1,167 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +/* + * $Id$ + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include +#include +#include +#include +#include + +#if defined(XERCES_NEW_IOSTREAMS) +#include +#else +#include +#endif + +XERCES_CPP_NAMESPACE_USE + + +inline XERCES_STD_QUALIFIER ostream& operator<<(XERCES_STD_QUALIFIER ostream& os, const XMLCh* xmlStr) +{ + char* transcoded = XMLString::transcode(xmlStr); + os << transcoded; + XMLString::release(&transcoded); + return os; +} + + +void +exercise(BinInputStream& stream) +{ + static float percents[] = { 1.0, 0.5, 0.25, 0.1, 0.15, 0.113, 0.333, 0.0015, 0.0013 }; + int numPercents = sizeof(percents) / sizeof(float); + + const unsigned int bufferMax = 4096; + XMLByte buffer[bufferMax]; + + int iteration = 0; + unsigned int bytesRead = 0; + do { + // Calculate a percentage of our maximum buffer size, going through + // them round-robin + float percent = percents[iteration % numPercents]; + unsigned int bufCnt = (unsigned int)(bufferMax * percent); + + // Check to make sure we didn't go out of bounds + if (bufCnt <= 0) + bufCnt = 1; + if (bufCnt > bufferMax) + bufCnt = bufferMax; + + // Read bytes into our buffer + bytesRead = stream.readBytes(buffer, bufCnt); + //XERCES_STD_QUALIFIER cerr << "Read " << bytesRead << " bytes into a " << bufCnt << " byte buffer\n"; + + if (bytesRead > 0) + { + // Write the data to standard out + XERCES_STD_QUALIFIER cout.write((char*)buffer, bytesRead); + } + + ++iteration; + } while (bytesRead > 0); +} + + +// --------------------------------------------------------------------------- +// Program entry point +// --------------------------------------------------------------------------- +int +main(int argc, char** argv) +{ + // Init the XML platform + try + { + XMLPlatformUtils::Initialize(); + } + + catch(const XMLException& toCatch) + { + XERCES_STD_QUALIFIER cout << "Error during platform init! Message:\n" + << toCatch.getMessage() << XERCES_STD_QUALIFIER endl; + return 1; + } + + // Look for our one and only parameter + if (argc != 2) + { + XERCES_STD_QUALIFIER cerr << "Usage: NetAccessorTest url\n" + "\n" + "This test reads data from the given url and writes the result\n" + "to standard output.\n" + "\n" + "A variety of buffer sizes is are used during the test.\n" + "\n" + ; + exit(1); + } + + // Get the URL + char* url = argv[1]; + + int r = 1; + + // Do the test + try + { + XMLURL xmlURL(url); + + // Get the netaccessor + XMLNetAccessor* na = XMLPlatformUtils::fgNetAccessor; + if (na == 0) + { + XERCES_STD_QUALIFIER cerr << "No netaccessor is available. Aborting.\n"; + exit(2); + } + + // Build a binary input stream + BinInputStream* is = na->makeNew(xmlURL); + if (is == 0) + { + XERCES_STD_QUALIFIER cerr << "No binary input stream created. Aborting.\n"; + exit(3); + } + + // Exercise the inputstream + exercise(*is); + + // Delete the is + delete is; + r = 0; + } + catch(const XMLException& toCatch) + { + XERCES_STD_QUALIFIER cerr << "Exception during test:\n " + << toCatch.getMessage() + << XERCES_STD_QUALIFIER endl; + } + + // And call the termination method + XMLPlatformUtils::Terminate(); + + return r; +} + diff --git a/libxerces-c/tests/net-accessor/buildfile b/libxerces-c/tests/net-accessor/buildfile new file mode 100644 index 0000000..ab3f79f --- /dev/null +++ b/libxerces-c/tests/net-accessor/buildfile @@ -0,0 +1,11 @@ +# file : tests/net-accessor/buildfile +# license : Apache License 2.0; see accompanying LICENSE file + +import libs = libxerces-c%lib{xerces-c} + +exe{driver}: {hxx cxx}{*} $libs testscript + +# Disable MSVC warnings that pop up with /W3. +# +if ($cxx.class == 'msvc') + cxx.coptions += /wd4267 /wd4305 diff --git a/libxerces-c/tests/net-accessor/handle-exception-as-error.patch b/libxerces-c/tests/net-accessor/handle-exception-as-error.patch new file mode 100644 index 0000000..674e5ba --- /dev/null +++ b/libxerces-c/tests/net-accessor/handle-exception-as-error.patch @@ -0,0 +1,35 @@ +diff --git a/libxerces-c/tests/net-accessor/NetAccessorTest.cpp b/libxerces-c/tests/net-accessor/NetAccessorTest.cpp +index 3bb735b..c2affbd 100644 +--- a/libxerces-c/tests/net-accessor/NetAccessorTest.cpp ++++ b/libxerces-c/tests/net-accessor/NetAccessorTest.cpp +@@ -122,6 +122,8 @@ main(int argc, char** argv) + // Get the URL + char* url = argv[1]; + ++ int r = 1; ++ + // Do the test + try + { +@@ -148,11 +150,11 @@ main(int argc, char** argv) + + // Delete the is + delete is; +- ++ r = 0; + } + catch(const XMLException& toCatch) + { +- XERCES_STD_QUALIFIER cout << "Exception during test:\n " ++ XERCES_STD_QUALIFIER cerr << "Exception during test:\n " + << toCatch.getMessage() + << XERCES_STD_QUALIFIER endl; + } +@@ -160,6 +162,6 @@ main(int argc, char** argv) + // And call the termination method + XMLPlatformUtils::Terminate(); + +- return 0; ++ return r; + } + diff --git a/libxerces-c/tests/net-accessor/testscript b/libxerces-c/tests/net-accessor/testscript new file mode 100644 index 0000000..993423b --- /dev/null +++ b/libxerces-c/tests/net-accessor/testscript @@ -0,0 +1,34 @@ +# file : tests/net-accessor/testscript +# license : Apache License 2.0; see accompanying LICENSE file + +: http +: +$* 'http://www.example.com' >>~%EOO% + %.+ + EOO + +# If we want to test how HTTPS URLs are handled, we need to make it work +# always (see how the curl utility is packaged for details). +# +#\ +: https +: +: Test that an HTTPS URL is queried successfully using libcurl via the system +: SSL backend on Windows and MacOS/Clang and fails for other targets that use +: the OpenSSL backend by default. +: +if ($cxx.target.class == 'windows' || \ + $cxx.target.class == 'macos' && $cxx.id == 'clang-apple') +{ + $* 'https://www.example.com' >>~%EOO% + %.+ + EOO +} +else +{ + $* 'https://www.example.com' 2>>~%EOE% != 0 + Exception during test: + %.+ + EOE +} +#\ diff --git a/libxerces-c/tests/psvi-writer/PSVIWriter b/libxerces-c/tests/psvi-writer/PSVIWriter new file mode 120000 index 0000000..92efd5c --- /dev/null +++ b/libxerces-c/tests/psvi-writer/PSVIWriter @@ -0,0 +1 @@ +../../../upstream/samples/src/PSVIWriter \ No newline at end of file diff --git a/libxerces-c/tests/psvi-writer/buildfile b/libxerces-c/tests/psvi-writer/buildfile new file mode 100644 index 0000000..9a5d84d --- /dev/null +++ b/libxerces-c/tests/psvi-writer/buildfile @@ -0,0 +1,11 @@ +# file : tests/psvi-writer/buildfile +# license : Apache License 2.0; see accompanying LICENSE file + +import libs = libxerces-c%lib{xerces-c} + +exe{driver}: PSVIWriter/{hxx cxx}{*} $libs testscript + +# Disable MSVC warnings that pop up with /W3. +# +if ($cxx.class == 'msvc') + cxx.coptions += /wd4267 diff --git a/libxerces-c/tests/psvi-writer/testscript b/libxerces-c/tests/psvi-writer/testscript new file mode 100644 index 0000000..5c3b58f --- /dev/null +++ b/libxerces-c/tests/psvi-writer/testscript @@ -0,0 +1,21 @@ +# file : tests/psvi-writer/testscript +# license : Apache License 2.0; see accompanying LICENSE file + +: utf8 +: +{ + cat <=f; + + + Mitteleuropäische catégorie + + EOI + + $* f >>~%EOO% + %.+ + %\s*% + %\s*Mitteleuropäische catégorie% + %\s*% + %.+ + EOO +} diff --git a/libxerces-c/tests/sax-print/SAXPrint b/libxerces-c/tests/sax-print/SAXPrint new file mode 120000 index 0000000..7c61024 --- /dev/null +++ b/libxerces-c/tests/sax-print/SAXPrint @@ -0,0 +1 @@ +../../../upstream/samples/src/SAXPrint \ No newline at end of file diff --git a/libxerces-c/tests/sax-print/buildfile b/libxerces-c/tests/sax-print/buildfile new file mode 100644 index 0000000..ed3d22b --- /dev/null +++ b/libxerces-c/tests/sax-print/buildfile @@ -0,0 +1,6 @@ +# file : tests/sax-print/buildfile +# license : Apache License 2.0; see accompanying LICENSE file + +import libs = libxerces-c%lib{xerces-c} + +exe{driver}: SAXPrint/{hxx cxx}{*} $libs testscript diff --git a/libxerces-c/tests/sax-print/testscript b/libxerces-c/tests/sax-print/testscript new file mode 100644 index 0000000..cbc62e4 --- /dev/null +++ b/libxerces-c/tests/sax-print/testscript @@ -0,0 +1,20 @@ +# file : tests/sax-print/testscript +# license : Apache License 2.0; see accompanying LICENSE file + +: utf8 +: +{ + cat <=f; + + + Mitteleuropäische catégorie + + EOI + + $* -x=UTF-8 f >>:EOO + + + Mitteleuropäische catégorie + + EOO +} diff --git a/libxerces-c/tests/sax2-print/SAX2Print b/libxerces-c/tests/sax2-print/SAX2Print new file mode 120000 index 0000000..9f0238e --- /dev/null +++ b/libxerces-c/tests/sax2-print/SAX2Print @@ -0,0 +1 @@ +../../../upstream/samples/src/SAX2Print \ No newline at end of file diff --git a/libxerces-c/tests/sax2-print/buildfile b/libxerces-c/tests/sax2-print/buildfile new file mode 100644 index 0000000..fd4875d --- /dev/null +++ b/libxerces-c/tests/sax2-print/buildfile @@ -0,0 +1,6 @@ +# file : tests/sax2-print/buildfile +# license : Apache License 2.0; see accompanying LICENSE file + +import libs = libxerces-c%lib{xerces-c} + +exe{driver}: SAX2Print/{hxx cxx}{*} $libs testscript diff --git a/libxerces-c/tests/sax2-print/testscript b/libxerces-c/tests/sax2-print/testscript new file mode 100644 index 0000000..6fedae3 --- /dev/null +++ b/libxerces-c/tests/sax2-print/testscript @@ -0,0 +1,20 @@ +# file : tests/sax2-print/testscript +# license : Apache License 2.0; see accompanying LICENSE file + +: utf8 +: +{ + cat <=f; + + + Mitteleuropäische catégorie + + EOI + + $* -x=UTF-8 f >>:EOO + + + Mitteleuropäische catégorie + + EOO +} -- cgit v1.1