diff options
-rw-r--r-- | Makefile.am | 17 | ||||
-rw-r--r-- | configure.ac | 16 | ||||
-rw-r--r-- | osinfo/Makefile.am | 4 | ||||
-rw-r--r-- | test/Makefile.am | 90 | ||||
-rw-r--r-- | test/osinfo.suppression | 2403 | ||||
-rw-r--r-- | test/test-dataread.c | 54 | ||||
-rw-r--r-- | test/test-db.c | 423 | ||||
-rw-r--r-- | test/test-device.c | 45 | ||||
-rw-r--r-- | test/test-devicelist.c | 216 | ||||
-rw-r--r-- | test/test-entity.c | 297 | ||||
-rw-r--r-- | test/test-filter.c | 161 | ||||
-rw-r--r-- | test/test-hypervisor.c | 120 | ||||
-rw-r--r-- | test/test-hypervisorlist.c | 216 | ||||
-rw-r--r-- | test/test-list.c | 366 | ||||
-rw-r--r-- | test/test-os.c | 321 | ||||
-rw-r--r-- | test/test-osfilter.c | 210 | ||||
-rw-r--r-- | test/test-oslist.c | 216 | ||||
-rw-r--r-- | test/test-skeleton.c | 68 |
18 files changed, 5159 insertions, 84 deletions
diff --git a/Makefile.am b/Makefile.am index 20d74d0..7aa92aa 100644 --- a/Makefile.am +++ b/Makefile.am @@ -9,3 +9,20 @@ EXTRA_DIST = \ ACLOCAL_AMFLAGS = -I m4 + +LCOV = lcov +GENHTML = genhtml + +cov: clean-cov + mkdir $(top_builddir)/coverage + $(LCOV) -c -o $(top_builddir)/coverage/libosinfo.info.tmp \ + -d $(top_builddir)/osinfo + $(LCOV) -r $(top_builddir)/coverage/libosinfo.info.tmp \ + -o $(top_builddir)/coverage/libosinfo.info + rm $(top_builddir)/coverage/libosinfo.info.tmp + $(GENHTML) --show-details -t "libosinfo" -o $(top_builddir)/coverage \ + --legend $(top_builddir)/coverage/libosinfo.info + + +clean-cov: + rm -rf $(top_builddir)/coverage
\ No newline at end of file diff --git a/configure.ac b/configure.ac index cab08d5..f9aae0d 100644 --- a/configure.ac +++ b/configure.ac @@ -17,6 +17,7 @@ m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) PKG_CHECK_MODULES([GOBJECT], [gobject-2.0]) PKG_CHECK_MODULES([LIBXML], [libxml-2.0 >= 2.6.0]) +PKG_CHECK_MODULES([CHECK], [check]) LIBOSINFO_MAJOR_VERSION=`echo $VERSION | awk -F. '{print $1}'` LIBOSINFO_MINOR_VERSION=`echo $VERSION | awk -F. '{print $2}'` @@ -82,6 +83,21 @@ if test "x$enable_introspection" != "xno" ; then fi AM_CONDITIONAL([WITH_GOBJECT_INTROSPECTION], [test "x$enable_introspection" = "xyes"]) +AC_ARG_ENABLE([coverage], + AS_HELP_STRING([--enable-coverage], [enable GCC code coverage]), + [], [enable_coverage=no]) + + +COVERAGE_CFLAGS= +COVERAGE_LDFLAGS= +if test "x$enable_coverage" == "xyes" ; then + COVERAGE_CFLAGS="-fprofile-arcs -ftest-coverage" + COVERAGE_LDFLAGS="$COVERAGE_CFLAGS" +fi +AC_SUBST(COVERAGE_CFLAGS) +AC_SUBST(COVERAGE_LDFLAGS) + + AC_CONFIG_FILES([ Makefile libosinfo.spec diff --git a/osinfo/Makefile.am b/osinfo/Makefile.am index 254a2be..531f20b 100644 --- a/osinfo/Makefile.am +++ b/osinfo/Makefile.am @@ -23,11 +23,13 @@ lib_LTLIBRARIES = libosinfo-1.0.la libosinfo_1_0_la_CFLAGS = \ $(WARN_CFLAGS) \ + $(COVERAGE_CFLAGS) \ -I$(top_srcdir) \ $(LIBXML_CFLAGS) \ $(GOBJECT_CFLAGS) libosinfo_1_0_la_LDFLAGS = \ + $(COVERAGE_LDFLAGS) \ $(LIBXML_LIBS) \ $(GOBJECT_LIBS) \ $(VERSION_SCRIPT_FLAGS)$(LIBOSINFO_VERSION_FILE) \ @@ -93,6 +95,6 @@ typelibs_DATA = Libosinfo-1.0.typelib --includedir=$(girdir) \ -o $@ $< -CLEANFILES = $(gir_DATA) $(typelibs_DATA) +CLEANFILES = $(gir_DATA) $(typelibs_DATA) $(wildcard *.gcno) endif # WITH_GOBJECT_INTROSPECTION diff --git a/test/Makefile.am b/test/Makefile.am index 642cb7b..f379a4d 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,23 +1,83 @@ -check_PROGRAMS = \ - test-skeleton +check_PROGRAMS = \ + test-entity \ + test-device \ + test-list \ + test-devicelist \ + test-filter \ + test-os \ + test-oslist \ + test-osfilter \ + test-hypervisor \ + test-hypervisorlist \ + test-db \ + test-dataread +COMMON_LDADD = \ + $(COVERAGE_LDFLAGS) \ + $(GOBJECT_LIBS) \ + $(CHECK_LIBS) \ + ../osinfo/libosinfo-1.0.la +COMMON_CFLAGS = \ + $(WARN_CFLAGS) \ + $(COVERAGE_CFLAGS) \ + $(GOBJECT_CFLAGS) \ + $(CHECK_CFLAGS) -generated_test_scripts = $(patsubst %,%.sh,$(check_PROGRAMS)) -TESTS = $(generated_test_scripts) +test_entity_LDADD = $(COMMON_LDADD) +test_entity_CFLAGS = $(COMMON_CFLAGS) +test_entity_SOURCES = test-entity.c -test_skeleton_LDADD = ../osinfo/libosinfo.la -test_skeleton_SOURCES = test-skeleton.c -test_skeleton_CFLAGS = \ - -I$(top_srcdir)/ \ - $(GOBJECT_CFLAGS) +test_device_LDADD = $(COMMON_LDADD) +test_device_CFLAGS = $(COMMON_CFLAGS) +test_device_SOURCES = test-device.c -DISTCLEANFILES = $(generated_test_scripts) +test_filter_LDADD = $(COMMON_LDADD) +test_filter_CFLAGS = $(COMMON_CFLAGS) +test_filter_SOURCES = test-filter.c -%.sh: Makefile - printf '#!$(SHELL)\nexec $(*F) $(srcdir)/data\n' > $@-tmp - chmod a+x $@-tmp - mv $@-tmp $@ +test_os_LDADD = $(COMMON_LDADD) +test_os_CFLAGS = $(COMMON_CFLAGS) +test_os_SOURCES = test-os.c + +test_osfilter_LDADD = $(COMMON_LDADD) +test_osfilter_CFLAGS = $(COMMON_CFLAGS) +test_osfilter_SOURCES = test-osfilter.c + +test_hypervisor_LDADD = $(COMMON_LDADD) +test_hypervisor_CFLAGS = $(COMMON_CFLAGS) +test_hypervisor_SOURCES = test-hypervisor.c + +test_list_LDADD = $(COMMON_LDADD) +test_list_CFLAGS = $(COMMON_CFLAGS) +test_list_SOURCES = test-list.c + +test_devicelist_LDADD = $(COMMON_LDADD) +test_devicelist_CFLAGS = $(COMMON_CFLAGS) +test_devicelist_SOURCES = test-devicelist.c + +test_hypervisorlist_LDADD = $(COMMON_LDADD) +test_hypervisorlist_CFLAGS = $(COMMON_CFLAGS) +test_hypervisorlist_SOURCES = test-hypervisorlist.c + +test_oslist_LDADD = $(COMMON_LDADD) +test_oslist_CFLAGS = $(COMMON_CFLAGS) +test_oslist_SOURCES = test-oslist.c + +test_db_LDADD = $(COMMON_LDADD) +test_db_CFLAGS = $(COMMON_CFLAGS) +test_db_SOURCES = test-db.c + +test_dataread_LDADD = $(COMMON_LDADD) +test_dataread_CFLAGS = $(COMMON_CFLAGS) +test_dataread_SOURCES = test-dataread.c + +TESTS = $(check_PROGRAMS) TESTS_ENVIRONMENT = \ - PATH='$(abs_top_builddir)/test$(PATH_SEPARATOR)'"$$PATH" + LC_ALL=C \ + G_SLICE=always-malloc G_DEBUG=gc-friendly \ + $(VG) + +valgrind: + $(MAKE) check VG="libtool --mode=execute valgrind --quiet --tool=memcheck --leak-check=full --leak-resolution=high --num-callers=20 --suppressions=osinfo.suppression" diff --git a/test/osinfo.suppression b/test/osinfo.suppression new file mode 100644 index 0000000..96b3b4b --- /dev/null +++ b/test/osinfo.suppression @@ -0,0 +1,2403 @@ +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:g_type_class_ref + fun:g_type_class_ref + fun:g_type_create_instance + fun:g_param_spec_internal + fun:g_param_spec_string + fun:osinfo_entity_class_intern_init + fun:g_type_class_ref + fun:g_type_class_ref + fun:g_object_new_valist + fun:g_object_new +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:g_type_class_ref + fun:g_type_class_ref + fun:g_type_create_instance + fun:g_param_spec_internal + fun:g_param_spec_string + fun:osinfo_db_class_intern_init + fun:g_type_class_ref + fun:g_object_new_valist + fun:g_object_new +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:g_malloc + fun:g_strdup + fun:g_get_language_names + fun:g_thread_init_glib + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_node_any_new_W + fun:g_type_register_static + fun:g_type_plugin_get_type + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_node_any_new_W + fun:g_type_register_static + fun:g_boxed_type_register_static + fun:g_value_array_get_type + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_node_any_new_W + fun:g_type_register_static + fun:g_gtype_get_type + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_node_any_new_W + fun:g_type_register_static + fun:g_type_register_static_simple + fun:osinfo_entity_get_type + fun:osinfo_dummy_get_type + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:realloc + fun:g_realloc + fun:type_node_any_new_W + fun:g_type_register_static + fun:g_type_register_static_simple + fun:osinfo_list_get_type + fun:osinfo_dummy_list_get_type + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_node_any_new_W + fun:g_type_register_static + fun:g_type_register_static_simple + fun:osinfo_entity_get_type + fun:osinfo_device_get_type + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_node_any_new_W + fun:g_type_register_static + fun:g_type_register_static_simple + fun:osinfo_entity_get_type + fun:osinfo_hypervisor_get_type + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_node_any_new_W + fun:g_type_register_static + fun:g_type_register_static_simple + fun:osinfo_entity_get_type + fun:osinfo_os_get_type + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_node_any_new_W + fun:g_type_register_static + fun:g_type_register_static_simple + fun:osinfo_list_get_type + fun:osinfo_hypervisorlist_get_type + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_node_any_new_W + fun:g_type_register_static + fun:g_type_register_static_simple + fun:osinfo_db_get_type + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:realloc + fun:g_realloc + fun:type_node_any_new_W + fun:g_type_register_static + fun:g_type_register_static_simple + fun:osinfo_list_get_type + fun:osinfo_oslist_get_type + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:realloc + fun:g_realloc + fun:type_node_any_new_W + fun:g_type_register_static + fun:g_type_register_static_simple + fun:osinfo_list_get_type + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:realloc + fun:g_realloc + fun:type_node_any_new_W + fun:g_type_register_static + fun:g_type_register_static_simple + fun:osinfo_list_get_type + fun:osinfo_devicelist_get_type + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:realloc + fun:g_realloc + fun:type_node_any_new_W + fun:g_type_register_static + fun:g_type_register_static_simple + fun:osinfo_filter_get_type + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:g_malloc + fun:g_strdup + fun:g_get_language_names + fun:g_thread_init_glib + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:g_malloc + fun:g_strdup + fun:g_get_charset + fun:g_get_filename_charsets + fun:_g_convert_thread_init + fun:g_thread_init_glib + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:g_malloc + fun:g_strdup + fun:g_get_charset + fun:g_get_filename_charsets + fun:_g_convert_thread_init + fun:g_thread_init_glib + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:g_malloc + fun:g_strdup + fun:g_get_filename_charsets + fun:_g_convert_thread_init + fun:g_thread_init_glib + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:g_malloc + fun:g_strdup + fun:g_get_filename_charsets + fun:_g_convert_thread_init + fun:g_thread_init_glib + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:g_get_filename_charsets + fun:_g_convert_thread_init + fun:g_thread_init_glib + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:g_get_language_names + fun:g_thread_init_glib + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_enum_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_enum_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_enum_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_enum_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_boxed_type_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_boxed_type_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_param_type_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_param_type_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_object_type_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_fundamental + fun:g_object_type_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:type_add_flags_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:g_get_filename_charsets + fun:_g_convert_thread_init + fun:g_thread_init_glib + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:g_get_charset + fun:g_get_filename_charsets + fun:_g_convert_thread_init + fun:g_thread_init_glib + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:g_malloc + fun:g_strconcat + fun:_g_compute_locale_variants + fun:g_get_language_names + fun:g_thread_init_glib + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:g_malloc + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:g_malloc + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:g_malloc + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:g_malloc + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:g_malloc + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:g_malloc + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:g_malloc + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:g_malloc + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:g_malloc + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:g_malloc + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:g_malloc + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:g_malloc + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:g_malloc + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:g_malloc + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:g_malloc + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:g_malloc + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:g_malloc + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:g_malloc + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:g_malloc + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:g_malloc + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:g_malloc + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:g_malloc + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:g_malloc + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + fun:g_malloc + fun:g_get_language_names + fun:g_thread_init_glib + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:realloc + fun:g_realloc + fun:g_array_maybe_expand + fun:g_array_set_size + fun:g_static_private_set + fun:g_get_language_names + fun:g_thread_init_glib + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_fundamental + fun:g_boxed_type_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_node_any_new_W + fun:type_node_fundamental_new_W + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_node_any_new_W + fun:type_node_fundamental_new_W + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_node_any_new_W + fun:type_node_fundamental_new_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_node_any_new_W + fun:type_node_fundamental_new_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_node_any_new_W + fun:type_node_fundamental_new_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_node_any_new_W + fun:type_node_fundamental_new_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_node_any_new_W + fun:type_node_fundamental_new_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_node_any_new_W + fun:type_node_fundamental_new_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_node_any_new_W + fun:type_node_fundamental_new_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_node_any_new_W + fun:type_node_fundamental_new_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_node_any_new_W + fun:type_node_fundamental_new_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_node_any_new_W + fun:type_node_fundamental_new_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_node_any_new_W + fun:type_node_fundamental_new_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_node_any_new_W + fun:type_node_fundamental_new_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_node_any_new_W + fun:type_node_fundamental_new_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_node_any_new_W + fun:type_node_fundamental_new_W + fun:g_type_register_fundamental + fun:g_value_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_node_any_new_W + fun:type_node_fundamental_new_W + fun:g_type_register_fundamental + fun:g_enum_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_node_any_new_W + fun:type_node_fundamental_new_W + fun:g_type_register_fundamental + fun:g_enum_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_node_any_new_W + fun:type_node_fundamental_new_W + fun:g_type_register_fundamental + fun:g_boxed_type_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_node_any_new_W + fun:type_node_fundamental_new_W + fun:g_type_register_fundamental + fun:g_param_type_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_node_any_new_W + fun:type_node_fundamental_new_W + fun:g_type_register_fundamental + fun:g_object_type_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_fundamental + fun:g_enum_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_fundamental + fun:g_enum_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_fundamental + fun:g_param_type_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:type_data_make_W + fun:g_type_register_fundamental + fun:g_object_type_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:realloc + fun:g_realloc + fun:type_node_any_new_W + fun:g_type_register_static + fun:g_param_type_register_static + fun:g_param_spec_types_init + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:memalign + fun:posix_memalign + fun:slab_allocator_alloc_chunk + fun:g_slice_alloc + fun:g_slist_prepend + fun:g_strsplit + fun:g_get_language_names + fun:g_thread_init_glib + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:malloc + obj:/usr/lib64/libcheck.so.0.0.0 + fun:srunner_create + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:memalign + fun:posix_memalign + fun:slab_allocator_alloc_chunk + fun:g_slice_alloc + fun:g_slist_prepend + fun:g_strsplit + fun:g_get_language_names + fun:g_thread_init_glib + fun:g_type_init_with_debug_flags + fun:main +} +{ + <insert_a_suppression_name_here> + Memcheck:Leak + fun:memalign + fun:posix_memalign + fun:slab_allocator_alloc_chunk + fun:g_slice_alloc + fun:g_array_sized_new + fun:g_static_private_set + fun:g_get_filename_charsets + fun:_g_convert_thread_init + fun:g_thread_init_glib + fun:g_type_init_with_debug_flags + fun:main +} diff --git a/test/test-dataread.c b/test/test-dataread.c new file mode 100644 index 0000000..7067dfb --- /dev/null +++ b/test/test-dataread.c @@ -0,0 +1,54 @@ +#include <stdlib.h> +#include <osinfo/osinfo.h> +#include <check.h> + +START_TEST(test_basic) +{ + OsinfoDb *db = osinfo_db_new("../data"); + + fail_unless(OSINFO_IS_DB(db), "Db is not a DB"); + + GError *error = NULL; + osinfo_db_initialize(db, &error); + fail_unless(error == NULL, "Error loading data files"); + + g_object_unref(db); +} +END_TEST + +static Suite * +list_suite(void) +{ + Suite *s = suite_create("List"); + TCase *tc = tcase_create("Core"); + tcase_add_test(tc, test_basic); + suite_add_tcase(s, tc); + return s; +} + +int main(void) +{ + int number_failed; + Suite *s = list_suite (); + SRunner *sr = srunner_create (s); + + g_type_init(); + + /* Upfront so we don't confuse valgrind */ + osinfo_entity_get_type(); + osinfo_db_get_type(); + osinfo_device_get_type(); + osinfo_hypervisor_get_type(); + osinfo_os_get_type(); + osinfo_list_get_type(); + osinfo_devicelist_get_type(); + osinfo_hypervisorlist_get_type(); + osinfo_oslist_get_type(); + osinfo_filter_get_type(); + + srunner_run_all (sr, CK_ENV); + number_failed = srunner_ntests_failed (sr); + srunner_free (sr); + + return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/test/test-db.c b/test/test-db.c new file mode 100644 index 0000000..64e2ad6 --- /dev/null +++ b/test/test-db.c @@ -0,0 +1,423 @@ +#include <stdlib.h> +#include <osinfo/osinfo.h> +#include <check.h> + +START_TEST(test_basic) +{ + OsinfoDb *db = osinfo_db_new("../data"); + + fail_unless(OSINFO_IS_DB(db), "Db is not a DB"); + + gchar *dir = NULL; + g_object_get(db, "backing-dir", &dir, NULL); + fail_unless(g_strcmp0(dir, "../data") == 0, "Backing dir missing"); + g_free(dir); + + g_object_unref(db); +} +END_TEST + + +START_TEST(test_device) +{ + OsinfoDb *db = osinfo_db_new("../data"); + OsinfoDevice *dev1 = osinfo_device_new("dev1"); + OsinfoDevice *dev2 = osinfo_device_new("dev2"); + OsinfoDevice *dev3 = osinfo_device_new("dev3"); + + OsinfoDeviceList *list = osinfo_db_get_device_list(db); + + osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(dev1)); + osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(dev2)); + osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(dev3)); + + OsinfoDevice *dev = osinfo_db_get_device(db, "dev2"); + fail_unless(dev != NULL, "Device is NULL"); + fail_unless(dev == dev2, "Device was not dev2"); + + g_object_unref(dev1); + g_object_unref(dev2); + g_object_unref(dev3); + g_object_unref(db); +} +END_TEST + + +START_TEST(test_hypervisor) +{ + OsinfoDb *db = osinfo_db_new("../data"); + OsinfoHypervisor *dev1 = osinfo_hypervisor_new("dev1"); + OsinfoHypervisor *dev2 = osinfo_hypervisor_new("dev2"); + OsinfoHypervisor *dev3 = osinfo_hypervisor_new("dev3"); + + OsinfoHypervisorList *list = osinfo_db_get_hypervisor_list(db); + + osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(dev1)); + osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(dev2)); + osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(dev3)); + + OsinfoHypervisor *dev = osinfo_db_get_hypervisor(db, "dev2"); + fail_unless(dev != NULL, "Hypervisor is NULL"); + fail_unless(dev == dev2, "Hypervisor was not dev2"); + + g_object_unref(dev1); + g_object_unref(dev2); + g_object_unref(dev3); + g_object_unref(db); +} +END_TEST + + +START_TEST(test_os) +{ + OsinfoDb *db = osinfo_db_new("../data"); + OsinfoOs *dev1 = osinfo_os_new("dev1"); + OsinfoOs *dev2 = osinfo_os_new("dev2"); + OsinfoOs *dev3 = osinfo_os_new("dev3"); + + OsinfoOsList *list = osinfo_db_get_os_list(db); + + osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(dev1)); + osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(dev2)); + osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(dev3)); + + OsinfoOs *dev = osinfo_db_get_os(db, "dev2"); + fail_unless(dev != NULL, "Os is NULL"); + fail_unless(dev == dev2, "Os was not dev2"); + + g_object_unref(dev1); + g_object_unref(dev2); + g_object_unref(dev3); + g_object_unref(db); +} +END_TEST + + + +START_TEST(test_prop_device) +{ + OsinfoDb *db = osinfo_db_new("../data"); + OsinfoDevice *dev1 = osinfo_device_new("dev1"); + OsinfoDevice *dev2 = osinfo_device_new("dev2"); + OsinfoDevice *dev3 = osinfo_device_new("dev3"); + + osinfo_entity_add_param(OSINFO_ENTITY(dev1), "class", "network"); + osinfo_entity_add_param(OSINFO_ENTITY(dev1), "class", "audio"); + osinfo_entity_add_param(OSINFO_ENTITY(dev2), "class", "input"); + osinfo_entity_add_param(OSINFO_ENTITY(dev3), "class", "display"); + osinfo_entity_add_param(OSINFO_ENTITY(dev3), "fruit", "apple"); + + OsinfoDeviceList *list = osinfo_db_get_device_list(db); + + osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(dev1)); + osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(dev2)); + osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(dev3)); + + GList *uniq = osinfo_db_unique_values_for_property_in_dev(db, "class"); + GList *tmp = uniq; + gboolean hasNetwork = FALSE; + gboolean hasAudio = FALSE; + gboolean hasInput = FALSE; + gboolean hasDisplay = FALSE; + gboolean hasBad = FALSE; + while (tmp) { + if (g_strcmp0(tmp->data, "network") == 0) + hasNetwork = TRUE; + else if (g_strcmp0(tmp->data, "audio") == 0) + hasAudio = TRUE; + else if (g_strcmp0(tmp->data, "input") == 0) + hasInput = TRUE; + else if (g_strcmp0(tmp->data, "display") == 0) + hasDisplay = TRUE; + else + hasBad = TRUE; + tmp = tmp->next; + } + fail_unless(hasNetwork, "Missing network"); + fail_unless(hasAudio, "Missing audio"); + fail_unless(hasInput, "Missing input"); + fail_unless(hasDisplay, "Missing display"); + fail_unless(!hasBad, "Unexpected property"); + + g_list_free(uniq); + + g_object_unref(dev1); + g_object_unref(dev2); + g_object_unref(dev3); + g_object_unref(db); +} +END_TEST + + +START_TEST(test_prop_hypervisor) +{ + OsinfoDb *db = osinfo_db_new("../data"); + OsinfoHypervisor *hv1 = osinfo_hypervisor_new("hv1"); + OsinfoHypervisor *hv2 = osinfo_hypervisor_new("hv2"); + OsinfoHypervisor *hv3 = osinfo_hypervisor_new("hv3"); + + osinfo_entity_add_param(OSINFO_ENTITY(hv1), "vendor", "acme"); + osinfo_entity_add_param(OSINFO_ENTITY(hv1), "vendor", "frog"); + osinfo_entity_add_param(OSINFO_ENTITY(hv2), "vendor", "acme"); + osinfo_entity_add_param(OSINFO_ENTITY(hv3), "vendor", "dog"); + osinfo_entity_add_param(OSINFO_ENTITY(hv3), "arch", "x86"); + + OsinfoHypervisorList *list = osinfo_db_get_hypervisor_list(db); + + osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(hv1)); + osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(hv2)); + osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(hv3)); + + GList *uniq = osinfo_db_unique_values_for_property_in_hv(db, "vendor"); + GList *tmp = uniq; + gboolean hasAcme = FALSE; + gboolean hasFrog = FALSE; + gboolean hasDog = FALSE; + gboolean hasBad = FALSE; + while (tmp) { + if (g_strcmp0(tmp->data, "acme") == 0) + hasAcme = TRUE; + else if (g_strcmp0(tmp->data, "frog") == 0) + hasFrog = TRUE; + else if (g_strcmp0(tmp->data, "dog") == 0) + hasDog = TRUE; + else + hasBad = TRUE; + tmp = tmp->next; + } + fail_unless(hasAcme, "Missing acme"); + fail_unless(hasFrog, "Missing frog"); + fail_unless(hasDog, "Missing dog"); + fail_unless(!hasBad, "Unexpected property"); + + g_list_free(uniq); + + g_object_unref(hv1); + g_object_unref(hv2); + g_object_unref(hv3); + g_object_unref(db); +} +END_TEST + + +START_TEST(test_prop_os) +{ + OsinfoDb *db = osinfo_db_new("../data"); + OsinfoOs *os1 = osinfo_os_new("os1"); + OsinfoOs *os2 = osinfo_os_new("os2"); + OsinfoOs *os3 = osinfo_os_new("os3"); + + osinfo_entity_add_param(OSINFO_ENTITY(os1), "vendor", "acme"); + osinfo_entity_add_param(OSINFO_ENTITY(os1), "vendor", "frog"); + osinfo_entity_add_param(OSINFO_ENTITY(os2), "vendor", "acme"); + osinfo_entity_add_param(OSINFO_ENTITY(os3), "vendor", "dog"); + osinfo_entity_add_param(OSINFO_ENTITY(os3), "arch", "x86"); + + + OsinfoOsList *list = osinfo_db_get_os_list(db); + + osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(os1)); + osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(os2)); + osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(os3)); + + GList *uniq = osinfo_db_unique_values_for_property_in_os(db, "vendor"); + GList *tmp = uniq; + gboolean hasAcme = FALSE; + gboolean hasFrog = FALSE; + gboolean hasDog = FALSE; + gboolean hasBad = FALSE; + while (tmp) { + if (g_strcmp0(tmp->data, "acme") == 0) + hasAcme = TRUE; + else if (g_strcmp0(tmp->data, "frog") == 0) + hasFrog = TRUE; + else if (g_strcmp0(tmp->data, "dog") == 0) + hasDog = TRUE; + else + hasBad = TRUE; + tmp = tmp->next; + } + fail_unless(hasAcme, "Missing acme"); + fail_unless(hasFrog, "Missing frog"); + fail_unless(hasDog, "Missing dog"); + fail_unless(!hasBad, "Unexpected property"); + + g_list_free(uniq); + + g_object_unref(os1); + g_object_unref(os2); + g_object_unref(os3); + g_object_unref(db); +} +END_TEST + + + +START_TEST(test_rel_os) +{ + OsinfoDb *db = osinfo_db_new("../data"); + OsinfoOs *os1 = osinfo_os_new("os1"); + OsinfoOs *os2 = osinfo_os_new("os2"); + OsinfoOs *os3 = osinfo_os_new("os3"); + OsinfoOs *os4 = osinfo_os_new("os4"); + OsinfoOs *os5 = osinfo_os_new("os5"); + + OsinfoOsList *list = osinfo_db_get_os_list(db); + + osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(os1)); + osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(os2)); + osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(os3)); + osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(os4)); + osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(os5)); + + osinfo_os_add_related_os(os1, OSINFO_OS_RELATIONSHIP_DERIVES_FROM, os2); + osinfo_os_add_related_os(os1, OSINFO_OS_RELATIONSHIP_DERIVES_FROM, os3); + osinfo_os_add_related_os(os2, OSINFO_OS_RELATIONSHIP_CLONES, os4); + osinfo_os_add_related_os(os3, OSINFO_OS_RELATIONSHIP_UPGRADES, os5); + + OsinfoOsList *sublist = osinfo_db_unique_values_for_os_relationship(db, OSINFO_OS_RELATIONSHIP_DERIVES_FROM); + gboolean hasOs1 = FALSE; + gboolean hasOs2 = FALSE; + gboolean hasOs3 = FALSE; + gboolean hasOs4 = FALSE; + gboolean hasOs5 = FALSE; + gboolean hasBad = FALSE; + int i; + for (i = 0 ; i < osinfo_list_get_length(OSINFO_LIST(sublist)) ; i++) { + OsinfoOs *ent = OSINFO_OS(osinfo_list_get_nth(OSINFO_LIST(sublist), i)); + + if (ent == os1) + hasOs1 = TRUE; + else if (ent == os2) + hasOs2 = TRUE; + else if (ent == os3) + hasOs3 = TRUE; + else if (ent == os4) + hasOs4 = TRUE; + else if (ent == os5) + hasOs5 = TRUE; + else + hasBad = TRUE; + + } + fail_unless(!hasOs1, "Unexpected OS 1"); + fail_unless(hasOs2, "Missing OS 2"); + fail_unless(hasOs3, "Missing OS 3"); + fail_unless(!hasOs4, "Unexpected OS 4"); + fail_unless(!hasOs5, "Unexpected OS 5"); + fail_unless(!hasBad, "Unexpected property"); + + g_object_unref(sublist); + + sublist = osinfo_db_unique_values_for_os_relationship(db, OSINFO_OS_RELATIONSHIP_UPGRADES); + hasOs1 = hasOs2 = hasOs3 = hasOs4 = hasOs5 = hasBad = FALSE; + for (i = 0 ; i < osinfo_list_get_length(OSINFO_LIST(sublist)) ; i++) { + OsinfoOs *ent = OSINFO_OS(osinfo_list_get_nth(OSINFO_LIST(sublist), i)); + + if (ent == os1) + hasOs1 = TRUE; + else if (ent == os2) + hasOs2 = TRUE; + else if (ent == os3) + hasOs3 = TRUE; + else if (ent == os4) + hasOs4 = TRUE; + else if (ent == os5) + hasOs5 = TRUE; + else + hasBad = TRUE; + + } + fail_unless(!hasOs1, "Unexpected OS 1"); + fail_unless(!hasOs2, "Unexpected OS 2"); + fail_unless(!hasOs3, "Unexpected OS 3"); + fail_unless(!hasOs4, "Unexpected OS 4"); + fail_unless(hasOs5, "Missing OS 5"); + fail_unless(!hasBad, "Unexpected property"); + + g_object_unref(sublist); + + sublist = osinfo_db_unique_values_for_os_relationship(db, OSINFO_OS_RELATIONSHIP_CLONES); + hasOs1 = hasOs2 = hasOs3 = hasOs4 = hasOs5 = hasBad = FALSE; + for (i = 0 ; i < osinfo_list_get_length(OSINFO_LIST(sublist)) ; i++) { + OsinfoOs *ent = OSINFO_OS(osinfo_list_get_nth(OSINFO_LIST(sublist), i)); + + if (ent == os1) + hasOs1 = TRUE; + else if (ent == os2) + hasOs2 = TRUE; + else if (ent == os3) + hasOs3 = TRUE; + else if (ent == os4) + hasOs4 = TRUE; + else if (ent == os5) + hasOs5 = TRUE; + else + hasBad = TRUE; + + } + fail_unless(!hasOs1, "Unexpected OS 1"); + fail_unless(!hasOs2, "Unexpected OS 2"); + fail_unless(!hasOs3, "Unexpected OS 3"); + fail_unless(hasOs4, "Missing OS 4"); + fail_unless(!hasOs5, "Unexpected OS 5"); + fail_unless(!hasBad, "Unexpected property"); + + g_object_unref(sublist); + + + g_object_unref(os1); + g_object_unref(os2); + g_object_unref(os3); + g_object_unref(os4); + g_object_unref(os5); + g_object_unref(db); +} +END_TEST + + + + +static Suite * +list_suite(void) +{ + Suite *s = suite_create("List"); + TCase *tc = tcase_create("Core"); + tcase_add_test(tc, test_basic); + tcase_add_test(tc, test_device); + tcase_add_test(tc, test_hypervisor); + tcase_add_test(tc, test_os); + tcase_add_test(tc, test_prop_device); + tcase_add_test(tc, test_prop_hypervisor); + tcase_add_test(tc, test_prop_os); + tcase_add_test(tc, test_rel_os); + suite_add_tcase(s, tc); + return s; +} + +int main(void) +{ + int number_failed; + Suite *s = list_suite (); + SRunner *sr = srunner_create (s); + + g_type_init(); + + /* Upfront so we don't confuse valgrind */ + osinfo_entity_get_type(); + osinfo_db_get_type(); + osinfo_device_get_type(); + osinfo_hypervisor_get_type(); + osinfo_os_get_type(); + osinfo_list_get_type(); + osinfo_devicelist_get_type(); + osinfo_hypervisorlist_get_type(); + osinfo_oslist_get_type(); + osinfo_filter_get_type(); + + srunner_run_all (sr, CK_ENV); + number_failed = srunner_ntests_failed (sr); + srunner_free (sr); + + return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/test/test-device.c b/test/test-device.c new file mode 100644 index 0000000..4d89f27 --- /dev/null +++ b/test/test-device.c @@ -0,0 +1,45 @@ +#include <stdlib.h> +#include <osinfo/osinfo.h> +#include <check.h> + + + +START_TEST(test_basic) +{ + OsinfoDevice *device = osinfo_device_new("e1000"); + + fail_unless(OSINFO_IS_DEVICE(device), "Device is a device object"); + fail_unless(g_strcmp0(osinfo_entity_get_id(OSINFO_ENTITY(device)), "e1000") == 0, "Device ID was e1000"); + + g_object_unref(device); +} +END_TEST + + +static Suite * +device_suite(void) +{ + Suite *s = suite_create("Device"); + TCase *tc = tcase_create("Core"); + tcase_add_test(tc, test_basic); + suite_add_tcase(s, tc); + return s; +} + +int main(void) +{ + int number_failed; + Suite *s = device_suite (); + SRunner *sr = srunner_create (s); + + g_type_init(); + + /* Upfront so we don't confuse valgrind */ + osinfo_device_get_type(); + + srunner_run_all (sr, CK_ENV); + number_failed = srunner_ntests_failed (sr); + srunner_free (sr); + + return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/test/test-devicelist.c b/test/test-devicelist.c new file mode 100644 index 0000000..3db307e --- /dev/null +++ b/test/test-devicelist.c @@ -0,0 +1,216 @@ +#include <stdlib.h> +#include <osinfo/osinfo.h> +#include <check.h> + + +START_TEST(test_union) +{ + OsinfoDeviceList *list1 = osinfo_devicelist_new(); + OsinfoDeviceList *list2 = osinfo_devicelist_new(); + OsinfoDeviceList *list3; + OsinfoDevice *ent1 = osinfo_device_new("wibble1"); + OsinfoDevice *ent2 = osinfo_device_new("wibble2"); + OsinfoDevice *ent3 = osinfo_device_new("wibble3"); + OsinfoDevice *ent4 = osinfo_device_new("wibble4"); + + osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent1)); + osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent2)); + osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent3)); + + osinfo_list_add(OSINFO_LIST(list2), OSINFO_ENTITY(ent1)); + osinfo_list_add(OSINFO_LIST(list2), OSINFO_ENTITY(ent4)); + + list3 = osinfo_devicelist_new_union(list1, list2); + + fail_unless(osinfo_list_get_length(OSINFO_LIST(list3)) == 4, "List did not have 4 elements"); + + gboolean has1 = FALSE; + gboolean has2 = FALSE; + gboolean has3 = FALSE; + gboolean has4 = FALSE; + gboolean hasBad = FALSE; + int i; + for (i = 0 ; i < osinfo_list_get_length(OSINFO_LIST(list3)) ; i++) { + OsinfoDevice *ent = OSINFO_DEVICE(osinfo_list_get_nth(OSINFO_LIST(list3), i)); + if (ent == ent1) + has1 = TRUE; + else if (ent == ent2) + has2 = TRUE; + else if (ent == ent3) + has3 = TRUE; + else if (ent == ent4) + has4 = TRUE; + else + hasBad = TRUE; + } + fail_unless(has1, "List was missing entity 1"); + fail_unless(has2, "List was missing entity 2"); + fail_unless(has3, "List was missing entity 3"); + fail_unless(has4, "List was missing entity 4"); + fail_unless(!hasBad, "List had unexpected entity"); + + g_object_unref(ent1); + g_object_unref(ent2); + g_object_unref(ent3); + g_object_unref(ent4); + g_object_unref(list1); + g_object_unref(list2); + g_object_unref(list3); +} +END_TEST + + +START_TEST(test_intersect) +{ + OsinfoDeviceList *list1 = osinfo_devicelist_new(); + OsinfoDeviceList *list2 = osinfo_devicelist_new(); + OsinfoDeviceList *list3; + OsinfoDevice *ent1 = osinfo_device_new("wibble1"); + OsinfoDevice *ent2 = osinfo_device_new("wibble2"); + OsinfoDevice *ent3 = osinfo_device_new("wibble3"); + OsinfoDevice *ent4 = osinfo_device_new("wibble4"); + + + osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent1)); + osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent2)); + osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent3)); + + osinfo_list_add(OSINFO_LIST(list2), OSINFO_ENTITY(ent1)); + osinfo_list_add(OSINFO_LIST(list2), OSINFO_ENTITY(ent3)); + osinfo_list_add(OSINFO_LIST(list2), OSINFO_ENTITY(ent4)); + + list3 = osinfo_devicelist_new_intersection(list1, list2); + + fail_unless(osinfo_list_get_length(OSINFO_LIST(list3)) == 2, "List did not have 2 elements"); + + gboolean has1 = FALSE; + gboolean has2 = FALSE; + gboolean has3 = FALSE; + gboolean has4 = FALSE; + gboolean hasBad = FALSE; + int i; + for (i = 0 ; i < osinfo_list_get_length(OSINFO_LIST(list3)) ; i++) { + OsinfoDevice *ent = OSINFO_DEVICE(osinfo_list_get_nth(OSINFO_LIST(list3), i)); + if (ent == ent1) + has1 = TRUE; + else if (ent == ent2) + has2 = TRUE; + else if (ent == ent3) + has3 = TRUE; + else if (ent == ent4) + has4 = TRUE; + else + hasBad = TRUE; + } + fail_unless(has1, "List was missing entity 1"); + fail_unless(!has2, "List had unexpected entity 2"); + fail_unless(has3, "List was missing entity 3"); + fail_unless(!has4, "List had unexpected entity 4"); + fail_unless(!hasBad, "List had unexpected entity"); + + g_object_unref(ent1); + g_object_unref(ent2); + g_object_unref(ent3); + g_object_unref(ent4); + g_object_unref(list1); + g_object_unref(list2); + g_object_unref(list3); +} +END_TEST + + +START_TEST(test_filter) +{ + OsinfoDeviceList *list1 = osinfo_devicelist_new(); + OsinfoDeviceList *list2; + OsinfoFilter *filter = osinfo_filter_new(); + OsinfoDevice *ent1 = osinfo_device_new("wibble1"); + OsinfoDevice *ent2 = osinfo_device_new("wibble2"); + OsinfoDevice *ent3 = osinfo_device_new("wibble3"); + OsinfoDevice *ent4 = osinfo_device_new("wibble4"); + + osinfo_entity_add_param(OSINFO_ENTITY(ent1), "class", "network"); + osinfo_entity_add_param(OSINFO_ENTITY(ent1), "class", "wilma"); + osinfo_entity_add_param(OSINFO_ENTITY(ent2), "class", "network"); + osinfo_entity_add_param(OSINFO_ENTITY(ent3), "class", "network"); + osinfo_entity_add_param(OSINFO_ENTITY(ent3), "class", "audio"); + osinfo_entity_add_param(OSINFO_ENTITY(ent4), "class", "audio"); + + osinfo_filter_add_constraint(filter, "class", "network"); + + osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent1)); + osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent2)); + osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent3)); + osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent4)); + + list2 = osinfo_devicelist_new_filtered(list1, filter); + + fail_unless(osinfo_list_get_length(OSINFO_LIST(list2)) == 3, "List did not have 3 elements"); + + gboolean has1 = FALSE; + gboolean has2 = FALSE; + gboolean has3 = FALSE; + gboolean has4 = FALSE; + gboolean hasBad = FALSE; + int i; + for (i = 0 ; i < osinfo_list_get_length(OSINFO_LIST(list2)) ; i++) { + OsinfoDevice *ent = OSINFO_DEVICE(osinfo_list_get_nth(OSINFO_LIST(list2), i)); + if (ent == ent1) + has1 = TRUE; + else if (ent == ent2) + has2 = TRUE; + else if (ent == ent3) + has3 = TRUE; + else if (ent == ent4) + has4 = TRUE; + else + hasBad = TRUE; + } + fail_unless(has1, "List was missing entity 1"); + fail_unless(has2, "List was missing entity 2"); + fail_unless(has3, "List was missing entity 3"); + fail_unless(!has4, "List had unexpected entity 4"); + fail_unless(!hasBad, "List had unexpected entity"); + + g_object_unref(ent1); + g_object_unref(ent2); + g_object_unref(ent3); + g_object_unref(ent4); + g_object_unref(filter); + g_object_unref(list1); + g_object_unref(list2); +} +END_TEST + + +static Suite * +list_suite(void) +{ + Suite *s = suite_create("List"); + TCase *tc = tcase_create("Core"); + tcase_add_test(tc, test_union); + tcase_add_test(tc, test_intersect); + tcase_add_test(tc, test_filter); + suite_add_tcase(s, tc); + return s; +} + +int main(void) +{ + int number_failed; + Suite *s = list_suite (); + SRunner *sr = srunner_create (s); + + g_type_init(); + + /* Upfront so we don't confuse valgrind */ + osinfo_device_get_type(); + osinfo_devicelist_get_type(); + osinfo_filter_get_type(); + + srunner_run_all (sr, CK_ENV); + number_failed = srunner_ntests_failed (sr); + srunner_free (sr); + + return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/test/test-entity.c b/test/test-entity.c new file mode 100644 index 0000000..6197864 --- /dev/null +++ b/test/test-entity.c @@ -0,0 +1,297 @@ +#include <stdlib.h> +#include <osinfo/osinfo.h> +#include <check.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) {} + + +START_TEST(test_id) +{ + OsinfoEntity *ent = g_object_new(osinfo_dummy_get_type(), "id", "myentity", NULL); + gchar *id; + + fail_unless(g_strcmp0(osinfo_entity_get_id(ent), "myentity") == 0, + "Entity id was not 'myentity'"); + + g_object_get(ent, "id", &id, NULL); + fail_unless(g_strcmp0(id, "myentity") == 0, + "Entity id was not 'myentity'"); + g_free(id); + + g_object_unref(ent); +} +END_TEST + +START_TEST(test_empty_props) +{ + OsinfoEntity *ent = g_object_new(osinfo_dummy_get_type(), "id", "myentity", NULL); + + GList *keys = osinfo_entity_get_param_keys(ent); + fail_unless(keys == NULL, "Entity param key list was not empty"); + + const gchar *value = osinfo_entity_get_param_value(ent, "wibble"); + fail_unless(value == NULL, "Entity param value was not NULL"); + + GList *values = osinfo_entity_get_param_value_list(ent, "wibble"); + fail_unless(values == NULL, "Entity param value list was not NULL"); + + g_object_unref(ent); +} +END_TEST + +START_TEST(test_single_prop_value) +{ + OsinfoEntity *ent = g_object_new(osinfo_dummy_get_type(), "id", "myentity", NULL); + + osinfo_entity_add_param(ent, "hello", "world"); + + GList *keys = osinfo_entity_get_param_keys(ent); + fail_unless(keys != NULL, "Entity param key list was empty"); + fail_unless(keys->next == NULL, "Entity param key list has too many values"); + fail_unless(g_strcmp0(keys->data, "hello") == 0, "Entity param key was not 'hello'"); + g_list_free(keys); + + const gchar *value = osinfo_entity_get_param_value(ent, "hello"); + fail_unless(g_strcmp0(value, "world") == 0, "Entity param value was not 'world'"); + value = osinfo_entity_get_param_value(ent, "world"); + fail_unless(value == NULL, "Entity param bogus value was not NULL"); + + GList *values = osinfo_entity_get_param_value_list(ent, "hello"); + fail_unless(values != NULL, "Entity param value list was empty"); + fail_unless(values->next == NULL, "Entity param value list has too many values"); + fail_unless(g_strcmp0(values->data, "world") == 0, "Entity param list value was not 'world'"); + + g_object_unref(ent); +} +END_TEST + +START_TEST(test_multi_prop_value) +{ + OsinfoEntity *ent = g_object_new(osinfo_dummy_get_type(), "id", "myentity", NULL); + + osinfo_entity_add_param(ent, "hello", "world"); + osinfo_entity_add_param(ent, "hello", "fred"); + osinfo_entity_add_param(ent, "hello", "elephant"); + + GList *keys = osinfo_entity_get_param_keys(ent); + fail_unless(keys != NULL, "Entity param key list was empty"); + fail_unless(keys->next == NULL, "Entity param key list has too many values"); + fail_unless(g_strcmp0(keys->data, "hello") == 0, "Entity param key was not 'hello'"); + g_list_free(keys); + + const gchar *value = osinfo_entity_get_param_value(ent, "hello"); + fail_unless(g_strcmp0(value, "world") == 0, "Entity param value was not 'world'"); + value = osinfo_entity_get_param_value(ent, "world"); + fail_unless(value == NULL, "Entity param bogus value was not NULL"); + + GList *values = osinfo_entity_get_param_value_list(ent, "hello"); + fail_unless(values != NULL, "Entity param value list was empty"); + fail_unless(values->next != NULL, "Entity param value list doesn't have enough values"); + fail_unless(values->next->next != NULL, "Entity param value list doesn't have enough values"); + fail_unless(values->next->next->next == NULL, "Entity param value list has too many values"); + fail_unless(g_strcmp0(values->data, "world") == 0, "Entity param list first value was not 'world'"); + fail_unless(g_strcmp0(values->next->data, "fred") == 0, "Entity param list second value was not 'fred'"); + fail_unless(g_strcmp0(values->next->next->data, "elephant") == 0, "Entity param list third was not 'elephant'"); + + g_object_unref(ent); +} +END_TEST + +START_TEST(test_multi_props) +{ + OsinfoEntity *ent = g_object_new(osinfo_dummy_get_type(), "id", "myentity", NULL); + + osinfo_entity_add_param(ent, "hello", "world"); + osinfo_entity_add_param(ent, "fish", "food"); + osinfo_entity_add_param(ent, "kevin", "bacon"); + + GList *keys = osinfo_entity_get_param_keys(ent); + GList *tmp = keys; + gboolean foundHello = FALSE; + gboolean foundFish = FALSE; + gboolean foundKevin = FALSE; + gboolean foundBad = FALSE; + while (tmp) { + if (g_strcmp0(tmp->data, "hello") == 0) + foundHello = TRUE; + else if (g_strcmp0(tmp->data, "fish") == 0) + foundFish = TRUE; + else if (g_strcmp0(tmp->data, "kevin") == 0) + foundKevin = TRUE; + else + foundBad = TRUE; + tmp = tmp->next; + } + fail_unless(foundHello, "Entity param key list was missing 'hello'"); + fail_unless(foundFish, "Entity param key list was missing 'fish'"); + fail_unless(foundKevin, "Entity param key list was missing 'kevin'"); + fail_unless(!foundBad, "Entity param key list has unexpected key"); + g_list_free(keys); + + const gchar *value = osinfo_entity_get_param_value(ent, "hello"); + fail_unless(g_strcmp0(value, "world") == 0, "Entity param value was not 'world'"); + value = osinfo_entity_get_param_value(ent, "fish"); + fail_unless(g_strcmp0(value, "food") == 0, "Entity param value was not 'food'"); + value = osinfo_entity_get_param_value(ent, "kevin"); + fail_unless(g_strcmp0(value, "bacon") == 0, "Entity param value was not 'bacon'"); + + GList *values = osinfo_entity_get_param_value_list(ent, "hello"); + fail_unless(values != NULL, "Entity param value list was empty"); + fail_unless(values->next == NULL, "Entity param value list has too many values"); + fail_unless(g_strcmp0(values->data, "world") == 0, "Entity param list value was not 'world'"); + + values = osinfo_entity_get_param_value_list(ent, "fish"); + fail_unless(values != NULL, "Entity param value list was empty"); + fail_unless(values->next == NULL, "Entity param value list has too many values"); + fail_unless(g_strcmp0(values->data, "food") == 0, "Entity param list value was not 'food'"); + + values = osinfo_entity_get_param_value_list(ent, "kevin"); + fail_unless(values != NULL, "Entity param value list was empty"); + fail_unless(values->next == NULL, "Entity param value list has too many values"); + fail_unless(g_strcmp0(values->data, "bacon") == 0, "Entity param list value was not 'bacon'"); + + g_object_unref(ent); +} +END_TEST + + +START_TEST(test_multi_props_clear) +{ + OsinfoEntity *ent = g_object_new(osinfo_dummy_get_type(), "id", "myentity", NULL); + + osinfo_entity_add_param(ent, "hello", "world"); + osinfo_entity_add_param(ent, "fish", "food"); + + GList *keys = osinfo_entity_get_param_keys(ent); + GList *tmp = keys; + gboolean foundHello = FALSE; + gboolean foundFish = FALSE; + gboolean foundBad = FALSE; + while (tmp) { + if (g_strcmp0(tmp->data, "hello") == 0) + foundHello = TRUE; + else if (g_strcmp0(tmp->data, "fish") == 0) + foundFish = TRUE; + else + foundBad = TRUE; + tmp = tmp->next; + } + fail_unless(foundHello, "Entity param key list was missing 'hello'"); + fail_unless(foundFish, "Entity param key list was missing 'fish'"); + fail_unless(!foundBad, "Entity param key list has unexpected key"); + g_list_free(keys); + + const gchar *value = osinfo_entity_get_param_value(ent, "hello"); + fail_unless(g_strcmp0(value, "world") == 0, "Entity param value was not 'world'"); + value = osinfo_entity_get_param_value(ent, "fish"); + fail_unless(g_strcmp0(value, "food") == 0, "Entity param value was not 'food'"); + + osinfo_entity_clear_param(ent, "hello"); + + keys = osinfo_entity_get_param_keys(ent); + tmp = keys; + foundHello = FALSE; + foundFish = FALSE; + foundBad = FALSE; + while (tmp) { + if (g_strcmp0(tmp->data, "hello") == 0) + foundHello = TRUE; + else if (g_strcmp0(tmp->data, "fish") == 0) + foundFish = TRUE; + else + foundBad = TRUE; + tmp = tmp->next; + } + fail_unless(!foundHello, "Entity param key list has unexpected 'hello'"); + fail_unless(foundFish, "Entity param key list was missing 'fish'"); + fail_unless(!foundBad, "Entity param key list has unexpected key"); + g_list_free(keys); + + value = osinfo_entity_get_param_value(ent, "hello"); + fail_unless(g_strcmp0(value, NULL) == 0, "Entity param value was not removed"); + value = osinfo_entity_get_param_value(ent, "fish"); + fail_unless(g_strcmp0(value, "food") == 0, "Entity param value was not 'food'"); + + osinfo_entity_add_param(ent, "hello", "world"); + osinfo_entity_clear_param(ent, "fish"); + + keys = osinfo_entity_get_param_keys(ent); + tmp = keys; + foundHello = FALSE; + foundFish = FALSE; + foundBad = FALSE; + while (tmp) { + if (g_strcmp0(tmp->data, "hello") == 0) + foundHello = TRUE; + else if (g_strcmp0(tmp->data, "fish") == 0) + foundFish = TRUE; + else + foundBad = TRUE; + tmp = tmp->next; + } + fail_unless(foundHello, "Entity param key list has unexpected 'hello'"); + fail_unless(!foundFish, "Entity param key list was missing 'fish'"); + fail_unless(!foundBad, "Entity param key list has unexpected key"); + g_list_free(keys); + + value = osinfo_entity_get_param_value(ent, "hello"); + fail_unless(g_strcmp0(value, "world") == 0, "Entity param value was not readded"); + value = osinfo_entity_get_param_value(ent, "fish"); + fail_unless(g_strcmp0(value, NULL) == 0, "Entity param value was not removed"); + + g_object_unref(ent); +} +END_TEST + + +static Suite * +entity_suite(void) +{ + Suite *s = suite_create("Entity"); + TCase *tc = tcase_create("Core"); + tcase_add_test(tc, test_id); + tcase_add_test(tc, test_empty_props); + tcase_add_test(tc, test_single_prop_value); + tcase_add_test(tc, test_multi_prop_value); + tcase_add_test(tc, test_multi_props); + tcase_add_test(tc, test_multi_props_clear); + suite_add_tcase(s, tc); + return s; +} + +int main(void) +{ + int number_failed; + Suite *s = entity_suite (); + SRunner *sr = srunner_create (s); + + g_type_init(); + + /* Upfront so we don't confuse valgrind */ + osinfo_dummy_get_type(); + + srunner_run_all (sr, CK_ENV); + number_failed = srunner_ntests_failed (sr); + srunner_free (sr); + + return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/test/test-filter.c b/test/test-filter.c new file mode 100644 index 0000000..aa386c8 --- /dev/null +++ b/test/test-filter.c @@ -0,0 +1,161 @@ +#include <stdlib.h> +#include <osinfo/osinfo.h> +#include <check.h> + + + +START_TEST(test_basic) +{ + OsinfoFilter *filter = osinfo_filter_new(); + OsinfoDevice *dev = osinfo_device_new("e1000"); + + fail_unless(OSINFO_IS_FILTER(filter), "Filter is a filter object"); + fail_unless(osinfo_filter_matches(filter, OSINFO_ENTITY(dev)), "Filter matches device"); + + osinfo_filter_add_constraint(filter, "class", "network"); + GList *keys = osinfo_filter_get_constraint_keys(filter); + fail_unless(keys != NULL, "missing key"); + fail_unless(g_strcmp0(keys->data, "class") == 0, "missing key"); + fail_unless(keys->next == NULL, "too many keys"); + g_list_free(keys); + + osinfo_filter_add_constraint(filter, "class", "audio"); + keys = osinfo_filter_get_constraint_keys(filter); + fail_unless(keys != NULL, "missing key"); + fail_unless(g_strcmp0(keys->data, "class") == 0, "missing key"); + fail_unless(keys->next == NULL, "too many keys"); + g_list_free(keys); + + osinfo_filter_add_constraint(filter, "bus", "pci"); + keys = osinfo_filter_get_constraint_keys(filter); + fail_unless(keys != NULL, "missing key"); + fail_unless(keys->next != NULL, "not enough keys"); + fail_unless(g_strcmp0(keys->data, "bus") == 0, "missing bus key"); + fail_unless(g_strcmp0(keys->next->data, "class") == 0, "missing class key"); + fail_unless(keys->next->next == NULL, "too many keys"); + g_list_free(keys); + + GList *values = osinfo_filter_get_constraint_values(filter, "bus"); + fail_unless(values != NULL, "missing value"); + fail_unless(g_strcmp0(values->data, "pci") == 0, "missing value"); + fail_unless(values->next == NULL, "too many keys"); + + values = osinfo_filter_get_constraint_values(filter, "class"); + fail_unless(values != NULL, "missing value"); + fail_unless(values->next != NULL, "not enough values"); + fail_unless(g_strcmp0(values->data, "audio") == 0, "missing value"); + fail_unless(g_strcmp0(values->next->data, "network") == 0, "missing value"); + fail_unless(values->next->next == NULL, "too many values"); + + g_object_unref(dev); + g_object_unref(filter); +} +END_TEST + +START_TEST(test_filter_single) +{ + OsinfoFilter *filter = osinfo_filter_new(); + OsinfoDevice *dev = osinfo_device_new("e1000"); + + osinfo_entity_add_param(OSINFO_ENTITY(dev), "bus", "pci"); + + osinfo_filter_add_constraint(filter, "class", "network"); + fail_unless(!osinfo_filter_matches(filter, OSINFO_ENTITY(dev)), "Filter does not match device"); + + osinfo_entity_add_param(OSINFO_ENTITY(dev), "class", "network"); + fail_unless(osinfo_filter_matches(filter, OSINFO_ENTITY(dev)), "Filter matches device"); + + osinfo_filter_clear_constraint(filter, "class"); + osinfo_filter_add_constraint(filter, "class", "audio"); + fail_unless(!osinfo_filter_matches(filter, OSINFO_ENTITY(dev)), "Filter does not match device"); + + g_object_unref(dev); + g_object_unref(filter); +} +END_TEST + +START_TEST(test_filter_multi) +{ + OsinfoFilter *filter = osinfo_filter_new(); + OsinfoDevice *dev = osinfo_device_new("e1000"); + + osinfo_entity_add_param(OSINFO_ENTITY(dev), "bus", "pci"); + + osinfo_filter_add_constraint(filter, "bus", "isa"); + fail_unless(!osinfo_filter_matches(filter, OSINFO_ENTITY(dev)), "Filter does not match device"); + + osinfo_filter_add_constraint(filter, "bus", "pci"); + /* XXX is this right ? Multiple values for a filter constraint + * is treated as requiring all constraint values to match, not + * required any to match */ + //fail_unless(osinfo_filter_matches(filter, OSINFO_ENTITY(dev)), "Filter matches device"); + fail_unless(!osinfo_filter_matches(filter, OSINFO_ENTITY(dev)), "Filter does not match device"); + + osinfo_filter_clear_constraints(filter); + osinfo_filter_add_constraint(filter, "bus", "pci"); + fail_unless(osinfo_filter_matches(filter, OSINFO_ENTITY(dev)), "Filter matches device"); + + g_object_unref(dev); + g_object_unref(filter); +} +END_TEST + + +START_TEST(test_filter_combine) +{ + OsinfoFilter *filter = osinfo_filter_new(); + OsinfoDevice *dev1 = osinfo_device_new("e1000"); + OsinfoDevice *dev2 = osinfo_device_new("ne2k"); + + osinfo_entity_add_param(OSINFO_ENTITY(dev1), "bus", "pci"); + osinfo_entity_add_param(OSINFO_ENTITY(dev1), "class", "network"); + + osinfo_entity_add_param(OSINFO_ENTITY(dev2), "bus", "isa"); + osinfo_entity_add_param(OSINFO_ENTITY(dev2), "class", "network"); + + osinfo_filter_add_constraint(filter, "class", "network"); + fail_unless(osinfo_filter_matches(filter, OSINFO_ENTITY(dev1)), "Filter does not match device"); + fail_unless(osinfo_filter_matches(filter, OSINFO_ENTITY(dev2)), "Filter does not match device"); + + osinfo_filter_add_constraint(filter, "bus", "isa"); + fail_unless(!osinfo_filter_matches(filter, OSINFO_ENTITY(dev1)), "Filter match device"); + fail_unless(osinfo_filter_matches(filter, OSINFO_ENTITY(dev2)), "Filter does not match device"); + + g_object_unref(dev1); + g_object_unref(dev2); + g_object_unref(filter); +} +END_TEST + + +static Suite * +filter_suite(void) +{ + Suite *s = suite_create("Filter"); + TCase *tc = tcase_create("Core"); + tcase_add_test(tc, test_basic); + tcase_add_test(tc, test_filter_single); + tcase_add_test(tc, test_filter_multi); + tcase_add_test(tc, test_filter_combine); + suite_add_tcase(s, tc); + return s; +} + +int main(void) +{ + int number_failed; + Suite *s = filter_suite (); + SRunner *sr = srunner_create (s); + + g_type_init(); + + /* Upfront so we don't confuse valgrind */ + osinfo_device_get_type(); + osinfo_filter_get_type(); + + srunner_run_all (sr, CK_ENV); + number_failed = srunner_ntests_failed (sr); + srunner_free (sr); + + return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/test/test-hypervisor.c b/test/test-hypervisor.c new file mode 100644 index 0000000..0671e2e --- /dev/null +++ b/test/test-hypervisor.c @@ -0,0 +1,120 @@ +#include <stdlib.h> +#include <osinfo/osinfo.h> +#include <check.h> + + + +START_TEST(test_basic) +{ + OsinfoHypervisor *hypervisor = osinfo_hypervisor_new("awesome"); + + fail_unless(OSINFO_IS_HYPERVISOR(hypervisor), "Hypervisor is a hypervisor object"); + fail_unless(g_strcmp0(osinfo_entity_get_id(OSINFO_ENTITY(hypervisor)), "awesome") == 0, "Hypervisor ID was awesome"); + + g_object_unref(hypervisor); +} +END_TEST + +START_TEST(test_devices) +{ + OsinfoHypervisor *hv = osinfo_hypervisor_new("awesome"); + OsinfoDevice *dev1 = osinfo_device_new("e1000"); + OsinfoDevice *dev2 = osinfo_device_new("rtl8139"); + + osinfo_hypervisor_add_device(hv, dev1, "pci-e1000"); + osinfo_hypervisor_add_device(hv, dev2, "pci-8139"); + + OsinfoDeviceList *devices = osinfo_hypervisor_get_devices(hv, NULL); + + fail_unless(osinfo_list_get_length(OSINFO_LIST(devices)) == 2, "Hypervisor has two devices"); + + gboolean hasDev1 = FALSE; + gboolean hasDev2 = FALSE; + gboolean hasBad = FALSE; + int i; + for (i = 0 ; i < osinfo_list_get_length(OSINFO_LIST(devices)) ; i++) { + OsinfoEntity *ent = osinfo_list_get_nth(OSINFO_LIST(devices), i); + fail_unless(OSINFO_IS_DEVICE(ent), "entity is a device"); + if (OSINFO_DEVICE(ent) == dev1) + hasDev1 = TRUE; + else if (OSINFO_DEVICE(ent) == dev2) + hasDev2 = TRUE; + else + hasBad = TRUE; + } + fail_unless(hasDev1, "Device 1 is missing"); + fail_unless(hasDev2, "Device 2 is missing"); + fail_unless(!hasBad, "Device was not expected"); + + g_object_unref(devices); + g_object_unref(dev1); + g_object_unref(dev2); + g_object_unref(hv); +} +END_TEST + + +START_TEST(test_devices_filter) +{ + OsinfoHypervisor *hv = osinfo_hypervisor_new("awesome"); + OsinfoDevice *dev1 = osinfo_device_new("e1000"); + OsinfoDevice *dev2 = osinfo_device_new("sb16"); + OsinfoFilter *filter = osinfo_filter_new(); + + osinfo_entity_add_param(OSINFO_ENTITY(dev1), "class", "network"); + osinfo_entity_add_param(OSINFO_ENTITY(dev2), "class", "audio"); + + osinfo_hypervisor_add_device(hv, dev1, "pci-e1000"); + osinfo_hypervisor_add_device(hv, dev2, "isa-sb16"); + + osinfo_filter_add_constraint(filter, "class", "network"); + + OsinfoDeviceList *devices = osinfo_hypervisor_get_devices(hv, filter); + + fail_unless(osinfo_list_get_length(OSINFO_LIST(devices)) == 1, "Hypervisor has one devices"); + OsinfoEntity *ent = osinfo_list_get_nth(OSINFO_LIST(devices), 0); + fail_unless(OSINFO_IS_DEVICE(ent), "entity is a device"); + fail_unless(OSINFO_DEVICE(ent) == dev1, "device is e1000"); + + g_object_unref(devices); + g_object_unref(filter); + g_object_unref(dev1); + g_object_unref(dev2); + g_object_unref(hv); +} +END_TEST + + + +static Suite * +hypervisor_suite(void) +{ + Suite *s = suite_create("Hypervisor"); + TCase *tc = tcase_create("Core"); + tcase_add_test(tc, test_basic); + tcase_add_test(tc, test_devices); + tcase_add_test(tc, test_devices_filter); + suite_add_tcase(s, tc); + return s; +} + +int main(void) +{ + int number_failed; + Suite *s = hypervisor_suite (); + SRunner *sr = srunner_create (s); + + g_type_init(); + + /* Upfront so we don't confuse valgrind */ + osinfo_hypervisor_get_type(); + osinfo_device_get_type(); + osinfo_devicelist_get_type(); + osinfo_filter_get_type(); + + srunner_run_all (sr, CK_ENV); + number_failed = srunner_ntests_failed (sr); + srunner_free (sr); + + return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/test/test-hypervisorlist.c b/test/test-hypervisorlist.c new file mode 100644 index 0000000..32301c6 --- /dev/null +++ b/test/test-hypervisorlist.c @@ -0,0 +1,216 @@ +#include <stdlib.h> +#include <osinfo/osinfo.h> +#include <check.h> + + +START_TEST(test_union) +{ + OsinfoHypervisorList *list1 = osinfo_hypervisorlist_new(); + OsinfoHypervisorList *list2 = osinfo_hypervisorlist_new(); + OsinfoHypervisorList *list3; + OsinfoHypervisor *ent1 = osinfo_hypervisor_new("wibble1"); + OsinfoHypervisor *ent2 = osinfo_hypervisor_new("wibble2"); + OsinfoHypervisor *ent3 = osinfo_hypervisor_new("wibble3"); + OsinfoHypervisor *ent4 = osinfo_hypervisor_new("wibble4"); + + osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent1)); + osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent2)); + osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent3)); + + osinfo_list_add(OSINFO_LIST(list2), OSINFO_ENTITY(ent1)); + osinfo_list_add(OSINFO_LIST(list2), OSINFO_ENTITY(ent4)); + + list3 = osinfo_hypervisorlist_new_union(list1, list2); + + fail_unless(osinfo_list_get_length(OSINFO_LIST(list3)) == 4, "List did not have 4 elements"); + + gboolean has1 = FALSE; + gboolean has2 = FALSE; + gboolean has3 = FALSE; + gboolean has4 = FALSE; + gboolean hasBad = FALSE; + int i; + for (i = 0 ; i < osinfo_list_get_length(OSINFO_LIST(list3)) ; i++) { + OsinfoHypervisor *ent = OSINFO_HYPERVISOR(osinfo_list_get_nth(OSINFO_LIST(list3), i)); + if (ent == ent1) + has1 = TRUE; + else if (ent == ent2) + has2 = TRUE; + else if (ent == ent3) + has3 = TRUE; + else if (ent == ent4) + has4 = TRUE; + else + hasBad = TRUE; + } + fail_unless(has1, "List was missing entity 1"); + fail_unless(has2, "List was missing entity 2"); + fail_unless(has3, "List was missing entity 3"); + fail_unless(has4, "List was missing entity 4"); + fail_unless(!hasBad, "List had unexpected entity"); + + g_object_unref(ent1); + g_object_unref(ent2); + g_object_unref(ent3); + g_object_unref(ent4); + g_object_unref(list1); + g_object_unref(list2); + g_object_unref(list3); +} +END_TEST + + +START_TEST(test_intersect) +{ + OsinfoHypervisorList *list1 = osinfo_hypervisorlist_new(); + OsinfoHypervisorList *list2 = osinfo_hypervisorlist_new(); + OsinfoHypervisorList *list3; + OsinfoHypervisor *ent1 = osinfo_hypervisor_new("wibble1"); + OsinfoHypervisor *ent2 = osinfo_hypervisor_new("wibble2"); + OsinfoHypervisor *ent3 = osinfo_hypervisor_new("wibble3"); + OsinfoHypervisor *ent4 = osinfo_hypervisor_new("wibble4"); + + + osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent1)); + osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent2)); + osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent3)); + + osinfo_list_add(OSINFO_LIST(list2), OSINFO_ENTITY(ent1)); + osinfo_list_add(OSINFO_LIST(list2), OSINFO_ENTITY(ent3)); + osinfo_list_add(OSINFO_LIST(list2), OSINFO_ENTITY(ent4)); + + list3 = osinfo_hypervisorlist_new_intersection(list1, list2); + + fail_unless(osinfo_list_get_length(OSINFO_LIST(list3)) == 2, "List did not have 2 elements"); + + gboolean has1 = FALSE; + gboolean has2 = FALSE; + gboolean has3 = FALSE; + gboolean has4 = FALSE; + gboolean hasBad = FALSE; + int i; + for (i = 0 ; i < osinfo_list_get_length(OSINFO_LIST(list3)) ; i++) { + OsinfoHypervisor *ent = OSINFO_HYPERVISOR(osinfo_list_get_nth(OSINFO_LIST(list3), i)); + if (ent == ent1) + has1 = TRUE; + else if (ent == ent2) + has2 = TRUE; + else if (ent == ent3) + has3 = TRUE; + else if (ent == ent4) + has4 = TRUE; + else + hasBad = TRUE; + } + fail_unless(has1, "List was missing entity 1"); + fail_unless(!has2, "List had unexpected entity 2"); + fail_unless(has3, "List was missing entity 3"); + fail_unless(!has4, "List had unexpected entity 4"); + fail_unless(!hasBad, "List had unexpected entity"); + + g_object_unref(ent1); + g_object_unref(ent2); + g_object_unref(ent3); + g_object_unref(ent4); + g_object_unref(list1); + g_object_unref(list2); + g_object_unref(list3); +} +END_TEST + + +START_TEST(test_filter) +{ + OsinfoHypervisorList *list1 = osinfo_hypervisorlist_new(); + OsinfoHypervisorList *list2; + OsinfoFilter *filter = osinfo_filter_new(); + OsinfoHypervisor *ent1 = osinfo_hypervisor_new("wibble1"); + OsinfoHypervisor *ent2 = osinfo_hypervisor_new("wibble2"); + OsinfoHypervisor *ent3 = osinfo_hypervisor_new("wibble3"); + OsinfoHypervisor *ent4 = osinfo_hypervisor_new("wibble4"); + + osinfo_entity_add_param(OSINFO_ENTITY(ent1), "class", "network"); + osinfo_entity_add_param(OSINFO_ENTITY(ent1), "class", "wilma"); + osinfo_entity_add_param(OSINFO_ENTITY(ent2), "class", "network"); + osinfo_entity_add_param(OSINFO_ENTITY(ent3), "class", "network"); + osinfo_entity_add_param(OSINFO_ENTITY(ent3), "class", "audio"); + osinfo_entity_add_param(OSINFO_ENTITY(ent4), "class", "audio"); + + osinfo_filter_add_constraint(filter, "class", "network"); + + osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent1)); + osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent2)); + osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent3)); + osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent4)); + + list2 = osinfo_hypervisorlist_new_filtered(list1, filter); + + fail_unless(osinfo_list_get_length(OSINFO_LIST(list2)) == 3, "List did not have 3 elements"); + + gboolean has1 = FALSE; + gboolean has2 = FALSE; + gboolean has3 = FALSE; + gboolean has4 = FALSE; + gboolean hasBad = FALSE; + int i; + for (i = 0 ; i < osinfo_list_get_length(OSINFO_LIST(list2)) ; i++) { + OsinfoHypervisor *ent = OSINFO_HYPERVISOR(osinfo_list_get_nth(OSINFO_LIST(list2), i)); + if (ent == ent1) + has1 = TRUE; + else if (ent == ent2) + has2 = TRUE; + else if (ent == ent3) + has3 = TRUE; + else if (ent == ent4) + has4 = TRUE; + else + hasBad = TRUE; + } + fail_unless(has1, "List was missing entity 1"); + fail_unless(has2, "List was missing entity 2"); + fail_unless(has3, "List was missing entity 3"); + fail_unless(!has4, "List had unexpected entity 4"); + fail_unless(!hasBad, "List had unexpected entity"); + + g_object_unref(ent1); + g_object_unref(ent2); + g_object_unref(ent3); + g_object_unref(ent4); + g_object_unref(filter); + g_object_unref(list1); + g_object_unref(list2); +} +END_TEST + + +static Suite * +list_suite(void) +{ + Suite *s = suite_create("List"); + TCase *tc = tcase_create("Core"); + tcase_add_test(tc, test_union); + tcase_add_test(tc, test_intersect); + tcase_add_test(tc, test_filter); + suite_add_tcase(s, tc); + return s; +} + +int main(void) +{ + int number_failed; + Suite *s = list_suite (); + SRunner *sr = srunner_create (s); + + g_type_init(); + + /* Upfront so we don't confuse valgrind */ + osinfo_hypervisor_get_type(); + osinfo_hypervisorlist_get_type(); + osinfo_filter_get_type(); + + srunner_run_all (sr, CK_ENV); + number_failed = srunner_ntests_failed (sr); + srunner_free (sr); + + return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/test/test-list.c b/test/test-list.c new file mode 100644 index 0000000..d90440d --- /dev/null +++ b/test/test-list.c @@ -0,0 +1,366 @@ +#include <stdlib.h> +#include <osinfo/osinfo.h> +#include <check.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 _OsinfoDummyList OsinfoDummyList; +typedef struct _OsinfoDummyListClass OsinfoDummyListClass; + +struct _OsinfoDummyList +{ + OsinfoList parent_instance; +}; + +struct _OsinfoDummyListClass +{ + OsinfoListClass parent_class; +}; + +GType osinfo_dummy_list_get_type(void); + +G_DEFINE_TYPE (OsinfoDummyList, osinfo_dummy_list, OSINFO_TYPE_LIST); + +static void osinfo_dummy_list_class_init(OsinfoDummyListClass *klass G_GNUC_UNUSED){} +static void osinfo_dummy_list_init (OsinfoDummyList *self G_GNUC_UNUSED) {} + + + +START_TEST(test_basic) +{ + OsinfoList *list = g_object_new(osinfo_dummy_list_get_type(), NULL); + + fail_unless(osinfo_list_get_length(list) == 0, "List was not empty"); + fail_unless(osinfo_list_find_by_id(list, "wibble") == NULL, "List was not empty"); + + g_object_unref(list); +} +END_TEST + + + +START_TEST(test_lookup) +{ + OsinfoList *list = g_object_new(osinfo_dummy_list_get_type(), NULL); + OsinfoEntity *ent = g_object_new(osinfo_dummy_get_type(), "id", "wibble", NULL); + + osinfo_list_add(list, ent); + + fail_unless(osinfo_list_get_length(list) == 1, "List was empty"); + fail_unless(osinfo_list_get_nth(list, 0) == ent, "Lookup wrong element"); + fail_unless(osinfo_list_find_by_id(list, "wibble") != NULL, "Could not find element"); + fail_unless(osinfo_list_find_by_id(list, "fish") == NULL, "Found wrong element"); + + g_object_unref(ent); + g_object_unref(list); +} +END_TEST + + +START_TEST(test_union) +{ + OsinfoList *list1 = g_object_new(osinfo_dummy_list_get_type(), NULL); + OsinfoList *list2 = g_object_new(osinfo_dummy_list_get_type(), NULL); + OsinfoList *list3 = g_object_new(osinfo_dummy_list_get_type(), NULL); + OsinfoEntity *ent1 = g_object_new(osinfo_dummy_get_type(), "id", "wibble1", NULL); + OsinfoEntity *ent2 = g_object_new(osinfo_dummy_get_type(), "id", "wibble2", NULL); + OsinfoEntity *ent3 = g_object_new(osinfo_dummy_get_type(), "id", "wibble3", NULL); + OsinfoEntity *ent4 = g_object_new(osinfo_dummy_get_type(), "id", "wibble4", NULL); + + osinfo_list_add(list1, ent1); + osinfo_list_add(list1, ent2); + osinfo_list_add(list1, ent3); + + osinfo_list_add(list2, ent1); + osinfo_list_add(list2, ent4); + + osinfo_list_add_union(list3, list1, list2); + + fail_unless(osinfo_list_get_length(list3) == 4, "List did not have 4 elements"); + + gboolean has1 = FALSE; + gboolean has2 = FALSE; + gboolean has3 = FALSE; + gboolean has4 = FALSE; + gboolean hasBad = FALSE; + int i; + for (i = 0 ; i < osinfo_list_get_length(list3) ; i++) { + OsinfoEntity *ent = osinfo_list_get_nth(list3, i); + if (ent == ent1) + has1 = TRUE; + else if (ent == ent2) + has2 = TRUE; + else if (ent == ent3) + has3 = TRUE; + else if (ent == ent4) + has4 = TRUE; + else + hasBad = TRUE; + } + fail_unless(has1, "List was missing entity 1"); + fail_unless(has2, "List was missing entity 2"); + fail_unless(has3, "List was missing entity 3"); + fail_unless(has4, "List was missing entity 4"); + fail_unless(!hasBad, "List had unexpected entity"); + + g_object_unref(ent1); + g_object_unref(ent2); + g_object_unref(ent3); + g_object_unref(ent4); + g_object_unref(list1); + g_object_unref(list2); + g_object_unref(list3); +} +END_TEST + + +START_TEST(test_intersect) +{ + OsinfoList *list1 = g_object_new(osinfo_dummy_list_get_type(), NULL); + OsinfoList *list2 = g_object_new(osinfo_dummy_list_get_type(), NULL); + OsinfoList *list3 = g_object_new(osinfo_dummy_list_get_type(), NULL); + OsinfoEntity *ent1 = g_object_new(osinfo_dummy_get_type(), "id", "wibble1", NULL); + OsinfoEntity *ent2 = g_object_new(osinfo_dummy_get_type(), "id", "wibble2", NULL); + OsinfoEntity *ent3 = g_object_new(osinfo_dummy_get_type(), "id", "wibble3", NULL); + OsinfoEntity *ent4 = g_object_new(osinfo_dummy_get_type(), "id", "wibble4", NULL); + + osinfo_list_add(list1, ent1); + osinfo_list_add(list1, ent2); + osinfo_list_add(list1, ent3); + + osinfo_list_add(list2, ent1); + osinfo_list_add(list2, ent3); + osinfo_list_add(list2, ent4); + + osinfo_list_add_intersection(list3, list1, list2); + + fail_unless(osinfo_list_get_length(list3) == 2, "List did not have 2 elements"); + + gboolean has1 = FALSE; + gboolean has2 = FALSE; + gboolean has3 = FALSE; + gboolean has4 = FALSE; + gboolean hasBad = FALSE; + int i; + for (i = 0 ; i < osinfo_list_get_length(list3) ; i++) { + OsinfoEntity *ent = osinfo_list_get_nth(list3, i); + if (ent == ent1) + has1 = TRUE; + else if (ent == ent2) + has2 = TRUE; + else if (ent == ent3) + has3 = TRUE; + else if (ent == ent4) + has4 = TRUE; + else + hasBad = TRUE; + } + fail_unless(has1, "List was missing entity 1"); + fail_unless(!has2, "List had unexpected entity 2"); + fail_unless(has3, "List was missing entity 3"); + fail_unless(!has4, "List had unexpected entity 4"); + fail_unless(!hasBad, "List had unexpected entity"); + + g_object_unref(ent1); + g_object_unref(ent2); + g_object_unref(ent3); + g_object_unref(ent4); + g_object_unref(list1); + g_object_unref(list2); + g_object_unref(list3); +} +END_TEST + + +START_TEST(test_filter) +{ + OsinfoList *list1 = g_object_new(osinfo_dummy_list_get_type(), NULL); + OsinfoList *list2 = g_object_new(osinfo_dummy_list_get_type(), NULL); + OsinfoFilter *filter = osinfo_filter_new(); + OsinfoEntity *ent1 = g_object_new(osinfo_dummy_get_type(), "id", "wibble1", NULL); + OsinfoEntity *ent2 = g_object_new(osinfo_dummy_get_type(), "id", "wibble2", NULL); + OsinfoEntity *ent3 = g_object_new(osinfo_dummy_get_type(), "id", "wibble3", NULL); + OsinfoEntity *ent4 = g_object_new(osinfo_dummy_get_type(), "id", "wibble4", NULL); + + osinfo_entity_add_param(ent1, "class", "network"); + osinfo_entity_add_param(ent1, "class", "wilma"); + osinfo_entity_add_param(ent2, "class", "network"); + osinfo_entity_add_param(ent3, "class", "network"); + osinfo_entity_add_param(ent3, "class", "audio"); + osinfo_entity_add_param(ent4, "class", "audio"); + + osinfo_filter_add_constraint(filter, "class", "network"); + + osinfo_list_add(list1, ent1); + osinfo_list_add(list1, ent2); + osinfo_list_add(list1, ent3); + osinfo_list_add(list1, ent4); + + osinfo_list_add_filtered(list2, list1, filter); + + fail_unless(osinfo_list_get_length(list2) == 3, "List did not have 3 elements"); + + gboolean has1 = FALSE; + gboolean has2 = FALSE; + gboolean has3 = FALSE; + gboolean has4 = FALSE; + gboolean hasBad = FALSE; + int i; + for (i = 0 ; i < osinfo_list_get_length(list2) ; i++) { + OsinfoEntity *ent = osinfo_list_get_nth(list2, i); + if (ent == ent1) + has1 = TRUE; + else if (ent == ent2) + has2 = TRUE; + else if (ent == ent3) + has3 = TRUE; + else if (ent == ent4) + has4 = TRUE; + else + hasBad = TRUE; + } + fail_unless(has1, "List was missing entity 1"); + fail_unless(has2, "List was missing entity 2"); + fail_unless(has3, "List was missing entity 3"); + fail_unless(!has4, "List had unexpected entity 4"); + fail_unless(!hasBad, "List had unexpected entity"); + + g_object_unref(ent1); + g_object_unref(ent2); + g_object_unref(ent3); + g_object_unref(ent4); + g_object_unref(filter); + g_object_unref(list1); + g_object_unref(list2); +} +END_TEST + +struct iterateData { + OsinfoEntity *ent1; + OsinfoEntity *ent2; + OsinfoEntity *ent3; + OsinfoEntity *ent4; + gboolean has1; + gboolean has2; + gboolean has3; + gboolean has4; + gboolean hasBad; +}; + +static gboolean iterator(OsinfoList *list G_GNUC_UNUSED, OsinfoEntity *ent, gpointer opaque) +{ + struct iterateData *data = opaque; + + if (data->ent1 == ent) + data->has1 = TRUE; + else if (data->ent2 == ent) + data->has2 = TRUE; + else if (data->ent3 == ent) + data->has3 = TRUE; + else if (data->ent4 == ent) + data->has4 = TRUE; + else + data->hasBad = TRUE; + + return TRUE; +} + +START_TEST(test_iterate) +{ + OsinfoList *list1 = g_object_new(osinfo_dummy_list_get_type(), NULL); + OsinfoList *list2 = g_object_new(osinfo_dummy_list_get_type(), NULL); + OsinfoEntity *ent1 = g_object_new(osinfo_dummy_get_type(), "id", "wibble1", NULL); + OsinfoEntity *ent2 = g_object_new(osinfo_dummy_get_type(), "id", "wibble2", NULL); + OsinfoEntity *ent3 = g_object_new(osinfo_dummy_get_type(), "id", "wibble3", NULL); + OsinfoEntity *ent4 = g_object_new(osinfo_dummy_get_type(), "id", "wibble4", NULL); + + osinfo_list_add(list1, ent1); + osinfo_list_add(list1, ent2); + osinfo_list_add(list1, ent3); + + osinfo_list_add(list2, ent1); + osinfo_list_add(list2, ent4); + + struct iterateData data = { + ent1, ent2, ent3, ent4, + FALSE, FALSE, FALSE, FALSE, FALSE + }; + osinfo_list_foreach(list1, iterator, &data); + fail_unless(data.has1, "List was missing entity 1"); + fail_unless(data.has2, "List was missing entity 2"); + fail_unless(data.has3, "List was missing entity 3"); + fail_unless(!data.has4, "List has unexpected entity 4"); + fail_unless(!data.hasBad, "List had unexpected entity"); + + data.has1 = data.has2 = data.has3 = data.has4 = data.hasBad = FALSE; + + osinfo_list_foreach(list2, iterator, &data); + fail_unless(data.has1, "List was missing entity 1"); + fail_unless(!data.has2, "List has unexpected entity 2"); + fail_unless(!data.has3, "List has unexpected entity 3"); + fail_unless(data.has4, "List was missing entity 4"); + fail_unless(!data.hasBad, "List had unexpected entity"); + + g_object_unref(ent1); + g_object_unref(ent2); + g_object_unref(ent3); + g_object_unref(ent4); + g_object_unref(list1); + g_object_unref(list2); +} +END_TEST + +static Suite * +list_suite(void) +{ + Suite *s = suite_create("List"); + TCase *tc = tcase_create("Core"); + tcase_add_test(tc, test_basic); + tcase_add_test(tc, test_lookup); + tcase_add_test(tc, test_union); + tcase_add_test(tc, test_intersect); + tcase_add_test(tc, test_filter); + tcase_add_test(tc, test_iterate); + suite_add_tcase(s, tc); + return s; +} + +int main(void) +{ + int number_failed; + Suite *s = list_suite (); + SRunner *sr = srunner_create (s); + + g_type_init(); + + /* Upfront so we don't confuse valgrind */ + osinfo_dummy_get_type(); + osinfo_dummy_list_get_type(); + osinfo_filter_get_type(); + + srunner_run_all (sr, CK_ENV); + number_failed = srunner_ntests_failed (sr); + srunner_free (sr); + + return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/test/test-os.c b/test/test-os.c new file mode 100644 index 0000000..8cf5cca --- /dev/null +++ b/test/test-os.c @@ -0,0 +1,321 @@ +#include <stdlib.h> +#include <osinfo/osinfo.h> +#include <check.h> + + + +START_TEST(test_basic) +{ + OsinfoOs *os = osinfo_os_new("pony"); + + fail_unless(OSINFO_IS_OS(os), "Os is a os object"); + fail_unless(g_strcmp0(osinfo_entity_get_id(OSINFO_ENTITY(os)), "pony") == 0, "Os ID was pony"); + + g_object_unref(os); +} +END_TEST + +START_TEST(test_devices) +{ + OsinfoOs *os = osinfo_os_new("awesome"); + OsinfoDevice *dev1 = osinfo_device_new("e1000"); + OsinfoDevice *dev2 = osinfo_device_new("rtl8139"); + + osinfo_os_add_device(os, NULL, dev1, "pci-e1000"); + osinfo_os_add_device(os, NULL, dev2, "pci-8139"); + + OsinfoDeviceList *devices = osinfo_os_get_devices(os, NULL, NULL); + + fail_unless(osinfo_list_get_length(OSINFO_LIST(devices)) == 2, "Os has two devices"); + fail_unless(osinfo_list_get_nth(OSINFO_LIST(devices), 0) == OSINFO_ENTITY(dev1), "Got device 1"); + fail_unless(osinfo_list_get_nth(OSINFO_LIST(devices), 1) == OSINFO_ENTITY(dev2), "Got device 2"); + + g_object_unref(devices); + g_object_unref(dev1); + g_object_unref(dev2); + g_object_unref(os); +} +END_TEST + + +START_TEST(test_devices_filter) +{ + OsinfoOs *os = osinfo_os_new("awesome"); + OsinfoDevice *dev1 = osinfo_device_new("e1000"); + OsinfoDevice *dev2 = osinfo_device_new("sb16"); + OsinfoFilter *filter = osinfo_filter_new(); + + osinfo_entity_add_param(OSINFO_ENTITY(dev1), "class", "network"); + osinfo_entity_add_param(OSINFO_ENTITY(dev2), "class", "audio"); + + osinfo_os_add_device(os, NULL, dev1, "pci-e1000"); + osinfo_os_add_device(os, NULL, dev2, "isa-sb16"); + + osinfo_filter_add_constraint(filter, "class", "network"); + + OsinfoDeviceList *devices = osinfo_os_get_devices(os, NULL, filter); + + fail_unless(osinfo_list_get_length(OSINFO_LIST(devices)) == 1, "Os has one devices"); + OsinfoEntity *ent = osinfo_list_get_nth(OSINFO_LIST(devices), 0); + fail_unless(OSINFO_IS_DEVICE(ent), "entity is a device"); + fail_unless(OSINFO_DEVICE(ent) == dev1, "device is e1000"); + + g_object_unref(devices); + g_object_unref(filter); + g_object_unref(dev1); + g_object_unref(dev2); + g_object_unref(os); +} +END_TEST + + +START_TEST(test_hv_devices) +{ + OsinfoOs *os = osinfo_os_new("awesome"); + OsinfoHypervisor *hv = osinfo_hypervisor_new("magical"); + OsinfoDevice *dev1 = osinfo_device_new("e1000"); + OsinfoDevice *dev2 = osinfo_device_new("rtl8139"); + OsinfoDevice *dev3 = osinfo_device_new("virtio"); + + osinfo_os_add_device(os, NULL, dev1, "pci-e1000"); + osinfo_os_add_device(os, NULL, dev2, "pci-8139"); + + osinfo_os_add_device(os, hv, dev1, "pci-e1000"); + osinfo_os_add_device(os, hv, dev3, "pci-virtio"); + + OsinfoDeviceList *devices = osinfo_os_get_devices(os, NULL, NULL); + fail_unless(osinfo_list_get_length(OSINFO_LIST(devices)) == 2, "Os has two devices"); + fail_unless(osinfo_list_get_nth(OSINFO_LIST(devices), 0) == OSINFO_ENTITY(dev1), "Got device 1"); + fail_unless(osinfo_list_get_nth(OSINFO_LIST(devices), 1) == OSINFO_ENTITY(dev2), "Got device 2"); + g_object_unref(devices); + + devices = osinfo_os_get_devices(os, hv, NULL); + fail_unless(osinfo_list_get_length(OSINFO_LIST(devices)) == 2, "Os has two devices"); + fail_unless(osinfo_list_get_nth(OSINFO_LIST(devices), 0) == OSINFO_ENTITY(dev1), "Got device 1"); + fail_unless(osinfo_list_get_nth(OSINFO_LIST(devices), 1) == OSINFO_ENTITY(dev3), "Got device 3"); + g_object_unref(devices); + + g_object_unref(hv); + g_object_unref(dev1); + g_object_unref(dev2); + g_object_unref(dev3); + g_object_unref(os); +} +END_TEST + + +START_TEST(test_hv_devices_filter) +{ + OsinfoOs *os = osinfo_os_new("awesome"); + OsinfoHypervisor *hv = osinfo_hypervisor_new("magical"); + OsinfoDevice *dev1 = osinfo_device_new("e1000"); + OsinfoDevice *dev2 = osinfo_device_new("sb16"); + OsinfoDevice *dev3 = osinfo_device_new("virtio"); + OsinfoFilter *filter = osinfo_filter_new(); + + osinfo_entity_add_param(OSINFO_ENTITY(dev1), "class", "network"); + osinfo_entity_add_param(OSINFO_ENTITY(dev2), "class", "audio"); + osinfo_entity_add_param(OSINFO_ENTITY(dev3), "class", "network"); + + osinfo_os_add_device(os, NULL, dev1, "pci-e1000"); + osinfo_os_add_device(os, NULL, dev2, "isa-sb16"); + + osinfo_os_add_device(os, hv, dev2, "pci-sb16"); + osinfo_os_add_device(os, hv, dev3, "pci-virtio"); + + osinfo_filter_add_constraint(filter, "class", "network"); + + OsinfoDeviceList *devices = osinfo_os_get_devices(os, NULL, filter); + + fail_unless(osinfo_list_get_length(OSINFO_LIST(devices)) == 1, "Os has one devices"); + OsinfoEntity *ent = osinfo_list_get_nth(OSINFO_LIST(devices), 0); + fail_unless(OSINFO_IS_DEVICE(ent), "entity is a device"); + fail_unless(OSINFO_DEVICE(ent) == dev1, "device is e1000"); + + g_object_unref(devices); + + devices = osinfo_os_get_devices(os, hv, filter); + + fail_unless(osinfo_list_get_length(OSINFO_LIST(devices)) == 1, "Os has one devices"); + ent = osinfo_list_get_nth(OSINFO_LIST(devices), 0); + fail_unless(OSINFO_IS_DEVICE(ent), "entity is a device"); + fail_unless(OSINFO_DEVICE(ent) == dev3, "device is virtio"); + + + g_object_unref(devices); + g_object_unref(filter); + g_object_unref(dev1); + g_object_unref(dev2); + g_object_unref(dev3); + g_object_unref(hv); + g_object_unref(os); +} +END_TEST + + +START_TEST(test_relos) +{ + OsinfoOs *os1 = osinfo_os_new("pony"); + OsinfoOs *os2 = osinfo_os_new("donkey"); + OsinfoOs *os3 = osinfo_os_new("wathog"); + OsinfoOs *os4 = osinfo_os_new("aardvark"); + OsinfoOs *os5 = osinfo_os_new("unicorn"); + + osinfo_os_add_related_os(os1, OSINFO_OS_RELATIONSHIP_DERIVES_FROM, os2); + osinfo_os_add_related_os(os1, OSINFO_OS_RELATIONSHIP_UPGRADES, os3); + osinfo_os_add_related_os(os1, OSINFO_OS_RELATIONSHIP_UPGRADES, os4); + osinfo_os_add_related_os(os3, OSINFO_OS_RELATIONSHIP_UPGRADES, os4); + osinfo_os_add_related_os(os1, OSINFO_OS_RELATIONSHIP_CLONES, os5); + + OsinfoOsList *os1rel = osinfo_os_get_related(os1, OSINFO_OS_RELATIONSHIP_DERIVES_FROM); + fail_unless(osinfo_list_get_length(OSINFO_LIST(os1rel)) == 1, "Os has 1 derived os"); + fail_unless(osinfo_list_get_nth(OSINFO_LIST(os1rel), 0) == OSINFO_ENTITY(os2), "derived os is os2"); + g_object_unref(os1rel); + + os1rel = osinfo_os_get_related(os1, OSINFO_OS_RELATIONSHIP_UPGRADES); + fail_unless(osinfo_list_get_length(OSINFO_LIST(os1rel)) == 2, "Os has 2 upgraded os"); + fail_unless((osinfo_list_get_nth(OSINFO_LIST(os1rel), 0) == OSINFO_ENTITY(os3) || + osinfo_list_get_nth(OSINFO_LIST(os1rel), 0) == OSINFO_ENTITY(os4)) && + (osinfo_list_get_nth(OSINFO_LIST(os1rel), 1) == OSINFO_ENTITY(os3) || + osinfo_list_get_nth(OSINFO_LIST(os1rel), 1) == OSINFO_ENTITY(os4)), + "upgraded oses are os3 + os4"); + g_object_unref(os1rel); + + os1rel = osinfo_os_get_related(os3, OSINFO_OS_RELATIONSHIP_UPGRADES); + fail_unless(osinfo_list_get_length(OSINFO_LIST(os1rel)) == 1, "Os has 1 upgraded os"); + fail_unless(osinfo_list_get_nth(OSINFO_LIST(os1rel), 0) == OSINFO_ENTITY(os4), "upgraded os is os4"); + g_object_unref(os1rel); + + os1rel = osinfo_os_get_related(os1, OSINFO_OS_RELATIONSHIP_CLONES); + fail_unless(osinfo_list_get_length(OSINFO_LIST(os1rel)) == 1, "Os has 1 upgraded os"); + fail_unless(osinfo_list_get_nth(OSINFO_LIST(os1rel), 0) == OSINFO_ENTITY(os5), "cloned os is os5"); + g_object_unref(os1rel); + + g_object_unref(os1); + g_object_unref(os2); + g_object_unref(os3); + g_object_unref(os4); + g_object_unref(os5); +} +END_TEST + + +START_TEST(test_device_driver) +{ + OsinfoOs *os = osinfo_os_new("awesome"); + OsinfoDevice *dev1 = osinfo_device_new("e1000"); + OsinfoDevice *dev2 = osinfo_device_new("rtl8139"); + OsinfoFilter *filter = osinfo_filter_new(); + + osinfo_entity_add_param(OSINFO_ENTITY(dev1), "class", "network"); + osinfo_entity_add_param(OSINFO_ENTITY(dev2), "class", "network"); + + osinfo_os_add_device(os, NULL, dev1, "pci-e1000"); + osinfo_os_add_device(os, NULL, dev2, "pci-8139"); + + osinfo_filter_add_constraint(filter, "class", "network"); + + const gchar *driver = NULL; + OsinfoDevice *dev = osinfo_os_get_preferred_device(os, NULL, filter, &driver); + fail_unless(OSINFO_IS_DEVICE(dev), "Got a preferred device"); + fail_unless(dev == dev1, "Got preferred device e1000"); + fail_unless(g_strcmp0(driver, "pci-e1000") == 0, "Driver is pci-e1000"); + + osinfo_filter_clear_constraints(filter); + osinfo_filter_add_constraint(filter, "class", "audio"); + + dev = osinfo_os_get_preferred_device(os, NULL, filter, &driver); + fail_unless(dev == NULL, "Got unexpected device"); + fail_unless(driver == NULL, "Got unexpected driver"); + + g_object_unref(filter); + g_object_unref(dev1); + g_object_unref(dev2); + g_object_unref(os); +} +END_TEST + + +START_TEST(test_hv_device_driver) +{ + OsinfoOs *os = osinfo_os_new("awesome"); + OsinfoHypervisor *hv = osinfo_hypervisor_new("special"); + OsinfoDevice *dev1 = osinfo_device_new("e1000"); + OsinfoDevice *dev2 = osinfo_device_new("rtl8139"); + OsinfoDevice *dev3 = osinfo_device_new("sb16"); + OsinfoFilter *filter = osinfo_filter_new(); + + osinfo_entity_add_param(OSINFO_ENTITY(dev1), "class", "network"); + osinfo_entity_add_param(OSINFO_ENTITY(dev2), "class", "network"); + osinfo_entity_add_param(OSINFO_ENTITY(dev3), "class", "audio"); + + osinfo_os_add_device(os, NULL, dev1, "pci-e1000"); + osinfo_os_add_device(os, NULL, dev2, "pci-8139"); + osinfo_os_add_device(os, NULL, dev3, "pci-8139"); + osinfo_os_add_device(os, hv, dev1, "pci-e1000"); + osinfo_os_add_device(os, hv, dev2, "pci-8139"); + + osinfo_filter_add_constraint(filter, "class", "network"); + + const gchar *driver = NULL; + OsinfoDevice *dev = osinfo_os_get_preferred_device(os, NULL, filter, &driver); + fail_unless(OSINFO_IS_DEVICE(dev), "Got a preferred device"); + fail_unless(dev == dev1, "Got preferred device e1000"); + fail_unless(g_strcmp0(driver, "pci-e1000") == 0, "Driver is pci-e1000"); + + osinfo_filter_clear_constraints(filter); + osinfo_filter_add_constraint(filter, "class", "audio"); + + dev = osinfo_os_get_preferred_device(os, hv, filter, &driver); + fail_unless(dev == NULL, "Got unexpected device"); + fail_unless(driver == NULL, "Got unexpected driver"); + + g_object_unref(filter); + g_object_unref(dev1); + g_object_unref(dev2); + g_object_unref(dev3); + g_object_unref(hv); + g_object_unref(os); +} +END_TEST + + +static Suite * +os_suite(void) +{ + Suite *s = suite_create("Os"); + TCase *tc = tcase_create("Core"); + tcase_add_test(tc, test_basic); + tcase_add_test(tc, test_devices); + tcase_add_test(tc, test_devices_filter); + tcase_add_test(tc, test_device_driver); + tcase_add_test(tc, test_hv_devices); + tcase_add_test(tc, test_hv_devices_filter); + tcase_add_test(tc, test_hv_device_driver); + tcase_add_test(tc, test_relos); + suite_add_tcase(s, tc); + return s; +} + +int main(void) +{ + int number_failed; + Suite *s = os_suite (); + SRunner *sr = srunner_create (s); + + g_type_init(); + + /* Upfront so we don't confuse valgrind */ + osinfo_hypervisor_get_type(); + osinfo_device_get_type(); + osinfo_os_get_type(); + osinfo_oslist_get_type(); + osinfo_devicelist_get_type(); + osinfo_filter_get_type(); + + srunner_run_all (sr, CK_ENV); + number_failed = srunner_ntests_failed (sr); + srunner_free (sr); + + return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/test/test-osfilter.c b/test/test-osfilter.c new file mode 100644 index 0000000..b210176 --- /dev/null +++ b/test/test-osfilter.c @@ -0,0 +1,210 @@ +#include <stdlib.h> +#include <osinfo/osinfo.h> +#include <check.h> + + + +START_TEST(test_basic) +{ + OsinfoOsfilter *osfilter = osinfo_osfilter_new(); + OsinfoOs *os1 = osinfo_os_new("pretty"); + OsinfoOs *os2 = osinfo_os_new("ugly"); + + fail_unless(OSINFO_IS_OSFILTER(osfilter), "Osfilter is a osfilter object"); + fail_unless(osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os1)), "Osfilter matches OS"); + + osinfo_osfilter_add_os_constraint(osfilter, OSINFO_OS_RELATIONSHIP_DERIVES_FROM, os1); + GList *tmp = osinfo_osfilter_get_os_constraint_values(osfilter, + OSINFO_OS_RELATIONSHIP_DERIVES_FROM); + fail_unless(tmp != NULL, "Unexpected missing OS"); + fail_unless(tmp->data == os1, "Derived OS is OS 1"); + fail_unless(tmp->next == NULL, "Too many derived OS"); + + tmp = osinfo_osfilter_get_os_constraint_values(osfilter, + OSINFO_OS_RELATIONSHIP_CLONES); + fail_unless(tmp == NULL, "Unexpected cloned OS"); + + + osinfo_osfilter_add_os_constraint(osfilter, OSINFO_OS_RELATIONSHIP_DERIVES_FROM, os2); + tmp = osinfo_osfilter_get_os_constraint_values(osfilter, + OSINFO_OS_RELATIONSHIP_DERIVES_FROM); + fail_unless(tmp != NULL, "Unexpected missing OS"); + fail_unless(tmp->data == os2, "Derived OS is OS 1"); + fail_unless(tmp->next != NULL, "Not enough derived OS"); + fail_unless(tmp->next->data == os1, "Derived OS is OS 1"); + fail_unless(tmp->next->next == NULL, "Too many derived OS"); + + osinfo_osfilter_add_os_constraint(osfilter, OSINFO_OS_RELATIONSHIP_UPGRADES, os1); + tmp = osinfo_osfilter_get_os_constraint_values(osfilter, + OSINFO_OS_RELATIONSHIP_UPGRADES); + fail_unless(tmp != NULL, "Unexpected missing OS"); + fail_unless(tmp->data == os1, "Derived OS is OS 1"); + fail_unless(tmp->next == NULL, "Too many derived OS"); + + osinfo_osfilter_add_os_constraint(osfilter, OSINFO_OS_RELATIONSHIP_CLONES, os1); + tmp = osinfo_osfilter_get_os_constraint_values(osfilter, + OSINFO_OS_RELATIONSHIP_CLONES); + fail_unless(tmp != NULL, "Unexpected missing OS"); + fail_unless(tmp->data == os1, "Derived OS is OS 1"); + fail_unless(tmp->next == NULL, "Too many derived OS"); + + g_object_unref(os2); + g_object_unref(os1); + g_object_unref(osfilter); +} +END_TEST + + +START_TEST(test_osfilter_single) +{ + OsinfoOsfilter *osfilter = osinfo_osfilter_new(); + OsinfoOs *os1 = osinfo_os_new("hot"); + OsinfoOs *os2 = osinfo_os_new("or"); + OsinfoOs *os3 = osinfo_os_new("not"); + OsinfoOs *os4 = osinfo_os_new("burger"); + + + osinfo_os_add_related_os(os1, OSINFO_OS_RELATIONSHIP_DERIVES_FROM, os2); + osinfo_os_add_related_os(os3, OSINFO_OS_RELATIONSHIP_DERIVES_FROM, os4); + + osinfo_osfilter_add_os_constraint(osfilter, OSINFO_OS_RELATIONSHIP_DERIVES_FROM, os2); + fail_unless(osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os1)), "Filter matches OS 1"); + fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os2)), "Filter does not match OS 2"); + fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os3)), "Filter does not match OS 3"); + fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os4)), "Filter does not match OS 4"); + + g_object_unref(os1); + g_object_unref(os2); + g_object_unref(os3); + g_object_unref(os4); + g_object_unref(osfilter); +} +END_TEST + + +START_TEST(test_osfilter_multi) +{ + OsinfoOsfilter *osfilter = osinfo_osfilter_new(); + OsinfoOs *os1 = osinfo_os_new("hot"); + OsinfoOs *os2 = osinfo_os_new("or"); + OsinfoOs *os3 = osinfo_os_new("not"); + OsinfoOs *os4 = osinfo_os_new("burger"); + OsinfoOs *os5 = osinfo_os_new("cat"); + + osinfo_os_add_related_os(os1, OSINFO_OS_RELATIONSHIP_DERIVES_FROM, os2); + osinfo_os_add_related_os(os1, OSINFO_OS_RELATIONSHIP_CLONES, os5); + osinfo_os_add_related_os(os3, OSINFO_OS_RELATIONSHIP_DERIVES_FROM, os2); + osinfo_os_add_related_os(os3, OSINFO_OS_RELATIONSHIP_CLONES, os4); + + osinfo_osfilter_add_os_constraint(osfilter, OSINFO_OS_RELATIONSHIP_DERIVES_FROM, os2); + osinfo_osfilter_add_os_constraint(osfilter, OSINFO_OS_RELATIONSHIP_CLONES, os5); + + fail_unless(osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os1)), "Filter matches OS 1"); + fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os2)), "Filter does not match OS 2"); + fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os3)), "Filter does not match OS 3"); + fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os4)), "Filter does not match OS 4"); + fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os5)), "Filter does not match OS 5"); + + osinfo_osfilter_clear_os_constraint(osfilter, OSINFO_OS_RELATIONSHIP_CLONES); + + fail_unless(osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os1)), "Filter matches OS 1"); + fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os2)), "Filter does not match OS 2"); + fail_unless(osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os3)), "Filter matches OS 3"); + fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os4)), "Filter does not match OS 4"); + fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os5)), "Filter does not match OS 5"); + + osinfo_osfilter_clear_os_constraints(osfilter); + + osinfo_osfilter_add_os_constraint(osfilter, OSINFO_OS_RELATIONSHIP_UPGRADES, os5); + fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os1)), "Filter does not match OS 1"); + fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os2)), "Filter does not match OS 2"); + fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os3)), "Filter does not match OS 3"); + fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os4)), "Filter does not match OS 4"); + fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os5)), "Filter does not match OS 5"); + + g_object_unref(os1); + g_object_unref(os2); + g_object_unref(os3); + g_object_unref(os4); + g_object_unref(os5); + g_object_unref(osfilter); +} +END_TEST + + +START_TEST(test_osfilter_combine) +{ + OsinfoOsfilter *osfilter = osinfo_osfilter_new(); + OsinfoOs *os1 = osinfo_os_new("hot"); + OsinfoOs *os2 = osinfo_os_new("or"); + OsinfoOs *os3 = osinfo_os_new("not"); + OsinfoOs *os4 = osinfo_os_new("burger"); + + osinfo_os_add_related_os(os1, OSINFO_OS_RELATIONSHIP_DERIVES_FROM, os2); + osinfo_os_add_related_os(os3, OSINFO_OS_RELATIONSHIP_DERIVES_FROM, os4); + + osinfo_entity_add_param(OSINFO_ENTITY(os1), "vendor", "drevil"); + osinfo_entity_add_param(OSINFO_ENTITY(os3), "vendor", "acme"); + + osinfo_osfilter_add_os_constraint(osfilter, OSINFO_OS_RELATIONSHIP_DERIVES_FROM, os2); + fail_unless(osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os1)), "Filter matches OS 1"); + fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os2)), "Filter does not match OS 2"); + fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os3)), "Filter does not match OS 3"); + fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os4)), "Filter does not match OS 4"); + + osinfo_filter_add_constraint(OSINFO_FILTER(osfilter), "vendor", "acme"); + fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os1)), "Filter does not match OS 1"); + fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os2)), "Filter does not match OS 2"); + fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os3)), "Filter does not match OS 3"); + fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os4)), "Filter does not match OS 4"); + + osinfo_osfilter_clear_os_constraint(osfilter, OSINFO_OS_RELATIONSHIP_DERIVES_FROM); + fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os1)), "Filter does not match OS 1"); + fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os2)), "Filter does not match OS 2"); + fail_unless(osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os3)), "Filter matches OS 3"); + fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os4)), "Filter does not match OS 4"); + + g_object_unref(os1); + g_object_unref(os2); + g_object_unref(os3); + g_object_unref(os4); + g_object_unref(osfilter); +} +END_TEST + + +static Suite * +osfilter_suite(void) +{ + Suite *s = suite_create("Osfilter"); + TCase *tc = tcase_create("Core"); + tcase_add_test(tc, test_basic); + tcase_add_test(tc, test_osfilter_single); + tcase_add_test(tc, test_osfilter_multi); + tcase_add_test(tc, test_osfilter_combine); + suite_add_tcase(s, tc); + return s; +} + +int main(void) +{ + int number_failed; + Suite *s = osfilter_suite (); + SRunner *sr = srunner_create (s); + + g_type_init(); + + /* Upfront so we don't confuse valgrind */ + osinfo_entity_get_type(); + osinfo_filter_get_type(); + osinfo_list_get_type(); + osinfo_oslist_get_type(); + osinfo_osfilter_get_type(); + osinfo_os_get_type(); + + srunner_run_all (sr, CK_ENV); + number_failed = srunner_ntests_failed (sr); + srunner_free (sr); + + return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/test/test-oslist.c b/test/test-oslist.c new file mode 100644 index 0000000..26d6ca8 --- /dev/null +++ b/test/test-oslist.c @@ -0,0 +1,216 @@ +#include <stdlib.h> +#include <osinfo/osinfo.h> +#include <check.h> + + +START_TEST(test_union) +{ + OsinfoOsList *list1 = osinfo_oslist_new(); + OsinfoOsList *list2 = osinfo_oslist_new(); + OsinfoOsList *list3; + OsinfoOs *ent1 = osinfo_os_new("wibble1"); + OsinfoOs *ent2 = osinfo_os_new("wibble2"); + OsinfoOs *ent3 = osinfo_os_new("wibble3"); + OsinfoOs *ent4 = osinfo_os_new("wibble4"); + + osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent1)); + osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent2)); + osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent3)); + + osinfo_list_add(OSINFO_LIST(list2), OSINFO_ENTITY(ent1)); + osinfo_list_add(OSINFO_LIST(list2), OSINFO_ENTITY(ent4)); + + list3 = osinfo_oslist_new_union(list1, list2); + + fail_unless(osinfo_list_get_length(OSINFO_LIST(list3)) == 4, "List did not have 4 elements"); + + gboolean has1 = FALSE; + gboolean has2 = FALSE; + gboolean has3 = FALSE; + gboolean has4 = FALSE; + gboolean hasBad = FALSE; + int i; + for (i = 0 ; i < osinfo_list_get_length(OSINFO_LIST(list3)) ; i++) { + OsinfoOs *ent = OSINFO_OS(osinfo_list_get_nth(OSINFO_LIST(list3), i)); + if (ent == ent1) + has1 = TRUE; + else if (ent == ent2) + has2 = TRUE; + else if (ent == ent3) + has3 = TRUE; + else if (ent == ent4) + has4 = TRUE; + else + hasBad = TRUE; + } + fail_unless(has1, "List was missing entity 1"); + fail_unless(has2, "List was missing entity 2"); + fail_unless(has3, "List was missing entity 3"); + fail_unless(has4, "List was missing entity 4"); + fail_unless(!hasBad, "List had unexpected entity"); + + g_object_unref(ent1); + g_object_unref(ent2); + g_object_unref(ent3); + g_object_unref(ent4); + g_object_unref(list1); + g_object_unref(list2); + g_object_unref(list3); +} +END_TEST + + +START_TEST(test_intersect) +{ + OsinfoOsList *list1 = osinfo_oslist_new(); + OsinfoOsList *list2 = osinfo_oslist_new(); + OsinfoOsList *list3; + OsinfoOs *ent1 = osinfo_os_new("wibble1"); + OsinfoOs *ent2 = osinfo_os_new("wibble2"); + OsinfoOs *ent3 = osinfo_os_new("wibble3"); + OsinfoOs *ent4 = osinfo_os_new("wibble4"); + + + osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent1)); + osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent2)); + osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent3)); + + osinfo_list_add(OSINFO_LIST(list2), OSINFO_ENTITY(ent1)); + osinfo_list_add(OSINFO_LIST(list2), OSINFO_ENTITY(ent3)); + osinfo_list_add(OSINFO_LIST(list2), OSINFO_ENTITY(ent4)); + + list3 = osinfo_oslist_new_intersection(list1, list2); + + fail_unless(osinfo_list_get_length(OSINFO_LIST(list3)) == 2, "List did not have 2 elements"); + + gboolean has1 = FALSE; + gboolean has2 = FALSE; + gboolean has3 = FALSE; + gboolean has4 = FALSE; + gboolean hasBad = FALSE; + int i; + for (i = 0 ; i < osinfo_list_get_length(OSINFO_LIST(list3)) ; i++) { + OsinfoOs *ent = OSINFO_OS(osinfo_list_get_nth(OSINFO_LIST(list3), i)); + if (ent == ent1) + has1 = TRUE; + else if (ent == ent2) + has2 = TRUE; + else if (ent == ent3) + has3 = TRUE; + else if (ent == ent4) + has4 = TRUE; + else + hasBad = TRUE; + } + fail_unless(has1, "List was missing entity 1"); + fail_unless(!has2, "List had unexpected entity 2"); + fail_unless(has3, "List was missing entity 3"); + fail_unless(!has4, "List had unexpected entity 4"); + fail_unless(!hasBad, "List had unexpected entity"); + + g_object_unref(ent1); + g_object_unref(ent2); + g_object_unref(ent3); + g_object_unref(ent4); + g_object_unref(list1); + g_object_unref(list2); + g_object_unref(list3); +} +END_TEST + + +START_TEST(test_filter) +{ + OsinfoOsList *list1 = osinfo_oslist_new(); + OsinfoOsList *list2; + OsinfoFilter *filter = osinfo_filter_new(); + OsinfoOs *ent1 = osinfo_os_new("wibble1"); + OsinfoOs *ent2 = osinfo_os_new("wibble2"); + OsinfoOs *ent3 = osinfo_os_new("wibble3"); + OsinfoOs *ent4 = osinfo_os_new("wibble4"); + + osinfo_entity_add_param(OSINFO_ENTITY(ent1), "class", "network"); + osinfo_entity_add_param(OSINFO_ENTITY(ent1), "class", "wilma"); + osinfo_entity_add_param(OSINFO_ENTITY(ent2), "class", "network"); + osinfo_entity_add_param(OSINFO_ENTITY(ent3), "class", "network"); + osinfo_entity_add_param(OSINFO_ENTITY(ent3), "class", "audio"); + osinfo_entity_add_param(OSINFO_ENTITY(ent4), "class", "audio"); + + osinfo_filter_add_constraint(filter, "class", "network"); + + osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent1)); + osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent2)); + osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent3)); + osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent4)); + + list2 = osinfo_oslist_new_filtered(list1, filter); + + fail_unless(osinfo_list_get_length(OSINFO_LIST(list2)) == 3, "List did not have 3 elements"); + + gboolean has1 = FALSE; + gboolean has2 = FALSE; + gboolean has3 = FALSE; + gboolean has4 = FALSE; + gboolean hasBad = FALSE; + int i; + for (i = 0 ; i < osinfo_list_get_length(OSINFO_LIST(list2)) ; i++) { + OsinfoOs *ent = OSINFO_OS(osinfo_list_get_nth(OSINFO_LIST(list2), i)); + if (ent == ent1) + has1 = TRUE; + else if (ent == ent2) + has2 = TRUE; + else if (ent == ent3) + has3 = TRUE; + else if (ent == ent4) + has4 = TRUE; + else + hasBad = TRUE; + } + fail_unless(has1, "List was missing entity 1"); + fail_unless(has2, "List was missing entity 2"); + fail_unless(has3, "List was missing entity 3"); + fail_unless(!has4, "List had unexpected entity 4"); + fail_unless(!hasBad, "List had unexpected entity"); + + g_object_unref(ent1); + g_object_unref(ent2); + g_object_unref(ent3); + g_object_unref(ent4); + g_object_unref(filter); + g_object_unref(list1); + g_object_unref(list2); +} +END_TEST + + +static Suite * +list_suite(void) +{ + Suite *s = suite_create("List"); + TCase *tc = tcase_create("Core"); + tcase_add_test(tc, test_union); + tcase_add_test(tc, test_intersect); + tcase_add_test(tc, test_filter); + suite_add_tcase(s, tc); + return s; +} + +int main(void) +{ + int number_failed; + Suite *s = list_suite (); + SRunner *sr = srunner_create (s); + + g_type_init(); + + /* Upfront so we don't confuse valgrind */ + osinfo_os_get_type(); + osinfo_oslist_get_type(); + osinfo_filter_get_type(); + + srunner_run_all (sr, CK_ENV); + number_failed = srunner_ntests_failed (sr); + srunner_free (sr); + + return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/test/test-skeleton.c b/test/test-skeleton.c deleted file mode 100644 index e0054d4..0000000 --- a/test/test-skeleton.c +++ /dev/null @@ -1,68 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <errno.h> -#include <assert.h> - -#include <glib-object.h> -#include <osinfo/osinfo.h> - -int -main (int argc, char *argv[]) -{ - int ret; - g_type_init(); - - /* Create our object */ - OsinfoDb *db = osinfo_db_new("../data"); - GError *err = NULL; - - // Read in data - osinfo_db_initialize(db, &err); - if (err) { - printf("Error loading db: %s\n", err->message); - exit(1); - } - - gchar *backing_dir; - gchar *libvirt_ver; - - g_object_get(G_OBJECT(db), "backing-dir", &backing_dir, - "libvirt-ver", &libvirt_ver, - NULL); - - - printf("Backing dir : %s Libvirt ver: %s\n", backing_dir, libvirt_ver); - g_free(backing_dir); - g_free(libvirt_ver); - - // Now set libvirt-ver and test - GValue val = { 0, }; - g_value_init (&val, G_TYPE_STRING); - g_value_set_string(&val, "2.4"); - - g_object_set_property (G_OBJECT (db), "libvirt-ver", &val); - g_value_unset(&val); - - g_object_get(G_OBJECT(db), "backing-dir", &backing_dir, - "libvirt-ver", &libvirt_ver, - NULL); - printf("Backing dir : %s Libvirt ver: %s\n", backing_dir, libvirt_ver); - g_free(backing_dir); - g_free(libvirt_ver); - - // Now try settomg backing-dir and test - g_value_init (&val, G_TYPE_STRING); - g_value_set_string(&val, "/evil/dir/"); - - g_object_set_property (G_OBJECT (db), "backing-dir", &val); - g_value_unset(&val); - - g_object_get(G_OBJECT(db), "backing-dir", &backing_dir, - "libvirt-ver", &libvirt_ver, - NULL); - printf("Backing dir : %s Libvirt ver: %s\n", backing_dir, libvirt_ver); - g_free(backing_dir); - g_free(libvirt_ver); - g_object_unref(db); - return 0; -} |