# HG changeset patch
# Node ID 92bca10a280c
# Parent  dd22a9f8ba3e
diff --git a/libpurple/purpleconversation.c b/libpurple/purpleconversation.c
--- a/libpurple/purpleconversation.c
+++ b/libpurple/purpleconversation.c
@@ -292,8 +292,13 @@
 	g_object_get(object, "account", &account, NULL);
 	gc = purple_account_get_connection(account);
 
-	/* copy features from the connection. */
-	purple_conversation_set_features(conv, purple_connection_get_flags(gc));
+	/* Check if we have a connection before we use it. The unit tests are one
+	 * case where we will not have a connection.
+	 */
+	if(PURPLE_IS_CONNECTION(gc)) {
+		purple_conversation_set_features(conv,
+		                                 purple_connection_get_flags(gc));
+	}
 
 	/* add the conversation to the appropriate lists */
 	manager = purple_conversation_manager_get_default();
diff --git a/libpurple/purplesqlitehistoryadapter.h b/libpurple/purplesqlitehistoryadapter.h
--- a/libpurple/purplesqlitehistoryadapter.h
+++ b/libpurple/purplesqlitehistoryadapter.h
@@ -32,7 +32,7 @@
 /**
  * SECTION:purplesqlitehistoryadapter
  * @section_id: libpurple-purplesqlitehistoryadapter
- * @title: Sqlite History Adapter Object
+ * @title: SQLite History Adapter Object
  */
 
 G_BEGIN_DECLS
diff --git a/libpurple/purplesqlitehistoryadapter.c b/libpurple/purplesqlitehistoryadapter.c
--- a/libpurple/purplesqlitehistoryadapter.c
+++ b/libpurple/purplesqlitehistoryadapter.c
@@ -81,8 +81,6 @@
 	                               "/im/pidgin/libpurple/sqlitehistoryadapter/01-schema.sql",
 	                               G_RESOURCE_LOOKUP_FLAGS_NONE, error);
 	if(bytes == NULL) {
-		g_set_error(error, PURPLE_HISTORY_ADAPTER_DOMAIN, 0,
-		            "failed to find resource for migration: %s", error_msg);
 		return FALSE;
 	}
 
diff --git a/libpurple/tests/test_history_adapter.c b/libpurple/tests/test_history_adapter.c
--- a/libpurple/tests/test_history_adapter.c
+++ b/libpurple/tests/test_history_adapter.c
@@ -207,7 +207,6 @@
 	g_assert_true(ta->query);
 	g_assert_false(ta->remove);
 	g_assert_false(ta->write);
-
 	g_list_free(result);
 	g_clear_object(&adapter);
 }
@@ -233,6 +232,7 @@
 
 static void
 test_purple_history_adapter_test_write(void) {
+	PurpleAccount *account = NULL;
 	PurpleConversation *conversation = NULL;
 	PurpleHistoryAdapter *adapter = test_purple_history_adapter_new();
 	PurpleMessage *message = NULL;
@@ -241,7 +241,11 @@
 	gboolean result = FALSE;
 
 	message = g_object_new(PURPLE_TYPE_MESSAGE, NULL);
-	conversation = g_object_new(PURPLE_TYPE_CONVERSATION, NULL);
+	account = purple_account_new("test", "test");
+	conversation = g_object_new(PURPLE_TYPE_IM_CONVERSATION,
+	                            "account", account,
+	                            "name", "pidgy",
+	                            NULL);
 	result = purple_history_adapter_write(adapter, conversation, message,
 	                                      &error);
 
@@ -255,6 +259,10 @@
 
 	g_clear_object(&adapter);
 	g_clear_object(&message);
+
+	/* TODO: something is freeing our ref. */
+	/* g_clear_object(&account); */
+
 	g_clear_object(&conversation);
 }
 
diff --git a/libpurple/tests/test_history_manager.c b/libpurple/tests/test_history_manager.c
--- a/libpurple/tests/test_history_manager.c
+++ b/libpurple/tests/test_history_manager.c
@@ -293,24 +293,43 @@
 	manager = purple_history_manager_get_default();
 	result = purple_history_manager_remove(manager, "", &error);
 
