[vala-tests] tests: update xml test from wiki



commit f495c6408057547eb1d9e6e73b8c9452622b892a
Author: Marc-André Lureau <marcandre lureau gmail com>
Date:   Thu Apr 8 00:14:17 2010 +0200

    tests: update xml test from wiki

 tests/examples/libxml2-writer.test              |    3 ++
 tests/examples/libxml2-writer.vala              |   34 +++++++++++++++++++++++
 tests/examples/soup-xmlrpc-test-addnumbers.test |    3 ++
 tests/examples/soup-xmlrpc-test-addnumbers.vala |   22 +++++++++++++++
 tests/examples/soup-xmlrpc-test-hello.test      |    3 ++
 tests/examples/soup-xmlrpc-test-hello.vala      |   20 +++++++++++++
 6 files changed, 85 insertions(+), 0 deletions(-)
---
diff --git a/tests/examples/libxml2-writer.test b/tests/examples/libxml2-writer.test
new file mode 100755
index 0000000..8c65445
--- /dev/null
+++ b/tests/examples/libxml2-writer.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. test-common.sh
diff --git a/tests/examples/libxml2-writer.vala b/tests/examples/libxml2-writer.vala
new file mode 100644
index 0000000..d746ed1
--- /dev/null
+++ b/tests/examples/libxml2-writer.vala
@@ -0,0 +1,34 @@
+
+// http://live.gnome.org/Vala/XmlSample vala-test:examples/libxml2-writer.vala
+
+void main () {
+    var writer = new Xml.TextWriter.filename ("test.xml");
+    writer.set_indent (true);
+    writer.set_indent_string ("\t");
+
+    writer.start_document ();
+    writer.start_element ("root_element");
+
+    writer.start_attribute ("base64attribute");
+    writer.write_base64 ("test", 0, 4);
+    writer.end_attribute ();
+
+    writer.write_attribute ("alpha", "abcdef..");
+
+    writer.write_element ("element", "content");
+    writer.write_element_ns ("ns", "elementWithNS", "http://www.example.org/test/ns";, "contentNS");
+
+    writer.write_comment ("My comment!");
+    writer.format_element_ns ("ns", "elementWithFormattedContent", "http://www.example.org/test/ns";, "One: %d", 10);
+
+    writer.start_element("cdataContent");
+    writer.start_cdata();
+    writer.format_string("%s beer on the wall..", "One");
+    writer.end_cdata();
+    writer.end_element();
+
+    writer.end_element();
+    writer.end_document();
+
+    writer.flush();
+}
diff --git a/tests/examples/soup-xmlrpc-test-addnumbers.test b/tests/examples/soup-xmlrpc-test-addnumbers.test
new file mode 100755
index 0000000..8c65445
--- /dev/null
+++ b/tests/examples/soup-xmlrpc-test-addnumbers.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. test-common.sh
diff --git a/tests/examples/soup-xmlrpc-test-addnumbers.vala b/tests/examples/soup-xmlrpc-test-addnumbers.vala
new file mode 100644
index 0000000..278613b
--- /dev/null
+++ b/tests/examples/soup-xmlrpc-test-addnumbers.vala
@@ -0,0 +1,22 @@
+
+// http://live.gnome.org/Vala/LibSoupSample vala-test:examples/soup-xmlrpc-test-addnumbers.vala
+
+using Soup;
+
+void main () {
+    var message = xmlrpc_request_new ("http://kushaldas.wordpress.com/xmlrpc.php";,
+                                     "demo.addTwoNumbers",
+                                     typeof (int), 20,
+                                     typeof (int), 30);
+    var session = new SessionSync ();
+    session.send_message (message);
+    
+    string data = message.response_body.flatten ().data;
+    try {
+        Value v = Value (typeof (int));
+        xmlrpc_parse_method_response (data, -1, v);
+        stdout.printf ("Result: %d\n", (int) v);
+    } catch (Error e) {
+        stderr.printf ("Error while processing the response: %s\n", e.message);
+    }
+}
diff --git a/tests/examples/soup-xmlrpc-test-hello.test b/tests/examples/soup-xmlrpc-test-hello.test
new file mode 100755
index 0000000..8c65445
--- /dev/null
+++ b/tests/examples/soup-xmlrpc-test-hello.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. test-common.sh
diff --git a/tests/examples/soup-xmlrpc-test-hello.vala b/tests/examples/soup-xmlrpc-test-hello.vala
new file mode 100644
index 0000000..9b0283f
--- /dev/null
+++ b/tests/examples/soup-xmlrpc-test-hello.vala
@@ -0,0 +1,20 @@
+
+// http://live.gnome.org/Vala/LibSoupSample vala-test:examples/soup-xmlrpc-test-hello.vala
+
+using Soup;
+
+void main () {
+    var message = xmlrpc_request_new ("http://kushaldas.wordpress.com/xmlrpc.php";,
+                                     "demo.sayHello");
+    var session = new SessionSync ();
+    session.send_message (message);
+
+    string data = message.response_body.flatten ().data;
+    try {
+        Value v = Value (typeof (string));
+        xmlrpc_parse_method_response (data, -1, v);
+        stdout.printf ("Got: %s\n", (string) v);
+    } catch (Error e) {
+        stderr.printf ("Error while processing the response: %s\n", e.message);
+    }
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]