Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx> --- .gitignore | 1 + tests/Makefile.am | 5 +++ tests/test-link.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 tests/test-link.c diff --git a/.gitignore b/.gitignore index 1c31793..47f15db 100644 --- a/.gitignore +++ b/.gitignore @@ -50,6 +50,7 @@ tests/test-device tests/test-os tests/test-entity tests/test-hypervisor +tests/test-link tests/test-list tests/test-db tests/test-devicelist diff --git a/tests/Makefile.am b/tests/Makefile.am index 303a57a..3f7f14c 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -4,6 +4,7 @@ EXTRA_DIST = isodata dbdata check_PROGRAMS = \ test-entity \ test-device \ + test-link \ test-list \ test-devicelist \ test-devicelinklist \ @@ -80,6 +81,10 @@ test_platform_LDADD = $(COMMON_LDADD) test_platform_CFLAGS = $(COMMON_CFLAGS) test_platform_SOURCES = test-platform.c +test_link_LDADD = $(COMMON_LDADD) +test_link_CFLAGS = $(COMMON_CFLAGS) +test_link_SOURCES = test-link.c + test_list_LDADD = $(COMMON_LDADD) test_list_CFLAGS = $(COMMON_CFLAGS) test_list_SOURCES = test-list.c diff --git a/tests/test-link.c b/tests/test-link.c new file mode 100644 index 0000000..601c776 --- /dev/null +++ b/tests/test-link.c @@ -0,0 +1,104 @@ +/* + * 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êncio <fidencio@xxxxxxxxxx> + */ + +#include <config.h> + +#include <osinfo/osinfo.h> + +/* OsinfoEntity is abstract, so we need to trivially subclass it to test it */ +typedef struct _OsinfoDummy OsinfoDummy; +typedef struct _OsinfoDummyClass OsinfoDummyClass; + +struct _OsinfoDummy +{ + OsinfoEntity parent_instance; +}; + +struct _OsinfoDummyClass +{ + OsinfoEntityClass parent_class; +}; + +GType osinfo_dummy_get_type(void); + +G_DEFINE_TYPE(OsinfoDummy, osinfo_dummy, OSINFO_TYPE_ENTITY); + +static void osinfo_dummy_class_init(OsinfoDummyClass *klass G_GNUC_UNUSED){} +static void osinfo_dummy_init(OsinfoDummy *self G_GNUC_UNUSED) {} + + +typedef struct _OsinfoDummyLink OsinfoDummyLink; +typedef struct _OsinfoDummyLinkClass OsinfoDummyLinkClass; + +struct _OsinfoDummyLink +{ + OsinfoLink parent_instance; +}; + +struct _OsinfoDummyLinkClass +{ + OsinfoLinkClass parent_class; +}; + +GType osinfo_dummy_link_get_type(void); + +G_DEFINE_TYPE(OsinfoDummyLink, osinfo_dummy_link, OSINFO_TYPE_LINK); + +static void osinfo_dummy_link_class_init(OsinfoDummyLinkClass *klass G_GNUC_UNUSED){} +static void osinfo_dummy_link_init(OsinfoDummyLink *self G_GNUC_UNUSED) {} + + +static void +test_basic(void) +{ + OsinfoEntity *ent = g_object_new(osinfo_dummy_get_type(), "id", "wibble", NULL); + OsinfoDummyLink *link = g_object_new(osinfo_dummy_link_get_type(), + "id", osinfo_entity_get_id(ent), + "target", ent, + NULL); + + g_assert_true(osinfo_link_get_target(OSINFO_LINK(link)) == ent); + + g_object_unref(link); +} + + +int +main(int argc, char *argv[]) +{ + g_test_init(&argc, &argv, NULL); + + g_test_add_func("/link/basic", test_basic); + + /* Upfront so we don't confuse valgrind */ + osinfo_dummy_get_type(); + osinfo_dummy_link_get_type(); + osinfo_entity_get_type(); + osinfo_link_get_type(); + + return g_test_run(); +} +/* + * Local variables: + * indent-tabs-mode: nil + * c-indent-level: 4 + * c-basic-offset: 4 + * End: + */ -- 2.19.1 _______________________________________________ Libosinfo mailing list Libosinfo@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libosinfo