Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

ContentHandler_Test.cpp

Go to the documentation of this file.
00001 //=============================================================================
00002 /**
00003  *  @file    ContentHandler_Test.cpp
00004  *
00005  *  $Id: ContentHandler_Test.cpp,v 1.1.1.1 2003/02/21 18:36:32 chad Exp $
00006  *
00007  *  @author Steve Huston  <shuston@riverace.com>
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 
00016 class Basic_Content_Tester : public ACEXML_DefaultHandler
00017 {
00018 public:
00019   /**
00020    * Receive notification of character data.
00021    */
00022   virtual void characters (const ACEXML_Char *ch,
00023                            int start,
00024                            int length ACEXML_ENV_ARG_DECL)
00025         ACE_THROW_SPEC ((ACEXML_SAXException));
00026 
00027   const ACEXML_Char *get_test_string (void)
00028     { return Basic_Content_Tester::test_string_; }
00029 
00030 private:
00031   static const ACEXML_Char *test_string_;
00032 };
00033 
00034 const ACEXML_Char * Basic_Content_Tester::test_string_ =
00035   ACE_TEXT ("<?xml version=\"1.0\"?>")
00036   ACE_TEXT ("<translation type=\"unfinished\">Example\n")
00037   ACE_TEXT ("d&apos;internationalisation</translation></xml>");
00038 
00039 void
00040 Basic_Content_Tester::characters (const ACEXML_Char *ch,
00041                                   int start,
00042                                   int length ACEXML_ENV_ARG_DECL)
00043         ACE_THROW_SPEC ((ACEXML_SAXException))
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   int expected_len = ACE_static_cast (int, ACE_OS::strlen (expect));
00057   if (length != expected_len)
00058     {
00059       ACE_ERROR ((LM_ERROR,
00060                   ACE_TEXT ("characters() expected len %d (%*s); ")
00061                   ACE_TEXT ("got %d (%*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 =
00075     new ACEXML_StrCharStream (tester.get_test_string ());
00076   ACEXML_InputSource input (test_stream);
00077   ACEXML_Parser parser;
00078   parser.setContentHandler (&tester);
00079   ACEXML_TRY_NEW_ENV
00080     {
00081       parser.parse (&input ACEXML_ENV_ARG_PARAMETER);
00082       ACEXML_TRY_CHECK;
00083     }
00084   ACEXML_CATCHANY
00085     {
00086       ACE_ERROR ((LM_ERROR, ACE_TEXT ("Caught exception.\n")));
00087       status = 1;
00088     }
00089   ACEXML_ENDTRY;
00090   return status;
00091 }

Generated on Mon Jun 16 13:23:19 2003 for ACEXML by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002