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"
|
2013-02-02 17:54:16 -05:00
|
|
|
#include "tools/autocomplete.h"
|
2012-05-17 20:33:40 -04:00
|
|
|
|
|
|
|
static void clear_empty(void)
|
|
|
|
{
|
2013-01-24 20:11:49 -05:00
|
|
|
Autocomplete ac = autocomplete_new();
|
|
|
|
autocomplete_clear(ac);
|
2012-05-17 20:33:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void reset_after_create(void)
|
|
|
|
{
|
2013-01-24 20:11:49 -05:00
|
|
|
Autocomplete ac = autocomplete_new();
|
|
|
|
autocomplete_reset(ac);
|
|
|
|
autocomplete_clear(ac);
|
2012-05-17 20:33:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void find_after_create(void)
|
|
|
|
{
|
2013-01-24 20:11:49 -05:00
|
|
|
Autocomplete ac = autocomplete_new();
|
|
|
|
autocomplete_complete(ac, "hello");
|
|
|
|
autocomplete_clear(ac);
|
2012-05-17 20:33:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void get_after_create_returns_null(void)
|
|
|
|
{
|
2013-01-24 20:11:49 -05:00
|
|
|
Autocomplete ac = autocomplete_new();
|
|
|
|
GSList *result = autocomplete_get_list(ac);
|
2012-05-17 20:53:17 -04:00
|
|
|
|
|
|
|
assert_is_null(result);
|
|
|
|
|
2013-01-24 20:11:49 -05:00
|
|
|
autocomplete_clear(ac);
|
2012-05-17 20:33:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void add_one_and_complete(void)
|
|
|
|
{
|
2013-01-24 20:11:49 -05:00
|
|
|
Autocomplete ac = autocomplete_new();
|
2013-08-25 20:29:50 -04:00
|
|
|
autocomplete_add(ac, "Hello");
|
2013-01-24 20:11:49 -05:00
|
|
|
char *result = 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
|
|
|
|
2013-01-24 20:11:49 -05:00
|
|
|
autocomplete_clear(ac);
|
2012-05-17 20:33:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void add_two_and_complete_returns_first(void)
|
|
|
|
{
|
2013-01-24 20:11:49 -05:00
|
|
|
Autocomplete ac = autocomplete_new();
|
2013-08-25 20:29:50 -04:00
|
|
|
autocomplete_add(ac, "Hello");
|
|
|
|
autocomplete_add(ac, "Help");
|
2013-01-24 20:11:49 -05:00
|
|
|
char *result = 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
|
|
|
|
2013-01-24 20:11:49 -05:00
|
|
|
autocomplete_clear(ac);
|
2012-05-17 20:33:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void add_two_and_complete_returns_second(void)
|
|
|
|
{
|
2013-01-24 20:11:49 -05:00
|
|
|
Autocomplete ac = autocomplete_new();
|
2013-08-25 20:29:50 -04:00
|
|
|
autocomplete_add(ac, "Hello");
|
|
|
|
autocomplete_add(ac, "Help");
|
2013-01-24 20:11:49 -05:00
|
|
|
char *result1 = autocomplete_complete(ac, "Hel");
|
|
|
|
char *result2 = 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
|
|
|
|
2013-01-24 20:11:49 -05:00
|
|
|
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)
|
|
|
|
{
|
2013-01-24 20:11:49 -05:00
|
|
|
Autocomplete ac = autocomplete_new();
|
2013-08-25 20:29:50 -04:00
|
|
|
autocomplete_add(ac, "Hello");
|
|
|
|
autocomplete_add(ac, "Help");
|
2013-01-24 20:11:49 -05:00
|
|
|
GSList *result = autocomplete_get_list(ac);
|
2012-05-19 19:09:33 -04:00
|
|
|
|
|
|
|
assert_int_equals(2, g_slist_length(result));
|
|
|
|
|
2013-01-24 20:11:49 -05:00
|
|
|
autocomplete_clear(ac);
|
2012-05-19 19:09:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void add_two_same_adds_one(void)
|
|
|
|
{
|
2013-01-24 20:11:49 -05:00
|
|
|
Autocomplete ac = autocomplete_new();
|
2013-08-25 20:29:50 -04:00
|
|
|
autocomplete_add(ac, "Hello");
|
|
|
|
autocomplete_add(ac, "Hello");
|
2013-01-24 20:11:49 -05:00
|
|
|
GSList *result = autocomplete_get_list(ac);
|
2012-05-19 19:09:33 -04:00
|
|
|
|
|
|
|
assert_int_equals(1, g_slist_length(result));
|
|
|
|
|
2013-01-24 20:11:49 -05:00
|
|
|
autocomplete_clear(ac);
|
2012-05-19 19:09:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void add_two_same_updates(void)
|
|
|
|
{
|
2013-01-24 20:11:49 -05:00
|
|
|
Autocomplete ac = autocomplete_new();
|
2013-08-25 20:29:50 -04:00
|
|
|
autocomplete_add(ac, "Hello");
|
|
|
|
autocomplete_add(ac, "Hello");
|
2013-01-24 20:11:49 -05:00
|
|
|
GSList *result = 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);
|
|
|
|
|
2013-01-24 20:11:49 -05:00
|
|
|
autocomplete_clear(ac);
|
2012-05-19 19:09:33 -04:00
|
|
|
}
|
|
|
|
|
2013-01-24 20:11:49 -05:00
|
|
|
void register_autocomplete_tests(void)
|
2012-05-17 20:33:40 -04:00
|
|
|
{
|
2013-01-24 20:11:49 -05:00
|
|
|
TEST_MODULE("autocomplete tests");
|
2012-05-17 20:33:40 -04:00
|
|
|
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-17 20:33:40 -04:00
|
|
|
}
|