diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
commit | ed5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch) | |
tree | 7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /sax/qa | |
parent | Initial commit. (diff) | |
download | libreoffice-upstream.tar.xz libreoffice-upstream.zip |
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sax/qa')
-rw-r--r-- | sax/qa/cppunit/attributes.cxx | 75 | ||||
-rw-r--r-- | sax/qa/cppunit/parser.cxx | 99 | ||||
-rw-r--r-- | sax/qa/cppunit/test_converter.cxx | 623 | ||||
-rw-r--r-- | sax/qa/cppunit/xmlimport.cxx | 454 | ||||
-rw-r--r-- | sax/qa/data/defaultns.xml | 11 | ||||
-rw-r--r-- | sax/qa/data/inlinens.xml | 12 | ||||
-rw-r--r-- | sax/qa/data/manifestwithnsdecl.xml | 12 | ||||
-rw-r--r-- | sax/qa/data/manifestwithoutnsdecl.xml | 12 | ||||
-rw-r--r-- | sax/qa/data/multiplens.xml | 13 | ||||
-rw-r--r-- | sax/qa/data/multiplepfx.xml | 9 | ||||
-rw-r--r-- | sax/qa/data/nestedns.xml | 32 | ||||
-rw-r--r-- | sax/qa/data/nstoattributes.xml | 17 | ||||
-rw-r--r-- | sax/qa/data/simple.xml | 11 | ||||
-rw-r--r-- | sax/qa/data/testthreading.xml | 5 |
14 files changed, 1385 insertions, 0 deletions
diff --git a/sax/qa/cppunit/attributes.cxx b/sax/qa/cppunit/attributes.cxx new file mode 100644 index 000000000..6c71e9aa1 --- /dev/null +++ b/sax/qa/cppunit/attributes.cxx @@ -0,0 +1,75 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <sal/types.h> +#include <com/sun/star/xml/sax/SAXException.hpp> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +#include <rtl/ref.hxx> +#include <sax/fastattribs.hxx> + +using namespace css; +using namespace css::xml; + +namespace { + +class AttributesTest: public CppUnit::TestFixture +{ +public: + void test(); + + CPPUNIT_TEST_SUITE( AttributesTest ); + CPPUNIT_TEST( test ); + CPPUNIT_TEST_SUITE_END(); +}; + +void AttributesTest::test() +{ + rtl::Reference<sax_fastparser::FastAttributeList> xAttributeList( new sax_fastparser::FastAttributeList(nullptr) ); + xAttributeList->add(1, "1"); + xAttributeList->add(2, OString("2")); + + // We can't test getValueToken() and getOptionalValueToken() + // without XFastTokenHandler :-( + // Uncomment to get segmentation fault: + // xAttributeList->getOptionalValueToken(1, 0); + // xAttributeList->getValueToken(2); + + CPPUNIT_ASSERT( xAttributeList->hasAttribute(1) ); + CPPUNIT_ASSERT( !xAttributeList->hasAttribute(3) ); + + CPPUNIT_ASSERT_EQUAL( OUString("2"), xAttributeList->getOptionalValue(2) ); + CPPUNIT_ASSERT_EQUAL( OUString(), xAttributeList->getOptionalValue(3) ); + + CPPUNIT_ASSERT_EQUAL( OUString("1"), xAttributeList->getValue(1) ); + CPPUNIT_ASSERT_THROW( xAttributeList->getValue(3), xml::sax::SAXException ); + + xAttributeList->addUnknown("a", "a"); + xAttributeList->addUnknown("b", "b", "b"); + xAttributeList->addUnknown("c", "c"); + CPPUNIT_ASSERT_EQUAL( sal_Int32(3), xAttributeList->getUnknownAttributes().getLength() ); + + CPPUNIT_ASSERT_EQUAL( sal_Int32(2), xAttributeList->getFastAttributes().getLength() ); + + xAttributeList->clear(); + CPPUNIT_ASSERT( !xAttributeList->hasAttribute(1) ); + CPPUNIT_ASSERT( !xAttributeList->getFastAttributes().hasElements() ); + xAttributeList->addUnknown("c", "c"); + CPPUNIT_ASSERT_EQUAL( sal_Int32(1), xAttributeList->getUnknownAttributes().getLength() ); +} + +CPPUNIT_TEST_SUITE_REGISTRATION( AttributesTest ); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sax/qa/cppunit/parser.cxx b/sax/qa/cppunit/parser.cxx new file mode 100644 index 000000000..261091fe8 --- /dev/null +++ b/sax/qa/cppunit/parser.cxx @@ -0,0 +1,99 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <sal/config.h> + +#include <com/sun/star/io/Pipe.hpp> +#include <com/sun/star/xml/sax/FastToken.hpp> +#include <com/sun/star/xml/sax/SAXParseException.hpp> + +#include <sax/fastparser.hxx> +#include <sax/fastattribs.hxx> +#include <test/bootstrapfixture.hxx> +#include <rtl/ref.hxx> + +using namespace css; +using namespace css::xml::sax; + +namespace { + +class DummyTokenHandler : public sax_fastparser::FastTokenHandlerBase +{ +public: + DummyTokenHandler() {} + + virtual sal_Int32 SAL_CALL getTokenFromUTF8( const uno::Sequence<sal_Int8>& ) override + { + return FastToken::DONTKNOW; + } + virtual uno::Sequence< sal_Int8 > SAL_CALL getUTF8Identifier( sal_Int32 ) override + { + CPPUNIT_ASSERT_MESSAGE( "getUTF8Identifier: unexpected call", false ); + return uno::Sequence<sal_Int8>(); + } + virtual sal_Int32 getTokenDirect( const char * /* pToken */, sal_Int32 /* nLength */ ) const override + { + return -1; + } +}; + +class ParserTest: public test::BootstrapFixture +{ + InputSource maInput; + rtl::Reference< sax_fastparser::FastSaxParser > mxParser; + rtl::Reference< DummyTokenHandler > mxTokenHandler; + +public: + virtual void setUp() override; + + void parse(); + + CPPUNIT_TEST_SUITE(ParserTest); + CPPUNIT_TEST(parse); + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference< io::XInputStream > createStream(const OString& sInput); +}; + +void ParserTest::setUp() +{ + test::BootstrapFixture::setUp(); + mxTokenHandler.set( new DummyTokenHandler() ); + mxParser.set( new sax_fastparser::FastSaxParser() ); + mxParser->setTokenHandler( mxTokenHandler ); +} + +uno::Reference< io::XInputStream > ParserTest::createStream(const OString& sInput) +{ + uno::Reference< io::XOutputStream > xPipe( io::Pipe::create(m_xContext) ); + uno::Reference< io::XInputStream > xInStream( xPipe, uno::UNO_QUERY ); + uno::Sequence< sal_Int8 > aSeq( reinterpret_cast<sal_Int8 const *>(sInput.getStr()), sInput.getLength() ); + xPipe->writeBytes( aSeq ); + xPipe->flush(); + xPipe->closeOutput(); + return xInStream; +} + +void ParserTest::parse() +{ + maInput.aInputStream = createStream("<a>...<b />..</a>"); + mxParser->parseStream( maInput ); + + maInput.aInputStream = createStream("<b></a>"); + CPPUNIT_ASSERT_THROW( mxParser->parseStream( maInput ), css::xml::sax::SAXParseException ); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ParserTest); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sax/qa/cppunit/test_converter.cxx b/sax/qa/cppunit/test_converter.cxx new file mode 100644 index 000000000..525e110c1 --- /dev/null +++ b/sax/qa/cppunit/test_converter.cxx @@ -0,0 +1,623 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#include <limits> + +#include <sal/types.h> +#include <cppunit/TestAssert.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +#include <rtl/ustrbuf.hxx> + +#include <com/sun/star/util/DateTime.hpp> +#include <com/sun/star/util/Duration.hpp> +#include <com/sun/star/util/MeasureUnit.hpp> + +#include <sax/tools/converter.hxx> +#include <sal/log.hxx> + + +using namespace ::com::sun::star; +using namespace ::com::sun::star::util; +using sax::Converter; + + +namespace { + +class ConverterTest + : public ::CppUnit::TestFixture +{ +public: + + void testDuration(); + void testDateTime(); + void testTime(); + void testDouble(); + void testMeasure(); + void testBool(); + void testPercent(); + void testColor(); + void testNumber(); + + CPPUNIT_TEST_SUITE(ConverterTest); + CPPUNIT_TEST(testDuration); + CPPUNIT_TEST(testDateTime); + CPPUNIT_TEST(testTime); + CPPUNIT_TEST(testDouble); + CPPUNIT_TEST(testMeasure); + CPPUNIT_TEST(testBool); + CPPUNIT_TEST(testPercent); + CPPUNIT_TEST(testColor); + CPPUNIT_TEST(testNumber); + CPPUNIT_TEST_SUITE_END(); + +private: +}; + +void doTest(util::Duration const & rid, char const*const pis, + char const*const i_pos = nullptr) +{ + char const*const pos(i_pos ? i_pos : pis); + util::Duration od; + OUString is(OUString::createFromAscii(pis)); + SAL_INFO("sax.cppunit","about to convert '" << is << "'"); + bool bSuccess = Converter::convertDuration(od, is); + SAL_INFO("sax.cppunit","" << (od.Negative ? "-" : "+") << " " << od.Years << "Y " << od.Months << "M " << od.Days << "D " << od.Hours << "H " << od.Minutes << "M " << od.Seconds << "S " << od.NanoSeconds << "n"); + CPPUNIT_ASSERT(bSuccess); + CPPUNIT_ASSERT_EQUAL(rid.Years, od.Years); + CPPUNIT_ASSERT_EQUAL(rid.Months, od.Months); + CPPUNIT_ASSERT_EQUAL(rid.Days, od.Days); + CPPUNIT_ASSERT_EQUAL(rid.Hours, od.Hours); + CPPUNIT_ASSERT_EQUAL(rid.Minutes, od.Minutes); + CPPUNIT_ASSERT_EQUAL(rid.Seconds, od.Seconds); + CPPUNIT_ASSERT_EQUAL(rid.NanoSeconds, od.NanoSeconds); + CPPUNIT_ASSERT_EQUAL(rid.Negative, od.Negative); + OUStringBuffer buf(64); + Converter::convertDuration(buf, od); + SAL_INFO("sax.cppunit","" << buf.toString()); + CPPUNIT_ASSERT(buf.makeStringAndClear().equalsAscii(pos)); +} + +void doTestDurationF(char const*const pis) +{ + util::Duration od; + bool bSuccess = Converter::convertDuration(od, + OUString::createFromAscii(pis)); + SAL_INFO("sax.cppunit","" << (od.Negative ? "-" : "+") << " " << od.Years << "Y " << od.Months << "M " << od.Days << "D " << od.Hours << "H " << od.Minutes << "M " << od.Seconds << "S " << od.NanoSeconds << "n"); + CPPUNIT_ASSERT_MESSAGE(pis, !bSuccess); +} + +void ConverterTest::testDuration() +{ + SAL_INFO("sax.cppunit","\nSAX CONVERTER TEST BEGIN"); + doTest( util::Duration(false, 1, 0, 0, 0, 0, 0, 0), "P1Y" ); + doTest( util::Duration(false, 0, 42, 0, 0, 0, 0, 0), "P42M" ); + doTest( util::Duration(false, 0, 0, 111, 0, 0, 0, 0), "P111D" ); + doTest( util::Duration(false, 0, 0, 0, 52, 0, 0, 0), "PT52H" ); + doTest( util::Duration(false, 0, 0, 0, 0, 717, 0, 0), "PT717M" ); + doTest( util::Duration(false, 0, 0, 0, 0, 0, 121, 0), "PT121S" ); + doTest( util::Duration(false, 0, 0, 0, 0, 0, 0, 190000000), "PT0.19S", "PT0.190000000S"); + doTest( util::Duration(false, 0, 0, 0, 0, 0, 0, 90000000), "PT0.09S", "PT0.090000000S" ); + doTest( util::Duration(false, 0, 0, 0, 0, 0, 0, 9000000), "PT0.009S", "PT0.009000000S" ); + doTest( util::Duration(false, 0, 0, 0, 0, 0, 0, 9), "PT0.000000009S", "PT0.000000009S" ); + doTest( util::Duration(false, 0, 0, 0, 0, 0, 9, 999999999), + "PT9.999999999999999999999999999999S", "PT9.999999999S" ); + doTest( util::Duration(true , 0, 0, 9999, 0, 0, 0, 0), "-P9999D" ); + doTest( util::Duration(true , 7, 6, 5, 4, 3, 2, 10000000), + "-P7Y6M5DT4H3M2.01000S", "-P7Y6M5DT4H3M2.010000000S" ); + doTest( util::Duration(false, 0, 6, 0, 0, 3, 0, 0), "P6MT3M" ); + doTest( util::Duration(false, 0, 0, 0, 0, 0, 0, 0), "P0D" ); + doTestDurationF("1Y1M"); // invalid: no ^P + doTestDurationF("P-1Y1M"); // invalid: - after P + doTestDurationF("P1M1Y"); // invalid: Y after M + doTestDurationF("PT1Y"); // invalid: Y after T + doTestDurationF("P1Y1M1M"); // invalid: M twice, no T + doTestDurationF("P1YT1MT1M"); // invalid: T twice + doTestDurationF("P1YT"); // invalid: T but no H,M,S + doTestDurationF("P99999999999Y"); // cannot parse so many Ys + doTestDurationF("PT.1S"); // invalid: no 0 preceding . + doTestDurationF("PT5M.134S"); // invalid: no 0 preceding . + doTestDurationF("PT1.S"); // invalid: no digit following . + SAL_INFO("sax.cppunit","\nSAX CONVERTER TEST END"); +} + + +bool eqDateTime(const util::DateTime& a, const util::DateTime& b) { + return a.Year == b.Year && a.Month == b.Month && a.Day == b.Day + && a.Hours == b.Hours && a.Minutes == b.Minutes + && a.Seconds == b.Seconds + && a.NanoSeconds == b.NanoSeconds + && a.IsUTC == b.IsUTC; +} + +void doTest(util::DateTime const & rdt, char const*const pis, + char const*const i_pos = nullptr) +{ + char const*const pos(i_pos ? i_pos : pis); + OUString is(OUString::createFromAscii(pis)); + util::DateTime odt; + SAL_INFO("sax.cppunit","about to convert '" << is << "'"); + bool bSuccess( Converter::parseDateTime(odt, is) ); + SAL_INFO("sax.cppunit","Y:" << odt.Year << " M:" << odt.Month << " D:" << odt.Day << " H:" << odt.Hours << " M:" << odt.Minutes << " S:" << odt.Seconds << " nS:" << odt.NanoSeconds << " UTC: " << static_cast<bool>(odt.IsUTC)); + CPPUNIT_ASSERT(bSuccess); + CPPUNIT_ASSERT(eqDateTime(rdt, odt)); + OUStringBuffer buf(32); + Converter::convertDateTime(buf, odt, nullptr, true); + SAL_INFO("sax.cppunit","" << buf.toString()); + CPPUNIT_ASSERT_EQUAL(OUString::createFromAscii(pos), + buf.makeStringAndClear()); +} + +void doTestDateTimeF(char const*const pis) +{ + util::DateTime odt; + bool bSuccess = Converter::parseDateTime(odt, OUString::createFromAscii(pis)); + SAL_INFO("sax.cppunit","Y:" << odt.Year << " M:" << odt.Month << " D:" << odt.Day << " H:" << odt.Hours << "H M:" << odt.Minutes << " S:" << odt.Seconds << " nS:" << odt.NanoSeconds); + CPPUNIT_ASSERT(!bSuccess); +} + +void ConverterTest::testDateTime() +{ + SAL_INFO("sax.cppunit","\nSAX CONVERTER TEST BEGIN"); + doTest( util::DateTime(0, 0, 0, 0, 1, 1, 1, false), "0001-01-01T00:00:00" ); + doTest( util::DateTime(0, 0, 0, 0, 1, 1, 1, true), "0001-01-01T00:00:00Z" ); + doTest( util::DateTime(0, 0, 0, 0, 1, 1, -1, false), + "-0001-01-01T00:00:00"); + doTest( util::DateTime(0, 0, 0, 0, 1, 1, -1, true), + "-0001-01-01T01:00:00+01:00", "-0001-01-01T00:00:00Z"); + doTest( util::DateTime(0, 0, 0, 0, 1, 1, -324, false), + "-0324-01-01T00:00:00" ); + doTest( util::DateTime(0, 0, 0, 0, 1, 1, 1, true), + "0001-01-01T00:00:00-00:00", "0001-01-01T00:00:00Z" ); + doTest( util::DateTime(0, 0, 0, 0, 1, 1, 1, true), + "0001-01-01T00:00:00+00:00", "0001-01-01T00:00:00Z" ); + doTest( util::DateTime(0, 0, 0, 12, 2, 1, 1, true), + "0001-01-02T00:00:00-12:00", "0001-01-02T12:00:00Z" ); + doTest( util::DateTime(0, 0, 0, 12, 1, 1, 1, true), + "0001-01-02T00:00:00+12:00", "0001-01-01T12:00:00Z" ); + doTest( util::DateTime(990000000, 59, 59, 23, 31, 12, 9999, false), + "9999-12-31T23:59:59.99", "9999-12-31T23:59:59.990000000" ); + doTest( util::DateTime(990000000, 59, 59, 23, 31, 12, 9999, true), + "9999-12-31T23:59:59.99Z", "9999-12-31T23:59:59.990000000Z" ); + doTest( util::DateTime(999999999, 59, 59, 23, 31, 12, 9999, false), + "9999-12-31T23:59:59.9999999999999999999999999999999999999", + "9999-12-31T23:59:59.999999999" ); + doTest( util::DateTime(999999999, 59, 59, 23, 31, 12, 9999, true), + "9999-12-31T23:59:59.9999999999999999999999999999999999999Z", + "9999-12-31T23:59:59.999999999Z" ); + doTest( util::DateTime(0, 0, 0, 0, 29, 2, 2000, true), // leap year + "2000-02-29T00:00:00-00:00", "2000-02-29T00:00:00Z" ); + doTest( util::DateTime(0, 0, 0, 0, 29, 2, 1600, true), // leap year + "1600-02-29T00:00:00-00:00", "1600-02-29T00:00:00Z" ); + doTest( util::DateTime(0, 0, 0, 24, 1, 1, 333, false) + /*(0, 0, 0, 0, 2, 1, 333)*/, + "0333-01-01T24:00:00"/*, "0333-01-02T00:00:00"*/ ); + // While W3C XMLSchema specifies a minimum of 4 year digits we are lenient + // in what we accept. + doTest( util::DateTime(0, 0, 0, 0, 1, 1, 1, false), + "1-01-01T00:00:00", "0001-01-01T00:00:00" ); + doTestDateTimeF( "+0001-01-01T00:00:00" ); // invalid: ^+ + doTestDateTimeF( "0001-1-01T00:00:00" ); // invalid: < 2 M + doTestDateTimeF( "0001-01-1T00:00:00" ); // invalid: < 2 D + doTestDateTimeF( "0001-01-01T0:00:00" ); // invalid: < 2 H + doTestDateTimeF( "0001-01-01T00:0:00" ); // invalid: < 2 M + doTestDateTimeF( "0001-01-01T00:00:0" ); // invalid: < 2 S + doTestDateTimeF( "0001-01-01T00:00:00." ); // invalid: .$ + doTestDateTimeF( "0001-01-01T00:00:00+1:00" ); // invalid: < 2 TZ H + doTestDateTimeF( "0001-01-01T00:00:00+00:1" ); // invalid: < 2 TZ M + doTestDateTimeF( "0001-13-01T00:00:00" ); // invalid: M > 12 + doTestDateTimeF( "0001-01-32T00:00:00" ); // invalid: D > 31 + doTestDateTimeF( "0001-01-01T25:00:00" ); // invalid: H > 24 + doTestDateTimeF( "0001-01-01T00:60:00" ); // invalid: M > 59 + doTestDateTimeF( "0001-01-01T00:00:60" ); // invalid: S > 59 + doTestDateTimeF( "0001-01-01T24:01:00" ); // invalid: H=24, but M != 0 + doTestDateTimeF( "0001-01-01T24:00:01" ); // invalid: H=24, but S != 0 + doTestDateTimeF( "0001-01-01T24:00:00.1" ); // invalid: H=24, but H != 0 + doTestDateTimeF( "0001-01-02T00:00:00+15:00" ); // invalid: TZ > +14:00 + doTestDateTimeF( "0001-01-02T00:00:00+14:01" ); // invalid: TZ > +14:00 + doTestDateTimeF( "0001-01-02T00:00:00-15:00" ); // invalid: TZ < -14:00 + doTestDateTimeF( "0001-01-02T00:00:00-14:01" ); // invalid: TZ < -14:00 + doTestDateTimeF( "2100-02-29T00:00:00-00:00" ); // invalid: no leap year + doTestDateTimeF( "1900-02-29T00:00:00-00:00" ); // invalid: no leap year + doTestDateTimeF( "00:00:00" ); // invalid: no date + doTestDateTimeF( "T00:00:00" ); // invalid: no date + SAL_INFO("sax.cppunit","\nSAX CONVERTER TEST END"); +} + +void doTestTime(util::DateTime const & rdt, char const*const pis, + char const*const i_pos = nullptr) +{ + char const*const pos(i_pos ? i_pos : pis); + OUString is(OUString::createFromAscii(pis)); + util::DateTime odt; + SAL_INFO("sax.cppunit","about to convert '" << is << "'"); + bool bSuccess( Converter::parseTimeOrDateTime(odt, is) ); + SAL_INFO("sax.cppunit","Y:" << odt.Year << " M:" << odt.Month << " D:" << odt.Day << " H:" << odt.Hours << " M:" << odt.Minutes << " S:" << odt.Seconds << " nS:" << odt.NanoSeconds << " UTC: " << static_cast<bool>(odt.IsUTC)); + CPPUNIT_ASSERT(bSuccess); + CPPUNIT_ASSERT(eqDateTime(rdt, odt)); + OUStringBuffer buf(32); + Converter::convertTimeOrDateTime(buf, odt); + SAL_INFO("sax.cppunit","" << buf.toString()); + CPPUNIT_ASSERT_EQUAL(OUString::createFromAscii(pos), + buf.makeStringAndClear()); +} + +void doTestTimeF(char const*const pis) +{ + util::DateTime odt; + bool bSuccess = Converter::parseTimeOrDateTime(odt, OUString::createFromAscii(pis)); + SAL_INFO("sax.cppunit","Y:" << odt.Year << " M:" << odt.Month << " D:" << odt.Day << " H:" << odt.Hours << "H M:" << odt.Minutes << " S:" << odt.Seconds << " nS:" << odt.NanoSeconds); + CPPUNIT_ASSERT_MESSAGE(pis, !bSuccess); +} + +void ConverterTest::testTime() // time or dateTime + horrible backcompat mess +{ + doTestTime( util::DateTime(0, 0, 0, 0, 1, 1, 1, false), + "0001-01-01T00:00:00" ); + doTestTime( util::DateTime(0, 0, 0, 0, 1, 1, 1, false), + "0001-01-01T00:00:00" ); + doTestTime( util::DateTime(0, 0, 0, 0, 1, 1, 1, true), + "0001-01-01T00:00:00Z" ); + doTestTime( util::DateTime(0, 0, 0, 0, 1, 1, -1, false), + "-0001-01-01T00:00:00"); + doTestTime( util::DateTime(0, 0, 0, 0, 1, 1, -1, true), + "-0001-01-01T01:00:00+01:00", "-0001-01-01T00:00:00Z"); + doTestTime( util::DateTime(0, 0, 0, 0, 1, 1, -324, false), + "-0324-01-01T00:00:00" ); + doTestTime( util::DateTime(0, 0, 0, 0, 1, 1, 1, true), + "0001-01-01T00:00:00-00:00", "0001-01-01T00:00:00Z" ); + doTestTime( util::DateTime(0, 0, 0, 0, 1, 1, 1, true), + "0001-01-01T00:00:00+00:00", "0001-01-01T00:00:00Z" ); + doTestTime( util::DateTime(0, 0, 0, 12, 2, 1, 1, true), + "0001-01-02T00:00:00-12:00", "0001-01-02T12:00:00Z" ); + doTestTime( util::DateTime(0, 0, 0, 12, 1, 1, 1, true), + "0001-01-02T00:00:00+12:00", "0001-01-01T12:00:00Z" ); + doTestTime( util::DateTime(990000000, 59, 59, 23, 31, 12, 9999, false), + "9999-12-31T23:59:59.99", "9999-12-31T23:59:59.990000000" ); + doTestTime( util::DateTime(990000000, 59, 59, 23, 31, 12, 9999, true), + "9999-12-31T23:59:59.99Z", "9999-12-31T23:59:59.990000000Z" ); + doTestTime( util::DateTime(999999999, 59, 59, 23, 31, 12, 9999, false), + "9999-12-31T23:59:59.9999999999999999999999999999999999999", + "9999-12-31T23:59:59.999999999" ); + doTestTime( util::DateTime(999999999, 59, 59, 23, 31, 12, 9999, true), + "9999-12-31T23:59:59.9999999999999999999999999999999999999Z", + "9999-12-31T23:59:59.999999999Z" ); + doTestTime( util::DateTime(0, 0, 0, 0, 29, 2, 2000, true), // leap year + "2000-02-29T00:00:00-00:00", "2000-02-29T00:00:00Z" ); + doTestTime( util::DateTime(0, 0, 0, 0, 29, 2, 1600, true), // leap year + "1600-02-29T00:00:00-00:00", "1600-02-29T00:00:00Z" ); + doTestTime( util::DateTime(0, 0, 0, 24, 1, 1, 333, false) + /*(0, 0, 0, 0, 2, 1, 333)*/, + "0333-01-01T24:00:00"/*, "0333-01-02T00:00:00"*/ ); + // While W3C XMLSchema specifies a minimum of 4 year digits we are lenient + // in what we accept. + doTestTime( util::DateTime(0, 0, 0, 0, 1, 1, 1, false), + "1-01-01T00:00:00", "0001-01-01T00:00:00" ); + + doTestTime( util::DateTime(0, 0, 0, 0, 0, 0, 0, false), "00:00:00" ); + doTestTime( util::DateTime(0, 0, 0, 24, 0, 0, 0, false), "24:00:00" ); + doTestTime( util::DateTime(0, 0, 59, 0, 0, 0, 0, false), "00:59:00" ); + doTestTime( util::DateTime(0, 1, 2, 4, 0, 0, 0, true), "04:02:01Z" ); + doTestTime( util::DateTime(0, 1, 2, 4, 0, 0, 0, true), + "05:02:01+01:00", "04:02:01Z" ); + doTestTime( util::DateTime(0, 11, 12, 9, 0, 0, 0, true), + "05:12:11-04:00", "09:12:11Z" ); + doTestTime( util::DateTime(990000000, 59, 59, 23, 0, 0, 0, false), + "23:59:59.99", "23:59:59.990000000" ); + doTestTime( util::DateTime(990000000, 59, 59, 23, 0, 0, 0, true), + "23:59:59.99Z", "23:59:59.990000000Z" ); + // backwards compatible: recognize invalid 0000-00-00 date (LO 3.5) + doTestTime( util::DateTime(0, 1, 0, 0, 0, 0, 0, false), + "0000-00-00T00:00:01", "00:00:01" ); + // backwards compatible: recognize invalid 0-00-00 date (OOo) + doTestTime( util::DateTime(0, 0, 1, 0, 0, 0, 0, false), + "0-00-00T00:01:00", "00:01:00" ); + + doTestTimeF( "+0001-01-01T00:00:00" ); // invalid: ^+ + doTestTimeF( "0001-1-01T00:00:00" ); // invalid: < 2 M + doTestTimeF( "0001-01-1T00:00:00" ); // invalid: < 2 D + doTestTimeF( "0001-01-01T0:00:00" ); // invalid: < 2 H + doTestTimeF( "0001-01-01T00:0:00" ); // invalid: < 2 M + doTestTimeF( "0001-01-01T00:00:0" ); // invalid: < 2 S + doTestTimeF( "0001-01-01T00:00:00." ); // invalid: .$ + doTestTimeF( "0001-01-01T00:00:00+1:00" ); // invalid: < 2 TZ H + doTestTimeF( "0001-01-01T00:00:00+00:1" ); // invalid: < 2 TZ M + doTestTimeF( "0001-13-01T00:00:00" ); // invalid: M > 12 + doTestTimeF( "0001-01-32T00:00:00" ); // invalid: D > 31 + doTestTimeF( "0001-01-01T25:00:00" ); // invalid: H > 24 + doTestTimeF( "0001-01-01T00:60:00" ); // invalid: M > 59 + doTestTimeF( "0001-01-01T00:00:60" ); // invalid: S > 59 + doTestTimeF( "0001-01-01T24:01:00" ); // invalid: H=24, but M != 0 + doTestTimeF( "0001-01-01T24:00:01" ); // invalid: H=24, but S != 0 + doTestTimeF( "0001-01-01T24:00:00.1" ); // invalid: H=24, but H != 0 + doTestTimeF( "0001-01-02T00:00:00+15:00" ); // invalid: TZ > +14:00 + doTestTimeF( "0001-01-02T00:00:00+14:01" ); // invalid: TZ > +14:00 + doTestTimeF( "0001-01-02T00:00:00-15:00" ); // invalid: TZ < -14:00 + doTestTimeF( "0001-01-02T00:00:00-14:01" ); // invalid: TZ < -14:00 + doTestTimeF( "2100-02-29T00:00:00-00:00" ); // invalid: no leap year + doTestTimeF( "1900-02-29T00:00:00-00:00" ); // invalid: no leap year + doTestTimeF( "T00:00:00" ); // invalid: T + doTestTimeF( "0:00:00" ); // invalid: < 2 H + doTestTimeF( "00:0:00" ); // invalid: < 2 M + doTestTimeF( "00:00:0" ); // invalid: < 2 S + doTestTimeF( "00:00:00." ); // invalid: .$ + doTestTimeF( "00:00:00+1:00" ); // invalid: < 2 TZ H + doTestTimeF( "00:00:00+00:1" ); // invalid: < 2 TZ M + doTestTimeF( "25:00:00" ); // invalid: H > 24 + doTestTimeF( "00:60:00" ); // invalid: M > 59 + doTestTimeF( "00:00:60" ); // invalid: S > 59 + doTestTimeF( "24:01:00" ); // invalid: H=24, but M != 0 + doTestTimeF( "24:00:01" ); // invalid: H=24, but S != 0 + doTestTimeF( "24:00:00.1" ); // invalid: H=24, but H != 0 + doTestTimeF( "00:00:00+15:00" ); // invalid: TZ > +14:00 + doTestTimeF( "00:00:00+14:01" ); // invalid: TZ > +14:00 + doTestTimeF( "00:00:00-15:00" ); // invalid: TZ < -14:00 + doTestTimeF( "00:00:00-14:01" ); // invalid: TZ < -14:00 +} + +void doTestDouble(char const*const pis, double const rd, + sal_Int16 const nSourceUnit, sal_Int16 const nTargetUnit) +{ + OUString const is(OUString::createFromAscii(pis)); + double od; + bool bSuccess(Converter::convertDouble(od, is, nSourceUnit, nTargetUnit)); + SAL_INFO("sax.cppunit","" << od); + CPPUNIT_ASSERT(bSuccess); + CPPUNIT_ASSERT_DOUBLES_EQUAL(rd, od, 0.00000001); + OUStringBuffer buf; + Converter::convertDouble(buf, od, true, nTargetUnit, nSourceUnit); + SAL_INFO("sax.cppunit","" << buf.toString()); + CPPUNIT_ASSERT_EQUAL(is, buf.makeStringAndClear()); +} + +void ConverterTest::testDouble() +{ + doTestDouble("42", 42.0, MeasureUnit::TWIP, MeasureUnit::TWIP); + doTestDouble("42", 42.0, MeasureUnit::POINT, MeasureUnit::POINT); + doTestDouble("42", 42.0, MeasureUnit::MM_100TH, MeasureUnit::MM_100TH); + doTestDouble("42", 42.0, MeasureUnit::MM_10TH, MeasureUnit::MM_10TH); + doTestDouble("42", 42.0, MeasureUnit::MM, MeasureUnit::MM); // identity don't seem to add unit? + doTestDouble("42", 42.0, MeasureUnit::CM, MeasureUnit::CM); + doTestDouble("42", 42.0, MeasureUnit::INCH, MeasureUnit::INCH); + doTestDouble("2pt", 40.0, MeasureUnit::POINT, MeasureUnit::TWIP); + doTestDouble("20pc", 1, MeasureUnit::TWIP, MeasureUnit::POINT); + doTestDouble("4", 2.26771653543307, MeasureUnit::MM_100TH, MeasureUnit::TWIP); + doTestDouble("4", 22.6771653543307, MeasureUnit::MM_10TH, MeasureUnit::TWIP); + doTestDouble("4mm", 226.771653543307, MeasureUnit::MM, MeasureUnit::TWIP); + doTestDouble("4cm", 2267.71653543307, MeasureUnit::CM, MeasureUnit::TWIP); + doTestDouble("4in", 5760.0, MeasureUnit::INCH, MeasureUnit::TWIP); + doTestDouble("1440pc", 1.0, MeasureUnit::TWIP, MeasureUnit::INCH); + doTestDouble("567pc", 1.000125, MeasureUnit::TWIP, MeasureUnit::CM); + doTestDouble("56.7pc", 1.000125, MeasureUnit::TWIP, MeasureUnit::MM); + doTestDouble("5.67pc", 1.000125, MeasureUnit::TWIP, MeasureUnit::MM_10TH); + doTestDouble("0.567pc", 1.000125, MeasureUnit::TWIP, MeasureUnit::MM_100TH); + doTestDouble("42pt", 1.4816666666666, MeasureUnit::POINT, MeasureUnit::CM); + doTestDouble("42pt", 14.816666666666, MeasureUnit::POINT, MeasureUnit::MM); + doTestDouble("42pt", 148.16666666666, MeasureUnit::POINT, MeasureUnit::MM_10TH); + doTestDouble("42pt", 1481.6666666666, MeasureUnit::POINT, MeasureUnit::MM_100TH); + doTestDouble("72pt", 1.0, MeasureUnit::POINT, MeasureUnit::INCH); + doTestDouble("3.5in", 8.89, MeasureUnit::INCH, MeasureUnit::CM); + doTestDouble("3.5in", 88.9, MeasureUnit::INCH, MeasureUnit::MM); + doTestDouble("3.5in", 889.0, MeasureUnit::INCH, MeasureUnit::MM_10TH); + doTestDouble("3.5in", 8890.0, MeasureUnit::INCH, MeasureUnit::MM_100TH); + doTestDouble("2in", 144, MeasureUnit::INCH, MeasureUnit::POINT); + doTestDouble("5.08cm", 2.0, MeasureUnit::CM, MeasureUnit::INCH); + doTestDouble("3.5cm", 3500.0, MeasureUnit::CM, MeasureUnit::MM_100TH); + doTestDouble("3.5cm", 350.0, MeasureUnit::CM, MeasureUnit::MM_10TH); + doTestDouble("3.5cm", 35.0, MeasureUnit::CM, MeasureUnit::MM); + doTestDouble("10cm", 283.464566929134, MeasureUnit::CM, MeasureUnit::POINT); + doTestDouble("0.5cm", 283.464566929134, MeasureUnit::CM, MeasureUnit::TWIP); + doTestDouble("10mm", 28.3464566929134, MeasureUnit::MM, MeasureUnit::POINT); + doTestDouble("0.5mm", 28.3464566929134, MeasureUnit::MM, MeasureUnit::TWIP); + doTestDouble("10", 2.83464566929134, MeasureUnit::MM_10TH, MeasureUnit::POINT); + doTestDouble("0.5", 2.83464566929134, MeasureUnit::MM_10TH, MeasureUnit::TWIP); + doTestDouble("10", 0.283464566929134, MeasureUnit::MM_100TH, MeasureUnit::POINT); + doTestDouble("0.5", 0.283464566929134, MeasureUnit::MM_100TH, MeasureUnit::TWIP); + doTestDouble("10mm", 1.0, MeasureUnit::MM, MeasureUnit::CM); + doTestDouble("10mm", 100.0, MeasureUnit::MM, MeasureUnit::MM_10TH); + doTestDouble("20mm", 2000.0, MeasureUnit::MM, MeasureUnit::MM_100TH); + doTestDouble("300", 30.0, MeasureUnit::MM_10TH, MeasureUnit::MM); + doTestDouble("400", 4.0, MeasureUnit::MM_100TH, MeasureUnit::MM); + doTestDouble("600", 6000.0, MeasureUnit::MM_10TH, MeasureUnit::MM_100TH); + doTestDouble("700", 70.0, MeasureUnit::MM_100TH, MeasureUnit::MM_10TH); +} + +void doTestStringToMeasure(sal_Int32 rValue, char const*const pis, sal_Int16 nTargetUnit, sal_Int32 nMin, sal_Int32 nMax) +{ + OUString const is(OUString::createFromAscii(pis)); + sal_Int32 nVal; + bool bSuccess(Converter::convertMeasure(nVal, is, nTargetUnit, nMin, nMax)); + SAL_INFO("sax.cppunit","" << nVal); + CPPUNIT_ASSERT(bSuccess); + CPPUNIT_ASSERT_EQUAL(rValue, nVal); +} + +void doTestMeasureToString(char const*const pis, sal_Int32 nMeasure, sal_Int16 const nSourceUnit, sal_Int16 const nTargetUnit) +{ + OUString const is(OUString::createFromAscii(pis)); + OUStringBuffer buf; + Converter::convertMeasure(buf, nMeasure, nSourceUnit, nTargetUnit); + SAL_INFO("sax.cppunit","" << buf.toString()); + CPPUNIT_ASSERT_EQUAL(is, buf.makeStringAndClear()); +} + +void ConverterTest::testMeasure() +{ + //check all the measure units + doTestStringToMeasure(1000, "10mm", MeasureUnit::MM_100TH, -1, 4321); + doTestStringToMeasure(200, "20mm", MeasureUnit::MM_10TH, 12, 4567); + doTestStringToMeasure(300, "300", MeasureUnit::MM, 31, 555); + doTestStringToMeasure(400, "400", MeasureUnit::CM, 10, 4321); + doTestStringToMeasure(120, "120", MeasureUnit::INCH_1000TH, 10, 4321); + doTestStringToMeasure(111, "111", MeasureUnit::INCH_100TH, 10, 4321); + doTestStringToMeasure(22, "22", MeasureUnit::INCH_10TH, 10, 4321); + doTestStringToMeasure(27, "27", MeasureUnit::INCH, 10, 4321); + doTestStringToMeasure(52, "52", MeasureUnit::POINT, 10, 4321); + doTestStringToMeasure(120, "120", MeasureUnit::TWIP, 10, 4321); + doTestStringToMeasure(666, "666", MeasureUnit::M, 10, 4321); + doTestStringToMeasure(42, "42", MeasureUnit::KM, 10, 4321); + doTestStringToMeasure(30, "30", MeasureUnit::PICA, 10, 4321); + doTestStringToMeasure(20, "20", MeasureUnit::FOOT, 10, 4321); + doTestStringToMeasure(40, "40", MeasureUnit::MILE, 10, 4321); + doTestStringToMeasure(40, "40%", MeasureUnit::PERCENT, 10, 4321); + doTestStringToMeasure(800, "800", MeasureUnit::PIXEL, 10, 4321); + doTestStringToMeasure(600, "600px", MeasureUnit::PIXEL, 10, 4321); + doTestStringToMeasure(777, "777", MeasureUnit::APPFONT, 10, 4321); + doTestStringToMeasure(80000, "80000", MeasureUnit::SYSFONT, 10, 432100); + //strange values (negative, too large etc.) + doTestStringToMeasure(555, "666", MeasureUnit::MM, -1000, 555); + doTestStringToMeasure(-1000, "-1001", MeasureUnit::MM, -1000, 555); + doTestStringToMeasure(0, "-0", MeasureUnit::MM, -1, 0); + doTestStringToMeasure(::std::numeric_limits<sal_Int32>::max(), "1234567890mm", MeasureUnit::MM_10TH, 12, ::std::numeric_limits<sal_Int32>::max()); + doTestStringToMeasure(-300, "-300", MeasureUnit::MM, -1000, 555); + doTestStringToMeasure(::std::numeric_limits<sal_Int32>::min(), "-999999999999999px", MeasureUnit::PIXEL, ::std::numeric_limits<sal_Int32>::min(), 555); //really crazy numbers... + + doTestMeasureToString("6mm", 600, MeasureUnit::MM_100TH, MeasureUnit::MM); + doTestMeasureToString("0.005cm", 000000005, MeasureUnit::MM_100TH, MeasureUnit::CM); // zeros in the front doesn't count + doTestMeasureToString("3mm", 30, MeasureUnit::MM_10TH, MeasureUnit::MM); + doTestMeasureToString("6.66cm", 666, MeasureUnit::MM_10TH, MeasureUnit::CM); + doTestMeasureToString("-157.3pt", -555, MeasureUnit::MM_10TH, MeasureUnit::POINT); + doTestMeasureToString("174976.378in", 44444000, MeasureUnit::MM_10TH, MeasureUnit::INCH); //let's check accuracy + doTestMeasureToString("40%", 40, MeasureUnit::PERCENT, MeasureUnit::PERCENT); + doTestMeasureToString("70.56mm", 4000, MeasureUnit::TWIP, MeasureUnit::MM); + doTestMeasureToString("979.928cm", 555550, MeasureUnit::TWIP, MeasureUnit::CM); + doTestMeasureToString("111.1pt", 2222, MeasureUnit::TWIP, MeasureUnit::POINT); + doTestMeasureToString("385.7986in", 555550, MeasureUnit::TWIP, MeasureUnit::INCH); + doTestMeasureToString("-2147483.648cm", std::numeric_limits<sal_Int32>::min(), MeasureUnit::MM_100TH, MeasureUnit::CM); +} + +void doTestStringToBool(bool bBool, char const*const pis) +{ + OUString const is(OUString::createFromAscii(pis)); + bool bTemp; + bool bSuccess(Converter::convertBool(bTemp, is)); + SAL_INFO("sax.cppunit","" << bTemp); + CPPUNIT_ASSERT(bSuccess); + CPPUNIT_ASSERT_EQUAL(bBool, bTemp); + +} + +void doTestBoolToString(char const*const pis, bool bValue ) +{ + OUString const is(OUString::createFromAscii(pis)); + OUStringBuffer buf; + Converter::convertBool(buf, bValue); + SAL_INFO("sax.cppunit","" << buf.toString()); + CPPUNIT_ASSERT_EQUAL(is, buf.makeStringAndClear()); +} + +void ConverterTest::testBool() +{ + doTestStringToBool(true, "true"); + doTestStringToBool(false, "false"); + doTestBoolToString("true", true); + doTestBoolToString("false", false); +} + +void doTestStringToPercent(sal_Int32 nValue, char const*const pis) +{ + OUString const is(OUString::createFromAscii(pis)); + sal_Int32 nTemp; + bool bSuccess(Converter::convertPercent(nTemp, is)); + SAL_INFO("sax.cppunit","" << nTemp); + CPPUNIT_ASSERT(bSuccess); + CPPUNIT_ASSERT_EQUAL(nValue, nTemp); +} + +void doTestPercentToString(char const*const pis, sal_Int32 nValue) +{ + OUString const is(OUString::createFromAscii(pis)); + OUStringBuffer buf; + Converter::convertPercent(buf, nValue); + SAL_INFO("sax.cppunit","" << buf.toString()); + CPPUNIT_ASSERT_EQUAL(is, buf.makeStringAndClear()); +} + +void ConverterTest::testPercent() +{ + doTestStringToPercent(40, "40%"); + doTestStringToPercent(30, "30"); + doTestStringToPercent(120, "120%"); + doTestStringToPercent(-40, "-40%"); + doTestStringToPercent(0, "0%"); + doTestPercentToString("12%", 12); + doTestPercentToString("-123%", -123); + doTestPercentToString("0%", 0); + doTestPercentToString("1%", 00001); +} + +void doTestStringToColor(sal_Int32 nValue, char const*const pis) +{ + OUString const is(OUString::createFromAscii(pis)); + sal_Int32 nTemp; + bool bSuccess(Converter::convertColor(nTemp, is)); + SAL_INFO("sax.cppunit","" << nTemp); + CPPUNIT_ASSERT(bSuccess); + CPPUNIT_ASSERT_EQUAL(nValue, nTemp); +} + +void doTestColorToString(char const*const pis, sal_Int32 nValue) +{ + OUString const is(OUString::createFromAscii(pis)); + OUStringBuffer buf; + Converter::convertColor(buf, nValue); + SAL_INFO("sax.cppunit","" << buf.toString()); + CPPUNIT_ASSERT_EQUAL(is, buf.makeStringAndClear()); +} + +void ConverterTest::testColor() +{ + doTestStringToColor(11259375, "#abcdef"); + doTestStringToColor(160, "#0000a0"); + doTestStringToColor(40960, "#00a000"); + doTestStringToColor(0, "#000000"); + doTestColorToString("#000615", 1557); + doTestColorToString("#5bcd15", 123456789); + doTestColorToString("#fffac7", -1337); + doTestColorToString("#000000", 0); +} + +void doTestStringToNumber(sal_Int32 nValue, char const*const pis, sal_Int32 nMin, sal_Int32 nMax) +{ + OUString const is(OUString::createFromAscii(pis)); + sal_Int32 nTemp; + bool bSuccess(Converter::convertNumber(nTemp, is, nMin, nMax)); + SAL_INFO("sax.cppunit","" << nTemp); + CPPUNIT_ASSERT(bSuccess); + CPPUNIT_ASSERT_EQUAL(nValue, nTemp); +} + +void ConverterTest::testNumber() +{ + doTestStringToNumber(30, "30", 1, 40); + doTestStringToNumber(1, "-5", 1, 300); + doTestStringToNumber(-30, "7", -100, -30); + doTestStringToNumber(0, "-0", 0, 1); + doTestStringToNumber(0, "666", -0, 0); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ConverterTest); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sax/qa/cppunit/xmlimport.cxx b/sax/qa/cppunit/xmlimport.cxx new file mode 100644 index 000000000..1eb872d50 --- /dev/null +++ b/sax/qa/cppunit/xmlimport.cxx @@ -0,0 +1,454 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#include <sal/config.h> +#include <sal/types.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> +#include <test/bootstrapfixture.hxx> +#include <cppuhelper/implbase.hxx> +#include <com/sun/star/beans/Pair.hpp> +#include <com/sun/star/xml/sax/SAXException.hpp> +#include <com/sun/star/xml/sax/XDocumentHandler.hpp> +#include <com/sun/star/xml/sax/XFastTokenHandler.hpp> +#include <comphelper/processfactory.hxx> +#include <com/sun/star/xml/sax/Parser.hpp> +#include <com/sun/star/xml/sax/XParser.hpp> +#include <com/sun/star/xml/sax/XLocator.hpp> +#include <com/sun/star/xml/sax/FastToken.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <osl/file.hxx> +#include <unotools/ucbstreamhelper.hxx> +#include <unotools/streamwrap.hxx> +#include <sax/fastattribs.hxx> +#include <stack> +#include <string_view> +#include <deque> +#include <rtl/ref.hxx> + + +namespace { + +using namespace css; +using namespace uno; +using namespace io; +using namespace xml::sax; +using namespace ::osl; +using namespace sax_fastparser; + +Reference< XInputStream > createStreamFromFile ( + const OUString & filePath) +{ + Reference< XInputStream > xInputStream; + OUString aInStr; + FileBase::getFileURLFromSystemPath(filePath, aInStr); + std::unique_ptr<SvStream> pStream = utl::UcbStreamHelper::CreateStream(aInStr, StreamMode::READ); + if(pStream == nullptr) + CPPUNIT_ASSERT(false); + Reference< XStream > xStream(new utl::OStreamWrapper(std::move(pStream))); + xInputStream.set(xStream, UNO_QUERY); + return xInputStream; +} + +class TestDocumentHandler : public cppu::WeakImplHelper< XDocumentHandler > +{ +private: + OUString m_aStr; + std::deque< std::pair<OUString,OUString> > m_aNamespaceStack; + std::stack<sal_uInt16> m_aCountStack; + + OUString canonicalform(const OUString &sName, const OUString &sValue, bool isElement); + OUString getNamespace(std::u16string_view sName); + +public: + TestDocumentHandler() {} + const OUString & getString() const { return m_aStr; } + + // XDocumentHandler + virtual void SAL_CALL startDocument() override; + virtual void SAL_CALL endDocument() override; + virtual void SAL_CALL startElement( const OUString& aName, const Reference< XAttributeList >& xAttribs ) override; + virtual void SAL_CALL endElement( const OUString& aName ) override; + virtual void SAL_CALL characters( const OUString& aChars ) override; + virtual void SAL_CALL ignorableWhitespace( const OUString& aWhitespaces ) override; + virtual void SAL_CALL processingInstruction( const OUString& aTarget, const OUString& aData ) override; + virtual void SAL_CALL setDocumentLocator( const Reference< XLocator >& xLocator ) override; +}; + +OUString TestDocumentHandler::canonicalform(const OUString &sName, const OUString &sValue, bool isElement) +{ + sal_Int16 nIndex = sName.indexOf(":"); + if ( !isElement && sName.match( "xmlns" ) ) + { + m_aCountStack.top() += 1; + if ( nIndex < 0 ) + m_aNamespaceStack.emplace_back( OUString( "default" ), sValue ); + else + m_aNamespaceStack.emplace_back( sName.copy( nIndex + 1 ), sValue ); + } + else + { + if ( nIndex >= 0 ) + { + OUString sNamespace = getNamespace( sName.subView( 0, nIndex ) ); + return sNamespace + sName.subView(nIndex); + } + else + { + OUString sDefaultns = getNamespace( u"default" ); + if ( !isElement || sDefaultns.isEmpty() ) + return sName; + else + return sDefaultns + ":" + sName; + } + } + return OUString(); +} + +OUString TestDocumentHandler::getNamespace(std::u16string_view sName) +{ + for (sal_Int16 i = m_aNamespaceStack.size() - 1; i>=0; i--) + { + std::pair<OUString, OUString> aPair = m_aNamespaceStack.at(i); + if (aPair.first == sName) + return aPair.second; + } + return OUString(); +} + +void SAL_CALL TestDocumentHandler::startDocument() +{ + m_aStr.clear(); + m_aNamespaceStack.clear(); + m_aNamespaceStack.emplace_back( std::make_pair( OUString( "default" ), OUString() ) ); + m_aCountStack = std::stack<sal_uInt16>(); + m_aCountStack.emplace(0); +} + + +void SAL_CALL TestDocumentHandler::endDocument() +{ +} + +void SAL_CALL TestDocumentHandler::startElement( const OUString& aName, const Reference< XAttributeList >& xAttribs ) +{ + OUString sAttributes; + m_aCountStack.push(0); + sal_uInt16 len = xAttribs->getLength(); + for (sal_uInt16 i=0; i<len; i++) + { + OUString sAttrValue = xAttribs->getValueByIndex(i); + OUString sAttrName = canonicalform(xAttribs->getNameByIndex(i), sAttrValue, false); + if (!sAttrName.isEmpty()) + sAttributes += sAttrName + sAttrValue; + } + m_aStr += canonicalform(aName, "", true) + sAttributes; +} + + +void SAL_CALL TestDocumentHandler::endElement( const OUString& aName ) +{ + m_aStr += canonicalform(aName, "", true); + sal_uInt16 nPopQty = m_aCountStack.top(); + for (sal_uInt16 i=0; i<nPopQty; i++) + m_aNamespaceStack.pop_back(); + m_aCountStack.pop(); +} + + +void SAL_CALL TestDocumentHandler::characters( const OUString& aChars ) +{ + m_aStr += aChars; +} + + +void SAL_CALL TestDocumentHandler::ignorableWhitespace( const OUString& aWhitespaces ) +{ + m_aStr += aWhitespaces; +} + + +void SAL_CALL TestDocumentHandler::processingInstruction( const OUString& aTarget, const OUString& aData ) +{ + m_aStr += aTarget + aData; +} + + +void SAL_CALL TestDocumentHandler::setDocumentLocator( const Reference< XLocator >& /*xLocator*/ ) +{ +} + +class NSDocumentHandler : public cppu::WeakImplHelper< XDocumentHandler > +{ +public: + NSDocumentHandler() {} + + // XDocumentHandler + virtual void SAL_CALL startDocument() override {} + virtual void SAL_CALL endDocument() override {} + virtual void SAL_CALL startElement( const OUString& aName, const Reference< XAttributeList >& xAttribs ) override; + virtual void SAL_CALL endElement( const OUString& /* aName */ ) override {} + virtual void SAL_CALL characters( const OUString& /* aChars */ ) override {} + virtual void SAL_CALL ignorableWhitespace( const OUString& /* aWhitespaces */ ) override {} + virtual void SAL_CALL processingInstruction( const OUString& /* aTarget */, const OUString& /* aData */ ) override {} + virtual void SAL_CALL setDocumentLocator( const Reference< XLocator >& /* xLocator */ ) override {} +}; + +OUString getNamespaceValue( std::u16string_view rNamespacePrefix ) +{ + OUString aNamespaceURI; + if (rNamespacePrefix == u"office") + aNamespaceURI = "urn:oasis:names:tc:opendocument:xmlns:office:1.0"; + else if (rNamespacePrefix == u"text") + aNamespaceURI = "urn:oasis:names:tc:opendocument:xmlns:text:1.0"; + else if (rNamespacePrefix == u"note") + aNamespaceURI = "urn:oasis:names:tc:opendocument:xmlns:text:1.0"; + return aNamespaceURI; +} + +OUString resolveNamespace( const OUString& aName ) +{ + int index; + if (( index = aName.indexOf( ':' )) > 0 ) + { + if ( aName.getLength() > index + 1 ) + { + OUString aAttributeName = getNamespaceValue( aName.subView( 0, index ) ) + + ":" + aName.subView( index + 1 ); + return aAttributeName; + } + } + return aName; +} + +void SAL_CALL NSDocumentHandler::startElement( const OUString& aName, const Reference< XAttributeList >&/* xAttribs */ ) +{ + if (! (aName == "office:document" || aName == "office:body" || aName == "office:text" || + aName == "text:p" || aName == "note:p") ) + CPPUNIT_ASSERT(false); + + OUString sResolvedName = resolveNamespace(aName); + if (! ( sResolvedName == "urn:oasis:names:tc:opendocument:xmlns:office:1.0:document" || + sResolvedName == "urn:oasis:names:tc:opendocument:xmlns:office:1.0:body" || + sResolvedName == "urn:oasis:names:tc:opendocument:xmlns:office:1.0:text" || + sResolvedName == "urn:oasis:names:tc:opendocument:xmlns:text:1.0:p") ) + CPPUNIT_ASSERT(false); +} + +class DummyTokenHandler : public sax_fastparser::FastTokenHandlerBase +{ +public: + const static std::string_view tokens[]; + const static std::u16string_view namespaceURIs[]; + const static std::string_view namespacePrefixes[]; + + // XFastTokenHandler + virtual Sequence< sal_Int8 > SAL_CALL getUTF8Identifier( sal_Int32 nToken ) override; + virtual sal_Int32 SAL_CALL getTokenFromUTF8( const css::uno::Sequence< sal_Int8 >& Identifier ) override; + //FastTokenHandlerBase + virtual sal_Int32 getTokenDirect( const char *pToken, sal_Int32 nLength ) const override; +}; + +const std::string_view DummyTokenHandler::tokens[] = { + "Signature", "CanonicalizationMethod", + "Algorithm", "Type", + "DigestMethod", "Reference", + "document", "spacing", + "Player", "Height" }; + +const std::u16string_view DummyTokenHandler::namespaceURIs[] = { + u"http://www.w3.org/2000/09/xmldsig#", + u"http://schemas.openxmlformats.org/wordprocessingml/2006/main/", + u"xyzsports.com/players/football/" }; + +const std::string_view DummyTokenHandler::namespacePrefixes[] = { + "", + "w", + "Player" }; + +Sequence< sal_Int8 > DummyTokenHandler::getUTF8Identifier( sal_Int32 nToken ) +{ + std::string_view aUtf8Token; + if ( ( nToken & 0xffff0000 ) != 0 ) //namespace + { + sal_uInt32 nNamespaceToken = ( nToken >> 16 ) - 1; + if ( nNamespaceToken < std::size(namespacePrefixes) ) + aUtf8Token = namespacePrefixes[ nNamespaceToken ]; + } + else //element or attribute + { + size_t nElementToken = nToken & 0xffff; + if ( nElementToken < std::size(tokens) ) + aUtf8Token = tokens[ nElementToken ]; + } + Sequence< sal_Int8 > aSeq( reinterpret_cast< const sal_Int8* >( + aUtf8Token.data() ), aUtf8Token.size() ); + return aSeq; +} + +sal_Int32 DummyTokenHandler::getTokenFromUTF8( const uno::Sequence< sal_Int8 >& rIdentifier ) +{ + return getTokenDirect( reinterpret_cast< const char* >( + rIdentifier.getConstArray() ), rIdentifier.getLength() ); +} + +sal_Int32 DummyTokenHandler::getTokenDirect( const char* pToken, sal_Int32 nLength ) const +{ + std::string_view sToken( pToken, nLength ); + for( size_t i = 0; i < std::size(tokens); i++ ) + { + if ( tokens[i] == sToken ) + return static_cast<sal_Int32>(i); + } + return FastToken::DONTKNOW; +} + + +class XMLImportTest : public test::BootstrapFixture +{ +private: + OUString m_sDirPath; + rtl::Reference< TestDocumentHandler > m_xDocumentHandler; + Reference< XParser > m_xParser; + Reference< XParser > m_xLegacyFastParser; + +public: + virtual void setUp() override; + + XMLImportTest() : BootstrapFixture(true, false) {} + void parse(); + void testMissingNamespaceDeclaration(); + void testIllegalNamespaceUse(); + + CPPUNIT_TEST_SUITE( XMLImportTest ); + CPPUNIT_TEST( parse ); + CPPUNIT_TEST( testMissingNamespaceDeclaration ); + CPPUNIT_TEST( testIllegalNamespaceUse ); + CPPUNIT_TEST_SUITE_END(); +}; + +void XMLImportTest::setUp() +{ + test::BootstrapFixture::setUp(); + Reference< XComponentContext > xContext = comphelper::getProcessComponentContext(); + m_xDocumentHandler.set( new TestDocumentHandler() ); + m_xParser = Parser::create( xContext ); + m_xParser->setDocumentHandler( m_xDocumentHandler ); + m_xLegacyFastParser.set( xContext->getServiceManager()->createInstanceWithContext + ( "com.sun.star.xml.sax.LegacyFastParser", xContext ), UNO_QUERY ); + m_xLegacyFastParser->setDocumentHandler( m_xDocumentHandler ); + + Reference< XFastTokenHandler > xTokenHandler; + xTokenHandler.set( new DummyTokenHandler ); + uno::Reference<lang::XInitialization> const xInit(m_xLegacyFastParser, + uno::UNO_QUERY_THROW); + xInit->initialize({ uno::Any(xTokenHandler) }); + + sal_Int32 nNamespaceCount = SAL_N_ELEMENTS(DummyTokenHandler::namespaceURIs); + uno::Sequence<uno::Any> namespaceArgs( nNamespaceCount + 1 ); + auto p_namespaceArgs = namespaceArgs.getArray(); + p_namespaceArgs[0] <<= OUString( "registerNamespaces" ); + for (sal_Int32 i = 1; i <= nNamespaceCount; i++ ) + { + css::beans::Pair<OUString, sal_Int32> rPair( OUString(DummyTokenHandler::namespaceURIs[i - 1]), i << 16 ); + p_namespaceArgs[i] <<= rPair; + } + xInit->initialize( namespaceArgs ); + + m_sDirPath = m_directories.getPathFromSrc( u"/sax/qa/data/" ); +} + +void XMLImportTest::parse() +{ + OUString fileNames[] = {"simple.xml", "defaultns.xml", "inlinens.xml", + "multiplens.xml", "multiplepfx.xml", + "nstoattributes.xml", "nestedns.xml", "testthreading.xml"}; + + for (size_t i = 0; i < std::size( fileNames ); i++) + { + InputSource source; + source.sSystemId = "internal"; + + source.aInputStream = createStreamFromFile( m_sDirPath + fileNames[i] ); + m_xParser->parseStream(source); + const OUString rParserStr = m_xDocumentHandler->getString(); + + source.aInputStream = createStreamFromFile( m_sDirPath + fileNames[i] ); + m_xLegacyFastParser->parseStream(source); + const OUString rLegacyFastParserStr = m_xDocumentHandler->getString(); + + CPPUNIT_ASSERT_EQUAL( rParserStr, rLegacyFastParserStr ); + // OString o = OUStringToOString( Str, RTL_TEXTENCODING_ASCII_US ); + // CPPUNIT_ASSERT_MESSAGE( string(o.pData->buffer), false ); + } +} + +void XMLImportTest::testMissingNamespaceDeclaration() +{ + OUString fileNames[] = { "manifestwithnsdecl.xml", "manifestwithoutnsdecl.xml" }; + + uno::Reference<lang::XInitialization> const xInit(m_xLegacyFastParser, + uno::UNO_QUERY_THROW); + xInit->initialize({ uno::Any(OUString("IgnoreMissingNSDecl")) }); + + for (sal_uInt16 i = 0; i < std::size( fileNames ); i++) + { + try + { + InputSource source; + source.sSystemId = "internal"; + + source.aInputStream = createStreamFromFile( m_sDirPath + fileNames[i] ); + m_xParser->parseStream(source); + const OUString rParserStr = m_xDocumentHandler->getString(); + + source.aInputStream = createStreamFromFile( m_sDirPath + fileNames[i] ); + m_xLegacyFastParser->parseStream(source); + const OUString rLegacyFastParserStr = m_xDocumentHandler->getString(); + + CPPUNIT_ASSERT_EQUAL( rParserStr, rLegacyFastParserStr ); + } + catch( const SAXException & ) + { + } + } +} + +void XMLImportTest::testIllegalNamespaceUse() +{ + rtl::Reference< NSDocumentHandler > m_xNSDocumentHandler; + m_xNSDocumentHandler.set( new NSDocumentHandler() ); + m_xParser->setDocumentHandler( m_xNSDocumentHandler ); + InputSource source; + source.sSystemId = "internal"; + + source.aInputStream = createStreamFromFile( m_sDirPath + "multiplepfx.xml" ); + m_xParser->parseStream(source); + + m_xLegacyFastParser->setDocumentHandler( m_xNSDocumentHandler ); + source.aInputStream = createStreamFromFile( m_sDirPath + "multiplepfx.xml" ); + m_xLegacyFastParser->parseStream(source); +} + +CPPUNIT_TEST_SUITE_REGISTRATION( XMLImportTest ); +} //namespace + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sax/qa/data/defaultns.xml b/sax/qa/data/defaultns.xml new file mode 100644 index 000000000..2e7819b16 --- /dev/null +++ b/sax/qa/data/defaultns.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" ?> +<Books xmlns="http://xyzbooks.com/books/"> + <Book> + <Title>War and Peace</Title> + <Author>Leo Tolstoy</Author> + </Book> + <Book> + <Title>To Kill a Mockingbird</Title> + <Author>Harper Lee</Author> + </Book> +</Books> diff --git a/sax/qa/data/inlinens.xml b/sax/qa/data/inlinens.xml new file mode 100644 index 000000000..02c421408 --- /dev/null +++ b/sax/qa/data/inlinens.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" ?> +<Students xmlns="http://xyzuniversity.org/student/"> + <Student xmlns:ug="http://xyzuniversity.org/student/ug/"> + <Name>ABC</Name> + <ug:Branch>Computer Science</ug:Branch> + <ug:Grade>7.9</ug:Grade> + </Student> + <Student xmlns:pg="http://xyzuniversity.org/student/pg/"> + <Name>PQR</Name> + <pg:Field>Artificial Intelligence</pg:Field> + </Student> +</Students>
\ No newline at end of file diff --git a/sax/qa/data/manifestwithnsdecl.xml b/sax/qa/data/manifestwithnsdecl.xml new file mode 100644 index 000000000..ac61c3e20 --- /dev/null +++ b/sax/qa/data/manifestwithnsdecl.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0" manifest:version="1.2"> + <manifest:file-entry manifest:full-path="/" manifest:version="1.2" manifest:media-type="application/vnd.oasis.opendocument.text"/> + <manifest:file-entry manifest:full-path="Thumbnails/thumbnail.png" manifest:media-type="image/png"/> + <manifest:file-entry manifest:full-path="content.xml" manifest:media-type="text/xml"/> + <manifest:file-entry manifest:full-path="styles.xml" manifest:media-type="text/xml"/> + <manifest:file-entry manifest:full-path="meta.xml" manifest:media-type="text/xml"/> + <manifest:file-entry manifest:full-path="settings.xml" manifest:media-type="text/xml"/> + <manifest:file-entry manifest:full-path="Configurations2/accelerator/current.xml" manifest:media-type=""/> + <manifest:file-entry manifest:full-path="Configurations2/" manifest:media-type="application/vnd.sun.xml.ui.configuration"/> + <manifest:file-entry manifest:full-path="manifest.rdf" manifest:media-type="application/rdf+xml"/> +</manifest:manifest> diff --git a/sax/qa/data/manifestwithoutnsdecl.xml b/sax/qa/data/manifestwithoutnsdecl.xml new file mode 100644 index 000000000..1c8f53596 --- /dev/null +++ b/sax/qa/data/manifestwithoutnsdecl.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<manifest:manifest> + <manifest:file-entry manifest:full-path="/" manifest:version="1.2" manifest:media-type="application/vnd.oasis.opendocument.text"/> + <manifest:file-entry manifest:full-path="Thumbnails/thumbnail.png" manifest:media-type="image/png"/> + <manifest:file-entry manifest:full-path="content.xml" manifest:media-type="text/xml"/> + <manifest:file-entry manifest:full-path="styles.xml" manifest:media-type="text/xml"/> + <manifest:file-entry manifest:full-path="meta.xml" manifest:media-type="text/xml"/> + <manifest:file-entry manifest:full-path="settings.xml" manifest:media-type="text/xml"/> + <manifest:file-entry manifest:full-path="Configurations2/accelerator/current.xml" manifest:media-type=""/> + <manifest:file-entry manifest:full-path="Configurations2/" manifest:media-type="application/vnd.sun.xml.ui.configuration"/> + <manifest:file-entry manifest:full-path="manifest.rdf" manifest:media-type="application/rdf+xml"/> +</manifest:manifest> diff --git a/sax/qa/data/multiplens.xml b/sax/qa/data/multiplens.xml new file mode 100644 index 000000000..e1dc4ce01 --- /dev/null +++ b/sax/qa/data/multiplens.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" ?> +<Athletes> + <Player xmlns:Player="xyzsports.com/players/football/"> + <Player:Name>Lionel Messi</Player:Name> + <Player:Height>1.70 m</Player:Height> + <Player:Position>Forward</Player:Position> + </Player> + <Player xmlns:Player="xyzsports.com/players/Cricket/"> + <Player:Name>Sachin Ramesh Tendulkar</Player:Name> + <Player:Height>165 cm</Player:Height> + <Player:Style>Right handed</Player:Style> + </Player> +</Athletes>
\ No newline at end of file diff --git a/sax/qa/data/multiplepfx.xml b/sax/qa/data/multiplepfx.xml new file mode 100644 index 000000000..b7686cad5 --- /dev/null +++ b/sax/qa/data/multiplepfx.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" ?> +<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"> + <office:body> + <office:text> + <text:p xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" text:style-name="Title">Test Document </text:p> + <note:p xmlns:note="urn:oasis:names:tc:opendocument:xmlns:text:1.0" note:style-name="Heading">For testing purposes only</note:p> + </office:text> + </office:body> +</office:document> diff --git a/sax/qa/data/nestedns.xml b/sax/qa/data/nestedns.xml new file mode 100644 index 000000000..566332b40 --- /dev/null +++ b/sax/qa/data/nestedns.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" ?> +<?pi-target pi-data?> +<Elements> + <Book xmlns:lib="http://www.library.com/"> + <lib:Title>Sherlock Holmes - I</lib:Title> + <lib:Author>Arthur Conan Doyle</lib:Author> + <purchase xmlns:lib="http://www.otherlibrary.com/"> + <lib:Title>Sherlock Holmes - II</lib:Title> + <lib:Author>Arthur Conan Doyle</lib:Author> + </purchase> + <lib:Title>Sherlock Holmes - III</lib:Title> + <lib:Author>Arthur Conan Doyle</lib:Author> + </Book> + <Electronics xmlns="http://doesntexist.com/electronics/"> + <item> + <Name>Apple iPhone 6s</Name> + <?pi-target-only?> + <Price>$324</Price> + </item> + <item xmlns="http://doesntexist.com/dailyuse/"> + <Name>Philips Aqua Touch Shaver</Name> + <item xmlns="http://doesntexist.com/dailyuse/model/"> + <Model>AT890</Model> + <Price>$74</Price> + </item> + </item> + <item> + <Name>Macbook Pro</Name> + <Price>$500</Price> + </item> + </Electronics> +</Elements>
\ No newline at end of file diff --git a/sax/qa/data/nstoattributes.xml b/sax/qa/data/nstoattributes.xml new file mode 100644 index 000000000..dee2edfdc --- /dev/null +++ b/sax/qa/data/nstoattributes.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" ?> +<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main/"> + <w:body> + <w:p w:rsidR="009A1A3D" w:rsidRPr="00BA52A7" w:rsidRDefault="00225691" w:rsidP="00BA52A7"> + <w:pPr xyz="abc"> + <w:spacing w:line="276" w:lineRule="auto"/> + <w:rPr> + <w:rFonts w:asciiTheme="minorHAnsi" w:hAnsiTheme="minorHAnsi"/> + <w:sz w:val="24" val="27" /> + <w:szCs w:val="24"/> + </w:rPr> + </w:pPr> + <w:bookmarkStart w:id="0" w:name="page1"/> + <w:bookmarkEnd w:id="0"/> + </w:p> + </w:body> +</w:document>
\ No newline at end of file diff --git a/sax/qa/data/simple.xml b/sax/qa/data/simple.xml new file mode 100644 index 000000000..67c4fbde5 --- /dev/null +++ b/sax/qa/data/simple.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" ?> +<TVActors> + <Actor> + <Name>Bryan Cranston</Name> + <Show>Breaking Bad</Show> + </Actor> + <Actor> + <Name>Peter Dinklage</Name> + <Show>Game of Thrones</Show> + </Actor> +</TVActors>
\ No newline at end of file diff --git a/sax/qa/data/testthreading.xml b/sax/qa/data/testthreading.xml new file mode 100644 index 000000000..0d05fd995 --- /dev/null +++ b/sax/qa/data/testthreading.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="UTF-8"?><Signature xmlns="http://www.w3.org/2000/09/xmldsig#" Id="idPackageSignature"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/><SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/><Reference Type="http://www.w3.org/2000/09/xmldsig#Object" URI="#idPackageObject"><DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/><DigestValue>NOjlH6v6g2ojDvQoi4M5B8Bght0y3ES4fjxlRk2xtVE=</DigestValue></Reference><Reference Type="http://www.w3.org/2000/09/xmldsig#Object" URI="#idOfficeObject"><DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/><DigestValue>mq1H1GLrTZSuUUTqX5HpjytFwl8nJFggNsXJUgQZT0U=</DigestValue></Reference><Reference Type="http://uri.etsi.org/01903#SignedProperties" URI="#idSignedProperties"><Transforms><Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/></Transforms><DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/><DigestValue>6jeT5n6jeqOspz6K6BIgitwfLZf4s1/uS9dPdOQRF8s=</DigestValue></Reference></SignedInfo><SignatureValue>UZwOWZbOm9ysRa+eYwoksUW8d+jBFPOkqOtfTvT8waHWDe3siDc4N79W6jPCYMIHMtPQjCb4qMDe +dhCYvg6TTWFWCvU/br+A1Qo0xovWHD3DwB29qk7NDBfbnEIPxbOe2D70cZa86Zl2MgW5YqQlgRFH +g6+XxwBUp+ZYx4knFWEg8zgbe3JnV7zeI/RG/1iq9TYH1GUBloF10df4qaulrp2AUkdSvnnUcxRP +ZfbS+14YxUHkW0UTyV+6ZeXqtTnXS0F/LG5JH2/xkN+mgwLB6TPfxtQD6vcj+Tdnf0hHlnuOmvBS +L7Pn+zwS0ueMOTxIozcaYPsmJc9fVpEU2I59PA==</SignatureValue><KeyInfo><X509Data><X509Certificate>MIIE7jCCAtagAwIBAgICEAAwDQYJKoZIhvcNAQELBQAwVzELMAkGA1UEBhMCVUsxEDAOBgNVBAgMB0VuZ2xhbmQxEjAQBgNVBAoMCVRTQ1AgVGVzdDEiMCAGA1UEAwwZVFNDUCBJbnRlcm1lZGlhdGUgUm9vdCBDQTAeFw0xNTEyMTgwNzU4MTlaFw0xNjEyMjcwNzU4MTlaMFUxCzAJBgNVBAYTAlVLMRAwDgYDVQQIDAdFbmdsYW5kMRIwEAYDVQQKDAlUU0NQIFRlc3QxIDAeBgNVBAMMF1RTQ1AgVGVzdCBleGFtcGxlIEFsaWNlMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3m2YNdX+nc1LkhlrNrcIPI3yCWnv0/0k9zDKpKiwjMH4vjWM46M6ptAiupxVpAMW5ojnhEyxaNHvZNsCwddYE6778hut2SJvz0szSBuHUuedcALI2EhVwdM0yLqfGo6WGeOIBDId49TemdNCMhk2zOpb1BqYhKls0LfdbxT/an3JaDmmLhPjvgYMJNYVX86L199OQFLJ1zLqQ0YirkKqXL9cSPmyYBKjgnqQ4Z5YfPL63EP0TsEfa5oQmy/0gS5FB2Wz9CqIptB130v0GR4XObTpOkhPFfC5RDBFTMZoi4NCK10wn2NCbr7qZ3aMrOlfeKbsNIifwu0KYFHXyxL5AwIDAQABo4HFMIHCMAkGA1UdEwQCMAAwEQYJYIZIAYb4QgEBBAQDAgWgMDMGCWCGSAGG+EIBDQQmFiRPcGVuU1NMIEdlbmVyYXRlZCBDbGllbnQgQ2VydGlmaWNhdGUwHQYDVR0OBBYEFCL6DzsuAbni8475Z+HkX5tv8iiWMB8GA1UdIwQYMBaAFMuejS1rWjUf3x1+2QbPSVpuXFl+MA4GA1UdDwEB/wQEAwIF4DAdBgNVHSUEFjAUBggrBgEFBQcDAgYIKwYBBQUHAwQwDQYJKoZIhvcNAQELBQADggIBAFs0DeCDjttHQ0UHsYcnhfBCWRdOFdIr3F/IEbN2BL/grScGXoXRaYMIQJv/s5dKgZIuH7xMCVKazoftPVqU4bOEduAv0IJ6hQF/wEMBueA0UjvQQVYZgsOALi7TD3gYpFqYcH2Wfx5/5Ln6dllL8UsHoP+6gSLaYwjJd7FQ+IlNTzR65dRMLoJhoKqqyuM6cf/PM8sbK2NH2r8toypjfPixvD/w3wP7xn4oo/IGXcRK4DTHBF/rSMqeR6ePwXm5tVHrQBfnxN3dsGsXkQgqzBvvbPY0raraO4CPR7mZp4GVFHOsUNh5TI1SlfxWZ49HU3F5jWeiI9jPuw1RmuAyZdFEt403Wi67v6revXe1By6UqIZjq3b2pJGBKZH+60P1cJScawzrN8pi1qQFV8JiiJM6/MSciqplTT5F7SG0XZx1CjnBz5rMdYNhI9NNtF3oy9Xy9RvgYehFaC43ZlBBUMDmZFj5a78hOOkkq1UnrHUdeXyWhiEFzv5d8My2i0kWGq8r0HuC25BmOa17lHVxQ2o7Rdu9jDFP9oNizC7kQfA5QVRTfBFcWH7jml69RmVgfM+X+wdQgen9hJAILhBzmDfeteJ5ZEaoEYtw3isOGkpSyg7odjgYq7I+bOiN1toDg07vzfIkvF9KxlkDeRLXbmcFIvQsqFeF6cUwlZQYLOHA</X509Certificate></X509Data></KeyInfo><Object Id="idPackageObject"><Manifest><Reference URI="/_rels/.rels?ContentType=application/vnd.openxmlformats-package.relationships+xml"><Transforms><Transform Algorithm="http://schemas.openxmlformats.org/package/2006/RelationshipTransform"><mdssi:RelationshipReference xmlns:mdssi="http://schemas.openxmlformats.org/package/2006/digital-signature" SourceId="rId1"/></Transform><Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/></Transforms><DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/><DigestValue>Mq3mDDWudLiaQFa1psBgLG+/en7p7r8re0MtlxnuiUI=</DigestValue></Reference><Reference URI="/word/_rels/document.xml.rels?ContentType=application/vnd.openxmlformats-package.relationships+xml"><Transforms><Transform Algorithm="http://schemas.openxmlformats.org/package/2006/RelationshipTransform"><mdssi:RelationshipReference xmlns:mdssi="http://schemas.openxmlformats.org/package/2006/digital-signature" SourceId="rId2"/><mdssi:RelationshipReference xmlns:mdssi="http://schemas.openxmlformats.org/package/2006/digital-signature" SourceId="rId1"/><mdssi:RelationshipReference xmlns:mdssi="http://schemas.openxmlformats.org/package/2006/digital-signature" SourceId="rId5"/><mdssi:RelationshipReference xmlns:mdssi="http://schemas.openxmlformats.org/package/2006/digital-signature" SourceId="rId4"/><mdssi:RelationshipReference xmlns:mdssi="http://schemas.openxmlformats.org/package/2006/digital-signature" SourceId="rId3"/></Transform><Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/></Transforms><DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/><DigestValue>fLpr0+BDSSPPgsv2eBghgw8hu/vi7IslCQuCSKGf2X4=</DigestValue></Reference><Reference URI="/word/document.xml?ContentType=application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"><DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/><DigestValue>7Hrf+Oz9oMcqn7nOKgy1P39L313r8SO/pT3wQpVwq5k=</DigestValue></Reference><Reference URI="/word/fontTable.xml?ContentType=application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml"><DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/><DigestValue>VZENondrzBVuF5GsYtsdSYgGNQS11L4XQ7vYiTn5PBE=</DigestValue></Reference><Reference URI="/word/settings.xml?ContentType=application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml"><DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/><DigestValue>nYb+Wnf/ttBtq0PSR33tt+yKzvx6RdYmtEhD3XnBwaI=</DigestValue></Reference><Reference URI="/word/styles.xml?ContentType=application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"><DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/><DigestValue>4W+Exf0d9q8aHyBJ94YvTqRgdlhjR2r7F+eO3udy01s=</DigestValue></Reference><Reference URI="/word/theme/theme1.xml?ContentType=application/vnd.openxmlformats-officedocument.theme+xml"><DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/><DigestValue>L8HrIbYZUORASW6Jbsljhmie2tLKO9ld8ME0syr+ZDE=</DigestValue></Reference><Reference URI="/word/webSettings.xml?ContentType=application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml"><DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/><DigestValue>8JastnM5t30OLdmv2PyPNOe1YxAXc/Qz0O1UCFnWyxM=</DigestValue></Reference></Manifest><SignatureProperties><SignatureProperty Id="idSignatureTime" Target="#idPackageSignature"><mdssi:SignatureTime xmlns:mdssi="http://schemas.openxmlformats.org/package/2006/digital-signature"><mdssi:Format>YYYY-MM-DDThh:mm:ssTZD</mdssi:Format><mdssi:Value>2016-01-11T15:32:02Z</mdssi:Value></mdssi:SignatureTime></SignatureProperty></SignatureProperties></Object><Object Id="idOfficeObject"><SignatureProperties><SignatureProperty Id="idOfficeV1Details" Target="#idPackageSignature"><SignatureInfoV1 xmlns="http://schemas.microsoft.com/office/2006/digsig"><SetupID></SetupID><SignatureText></SignatureText><SignatureImage/><SignatureComments>purpose</SignatureComments><WindowsVersion>6.1</WindowsVersion><OfficeVersion>16.0</OfficeVersion><ApplicationVersion>16.0</ApplicationVersion><Monitors>1</Monitors><HorizontalResolution>1280</HorizontalResolution><VerticalResolution>800</VerticalResolution><ColorDepth>32</ColorDepth><SignatureProviderId>{00000000-0000-0000-0000-000000000000}</SignatureProviderId><SignatureProviderUrl></SignatureProviderUrl><SignatureProviderDetails>9</SignatureProviderDetails><SignatureType>1</SignatureType></SignatureInfoV1></SignatureProperty></SignatureProperties></Object><Object><xd:QualifyingProperties xmlns:xd="http://uri.etsi.org/01903/v1.3.2#" Target="#idPackageSignature"><xd:SignedProperties Id="idSignedProperties"><xd:SignedSignatureProperties><xd:SigningTime>2016-01-11T15:32:02Z</xd:SigningTime><xd:SigningCertificate><xd:Cert><xd:CertDigest><DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/><DigestValue>VRk3WQgpNIAnRxA9txzm7L2v1Iuwu2WrHpwa5WNTKV0=</DigestValue></xd:CertDigest><xd:IssuerSerial><X509IssuerName>CN=TSCP Intermediate Root CA, O=TSCP Test, S=England, C=UK</X509IssuerName><X509SerialNumber>4096</X509SerialNumber></xd:IssuerSerial></xd:Cert></xd:SigningCertificate><xd:SignaturePolicyIdentifier><xd:SignaturePolicyImplied/></xd:SignaturePolicyIdentifier></xd:SignedSignatureProperties></xd:SignedProperties><xd:UnsignedProperties><xd:UnsignedSignatureProperties><xd:CertificateValues><xd:EncapsulatedX509Certificate>MIIFiDCCA3CgAwIBAgICEAAwDQYJKoZIhvcNAQELBQAwTzELMAkGA1UEBhMCVUsxEDAOBgNVBAgMB0VuZ2xhbmQxEjAQBgNVBAoMCVRTQ1AgVGVzdDEaMBgGA1UEAwwRVFNDUCBUZXN0IFJvb3QgQ0EwHhcNMTUxMjE4MDc1ODE5WhcNMjUxMjE1MDc1ODE5WjBXMQswCQYDVQQGEwJVSzEQMA4GA1UECAwHRW5nbGFuZDESMBAGA1UECgwJVFNDUCBUZXN0MSIwIAYDVQQDDBlUU0NQIEludGVybWVkaWF0ZSBSb290IENBMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAz7cet97WutWedG8L4cU7vjXkkzc8PkXnuvoF6ltIbDbnt2jt+0JH8xjGpfMVF+si0RPMwNQDmrTSj6SCpBcFV11hgyLXeovO17cSfbUYhl53ghyY0w/J3We19JJNeXtXlgZKrzre1gaXPxUG6Q4/TGo/gh9DmqEWjGkL3E6FboNfrIXHvOyhYT0kuTJkp8uqbBhhb/jO/FUV2DvTdoX04YZlFsheP00FHYz5ge6e3tG/WSeabTCUOsqq4+1jFOGNapvBrMkYC4QJwOc4bjIP8UmMlHqJae2mQVTVK3hiXtdMuS/H7rM/ZzCzcNQ2kyXUr843oul2FZ9UK3HI0TVrBFi0mpcWtvo/PMLNNXHJ/2MVZcHVgQ5+uBk0/Zq1vrqmxEev5t9lkKIzXRdztKP/EuBEjSvtcx+KZiHei+CvN+5nn5D0A6BfMYiQKmr2lVkCDs5v++iLINGbf54UoeM/dv2VEaC9bcdPeR8JHcvzS1f/cjHAbmnbMUumX985jha9SJavXkgWU6LgL5+txGD2X4Sb/+cf4ver1Zd1QGxqZ80wwK/qRUFGHWehcjCKAzeqnMRTJLUeNH5TcnvYv5fRq9wDMLzcjXXHaKEE+n3xt4fyCdEn5AFWeCPenqW3iZpEJTOHXm65Gj33/OTqoMLj8Mas3shoES1tL7LqQu/ZhgMCAwEAAaNmMGQwHQYDVR0OBBYEFMuejS1rWjUf3x1+2QbPSVpuXFl+MB8GA1UdIwQYMBaAFBtcCsdShJelvNJRLLHhVOy17wRXMBIGA1UdEwEB/wQIMAYBAf8CAQAwDgYDVR0PAQH/BAQDAgGGMA0GCSqGSIb3DQEBCwUAA4ICAQAzYDupn8D+Vh5NYcyiufM86F7GqmQ8Rows5R9o1c/5iax4G95Ley5EjUXo7/Hq2JSmtGVwkmlCBKduxsWmkbcBCJwr5AFX4TY8QFgTwKm4+IDlDA+Qs5m5bFKwbpJ8+oakz2L4j032hh6pRlezYh0P6ciVrTUNIFdR4GLusV8ronHa2AIJy9OIihI8zwDvT5rlPtDVs/wPiSq5+qcM/wnKo8X1JYU/tM1w6xvge0WNIf2yzedl2jZbbQm6wmCioCMZ7nUyyywC7WYFgCgOwOKfEa7pWhwCXpWt4MetNzXSpumurhrmn7B8y6NNarHNMhB9xv4Do4VwezMRCydnOGkl/B2fMMSoS3hxItJWDzEMkD51M6uk3yGnrQnApfEcGhEUTE8WvR8Il+Od4qFX7r50A5LguHXc4EshDJU4IaZEcYvOu91Xh2vsIZU72CXUELqMwJB7NjAkVwv8dQzHbKnK4E6y0zO1dHsjvwBfJl56PNRYx9fxJoBqdK4VrVVZAQ+wQ7wrvbjF2p5EnciHQS1NmLJjNeVvCY1dprYjp9mDxBFNNm4DhXYHF1TXpDqS7nC5cdJlTtdg4LxI4isMY/R1plDq2oxwaxhd1+5CxtMTsuv1A2qFvaRLUNS8SQE6PjWz1NxdczS5aBrXBfBFhxkEP3AtEbAyv0HiHidUAcq4pw==</xd:EncapsulatedX509Certificate><xd:EncapsulatedX509Certificate>MIIFhDCCA2ygAwIBAgIJAIc74NSdmtB4MA0GCSqGSIb3DQEBCwUAME8xCzAJBgNVBAYTAlVLMRAwDgYDVQQIDAdFbmdsYW5kMRIwEAYDVQQKDAlUU0NQIFRlc3QxGjAYBgNVBAMMEVRTQ1AgVGVzdCBSb290IENBMB4XDTE1MTIxODA3NTgxOFoXDTM1MTIxMzA3NTgxOFowTzELMAkGA1UEBhMCVUsxEDAOBgNVBAgMB0VuZ2xhbmQxEjAQBgNVBAoMCVRTQ1AgVGVzdDEaMBgGA1UEAwwRVFNDUCBUZXN0IFJvb3QgQ0EwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCwJHjSIV2YE31STJk/bvGrTY5O949l2TnA0nt3nlIC+oe2O+dLnMIwZsSvZwZdGMjvc25AoQHJAiX8zeq/0AVMz9mhm9y239ziJBnSdP4eLBEntPFtZZooFQUV9uXHejIJs3czZmQsOBz9Ko5cL3fC0qZYXeNL14MGpAWQ0EbEMaz0uDSz3BCcJBLSgXmCEBCbXNP7mCt9vWoa0nE8HQUVmiB+SL9ltCLUojVEB9EsssH1Wo3rFR03Wk9ZbMcmmn8Av1ZLexFDD2TKhGcNHNfguB5rf+Sc/Vt45pSPemE60ro1ej4n/wwpyFM+5w6rOYqZTaBiRwzgTwYoS1JcgKnu0ACIxYqpIhxeBbNT6rA45bBvTQOCNdUWALyRkTiLYiX5HKbrrhg2ZsmX62GwEPtm+okJIQLmQp7nLfQMDONrETrBnj/D2aUo6LuwtONBD35c/hLKTMVCDIBOS35Js55GJr2Y+dhG5ly0dKoMnu0fXScrEYQzjJ1Pbv7zvpO7RBV0El8Qg8AfR2ZAD/UlugRnEDCyVhAXz8g333r0whz3LvacHTwMJoMXFXt9yVnt3ivrZ2NGLcvSNx2ZjBU7Y2EWJoEKGl49+idqmHK1Equ3dM+FNiCNX2PCEL3DGs8GpuzFFM9d9q863xCCNRecgG8rrQKSo328Q656g3iSUqFcCwIDAQABo2MwYTAdBgNVHQ4EFgQUG1wKx1KEl6W80lEsseFU7LXvBFcwHwYDVR0jBBgwFoAUG1wKx1KEl6W80lEsseFU7LXvBFcwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAYYwDQYJKoZIhvcNAQELBQADggIBADNoTWI0fdkdQW8/knVy+pEYh4y4f/9rit55MznmMsuOTHv9svNH9AMw/ZBvsfu4fEcXQyhmeonRMPdsz26ZigxG4k2wcN9fV2VMI3MlIbefCJZhIS89c3kyBF5MhbnaWxvP95nfa41cfbsXnSrj31VNMSXiA6YegbiL/v/0IkUd1mwXcXTcyxbkMLuTORgA6WiPpHVMN//YnQSMWa9ukh0uHsAuoDc2NvteXZsQkpOdZdJB4pIL2t68agyGy1Wv78jiaoxVbfYL4T3TJMxIGFSZFoV+1SYmVsfPxrSQ7vopT6y61r9c/b2fTPaHO+22pFx8lNsHII5kXpWQZIpRHgqjydN/VtnaC6dKq1lPvQTplzQVfCNWGaa/BddinGNV2qwo2a1QnEv7/6t1Gtxs5rte31aCNkfIx/mThk10fMmwJK9ECWKT/+X5iWpydI3zBIE+OvO0MKpaOeVVz1JehkZxGWP+qduF8lgL7Hs4osQNbQIu41twarpSjVCEm/FLVqo8wLmTi2Y5a7QTANeNLdyAKxjTJn3uuAvVYUUHzKOXgKF/X0tCZrUsH3//2MW3nqenN0ldXIzf7OjnVcbv2iKUzqYFzJHYtAuWHbew/kj2TvWeFFzdigLYjfnfZvHQ5sPxwrx6YpDeNf8inj48oEj6Raos0ClF0nmVg2eLMe9f</xd:EncapsulatedX509Certificate></xd:CertificateValues></xd:UnsignedSignatureProperties></xd:UnsignedProperties></xd:QualifyingProperties></Object></Signature>
\ No newline at end of file |