about summary refs log tree commit diff stats
path: root/linux/104new-segment.subx
blob: 5a79ff1928b5b2e042f243615e1732332faf061f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# Create a new segment (pool of memory for allocating chunks from) in the form
# of an *allocation descriptor* that can be passed to the memory allocator
# (defined in a later layer).
#
# Currently an allocation descriptor consists of just the bounds of the pool of
# available memory:
#
#   curr: address
#   end: address
#
# This isn't enough information to reclaim individual allocations. We can't
# support arbitrary reclamation yet.

== code
#   instruction                     effective address                                                   register    displacement    immediate
# . op          subop               mod             rm32          base        index         scale       r32
# . 1-3 bytes   3 bits              2 bits          3 bits        3 bits      3 bits        2 bits      2 bits      0/1/2/4 bytes   0/1/2/4 bytes

#? Entry:   # manual test
#?     # var ad/ecx: allocation-descriptor
#?     68/push  0/imm32/limit
#?     68/push  0/imm32/curr
#?     89/copy                         3/mod/direct    1/rm32/ecx    .           .             .           4/r32/esp   .               .                 # copy esp to ecx
#?     # new-segment(0x1000, ad)
#?     # . . push args
#?     51/push-ecx
#?     68/push  0x1000/imm32
#?     # . . call
#?     e8/call  new-segment/disp32
#?     # . . discard args
#?     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
#?     # var eax: (addr _) = ad->curr
#?     8b/copy                         0/mod/indirect  1/rm32/ecx    .           .             .           0/r32/eax   .               .                 # copy *ecx to eax
#?     # write to *eax to check that we have access to the newly-allocated segment
#?     c7          0/subop/copy        0/mod/direct    0/rm32/eax    .           .             .           .           .               0x34/imm32        # copy to *eax
#?     # syscall_exit(eax)
#?     89/copy                         3/mod/direct    3/rm32/ebx    .           .             .           0/r32/eax   .               .                 # copy eax to ebx
#?     e8/call  syscall_exit/disp32

