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 int start,
00026 int length ACEXML_ENV_ARG_DECL)
00027 ACE_THROW_SPEC ((ACEXML_SAXException));
00028
00029 const ACEXML_Char *get_test_string (void)
00030 { return Basic_Content_Tester::test_string_; }
00031
00032 private:
00033 static const ACEXML_Char *test_string_;
00034 };
00035
00036 const ACEXML_Char * Basic_Content_Tester::test_string_ =
00037 ACE_TEXT ("<?xml version=\"1.0\"?>")
00038 ACE_TEXT ("<translation type=\"unfinished\">Example\n")
00039 ACE_TEXT ("d'internationalisation</translation>");
00040
00041 void
00042 Basic_Content_Tester::characters (const ACEXML_Char *ch,
00043 int start,
00044 int length ACEXML_ENV_ARG_DECL)
00045 ACE_THROW_SPEC ((ACEXML_SAXException))
00046 {
00047 static int already_called = 0;
00048 static const ACEXML_Char *expect =
00049 ACE_TEXT ("Example\nd'internationalisation");
00050
00051 if (already_called)
00052 {
00053 ACEXML_THROW (ACEXML_SAXException
00054 (ACE_TEXT ("characters() called too much\n")));
00055 }
00056 already_called = 1;
00057
00058 int expected_len = static_cast<int> (ACE_OS::strlen (expect));
00059 if (length != expected_len)
00060 {
00061 ACE_ERROR ((LM_ERROR,
00062 ACE_TEXT ("characters() expected len %d (%*s); ")
00063 ACE_TEXT ("got %d (%*s)\n"),
00064 expected_len, expected_len, ch + start,
00065 length, length, ch + start));
00066 ACEXML_THROW (ACEXML_SAXException (ACE_TEXT ("Functionality failure")));
00067 }
00068 return;
00069 }
00070
00071 int
00072 ACE_TMAIN (int, ACE_TCHAR *[])
00073 {
00074 int status = 0;
00075 Basic_Content_Tester tester;
00076 ACEXML_StrCharStream *test_stream = 0;
00077 ACE_NEW_RETURN (test_stream, ACEXML_StrCharStream, -1);
00078 if (test_stream->open (tester.get_test_string (),
00079 ACE_TEXT ("test_stream")) < 0)
00080 {
00081 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Unable to create input stream\n")));
00082 return -1;
00083 }
00084 ACEXML_InputSource input (test_stream);
00085 ACEXML_Parser parser;
00086 parser.setContentHandler (&tester);
00087 ACEXML_TRY_NEW_ENV
00088 {
00089 parser.setFeature (ACE_TEXT ("http://xml.org/sax/features/validation"),
00090 0
00091 ACEXML_ENV_ARG_PARAMETER);
00092 ACEXML_TRY_CHECK;
00093 parser.parse (&input ACEXML_ENV_ARG_PARAMETER);
00094 ACEXML_TRY_CHECK;
00095 }
00096 ACEXML_CATCH (ACEXML_SAXException, ex)
00097 {
00098 ex.print();
00099 status = 1;
00100 }
00101 ACEXML_ENDTRY;
00102 return status;
00103 }