2012-05-19 19:09:33 -04:00
|
|
|
#include <stdio.h>
|
2012-05-17 20:53:17 -04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2012-05-17 20:33:40 -04:00
|
|
|
#include <head-unit.h>
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include "contact.h"
|
|
|
|
#include "prof_autocomplete.h"
|
|
|
|
|
|
|
|
static void clear_empty(void)
|
|
|
|
{
|
2012-05-19 19:54:17 -04:00
|
|
|
PAutocomplete ac = p_autocomplete_new();
|
2012-05-19 19:38:16 -04:00
|
|
|
p_autocomplete_clear(ac);
|
2012-05-17 20:33:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void reset_after_create(void)
|
|
|
|
{
|
2012-05-19 19:54:17 -04:00
|
|
|
PAutocomplete ac = p_autocomplete_new();
|
2012-05-17 20:33:40 -04:00
|
|
|
p_autocomplete_reset(ac);
|
2012-05-19 19:38:16 -04:00
|
|
|
p_autocomplete_clear(ac);
|
2012-05-17 20:33:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void find_after_create(void)
|
|
|
|
{
|
2012-05-19 19:54:17 -04:00
|
|
|
PAutocomplete ac = p_autocomplete_new();
|
2012-05-19 19:38:16 -04:00
|
|
|
p_autocomplete_complete(ac, "hello");
|
|
|
|
p_autocomplete_clear(ac);
|
2012-05-17 20:33:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void get_after_create_returns_null(void)
|
|
|
|
{
|
2012-05-19 19:54:17 -04:00
|
|
|
PAutocomplete ac = p_autocomplete_new();
|
2012-05-19 19:38:16 -04:00
|
|
|
GSList *result = p_autocomplete_get_list(ac);
|
2012-05-17 20:53:17 -04:00
|
|
|
|
|
|
|
assert_is_null(result);
|
|
|
|
|
2012-05-19 19:38:16 -04:00
|
|
|
p_autocomplete_clear(ac);
|
2012-05-17 20:33:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void add_one_and_complete(void)
|
|
|
|
{
|
2012-05-17 20:53:17 -04:00
|
|
|
char *item = strdup("Hello");
|
2012-05-19 19:54:17 -04:00
|
|
|
PAutocomplete ac = p_autocomplete_new();
|
2012-05-19 19:38:16 -04:00
|
|
|
p_autocomplete_add(ac, item);
|
|
|
|
char *result = p_autocomplete_complete(ac, "Hel");
|
2012-05-17 20:33:40 -04:00
|
|
|
|
|
|
|
assert_string_equals("Hello", result);
|
2012-05-17 20:53:17 -04:00
|
|
|
|
2012-05-19 19:38:16 -04:00
|
|
|
p_autocomplete_clear(ac);
|
2012-05-17 20:33:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void add_two_and_complete_returns_first(void)
|
|
|
|
{
|
2012-05-17 20:53:17 -04:00
|
|
|
char *item1 = strdup("Hello");
|
|
|
|
char *item2 = strdup("Help");
|
2012-05-19 19:54:17 -04:00
|
|
|
PAutocomplete ac = p_autocomplete_new();
|
2012-05-19 19:38:16 -04:00
|
|
|
p_autocomplete_add(ac, item1);
|
|
|
|
p_autocomplete_add(ac, item2);
|
|
|
|
char *result = p_autocomplete_complete(ac, "Hel");
|
2012-05-17 20:33:40 -04:00
|
|
|
|
|
|
|
assert_string_equals("Hello", result);
|
2012-10-21 15:02:20 -04:00
|
|
|
|
2012-05-19 19:38:16 -04:00
|
|
|
p_autocomplete_clear(ac);
|
2012-05-17 20:33:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void add_two_and_complete_returns_second(void)
|
|
|
|
{
|
2012-05-17 20:53:17 -04:00
|
|
|
char *item1 = strdup("Hello");
|
|
|
|
char *item2 = strdup("Help");
|
2012-05-19 19:54:17 -04:00
|
|
|
PAutocomplete ac = p_autocomplete_new();
|
2012-05-19 19:38:16 -04:00
|
|
|
p_autocomplete_add(ac, item1);
|
|
|
|
p_autocomplete_add(ac, item2);
|
|
|
|
char *result1 = p_autocomplete_complete(ac, "Hel");
|
|
|
|
char *result2 = p_autocomplete_complete(ac, result1);
|
2012-05-17 20:33:40 -04:00
|
|
|
|
|
|
|
assert_string_equals("Help", result2);
|
2012-10-21 15:02:20 -04:00
|
|
|
|
2012-05-19 19:38:16 -04:00
|
|
|
p_autocomplete_clear(ac);
|
2012-05-17 20:33:40 -04:00
|
|
|
}
|
|
|
|
|
2012-05-19 19:09:33 -04:00
|
|
|
static void add_two_adds_two(void)
|
|
|
|
{
|
|
|
|
char *item1 = strdup("Hello");
|
|
|
|
char *item2 = strdup("Help");
|
2012-05-19 19:54:17 -04:00
|
|
|
PAutocomplete ac = p_autocomplete_new();
|
2012-05-19 19:38:16 -04:00
|
|
|
p_autocomplete_add(ac, item1);
|
|
|
|
p_autocomplete_add(ac, item2);
|
|
|
|
GSList *result = p_autocomplete_get_list(ac);
|
2012-05-19 19:09:33 -04:00
|
|
|
|
|
|
|
assert_int_equals(2, g_slist_length(result));
|
|
|
|
|
2012-05-19 19:38:16 -04:00
|
|
|
p_autocomplete_clear(ac);
|
2012-05-19 19:09:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void add_two_same_adds_one(void)
|
|
|
|
{
|
|
|
|
char *item1 = strdup("Hello");
|
|
|
|
char *item2 = strdup("Hello");
|
2012-05-19 19:54:17 -04:00
|
|
|
PAutocomplete ac = p_autocomplete_new();
|
2012-05-19 19:38:16 -04:00
|
|
|
p_autocomplete_add(ac, item1);
|
|
|
|
p_autocomplete_add(ac, item2);
|
|
|
|
GSList *result = p_autocomplete_get_list(ac);
|
2012-05-19 19:09:33 -04:00
|
|
|
|
|
|
|
assert_int_equals(1, g_slist_length(result));
|
|
|
|
|
2012-05-19 19:38:16 -04:00
|
|
|
p_autocomplete_clear(ac);
|
2012-05-19 19:09:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void add_two_same_updates(void)
|
|
|
|
{
|
|
|
|
char *item1 = strdup("Hello");
|
|
|
|
char *item2 = strdup("Hello");
|
2012-05-19 19:54:17 -04:00
|
|
|
PAutocomplete ac = p_autocomplete_new();
|
2012-05-19 19:38:16 -04:00
|
|
|
p_autocomplete_add(ac, item1);
|
|
|
|
p_autocomplete_add(ac, item2);
|
|
|
|
GSList *result = p_autocomplete_get_list(ac);
|
2012-05-19 19:09:33 -04:00
|
|
|
|
|
|
|
GSList *first = g_slist_nth(result, 0);
|
|
|
|
|
|
|
|
char *str = first->data;
|
|
|
|
|
|
|
|
assert_string_equals("Hello", str);
|
|
|
|
|
2012-05-19 19:38:16 -04:00
|
|
|
p_autocomplete_clear(ac);
|
2012-05-19 19:09:33 -04:00
|
|
|
}
|
|
|
|
|
2012-05-23 19:38:54 -04:00
|
|
|
static void add_one_returns_true(void)
|
|
|
|
{
|
|
|
|
char *item = strdup("Hello");
|
|
|
|
PAutocomplete ac = p_autocomplete_new();
|
|
|
|
int result = p_autocomplete_add(ac, item);
|
|
|
|
|
|
|
|
assert_true(result);
|
|
|
|
|
|
|
|
p_autocomplete_clear(ac);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void add_two_different_returns_true(void)
|
|
|
|
{
|
|
|
|
char *item1 = strdup("Hello");
|
|
|
|
char *item2 = strdup("Hello there");
|
|
|
|
PAutocomplete ac = p_autocomplete_new();
|
|
|
|
int result1 = p_autocomplete_add(ac, item1);
|
|
|
|
int result2 = p_autocomplete_add(ac, item2);
|
|
|
|
|
|
|
|
assert_true(result1);
|
|
|
|
assert_true(result2);
|
|
|
|
|
|
|
|
p_autocomplete_clear(ac);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void add_two_same_returns_false(void)
|
|
|
|
{
|
|
|
|
char *item1 = strdup("Hello");
|
|
|
|
char *item2 = strdup("Hello");
|
|
|
|
PAutocomplete ac = p_autocomplete_new();
|
|
|
|
int result1 = p_autocomplete_add(ac, item1);
|
|
|
|
int result2 = p_autocomplete_add(ac, item2);
|
|
|
|
|
|
|
|
assert_true(result1);
|
|
|
|
assert_false(result2);
|
|
|
|
|
|
|
|
p_autocomplete_clear(ac);
|
|
|
|
}
|
|
|
|
|
2012-05-17 20:33:40 -04:00
|
|
|
void register_prof_autocomplete_tests(void)
|
|
|
|
{
|
|
|
|
TEST_MODULE("prof_autocomplete tests");
|
|
|
|
TEST(clear_empty);
|
|
|
|
TEST(reset_after_create);
|
|
|
|
TEST(find_after_create);
|
|
|
|
TEST(get_after_create_returns_null);
|
|
|
|
TEST(add_one_and_complete);
|
|
|
|
TEST(add_two_and_complete_returns_first);
|
|
|
|
TEST(add_two_and_complete_returns_second);
|
2012-05-19 19:09:33 -04:00
|
|
|
TEST(add_two_adds_two);
|
|
|
|
TEST(add_two_same_adds_one);
|
|
|
|
TEST(add_two_same_updates);
|
2012-05-23 19:38:54 -04:00
|
|
|
TEST(add_one_returns_true);
|
|
|
|
TEST(add_two_different_returns_true);
|
|
|
|
TEST(add_two_same_returns_false);
|
2012-05-17 20:33:40 -04:00
|
|
|
}
|