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

[virt-tools-list] [libosinfo PATCHv2 11/11] test: Add test for param remapping in install scripts



---
 test/dbdata/datamaps/test-datamap.xml              | 47 +++++++++++
 .../dbdata/install-scripts/test-install-script.xml | 26 ++++++
 test/test-install-script.c                         | 96 ++++++++++++++++++++++
 3 files changed, 169 insertions(+)
 create mode 100644 test/dbdata/datamaps/test-datamap.xml
 create mode 100644 test/dbdata/install-scripts/test-install-script.xml

diff --git a/test/dbdata/datamaps/test-datamap.xml b/test/dbdata/datamaps/test-datamap.xml
new file mode 100644
index 0000000..8c5408b
--- /dev/null
+++ b/test/dbdata/datamaps/test-datamap.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<libosinfo version="0.0.1">
+
+  <datamap id="http://example.com/libosinfo/test-datamap";>
+    <entry>
+      <!-- default value for keyboard, mandatory -->
+      <inval>us</inval>
+      <outval>us</outval>
+    </entry>
+    <entry>
+      <inval>val1</inval>
+      <outval>foo</outval>
+    </entry>
+    <entry>
+      <inval>val2</inval>
+      <outval>bar</outval>
+    </entry>
+    <entry>
+      <inval>val3</inval>
+      <outval>baz</outval>
+    </entry>
+    <entry>
+      <inval>VAL1</inval>
+      <outval>FOOBAR</outval>
+    </entry>
+  </datamap>
+
+  <datamap id="http://example.com/libosinfo/test-datamap2";>
+    <entry>
+      <!-- default value for language, mandatory -->
+      <inval>en_EN.UTF-8</inval>
+      <outval>English</outval>
+    </entry>
+    <entry>
+      <inval>en_EN</inval>
+      <outval>English</outval>
+    </entry>
+    <entry>
+      <inval>fr_FR</inval>
+      <outval>French</outval>
+    </entry>
+    <entry>
+      <inval>fi_FI</inval>
+      <outval>Finnish</outval>
+    </entry>
+  </datamap>
+</libosinfo>
diff --git a/test/dbdata/install-scripts/test-install-script.xml b/test/dbdata/install-scripts/test-install-script.xml
new file mode 100644
index 0000000..48469ef
--- /dev/null
+++ b/test/dbdata/install-scripts/test-install-script.xml
@@ -0,0 +1,26 @@
+<libosinfo version="0.0.1">
+  <!-- JEOS PROFILE -->
+  <install-script id="http://example.com/libosinfo/test-install-script";>
+    <profile>jeos</profile>
+    <expected-filename>test.ks</expected-filename>
+    <config>
+      <param name="l10n-keyboard" policy="optional" value-map="http://example.com/libosinfo/test-datamap"/>
+      <param name="l10n-language" policy="optional" value-map="http://example.com/libosinfo/test-datamap2"/>
+      <param name="l10n-timezone" policy="optional"/>
+    </config>
+    <template>
+      <xsl:stylesheet
+        xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
+        version="1.0">
+
+        <xsl:output method="text"/>
+
+        <xsl:template match="/install-script-config">
+keyboard <xsl:value-of select="config/l10n-keyboard"/>
+lang <xsl:value-of select="config/l10n-language"/>
+timezone --utc <xsl:value-of select="config/l10n-timezone"/>
+        </xsl:template>
+      </xsl:stylesheet>
+    </template>
+  </install-script>
+</libosinfo>
diff --git a/test/test-install-script.c b/test/test-install-script.c
index 6abeeb3..cd8f378 100644
--- a/test/test-install-script.c
+++ b/test/test-install-script.c
@@ -56,6 +56,12 @@ static const gchar *expectData =                                        \
     "%end\n"                                                            \
     "  ";
 
+static const gchar *expectData2 =                                       \
+    "\n"                                                                \
+    "keyboard FOOBAR\n"                                                 \
+    "lang French\n"                                                     \
+    "timezone --utc Europe/Paris";
+
 static void test_generate_finish(GObject *src,
                                  GAsyncResult *res,
                                  gpointer user_data)
@@ -172,6 +178,95 @@ START_TEST(test_script_data)
 }
 END_TEST
 
