[Libosinfo] [libosinfo PATCH 1/3] tests: Add test-image

Fabiano Fidêncio fidencio at redhat.com
Thu Nov 1 14:57:56 UTC 2018


test-image tests the basic functionally of OsImage APIs.

Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
 tests/Makefile.am  |  5 ++++
 tests/test-image.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 69 insertions(+)
 create mode 100644 tests/test-image.c

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 06f81bf..410f373 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -18,6 +18,7 @@ check_PROGRAMS = \
 	test-isodetect \
 	test-install-script \
 	test-os-resources \
+	test-image \
         $(NULL)
 
 if HAVE_CURL
@@ -116,6 +117,10 @@ test_os_resources_LDADD = $(COMMON_LDADD)
 test_os_resources_CFLAGS = $(COMMON_CFLAGS)
 test_os_resources_SOURCES = test-os-resources.c
 
+test_image_LDADD = $(COMMON_LDADD)
+test_image_CFLAGS = $(COMMON_CFLAGS)
+test_image_SOURCES = test-image.c
+
 TESTS = $(check_PROGRAMS) \
 	$(NULL)
 
diff --git a/tests/test-image.c b/tests/test-image.c
new file mode 100644
index 0000000..cc0e335
--- /dev/null
+++ b/tests/test-image.c
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2018 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ * Authors:
+ *   Fabiano Fidênciog <fidencio at redhat.com>
+ */
+
+#include <config.h>
+
+#include <osinfo/osinfo.h>
+
+#define ID "foo"
+#define ARCH "x86_64"
+#define URL "https://foo.bar/foobar.img"
+
+static void
+test_basic(void)
+{
+    OsinfoImage *image = osinfo_image_new(ID, ARCH);
+    osinfo_entity_set_param(OSINFO_ENTITY(image),
+                            OSINFO_IMAGE_PROP_URL,
+                            URL);
+
+    g_assert_true(OSINFO_IS_IMAGE(image));
+    g_assert_cmpstr(osinfo_entity_get_id(OSINFO_ENTITY(image)), ==, ID);
+    g_assert_cmpstr(osinfo_image_get_architecture(image), ==, ARCH);
+    g_assert_cmpstr(osinfo_image_get_url(image), ==, URL);
+
+    g_object_unref(image);
+}
+
+
+int
+main(int argc, char *argv[])
+{
+    g_test_init(&argc, &argv, NULL);
+
+    g_test_add_func("/image/basic", test_basic);
+
+    /* Upfront so we don't confuse valgrind */
+    osinfo_image_get_type();
+
+    return g_test_run();
+}
+/*
+ * Local variables:
+ *  indent-tabs-mode: nil
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ * End:
+ */
-- 
2.19.1




More information about the Libosinfo mailing list