-	g_assert_true(result);
 	g_assert_error(error, PURPLE_HISTORY_MANAGER_DOMAIN, 0);
 	g_clear_error(&error);
+
+	g_assert_false(result);
 }
 
 static void
 test_purple_history_manager_no_adapter_write(void) {
+	PurpleAccount *account = NULL;
+	PurpleConversation *conversation = NULL;
 	PurpleHistoryManager *manager = NULL;
+	PurpleMessage *message = NULL;
 	GError *error = NULL;
 	gboolean result = FALSE;
 
 	manager = purple_history_manager_get_default();
 
-	result = purple_history_manager_write(manager, NULL, NULL, &error);
+	message = g_object_new(PURPLE_TYPE_MESSAGE, NULL);
+	account = purple_account_new("test", "test");
+	conversation = g_object_new(PURPLE_TYPE_IM_CONVERSATION,
+	                            "account", account,
+	                            "name", "pidgy",
+	                            NULL);
 
-	g_assert_true(result);
+	result = purple_history_manager_write(manager, conversation, message,
+	                                      &error);
+
 	g_assert_error(error, PURPLE_HISTORY_MANAGER_DOMAIN, 0);
 	g_clear_error(&error);
+
+	g_assert_false(result);
+
+	/* TODO: someone is freeing our ref. */
+	/* g_clear_object(&account); */
+
+	g_clear_object(&message);
+	g_clear_object(&conversation);
 }
 
 /******************************************************************************
@@ -385,13 +404,14 @@
 
 static void
 test_purple_history_manager_adapter_write(void) {
+	PurpleAccount *account = NULL;
+	PurpleConversation *conversation = NULL;
 	PurpleHistoryManager *manager = purple_history_manager_get_default();
 	PurpleHistoryAdapter *adapter = test_purple_history_adapter_new();
+	PurpleMessage *message = NULL;
 	TestPurpleHistoryAdapter *ta = TEST_PURPLE_HISTORY_ADAPTER(adapter);
 	GError *error = NULL;
 	gboolean result = FALSE;
-	PurpleMessage *message = NULL;
-	PurpleConversation *conversation = NULL;
 
 	result = purple_history_manager_register(manager, adapter, &error);
 	g_assert_no_error(error);
@@ -402,8 +422,11 @@
 	g_assert_true(result);
 
 	message = g_object_new(PURPLE_TYPE_MESSAGE, NULL);
-
-	conversation = g_object_new(PURPLE_TYPE_CONVERSATION, NULL);
+	account = purple_account_new("test", "test");
+	conversation = g_object_new(PURPLE_TYPE_IM_CONVERSATION,
+	                            "account", account,
+	                            "name", "pidgy",
+	                            NULL);
 	result = purple_history_manager_write(manager, conversation, message,
 	                                      &error);
 	g_assert_no_error(error);
@@ -419,6 +442,12 @@
 	g_assert_true(result);
 
 	g_clear_object(&adapter);
+	g_clear_object(&message);
+
+	/* TODO: something is freeing our ref. */
+	/* g_clear_object(&account); */
+
+	g_clear_object(&conversation);
 }
 
 /******************************************************************************
diff --git a/purple-history/purplehistorycore.c b/purple-history/purplehistorycore.c
--- a/purple-history/purplehistorycore.c
+++ b/purple-history/purplehistorycore.c
@@ -52,7 +52,7 @@
 		results = g_list_delete_link(results, results);
 	}
 
-	return EXIT_SUCCESS;
+	return TRUE;
 }
 
 static gboolean
@@ -71,7 +71,7 @@
 		g_printf("Remove successful\n");
 	}
 
-	return EXIT_SUCCESS;
+	return TRUE;
 }
 
 /******************************************************************************
@@ -116,6 +116,8 @@
 			fprintf(stderr, "query failed: %s\n",
 			        error ? error->message : "unknown error");
 
+			g_clear_error(error);
+
 			exit_code = EXIT_FAILURE;
 		}
 	}
