chiark / gitweb /
Switch to GPL v3
[disorder] / libtests / t-selection.c
1 /*
2  * This file is part of DisOrder.
3  * Copyright (C) 2005, 2007, 2008 Richard Kettlewell
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  * 
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  * 
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 #include "test.h"
19
20 static void test_selection(void) {
21   hash *h;
22
23   insist((h = selection_new()) != 0);
24   selection_set(h, "one", 1);
25   selection_set(h, "two", 1);
26   selection_set(h, "three", 0);
27   selection_set(h, "four", 1);
28   insist(selection_selected(h, "one") == 1);
29   insist(selection_selected(h, "two") == 1);
30   insist(selection_selected(h, "three") == 0);
31   insist(selection_selected(h, "four") == 1);
32   insist(selection_selected(h, "five") == 0);
33   insist(hash_count(h) == 3);
34   selection_flip(h, "one"); 
35   selection_flip(h, "three"); 
36   insist(selection_selected(h, "one") == 0);
37   insist(selection_selected(h, "three") == 1);
38   insist(hash_count(h) == 3);
39   selection_live(h, "one");
40   selection_live(h, "two");
41   selection_live(h, "three");
42   selection_cleanup(h);
43   insist(selection_selected(h, "one") == 0);
44   insist(selection_selected(h, "two") == 1);
45   insist(selection_selected(h, "three") == 1);
46   insist(selection_selected(h, "four") == 0);
47   insist(selection_selected(h, "five") == 0);
48   insist(hash_count(h) == 2);
49   selection_empty(h);
50   insist(selection_selected(h, "one") == 0);
51   insist(selection_selected(h, "two") == 0);
52   insist(selection_selected(h, "three") == 0);
53   insist(selection_selected(h, "four") == 0);
54   insist(selection_selected(h, "five") == 0);
55   insist(hash_count(h) == 0);
56 }
57
58 TEST(selection);
59
60 /*
61 Local Variables:
62 c-basic-offset:2
63 comment-column:40
64 fill-column:79
65 indent-tabs-mode:nil
66 End:
67 */