aba4ce97c94c7c98a302986954b604793c823197
1 /**
2 * Phoebe DOM Implementation.
3 *
4 * This is a C++ approximation of the W3C DOM model, which follows
5 * fairly closely the specifications in the various .idl files, copies of
6 * which are provided for reference. Most important is this one:
7 *
8 * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html
9 *
10 * Authors:
11 * Bob Jamison
12 *
13 * Copyright (C) 2005 Bob Jamison
14 *
15 * This library is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU Lesser General Public
17 * License as published by the Free Software Foundation; either
18 * version 2.1 of the License, or (at your option) any later version.
19 *
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
24 *
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 */
32 #include "jsengine.h"
33 #include "lsimpl.h"
35 using namespace org::w3c::dom;
38 bool doTest1()
39 {
41 char *filename = "test.xml";
42 ls::DOMImplementationLSImpl domImpl;
43 ls::LSInput input = domImpl.createLSInput();
44 ls::LSParser &parser = domImpl.createLSParser(0, "");
46 DOMString buf;
47 FILE *f = fopen(filename, "rb");
48 if (!f)
49 {
50 printf("Cannot open %s for reading\n", filename);
51 return false;
52 }
53 while (!feof(f))
54 {
55 int ch = fgetc(f);
56 buf.push_back(ch);
57 }
58 fclose(f);
59 input.setStringData(buf);
61 printf("######## PARSE ######################################\n");
62 DocumentPtr doc = parser.parse(input);
64 if (!doc)
65 {
66 printf("parsing failed\n");
67 return 0;
68 }
70 //### OUTPUT
71 printf("######## SERIALIZE ##################################\n");
72 ls::LSSerializer &serializer = domImpl.createLSSerializer();
73 ls::LSOutput output = domImpl.createLSOutput();
74 io::StdWriter writer;
75 output.setCharacterStream(&writer);
76 serializer.write(doc, output);
78 printf("####### Namespace check\n");
79 DOMString svgNamespace = "http://www.w3.org/2000/svg";
80 NodeList list = doc->getElementsByTagNameNS(svgNamespace, "svg");
81 int nodeCount = list.getLength();
82 printf("Nodes:%d\n", nodeCount);
83 for (int i=0; i<nodeCount ; i++)
84 {
85 NodePtr node = list.item(i);
86 serializer.write(node, output);
87 }
89 return true;
90 }
93 bool doTest2()
94 {
95 JavascriptEngine js;
96 bool ret = js.evaluate("print(3 * 5);");
97 if (!ret)
98 return false;
100 ret = js.evaluate("var s = new CDATASection();");
101 if (!ret)
102 return false;
104 return true;
105 }
110 bool doTests()
111 {
112 //if (!doTest1())
113 // return false;
114 if (!doTest2())
115 return false;
116 return true;
117 }
120 int main(int argc, char **argv)
121 {
122 if (!doTests())
123 return 1;
124 return 0;
125 }