Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / ACEXML / tests / ContentHandler_Test.cpp
blob4e4231e7d6fe109503a6c6a329fa172bda47c6a1
1 //=============================================================================
2 /**
3 * @file ContentHandler_Test.cpp
5 * @author Steve Huston <shuston@riverace.com>
6 */
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
18 public:
19 /**
20 * Receive notification of character data.
22 virtual void characters (const ACEXML_Char *ch,
23 size_t start,
24 size_t length);
26 const ACEXML_Char *get_test_string ()
27 { return Basic_Content_Tester::test_string_; }
29 private:
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&apos;internationalisation</translation>");
38 void
39 Basic_Content_Tester::characters (const ACEXML_Char *ch,
40 size_t start,
41 size_t length)
43 static bool already_called = false;
44 static const ACEXML_Char *expect =
45 ACE_TEXT ("Example\nd'internationalisation");
47 if (already_called)
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)
57 ACE_ERROR ((LM_ERROR,
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"));
66 int
67 ACE_TMAIN (int, ACE_TCHAR *[])
69 int status = 0;
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")));
77 return -1;
79 ACEXML_InputSource input (test_stream);
80 ACEXML_Parser parser;
81 parser.setContentHandler (&tester);
82 try
84 parser.setFeature (ACE_TEXT ("http://xml.org/sax/features/validation"),
85 0);
86 parser.parse (&input);
88 catch (const ACEXML_SAXException& ex)
90 ex.print();
91 status = 1;
93 return status;