1 /* testreadonlybidirlist.vala
3 * Copyright (C) 2011 Maciej Piechotka
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library 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 GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * Maciej Piechotka <uzytkownik2@gmail.com>
25 public class ReadOnlyBidirListTests : ReadOnlyListTests {
27 public ReadOnlyBidirListTests () {
28 base.with_name ("ReadOnlyBidirList");
29 add_test ("[ReadOnlyBidirList] immutable iterator", test_immutable_iterator);
32 protected override Collection<string> get_ro_view (Collection<string> collection) {
33 return ((Gee.BidirList) collection).read_only_view;
36 public new void test_immutable_iterator () {
37 var test_list = test_collection as Gee.BidirList<string>;
38 var ro_list = ro_collection as Gee.BidirList<string>;
40 assert (test_list.add ("one"));
41 assert (test_list.add ("two"));
43 assert (ro_list.size == 2);
44 assert (ro_list.get (0) == "one");
45 assert (ro_list.get (1) == "two");
47 Gee.BidirListIterator<string> iterator = ro_list.bidir_list_iterator ();
49 assert (iterator.has_next ());
50 assert (iterator.next ());
51 assert (iterator.get () == "one");
52 assert (iterator.index () == 0);
54 assert (iterator.has_next ());
55 assert (iterator.next ());
56 assert (iterator.get () == "two");
57 assert (iterator.index () == 1);
59 assert (! iterator.has_next ());
60 assert (! iterator.next ());
62 assert (iterator.has_previous ());
63 assert (iterator.previous ());
64 assert (iterator.get () == "one");
65 assert (iterator.index () == 0);
67 assert (iterator.last ());
68 assert (iterator.get () == "two");
69 assert (iterator.index () == 1);
71 assert (iterator.first ());
72 assert (iterator.get () == "one");
73 assert (iterator.index () == 0);
75 if (Test.trap_fork (0, TestTrapFlags.SILENCE_STDOUT |
76 TestTrapFlags.SILENCE_STDERR)) {
80 Test.trap_assert_failed ();
81 assert (ro_list.size == 2);
82 assert (ro_list.get (0) == "one");
83 assert (ro_list.get (1) == "two");
84 assert (iterator.index () == 0);
86 if (Test.trap_fork (0, TestTrapFlags.SILENCE_STDOUT |
87 TestTrapFlags.SILENCE_STDERR)) {
88 iterator.set ("three");
91 Test.trap_assert_failed ();
92 assert (ro_list.size == 2);
93 assert (ro_list.get (0) == "one");
94 assert (ro_list.get (1) == "two");
95 assert (iterator.index () == 0);
97 if (Test.trap_fork (0, TestTrapFlags.SILENCE_STDOUT |
98 TestTrapFlags.SILENCE_STDERR)) {
99 iterator.insert ("three");
102 Test.trap_assert_failed ();
103 assert (ro_list.size == 2);
104 assert (ro_list.get (0) == "one");
105 assert (ro_list.get (1) == "two");
106 assert (iterator.index () == 0);
108 if (Test.trap_fork (0, TestTrapFlags.SILENCE_STDOUT |
109 TestTrapFlags.SILENCE_STDERR)) {
110 iterator.add ("three");
113 Test.trap_assert_failed ();
114 assert (ro_list.size == 2);
115 assert (ro_list.get (0) == "one");
116 assert (ro_list.get (1) == "two");
117 assert (iterator.index () == 0);