diff options
Diffstat (limited to 'ACE/ACEXML/tests')
-rw-r--r-- | ACE/ACEXML/tests/ContentHandler_Test.cpp | 103 | ||||
-rw-r--r-- | ACE/ACEXML/tests/HttpCharStream_Test.cpp | 40 | ||||
-rw-r--r-- | ACE/ACEXML/tests/Makefile.am | 114 | ||||
-rw-r--r-- | ACE/ACEXML/tests/NamespaceSupport_Test.cpp | 150 | ||||
-rw-r--r-- | ACE/ACEXML/tests/Transcoder_Test.cpp | 71 | ||||
-rw-r--r-- | ACE/ACEXML/tests/tests.mpc | 30 | ||||
-rw-r--r-- | ACE/ACEXML/tests/util/Makefile.am | 43 | ||||
-rw-r--r-- | ACE/ACEXML/tests/util/test.cpp | 111 | ||||
-rw-r--r-- | ACE/ACEXML/tests/util/util.mpc | 4 |
9 files changed, 666 insertions, 0 deletions
diff --git a/ACE/ACEXML/tests/ContentHandler_Test.cpp b/ACE/ACEXML/tests/ContentHandler_Test.cpp new file mode 100644 index 00000000000..ec4315f892a --- /dev/null +++ b/ACE/ACEXML/tests/ContentHandler_Test.cpp @@ -0,0 +1,103 @@ +//============================================================================= +/** + * @file ContentHandler_Test.cpp + * + * $Id$ + * + * @author Steve Huston <shuston@riverace.com> + */ +//============================================================================= + +#include "ACEXML/common/DefaultHandler.h" +#include "ACEXML/common/InputSource.h" +#include "ACEXML/common/StrCharStream.h" +#include "ACEXML/parser/parser/Parser.h" +#include "ace/OS_NS_string.h" +#include "ace/OS_main.h" + +class Basic_Content_Tester : public ACEXML_DefaultHandler +{ +public: + /** + * Receive notification of character data. + */ + virtual void characters (const ACEXML_Char *ch, + int start, + int length ACEXML_ENV_ARG_DECL) + ACE_THROW_SPEC ((ACEXML_SAXException)); + + const ACEXML_Char *get_test_string (void) + { return Basic_Content_Tester::test_string_; } + +private: + static const ACEXML_Char *test_string_; +}; + +const ACEXML_Char * Basic_Content_Tester::test_string_ = + ACE_TEXT ("<?xml version=\"1.0\"?>") + ACE_TEXT ("<translation type=\"unfinished\">Example\n") + ACE_TEXT ("d'internationalisation</translation>"); + +void +Basic_Content_Tester::characters (const ACEXML_Char *ch, + int start, + int length ACEXML_ENV_ARG_DECL) + ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + static int already_called = 0; + static const ACEXML_Char *expect = + ACE_TEXT ("Example\nd'internationalisation"); + + if (already_called) + { + ACEXML_THROW (ACEXML_SAXException + (ACE_TEXT ("characters() called too much\n"))); + } + already_called = 1; + + int expected_len = static_cast<int> (ACE_OS::strlen (expect)); + if (length != expected_len) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("characters() expected len %d (%*s); ") + ACE_TEXT ("got %d (%*s)\n"), + expected_len, expected_len, ch + start, + length, length, ch + start)); + ACEXML_THROW (ACEXML_SAXException (ACE_TEXT ("Functionality failure"))); + } + return; +} + +int +ACE_TMAIN (int, ACE_TCHAR *[]) +{ + int status = 0; + Basic_Content_Tester tester; + ACEXML_StrCharStream *test_stream = 0; + ACE_NEW_RETURN (test_stream, ACEXML_StrCharStream, -1); + if (test_stream->open (tester.get_test_string (), + ACE_TEXT ("test_stream")) < 0) + { + ACE_ERROR ((LM_ERROR, ACE_TEXT ("Unable to create input stream\n"))); + return -1; + } + ACEXML_InputSource input (test_stream); + ACEXML_Parser parser; + parser.setContentHandler (&tester); + ACEXML_TRY_NEW_ENV + { + parser.setFeature (ACE_TEXT ("http://xml.org/sax/features/validation"), + 0 + ACEXML_ENV_ARG_PARAMETER); + ACEXML_TRY_CHECK; + parser.parse (&input ACEXML_ENV_ARG_PARAMETER); + ACEXML_TRY_CHECK; + } + ACEXML_CATCH (ACEXML_SAXException, ex) + { + ex.print(); + status = 1; + } + ACEXML_ENDTRY; + return status; +} diff --git a/ACE/ACEXML/tests/HttpCharStream_Test.cpp b/ACE/ACEXML/tests/HttpCharStream_Test.cpp new file mode 100644 index 00000000000..ba969753a3d --- /dev/null +++ b/ACE/ACEXML/tests/HttpCharStream_Test.cpp @@ -0,0 +1,40 @@ +// $Id$ + +#include "ACEXML/common/HttpCharStream.h" +#include "ace/OS_NS_stdio.h" +#include "ace/OS_main.h" + +int ACE_TMAIN (int, ACE_TCHAR *[]) +{ + const ACEXML_Char* test = ACE_TEXT("http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"); + + const ACEXML_Char* simple = ACE_TEXT("http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent"); + + ACEXML_HttpCharStream first; + ACEXML_HttpCharStream second; + ACEXML_Char ch; + + if (first.open (test) != -1) + { + while (first.get (ch) != -1) + ACE_OS::printf ("%c", ch); + } + else + { + first.close(); + ACE_ERROR ((LM_ERROR, "Error in opening stream : %m\n")); + } + if (second.open (simple) != -1) + { + while (second.get (ch) != -1) + ACE_OS::printf ("%c", ch); + } + else + { + second.close(); + ACE_ERROR ((LM_ERROR, "Error in opening stream : %m\n")); + } + first.close(); + second.close(); + return 0; +} diff --git a/ACE/ACEXML/tests/Makefile.am b/ACE/ACEXML/tests/Makefile.am new file mode 100644 index 00000000000..926a3fd9212 --- /dev/null +++ b/ACE/ACEXML/tests/Makefile.am @@ -0,0 +1,114 @@ +## Process this file with automake to create Makefile.in +## +## $Id$ +## +## This file was generated by MPC. Any changes made directly to +## this file will be lost the next time it is generated. +## +## MPC Command: +## /acebuilds/ACE_wrappers-repository/bin/mwc.pl -include /acebuilds/MPC/config -include /acebuilds/MPC/templates -feature_file /acebuilds/ACE_wrappers-repository/local.features -noreldefs -type automake -exclude build,Kokyu + +ACE_BUILDDIR = $(top_builddir) +ACE_ROOT = $(top_srcdir) + +SUBDIRS = \ + . \ + util + +noinst_PROGRAMS = + +## Makefile.ContentHandler_Test.am + +if BUILD_ACEXML +if !BUILD_ACE_FOR_TAO +noinst_PROGRAMS += ContentHandler_Test + +ContentHandler_Test_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) \ + -I$(ACE_ROOT)/ACEXML/common + +ContentHandler_Test_SOURCES = \ + ContentHandler_Test.cpp + +ContentHandler_Test_LDADD = \ + $(ACE_BUILDDIR)/ACEXML/parser/parser/libACEXML_Parser.la \ + $(ACE_BUILDDIR)/ACEXML/common/libACEXML.la \ + $(ACE_BUILDDIR)/ace/libACE.la + +endif !BUILD_ACE_FOR_TAO +endif BUILD_ACEXML + +## Makefile.HttpCharStream_Test.am + +if BUILD_ACEXML +if !BUILD_ACE_FOR_TAO +noinst_PROGRAMS += HttpCharStream_Test + +HttpCharStream_Test_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) \ + -I$(ACE_ROOT)/ACEXML/common + +HttpCharStream_Test_SOURCES = \ + HttpCharStream_Test.cpp + +HttpCharStream_Test_LDADD = \ + $(ACE_BUILDDIR)/ACEXML/parser/parser/libACEXML_Parser.la \ + $(ACE_BUILDDIR)/ACEXML/common/libACEXML.la \ + $(ACE_BUILDDIR)/ace/libACE.la + +endif !BUILD_ACE_FOR_TAO +endif BUILD_ACEXML + +## Makefile.NamespaceSupport_Test.am + +if BUILD_ACEXML +if !BUILD_ACE_FOR_TAO +noinst_PROGRAMS += NamespaceSupport_Test + +NamespaceSupport_Test_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) \ + -I$(ACE_ROOT)/ACEXML/common + +NamespaceSupport_Test_SOURCES = \ + NamespaceSupport_Test.cpp + +NamespaceSupport_Test_LDADD = \ + $(ACE_BUILDDIR)/ACEXML/parser/parser/libACEXML_Parser.la \ + $(ACE_BUILDDIR)/ACEXML/common/libACEXML.la \ + $(ACE_BUILDDIR)/ace/libACE.la + +endif !BUILD_ACE_FOR_TAO +endif BUILD_ACEXML + +## Makefile.Transcoder_Test.am + +if BUILD_ACEXML +if !BUILD_ACE_FOR_TAO +noinst_PROGRAMS += Transcoder_Test + +Transcoder_Test_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) \ + -I$(ACE_ROOT)/ACEXML/common + +Transcoder_Test_SOURCES = \ + Transcoder_Test.cpp + +Transcoder_Test_LDADD = \ + $(ACE_BUILDDIR)/ACEXML/parser/parser/libACEXML_Parser.la \ + $(ACE_BUILDDIR)/ACEXML/common/libACEXML.la \ + $(ACE_BUILDDIR)/ace/libACE.la + +endif !BUILD_ACE_FOR_TAO +endif BUILD_ACEXML + +## Clean up template repositories, etc. +clean-local: + -rm -f *~ *.bak *.rpo *.sym lib*.*_pure_* core core.* + -rm -f gcctemp.c gcctemp so_locations *.ics + -rm -rf cxx_repository ptrepository ti_files + -rm -rf templateregistry ir.out + -rm -rf ptrepository SunWS_cache Templates.DB diff --git a/ACE/ACEXML/tests/NamespaceSupport_Test.cpp b/ACE/ACEXML/tests/NamespaceSupport_Test.cpp new file mode 100644 index 00000000000..2632c6dc571 --- /dev/null +++ b/ACE/ACEXML/tests/NamespaceSupport_Test.cpp @@ -0,0 +1,150 @@ +// $Id$ + +#include "ACEXML/common/NamespaceSupport.h" +#include "ace/OS_main.h" + +int ACE_TMAIN (int, ACE_TCHAR *[]) +{ + ACEXML_NamespaceSupport xmlns; + if (xmlns.init() == -1) + { + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("Error in initializing namespace support."))); + return 1; + } + xmlns.pushContext(); + xmlns.declarePrefix(ACE_TEXT (""), + ACE_TEXT ("http://www.w3.org/1999/xhtml")); + xmlns.declarePrefix(ACE_TEXT ("dc"), + ACE_TEXT ("http://www.purl.org/dc#")); + xmlns.declarePrefix(ACE_TEXT ("xc"), + ACE_TEXT ("http://www.purl.org/dc#")); + + const ACEXML_Char *lName, *uri; + const ACEXML_Char *n1 = ACE_TEXT ("p"); + + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("*** Checking processName:\n"))); + if (xmlns.processName (n1, uri, lName, 0) != 0) + ACE_DEBUG ((LM_ERROR, + ACE_TEXT ("Fail to resolve namespace name %s\n"), + n1)); + else + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("Namespace URI: %s\nLocal name: %s\nRaw name: %s\n"), + uri, lName, n1)); + + const ACEXML_Char *n2 = ACE_TEXT ("dc:title"); + if (xmlns.processName(n2, uri, lName, 0) != 0) + ACE_DEBUG ((LM_ERROR, + ACE_TEXT ("Fail to resolve namespace name %S\n"), + n2)); + else + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("Namespace URI: %s\nLocal name: %s\nRaw name: %s\n"), + uri, lName, n2)); + + const ACEXML_Char *n3 = ACE_TEXT ("xml:title"); + if (xmlns.processName(n3, uri, lName, 0) != 0) + ACE_DEBUG ((LM_ERROR, + ACE_TEXT ("Fail to resolve namespace name %S\n"), + n3)); + else + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("Namespace URI: %s\nLocal name: %s\nRaw name: %s\n"), + uri, lName, n3)); + + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("\n*** Checking getDeclaredPrefixes\n"))); + + ACEXML_STR_LIST prefixes; + if (xmlns.getDeclaredPrefixes (prefixes) != 0) + ACE_DEBUG ((LM_ERROR, + ACE_TEXT ("Fail to get a list of declared prefixes\n"))); + else + { + ACEXML_STR_LIST::ITERATOR iter = prefixes.begin (); + const ACEXML_Char **prefix = 0; + + for (; iter.next (prefix);iter.advance ()) + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("prefix: \"%s\"\n"), *prefix)); + } + + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n*** Checking getPrefix\n"))); + const ACEXML_Char *prefix = 0; + + if ((prefix = xmlns.getPrefix (ACE_TEXT ("http://www.purl.org/dc#"))) == 0) + ACE_DEBUG ((LM_ERROR, + ACE_TEXT ("Fail to get prefix of http://www.purl.org/dc#\n"))); + else + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("Prefix of http://www.purl.org/dc# is %s\n"), + prefix)); + + if ((prefix = xmlns.getPrefix (ACE_TEXT ("http://www.w3.org/1999/xhtml"))) == 0) + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("Fail to get prefix of http://www.w3.org/1999/xhtml which is okay\n"))); + else + ACE_DEBUG ((LM_ERROR, + ACE_TEXT ("ERROR: Prefix of http://www.w3.org/1999/xhtml is %s\n"), + prefix)); + + if ((prefix = xmlns.getPrefix (ACE_TEXT ("http://www.w3.org/XML/1998/namespace"))) == 0) + ACE_DEBUG ((LM_ERROR, + ACE_TEXT ("Fail to get prefix of http://www.w3.org/XML/1998/namespace\n"))); + else + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("Prefix of http://www.w3.org/XML/1998/namespace is %s\n"), + prefix)); + + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n*** Checking getPrefixes with known URI\n"))); + prefixes.reset (); + + if (xmlns.getPrefixes (ACE_TEXT ("http://www.purl.org/dc#"), prefixes) != 0) + ACE_DEBUG ((LM_ERROR, ACE_TEXT ("Fail to getPrefixes based on known URI\n"))); + else + { + ACEXML_STR_LIST::ITERATOR iter = prefixes.begin (); + const ACEXML_Char **prefix = 0; + + for (; iter.next (prefix);iter.advance ()) + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("prefix: \"%s\"\n"), *prefix)); + } + + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n*** Checking getPrefixes\n"))); + prefixes.reset (); + + if (xmlns.getPrefixes (prefixes) != 0) + ACE_DEBUG ((LM_ERROR, ACE_TEXT ("Fail to getPrefixes\n"))); + else + { + ACEXML_STR_LIST::ITERATOR iter = prefixes.begin (); + const ACEXML_Char **prefix = 0; + + for (; iter.next (prefix);iter.advance ()) + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("prefix: \"%s\"\n"), *prefix)); + } + + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n*** Checking getURI\n"))); + const ACEXML_Char *URI = 0; + + if ((URI = xmlns.getURI (ACE_TEXT ("dc"))) == 0) + ACE_DEBUG((LM_ERROR, ACE_TEXT ("Fail to get URI for \"dc\"\n"))); + else + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("URI for \"dc\" is %s\n"), URI)); + if ((URI = xmlns.getURI (ACE_TEXT ("xc"))) == 0) + ACE_DEBUG ((LM_ERROR, ACE_TEXT ("Fail to get URI for \"xc\"\n"))); + else + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("URI for \"xc\" is %s\n"), URI)); + if ((URI = xmlns.getURI (ACE_TEXT ("xml"))) == 0) + ACE_DEBUG ((LM_ERROR, ACE_TEXT ("Fail to get URI for \"xml\"\n"))); + else + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("URI for \"xml\" is %s\n"), URI)); + if ((URI = xmlns.getURI (ACE_TEXT (""))) == 0) + ACE_DEBUG ((LM_ERROR, ACE_TEXT ("Fail to get default namespace URI\n"))); + else + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("URI for default namespace is %s\n"), URI)); + + xmlns.popContext(); + + return 0; +} diff --git a/ACE/ACEXML/tests/Transcoder_Test.cpp b/ACE/ACEXML/tests/Transcoder_Test.cpp new file mode 100644 index 00000000000..f5dc289e5e0 --- /dev/null +++ b/ACE/ACEXML/tests/Transcoder_Test.cpp @@ -0,0 +1,71 @@ +// -*- C++ -*- $Id$ + +#include "ACEXML/common/Transcode.h" +#include "ace/Log_Msg.h" +#include "ace/OS_NS_string.h" +#include "ace/OS_main.h" + +void dump_utf16 (const ACEXML_UTF16 *data, + size_t len) +{ + size_t ptr = 0; + + while (1) + { + ACE_DEBUG ((LM_DEBUG, "%04x", data[ptr])); + + if (++ptr >= len) + break; + + if (ptr % 4 == 0) + ACE_DEBUG ((LM_DEBUG, "\n")); + else + ACE_DEBUG ((LM_DEBUG, " ")); + } + ACE_DEBUG ((LM_DEBUG, "\n")); + return; +} + +int +ACE_TMAIN (int, ACE_TCHAR*[]) +{ + ACEXML_UTF16 org [18]; +// = { 1, 2, 4, 8, 0x10, 0x20, 0x40, +// 0x80, +// 0x100, 0x200, 0x400, +// 0x800, 0x801, 0x802, 0x804, 0x808, 0x810, 0x820, +// 0x840, 0x880, 0x900, 0xa00, 0xc00, +// 0x1000, 0x2000, 0x4000, 0x8000, 0 } + ACEXML_UCS4 temp = 1; + + ACE_OS::memset (org, 0, sizeof org); + size_t x; + + for (x = 0; temp < 0x10000; x++, temp <<= 1) + { + org[x] = static_cast<ACEXML_UTF16> (temp); + } + + ACE_DEBUG ((LM_DEBUG, "Original UTF16 string:\n")); + dump_utf16 (org, x); + ACE_DEBUG ((LM_DEBUG, "\n\n")); + + ACEXML_UTF8 decoded [MAXPATHLEN]; + ACE_OS::memset (decoded, 0, sizeof decoded); + + ACEXML_Transcoder::utf16s2utf8s (org, decoded, MAXPATHLEN); + + ACE_DEBUG ((LM_DEBUG, "Transcoded UTF8 string:\n")); + ACE_HEX_DUMP ((LM_DEBUG, decoded, ACE_OS::strlen (decoded) + 1)); + ACE_DEBUG ((LM_DEBUG, "\n\n")); + + ACEXML_UTF16 after [18]; + ACE_OS::memset (after, 0, sizeof after); + ACEXML_Transcoder::utf8s2utf16s (decoded, after, 18); + + ACE_DEBUG ((LM_DEBUG, "Restored UTF16 string:\n")); + dump_utf16 (after, x); + ACE_DEBUG ((LM_DEBUG, "\n\n")); + + return 0; +} diff --git a/ACE/ACEXML/tests/tests.mpc b/ACE/ACEXML/tests/tests.mpc new file mode 100644 index 00000000000..e0a2365e689 --- /dev/null +++ b/ACE/ACEXML/tests/tests.mpc @@ -0,0 +1,30 @@ +// -*- MPC -*- +// $Id$ + +project(Transcoder_Test): aceexe, acexml { + exename = Transcoder_Test + Source_Files { + Transcoder_Test.cpp + } +} + +project(NamespaceSupport_Test): aceexe, acexml { + exename = NamespaceSupport_Test + Source_Files { + NamespaceSupport_Test.cpp + } +} + +project(HttpCharStream_Test): aceexe, acexml { + exename = HttpCharStream_Test + Source_Files { + HttpCharStream_Test.cpp + } +} + +project(ContentHandler_Test): aceexe, acexml { + exename = ContentHandler_Test + Source_Files { + ContentHandler_Test.cpp + } +} diff --git a/ACE/ACEXML/tests/util/Makefile.am b/ACE/ACEXML/tests/util/Makefile.am new file mode 100644 index 00000000000..486d37c1902 --- /dev/null +++ b/ACE/ACEXML/tests/util/Makefile.am @@ -0,0 +1,43 @@ +## Process this file with automake to create Makefile.in +## +## $Id$ +## +## This file was generated by MPC. Any changes made directly to +## this file will be lost the next time it is generated. +## +## MPC Command: +## /acebuilds/ACE_wrappers-repository/bin/mwc.pl -include /acebuilds/MPC/config -include /acebuilds/MPC/templates -feature_file /acebuilds/ACE_wrappers-repository/local.features -noreldefs -type automake -exclude build,Kokyu + +ACE_BUILDDIR = $(top_builddir) +ACE_ROOT = $(top_srcdir) + + +## Makefile.util.am + +if BUILD_ACEXML +if !BUILD_ACE_FOR_TAO +noinst_PROGRAMS = test + +test_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) \ + -I$(ACE_ROOT)/ACEXML/common + +test_SOURCES = \ + test.cpp + +test_LDADD = \ + $(ACE_BUILDDIR)/ACEXML/parser/parser/libACEXML_Parser.la \ + $(ACE_BUILDDIR)/ACEXML/common/libACEXML.la \ + $(ACE_BUILDDIR)/ace/libACE.la + +endif !BUILD_ACE_FOR_TAO +endif BUILD_ACEXML + +## Clean up template repositories, etc. +clean-local: + -rm -f *~ *.bak *.rpo *.sym lib*.*_pure_* core core.* + -rm -f gcctemp.c gcctemp so_locations *.ics + -rm -rf cxx_repository ptrepository ti_files + -rm -rf templateregistry ir.out + -rm -rf ptrepository SunWS_cache Templates.DB diff --git a/ACE/ACEXML/tests/util/test.cpp b/ACE/ACEXML/tests/util/test.cpp new file mode 100644 index 00000000000..40f0eb41001 --- /dev/null +++ b/ACE/ACEXML/tests/util/test.cpp @@ -0,0 +1,111 @@ +// $Id$ +// A simple test for performance of the ACEXML_escape_string() function + +#include "ACEXML/common/XML_Util.h" + +#include "ace/OS_main.h" +#include "ace/Time_Value.h" +#include "ace/OS_NS_sys_time.h" +#include "ace/Log_Msg.h" + +const int MAX_ITERATIONS = 100 * 1000; +const int NUM_TEST_STRS = 6; + +static bool is_escaped(const ACEXML_String& s) +{ + if (s[0] != ACE_TEXT('&')) + return false; + if (s[s.length() - 1] != ACE_TEXT(';')) + return false; + return true; +} + +static int run_tests(ACEXML_String test_strings[NUM_TEST_STRS], int iterations) +{ + // Test 1 - Escape the strings using a new temporary string each iteration. + ACE_Time_Value start = ACE_OS::gettimeofday(); + int i = 0; + for (i = 0; i < iterations; ++i) + { + ACEXML_String tmp = ACEXML_escape_string(test_strings[i % NUM_TEST_STRS]); + if (! is_escaped(tmp)) + { + ACE_ERROR((LM_ERROR, "Error: Failed to escape string\n")); + return 1; + } + } + ACE_DEBUG((LM_DEBUG, "Test1 took %dms\n", (ACE_OS::gettimeofday() - start).msec())); + + // Test 2 - Escape the strings using a shared temporary string. This shouldn't + // be any faster than Test 1 as long as the compiler has return value optimization. + ACEXML_String tmp; + start = ACE_OS::gettimeofday(); + for (i = 0; i < iterations; ++i) + { + tmp = ACEXML_escape_string(test_strings[i % NUM_TEST_STRS]); + if (! is_escaped(tmp)) + { + ACE_ERROR((LM_ERROR, "Error: Failed to escape string\n")); + return 1; + } + } + ACE_DEBUG((LM_DEBUG, "Test2 took %dms\n", (ACE_OS::gettimeofday() - start).msec())); + + // Test 3 - Escape the strings using a shared temporary string. This time, we use + // the alternate form of ACEXML_escape_string() so that our temporary buffer is reused. + tmp.clear(1); + start = ACE_OS::gettimeofday(); + for (i = 0; i < iterations; ++i) + { + ACEXML_escape_string(test_strings[i % NUM_TEST_STRS], tmp); + if (! is_escaped(tmp)) + { + ACE_ERROR((LM_ERROR, "Error: Failed to escape string\n")); + return 1; + } + } + ACE_DEBUG((LM_DEBUG, "Test3 took %dms\n", (ACE_OS::gettimeofday() - start).msec())); + + // Test 4 - Same as Test 3, except that the tmp buffer shouldn't have to resize. + start = ACE_OS::gettimeofday(); + for (i = 0; i < iterations; ++i) + { + ACEXML_escape_string(test_strings[i % NUM_TEST_STRS], tmp); + if (! is_escaped(tmp)) + { + ACE_ERROR((LM_ERROR, "Error: Failed to escape string\n")); + return 1; + } + } + ACE_DEBUG((LM_DEBUG, "Test4 took %dms\n", (ACE_OS::gettimeofday() - start).msec())); + return 0; +} + +int ACE_TMAIN (int, ACE_TCHAR *[]) +{ + ACEXML_String test_strings[NUM_TEST_STRS] = { + ACE_TEXT("\"xxxxx\"xxxxxxxx xx\"xxxxxx xxxxxx\"xxxxxxxxxx xxxxxxxx\"xxxxxx\""), + ACE_TEXT("'xxxxx\'xxxxxxxx' xxxxxxxx xx'xxxxxxxx'xxxxxx xxxxxxx'xxxxxxx'"), + ACE_TEXT("&xxxx&xxxxxxxxx &xxxxxxxx xxxxx&xxxxxxxxxxx xxxx&xxxxxxxxxx&"), + ACE_TEXT(">xx>xxxxxxxxxxx >xxxxxxxx xxxxx>xxxxxxxxxxx xxxxx>xxxxxxxxx>"), + ACE_TEXT("<xxxxx<xxxxxxxx xxxxxxxx <xxxxxxxxxxxxxxx<x xxxxxxxxxxxxxx<"), + ACE_TEXT("&xxxx\"xxxxxxx&xx xxx'xxxxx xx<xxxxxxx>xxxxxxx xx\"xxxxxxxxxxxx>"), + }; + + if (run_tests(test_strings, MAX_ITERATIONS) != 0) + return 1; + + ACE_DEBUG((LM_DEBUG, "Rerun tests with larger strings\n")); + for (int i = 0; i < NUM_TEST_STRS; ++i) + { + for (int j = 0; j < 5; ++j) + { + test_strings[i] += test_strings[i]; + } + } + + if (run_tests(test_strings, MAX_ITERATIONS / 10) != 0) + return 1; + + return 0; +} diff --git a/ACE/ACEXML/tests/util/util.mpc b/ACE/ACEXML/tests/util/util.mpc new file mode 100644 index 00000000000..4deaa3719c4 --- /dev/null +++ b/ACE/ACEXML/tests/util/util.mpc @@ -0,0 +1,4 @@ +// $Id$ +project: aceexe, acexml { + exename = test +} |