3 * Copyright (C) 2009 Didier Villevalois
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 * Didier 'Ptitjes' Villevalois <ptitjes@free.fr>
25 public abstract class QueueTests : CollectionTests {
27 public QueueTests (string name) {
29 add_test ("[Queue] capacity bound", test_capacity_bound);
30 add_test ("[Queue] one element operation", test_one_element_operation);
31 add_test ("[Queue] GObject properties", test_gobject_properties);
34 public void test_capacity_bound () {
35 var test_queue = test_collection as Gee.Queue<string>;
37 // Check the test queue is not null
38 assert (test_queue != null);
40 if (test_queue.capacity == Gee.Queue.UNBOUNDED_CAPACITY) {
42 assert (test_queue.remaining_capacity == Gee.Queue.UNBOUNDED_CAPACITY);
43 assert (! test_queue.is_full);
46 assert (test_queue.is_empty);
48 // Check that we can fill it completely
49 int capacity = test_queue.capacity;
50 for (int i = 1; i <= capacity; i++) {
51 assert (! test_queue.is_full);
52 assert (test_queue.offer ("one"));
53 assert (test_queue.remaining_capacity == capacity - i);
55 assert (test_queue.is_full);
57 // Check that we can empty it completely
58 for (int i = 1; i <= capacity; i++) {
59 assert (test_queue.poll () == "one");
60 assert (! test_queue.is_full);
61 assert (test_queue.remaining_capacity == i);
63 assert (test_queue.is_empty);
67 public void test_one_element_operation () {
68 var test_queue = test_collection as Gee.Queue<string>;
69 ArrayList<string> recipient = new ArrayList<string> ();
71 // Check the test queue is not null
72 assert (test_queue != null);
74 // Check offer one element when there is none yet
75 assert (test_queue.offer ("one"));
76 assert (test_queue.peek () == "one");
77 assert (test_queue.size == 1);
78 assert (! test_queue.is_empty);
80 // Check poll when there is one element
81 assert (test_queue.poll () == "one");
82 assert (test_queue.size == 0);
83 assert (test_queue.is_empty);
85 // Check poll when there is no element
86 assert (test_queue.peek () == null);
87 assert (test_queue.poll () == null);
89 // Check drain one element when there is one
91 assert (test_queue.offer ("one"));
92 assert (test_queue.drain (recipient, 1) == 1);
93 assert (test_queue.size == 0);
94 assert (test_queue.is_empty);
95 assert (recipient.size == 1);
96 assert (recipient.get (0) == "one");
98 // Check drain one element when there is none
100 assert (test_queue.drain (recipient, 1) == 0);
101 assert (test_queue.size == 0);
102 assert (test_queue.is_empty);
103 assert (recipient.size == 0);
105 // Check drain all elements when there is one
107 assert (test_queue.offer ("one"));
108 assert (test_queue.drain (recipient) == 1);
109 assert (test_queue.size == 0);
110 assert (test_queue.is_empty);
111 assert (recipient.size == 1);
112 assert (recipient.get (0) == "one");
115 public new void test_gobject_properties () {
116 var test_queue = test_collection as Gee.Queue<string>;
118 // Check the list exists
119 assert (test_queue != null);
122 value = Value (typeof (int));
123 test_queue.get_property ("capacity", ref value);
124 assert (value.get_int () == test_queue.capacity);
127 value = Value (typeof (int));
128 test_queue.get_property ("remaining-capacity", ref value);
129 assert (value.get_int () == test_queue.remaining_capacity);
132 value = Value (typeof (bool));
133 test_queue.get_property ("is-full", ref value);
134 assert (value.get_boolean () == test_queue.is_full);