| 27 *****************************************************************************/ |
27 *****************************************************************************/ |
| 28 static void |
28 static void |
| 29 test_purple_contact_new(void) { |
29 test_purple_contact_new(void) { |
| 30 PurpleAccount *account = NULL; |
30 PurpleAccount *account = NULL; |
| 31 PurpleContact *contact = NULL; |
31 PurpleContact *contact = NULL; |
| |
32 PurpleContactInfo *info = NULL; |
| 32 |
33 |
| 33 account = purple_account_new("test", "test"); |
34 account = purple_account_new("test", "test"); |
| 34 contact = purple_contact_new(account, "id"); |
35 contact = purple_contact_new(account, "id"); |
| |
36 info = PURPLE_CONTACT_INFO(contact); |
| 35 |
37 |
| 36 g_assert_true(purple_contact_get_account(contact) == account); |
38 g_assert_true(purple_contact_get_account(contact) == account); |
| 37 g_assert_cmpstr(purple_contact_get_id(contact), ==, "id"); |
39 g_assert_cmpstr(purple_contact_info_get_id(info), ==, "id"); |
| 38 |
40 |
| 39 g_clear_object(&contact); |
41 g_clear_object(&contact); |
| 40 g_clear_object(&account); |
42 g_clear_object(&account); |
| 41 } |
43 } |
| 42 |
44 |
| 43 static void |
45 static void |
| 44 test_purple_contact_properties(void) { |
46 test_purple_contact_properties(void) { |
| 45 PurpleAccount *account = NULL; |
47 PurpleAccount *account = NULL; |
| 46 PurpleAccount *account1 = NULL; |
48 PurpleAccount *account1 = NULL; |
| 47 PurpleContact *contact = NULL; |
49 PurpleContact *contact = NULL; |
| 48 PurpleContactPermission permission; |
50 char *id = NULL; |
| 49 PurplePerson *person = NULL; |
|
| 50 PurplePerson *person1 = NULL; |
|
| 51 PurplePresence *presence1 = NULL; |
|
| 52 PurpleTags *tags = NULL; |
|
| 53 GdkPixbuf *avatar = NULL; |
|
| 54 GdkPixbuf *avatar1 = NULL; |
|
| 55 gchar *id = NULL; |
|
| 56 gchar *username = NULL; |
|
| 57 gchar *display_name = NULL; |
|
| 58 gchar *alias = NULL; |
|
| 59 |
51 |
| 60 account = purple_account_new("test", "test"); |
52 account = purple_account_new("test", "test"); |
| 61 avatar = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 1, 1); |
|
| 62 person = purple_person_new(); |
|
| 63 |
53 |
| 64 /* Use g_object_new so we can test setting properties by name. All of them |
54 /* Use g_object_new so we can test setting properties by name. All of them |
| 65 * call the setter methods, so by doing it this way we exercise more of the |
55 * call the setter methods, so by doing it this way we exercise more of the |
| 66 * code. |
56 * code. |
| 67 */ |
57 */ |
| 68 contact = g_object_new( |
58 contact = g_object_new( |
| 69 PURPLE_TYPE_CONTACT, |
59 PURPLE_TYPE_CONTACT, |
| 70 "account", account, |
60 "account", account, |
| 71 "id", "id1", |
61 "id", "id1", |
| 72 "username", "username", |
|
| 73 "display-name", "display-name", |
|
| 74 "alias", "alias", |
|
| 75 "avatar", avatar, |
|
| 76 "person", person, |
|
| 77 "permission", PURPLE_CONTACT_PERMISSION_ALLOW, |
|
| 78 NULL); |
62 NULL); |
| 79 |
63 |
| 80 /* Now use g_object_get to read all of the properties. */ |
64 /* Now use g_object_get to read all of the properties. */ |
| 81 g_object_get(contact, |
65 g_object_get(contact, |
| 82 "id", &id, |
66 "id", &id, |
| 83 "account", &account1, |
67 "account", &account1, |
| 84 "username", &username, |
|
| 85 "display-name", &display_name, |
|
| 86 "alias", &alias, |
|
| 87 "avatar", &avatar1, |
|
| 88 "presence", &presence1, |
|
| 89 "tags", &tags, |
|
| 90 "person", &person1, |
|
| 91 "permission", &permission, |
|
| 92 NULL); |
68 NULL); |
| 93 |
69 |
| 94 /* Compare all the things. */ |
70 /* Compare all the things. */ |
| 95 g_assert_cmpstr(id, ==, "id1"); |
71 g_assert_cmpstr(id, ==, "id1"); |
| 96 g_assert_true(account1 == account); |
72 g_assert_true(account1 == account); |
| 97 g_assert_cmpstr(username, ==, "username"); |
|
| 98 g_assert_cmpstr(display_name, ==, "display-name"); |
|
| 99 g_assert_cmpstr(alias, ==, "alias"); |
|
| 100 g_assert_true(avatar1 == avatar); |
|
| 101 g_assert_nonnull(presence1); |
|
| 102 g_assert_nonnull(tags); |
|
| 103 g_assert_true(person1 == person); |
|
| 104 g_assert_true(permission == PURPLE_CONTACT_PERMISSION_ALLOW); |
|
| 105 |
73 |
| 106 /* Free/unref all the things. */ |
74 /* Free/unref all the things. */ |
| 107 g_clear_pointer(&id, g_free); |
75 g_clear_pointer(&id, g_free); |
| 108 g_clear_object(&account1); |
76 g_clear_object(&account1); |
| 109 g_clear_pointer(&username, g_free); |
|
| 110 g_clear_pointer(&display_name, g_free); |
|
| 111 g_clear_pointer(&alias, g_free); |
|
| 112 g_clear_object(&avatar1); |
|
| 113 g_clear_object(&presence1); |
|
| 114 g_clear_object(&tags); |
|
| 115 g_clear_object(&person); |
|
| 116 g_clear_object(&person1); |
|
| 117 |
|
| 118 g_clear_object(&avatar); |
|
| 119 g_clear_object(&contact); |
77 g_clear_object(&contact); |
| 120 g_clear_object(&account); |
78 g_clear_object(&account); |
| 121 } |
|
| 122 |
|
| 123 /****************************************************************************** |
|
| 124 * get_name_for_display tests |
|
| 125 *****************************************************************************/ |
|
| 126 static void |
|
| 127 test_purple_contact_get_name_for_display_person_with_alias(void) { |
|
| 128 PurpleAccount *account = NULL; |
|
| 129 PurpleContact *contact = NULL; |
|
| 130 PurplePerson *person = NULL; |
|
| 131 const char *alias = NULL; |
|
| 132 |
|
| 133 account = purple_account_new("test", "test"); |
|
| 134 |
|
| 135 person = purple_person_new(); |
|
| 136 purple_person_set_alias(person, "this is the alias"); |
|
| 137 |
|
| 138 contact = purple_contact_new(account, NULL); |
|
| 139 purple_contact_set_person(contact, person); |
|
| 140 |
|
| 141 alias = purple_contact_get_name_for_display(contact); |
|
| 142 g_assert_cmpstr(alias, ==, "this is the alias"); |
|
| 143 |
|
| 144 g_clear_object(&account); |
|
| 145 g_clear_object(&contact); |
|
| 146 g_clear_object(&person); |
|
| 147 } |
|
| 148 |
|
| 149 static void |
|
| 150 test_purple_contact_get_name_for_display_contact_with_alias(void) { |
|
| 151 PurpleAccount *account = NULL; |
|
| 152 PurpleContact *contact = NULL; |
|
| 153 PurplePerson *person = NULL; |
|
| 154 const char *alias = NULL; |
|
| 155 |
|
| 156 account = purple_account_new("test", "test"); |
|
| 157 person = purple_person_new(); |
|
| 158 |
|
| 159 contact = purple_contact_new(account, NULL); |
|
| 160 purple_contact_set_person(contact, person); |
|
| 161 |
|
| 162 purple_contact_set_alias(contact, "this is the alias"); |
|
| 163 |
|
| 164 alias = purple_contact_get_name_for_display(contact); |
|
| 165 g_assert_cmpstr(alias, ==, "this is the alias"); |
|
| 166 |
|
| 167 g_clear_object(&account); |
|
| 168 g_clear_object(&contact); |
|
| 169 g_clear_object(&person); |
|
| 170 } |
|
| 171 |
|
| 172 static void |
|
| 173 test_purple_contact_get_name_for_display_contact_with_display_name(void) { |
|
| 174 PurpleAccount *account = NULL; |
|
| 175 PurpleContact *contact = NULL; |
|
| 176 PurplePerson *person = NULL; |
|
| 177 const char *alias = NULL; |
|
| 178 |
|
| 179 account = purple_account_new("test", "test"); |
|
| 180 person = purple_person_new(); |
|
| 181 |
|
| 182 contact = purple_contact_new(account, NULL); |
|
| 183 purple_contact_set_person(contact, person); |
|
| 184 |
|
| 185 purple_contact_set_display_name(contact, "this is the display name"); |
|
| 186 |
|
| 187 alias = purple_contact_get_name_for_display(contact); |
|
| 188 g_assert_cmpstr(alias, ==, "this is the display name"); |
|
| 189 |
|
| 190 g_clear_object(&account); |
|
| 191 g_clear_object(&contact); |
|
| 192 g_clear_object(&person); |
|
| 193 } |
|
| 194 |
|
| 195 static void |
|
| 196 test_purple_contact_get_name_for_display_username_fallback(void) { |
|
| 197 PurpleAccount *account = NULL; |
|
| 198 PurpleContact *contact = NULL; |
|
| 199 PurplePerson *person = NULL; |
|
| 200 const char *alias = NULL; |
|
| 201 |
|
| 202 account = purple_account_new("test", "test"); |
|
| 203 person = purple_person_new(); |
|
| 204 |
|
| 205 contact = purple_contact_new(account, NULL); |
|
| 206 purple_contact_set_username(contact, "username"); |
|
| 207 purple_contact_set_person(contact, person); |
|
| 208 |
|
| 209 alias = purple_contact_get_name_for_display(contact); |
|
| 210 g_assert_cmpstr(alias, ==, "username"); |
|
| 211 |
|
| 212 g_clear_object(&account); |
|
| 213 g_clear_object(&contact); |
|
| 214 g_clear_object(&person); |
|
| 215 } |
|
| 216 |
|
| 217 static void |
|
| 218 test_purple_contact_get_name_for_display_id_fallback(void) { |
|
| 219 PurpleAccount *account = NULL; |
|
| 220 PurpleContact *contact = NULL; |
|
| 221 PurplePerson *person = NULL; |
|
| 222 const char *alias = NULL; |
|
| 223 |
|
| 224 account = purple_account_new("test", "test"); |
|
| 225 person = purple_person_new(); |
|
| 226 |
|
| 227 contact = purple_contact_new(account, "id"); |
|
| 228 purple_contact_set_person(contact, person); |
|
| 229 |
|
| 230 alias = purple_contact_get_name_for_display(contact); |
|
| 231 g_assert_cmpstr(alias, ==, "id"); |
|
| 232 |
|
| 233 g_clear_object(&account); |
|
| 234 g_clear_object(&contact); |
|
| 235 g_clear_object(&person); |
|
| 236 } |
|
| 237 |
|
| 238 /****************************************************************************** |
|
| 239 * purple_contact_compare tests |
|
| 240 *****************************************************************************/ |
|
| 241 static void |
|
| 242 test_purple_contact_compare_not_null__null(void) { |
|
| 243 PurpleAccount *account = NULL; |
|
| 244 PurpleContact *contact = NULL; |
|
| 245 |
|
| 246 account = purple_account_new("test", "test"); |
|
| 247 contact = purple_contact_new(account, NULL); |
|
| 248 |
|
| 249 g_assert_cmpint(purple_contact_compare(contact, NULL), <, 0); |
|
| 250 |
|
| 251 g_clear_object(&account); |
|
| 252 g_clear_object(&contact); |
|
| 253 } |
|
| 254 |
|
| 255 static void |
|
| 256 test_purple_contact_compare_null__not_null(void) { |
|
| 257 PurpleAccount *account = NULL; |
|
| 258 PurpleContact *contact = NULL; |
|
| 259 |
|
| 260 account = purple_account_new("test", "test"); |
|
| 261 contact = purple_contact_new(account, NULL); |
|
| 262 |
|
| 263 g_assert_cmpint(purple_contact_compare(NULL, contact), >, 0); |
|
| 264 |
|
| 265 g_clear_object(&account); |
|
| 266 g_clear_object(&contact); |
|
| 267 } |
|
| 268 |
|
| 269 static void |
|
| 270 test_purple_contact_compare_null__null(void) { |
|
| 271 g_assert_cmpint(purple_contact_compare(NULL, NULL), ==, 0); |
|
| 272 } |
|
| 273 |
|
| 274 static void |
|
| 275 test_purple_contact_compare_person__no_person(void) { |
|
| 276 PurpleAccount *account = NULL; |
|
| 277 PurpleContact *contact_a = NULL; |
|
| 278 PurpleContact *contact_b = NULL; |
|
| 279 PurplePerson *person = NULL; |
|
| 280 |
|
| 281 account = purple_account_new("test", "test"); |
|
| 282 |
|
| 283 contact_a = purple_contact_new(account, NULL); |
|
| 284 person = purple_person_new(); |
|
| 285 purple_contact_set_person(contact_a, person); |
|
| 286 |
|
| 287 contact_b = purple_contact_new(account, NULL); |
|
| 288 |
|
| 289 g_assert_cmpint(purple_contact_compare(contact_a, contact_b), <, 0); |
|
| 290 |
|
| 291 g_clear_object(&account); |
|
| 292 g_clear_object(&contact_a); |
|
| 293 g_clear_object(&contact_b); |
|
| 294 g_clear_object(&person); |
|
| 295 } |
|
| 296 |
|
| 297 static void |
|
| 298 test_purple_contact_compare_no_person__person(void) { |
|
| 299 PurpleAccount *account = NULL; |
|
| 300 PurpleContact *contact_a = NULL; |
|
| 301 PurpleContact *contact_b = NULL; |
|
| 302 PurplePerson *person = NULL; |
|
| 303 |
|
| 304 account = purple_account_new("test", "test"); |
|
| 305 |
|
| 306 contact_a = purple_contact_new(account, NULL); |
|
| 307 |
|
| 308 contact_b = purple_contact_new(account, NULL); |
|
| 309 person = purple_person_new(); |
|
| 310 purple_contact_set_person(contact_b, person); |
|
| 311 |
|
| 312 g_assert_cmpint(purple_contact_compare(contact_a, contact_b), >, 0); |
|
| 313 |
|
| 314 g_clear_object(&account); |
|
| 315 g_clear_object(&contact_a); |
|
| 316 g_clear_object(&contact_b); |
|
| 317 g_clear_object(&person); |
|
| 318 } |
|
| 319 |
|
| 320 static void |
|
| 321 test_purple_contact_compare_name__name(void) { |
|
| 322 PurpleAccount *account = NULL; |
|
| 323 PurpleContact *contact_a = NULL; |
|
| 324 PurpleContact *contact_b = NULL; |
|
| 325 |
|
| 326 account = purple_account_new("test", "test"); |
|
| 327 |
|
| 328 contact_a = purple_contact_new(account, NULL); |
|
| 329 purple_contact_set_username(contact_a, "aaa"); |
|
| 330 |
|
| 331 contact_b = purple_contact_new(account, NULL); |
|
| 332 purple_contact_set_username(contact_b, "zzz"); |
|
| 333 |
|
| 334 g_assert_cmpint(purple_contact_compare(contact_a, contact_b), <, 0); |
|
| 335 g_assert_cmpint(purple_contact_compare(contact_b, contact_a), >, 0); |
|
| 336 |
|
| 337 purple_contact_set_username(contact_b, "aaa"); |
|
| 338 g_assert_cmpint(purple_contact_compare(contact_b, contact_a), ==, 0); |
|
| 339 |
|
| 340 g_clear_object(&account); |
|
| 341 g_clear_object(&contact_a); |
|
| 342 g_clear_object(&contact_b); |
|
| 343 } |
79 } |
| 344 |
80 |
| 345 /****************************************************************************** |
81 /****************************************************************************** |
| 346 * Main |
82 * Main |
| 347 *****************************************************************************/ |
83 *****************************************************************************/ |