00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "ACEXML/common/DefaultHandler.h"
00012 #include "ACEXML/common/InputSource.h"
00013 #include "ACEXML/common/StrCharStream.h"
00014 #include "ACEXML/parser/parser/Parser.h"
00015 #include "ace/OS_NS_string.h"
00016 #include "ace/OS_main.h"
00017
00018 class Basic_Content_Tester : public ACEXML_DefaultHandler
00019 {
00020 public:
00021
00022
00023
00024 virtual void characters (const ACEXML_Char *ch,
00025 size_t start,
00026 size_t length ACEXML_ENV_ARG_DECL);
00027
00028 const ACEXML_Char *get_test_string (void)
00029 { return Basic_Content_Tester::test_string_; }
00030
00031 private:
00032 static const ACEXML_Char *test_string_;
00033 };
00034
00035 const ACEXML_Char * Basic_Content_Tester::test_string_ =
00036 ACE_TEXT ("<?xml version=\"1.0\"?>")
00037 ACE_TEXT ("<translation type=\"unfinished\">Example\n")
00038 ACE_TEXT ("d'internationalisation</translation>");
00039
00040 void
00041 Basic_Content_Tester::characters (const ACEXML_Char *ch,
00042 size_t start,
00043 size_t length ACEXML_ENV_ARG_DECL)
00044 {
00045 static int already_called = 0;
00046 static const ACEXML_Char *expect =
00047 ACE_TEXT ("Example\nd'internationalisation");
00048
00049 if (already_called)
00050 {
00051 ACEXML_THROW (ACEXML_SAXException
00052 (ACE_TEXT ("characters() called too much\n")));
00053 }
00054 already_called = 1;
00055
00056 size_t expected_len = ACE_OS::strlen (expect);
00057 if (length != expected_len)
00058 {
00059 ACE_ERROR ((LM_ERROR,
00060 ACE_TEXT ("characters() expected len %u (%*s); ")
00061 ACE_TEXT ("got %u (%*s)\n"),
00062 expected_len, expected_len, ch + start,
00063 length, length, ch + start));
00064 ACEXML_THROW (ACEXML_SAXException (ACE_TEXT ("Functionality failure")));
00065 }
00066 return;
00067 }
00068
00069 int
00070 ACE_TMAIN (int, ACE_TCHAR *[])
00071 {
00072 int status = 0;
00073 Basic_Content_Tester tester;
00074 ACEXML_StrCharStream *test_stream = 0;
00075 ACE_NEW_RETURN (test_stream, ACEXML_StrCharStream, -1);
00076 if (test_stream->open (tester.get_test_string (),
00077 ACE_TEXT ("test_stream")) < 0)
00078 {
00079 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Unable to create input stream\n")));
00080 return -1;
00081 }
00082 ACEXML_InputSource input (test_stream);
00083 ACEXML_Parser parser;
00084 parser.setContentHandler (&tester);
00085 ACEXML_TRY_NEW_ENV
00086 {
00087 parser.setFeature (ACE_TEXT ("http://xml.org/sax/features/validation"),
00088 0
00089 ACEXML_ENV_ARG_PARAMETER);
00090 ACEXML_TRY_CHECK;
00091 parser.parse (&input ACEXML_ENV_ARG_PARAMETER);
00092 ACEXML_TRY_CHECK;
00093 }
00094 ACEXML_CATCH (ACEXML_SAXException, ex)
00095 {
00096 ex.print();
00097 status = 1;
00098 }
00099 ACEXML_ENDTRY;
00100 return status;
00101 }