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: mark_test.cc /main/5 1996/07/18 16:03:09 drk $ */
25 #ifdef REGRESSION_TEST
27 #include "mark_test.h"
29 void print_mark_list(mark_base* bptr, char* locator)
31 oid_list_handler* x = bptr -> get_mark_list(locator);
34 MESSAGE(cerr, "empty oid_list");
38 int ind = (*x) -> first();
42 oid_t id = (*x) -> operator()(ind);
44 if ( id.eq(ground) == false ) {
45 mark_smart_ptr y(bptr, id);
53 mark_base* get_mark_base(char* path, char* name)
66 catch (MMDBeXCEPtion &,e)
72 if ( ub -> open_status() != user_base::SUCC ) {
80 void _get_id(istream& in, oid_t& x)
82 static char buf[LBUFSIZ];
83 in.getline(buf, LBUFSIZ);
85 if ( buf[0] != 'k' || buf[1] != '\t' ) {
87 throw(stringException("_get_id(): missing k\t"));
92 oid_t id(key, true, false);
97 void _get_key(istream& in, char*& key)
99 static char buf[LBUFSIZ];
100 in.getline(buf, LBUFSIZ);
102 if ( buf[0] != 'k' || buf[1] != '\t' ) {
104 throw(stringException("_get_key(): missing k\t"));
110 void _get_data(istream& in, char*& data)
112 static char buf[LBUFSIZ];
113 in.getline(buf, LBUFSIZ);
115 if ( buf[0] != 'd' || buf[1] != '\t' ) {
117 throw(stringException("_get_data(): missing d\t"));
123 void _get_key_pos(istream& in, char*& key, int& n)
125 static char buf[LBUFSIZ];
126 in.getline(buf, LBUFSIZ);
128 if ( buf[0] != 'k' || buf[1] != '\t' ) {
130 throw(stringException("_get_key_pos(): missing k\t"));
135 char* nextToken = strchr(key, '\t');
137 if ( nextToken == 0 )
138 throw(stringException("can't find position (integer)."));
142 n = atoi(nextToken+1);
146 oid_t get_nth_mark_id(mark_base* ub, char* key, int n)
148 oid_list_handler* handle = ub -> get_mark_list(key);
151 throw(stringException("empty mark list"));
154 int ind = (*handle) -> first();
161 oid_t id = (*handle) -> operator()(ind);
166 (*handle) -> next(ind);
170 int count = (*handle)->count();
172 throw(boundaryException(0, count, i));
181 int _create_subtest(char* buf, istream& in, mark_base* ub)
184 mark_smart_ptr* x = 0;
186 if ( strcmp(buf, "create") == 0 ) {
188 cout << ">>> create:" << endl;
193 cout << "---- new mark smtart_ptr ..." << endl;
194 x = new mark_smart_ptr(ub, key);
196 cout << "---- updating ..." << endl;
197 x -> update_usermark(data, strlen(data));
199 cout << "<<< create:" << endl;
209 _get_by_key_subtest(char* buf, istream& in, mark_base* ub)
213 mark_smart_ptr* x = 0;
215 if ( strcmp(buf, "get_by_key") == 0 ) {
216 cout << ">>> get_by_key:" << endl;
218 _get_key_pos(in, key, n);
220 oid_t id = get_nth_mark_id(ub, key, n);
222 x = new mark_smart_ptr(ub, id);
224 cout << x->node_locator();
226 cout << *(x->mark_value());
231 cout << "<<< get_by_key:" << endl;
239 _get_by_oid_subtest(char* buf, istream& in, mark_base* ub)
242 mark_smart_ptr* x = 0;
243 if ( strcmp(buf, "get_by_oid") == 0 ) {
247 oid_t id(key, true, false);
249 x = new mark_smart_ptr(ub, id);
251 cout << x->node_locator();
253 cout << *(x->mark_value());
263 // show_for_a_locator
266 _show_for_a_locator_subtest(char* buf, istream& in, mark_base* ub)
269 if ( strcmp(buf, "show_for_a_locator") == 0 ) {
271 cout << ">>> show_for_a_locator:" << endl;
275 oid_list_handler* z = ub-> get_mark_list(key);
278 throw(stringException("empty oid_list"));
281 int ind = (*z) -> first();
285 oid_t id = (*z) -> operator()(ind);
288 if ( id.eq(ground) == false ) {
290 mark_smart_ptr y(ub, id);
293 cout << y.node_locator();
295 cout << *(y.mark_value());
305 cout << "<<< show_for_a_locator" << endl;
311 //show_all_marks_subtest
313 _show_all_marks_subtest(char* buf, istream& in, mark_base* ub)
315 if ( strcmp(buf, "show_all_marks") == 0 ) {
316 cout << ">>> show_all_marks" << endl;
318 mmdb_pos_t ind = ub -> first();
320 oid_t id = ub -> get_mark_oid(ind);
322 if ( id.eq(ground) == false ) {
324 mark_smart_ptr y(ub, id);
327 cout << y.node_locator();
329 cout << *(y.mark_value());
336 cout << "<<< show_all_marks." << endl;
341 //////////////////////////////////////
342 //////////////////////////////////////
343 int _update_by_id_subtest(istream& in, oid_t id, mark_base* ub)
346 mark_smart_ptr* x = 0;
349 x = new mark_smart_ptr(ub, id);
351 cout << x -> its_oid() << "\n";
353 x -> update_usermark(data, strlen(data));
356 x = new mark_smart_ptr(ub, id);
358 pstring* y = x->mark_value();
360 if ( y -> size() != strlen(data) || strcmp(y -> get(), data) != 0 )
362 debug(cerr, y->size());
363 debug(cerr, (long)strlen(data));
364 debug(cerr, y -> get());
366 throw(stringException("improperly updated mark"));
380 _update_by_key_subtest(char* buf, istream& in, mark_base* ub)
385 if ( strcmp(buf, "update_by_key") == 0 ) {
387 cout << ">>> update_by_key" << endl;
389 _get_key_pos(in, key, n);
391 oid_t id = get_nth_mark_id(ub, key, n);
393 _update_by_id_subtest(in, id, ub);
395 cout << "<<< update_by_key" << endl;
408 _update_by_id_subtest(char* buf, istream& in, mark_base* ub)
410 if ( strcmp(buf, "update_by_id") == 0 ) {
412 cout << ">>> _update_by_id_subtest" << endl;
418 _update_by_id_subtest(in, id, ub);
420 cout << "<<< _update_by_id_subtest" << endl;
432 _delete_by_key_subtest(char* buf, istream& in, mark_base* ub)
434 mark_smart_ptr* x = 0;
436 if ( strcmp(buf, "delete_by_key") == 0 ) {
438 cout << ">>> _delete_by_key_subtest" << endl;
440 _get_key_pos(in, key, n);
442 oid_t id = get_nth_mark_id(ub, key, n);
444 x = new mark_smart_ptr(ub, id);
446 x -> remove_from_db();
450 cout << "<<< _delete_by_key_subtest" << endl;
459 _delete_by_oid_subtest(char* buf, istream& in, mark_base* ub)
461 mark_smart_ptr* x = 0;
462 if ( strcmp(buf, "delete_by_oid") == 0 ) {
466 x = new mark_smart_ptr(ub, id);
468 x -> remove_from_db();
475 int mark_test(int argc, char** argv)
479 if ( strcmp(argv[1], "create_mark_base") == 0 ) {
481 MESSAGE(cerr, "args: create_mark_base path name");
485 mark_base* ub = get_mark_base(argv[2], argv[3]);
487 if ( ub == 0 || ub -> open_status() != user_base::SUCC ) {
496 if ( strcmp(argv[1], "mark_comprehensive") == 0 ) {
499 "mark_comprehensive args: mark_comprehensive test_file path name");
503 mark_base* ub = get_mark_base(argv[3], argv[4]);
505 if ( ub == 0 || ub -> open_status() != user_base::SUCC ) {
510 fstream in(argv[2], ios::in);
515 while ( in.getline(buf, LBUFSIZ) ) {
520 if ( _create_subtest(buf, in, ub) != 1 )
523 if ( _get_by_key_subtest(buf, in, ub) != 1 )
526 if ( _get_by_oid_subtest(buf, in, ub) != 1 )
529 if ( _show_for_a_locator_subtest(buf, in, ub) != 1 )
532 if ( _show_all_marks_subtest(buf, in, ub) != 1 )
535 if ( _update_by_key_subtest(buf, in, ub) != 1 )
538 if ( _update_by_id_subtest(buf, in, ub) != 1 )
541 if ( _delete_by_key_subtest(buf, in, ub) != 1 )
544 if ( _delete_by_oid_subtest(buf, in, ub) != 1 ) {
546 throw(stringException("bad subtest command"));
550 MESSAGE(cerr, form("%d processed", i));