+START_TEST(test_script_datamap)
+{
+    OsinfoLoader *loader = osinfo_loader_new();
+    OsinfoDb *db;
+    OsinfoOs *os;
+    OsinfoInstallScript *script;
+    OsinfoInstallConfig *config;
+    GMainLoop *loop;
+
+    osinfo_loader_process_path(loader, SRCDIR "/test/dbdata", &error);
+    fail_unless(error == NULL, error ? error->message : "none");
+    db = g_object_ref(osinfo_loader_get_db(loader));
+    g_object_unref(loader);
+
+    fail_unless(osinfo_db_get_datamap(db, "http://example.com/libosinfo/test-datamap";) != NULL, "Could not find OsinfoDatamap 'test-datamap'");
+    fail_unless(osinfo_db_get_datamap(db, "http://example.com/libosinfo/test-datamap2";) != NULL, "Could not find OsinfoDatamap 'test-datamap2'");
+    script = osinfo_db_get_install_script(db, "http://example.com/libosinfo/test-install-script";);
+    fail_unless(script != NULL, "Could not find OsinfoInstallScript 'test-install-script'");
+
+    config = osinfo_install_config_new_for_script("http://example.com";, script);
+
+    osinfo_install_config_set_l10n_keyboard(config, "unknown");
+    fail_unless(g_strcmp0(osinfo_install_config_get_l10n_keyboard(config), "unknown") == 0,
+                "Got %s instead of 'unknown'", osinfo_install_config_get_l10n_keyboard(config));
+    fail_unless(g_strcmp0(osinfo_entity_get_param_value(OSINFO_ENTITY(config), "l10n-keyboard"), "unknown") == 0,
+                "Got %s instead of 'foo'", osinfo_install_config_get_l10n_keyboard(config));
+
+    osinfo_install_config_set_l10n_keyboard(config, "val1");
+    fail_unless(g_strcmp0(osinfo_install_config_get_l10n_keyboard(config), "val1") == 0,
+                "Got %s instead of 'val1'", osinfo_install_config_get_l10n_keyboard(config));
+    fail_unless(g_strcmp0(osinfo_entity_get_param_value(OSINFO_ENTITY(config), "l10n-keyboard"), "foo") == 0,
+                "Got %s instead of 'foo'", osinfo_install_config_get_l10n_keyboard(config));
+
+    osinfo_install_config_set_l10n_keyboard(config, "val2");
+    fail_unless(g_strcmp0(osinfo_install_config_get_l10n_keyboard(config), "val2") == 0,
+                "Got %s instead of 'val2'", osinfo_install_config_get_l10n_keyboard(config));
+    fail_unless(g_strcmp0(osinfo_entity_get_param_value(OSINFO_ENTITY(config), "l10n-keyboard"), "bar") == 0,
+                "Got %s instead of 'bar'", osinfo_install_config_get_l10n_keyboard(config));
+
+    osinfo_install_config_set_l10n_keyboard(config, "val3");
+    fail_unless(g_strcmp0(osinfo_install_config_get_l10n_keyboard(config), "val3") == 0,
+                "Got %s instead of 'val3'", osinfo_install_config_get_l10n_keyboard(config));
+    fail_unless(g_strcmp0(osinfo_entity_get_param_value(OSINFO_ENTITY(config), "l10n-keyboard"), "baz") == 0,
+                "Got %s instead of 'baz'", osinfo_install_config_get_l10n_keyboard(config));
+
+    osinfo_install_config_set_l10n_keyboard(config, "VAL1");
+    fail_unless(g_strcmp0(osinfo_install_config_get_l10n_keyboard(config), "VAL1") == 0,
+                "Got %s instead of 'VAL1", osinfo_install_config_get_l10n_keyboard(config));
+    fail_unless(g_strcmp0(osinfo_entity_get_param_value(OSINFO_ENTITY(config), "l10n-keyboard"), "FOOBAR") == 0,
+                "Got %s instead of 'FOOBAR'", osinfo_install_config_get_l10n_keyboard(config));
+
+    osinfo_install_config_set_l10n_language(config, "en_EN");
+    fail_unless(g_strcmp0(osinfo_install_config_get_l10n_language(config), "en_EN") == 0,
+                "Got %s instead of 'en_EN'", osinfo_install_config_get_l10n_language(config));
+    fail_unless(g_strcmp0(osinfo_entity_get_param_value(OSINFO_ENTITY(config), "l10n-language"), "English") == 0,
+                "Got %s instead of 'English'", osinfo_install_config_get_l10n_language(config));
+    osinfo_install_config_set_l10n_language(config, "fr_FR");
+    osinfo_install_config_set_l10n_timezone(config, "Europe/Paris");
+
+
+    os = osinfo_os_new("http://fedoraproject.org/fedora/16";);
+    osinfo_entity_set_param(OSINFO_ENTITY(os),
+                            OSINFO_PRODUCT_PROP_SHORT_ID,
+                            "fedora16");
+
+    loop = g_main_loop_new (g_main_context_get_thread_default (),
+                            TRUE);
+
+    osinfo_install_script_generate_async(script,
+                                         os,
+                                         config,
+                                         NULL,
+                                         test_generate_finish,
+                                         loop);
+
+    if (g_main_loop_is_running(loop))
+        g_main_loop_run(loop);
+
+    unlink(BUILDDIR "/test/install-script-actual.txt");
+    fail_unless(error == NULL, error ? error->message : "none");
+
+    fail_unless(strcmp(actualData, expectData2) == 0, "Actual '%s' match expect '%s'",
+                actualData, expectData2);
+
+    g_object_unref(db);
+    g_object_unref(os);
+    g_object_unref(config);
+}
+END_TEST
 
 
 static Suite *
@@ -183,6 +278,7 @@ list_suite(void)
 
     tcase_add_test(tc, test_script_file);
     tcase_add_test(tc, test_script_data);
+    tcase_add_test(tc, test_script_datamap);
     suite_add_tcase(s, tc);
     return s;
 }
-- 
1.8.0.1


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