From cf0d026adfdaf94949799699e0359ca3e87bba76 Mon Sep 17 00:00:00 2001 From: Evangelos Ribeiro Tzaras Date: Mon, 10 Apr 2023 10:56:56 +0200 Subject: [PATCH] test-contacts: Add more test cases Testing lookup of both empty string and NULL ensures we won't regress. --- tests/test-contacts.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/tests/test-contacts.c b/tests/test-contacts.c index c970b34..9225df0 100644 --- a/tests/test-contacts.c +++ b/tests/test-contacts.c @@ -25,13 +25,48 @@ test_contacts_null_contact (void) g_assert_cmpstr (calls_best_match_get_secondary_info (best_match), ==, ""); } + +static void +test_contacts_empty_contact (void) +{ + g_autoptr (CallsContactsProvider) contacts_provider = + calls_contacts_provider_new (); + g_autoptr (CallsBestMatch) best_match = NULL; + + best_match = calls_contacts_provider_lookup_id (contacts_provider, ""); + g_assert_nonnull (best_match); + + g_assert_cmpstr (calls_best_match_get_primary_info (best_match), ==, "Anonymous caller"); + g_assert_cmpstr (calls_best_match_get_secondary_info (best_match), ==, ""); +} + + +static void +test_contacts_unknown_contact (void) +{ + g_autoptr (CallsContactsProvider) contacts_provider = + calls_contacts_provider_new (); + g_autoptr (CallsBestMatch) best_match = NULL; + const char *id = "111222333444555666"; + + best_match = calls_contacts_provider_lookup_id (contacts_provider, id); + g_assert_nonnull (best_match); + + g_assert_cmpstr (calls_best_match_get_primary_info (best_match), ==, id); + g_assert_cmpstr (calls_best_match_get_secondary_info (best_match), ==, ""); +} + +/* TODO set up folks keyfile backend to test "known" contact */ + int main (int argc, char *argv[]) { - gtk_test_init (&argc, &argv, NULL); + g_test_init (&argc, &argv, NULL); g_test_add_func ("/Calls/contacts/null", (GTestFunc) test_contacts_null_contact); + g_test_add_func ("/Calls/contacts/empty", (GTestFunc) test_contacts_empty_contact); + g_test_add_func ("/Calls/contacts/unknown", (GTestFunc) test_contacts_unknown_contact); g_test_run (); }