1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
13 #include <anna/core/core.hpp>
14 #include <anna/xml/xml.hpp>
16 #include <anna/app/Application.hpp>
18 class Test : public app::Application {
23 void run () throw (anna::RuntimeException);
28 int main (int argc, const char** argv)
30 CommandLine& commandLine (CommandLine::instantiate ());
33 xml::functions::initialize ();
36 commandLine.initialize (argv, argc);
37 commandLine.verify ();
39 Logger::setLevel (Logger::Debug);
40 Logger::initialize ("XML", new TraceWriter ("file.trace", 2048000));
44 catch (Exception& ex) {
45 cout << ex.asString () << endl;
52 app::Application ("testfunctions", "Checking xpath", "1.0")
54 CommandLine& commandLine (CommandLine::instantiate ());
56 commandLine.add ("xml", CommandLine::Argument::Mandatory, "XML document");
57 commandLine.add ("xpath", CommandLine::Argument::Mandatory, "XPath condition");
58 commandLine.add ("mode", CommandLine::Argument::Optional, "Result type (simple,full,namespace)");
62 throw (RuntimeException)
64 CommandLine& commandLine (CommandLine::instantiate ());
66 xml::DocumentFile xmlDoc;
67 xml::Compiler xmlCompiler;
68 XPath xpath ("testing");
70 xmlDoc.initialize (commandLine.getValue ("xml"));
72 Microsecond init, final;
74 const char* expression = commandLine.getValue ("xpath");
75 const char* smode = NULL;
77 int mode = xml::XPath::Mode::Simple;
79 if (commandLine.exists ("mode")) {
80 smode = commandLine.getValue ("mode");
81 if (anna_strstr (smode, "full") != 0)
82 mode = xml::XPath::Mode::Full;
83 if (anna_strstr (smode, "namespace") != 0)
84 mode |= xml::XPath::Mode::Namespace;
87 // Several times to check reuse
88 for (int i = 0; i < 5; i ++) {
89 init = anna::functions::hardwareClock ();
90 xpath.apply (xmlDoc, expression, mode);
91 final = anna::functions::hardwareClock ();
92 cout << "Time (apply" << i << "): " << final - init << " us" << endl << endl;
93 if (xpath.isEmpty () == false) {
95 for (Node::const_child_iterator ii = xpath.node_begin (), maxii = xpath.node_end (); ii != maxii; ii ++)
96 cout << xmlCompiler.apply (XPath::node (ii)) << endl;
100 cout << "apply: no node matching expression" << endl << endl;
103 init = anna::functions::hardwareClock ();
104 bool match = xpath.match (xmlDoc, expression, mode);
105 final = anna::functions::hardwareClock ();
106 cout << "Time (match): " << final - init << " us" << endl << endl;
109 cout << "match: no node matching expression" << endl << endl;
111 xpath.apply (xmlDoc, expression, mode);
112 for (Node::const_child_iterator ii = xpath.node_begin (), maxii = xpath.node_end (); ii != maxii; ii ++)
113 cout << xmlCompiler.apply (XPath::node (ii), xml::Compiler::Mode::Compact | xml::Compiler::Mode::NoNamespaces) << endl;