[Libosinfo] [libosinfo PATCH 2/7] test-entity: Add tests for flags related methods
Fabiano Fidêncio
fidencio at redhat.com
Mon Dec 3 09:11:47 UTC 2018
Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
tests/test-entity.c | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/tests/test-entity.c b/tests/test-entity.c
index e65963c..f021f9f 100644
--- a/tests/test-entity.c
+++ b/tests/test-entity.c
@@ -309,6 +309,45 @@ test_int64_props(void)
g_object_unref(ent);
}
+typedef enum {
+ TEST_FLAGS_FOO = 1 << 0,
+ TEST_FLAGS_BAR = 1 << 1,
+} TestFlags;
+
+GType test_flags_get_type (void) G_GNUC_CONST;
+#define TYPE_TEST_FLAGS (test_flags_get_type ())
+
+GType test_flags_get_type (void)
+{
+ static volatile gsize g_define_type_id__volatile = 0;
+
+ if (g_once_init_enter (&g_define_type_id__volatile)) {
+ static const GFlagsValue values[] = {
+ { TEST_FLAGS_FOO, "TEST_FLAGS_FOO", "foo" },
+ { TEST_FLAGS_BAR, "TEST_FLAGS_BAR", "bar" },
+ { 0, NULL, NULL}
+ };
+ GType g_define_type_id =
+ g_flags_register_static (g_intern_static_string ("TestFlags"), values);
+ g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
+ }
+
+ return g_define_type_id__volatile;
+}
+
+
+static void
+test_flags_props(void)
+{
+ OsinfoEntity *ent = g_object_new(osinfo_dummy_get_type(), "id", "myentity", NULL);
+
+ g_assert_true(osinfo_entity_get_param_value_flags(ent, "my_flag", TYPE_TEST_FLAGS, TEST_FLAGS_FOO) == TEST_FLAGS_FOO);
+ osinfo_entity_set_param_flags(ent, "my_flag", TEST_FLAGS_BAR, TYPE_TEST_FLAGS);
+ g_assert_true(osinfo_entity_get_param_value_flags(ent, "my_flag", TYPE_TEST_FLAGS, TEST_FLAGS_FOO) == TEST_FLAGS_BAR);
+
+ g_object_unref(ent);
+}
+
int
main(int argc, char *argv[])
{
@@ -321,6 +360,7 @@ main(int argc, char *argv[])
g_test_add_func("/entity/multi_props", test_multi_props);
g_test_add_func("/entity/multi_props_clear", test_multi_props_clear);
g_test_add_func("/entity/int64_props", test_int64_props);
+ g_test_add_func("/entity/flags_props", test_flags_props);
/* Upfront so we don't confuse valgrind */
osinfo_dummy_get_type();
--
2.19.1
More information about the Libosinfo
mailing list