summaryrefslogtreecommitdiffstats
path: root/Tests/FindOpenSP/Test/main.cxx
blob: ef8aa2c4e67b989dc9ddff82398bba244623346e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <cassert>
#include <string>

#include "ParserEventGeneratorKit.h"

std::string CharStringtostring(const SGMLApplication::CharString source)
{
  // The CharString type might have multi-byte characters if SP_MULTI_BYTE was
  // defined
  std::string result;
  result.resize(source.len);
  for (size_t i = 0; i < source.len; i++) {
    result[i] = static_cast<char>(source.ptr[i]);
  }
  return result;
}

class OutlineApplication : public SGMLApplication
{
public:
  OutlineApplication()
    : depth_(0)
  {
  }
  void startElement(const StartElementEvent& event)
  {
    for (unsigned i = 0; i < depth_; i++)
      parsedOutput += "\t";
    parsedOutput += CharStringtostring(event.gi);
    depth_++;
  }
  void endElement(const EndElementEvent&) { depth_--; }
  std::string parsedOutput;

private:
  unsigned depth_;
};

int main()
{
  std::string expectedOutput = "TESTDOC\tTESTELEMENT";
  char file_name[] = "test.sgml";
  char* files[] = { file_name, 0 };

  ParserEventGeneratorKit parserKit;
  EventGenerator* egp = parserKit.makeEventGenerator(1, files);
  OutlineApplication app;
  unsigned nErrors = egp->run(app);

  assert(nErrors == 0);
  assert(app.parsedOutput.compare(expectedOutput) == 0);

  delete egp;
  return 0;
}