2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 // $XConsortium: main.cc /main/3 1996/06/11 16:57:24 cde-hal $
26 #include "Exceptions.hh"
27 #include "cc_exceptions.h"
30 #include "CC_String.h"
31 #include "CC_Tokenizer.h"
34 CC_Boolean mytestfunc(int *a, void *b)
40 cout << "Testing " << "(" << #tcond << ")\t"; \
42 cout << "Test #" << TestNum << " passed\n"; \
46 cout << "Test #" << TestNum << " failed\n"; \
62 CC_TPtrSlist<int> slist;
67 // inserting 10, 20 , 30
73 TEST(*slist.first() == 10);
74 TEST(*slist.at(0) == 10);
75 TEST(*slist.at(1) == 20);
76 TEST(*slist.at(2) == 30);
77 TEST(slist.entries() == 3);
84 TEST(*slist.first() == 40);
85 TEST(*slist.at(4) == 40);
87 TEST(*slist.removeAt(2) == 20);
88 TEST(*slist.at(2) == 30);
89 TEST(slist.find(&a) != NULL);
90 TEST(slist.find(&b) == NULL);
91 TEST(slist.contains(&a) == 1);
92 TEST(slist.contains(&b) == 0);
93 TEST(slist.remove(&b) == NULL);
94 TEST(*slist.remove(&a) == 10);
95 TEST(slist.remove(&a) == NULL);
96 TEST(*slist.remove(&d) == 40);
97 TEST(*slist.remove(&d) == 40);
98 TEST(slist.remove(&d) == NULL);
100 // Test slist copy constructor
101 CC_TPtrSlistIterator<int> slist_iter( slist );
102 CC_TPtrSlist<int> new_slist( slist );
103 CC_TPtrSlistIterator<int> new_slist_iter(new_slist);
105 TEST(slist.entries() == new_slist.entries());
106 for ( int w = 0; w < slist.entries(); w++ ) {
109 TEST(*slist_iter.key() == *new_slist_iter.key());
113 CC_TPtrSlist<int> empty_list;
114 TEST(empty_list.remove(&d) == NULL) ;
115 TEST(empty_list.find(&d) == NULL);
116 TEST(empty_list.removeFirst() == NULL);
117 TEST(empty_list.removeLast() == NULL);
119 empty_list.clearAndDestroy();
121 CC_TPtrDlist<int> dlist;
126 TEST(*dlist.first() == 10 );
127 TEST(*dlist.at(1) == 20 );
128 TEST(*dlist.at(2) == 30);
130 TEST(*dlist.last() == 30);
133 TEST(*dlist.first() == 30);
136 TEST(*dlist.last() == 20);
138 TEST(*dlist.removeFirst() == 30);
139 TEST(*dlist.removeLast() == 20);
140 TEST(*dlist.remove(&b) == 20);
141 TEST(*dlist.remove(&c) == 30);
146 CC_TPtrDlistIterator<int> dlist_iter(dlist);
147 CC_TPtrDlist<int> new_dlist(dlist);
148 CC_TPtrDlistIterator<int> new_dlist_iter(new_dlist);
150 // Compare the elements in the 2 lists
151 for ( int i = 0; i < dlist.entries(); i++ ) {
154 TEST(*dlist_iter.key() == *new_dlist_iter.key());
157 /* Traverse backward */
158 for ( int j = 0; j < dlist.entries(); j++ ) {
159 cout << *dlist_iter.key() << ", ";
166 TEST(*dlist_iter.key() == 20);
168 TEST(*dlist.find(mytestfunc, NULL) == 20 );
170 // dlist.clearAndDestroy();
172 CC_String cstr("abc");
173 TEST(cstr.isNull() == FALSE);
174 TEST(cstr.length() == 3);
175 TEST(cstr.compareTo("abc") == 0);
176 TEST(cstr.compareTo("def") < 0 );
178 TEST(cstr.compareTo("ABC") != 0);
179 TEST(cstr.compareTo("ABC", CC_String::ignoreCase) == 0);
180 TEST(cstr.compareTo("ABC", CC_String::exact) != 0);
182 CC_String dstr("abc");
183 TEST(cstr.compareTo(dstr) == 0);
184 TEST(cstr.compareTo(dstr, CC_String::ignoreCase) == 0);
185 TEST(cstr.compareTo(dstr.data()) == 0);
186 TEST(cstr.compareTo("abcde") != 0 );
187 TEST(cstr.compareTo("abcde", CC_String::ignoreCase) != 0 );
189 CC_TValSlist<int> vlist;
194 CC_TValSlistIterator<int> vlist_iter(vlist);
195 CC_TValSlist<int> new_vlist(vlist);
196 TEST(vlist.entries() == new_vlist.entries());
197 CC_TValSlistIterator<int> new_vlist_iter(new_vlist);
199 for ( int k = 0; k < vlist.entries(); k++ ) {
202 TEST(vlist_iter.key() == new_vlist_iter.key());
212 CC_String cc_str1("This is a pretty long string for testing");
213 CC_Tokenizer next1( cc_str1 );
216 cout << next1.data() << endl;
221 snprintf(str, sizeof(str), "\t\nthis is \t another string\t\n");
222 CC_String cc_str2( (const char *)str);
224 CC_Tokenizer next2( cc_str2 );
226 cout << next2.data() << endl;
230 CC_TPtrDlist<int> tdlist;
231 // tdlist.insert(empty);
232 TEST(tdlist.removeFirst() == NULL);
233 TEST(tdlist.removeLast() == NULL);
234 tdlist.prepend(empty);
235 tdlist.insert(empty);
236 tdlist.removeFirst();
238 TEST(tdlist.removeFirst() == NULL);
247 TEST(stack.top() == 4 );
248 TEST(stack.pop() == 4 );
249 TEST(stack.pop() == 3 );
250 TEST(stack.pop() == 2 );
252 TEST(stack.top() == 20);
253 TEST(stack.pop() == 20);
256 cout << "test passed = " << TestPassed << endl;
257 cout << "test failed = " << TestFailed << endl;
260 TEST(stack.top()); // This will throw exception
262 catch( Exception&, u)
264 cerr << "Exception generated by top() were caught\n";
270 catch( Exception&, u )
272 cerr << "Exception generated by pop() were caught\n";
277 catch(ccException&, u)
279 cerr << "ccException caught\n";
283 cout << "Exception generated by pop() caught\n";