qulogic/gplugin

Use more specific g_assert_* macros.
feature/new-glib-stuff
2019-01-24, Elliott Sales de Andrade
254c5996697e
Parents 6067f6b7ecb0
Children 41b3b3816922
Use more specific g_assert_* macros.

The g_assert() macro is generic and can be turned off. The g_assert_* macros
are specifically for tests and cannot be disabled.
--- a/gplugin/gplugin-loader-tests.c Thu Jan 24 19:19:42 2019 -0500
+++ b/gplugin/gplugin-loader-tests.c Thu Jan 24 19:36:30 2019 -0500
@@ -46,10 +46,10 @@
id = g_strdup_printf("gplugin/%s-basic-plugin", (const gchar *)d);
plugin = gplugin_manager_find_plugin(id);
- g_assert(plugin != NULL);
+ g_assert_nonnull(plugin);
info = gplugin_plugin_get_info(plugin);
- g_assert(info != NULL);
+ g_assert_nonnull(info);
g_assert_cmpstr(gplugin_plugin_info_get_id(info), ==, id);
g_free(id);
@@ -98,10 +98,10 @@
id = g_strdup_printf("gplugin/%s-load-failed", (const gchar *)d);
plugin = gplugin_manager_find_plugin(id);
g_free(id);
- g_assert(plugin != NULL);
+ g_assert_nonnull(plugin);
ret = gplugin_manager_load_plugin(plugin, &error);
- g_assert(ret == FALSE);
+ g_assert_false(ret);
g_assert_error(error, GPLUGIN_DOMAIN, 0);
g_assert_cmpint(gplugin_plugin_get_state(plugin), ==,
GPLUGIN_PLUGIN_STATE_LOAD_FAILED);
@@ -119,10 +119,10 @@
id = g_strdup_printf("gplugin/%s-load-exception", (const gchar *)d);
plugin = gplugin_manager_find_plugin(id);
g_free(id);
- g_assert(plugin != NULL);
+ g_assert_nonnull(plugin);
ret = gplugin_manager_load_plugin(plugin, &error);
- g_assert(ret == FALSE);
+ g_assert_false(ret);
g_assert_error(error, GPLUGIN_DOMAIN, 0);
g_assert_cmpint(gplugin_plugin_get_state(plugin), ==,
GPLUGIN_PLUGIN_STATE_LOAD_FAILED);
@@ -140,16 +140,16 @@
id = g_strdup_printf("gplugin/%s-unload-failed", (const gchar *)d);
plugin = gplugin_manager_find_plugin(id);
g_free(id);
- g_assert(plugin != NULL);
+ g_assert_nonnull(plugin);
ret = gplugin_manager_load_plugin(plugin, &error);
- g_assert(ret != FALSE);
+ g_assert_true(ret);
g_assert_no_error(error);
g_assert_cmpint(gplugin_plugin_get_state(plugin), ==,
GPLUGIN_PLUGIN_STATE_LOADED);
ret = gplugin_manager_unload_plugin(plugin, &error);
- g_assert(ret != TRUE);
+ g_assert_false(ret);
g_assert_error(error, GPLUGIN_DOMAIN, 0);
g_assert_cmpint(gplugin_plugin_get_state(plugin), ==,
GPLUGIN_PLUGIN_STATE_LOADED);
@@ -169,10 +169,10 @@
id = g_strdup_printf("gplugin/%s-dependent-plugin", (const gchar *)d);
plugin = gplugin_manager_find_plugin(id);
g_free(id);
- g_assert(plugin != NULL);
+ g_assert_nonnull(plugin);
info = gplugin_plugin_get_info(plugin);
- g_assert(info != NULL);
+ g_assert_nonnull(info);
deps = (gchar **)gplugin_plugin_info_get_dependencies(info);
for(i = 0; r_deps[i]; i++)
--- a/gplugin/tests/test-bind-local.c Thu Jan 24 19:19:42 2019 -0500
+++ b/gplugin/tests/test-bind-local.c Thu Jan 24 19:36:30 2019 -0500
@@ -39,9 +39,9 @@
gplugin_manager_refresh();
plugin = gplugin_manager_find_plugin("gplugin/bind-local");
- g_assert(plugin);
- g_assert(GPLUGIN_IS_PLUGIN(plugin));
- g_assert(GPLUGIN_IS_NATIVE_PLUGIN(plugin));
+ g_assert_nonnull(plugin);
+ g_assert_true(GPLUGIN_IS_PLUGIN(plugin));
+ g_assert_true(GPLUGIN_IS_NATIVE_PLUGIN(plugin));
}
/******************************************************************************
--- a/gplugin/tests/test-dynamic-type.c Thu Jan 24 19:19:42 2019 -0500
+++ b/gplugin/tests/test-dynamic-type.c Thu Jan 24 19:36:30 2019 -0500
@@ -38,8 +38,8 @@
provider = gplugin_manager_find_plugin("gplugin/dynamic-type-provider");
- g_assert(provider);
- g_assert(gplugin_manager_load_plugin(provider, &error));
+ g_assert_nonnull(provider);
+ g_assert_true(gplugin_manager_load_plugin(provider, &error));
g_assert_no_error(error);
state = gplugin_plugin_get_state(provider);
@@ -47,21 +47,21 @@
user = gplugin_manager_find_plugin("gplugin/dynamic-type-user");
- g_assert(user);
- g_assert(gplugin_manager_load_plugin(user, &error));
+ g_assert_nonnull(user);
+ g_assert_true(gplugin_manager_load_plugin(user, &error));
g_assert_no_error(error);
state = gplugin_plugin_get_state(user);
g_assert_cmpint(state, ==, GPLUGIN_PLUGIN_STATE_LOADED);
/* now unload the plugin */
- g_assert(gplugin_manager_unload_plugin(user, &error));
+ g_assert_true(gplugin_manager_unload_plugin(user, &error));
g_assert_no_error(error);
state = gplugin_plugin_get_state(user);
g_assert_cmpint(state, ==, GPLUGIN_PLUGIN_STATE_QUERIED);
- g_assert(gplugin_manager_unload_plugin(provider, &error));
+ g_assert_true(gplugin_manager_unload_plugin(provider, &error));
g_assert_no_error(error);
state = gplugin_plugin_get_state(provider);
--- a/gplugin/tests/test-id-collision.c Thu Jan 24 19:19:42 2019 -0500
+++ b/gplugin/tests/test-id-collision.c Thu Jan 24 19:36:30 2019 -0500
@@ -35,9 +35,9 @@
gplugin_manager_refresh();
plugins = gplugin_manager_find_plugins("gplugin/id-collision");
- g_assert(plugins);
+ g_assert_nonnull(plugins);
- g_assert(g_slist_length(plugins) == 2);
+ g_assert_cmpuint(g_slist_length(plugins), ==, 2);
gplugin_manager_free_plugin_list(plugins);
}
--- a/gplugin/tests/test-load-on-query.c Thu Jan 24 19:19:42 2019 -0500
+++ b/gplugin/tests/test-load-on-query.c Thu Jan 24 19:36:30 2019 -0500
@@ -35,8 +35,8 @@
gplugin_manager_refresh();
plugin = gplugin_manager_find_plugin("gplugin/load-on-query");
- g_assert(plugin);
- g_assert(GPLUGIN_IS_PLUGIN(plugin));
+ g_assert_nonnull(plugin);
+ g_assert_true(GPLUGIN_IS_PLUGIN(plugin));
g_assert_cmpint(gplugin_plugin_get_state(plugin), ==,
GPLUGIN_PLUGIN_STATE_LOADED);
--- a/gplugin/tests/test-native-loader.c Thu Jan 24 19:19:42 2019 -0500
+++ b/gplugin/tests/test-native-loader.c Thu Jan 24 19:36:30 2019 -0500
@@ -42,13 +42,13 @@
/* find the dependent plugin and make sure it isn't loaded */
plugin =
gplugin_manager_find_plugin("gplugin/broken-dependent-native-plugin");
- g_assert(plugin != NULL);
+ g_assert_nonnull(plugin);
state = gplugin_plugin_get_state(plugin);
g_assert_cmpint(state, !=, GPLUGIN_PLUGIN_STATE_LOADED);
/* now attempt to load the dependent plugin, it's supposed to fail */
- g_assert(!gplugin_manager_load_plugin(plugin, &error));
+ g_assert_false(gplugin_manager_load_plugin(plugin, &error));
}
/******************************************************************************
@@ -66,7 +66,7 @@
/* find the query-error plugin */
plugin = gplugin_manager_find_plugin("gplugin/query-error");
- g_assert(plugin == NULL);
+ g_assert_null(plugin);
}
static void
--- a/gplugin/tests/test-option-group.c Thu Jan 24 19:19:42 2019 -0500
+++ b/gplugin/tests/test-option-group.c Thu Jan 24 19:36:30 2019 -0500
@@ -54,7 +54,7 @@
}
/* now check to see if we exited early */
- g_assert(l1 == NULL || l2 == NULL);
+ g_assert_true(l1 == NULL || l2 == NULL);
for(l2 = expected; l2; l2 = l2->next)
g_free(l2->data);
--- a/gplugin/tests/test-plugin-info.c Thu Jan 24 19:19:42 2019 -0500
+++ b/gplugin/tests/test-plugin-info.c Thu Jan 24 19:36:30 2019 -0500
@@ -31,9 +31,14 @@
g_assert_cmpuint((var), ==, gplugin_plugin_info_get_##var(info)); \
} G_STMT_END
-#define test_bool(var, value) G_STMT_START { \
- g_assert((var) == (value)); \
- g_assert((var) == gplugin_plugin_info_get_##var(info)); \
+#define test_true(var) G_STMT_START { \
+ g_assert_true((var)); \
+ g_assert_true(gplugin_plugin_info_get_##var(info)); \
+} G_STMT_END
+
+#define test_false(var) G_STMT_START { \
+ g_assert_false((var)); \
+ g_assert_false(gplugin_plugin_info_get_##var(info)); \
} G_STMT_END
typedef gchar **(*TestStringVFunc)(GPluginPluginInfo *info);
@@ -93,7 +98,7 @@
NULL
);
- g_assert(GPLUGIN_IS_PLUGIN_INFO(info));
+ g_assert_true(GPLUGIN_IS_PLUGIN_INFO(info));
g_object_get(G_OBJECT(info),
"id", &id,
@@ -118,8 +123,8 @@
test_string(id, "gplugin-test/plugin-info-test");
test_uint(abi_version, GPLUGIN_NATIVE_PLUGIN_ABI_VERSION);
- test_bool(internal, TRUE);
- test_bool(load_on_query, TRUE);
+ test_true(internal);
+ test_true(load_on_query);
test_string(name, "name");
test_string(version, "version");
test_string(license_id, "license-id");
@@ -145,7 +150,7 @@
info = gplugin_plugin_info_new("empty", 1, NULL);
- g_assert(GPLUGIN_IS_PLUGIN_INFO(info));
+ g_assert_true(GPLUGIN_IS_PLUGIN_INFO(info));
g_object_get(G_OBJECT(info),
"id", &id,
@@ -192,7 +197,7 @@
NULL
);
- g_assert(GPLUGIN_IS_PLUGIN_INFO(info));
+ g_assert_true(GPLUGIN_IS_PLUGIN_INFO(info));
g_object_get(G_OBJECT(info),
"id", &id,
@@ -217,8 +222,8 @@
test_string(id, "gplugin-test/plugin-info-test");
test_uint(abi_version, GPLUGIN_NATIVE_PLUGIN_ABI_VERSION);
- test_bool(internal, TRUE);
- test_bool(load_on_query, TRUE);
+ test_true(internal);
+ test_true(load_on_query);
test_string(name, "name");
test_string(version, "version");
test_string(license_id, "license-id");
@@ -337,7 +342,7 @@
NULL);
got = gplugin_plugin_info_get_version_func(info);
- g_assert(func == got);
+ g_assert_true(func == got);
}
static gint
--- a/gplugin/tests/test-signals.c Thu Jan 24 19:19:42 2019 -0500
+++ b/gplugin/tests/test-signals.c Thu Jan 24 19:36:30 2019 -0500
@@ -150,13 +150,13 @@
plugin = gplugin_manager_find_plugin("gplugin/native-basic-plugin");
gplugin_manager_load_plugin(plugin, &error);
g_assert_no_error(error);
- g_assert(data.loading);
- g_assert(data.loaded);
+ g_assert_true(data.loading);
+ g_assert_true(data.loaded);
gplugin_manager_unload_plugin(plugin, &error);
g_assert_no_error(error);
- g_assert(data.unloading);
- g_assert(data.unloaded);
+ g_assert_true(data.unloading);
+ g_assert_true(data.unloaded);
g_signal_handler_disconnect(manager, signals[0]);
g_signal_handler_disconnect(manager, signals[1]);
@@ -195,10 +195,10 @@
plugin = gplugin_manager_find_plugin("gplugin/native-basic-plugin");
gplugin_manager_load_plugin(plugin, &error);
g_assert_error(error, GPLUGIN_DOMAIN, 0);
- g_assert(data.loading);
- g_assert(data.loaded == FALSE);
- g_assert(data.unloading == FALSE);
- g_assert(data.unloaded == FALSE);
+ g_assert_true(data.loading);
+ g_assert_false(data.loaded);
+ g_assert_false(data.unloading);
+ g_assert_false(data.unloaded);
g_signal_handler_disconnect(manager, signals[0]);
g_signal_handler_disconnect(manager, signals[1]);
@@ -237,13 +237,13 @@
plugin = gplugin_manager_find_plugin("gplugin/native-basic-plugin");
gplugin_manager_load_plugin(plugin, &error);
g_assert_no_error(error);
- g_assert(data.loading);
- g_assert(data.loaded);
+ g_assert_true(data.loading);
+ g_assert_true(data.loaded);
gplugin_manager_unload_plugin(plugin, &error);
g_assert_error(error, GPLUGIN_DOMAIN, 0);
- g_assert(data.unloading);
- g_assert(data.unloaded == FALSE);
+ g_assert_true(data.unloading);
+ g_assert_false(data.unloaded);
g_signal_handler_disconnect(manager, signals[0]);
g_signal_handler_disconnect(manager, signals[1]);
@@ -274,8 +274,8 @@
plugin = gplugin_manager_find_plugin("gplugin/native-load-failed");
gplugin_manager_load_plugin(plugin, &error);
g_assert_error(error, GPLUGIN_DOMAIN, 0);
- g_assert(data.loading);
- g_assert(data.load_failed);
+ g_assert_true(data.loading);
+ g_assert_true(data.load_failed);
g_signal_handler_disconnect(manager, signals[0]);
g_signal_handler_disconnect(manager, signals[1]);
--- a/gplugin/tests/test-version-compare.c Thu Jan 24 19:19:42 2019 -0500
+++ b/gplugin/tests/test-version-compare.c Thu Jan 24 19:36:30 2019 -0500
@@ -82,7 +82,7 @@
t = gplugin_version_compare("abc", "1.2.3", &error);
- g_assert(t == 1);
+ g_assert_cmpint(t, ==, 1);
g_assert_no_error(error);
}
@@ -106,7 +106,7 @@
t = gplugin_version_compare("1.2.3", "abc", &error);
- g_assert(t == -1);
+ g_assert_cmpint(t, ==, -1);
g_assert_no_error(error);
}
@@ -126,49 +126,49 @@
/* major version tests */
static void
test_gplugin_version_1_0_0__0_0_0(void) {
- g_assert(gplugin_version_compare("1.0.0", "0.0.0", NULL) == -1);
+ g_assert_cmpint(gplugin_version_compare("1.0.0", "0.0.0", NULL), ==, -1);
}
static void
test_gplugin_version_1_0_0__1_0_0(void) {
- g_assert(gplugin_version_compare("1.0.0", "1.0.0", NULL) == 0);
+ g_assert_cmpint(gplugin_version_compare("1.0.0", "1.0.0", NULL), ==, 0);
}
static void
test_gplugin_version_0_0_0__1_0_0(void) {
- g_assert(gplugin_version_compare("0.0.0", "1.0.0", NULL) == 1);
+ g_assert_cmpint(gplugin_version_compare("0.0.0", "1.0.0", NULL), ==, 1);
}
/* minor version tests */
static void
test_gplugin_version_0_1_0__0_0_0(void) {
- g_assert(gplugin_version_compare("0.1.0", "0.0.0", NULL) == -1);
+ g_assert_cmpint(gplugin_version_compare("0.1.0", "0.0.0", NULL), ==, -1);
}
static void
test_gplugin_version_0_1_0__0_1_0(void) {
- g_assert(gplugin_version_compare("0.1.0", "0.1.0", NULL) == 0);
+ g_assert_cmpint(gplugin_version_compare("0.1.0", "0.1.0", NULL), ==, 0);
}
static void
test_gplugin_version_0_0_0__0_1_0(void) {
- g_assert(gplugin_version_compare("0.0.0", "0.1.0", NULL) == 1);
+ g_assert_cmpint(gplugin_version_compare("0.0.0", "0.1.0", NULL), ==, 1);
}
/* micro version tests */
static void
test_gplugin_version_0_0_1__0_0_0(void) {
- g_assert(gplugin_version_compare("0.1.0", "0.0.0", NULL) == -1);
+ g_assert_cmpint(gplugin_version_compare("0.1.0", "0.0.0", NULL), ==, -1);
}
static void
test_gplugin_version_0_0_1__0_0_1(void) {
- g_assert(gplugin_version_compare("0.1.0", "0.1.0", NULL) == 0);
+ g_assert_cmpint(gplugin_version_compare("0.1.0", "0.1.0", NULL), ==, 0);
}
static void
test_gplugin_version_0_0_0__0_0_1(void) {
- g_assert(gplugin_version_compare("0.0.0", "0.1.0", NULL) == 1);
+ g_assert_cmpint(gplugin_version_compare("0.0.0", "0.1.0", NULL), ==, 1);
}
/* major-minor tests */
--- a/gplugin/tests/test-versioned-dependencies.c Thu Jan 24 19:19:42 2019 -0500
+++ b/gplugin/tests/test-versioned-dependencies.c Thu Jan 24 19:36:30 2019 -0500
@@ -66,8 +66,8 @@
gplugin_manager_refresh();
plugin = gplugin_manager_find_plugin("gplugin/super-dependent");
- g_assert(plugin);
- g_assert(GPLUGIN_IS_PLUGIN(plugin));
+ g_assert_nonnull(plugin);
+ g_assert_true(GPLUGIN_IS_PLUGIN(plugin));
gplugin_manager_load_plugin(plugin, &error);
g_assert_no_error(error);