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
24 * $XConsortium: olias_test.C /main/8 1996/10/26 18:20:03 cde-hal $
26 * Copyright (c) 1992 HAL Computer Systems International, Ltd.
27 * All rights reserved. Unpublished -- rights reserved under
28 * the Copyright Laws of the United States. USE OF A COPYRIGHT
29 * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
32 * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
33 * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
34 * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
35 * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
38 * RESTRICTED RIGHTS LEGEND
39 * Use, duplication, or disclosure by the Government is subject
40 * to the restrictions as set forth in subparagraph (c)(l)(ii)
41 * of the Rights in Technical Data and Computer Software clause
42 * at DFARS 252.227-7013.
44 * HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
51 #include "oliasdb/olias_test.h"
52 #include "api/utility.h"
53 #include "utility/pm_random.h"
54 #include "misc/unique_id.h"
55 #include "storage/vm_storage.h"
56 #include "dstr/dstr_test.h"
57 #include "storage/store_test.h"
58 #include "oliasdb/olias_funcs.h"
60 #include "object/random_gen.h"
62 #ifdef REGRESSION_TEST
64 #include "oliasdb/graphic_test.h"
65 #include "oliasdb/loc_test.h"
66 #include "oliasdb/stylesheet_test.h"
67 #include "oliasdb/dlp_test.h"
68 #include "oliasdb/mark_test.h"
69 #include "oliasdb/toc_test.h"
70 #include "oliasdb/doc_test.h"
71 #include "oliasdb/node_test.h"
75 #include "oliasdb/collectionIterator.h"
76 #include "oliasdb/mmdb.h"
80 void test_collector_iterator(info_base* base)
82 MESSAGE(cerr, "node locators:");
83 nodeCollectionIterator x(base);
86 debug(cerr, x.get_locator());
89 MESSAGE(cerr, "stylesheet locators:");
91 stylesheetCollectionIterator y(base);
94 debug(cerr, y.get_locator());
97 MESSAGE(cerr, "locator set locators:");
99 locatorCollectionIterator z(base);
102 debug(cerr, z.get_locator());
106 int dump_instances(info_base* base_ptr, char* col_nm, c_code_t ins_code)
109 throw(stringException("null base ptr"));
111 Iterator *it = base_ptr -> first(col_nm, ins_code);
114 throw(stringException("null iterator pointer"));
119 oid_t id = base_ptr -> get_oid(*it);
121 if ( strcmp(col_nm, NODE_SET_NAME) == 0 ) {
123 node_smart_ptr x(base_ptr, id);
125 //debug(cerr, x.long_title());
127 if ( strcmp(col_nm, LOCATOR_SET_NAME) == 0 ) {
129 locator_smart_ptr x(base_ptr, id);
130 cout << x.inside_node_locator_str() << "\n";
132 if ( strcmp(col_nm, GRAPHIC_SET_NAME) == 0 ) {
134 graphic_smart_ptr x(base_ptr, id);
136 if ( x.type() == 3 ) {
137 const char* ps_str = x.data();
140 cout << x.data_size() << "\t";
141 for ( int j=0; j<x.data_size(); j++ )
148 base_ptr -> next(*it);
157 int cache_test( info_lib* infolib_ptr, const char* base_name, int argc, char** argv )
159 locator_smart_ptrPtr* ptr_array = new locator_smart_ptrPtr[argc];
163 for ( i=0; i<argc; i++ ) {
164 ptr_array[i] = new locator_smart_ptr(infolib_ptr, base_name, argv[i]);
166 cerr << form("node_id of locator %s:\n", argv[i]);
167 ptr_array[i] -> node_id().asciiOut(cerr); cerr << "\n";
168 //debug(cerr, ptr_array[i] -> vcc_num());
172 for ( i=0; i<argc; i++ ) {
180 void dump_node_ids(info_base* x_base)
185 int docs = x_base -> num_of_docs();
187 doc_smart_ptr* doc = 0;
189 node_smart_ptr* first_node = 0, *node = 0;
190 dlp_smart_ptr* x = 0, *dlp_cell = 0;
192 for ( int i=0; i<docs; i++ ) {
193 doc = new doc_smart_ptr(x_base, i+1);
195 debug(cerr, doc -> long_title());
197 first_node = new node_smart_ptr(x_base, doc -> locator_id());
199 dlp_cell = new dlp_smart_ptr(x_base, first_node -> its_oid());
203 debug(cerr, dlp_cell -> node_id());
205 x = dlp_cell -> next();
220 #ifdef REGRESSION_TEST
222 #define TEST_STY_FILE "test.sty"
223 #define TEST_SEC_FILE "test.sec"
224 #define TEST_MIX_FILE "test.mix"
226 int generate_stream(info_base* b_ptr, char* path, int num_sections, int min, int max)
230 if ( check_and_create_dir(path) == false )
233 // generate stylesheet stream
235 cerr << " stylesheets ..." << endl;
236 int stylesheets = x.pick_a_value(5, 20); // assume [5, 20] is the range
239 snprintf(buf, sizeof(buf), "%s/%s", path, TEST_STY_FILE);
240 fstream stylesheet_stream(buf, ios::out);
242 if ( !stylesheet_stream )
246 for (i=0; i<stylesheets; i++ ) {
247 // assume the stylesheet and section are of approx. length
248 generate_stylesheet_instance(x, stylesheet_stream, min, max);
251 // generate section stream
253 cerr << " sections ..." << endl;
255 snprintf(buf, sizeof(buf), "%s/%s", path, TEST_SEC_FILE);
256 fstream section_stream(buf, ios::out);
258 if ( !section_stream ) return -1;
261 // prepare mixed stream
262 snprintf(buf, sizeof(buf), "%s/%s", path, TEST_MIX_FILE);
263 fstream mix_stream(buf, ios::out);
265 if ( !mix_stream ) return -1;
267 for (i=0; i<num_sections; i++ )
268 generate_node_instance(b_ptr, x, section_stream, mix_stream, min, max);
270 // generate mixed stream
271 cerr << " docs ..." << endl;
274 int docs = x.pick_a_value(num_sections/4, num_sections/2);
275 for (i=0; i<docs; i++ ) {
276 // [docs/10, docs] is for the number of tab sections
277 //generate_doc_instance(x, mix_stream, i+1, docs/10, docs);
278 generate_doc_instance(x, mix_stream, i+1, 1, 10);
282 cerr << " tocs ..." << endl;
284 for (i=0; i<tocs; i++ ) {
285 // [0, num_sections/10] is for the branch factor
286 generate_toc_instance(x, mix_stream, i, 0, num_sections/10);
292 cerr << " graphics ..." << endl;
293 int graphics = x.pick_a_value(num_sections/2, 2*num_sections);
294 for (i=0; i<graphics; i++ )
295 generate_graphic_instance(b_ptr, x, mix_stream, min, max);
298 cerr << " locators ..." << endl;
299 int locs = x.pick_a_value(num_sections, num_sections*5);
300 for (i=0; i<locs; i++ )
301 generate_loc_instance(x, mix_stream);
306 int destroy_stream(char* path)
309 del_file(TEST_STY_FILE, path);
310 del_file(TEST_SEC_FILE, path);
311 del_file(TEST_MIX_FILE, path);
322 int extract_and_compare_objects(istream& in, info_base* base_ptr, int code)
326 handler* root_hd_ptr = 0;
328 vm_storage st((char*)"", (char*)"");
330 char ccode_buf[LBUFSIZ];
332 while ( (c = in.get()) != EOF ) {
335 in.getline(ccode_buf, LBUFSIZ);
337 sscanf(ccode_buf, "%u", &c);
339 //fprintf(stderr, "code = %d\n", c);
341 if ( c == SGML_CONTENT_CODE ) {
342 if ( code == c || code == 0 )
343 ok |= compare_SGML_content(in, base_ptr, (Boolean)true);
345 compare_SGML_content(in, base_ptr, (Boolean)false);
348 root_hd_ptr = new handler(c, &st);
350 (*root_hd_ptr) -> asciiIn(in);
352 if ( code == c || code == 0 ) {
354 case OLIAS_NODE_CODE :
355 ok |= compare_node(*(node_smart_ptr*)root_hd_ptr, base_ptr);
357 case STYLESHEET_CODE :
358 ok |= compare_stylesheet(*(stylesheet_smart_ptr*)root_hd_ptr, base_ptr);
361 ok |= compare_doc(*(doc_smart_ptr*)root_hd_ptr, base_ptr);
364 ok |= compare_graphic(*(graphic_smart_ptr*)root_hd_ptr, base_ptr);
367 ok |= compare_toc(*(toc_smart_ptr*)root_hd_ptr, base_ptr);
370 ok |= compare_locator(*(locator_smart_ptr*)root_hd_ptr, base_ptr);
389 {(char*)"auto_node_test", OLIAS_NODE_CODE},
390 {(char*)"auto_SGML_content_test", SGML_CONTENT_CODE},
391 {(char*)"auto_stylesheet_test", STYLESHEET_CODE},
392 {(char*)"auto_graphic_test", GRAPHIC_CODE},
393 {(char*)"auto_doc_test", DOC_CODE},
394 {(char*)"auto_toc_test", TOC_CODE},
395 {(char*)"auto_loc_test", LOCATOR_CODE},
398 #define NUM_OF_AUTO_TESTS 7
400 int auto_test(int argc, char** argv, OLIAS_DB& db)
404 info_lib* infolib_ptr = db.openInfoLib(argv[2]);
407 if ( infolib_ptr == 0 ||
408 infolib_ptr->define_info_base(argv[4],argv[4],argv[3]) == false
410 STDERR_MESSAGE("creating test database failed\n");
413 STDERR_MESSAGE("creating test database done\n");
415 db.closeInfoLib(infolib_ptr->get_info_lib_uid());
417 // randomly generate raw stream
418 infolib_ptr = db.openInfoLib(argv[2]);
419 info_base* base_ptr = infolib_ptr -> get_info_base(argv[4]);
420 ok = generate_stream(base_ptr, argv[2],
421 atoi(argv[5]), atoi(argv[6]), atoi(argv[7])
424 STDERR_MESSAGE("generating test data failed\n");
427 STDERR_MESSAGE("generating test data done\n");
429 db.closeInfoLib(infolib_ptr->get_info_lib_uid());
432 cerr << " loading stylesheets ..." << endl;
435 snprintf(buf, sizeof(buf), "%s.stylesheet", argv[4]);
436 snprintf(file_name, sizeof(file_name), "%s/%s", argv[2], TEST_STY_FILE);
438 infolib_ptr = db.openInfoLib(argv[2]);
439 base_ptr = infolib_ptr -> get_info_base(argv[4]);
440 ok = load( base_ptr, buf, file_name );
443 STDERR_MESSAGE("loading test stylesheet data failed\n");
446 STDERR_MESSAGE("loading test stylesheet data done\n");
448 db.closeInfoLib(infolib_ptr->get_info_lib_uid());
451 // load sections (small component)
452 cerr << " loading sections ..." << endl;
453 snprintf(buf, sizeof(buf), "%s.node", argv[4]);
454 snprintf(file_name, sizeof(file_name), "%s/%s", argv[2], TEST_SEC_FILE);
456 infolib_ptr = db.openInfoLib(argv[2]);
457 base_ptr = infolib_ptr -> get_info_base(argv[4]);
458 ok = load( base_ptr, buf, file_name );
461 STDERR_MESSAGE("loading test section data failed\n");
464 STDERR_MESSAGE("loading test section data done\n");
466 db.closeInfoLib(infolib_ptr->get_info_lib_uid());
468 // load all other objects
469 cerr << " loading all other objects ..." << endl;
470 snprintf(file_name, sizeof(file_name), "%s/%s", argv[2], TEST_MIX_FILE);
471 fstream in(file_name, ios::in);
473 if ( !in ) return -1;
475 infolib_ptr = db.openInfoLib(argv[2]);
476 base_ptr = infolib_ptr -> get_info_base(argv[4]);
477 ok = _load_mixed_objects(base_ptr, in);
480 STDERR_MESSAGE("loading all other test data failed\n");
483 STDERR_MESSAGE("loading all other test data done\n");
485 db.closeInfoLib(infolib_ptr->get_info_lib_uid());
489 infolib_ptr = db.openInfoLib(argv[2]);
490 base_ptr = infolib_ptr -> get_info_base(argv[4]);
493 snprintf(file_name, sizeof(file_name), "%s/%s", argv[2], TEST_STY_FILE);
494 fstream ss_in(file_name, ios::in);
496 if ( !ss_in ) return -1;
498 ok = extract_and_compare_objects(ss_in, base_ptr, 0);
501 STDERR_MESSAGE("testing stylesheet data failed\n");
504 STDERR_MESSAGE("testing stylesheet data done\n");
507 snprintf(file_name, sizeof(file_name), "%s/%s", argv[2], TEST_SEC_FILE);
508 fstream nd_in(file_name, ios::in);
509 if ( !nd_in ) return -1;
511 ok = extract_and_compare_objects(nd_in, base_ptr, 0);
514 STDERR_MESSAGE("testing section failed\n");
517 STDERR_MESSAGE("testing section done\n");
520 snprintf(file_name, sizeof(file_name), "%s/%s", argv[2], TEST_MIX_FILE);
521 fstream all_in(file_name, ios::in);
522 if ( !all_in ) return -1;
524 ok = extract_and_compare_objects(all_in, base_ptr, 0);
527 STDERR_MESSAGE("testing all other data failed\n");
530 STDERR_MESSAGE("testing all other data done\n");
532 db.closeInfoLib(infolib_ptr->get_info_lib_uid());
535 ( argc == 9 && strcmp(argv[8], "true") == 0 ) )
538 destroy_stream(argv[2]);
546 int select_debug_routine(int argc, char** argv, OLIAS_DB& db)
550 #ifdef REGRESSION_TEST
551 if ( strcmp(argv[1], "auto_test") == 0 ) {
553 if (argc != 8 && argc != 9 ) {
555 cerr << "usage: auto_test info_lib_path info_base_spec base_name number_of_sections max_section_size, min_section_size [true|false]\n";
558 return auto_test(argc, argv, db);
562 ok =store_test(argc, argv);
568 ok =dstr_test(argc, argv);
574 ok =mark_test(argc, argv);
577 cerr << "mark_test failed." << endl;
581 cerr << "mark_test done." << endl;
588 for ( int i=0; i<NUM_OF_AUTO_TESTS; i++ )
590 if ( strcmp(argv[1], auto_test_spec[i].name) == 0 ) {
592 if ( argc != 4 && argc != 3 ) {
593 cerr << " args: " << auto_test_spec[i].name ;
594 cerr << " base_name [stream_file_name]";
598 info_base* base_ptr = db.openInfoLib() -> get_info_base(argv[2]);
601 fstream in(argv[3], ios::in);
602 return extract_and_compare_objects(in, base_ptr, auto_test_spec[i].code);
604 return extract_and_compare_objects(cin, base_ptr, auto_test_spec[i].code);
610 if ( strcmp(argv[1], "random_gen") == 0 ) {
612 cerr << "random_gen args: " << "random_gen base_name path num_sections min_section_len max_sec_len\n";
615 info_base* base_ptr = db.openInfoLib() -> get_info_base(argv[2]);
617 return generate_stream(base_ptr, argv[3], atoi(argv[4]), atoi(argv[5]), atoi(argv[6]));
620 if ( strcmp(argv[1], "test_iterator") == 0 ) {
621 info_base* base_ptr = db.openInfoLib() -> get_info_base(argv[2]);
622 test_collector_iterator(base_ptr);
626 if ( strcmp(argv[1], "dump_node_ids") == 0 ) {
628 MESSAGE(cerr, "dump_node_ids args: dump_node_ids base_nm");
630 info_base* base_ptr = db.openInfoLib() -> get_info_base(argv[2]);
631 dump_node_ids(base_ptr);
636 if ( strcmp(argv[1], "dump_instances") == 0 ) {
638 MESSAGE(cerr, "load args: dump_all_instance base_nm type");
640 info_base* base_ptr = db.openInfoLib() -> get_info_base(argv[2]);
642 if ( strcmp(argv[3], "nodes") == 0 )
643 ok = dump_instances(base_ptr, NODE_SET_NAME, OLIAS_NODE_CODE);
645 if ( strcmp(argv[3], "locators") == 0 )
646 ok = dump_instances(base_ptr, LOCATOR_SET_NAME, LOCATOR_CODE);
648 if ( strcmp(argv[3], "graphics") == 0 )
649 ok = dump_instances(base_ptr, GRAPHIC_SET_NAME, GRAPHIC_CODE);
653 if ( strcmp(argv[1], "file_load") == 0 ) {
654 if ( (argc-2) % 3 != 0 ) {
656 "load args: file_load [obj_type obj_name data_file]+");
658 info_base* base_ptr = db.openInfoLib() -> get_info_base(argv[2]);
659 ok = load( base_ptr, argv+2, argc-2 );
664 if ( strcmp(argv[1], "loc_test") == 0 ) {
667 "loc_test args: loc_test base_name loc_value");
669 ok = loc_test( db.openInfoLib(), argv[2], argv[3] );
673 if ( strcmp(argv[1], "toc_test") == 0 ) {
676 "toc_test args: toc_test base_name oid_str");
678 ok = toc_test( db.openInfoLib(), argv[2], argv[3] );
682 if ( strcmp(argv[1], "graphic_test") == 0 ) {
685 "graphic_test args: graphic_test base_name oid_str");
687 ok = graphic_test( db.openInfoLib(), argv[2], argv[3] );
691 if ( strcmp(argv[1], "stylesheet_test_loc") == 0 ) {
694 "stylesheet_test_loc args: stylesheet_test_loc base_name loc");
696 ok = stylesheet_test_loc( db.openInfoLib(), argv[2], argv[3] );
699 if ( strcmp(argv[1], "stylesheet_test_oid") == 0 ) {
702 "stylesheet_test_oid args: stylesheet_test_oid base_name oid");
704 ok = stylesheet_test_oid( db.openInfoLib(), argv[2], argv[3] );
707 if ( strcmp(argv[1], "node_test_loc") == 0 ) {
710 "node_test_loc args: node_test_loc base_name loc");
712 ok = node_test_loc( db.openInfoLib(), argv[2], argv[3] );
716 if ( strcmp(argv[1], "node_test_oid") == 0 ) {
719 "node_test_oid args: node_test_oid base_name oid_str");
721 ok = node_test_oid( db.openInfoLib(), argv[2], argv[3] );
725 if ( strcmp(argv[1], "dlp_test") == 0 ) {
728 "dlp_test args: dlp_test base_name oid_str");
730 ok = dlp_test( db.openInfoLib(), argv[2], argv[3] );
734 if ( strcmp(argv[1], "doc_test_oid") == 0 ) {
737 "doc_test_oid args: doc_test_oid base_name oid_str");
739 ok = doc_test_oid( db.openInfoLib(), argv[2], argv[3] );
743 if ( strcmp(argv[1], "doc_test_int") == 0 ) {
746 "doc_test_int args: doc_test_int base_name int_str");
748 ok = doc_test_int( db.openInfoLib(), argv[2], argv[3] );