new-segment:  # len: int, ad: (addr allocation-descriptor)
    # . prologue
    55/push-ebp
    89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
    # . save registers
    50/push-eax
    53/push-ebx
    # copy len to _mmap-new-segment->len
    8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           0/r32/eax   8/disp8         .                 # copy *(ebp+8) to eax
    89/copy                         0/mod/indirect  5/rm32/.disp32            .             .           0/r32/eax   $_mmap-new-segment:len/disp32     # copy eax to *$_mmap-new-segment:len
    # mmap(_mmap-new-segment)
    bb/copy-to-ebx  _mmap-new-segment/imm32
    e8/call  syscall_mmap/disp32
    # copy {eax, eax+len} to *ad
    # . ebx = ad
    8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           3/r32/ebx   0xc/disp8       .                 # copy *(ebp+12) to ebx
    # . ad->curr = eax
    89/copy                         0/mod/indirect  3/rm32/ebx    .           .             .           0/r32/eax   .               .                 # copy eax to *ebx
    # . ad->end = eax+len
    03/add                          1/mod/*+disp8   5/rm32/ebp    .           .             .           0/r32/eax   8/disp8         .                 # add *(ebp+8) to eax
    89/copy                         1/mod/*+disp8   3/rm32/ebx    .           .             .           0/r32/eax   4/disp8         .                 # copy eax to *(ebx+4)
$new-segment:end:
    # . restore registers
    5b/pop-to-ebx
    58/pop-to-eax
    # . epilogue
    89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
    5d/pop-to-ebp
    c3/return

== data

# various constants used here were found in the Linux sources (search for file mman-common.h)
_mmap-new-segment:  # mmap_arg_struct
    # addr
    0/imm32
$_mmap-new-segment:len:
    # len
    0/imm32
    # protection flags
    3/imm32  # PROT_READ | PROT_WRITE
    # sharing flags
    0x22/imm32  # MAP_PRIVATE | MAP_ANONYMOUS
    # fd
    -1/imm32  # since MAP_ANONYMOUS is specified
    # offset
    0/imm32  # since MAP_ANONYMOUS is specified

# . . vim:nowrap:textwidth=0
ded connection status tests for cmd_join' href='/danisanti/profani-tty/commit/tests/testsuite.c?id=f3fe1d34d2608bed06bdf0302656cde5b0107183'>f3fe1d34 ^
63b3299b ^
93397e45 ^
96e32fe1 ^
ab7bd6fe ^
b934ad54 ^
7f7973f9 ^

3dc5f60f ^
7f7973f9 ^






























3a403046 ^
d5a2e645 ^







f592f610 ^






ba892973 ^





6b9f404c ^
3a403046 ^








07308673 ^
b3dd7d84 ^
07308673 ^



































4bb38ac0 ^
e263e00a ^

4bb38ac0 ^









































8d77930e ^







24197370 ^
0b3a9f57 ^










0b3a9f57 ^







d0a0e5e7 ^
f7843def ^


9bd2315d ^
f7843def ^

9bd2315d ^
f7843def ^

9bd2315d ^
f7843def ^

833fd4d2 ^










































































7db1bcee ^
52f6ad6f ^






7db1bcee ^
8c01021a ^

52f6ad6f ^


d56f6dc3 ^
52f6ad6f ^

52f6ad6f ^

52f6ad6f ^


52f6ad6f ^



52f6ad6f ^



52f6ad6f ^



9b41c4ee ^
8adca66f ^
3b2446c4 ^
f6da9444 ^


de06c40d ^
de06c40d ^
c20e38a4 ^


76e7a834 ^


ba66d6b7 ^

f47bd58a ^




7a63cf2e ^



6d6bc67d ^
122fe09c ^

122fe09c ^

9537592b ^
976f3e30 ^
0331cbe2 ^
976f3e30 ^
d1575164 ^






80acfdae ^
5898da96 ^
















c7325de0 ^



79e9ab83 ^
6ef1174b ^
b231133f ^
79e9ab83 ^
6ef1174b ^
b231133f ^
79e9ab83 ^
6ef1174b ^
b231133f ^
79e9ab83 ^
6ef1174b ^
b231133f ^
79e9ab83 ^
6ef1174b ^
b231133f ^
79e9ab83 ^
6ef1174b ^
b231133f ^
2af418fd ^
6ef1174b ^
b231133f ^
2af418fd ^



6ef1174b ^
b231133f ^
fa23084c ^
69f2f4a1 ^
6ef1174b ^
b231133f ^
69f2f4a1 ^
6ef1174b ^
b231133f ^
2af418fd ^
6ef1174b ^
b231133f ^
69f2f4a1 ^
a7a28506 ^
6ef1174b ^
b231133f ^
a7a28506 ^
6ef1174b ^
b231133f ^
a7a28506 ^
6ef1174b ^
b231133f ^
a7a28506 ^
6ef1174b ^
b231133f ^
a7a28506 ^
6ef1174b ^
b231133f ^
788fc48b ^
6ef1174b ^
b231133f ^
0338d136 ^

6ef1174b ^
571665ee ^
0338d136 ^
6ef1174b ^
571665ee ^
0338d136 ^

2c15aba9 ^
95ad5643 ^
f180925c ^
7a104431 ^
8dbe300d ^




6ef1174b ^
b231133f ^
788fc48b ^
6ef1174b ^
b231133f ^
8dbe300d ^
6ef1174b ^
b231133f ^
8dbe300d ^
6ef1174b ^
b231133f ^
8dbe300d ^
6ef1174b ^
b231133f ^
4906f3f6 ^
d25d6b45 ^
16aecaf0 ^
d25d6b45 ^

23842e52 ^
d25d6b45 ^
4906f3f6 ^
614ae232 ^




652e99fd ^
3d7d070b ^
a564b024 ^
af51fa3c ^

38d8d8d9 ^
af51fa3c ^
a8ecbccc ^
9d957e5f ^
62953362 ^


c6220e01 ^



6ef1174b ^
c6220e01 ^

6ef1174b ^
c6220e01 ^

6ef1174b ^
c6220e01 ^

6ef1174b ^
c6220e01 ^

6ef1174b ^
c6220e01 ^
7e956fb3 ^


6ef1174b ^
7e956fb3 ^

6ef1174b ^
7e956fb3 ^
60e03094 ^
e048b319 ^
4eac5c0d ^
d1d80fc2 ^




6e58d954 ^




18e0884f ^
82ad0cd3 ^
4afec6ab ^
a25714b6 ^

b4b46399 ^
037ca818 ^
1f78d5b5 ^


d25245a2 ^
da058359 ^
833fd4d2 ^


62953362 ^


419f37fe ^
f3fe1d34 ^



2d54c565 ^
a94814f0 ^
baf46c6a ^
dd1ee18c ^
bafc0f25 ^
15fce2cf ^
a871ad80 ^
93397e45 ^




a578419d ^

bcafba2d ^

11c04d9f ^






59296054 ^
96e32fe1 ^
7113b979 ^
b934ad54 ^










d1ace328 ^


ea24a7c4 ^

aa85e29a ^





ab7bd6fe ^

652e99fd ^

90d2cbff ^
a05a65fe ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
                   


                   


                   
                     
 
                   
                         
 
                    
                              
                              
                        
                         
                             
                             
                           
                         
                              
                         

                         
                        
                             
                             
                               
                           
                              
                          
                     
                            
                         
                                
                      

                                  
                                  






























                                                    
                                                   







                                                                          






                                     





                                               
 








                                                       
                                        
 



































                                                                       
                                                   

                                                           









































                                                                          







                                                                
                                                                   










                                                     







                                                                     
 


                                                                                
                                                                            

                                 
                                                                                                     

                                 
                                                      

                                 










































































                                                                                        
 






                                                              
 

                                                                          


                                                                              
                                                              

                                                           

                                                              


                                                                              



                                                                               



                                                                     



                                                                           
                                                      
                                                          
                                                          


                                                                    
                                                
                                                  


                                                                   


                                                                            

                                                                                  




                                                                   



                                                                          
                                                                                                  

                                                              

                                                                             
 
                                                            
                                                   
 






                                                        
                                            
















                                                                     



                                                                     
                                                               
                             
                               
                                                                  
                             
                               
                                                                
                             
                               
                                                            
                             
                               
                                                               
                             
                               
                                                             
                             
                               
                                                           
                             
                               



                                                              
                             
                               
 
                                                                  
                             
                               
                                                               
                             
                               
                                                              
                             
                               
 
                                                                                   
                             
                               
                                                                               
                             
                               
                                                                            
                             
                               
                                                                                
                             
                               
                                                                                  
                             
                               
                                                                         
                             
                               

                                                                            
                             
                               
                                                                                                  
                             
                               

                                                                   
                                                             
                                                       
                                                        
 




                                                             
                             
                               
                                                                         
                             
                               
                                                                
                             
                               
                                                                              
                             
                               
                                                                  
                             
                               
 
                                                                                        
                                                                                          

                                                                                            
                                                                                               
                                                                                   
 




                                                                 
                                                         
                                                     
                                                                   

                                                                
                                                                    
                                                                         
                                                        
                                                                      


                                                    



                                                                   
                             

                                                                  
                             

                                                                
                             

                                                                                  
                             

                                                                                      
                             
                               


                                                                             
                             

                                                                               
                             
                               
                                                       
                                                                
                                                                   




                                                                




                                                                 
                                                          
                                                     
                                                                 

                                                                 
                                                                          
                                                     


                                                               
                                                                    
                                                           


                                                                                            


                                                              
 



                                                             
                                                     
                                                                      
                                                                              
                                               
                                                                
                                                        
 




                                                               

                                                            

                                                                 






                                                                                  
 
                                                               
                                                             










                                                                     


                                              

                                                               





                                                                          

                                        

      
                                
 
#include <stdarg.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <sys/stat.h>

#include "config.h"
#include "chat_session.h"

#include "helpers.h"
#include "test_autocomplete.h"
#include "test_chat_session.h"
#include "test_common.h"
#include "test_contact.h"
#include "test_cmd_connect.h"
#include "test_cmd_account.h"
#include "test_cmd_rooms.h"
#include "test_cmd_sub.h"
#include "test_cmd_statuses.h"
#include "test_cmd_otr.h"
#include "test_history.h"
#include "test_jid.h"
#include "test_parser.h"
#include "test_roster_list.h"
#include "test_preferences.h"
#include "test_server_events.h"
#include "test_cmd_alias.h"
#include "test_cmd_bookmark.h"
#include "test_cmd_join.h"
#include "test_muc.h"
#include "test_cmd_roster.h"
#include "test_cmd_win.h"
#include "test_cmd_disconnect.h"
#include "test_form.h"

int main(int argc, char* argv[]) {
    const UnitTest all_tests[] = {
        unit_test(replace_one_substr),
        unit_test(replace_one_substr_beginning),
        unit_test(replace_one_substr_end),
        unit_test(replace_two_substr),
        unit_test(replace_char),
        unit_test(replace_when_none),
        unit_test(replace_when_match),
        unit_test(replace_when_string_empty),
        unit_test(replace_when_string_null),
        unit_test(replace_when_sub_empty),
        unit_test(replace_when_sub_null),
        unit_test(replace_when_new_empty),
        unit_test(replace_when_new_null),
        unit_test(compare_win_nums_less),
        unit_test(compare_win_nums_equal),
        unit_test(compare_win_nums_greater),
        unit_test(compare_0s_equal),
        unit_test(compare_0_greater_than_1),
        unit_test(compare_1_less_than_0),
        unit_test(compare_0_less_than_11),
        unit_test(compare_11_greater_than_0),
        unit_test(compare_0_greater_than_9),
        unit_test(compare_9_less_than_0),
        unit_test(next_available_when_only_console),
        unit_test(next_available_3_at_end),
        unit_test(next_available_9_at_end),
        unit_test(next_available_0_at_end),
        unit_test(next_available_2_in_first_gap),
        unit_test(next_available_9_in_first_gap),
        unit_test(next_available_0_in_first_gap),
        unit_test(next_available_11_in_first_gap),
        unit_test(next_available_24_first_big_gap),
        unit_test(test_online_is_valid_resource_presence_string),
        unit_test(test_chat_is_valid_resource_presence_string),
        unit_test(test_away_is_valid_resource_presence_string),
        unit_test(test_xa_is_valid_resource_presence_string),
        unit_test(test_dnd_is_valid_resource_presence_string),
        unit_test(test_available_is_not_valid_resource_presence_string),
        unit_test(test_unavailable_is_not_valid_resource_presence_string),
        unit_test(test_blah_is_not_valid_resource_presence_string),
        unit_test(test_p_sha1_hash1),
        unit_test(test_p_sha1_hash2),
        unit_test(test_p_sha1_hash3),
        unit_test(test_p_sha1_hash4),
        unit_test(test_p_sha1_hash5),
        unit_test(test_p_sha1_hash6),
        unit_test(test_p_sha1_hash7),
        unit_test(utf8_display_len_null_str),
        unit_test(utf8_display_len_1_non_wide),
        unit_test(utf8_display_len_1_wide),
        unit_test(utf8_display_len_non_wide),
        unit_test(utf8_display_len_wide),
        unit_test(utf8_display_len_all_wide),

        unit_test(clear_empty),
        unit_test(reset_after_create),
        unit_test(find_after_create),
        unit_test(get_after_create_returns_null),
        unit_test(add_one_and_complete),
        unit_test(add_two_and_complete_returns_first),
        unit_test(add_two_and_complete_returns_second),
        unit_test(add_two_adds_two),
        unit_test(add_two_same_adds_one),
        unit_test(add_two_same_updates),

        unit_test(previous_on_empty_returns_null),
        unit_test(next_on_empty_returns_null),
        unit_test(previous_once_returns_last),
        unit_test(previous_twice_when_one_returns_first),
        unit_test(previous_always_stops_at_first),
        unit_test(previous_goes_to_correct_element),
        unit_test(prev_then_next_returns_empty),
        unit_test(prev_with_val_then_next_returns_val),
        unit_test(prev_with_val_then_next_twice_returns_null),
        unit_test(navigate_then_append_new),
        unit_test(edit_item_mid_history),
        unit_test(edit_previous_and_append),
        unit_test(start_session_add_new_submit_previous),

        unit_test(create_jid_from_null_returns_null),
        unit_test(create_jid_from_empty_string_returns_null),
        unit_test(create_jid_from_full_returns_full),
        unit_test(create_jid_from_full_returns_bare),
        unit_test(create_jid_from_full_returns_resourcepart),
        unit_test(create_jid_from_full_returns_localpart),
        unit_test(create_jid_from_full_returns_domainpart),
        unit_test(create_jid_from_full_nolocal_returns_full),
        unit_test(create_jid_from_full_nolocal_returns_bare),
        unit_test(create_jid_from_full_nolocal_returns_resourcepart),
        unit_test(create_jid_from_full_nolocal_returns_domainpart),
        unit_test(create_jid_from_full_nolocal_returns_null_localpart),
        unit_test(create_jid_from_bare_returns_null_full),
        unit_test(create_jid_from_bare_returns_null_resource),
        unit_test(create_jid_from_bare_returns_bare),
        unit_test(create_jid_from_bare_returns_localpart),
        unit_test(create_jid_from_bare_returns_domainpart),
        unit_test(create_room_jid_returns_room),
        unit_test(create_room_jid_returns_nick),
        unit_test(create_with_slash_in_resource),
        unit_test(create_with_at_in_resource),
        unit_test(create_with_at_and_slash_in_resource),
        unit_test(create_full_with_trailing_slash),
        unit_test(returns_fulljid_when_exists),
        unit_test(returns_barejid_when_fulljid_not_exists),

        unit_test(parse_null_returns_null),
        unit_test(parse_empty_returns_null),
        unit_test(parse_space_returns_null),
        unit_test(parse_cmd_no_args_returns_null),
        unit_test(parse_cmd_with_space_returns_null),
        unit_test(parse_cmd_with_too_few_returns_null),
        unit_test(parse_cmd_with_too_many_returns_null),
        unit_test(parse_cmd_one_arg),
        unit_test(parse_cmd_two_args),
        unit_test(parse_cmd_three_args),
        unit_test(parse_cmd_three_args_with_spaces),
        unit_test(parse_cmd_with_freetext),
        unit_test(parse_cmd_one_arg_with_freetext),
        unit_test(parse_cmd_two_args_with_freetext),
        unit_test(parse_cmd_min_zero),
        unit_test(parse_cmd_min_zero_with_freetext),
        unit_test(parse_cmd_with_quoted),
        unit_test(parse_cmd_with_quoted_and_space),
        unit_test(parse_cmd_with_quoted_and_many_spaces),
        unit_test(parse_cmd_with_many_quoted_and_many_spaces),
        unit_test(parse_cmd_freetext_with_quoted),
        unit_test(parse_cmd_freetext_with_quoted_and_space),
        unit_test(parse_cmd_freetext_with_quoted_and_many_spaces),
        unit_test(parse_cmd_freetext_with_many_quoted_and_many_spaces),
        unit_test(parse_cmd_with_quoted_freetext),
        unit_test(parse_cmd_with_third_arg_quoted_0_min_3_max),
        unit_test(parse_cmd_with_second_arg_quoted_0_min_3_max),
        unit_test(parse_cmd_with_second_and_third_arg_quoted_0_min_3_max),
        unit_test(count_one_token),
        unit_test(count_one_token_quoted_no_whitespace),
        unit_test(count_one_token_quoted_with_whitespace),
        unit_test(count_two_tokens),
        unit_test(count_two_tokens_first_quoted),
        unit_test(count_two_tokens_second_quoted),
        unit_test(count_two_tokens_both_quoted),
        unit_test(get_first_of_one),
        unit_test(get_first_of_two),
        unit_test(get_first_two_of_three),
        unit_test(get_first_two_of_three_first_quoted),
        unit_test(get_first_two_of_three_second_quoted),
        unit_test(get_first_two_of_three_first_and_second_quoted),
        unit_test(parse_options_when_none_returns_empty_hasmap),
        unit_test(parse_options_when_opt1_no_val_sets_error),
        unit_test(parse_options_when_one_returns_map),
        unit_test(parse_options_when_opt2_no_val_sets_error),
        unit_test(parse_options_when_two_returns_map),
        unit_test(parse_options_when_opt3_no_val_sets_error),
        unit_test(parse_options_when_three_returns_map),
        unit_test(parse_options_when_unknown_opt_sets_error),
        unit_test(parse_options_with_duplicated_option_sets_error),

        unit_test(empty_list_when_none_added),
        unit_test(contains_one_element),
        unit_test(first_element_correct),
        unit_test(contains_two_elements),
        unit_test(first_and_second_elements_correct),
        unit_test(contains_three_elements),
        unit_test(first_three_elements_correct),
        unit_test(add_twice_at_beginning_adds_once),
        unit_test(add_twice_in_middle_adds_once),
        unit_test(add_twice_at_end_adds_once),
        unit_test(find_first_exists),
        unit_test(find_second_exists),
        unit_test(find_third_exists),
        unit_test(find_returns_null),
        unit_test(find_on_empty_returns_null),
        unit_test(find_twice_returns_second_when_two_match),
        unit_test(find_five_times_finds_fifth),
        unit_test(find_twice_returns_first_when_two_match_and_reset),

        unit_test_setup_teardown(returns_false_when_chat_session_does_not_exist,
            init_chat_sessions,
            close_chat_sessions),
        unit_test_setup_teardown(creates_chat_session_on_recipient_activity,
            init_chat_sessions,
            close_chat_sessions),
        unit_test_setup_teardown(replaces_chat_session_on_recipient_activity_with_different_resource,
            init_chat_sessions,
            close_chat_sessions),
        unit_test_setup_teardown(removes_chat_session,
            init_chat_sessions,
            close_chat_sessions),
        unit_test_setup_teardown(cmd_connect_shows_message_when_disconnecting,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_connect_shows_message_when_connecting,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_connect_shows_message_when_connected,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_connect_shows_message_when_undefined,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_connect_when_no_account,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_connect_fail_message,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_connect_lowercases_argument,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_connect_asks_password_when_not_in_account,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_connect_shows_message_when_connecting_with_account,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_connect_connects_with_account,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_connect_shows_usage_when_no_server_value,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_connect_shows_usage_when_server_no_port_value,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_connect_shows_usage_when_no_port_value,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_connect_shows_usage_when_port_no_server_value,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_connect_shows_message_when_port_0,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_connect_shows_message_when_port_minus1,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_connect_shows_message_when_port_65536,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_connect_shows_message_when_port_contains_chars,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_connect_with_server_when_provided,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_connect_with_port_when_provided,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_connect_with_server_and_port_when_provided,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_connect_shows_usage_when_server_provided_twice,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_connect_shows_usage_when_port_provided_twice,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_connect_shows_usage_when_invalid_first_property,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_connect_shows_usage_when_invalid_second_property,
            load_preferences,
            close_preferences),

        unit_test(cmd_rooms_shows_message_when_disconnected),
        unit_test(cmd_rooms_shows_message_when_disconnecting),
        unit_test(cmd_rooms_shows_message_when_connecting),
        unit_test(cmd_rooms_shows_message_when_started),
        unit_test(cmd_rooms_shows_message_when_undefined),
        unit_test(cmd_rooms_uses_account_default_when_no_arg),
        unit_test(cmd_rooms_arg_used_when_passed),

        unit_test(cmd_account_shows_usage_when_not_connected_and_no_args),
        unit_test(cmd_account_shows_account_when_connected_and_no_args),
        unit_test(cmd_account_list_shows_accounts),
        unit_test(cmd_account_show_shows_usage_when_no_arg),
        unit_test(cmd_account_show_shows_message_when_account_does_not_exist),
        unit_test(cmd_account_show_shows_account_when_exists),
        unit_test(cmd_account_add_shows_usage_when_no_arg),
        unit_test(cmd_account_add_adds_account),
        unit_test(cmd_account_enable_shows_usage_when_no_arg),
        unit_test(cmd_account_enable_enables_account),
        unit_test(cmd_account_enable_shows_message_when_account_doesnt_exist),
        unit_test(cmd_account_disable_shows_usage_when_no_arg),
        unit_test(cmd_account_disable_disables_account),
        unit_test(cmd_account_disable_shows_message_when_account_doesnt_exist),
        unit_test(cmd_account_rename_shows_usage_when_no_args),
        unit_test(cmd_account_rename_shows_usage_when_one_arg),
        unit_test(cmd_account_rename_renames_account),
        unit_test(cmd_account_rename_shows_message_when_not_renamed),
        unit_test(cmd_account_set_shows_usage_when_no_args),
        unit_test(cmd_account_set_shows_usage_when_one_arg),
        unit_test(cmd_account_set_shows_usage_when_two_args),
        unit_test(cmd_account_set_shows_message_when_account_doesnt_exist),
        unit_test(cmd_account_set_jid_shows_message_for_malformed_jid),
        unit_test(cmd_account_set_jid_sets_barejid),
        unit_test(cmd_account_set_jid_sets_resource),
        unit_test(cmd_account_set_server_sets_server),
        unit_test(cmd_account_set_resource_sets_resource),
        unit_test(cmd_account_set_password_sets_password),
        unit_test(cmd_account_set_eval_password_sets_eval_password),
        unit_test(cmd_account_set_password_when_eval_password_set),
        unit_test(cmd_account_set_eval_password_when_password_set),
        unit_test(cmd_account_set_muc_sets_muc),
        unit_test(cmd_account_set_nick_sets_nick),
        unit_test(cmd_account_show_message_for_missing_otr_policy),
        unit_test(cmd_account_show_message_for_invalid_otr_policy),
        unit_test(cmd_account_set_otr_sets_otr),
        unit_test(cmd_account_set_status_shows_message_when_invalid_status),
        unit_test(cmd_account_set_status_sets_status_when_valid),
        unit_test(cmd_account_set_status_sets_status_when_last),
        unit_test(cmd_account_set_invalid_presence_string_priority_shows_message),
        unit_test(cmd_account_set_last_priority_shows_message),
        unit_test(cmd_account_set_online_priority_sets_preference),
        unit_test(cmd_account_set_chat_priority_sets_preference),
        unit_test(cmd_account_set_away_priority_sets_preference),
        unit_test(cmd_account_set_xa_priority_sets_preference),
        unit_test(cmd_account_set_dnd_priority_sets_preference),
        unit_test(cmd_account_set_priority_too_low_shows_message),
        unit_test(cmd_account_set_priority_too_high_shows_message),
        unit_test(cmd_account_set_priority_when_not_number_shows_message),
        unit_test(cmd_account_set_priority_when_empty_shows_message),
        unit_test(cmd_account_set_priority_updates_presence_when_account_connected_with_presence),
        unit_test(cmd_account_clear_shows_usage_when_no_args),
        unit_test(cmd_account_clear_shows_usage_when_one_arg),
        unit_test(cmd_account_clear_shows_message_when_account_doesnt_exist),
        unit_test(cmd_account_clear_shows_message_when_invalid_property),

        unit_test(cmd_sub_shows_message_when_not_connected),
        unit_test(cmd_sub_shows_usage_when_no_arg),

        unit_test(contact_in_group),
        unit_test(contact_not_in_group),
        unit_test(contact_name_when_name_exists),
        unit_test(contact_jid_when_name_not_exists),
        unit_test(contact_string_when_name_exists),
        unit_test(contact_string_when_name_not_exists),
        unit_test(contact_string_when_default_resource),
        unit_test(contact_presence_offline),
        unit_test(contact_presence_uses_highest_priority),
        unit_test(contact_presence_chat_when_same_prioroty),
        unit_test(contact_presence_online_when_same_prioroty),
        unit_test(contact_presence_away_when_same_prioroty),
        unit_test(contact_presence_xa_when_same_prioroty),
        unit_test(contact_presence_dnd),
        unit_test(contact_subscribed_when_to),
        unit_test(contact_subscribed_when_both),
        unit_test(contact_not_subscribed_when_from),
        unit_test(contact_not_subscribed_when_no_subscription_value),
        unit_test(contact_not_available),
        unit_test(contact_not_available_when_highest_priority_away),
        unit_test(contact_not_available_when_highest_priority_xa),
        unit_test(contact_not_available_when_highest_priority_dnd),
        unit_test(contact_available_when_highest_priority_online),
        unit_test(contact_available_when_highest_priority_chat),

        unit_test(cmd_statuses_shows_usage_when_bad_subcmd),
        unit_test(cmd_statuses_shows_usage_when_bad_console_setting),
        unit_test(cmd_statuses_shows_usage_when_bad_chat_setting),
        unit_test(cmd_statuses_shows_usage_when_bad_muc_setting),
        unit_test_setup_teardown(cmd_statuses_console_sets_all,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_statuses_console_sets_online,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_statuses_console_sets_none,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_statuses_chat_sets_all,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_statuses_chat_sets_online,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_statuses_chat_sets_none,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_statuses_muc_sets_all,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_statuses_muc_sets_online,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_statuses_muc_sets_none,
            load_preferences,
            close_preferences),

        unit_test_setup_teardown(statuses_console_defaults_to_all,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(statuses_chat_defaults_to_all,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(statuses_muc_defaults_to_all,
            load_preferences,
            close_preferences),

        unit_test_setup_teardown(console_doesnt_show_online_presence_when_set_none,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(console_shows_online_presence_when_set_online,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(console_shows_online_presence_when_set_all,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(console_doesnt_show_dnd_presence_when_set_none,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(console_doesnt_show_dnd_presence_when_set_online,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(console_shows_dnd_presence_when_set_all,
            load_preferences,
            close_preferences),
        unit_test(handle_message_error_when_no_recipient),
        unit_test_setup_teardown(handle_message_error_when_recipient_cancel,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(handle_message_error_when_recipient_cancel_disables_chat_session,
            load_preferences,
            close_preferences),
        unit_test(handle_message_error_when_recipient_and_no_type),
        unit_test(handle_presence_error_when_no_recipient),
        unit_test(handle_presence_error_when_from_recipient),
        unit_test(handle_offline_removes_chat_session),
        unit_test(lost_connection_clears_chat_sessions),

        unit_test(cmd_alias_add_shows_usage_when_no_args),
        unit_test(cmd_alias_add_shows_usage_when_no_value),
        unit_test(cmd_alias_remove_shows_usage_when_no_args),
        unit_test(cmd_alias_show_usage_when_invalid_subcmd),
        unit_test_setup_teardown(cmd_alias_add_adds_alias,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_alias_add_shows_message_when_exists,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_alias_remove_removes_alias,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_alias_remove_shows_message_when_no_alias,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_alias_list_shows_all_aliases,
            load_preferences,
            close_preferences),

        unit_test_setup_teardown(test_muc_invites_add, muc_before_test, muc_after_test),
        unit_test_setup_teardown(test_muc_remove_invite, muc_before_test, muc_after_test),
        unit_test_setup_teardown(test_muc_invites_count_0, muc_before_test, muc_after_test),
        unit_test_setup_teardown(test_muc_invites_count_5, muc_before_test, muc_after_test),
        unit_test_setup_teardown(test_muc_room_is_not_active, muc_before_test, muc_after_test),
        unit_test_setup_teardown(test_muc_active, muc_before_test, muc_after_test),

        unit_test(cmd_bookmark_shows_message_when_disconnected),
        unit_test(cmd_bookmark_shows_message_when_disconnecting),
        unit_test(cmd_bookmark_shows_message_when_connecting),
        unit_test(cmd_bookmark_shows_message_when_started),
        unit_test(cmd_bookmark_shows_message_when_undefined),
        unit_test(cmd_bookmark_shows_usage_when_no_args),
        unit_test(cmd_bookmark_list_shows_bookmarks),
        unit_test(cmd_bookmark_add_shows_message_when_invalid_jid),
        unit_test(cmd_bookmark_add_adds_bookmark_with_jid),
        unit_test(cmd_bookmark_add_adds_bookmark_with_jid_nick),
        unit_test(cmd_bookmark_add_adds_bookmark_with_jid_autojoin),
        unit_test(cmd_bookmark_add_adds_bookmark_with_jid_nick_autojoin),
        unit_test(cmd_bookmark_remove_removes_bookmark),
        unit_test(cmd_bookmark_remove_shows_message_when_no_bookmark),

#ifdef HAVE_LIBOTR
        unit_test(cmd_otr_shows_usage_when_no_args),
        unit_test(cmd_otr_shows_usage_when_invalid_subcommand),
        unit_test(cmd_otr_log_shows_usage_when_no_args),
        unit_test(cmd_otr_log_shows_usage_when_invalid_subcommand),
        unit_test_setup_teardown(cmd_otr_log_on_enables_logging,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_otr_log_off_disables_logging,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_otr_redact_redacts_logging,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_otr_log_on_shows_warning_when_chlog_disabled,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_otr_log_redact_shows_warning_when_chlog_disabled,
            load_preferences,
            close_preferences),
        unit_test(cmd_otr_warn_shows_usage_when_no_args),
        unit_test(cmd_otr_warn_shows_usage_when_invalid_arg),
        unit_test_setup_teardown(cmd_otr_warn_on_enables_unencrypted_warning,
            load_preferences,
            close_preferences),
        unit_test_setup_teardown(cmd_otr_warn_off_disables_unencrypted_warning,
            load_preferences,
            close_preferences),
        unit_test(cmd_otr_libver_shows_libotr_version),
        unit_test(cmd_otr_gen_shows_message_when_not_connected),
        unit_test(cmd_otr_gen_generates_key_for_connected_account),
        unit_test(cmd_otr_gen_shows_message_when_disconnected),
        unit_test(cmd_otr_gen_shows_message_when_undefined),
        unit_test(cmd_otr_gen_shows_message_when_started),
        unit_test(cmd_otr_gen_shows_message_when_connecting),
        unit_test(cmd_otr_gen_shows_message_when_disconnecting),
        unit_test(cmd_otr_myfp_shows_message_when_disconnected),
        unit_test(cmd_otr_myfp_shows_message_when_undefined),
        unit_test(cmd_otr_myfp_shows_message_when_started),
        unit_test(cmd_otr_myfp_shows_message_when_connecting),
        unit_test(cmd_otr_myfp_shows_message_when_disconnecting),
        unit_test(cmd_otr_myfp_shows_message_when_no_key),
        unit_test(cmd_otr_myfp_shows_my_fingerprint),
        unit_test(cmd_otr_theirfp_shows_message_when_in_console),
        unit_test(cmd_otr_theirfp_shows_message_when_in_muc),
        unit_test(cmd_otr_theirfp_shows_message_when_in_private),
        unit_test(cmd_otr_theirfp_shows_message_when_non_otr_chat_window),
        unit_test(cmd_otr_theirfp_shows_fingerprint),
        unit_test(cmd_otr_start_shows_message_when_in_console),
        unit_test(cmd_otr_start_shows_message_when_in_muc),
        unit_test(cmd_otr_start_shows_message_when_in_private),
        unit_test(cmd_otr_start_shows_message_when_already_started),
        unit_test(cmd_otr_start_shows_message_when_no_key),
        unit_test_setup_teardown(cmd_otr_start_sends_otr_query_message_to_current_recipeint,
            load_preferences,
            close_preferences),
#else
        unit_test(cmd_otr_shows_message_when_otr_unsupported),
#endif

        unit_test(cmd_join_shows_message_when_disconnecting),
        unit_test(cmd_join_shows_message_when_connecting),
        unit_test(cmd_join_shows_message_when_disconnected),
        unit_test(cmd_join_shows_message_when_undefined),
        unit_test(cmd_join_shows_usage_when_no_args),
        unit_test(cmd_join_shows_error_message_when_invalid_room_jid),
        unit_test(cmd_join_uses_account_mucservice_when_no_service_specified),
        unit_test(cmd_join_uses_supplied_nick),
        unit_test(cmd_join_uses_account_nick_when_not_supplied),
        unit_test(cmd_join_uses_password_when_supplied),

        unit_test(cmd_roster_shows_message_when_disconnecting),
        unit_test(cmd_roster_shows_message_when_connecting),
        unit_test(cmd_roster_shows_message_when_disconnected),
        unit_test(cmd_roster_shows_message_when_undefined),
        unit_test(cmd_roster_shows_roster_when_no_args),
        unit_test(cmd_roster_add_shows_message_when_no_jid),
        unit_test(cmd_roster_add_sends_roster_add_request),
        unit_test(cmd_roster_remove_shows_message_when_no_jid),
        unit_test(cmd_roster_remove_sends_roster_remove_request),
        unit_test(cmd_roster_nick_shows_message_when_no_jid),
        unit_test(cmd_roster_nick_shows_message_when_no_nick),
        unit_test(cmd_roster_nick_shows_message_when_no_contact_exists),
        unit_test(cmd_roster_nick_sends_name_change_request),
        unit_test(cmd_roster_clearnick_shows_message_when_no_jid),
        unit_test(cmd_roster_clearnick_shows_message_when_no_contact_exists),
        unit_test(cmd_roster_clearnick_sends_name_change_request_with_empty_nick),

        unit_test(cmd_win_shows_message_when_win_doesnt_exist),
        unit_test(cmd_win_switches_to_given_win_when_exists),

        unit_test(get_form_type_field_returns_null_no_fields),
        unit_test(get_form_type_field_returns_null_when_not_present),
        unit_test(get_form_type_field_returns_value_when_present),
        unit_test(get_field_type_returns_unknown_when_no_fields),
        unit_test(get_field_type_returns_correct_type),
        unit_test(set_value_adds_when_none),
        unit_test(set_value_updates_when_one),
        unit_test(add_unique_value_adds_when_none),
        unit_test(add_unique_value_does_nothing_when_exists),
        unit_test(add_unique_value_adds_when_doesnt_exist),
        unit_test(add_value_adds_when_none),
        unit_test(add_value_adds_when_some),
        unit_test(add_value_adds_when_exists),
        unit_test(remove_value_does_nothing_when_none),
        unit_test(remove_value_does_nothing_when_doesnt_exist),
        unit_test(remove_value_removes_when_one),
        unit_test(remove_value_removes_when_many),
        unit_test(remove_text_multi_value_does_nothing_when_none),
        unit_test(remove_text_multi_value_does_nothing_when_doesnt_exist),
        unit_test(remove_text_multi_value_removes_when_one),
        unit_test(remove_text_multi_value_removes_when_many),

        unit_test(clears_chat_sessions),
    };

    return run_tests(all_tests);
}