source: icXML/icXML-devel/tests/src/XSTSHarness/XSTSHarness.hpp @ 2733

Last change on this file since 2733 was 2733, checked in by cameron, 6 years ago

More path fixes.

File size: 5.4 KB
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/*
19 * $Id: XSTSHarness.hpp 804211 2009-08-14 13:18:09Z amassari $
20 */
21
22#ifndef XSTS_HARNESS_HPP
23#define XSTS_HARNESS_HPP
24
25// ---------------------------------------------------------------------------
26//  Includes for all the program files to see
27// ---------------------------------------------------------------------------
28
29#include <icxercesc/util/PlatformUtils.hpp>
30#include <stdlib.h>
31#include <string.h>
32#if defined(XERCES_NEW_IOSTREAMS)
33#include <iostream>
34#else
35#include <iostream.h>
36#endif
37#include <xercesc/sax2/XMLReaderFactory.hpp>
38#include <xercesc/sax2/SAX2XMLReader.hpp>
39#include <icxercesc/sax2/DefaultHandler.hpp>
40#include <xercesc/util/XMLURL.hpp>
41#include <xercesc/util/XMLEntityResolver.hpp>
42
43XERCES_CPP_NAMESPACE_USE
44
45typedef enum
46{
47    unknown,
48    invalid,
49    valid
50} ValidityOutcome;
51
52extern const XMLCh dummy[];
53
54// ---------------------------------------------------------------------------
55//  This is a simple class that lets us do easy (though not terribly efficient)
56//  trancoding of XMLCh data to local code page for display.
57// ---------------------------------------------------------------------------
58class StrX
59{
60public :
61    // -----------------------------------------------------------------------
62    //  Constructors and Destructor
63    // -----------------------------------------------------------------------
64    StrX(const XMLCh* const toTranscode)
65    {
66        // Call the private transcoding method
67        fLocalForm = XMLString::transcode(toTranscode);
68    }
69
70    ~StrX()
71    {
72        XMLString::release(&fLocalForm);
73    }
74
75    // -----------------------------------------------------------------------
76    //  Getter methods
77    // -----------------------------------------------------------------------
78    const char* localForm() const
79    {
80        return fLocalForm;
81    }
82
83private :
84    // -----------------------------------------------------------------------
85    //  Private data members
86    //
87    //  fLocalForm
88    //      This is the local code page form of the string.
89    // -----------------------------------------------------------------------
90    char*   fLocalForm;
91};
92
93inline XERCES_STD_QUALIFIER ostream& operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
94{
95    target << toDump.localForm();
96    return target;
97}
98
99class BaseHarnessHandlers : public DefaultHandler
100{
101public:
102    // -----------------------------------------------------------------------
103    //  Constructors and Destructor
104    // -----------------------------------------------------------------------
105    BaseHarnessHandlers(const XMLCh* baseURL);
106
107    unsigned int getTotalTests() const
108    {
109        return fTests;
110    }
111    unsigned int getFailedTests() const
112    {
113        return fFailures;
114    }
115
116    bool getSawErrors() const
117    {
118        return fSawErrors;
119    }
120
121    void printFile(XMLURL& url);
122
123    // -----------------------------------------------------------------------
124    //  Handlers for the SAX ErrorHandler interface
125    // -----------------------------------------------------------------------
126        void warning(const SAXParseException& exc);
127    void error(const SAXParseException& exc);
128    void fatalError(const SAXParseException& exc);
129    void resetErrors()
130    {
131        fSawErrors = false;
132    }
133
134protected:
135    XMLURL              fBaseURL;
136    bool                fSawErrors;
137    unsigned int        fFailures, fTests;
138};
139
140class BaseErrorHandler : public ErrorHandler
141{
142public:
143    BaseErrorHandler() : fSawErrors(false) {}
144
145    bool getSawErrors() const
146    {
147        return fSawErrors;
148    }
149    const XMLCh* getErrorText()
150    {
151        return fErrorText.getRawBuffer();
152    }
153
154    // -----------------------------------------------------------------------
155    //  Handlers for the SAX ErrorHandler interface
156    // -----------------------------------------------------------------------
157    void warning(const SAXParseException& exc)      {}
158    void error(const SAXParseException& exc);
159    void fatalError(const SAXParseException& exc);
160    void resetErrors()                              { fSawErrors=false; fErrorText.reset(); }
161
162private:
163    // -----------------------------------------------------------------------
164    //  Private data members
165    //
166    //  fSawErrors
167    //      This is set by the error handlers, and is queryable later to
168    //      see if any errors occured.
169    // -----------------------------------------------------------------------
170    bool            fSawErrors;
171    XMLBuffer       fErrorText;
172};
173
174class BaseEntityResolver : public XMLEntityResolver
175{
176public:
177    BaseEntityResolver() {};
178
179    virtual InputSource* resolveEntity(XMLResourceIdentifier* resourceIdentifier);
180
181};
182
183#endif
Note: See TracBrowser for help on using the repository browser.