Imported Upstream version 3.25.0
[platform/upstream/cmake.git] / Tests / FindOpenSP / Test / main.cxx
1 #include <cassert>
2 #include <string>
3
4 #include "ParserEventGeneratorKit.h"
5
6 std::string CharStringtostring(const SGMLApplication::CharString source)
7 {
8   // The CharString type might have multi-byte characters if SP_MULTI_BYTE was
9   // defined
10   std::string result;
11   result.resize(source.len);
12   for (size_t i = 0; i < source.len; i++) {
13     result[i] = static_cast<char>(source.ptr[i]);
14   }
15   return result;
16 }
17
18 class OutlineApplication : public SGMLApplication
19 {
20 public:
21   OutlineApplication()
22     : depth_(0)
23   {
24   }
25   void startElement(const StartElementEvent& event)
26   {
27     for (unsigned i = 0; i < depth_; i++)
28       parsedOutput += "\t";
29     parsedOutput += CharStringtostring(event.gi);
30     depth_++;
31   }
32   void endElement(const EndElementEvent&) { depth_--; }
33   std::string parsedOutput;
34
35 private:
36   unsigned depth_;
37 };
38
39 int main()
40 {
41   std::string expectedOutput = "TESTDOC\tTESTELEMENT";
42   char file_name[] = "test.sgml";
43   char* files[] = { file_name, 0 };
44
45   ParserEventGeneratorKit parserKit;
46   EventGenerator* egp = parserKit.makeEventGenerator(1, files);
47   OutlineApplication app;
48   unsigned nErrors = egp->run(app);
49
50   assert(nErrors == 0);
51   assert(app.parsedOutput.compare(expectedOutput) == 0);
52
53   delete egp;
54   return 0;
55 }