[libosinfo PATCH 5/5] test-media: Add tests for OsinfoMedia attributes

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

 



Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
 .../test-os-media-no-installer.xml            | 13 ++++
 .../dbdata/os/libosinfo.org/test-os-media.xml | 17 +++++
 tests/test-media.c                            | 76 +++++++++++++++++++
 3 files changed, 106 insertions(+)
 create mode 100644 tests/dbdata/os/libosinfo.org/test-os-media-no-installer.xml
 create mode 100644 tests/dbdata/os/libosinfo.org/test-os-media.xml

diff --git a/tests/dbdata/os/libosinfo.org/test-os-media-no-installer.xml b/tests/dbdata/os/libosinfo.org/test-os-media-no-installer.xml
new file mode 100644
index 0000000..758490e
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-os-media-no-installer.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<libosinfo version="0.0.1">
+  <os id="http://libosinfo.org/test/os/media-no-installer";>
+    <short-id>media-no-installer</short-id>
+    <name>Media no installer</name>
+    <version>unknown</version>
+    <vendor>libosinfo.org</vendor>
+    <family>test</family>
+
+    <media arch="x86_64" installer-script="true"/>
+    <media arch="x86"/>
+  </os>
+</libosinfo>
diff --git a/tests/dbdata/os/libosinfo.org/test-os-media.xml b/tests/dbdata/os/libosinfo.org/test-os-media.xml
new file mode 100644
index 0000000..ddde1ef
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-os-media.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<libosinfo version="0.0.1">
+  <os id="http://libosinfo.org/test/os/media";>
+    <short-id>media</short-id>
+    <name>Media</name>
+    <version>unknown</version>
+    <vendor>libosinfo.org</vendor>
+    <family>test</family>
+
+    <media arch="x86_64" live="true" installer-reboots="3" eject-after-install="false" installer-script="false"/>
+    <media arch="x86"/>
+
+    <installer>
+      <script id="http://example.com/libosinfo/test-install-script"/>
+    </installer>
+  </os>
+</libosinfo>
diff --git a/tests/test-media.c b/tests/test-media.c
index 062b751..bfa053f 100644
--- a/tests/test-media.c
+++ b/tests/test-media.c
@@ -37,12 +37,88 @@ test_basic(void)
 }
 
 
+static void
+test_loaded_attributes(void)
+{
+    OsinfoLoader *loader = osinfo_loader_new();
+    OsinfoDb *db;
+    OsinfoOs *os;
+    OsinfoMediaList *list;
+    gint list_len, i;
+    GError *error = NULL;
+
+    osinfo_loader_process_path(loader, SRCDIR "/tests/dbdata", &error);
+    g_assert_no_error(error);
+    db = osinfo_loader_get_db(loader);
+
+    os = osinfo_db_get_os(db, "http://libosinfo.org/test/os/media";);
+
+    list = osinfo_os_get_media_list(os);
+    list_len = osinfo_list_get_length(OSINFO_LIST(list));
+    g_assert_cmpint(list_len, ==, 2);
+
+    for (i = 0; i < list_len; i++) {
+        OsinfoMedia *media = OSINFO_MEDIA(osinfo_list_get_nth(OSINFO_LIST(list), i));
+
+        if (g_str_equal(osinfo_media_get_architecture(media), "x86_64")) {
+            /* non-default values */
+            g_assert_true(osinfo_media_get_live(media));
+            g_assert_cmpint(osinfo_media_get_installer_reboots(media), ==, 3);
+            g_assert_false(osinfo_media_get_eject_after_install(media));
+            g_assert_false(osinfo_media_supports_installer_script(media));
+        } else if (g_str_equal(osinfo_media_get_architecture(media), "x86")) {
+            /* default-values */
+            g_assert_false(osinfo_media_get_live(media));
+            g_assert_cmpint(osinfo_media_get_installer_reboots(media), ==, 1);
+            g_assert_true(osinfo_media_get_eject_after_install(media));
+            g_assert_true(osinfo_media_supports_installer_script(media));
+        }
+    }
+
+    g_object_unref(list);
+    g_object_unref(loader);
+}
+
+
+static void
+test_loaded_no_installer(void)
+{
+    OsinfoLoader *loader = osinfo_loader_new();
+    OsinfoDb *db;
+    OsinfoOs *os;
+    OsinfoMediaList *list;
+    gint list_len, i;
+    GError *error = NULL;
+
+    osinfo_loader_process_path(loader, SRCDIR "/tests/dbdata", &error);
+    g_assert_no_error(error);
+    db = osinfo_loader_get_db(loader);
+
+    os = osinfo_db_get_os(db, "http://libosinfo.org/test/os/media-no-installer";);
+
+    list = osinfo_os_get_media_list(os);
+    list_len = osinfo_list_get_length(OSINFO_LIST(list));
+    g_assert_cmpint(list_len, ==, 2);
+
+    for (i = 0; i < list_len; i++) {
+        OsinfoMedia *media = OSINFO_MEDIA(osinfo_list_get_nth(OSINFO_LIST(list), i));
+
+        g_assert_false(osinfo_media_supports_installer_script(media));
+    }
+
+    g_object_unref(list);
+    g_object_unref(loader);
+}
+
+
 int
 main(int argc, char *argv[])
 {
     g_test_init(&argc, &argv, NULL);
 
     g_test_add_func("/media/basic", test_basic);
+    g_test_add_func("/media/loaded/attributes", test_loaded_attributes);
+    g_test_add_func("/media/loaded/no-installer", test_loaded_no_installer);
 
     /* Upfront so we don't confuse valgrind */
     osinfo_media_get_type();
-- 
2.19.1

_______________________________________________
Libosinfo mailing list
Libosinfo@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libosinfo




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

  Powered by Linux