pidgin/pidgin

Fix some broken unit tests

2021-01-02, Gary Kramlich
a0c11a532ee7
Parents dcc53af7a4fb
Children bdeaceebb0bd
Fix some broken unit tests

* Output the account username instead of the display name in an error message
that causes the tests to fail because the account has no connection.
* Move all `g_assert_no_error` checks **BEFORE** we check the any other results
that we're checking. If we're not supposed to get an error and we have one,
that error helps us find the issue which therefore makes unit test failures
actionable instead of a message to debug.

Testing Done:
Compiled and made sure the tests pass.

Reviewed at https://reviews.imfreedom.org/r/326/
--- a/libpurple/purplecredentialmanager.c Sat Jan 02 22:05:09 2021 -0600
+++ b/libpurple/purplecredentialmanager.c Sat Jan 02 23:24:44 2021 -0600
@@ -406,7 +406,7 @@
if(!purple_account_get_remember_password(account)) {
GError *error = NULL;
- const gchar *name = purple_account_get_name_for_display(account);
+ const gchar *name = purple_account_get_username(account);
error = g_error_new(PURPLE_CREDENTIAL_MANAGER_DOMAIN, 0,
_("account \"%s\" is not marked to be stored"),
--- a/libpurple/tests/test_credential_manager.c Sat Jan 02 22:05:09 2021 -0600
+++ b/libpurple/tests/test_credential_manager.c Sat Jan 02 23:24:44 2021 -0600
@@ -212,8 +212,8 @@
/* Register the first time cleanly. */
r = purple_credential_manager_register_provider(manager, provider, &error);
+ g_assert_no_error(error);
g_assert_true(r);
- g_assert_no_error(error);
/* Register again and verify the error. */
r = purple_credential_manager_register_provider(manager, provider, &error);
@@ -224,8 +224,8 @@
/* Unregister the provider. */
r = purple_credential_manager_unregister_provider(manager, provider,
&error);
+ g_assert_no_error(error);
g_assert_true(r);
- g_assert_no_error(error);
/* Unregister the provider again and verify the error. */
r = purple_credential_manager_unregister_provider(manager, provider,
@@ -251,8 +251,8 @@
ret = purple_credential_manager_set_active_provider(manager, NULL, &error);
+ g_assert_no_error(error);
g_assert_true(ret);
- g_assert_no_error(error);
}
@@ -283,14 +283,14 @@
/* Create the provider and register it in the manager. */
provider = test_purple_credential_provider_new();
r = purple_credential_manager_register_provider(manager, provider, &error);
+ g_assert_no_error(error);
g_assert_true(r);
- g_assert_no_error(error);
/* Set the provider as active and verify it was successful. */
r = purple_credential_manager_set_active_provider(manager, "test-provider",
&error);
+ g_assert_no_error(error);
g_assert_true(r);
- g_assert_no_error(error);
/* Verify that unregistering the provider fails. */
r = purple_credential_manager_unregister_provider(manager, provider,
@@ -301,14 +301,14 @@
/* Now unset the active provider. */
r = purple_credential_manager_set_active_provider(manager, NULL, &error);
+ g_assert_no_error(error);
g_assert_true(r);
- g_assert_no_error(error);
/* Finally unregister the provider now that it's no longer active. */
r = purple_credential_manager_unregister_provider(manager, provider,
&error);
+ g_assert_no_error(error);
g_assert_true(r);
- g_assert_no_error(error);
/* And our final cleanup. */
g_clear_object(&provider);
@@ -343,6 +343,7 @@
PurpleAccount *account = NULL;
account = purple_account_new("test", "test");
+ purple_account_set_remember_password(account, TRUE);
purple_credential_manager_read_password_async(m, account, NULL,
test_purple_credential_manager_no_provider_read_password_cb,
@@ -386,6 +387,7 @@
PurpleAccount *account = NULL;
account = purple_account_new("test", "test");
+ purple_account_set_remember_password(account, TRUE);
purple_credential_manager_write_password_async(m, account, NULL, NULL,
test_purple_credential_manager_no_provider_write_password_cb,
@@ -430,6 +432,7 @@
PurpleAccount *account = NULL;
account = purple_account_new("test", "test");
+ purple_account_set_remember_password(account, TRUE);
purple_credential_manager_clear_password_async(m, account, NULL,
test_purple_credential_manager_no_provider_clear_password_cb,
@@ -508,6 +511,7 @@
PurpleAccount *account = NULL;
account = purple_account_new("test", "test");
+ purple_account_set_remember_password(account, TRUE);
purple_credential_manager_read_password_async(m, account, NULL,
test_purple_credential_manager_read_password_cb,
@@ -524,12 +528,12 @@
gboolean r = FALSE;
r = purple_credential_manager_register_provider(m, p, &e);
+ g_assert_no_error(e);
g_assert_true(r);
- g_assert_no_error(e);
r = purple_credential_manager_set_active_provider(m, "test-provider", &e);
+ g_assert_no_error(e);
g_assert_true(r);
- g_assert_no_error(e);
g_idle_add(test_purple_credential_manager_read_password_idle, m);
g_timeout_add_seconds(10, test_purple_credential_manager_timeout_cb, loop);
@@ -537,12 +541,12 @@
g_main_loop_run(loop);
r = purple_credential_manager_set_active_provider(m, NULL, &e);
+ g_assert_no_error(e);
g_assert_true(r);
- g_assert_no_error(e);
r = purple_credential_manager_unregister_provider(m, p, &e);
+ g_assert_no_error(e);
g_assert_true(r);
- g_assert_no_error(e);
g_clear_object(&p);
}
@@ -557,8 +561,8 @@
gboolean r = FALSE;
r = purple_credential_manager_write_password_finish(manager, res, &error);
+ g_assert_no_error(error);
g_assert_true(r);
- g_assert_no_error(error);
g_clear_object(&account);
@@ -571,6 +575,7 @@
PurpleAccount *account = NULL;
account = purple_account_new("test", "test");
+ purple_account_set_remember_password(account, TRUE);
purple_credential_manager_write_password_async(m, account, NULL, NULL,
test_purple_credential_manager_write_password_cb,
@@ -587,12 +592,12 @@
gboolean r = FALSE;
r = purple_credential_manager_register_provider(m, p, &e);
+ g_assert_no_error(e);
g_assert_true(r);
- g_assert_no_error(e);
r = purple_credential_manager_set_active_provider(m, "test-provider", &e);
+ g_assert_no_error(e);
g_assert_true(r);
- g_assert_no_error(e);
g_idle_add(test_purple_credential_manager_write_password_idle, m);
g_timeout_add_seconds(10, test_purple_credential_manager_timeout_cb, loop);
@@ -600,12 +605,12 @@
g_main_loop_run(loop);
r = purple_credential_manager_set_active_provider(m, NULL, &e);
+ g_assert_no_error(e);
g_assert_true(r);
- g_assert_no_error(e);
r = purple_credential_manager_unregister_provider(m, p, &e);
+ g_assert_no_error(e);
g_assert_true(r);
- g_assert_no_error(e);
g_clear_object(&p);
}
@@ -620,8 +625,8 @@
gboolean r = FALSE;
r = purple_credential_manager_clear_password_finish(manager, res, &error);
+ g_assert_no_error(error);
g_assert_true(r);
- g_assert_no_error(error);
g_clear_object(&account);
@@ -634,6 +639,7 @@
PurpleAccount *account = NULL;
account = purple_account_new("test", "test");
+ purple_account_set_remember_password(account, TRUE);
purple_credential_manager_clear_password_async(m, account, NULL,
test_purple_credential_manager_clear_password_cb,
@@ -650,12 +656,12 @@
gboolean r = FALSE;
r = purple_credential_manager_register_provider(m, p, &e);
+ g_assert_no_error(e);
g_assert_true(r);
- g_assert_no_error(e);
r = purple_credential_manager_set_active_provider(m, "test-provider", &e);
+ g_assert_no_error(e);
g_assert_true(r);
- g_assert_no_error(e);
g_idle_add(test_purple_credential_manager_clear_password_idle, m);
g_timeout_add_seconds(10, test_purple_credential_manager_timeout_cb, loop);
@@ -663,12 +669,12 @@
g_main_loop_run(loop);
r = purple_credential_manager_set_active_provider(m, NULL, &e);
+ g_assert_no_error(e);
g_assert_true(r);
- g_assert_no_error(e);
r = purple_credential_manager_unregister_provider(m, p, &e);
+ g_assert_no_error(e);
g_assert_true(r);
- g_assert_no_error(e);
g_clear_object(&p);
}
@@ -683,23 +689,23 @@
gboolean r = FALSE;
r = purple_credential_manager_register_provider(m, p, &e);
+ g_assert_no_error(e);
g_assert_true(r);
- g_assert_no_error(e);
r = purple_credential_manager_set_active_provider(m, "test-provider", &e);
+ g_assert_no_error(e);
g_assert_true(r);
- g_assert_no_error(e);
fields = purple_credential_manager_read_settings(m, &e);
+ g_assert_no_error(e);
g_assert_nonnull(fields);
- g_assert_no_error(e);
purple_request_fields_destroy(fields);
fields = purple_request_fields_new();
r = purple_credential_manager_write_settings(m, fields, &e);
+ g_assert_no_error(e);
g_assert_true(r);
g_assert_true(tp->fields == fields);
- g_assert_no_error(e);
purple_request_fields_destroy(fields);