[libvirt-glib 12/23] Add domain creation/parsing test

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

 



---
 configure.ac                                  |    1 +
 libvirt-gconfig/Makefile.am                   |    1 +
 libvirt-gconfig/tests/Makefile.am             |   16 ++++++
 libvirt-gconfig/tests/test-domain-create.c    |   53 +++++++++++++++++++
 libvirt-gconfig/tests/test-domain-invalid.xml |    6 ++
 libvirt-gconfig/tests/test-domain-noname.xml  |    4 ++
 libvirt-gconfig/tests/test-domain-parse.c     |   67 +++++++++++++++++++++++++
 libvirt-gconfig/tests/test-domain.xml         |    5 ++
 8 files changed, 153 insertions(+), 0 deletions(-)
 create mode 100644 libvirt-gconfig/tests/Makefile.am
 create mode 100644 libvirt-gconfig/tests/test-domain-create.c
 create mode 100644 libvirt-gconfig/tests/test-domain-invalid.xml
 create mode 100644 libvirt-gconfig/tests/test-domain-noname.xml
 create mode 100644 libvirt-gconfig/tests/test-domain-parse.c
 create mode 100644 libvirt-gconfig/tests/test-domain.xml

diff --git a/configure.ac b/configure.ac
index 0581874..7903281 100644
--- a/configure.ac
+++ b/configure.ac
@@ -201,6 +201,7 @@ AM_CONDITIONAL([WITH_GOBJECT_INTROSPECTION], [test "x$enable_introspection" = "x
 AC_OUTPUT(Makefile
           libvirt-glib/Makefile
           libvirt-gconfig/Makefile
+          libvirt-gconfig/tests/Makefile
           libvirt-gobject/Makefile
           examples/Makefile
           python/Makefile
diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am
index 634ad5a..8296dd1 100644
--- a/libvirt-gconfig/Makefile.am
+++ b/libvirt-gconfig/Makefile.am
@@ -1,3 +1,4 @@
+SUBDIRS = . tests
 
 EXTRA_DIST = libvirt-gconfig.sym
 
diff --git a/libvirt-gconfig/tests/Makefile.am b/libvirt-gconfig/tests/Makefile.am
new file mode 100644
index 0000000..1406b17
--- /dev/null
+++ b/libvirt-gconfig/tests/Makefile.am
@@ -0,0 +1,16 @@
+noinst_PROGRAMS = test-domain-create test-domain-parse
+
+AM_CFLAGS = \
+		$(GOBJECT2_CFLAGS) \
+		$(LIBXML2_CFLAGS) \
+		$(WARN_CFLAGS)
+INCLUDES = -I$(top_srcdir)/libvirt-gconfig
+LDADD = \
+		$(top_builddir)/libvirt-gconfig/libvirt-gconfig-1.0.la \
+		$(GOBJECT2_LIBS) \
+		$(LIBXML2_LIBS) \
+		$(CYGWIN_EXTRA_LIBADD)
+
+test_domain_create_SOURCES = test-domain-create.c
+
+test_domain_parse_SOURCES = test-domain-parse.c
diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c
new file mode 100644
index 0000000..a742dd7
--- /dev/null
+++ b/libvirt-gconfig/tests/test-domain-create.c
@@ -0,0 +1,53 @@
+/*
+ * test-domain-create.c: test libvirt-gconfig domain creation
+ *
+ * Copyright (C) 2011 Red Hat
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * The Software is provided "as is", without warranty of any kind, express
+ * or implied, including but not limited to the warranties of
+ * merchantability, fitness for a particular purpose and noninfringement.
+ * In no event shall the authors or copyright holders be liable for any
+ * claim, damages or other liability, whether in an action of contract,
+ * tort or otherwise, arising from, out of or in connection with the
+ * software or the use or other dealings in the Software.
+ *
+ * Author: Christophe Fergeau <cfergeau@xxxxxxxxxx>
+ */
+
+#include <string.h>
+#include <libvirt-gconfig/libvirt-gconfig.h>
+
+int main(void)
+{
+    GVirConfigDomain *domain;
+    char *name;
+    char *xml;
+
+    g_type_init();
+
+    domain = gvir_config_domain_new();
+    g_assert(domain != NULL);
+    gvir_config_domain_set_name(domain, "foo");
+    name = gvir_config_domain_get_name(domain);
+    g_assert(name != NULL);
+    g_assert(strcmp(name, "foo") == 0);
+    g_free(name);
+
+    xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(domain));
+    g_print("%s\n", xml);
+    g_free(xml);
+    g_object_unref(G_OBJECT(domain));
+
+    return 0;
+}
diff --git a/libvirt-gconfig/tests/test-domain-invalid.xml b/libvirt-gconfig/tests/test-domain-invalid.xml
new file mode 100644
index 0000000..73c6e6e
--- /dev/null
+++ b/libvirt-gconfig/tests/test-domain-invalid.xml
@@ -0,0 +1,6 @@
+<invalidtag
+<domain type='xen' id='3'>
+  <name>fv0</name>
+  <uuid>4dea22b31d52d8f32516782e98ab3fa0</uuid>
+  <description>Some human readable description</description>
+</domain>
diff --git a/libvirt-gconfig/tests/test-domain-noname.xml b/libvirt-gconfig/tests/test-domain-noname.xml
new file mode 100644
index 0000000..7974f83
--- /dev/null
+++ b/libvirt-gconfig/tests/test-domain-noname.xml
@@ -0,0 +1,4 @@
+<domain type='xen' id='3'>
+  <uuid>4dea22b31d52d8f32516782e98ab3fa0</uuid>
+  <description>Some human readable description</description>
+</domain>
diff --git a/libvirt-gconfig/tests/test-domain-parse.c b/libvirt-gconfig/tests/test-domain-parse.c
new file mode 100644
index 0000000..3a36144
--- /dev/null
+++ b/libvirt-gconfig/tests/test-domain-parse.c
@@ -0,0 +1,67 @@
+/*
+ * test-domain-create.c: test libvirt-gconfig domain parsing
+ *
+ * Copyright (C) 2011 Red Hat
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * The Software is provided "as is", without warranty of any kind, express
+ * or implied, including but not limited to the warranties of
+ * merchantability, fitness for a particular purpose and noninfringement.
+ * In no event shall the authors or copyright holders be liable for any
+ * claim, damages or other liability, whether in an action of contract,
+ * tort or otherwise, arising from, out of or in connection with the
+ * software or the use or other dealings in the Software.
+ *
+ * Author: Christophe Fergeau <cfergeau@xxxxxxxxxx>
+ */
+
+#include <string.h>
+#include <libvirt-gconfig/libvirt-gconfig.h>
+
+
+int main(int argc, char **argv)
+{
+    GVirConfigDomain *domain;
+    char *name;
+    char *xml;
+    GError *error = NULL;
+
+    if (argc != 2) {
+        g_print("Usage: %s filename\n", argv[0]);
+        g_print("Attempt to parse the libvirt XML definition from filename\n");
+        return 1;
+    }
+
+    g_file_get_contents(argv[1], &xml, NULL, &error);
+    if (error != NULL) {
+        g_print("Couldn't read %s: %s\n", argv[1], error->message);
+        return 2;
+    }
+
+    g_type_init();
+
+    domain = gvir_config_domain_new_from_xml(xml);
+    g_assert(domain != NULL);
+    name = gvir_config_domain_get_name(domain);
+    g_assert(name != NULL);
+    g_assert(strcmp(name, "foo") == 0);
+    g_free(name);
+    g_free(xml);
+
+    xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(domain));
+    g_print("%s\n", xml);
+    g_free(xml);
+    g_object_unref(G_OBJECT(domain));
+
+    return 0;
+}
diff --git a/libvirt-gconfig/tests/test-domain.xml b/libvirt-gconfig/tests/test-domain.xml
new file mode 100644
index 0000000..08a926e
--- /dev/null
+++ b/libvirt-gconfig/tests/test-domain.xml
@@ -0,0 +1,5 @@
+<domain type='xen' id='3'>
+  <name>foo</name>
+  <uuid>4dea22b31d52d8f32516782e98ab3fa0</uuid>
+  <description>Some human readable description</description>
+</domain>
-- 
1.7.6.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]