Code

Start shell. Begin to make prototypes and wrappers.
[inkscape.git] / src / dom / work / testjs.cpp
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     Document *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         Node *node = list.item(i);
86         serializer.write(node, output);
87         }
89     delete doc;
90     return true;
91 }
94 bool doTest2()
95 {
96     JavascriptEngine js;
97     bool ret = js.evaluate("print(3 * 5);");
98     if (!ret)
99         return false;
101     ret = js.evaluate("var s = new CDATASection();");
102     if (!ret)
103         return false;
104         
105     return true;
111 bool doTests()
113     //if (!doTest1())
114     //    return false;
115     if (!doTest2())
116         return false;
117     return true;
121 int main(int argc, char **argv)
123     if (!doTests())
124         return 1;
125     return 0;