mirror of
https://github.com/profanity-im/profanity.git
synced 2025-01-03 14:57:42 -05:00
Merge branch 'presence'
This commit is contained in:
commit
9f5cff096c
1
DESIGN
1
DESIGN
@ -179,4 +179,5 @@ types:
|
||||
PStrFunc: A function that will get a string out of the data structure
|
||||
PCopyFunc: A function that will make a copy the data structure, allocating
|
||||
memory for it.
|
||||
PEqualDeepFunc: A function to compare two structures by comparing all members.
|
||||
GDestroyNotify: A function that will free memory for the data structure.
|
||||
|
11
contact.c
11
contact.c
@ -23,6 +23,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "contact.h"
|
||||
|
||||
struct p_contact_t {
|
||||
@ -95,3 +97,12 @@ const char * p_contact_status(const PContact contact)
|
||||
{
|
||||
return contact->status;
|
||||
}
|
||||
|
||||
int p_contacts_equal_deep(const PContact c1, const PContact c2)
|
||||
{
|
||||
int name_eq = (g_strcmp0(c1->name, c2->name) == 0);
|
||||
int show_eq = (g_strcmp0(c1->show, c2->show) == 0);
|
||||
int status_eq = (g_strcmp0(c1->status, c2->status) == 0);
|
||||
|
||||
return (name_eq && show_eq && status_eq);
|
||||
}
|
||||
|
@ -32,5 +32,6 @@ void p_contact_free(PContact contact);
|
||||
const char * p_contact_name(PContact contact);
|
||||
const char * p_contact_show(PContact contact);
|
||||
const char * p_contact_status(PContact contact);
|
||||
int p_contacts_equal_deep(const PContact c1, const PContact c2);
|
||||
|
||||
#endif
|
||||
|
@ -36,6 +36,7 @@ void contact_list_init(void)
|
||||
{
|
||||
ac = p_obj_autocomplete_new((PStrFunc)p_contact_name,
|
||||
(PCopyFunc)p_contact_copy,
|
||||
(PEqualDeepFunc)p_contacts_equal_deep,
|
||||
(GDestroyNotify)p_contact_free);
|
||||
}
|
||||
|
||||
@ -49,15 +50,15 @@ void reset_search_attempts(void)
|
||||
p_autocomplete_reset(ac);
|
||||
}
|
||||
|
||||
void contact_list_remove(const char * const name)
|
||||
gboolean contact_list_remove(const char * const name)
|
||||
{
|
||||
p_autocomplete_remove(ac, name);
|
||||
return p_autocomplete_remove(ac, name);
|
||||
}
|
||||
|
||||
void contact_list_add(const char * const name, const char * const show,
|
||||
gboolean contact_list_add(const char * const name, const char * const show,
|
||||
const char * const status)
|
||||
{
|
||||
p_autocomplete_add(ac, p_contact_new(name, show, status));
|
||||
return p_autocomplete_add(ac, p_contact_new(name, show, status));
|
||||
}
|
||||
|
||||
GSList * get_contact_list(void)
|
||||
|
@ -30,9 +30,9 @@
|
||||
void contact_list_init(void);
|
||||
void contact_list_clear(void);
|
||||
void reset_search_attempts(void);
|
||||
void contact_list_add(const char * const name, const char * const show,
|
||||
gboolean contact_list_add(const char * const name, const char * const show,
|
||||
const char * const status);
|
||||
void contact_list_remove(const char * const name);
|
||||
gboolean contact_list_remove(const char * const name);
|
||||
GSList * get_contact_list(void);
|
||||
char * find_contact(char *search_str);
|
||||
|
||||
|
1729
examplelog.txt
Normal file
1729
examplelog.txt
Normal file
File diff suppressed because one or more lines are too long
12
jabber.c
12
jabber.c
@ -335,11 +335,15 @@ static int _jabber_presence_handler(xmpp_conn_t * const conn,
|
||||
|
||||
if (strcmp(short_jid, short_from) !=0) {
|
||||
if (type == NULL) {// online
|
||||
win_contact_online(short_from, show_str, status_str);
|
||||
contact_list_add(short_from, show_str, status_str);
|
||||
gboolean result = contact_list_add(short_from, show_str, status_str);
|
||||
if (result) {
|
||||
win_contact_online(short_from, show_str, status_str);
|
||||
}
|
||||
} else {// offline
|
||||
win_contact_offline(short_from, show_str, status_str);
|
||||
contact_list_remove(short_from);
|
||||
gboolean result = contact_list_remove(short_from);
|
||||
if (result) {
|
||||
win_contact_offline(short_from, show_str, status_str);
|
||||
}
|
||||
}
|
||||
|
||||
win_page_off();
|
||||
|
57
presence_example.txt
Normal file
57
presence_example.txt
Normal file
@ -0,0 +1,57 @@
|
||||
<presence to="james.booth@framework"
|
||||
from="tony.walsh@framework/407908c3">
|
||||
<show>away</show>
|
||||
<status>I'm not here right now</status>
|
||||
<c hash="sha-1"
|
||||
xmlns="http://jabber.org/protocol/caps"
|
||||
ver="I22W7CegORwdbnu0ZiQwGpxr0Go="
|
||||
node="http://pidgin.im/"/>
|
||||
<x xmlns="vcard-temp:x:update"><photo/></x>
|
||||
</presence>
|
||||
|
||||
<presence to="james.booth@framework"
|
||||
from="tony.walsh@framework/407908c3">
|
||||
<show>away</show>
|
||||
<status>I'm not here right now</status>
|
||||
<query xmlns="jabber:iq:last"
|
||||
seconds="302"/>
|
||||
<c hash="sha-1"
|
||||
xmlns="http://jabber.org/protocol/caps"
|
||||
ver="I22W7CegORwdbnu0ZiQwGpxr0Go="
|
||||
node="http://pidgin.im/"/>
|
||||
<x xmlns="vcard-temp:x:update"><photo/></x>
|
||||
</presence>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<presence to="james.booth@framework"
|
||||
from="chris.hosegood@framework/e63f97b3">
|
||||
<priority>1</priority>
|
||||
<c hash="sha-1"
|
||||
xmlns="http://jabber.org/protocol/caps"
|
||||
ext="voice-v1 camera-v1 video-v1"
|
||||
ver="AcN1/PEN8nq7AHD+9jpxMV4U6YM="
|
||||
node="http://pidgin.im/"/>
|
||||
<x xmlns="vcard-temp:x:update">
|
||||
<photo>768d0f2eb2785fb470a1a629d46b4482ebea5c55</photo>
|
||||
</x>
|
||||
</presence>
|
||||
|
||||
<presence to="james.booth@framework"
|
||||
type="unavailable"
|
||||
from="chris.hosegood@framework/e63f97b3"/>
|
||||
|
||||
<presence to="james.booth@framework"
|
||||
from="chris.hosegood@framework/c718dfe1">
|
||||
<priority>1</priority>
|
||||
<c hash="sha-1"
|
||||
xmlns="http://jabber.org/protocol/caps"
|
||||
ext="voice-v1 camera-v1 video-v1"
|
||||
ver="AcN1/PEN8nq7AHD+9jpxMV4U6YM="
|
||||
node="http://pidgin.im/"/>
|
||||
<x xmlns="vcard-temp:x:update">
|
||||
<photo>768d0f2eb2785fb470a1a629d46b4482ebea5c55</photo>
|
||||
</x>
|
||||
</presence>
|
@ -34,20 +34,22 @@ struct p_autocomplete_t {
|
||||
gchar *search_str;
|
||||
PStrFunc str_func;
|
||||
PCopyFunc copy_func;
|
||||
PEqualDeepFunc equal_deep_func;
|
||||
GDestroyNotify free_func;
|
||||
};
|
||||
|
||||
static gchar * _search_from(PAutocomplete ac, GSList *curr);
|
||||
static const char *_str_func_default(const char *orig);
|
||||
static const char *_copy_func_default(const char *orig);
|
||||
static int _deep_equals_func_default(const char *o1, const char *o2);
|
||||
|
||||
PAutocomplete p_autocomplete_new(void)
|
||||
{
|
||||
return p_obj_autocomplete_new(NULL, NULL, NULL);
|
||||
return p_obj_autocomplete_new(NULL, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
PAutocomplete p_obj_autocomplete_new(PStrFunc str_func, PCopyFunc copy_func,
|
||||
GDestroyNotify free_func)
|
||||
PEqualDeepFunc equal_deep_func, GDestroyNotify free_func)
|
||||
{
|
||||
PAutocomplete new = malloc(sizeof(struct p_autocomplete_t));
|
||||
new->items = NULL;
|
||||
@ -69,6 +71,11 @@ PAutocomplete p_obj_autocomplete_new(PStrFunc str_func, PCopyFunc copy_func,
|
||||
else
|
||||
new->free_func = (GDestroyNotify)free;
|
||||
|
||||
if (equal_deep_func)
|
||||
new->equal_deep_func = equal_deep_func;
|
||||
else
|
||||
new->equal_deep_func = (PEqualDeepFunc)_deep_equals_func_default;
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
@ -89,11 +96,11 @@ void p_autocomplete_reset(PAutocomplete ac)
|
||||
}
|
||||
}
|
||||
|
||||
void p_autocomplete_add(PAutocomplete ac, void *item)
|
||||
gboolean p_autocomplete_add(PAutocomplete ac, void *item)
|
||||
{
|
||||
if (ac->items == NULL) {
|
||||
ac->items = g_slist_append(ac->items, item);
|
||||
return;
|
||||
return TRUE;
|
||||
} else {
|
||||
GSList *curr = ac->items;
|
||||
|
||||
@ -103,13 +110,18 @@ void p_autocomplete_add(PAutocomplete ac, void *item)
|
||||
if (g_strcmp0(ac->str_func(curr->data), ac->str_func(item)) > 0) {
|
||||
ac->items = g_slist_insert_before(ac->items,
|
||||
curr, item);
|
||||
return;
|
||||
return TRUE;
|
||||
|
||||
// update
|
||||
} else if (g_strcmp0(ac->str_func(curr->data), ac->str_func(item)) == 0) {
|
||||
ac->free_func(curr->data);
|
||||
curr->data = item;
|
||||
return;
|
||||
// only update if data different
|
||||
if (!ac->equal_deep_func(curr->data, item)) {
|
||||
ac->free_func(curr->data);
|
||||
curr->data = item;
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
curr = g_slist_next(curr);
|
||||
@ -118,11 +130,11 @@ void p_autocomplete_add(PAutocomplete ac, void *item)
|
||||
// hit end, append
|
||||
ac->items = g_slist_append(ac->items, item);
|
||||
|
||||
return;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
void p_autocomplete_remove(PAutocomplete ac, const char * const item)
|
||||
gboolean p_autocomplete_remove(PAutocomplete ac, const char * const item)
|
||||
{
|
||||
// reset last found if it points to the item to be removed
|
||||
if (ac->last_found != NULL)
|
||||
@ -130,7 +142,7 @@ void p_autocomplete_remove(PAutocomplete ac, const char * const item)
|
||||
ac->last_found = NULL;
|
||||
|
||||
if (!ac->items) {
|
||||
return;
|
||||
return FALSE;
|
||||
} else {
|
||||
GSList *curr = ac->items;
|
||||
|
||||
@ -140,13 +152,13 @@ void p_autocomplete_remove(PAutocomplete ac, const char * const item)
|
||||
ac->items = g_slist_remove(ac->items, curr->data);
|
||||
ac->free_func(current_item);
|
||||
|
||||
return;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
|
||||
return;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
@ -233,3 +245,7 @@ static const char *_copy_func_default(const char *orig)
|
||||
return strdup(orig);
|
||||
}
|
||||
|
||||
static int _deep_equals_func_default(const char *o1, const char *o2)
|
||||
{
|
||||
return (strcmp(o1, o2) == 0);
|
||||
}
|
||||
|
@ -28,14 +28,16 @@
|
||||
typedef struct p_autocomplete_t *PAutocomplete;
|
||||
typedef const char * (*PStrFunc)(const void *obj);
|
||||
typedef void * (*PCopyFunc)(const void *obj);
|
||||
typedef int (*PEqualFunc)(const void *o1, const void *o2);
|
||||
typedef int (*PEqualDeepFunc)(const void *o1, const void *o2);
|
||||
|
||||
PAutocomplete p_autocomplete_new(void);
|
||||
PAutocomplete p_obj_autocomplete_new(PStrFunc str_func, PCopyFunc copy_func,
|
||||
GDestroyNotify free_func);
|
||||
PEqualDeepFunc equal_deep_func, GDestroyNotify free_func);
|
||||
void p_autocomplete_clear(PAutocomplete ac);
|
||||
void p_autocomplete_reset(PAutocomplete ac);
|
||||
void p_autocomplete_add(PAutocomplete ac, void *item);
|
||||
void p_autocomplete_remove(PAutocomplete ac, const char * const item);
|
||||
gboolean p_autocomplete_add(PAutocomplete ac, void *item);
|
||||
gboolean p_autocomplete_remove(PAutocomplete ac, const char * const item);
|
||||
GSList * p_autocomplete_get_list(PAutocomplete ac);
|
||||
gchar * p_autocomplete_complete(PAutocomplete ac, gchar *search_str);
|
||||
|
||||
|
@ -15,8 +15,11 @@ static void clear_empty(void)
|
||||
|
||||
static void clear_empty_with_free_func(void)
|
||||
{
|
||||
PAutocomplete ac = p_obj_autocomplete_new(NULL, NULL,
|
||||
(GDestroyNotify)p_contact_free);
|
||||
PAutocomplete ac =
|
||||
p_obj_autocomplete_new((PStrFunc)p_contact_name,
|
||||
(PCopyFunc)p_contact_copy,
|
||||
(PEqualDeepFunc)p_contacts_equal_deep,
|
||||
(GDestroyNotify)p_contact_free);
|
||||
p_autocomplete_clear(ac);
|
||||
}
|
||||
|
||||
@ -46,8 +49,11 @@ static void get_after_create_returns_null(void)
|
||||
|
||||
static void get_after_create_with_copy_func_returns_null(void)
|
||||
{
|
||||
PAutocomplete ac = p_obj_autocomplete_new(NULL, (PCopyFunc)p_contact_copy,
|
||||
(GDestroyNotify)p_contact_free);
|
||||
PAutocomplete ac =
|
||||
p_obj_autocomplete_new((PStrFunc)p_contact_name,
|
||||
(PCopyFunc)p_contact_copy,
|
||||
(PEqualDeepFunc)p_contacts_equal_deep,
|
||||
(GDestroyNotify)p_contact_free);
|
||||
GSList *result = p_autocomplete_get_list(ac);
|
||||
|
||||
assert_is_null(result);
|
||||
@ -70,8 +76,11 @@ static void add_one_and_complete(void)
|
||||
static void add_one_and_complete_with_funcs(void)
|
||||
{
|
||||
PContact contact = p_contact_new("James", "Online", "I'm here");
|
||||
PAutocomplete ac = p_obj_autocomplete_new((PStrFunc)p_contact_name, NULL,
|
||||
(GDestroyNotify)p_contact_free);
|
||||
PAutocomplete ac =
|
||||
p_obj_autocomplete_new((PStrFunc)p_contact_name,
|
||||
(PCopyFunc)p_contact_copy,
|
||||
(PEqualDeepFunc)p_contacts_equal_deep,
|
||||
(GDestroyNotify)p_contact_free);
|
||||
p_autocomplete_add(ac, contact);
|
||||
char *result = p_autocomplete_complete(ac, "Jam");
|
||||
|
||||
@ -98,8 +107,11 @@ static void add_two_and_complete_returns_first_with_funcs(void)
|
||||
{
|
||||
PContact contact1 = p_contact_new("James", "Online", "I'm here");
|
||||
PContact contact2 = p_contact_new("Jamie", "Away", "Out to lunch");
|
||||
PAutocomplete ac = p_obj_autocomplete_new((PStrFunc)p_contact_name, NULL,
|
||||
(GDestroyNotify)p_contact_free);
|
||||
PAutocomplete ac =
|
||||
p_obj_autocomplete_new((PStrFunc)p_contact_name,
|
||||
(PCopyFunc)p_contact_copy,
|
||||
(PEqualDeepFunc)p_contacts_equal_deep,
|
||||
(GDestroyNotify)p_contact_free);
|
||||
p_autocomplete_add(ac, contact1);
|
||||
p_autocomplete_add(ac, contact2);
|
||||
char *result = p_autocomplete_complete(ac, "Jam");
|
||||
@ -128,8 +140,11 @@ static void add_two_and_complete_returns_second_with_funcs(void)
|
||||
{
|
||||
PContact contact1 = p_contact_new("James", "Online", "I'm here");
|
||||
PContact contact2 = p_contact_new("Jamie", "Away", "Out to lunch");
|
||||
PAutocomplete ac = p_obj_autocomplete_new((PStrFunc)p_contact_name, NULL,
|
||||
(GDestroyNotify)p_contact_free);
|
||||
PAutocomplete ac =
|
||||
p_obj_autocomplete_new((PStrFunc)p_contact_name,
|
||||
(PCopyFunc)p_contact_copy,
|
||||
(PEqualDeepFunc)p_contacts_equal_deep,
|
||||
(GDestroyNotify)p_contact_free);
|
||||
p_autocomplete_add(ac, contact1);
|
||||
p_autocomplete_add(ac, contact2);
|
||||
char *result1 = p_autocomplete_complete(ac, "Jam");
|
||||
@ -158,8 +173,11 @@ static void add_two_adds_two_with_funcs(void)
|
||||
{
|
||||
PContact contact1 = p_contact_new("James", "Online", "I'm here");
|
||||
PContact contact2 = p_contact_new("Jamie", "Away", "Out to lunch");
|
||||
PAutocomplete ac = p_obj_autocomplete_new((PStrFunc)p_contact_name,
|
||||
(PCopyFunc)p_contact_copy, (GDestroyNotify)p_contact_free);
|
||||
PAutocomplete ac =
|
||||
p_obj_autocomplete_new((PStrFunc)p_contact_name,
|
||||
(PCopyFunc)p_contact_copy,
|
||||
(PEqualDeepFunc)p_contacts_equal_deep,
|
||||
(GDestroyNotify)p_contact_free);
|
||||
p_autocomplete_add(ac, contact1);
|
||||
p_autocomplete_add(ac, contact2);
|
||||
GSList *result = p_autocomplete_get_list(ac);
|
||||
@ -187,8 +205,11 @@ static void add_two_same_adds_one_with_funcs(void)
|
||||
{
|
||||
PContact contact1 = p_contact_new("James", "Online", "I'm here");
|
||||
PContact contact2 = p_contact_new("James", "Away", "Out to lunch");
|
||||
PAutocomplete ac = p_obj_autocomplete_new((PStrFunc)p_contact_name,
|
||||
(PCopyFunc)p_contact_copy, (GDestroyNotify)p_contact_free);
|
||||
PAutocomplete ac =
|
||||
p_obj_autocomplete_new((PStrFunc)p_contact_name,
|
||||
(PCopyFunc)p_contact_copy,
|
||||
(PEqualDeepFunc)p_contacts_equal_deep,
|
||||
(GDestroyNotify)p_contact_free);
|
||||
p_autocomplete_add(ac, contact1);
|
||||
p_autocomplete_add(ac, contact2);
|
||||
GSList *result = p_autocomplete_get_list(ac);
|
||||
@ -220,8 +241,11 @@ static void add_two_same_updates_with_funcs(void)
|
||||
{
|
||||
PContact contact1 = p_contact_new("James", "Online", "I'm here");
|
||||
PContact contact2 = p_contact_new("James", "Away", "Out to lunch");
|
||||
PAutocomplete ac = p_obj_autocomplete_new((PStrFunc)p_contact_name,
|
||||
(PCopyFunc)p_contact_copy, (GDestroyNotify)p_contact_free);
|
||||
PAutocomplete ac =
|
||||
p_obj_autocomplete_new((PStrFunc)p_contact_name,
|
||||
(PCopyFunc)p_contact_copy,
|
||||
(PEqualDeepFunc)p_contacts_equal_deep,
|
||||
(GDestroyNotify)p_contact_free);
|
||||
p_autocomplete_add(ac, contact1);
|
||||
p_autocomplete_add(ac, contact2);
|
||||
GSList *result = p_autocomplete_get_list(ac);
|
||||
@ -236,6 +260,114 @@ static void add_two_same_updates_with_funcs(void)
|
||||
p_autocomplete_clear(ac);
|
||||
}
|
||||
|
||||
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_one_returns_true_with_funcs(void)
|
||||
{
|
||||
PContact contact = p_contact_new("James", "Online", "I'm here");
|
||||
PAutocomplete ac =
|
||||
p_obj_autocomplete_new((PStrFunc)p_contact_name,
|
||||
(PCopyFunc)p_contact_copy,
|
||||
(PEqualDeepFunc)p_contacts_equal_deep,
|
||||
(GDestroyNotify)p_contact_free);
|
||||
int result = p_autocomplete_add(ac, contact);
|
||||
|
||||
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_different_returns_true_with_funcs(void)
|
||||
{
|
||||
PContact contact1 = p_contact_new("James", "Online", "I'm here");
|
||||
PContact contact2 = p_contact_new("JamesB", "Away", "Out to lunch");
|
||||
PAutocomplete ac =
|
||||
p_obj_autocomplete_new((PStrFunc)p_contact_name,
|
||||
(PCopyFunc)p_contact_copy,
|
||||
(PEqualDeepFunc)p_contacts_equal_deep,
|
||||
(GDestroyNotify)p_contact_free);
|
||||
int result1 = p_autocomplete_add(ac, contact1);
|
||||
int result2 = p_autocomplete_add(ac, contact2);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
static void add_two_same_returns_false_with_funcs(void)
|
||||
{
|
||||
PContact contact1 = p_contact_new("James", "Online", "I'm here");
|
||||
PContact contact2 = p_contact_new("James", "Online", "I'm here");
|
||||
PAutocomplete ac =
|
||||
p_obj_autocomplete_new((PStrFunc)p_contact_name,
|
||||
(PCopyFunc)p_contact_copy,
|
||||
(PEqualDeepFunc)p_contacts_equal_deep,
|
||||
(GDestroyNotify)p_contact_free);
|
||||
int result1 = p_autocomplete_add(ac, contact1);
|
||||
int result2 = p_autocomplete_add(ac, contact2);
|
||||
|
||||
assert_true(result1);
|
||||
assert_false(result2);
|
||||
|
||||
p_autocomplete_clear(ac);
|
||||
}
|
||||
|
||||
static void add_two_same_different_data_returns_true(void)
|
||||
{
|
||||
PContact contact1 = p_contact_new("James", "Online", "I'm here");
|
||||
PContact contact2 = p_contact_new("James", "Away", "I'm not here right now");
|
||||
PAutocomplete ac =
|
||||
p_obj_autocomplete_new((PStrFunc)p_contact_name,
|
||||
(PCopyFunc)p_contact_copy,
|
||||
(PEqualDeepFunc)p_contacts_equal_deep,
|
||||
(GDestroyNotify)p_contact_free);
|
||||
int result1 = p_autocomplete_add(ac, contact1);
|
||||
int result2 = p_autocomplete_add(ac, contact2);
|
||||
|
||||
assert_true(result1);
|
||||
assert_true(result2);
|
||||
|
||||
p_autocomplete_clear(ac);
|
||||
}
|
||||
|
||||
void register_prof_autocomplete_tests(void)
|
||||
{
|
||||
TEST_MODULE("prof_autocomplete tests");
|
||||
@ -257,4 +389,11 @@ void register_prof_autocomplete_tests(void)
|
||||
TEST(add_two_same_adds_one_with_funcs);
|
||||
TEST(add_two_same_updates);
|
||||
TEST(add_two_same_updates_with_funcs);
|
||||
TEST(add_one_returns_true);
|
||||
TEST(add_one_returns_true_with_funcs);
|
||||
TEST(add_two_different_returns_true);
|
||||
TEST(add_two_different_returns_true_with_funcs);
|
||||
TEST(add_two_same_returns_false);
|
||||
TEST(add_two_same_returns_false_with_funcs);
|
||||
TEST(add_two_same_different_data_returns_true);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user