1 //=============================================================================
3 * @file ContentHandler_Test.cpp
5 * @author Steve Huston <shuston@riverace.com>
7 //=============================================================================
9 #include "ACEXML/common/DefaultHandler.h"
10 #include "ACEXML/common/InputSource.h"
11 #include "ACEXML/common/StrCharStream.h"
12 #include "ACEXML/parser/parser/Parser.h"
13 #include "ace/OS_NS_string.h"
14 #include "ace/OS_main.h"
16 class Basic_Content_Tester
: public ACEXML_DefaultHandler
20 * Receive notification of character data.
22 virtual void characters (const ACEXML_Char
*ch
,
26 const ACEXML_Char
*get_test_string ()
27 { return Basic_Content_Tester::test_string_
; }
30 static const ACEXML_Char
*test_string_
;
33 const ACEXML_Char
* Basic_Content_Tester::test_string_
=
34 ACE_TEXT ("<?xml version=\"1.0\"?>")
35 ACE_TEXT ("<translation type=\"unfinished\">Example\n")
36 ACE_TEXT ("d'internationalisation</translation>");
39 Basic_Content_Tester::characters (const ACEXML_Char
*ch
,
43 static bool already_called
= false;
44 static const ACEXML_Char
*expect
=
45 ACE_TEXT ("Example\nd'internationalisation");
49 throw ACEXML_SAXException
50 (ACE_TEXT ("characters() called too much\n"));
52 already_called
= true;
54 size_t const expected_len
= ACE_OS::strlen (expect
);
55 if (length
!= expected_len
)
58 ACE_TEXT ("characters() expected len %u (%*s); ")
59 ACE_TEXT ("got %u (%*s)\n"),
60 expected_len
, expected_len
, ch
+ start
,
61 length
, length
, ch
+ start
));
62 throw ACEXML_SAXException (ACE_TEXT ("Functionality failure"));
67 ACE_TMAIN (int, ACE_TCHAR
*[])
70 Basic_Content_Tester tester
;
71 ACEXML_StrCharStream
*test_stream
= 0;
72 ACE_NEW_RETURN (test_stream
, ACEXML_StrCharStream
, -1);
73 if (test_stream
->open (tester
.get_test_string (),
74 ACE_TEXT ("test_stream")) < 0)
76 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("Unable to create input stream\n")));
79 ACEXML_InputSource
input (test_stream
);
81 parser
.setContentHandler (&tester
);
84 parser
.setFeature (ACE_TEXT ("http://xml.org/sax/features/validation"),
86 parser
.parse (&input
);
88 catch (const ACEXML_SAXException
& ex
)