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: node_test.cc /main/4 1996/07/18 16:03:28 drk $ */
25 #ifdef REGRESSION_TEST
27 #include "oliasdb/node_test.h"
29 #define LARGE_BUFSIZ 2048
31 void print_node(node_smart_ptr& x, ostream& out, Boolean get_data, Boolean get_doc_id)
33 out << "locator=" << x.locator() << "\n";
34 out << "long_title=" << x.long_title() << "\n";
35 out << "short_title=" << x.short_title() << "\n";
37 if ( get_data == true ) {
38 out << "data_size=" << x.data_size() << "\n";
39 out << "data=" << x.data() << "\n";
42 out << "toc_node_loc=" << x.toc_node_loc() << "\n";
44 if ( get_data == true ) {
45 out << "doc_id=" << x.doc_id() << "\n";
48 out << "stylesheet_id=" << x.stylesheet_id() << "\n";
51 int compare_node(node_smart_ptr& pattern, info_base* base_ptr)
53 char pattern_buf[LARGE_BUFSIZ];
54 ostringstream pattern_out(pattern_buf, LARGE_BUFSIZ, ios::out);
55 print_node(pattern, pattern_out, false, false);
58 int len = MIN(strlen(pattern.locator()), BUFSIZ - 1);
59 *((char *) memcpy(loc, pattern.locator(), len) + len) = '\0';
61 node_smart_ptr x( base_ptr, loc );
62 char db_buf[LARGE_BUFSIZ];
63 ostringstream db_out(db_buf, LARGE_BUFSIZ, ios::out);
64 print_node(x, db_out, false, false);
66 return compare_stream(pattern_out, db_out);
70 int compare_SGML_content(istream& in, info_base* base_ptr, Boolean doingTest)
76 in >> loc_size; in.get();
78 for ( int i=0; i<loc_size; i++ )
79 loc[i] = (char)in.get();
83 MESSAGE(cerr, "compare_SGML_content():");
85 debug(cerr, loc_size);
92 ostringstream* db_out;
95 node_smart_ptr x( base_ptr, loc );
96 data_size = x.data_size();
98 db_buf = new char[data_size+1];
99 db_out = new ostringstream(db_buf, data_size+1, ios::out);
101 const char* z = x.data();
102 for ( int i=0; i<data_size; i++ )
106 in >> data_size; in.get();
108 char* pattern_buf = new char[data_size+1];
109 ostringstream pattern_out(pattern_buf, data_size+1, ios::out);
111 for ( i=0; i<data_size; i++ )
112 pattern_out.put((char)in.get());
117 ok = compare_stream(pattern_out, *db_out);
127 int node_test_loc( info_lib* infolib_ptr, const char* base_name, const char* loc )
129 node_smart_ptr x( infolib_ptr, base_name, loc );
131 cerr << form("info of node with loc %s:\n", loc);
132 x.its_oid().asciiOut(cerr); cerr << "\n";
133 print_node(x, cerr, true, true);
138 int node_test_oid( info_lib* infolib_ptr, const char* base_name, const char* oid_str)
140 oid_t id((char*)oid_str, true, false);
141 node_smart_ptr x( infolib_ptr, base_name, id );
143 cerr << form("info of node with oid string %s:\n", oid_str);
144 print_node(x, cerr, true, true);
155 19 Component Test Book
157 19 Component Test Book
169 void generate_node_instance(info_base* b_ptr, random_gen& x, ostream& out,
170 ostream& mixed_out, int min_len, int max_len)
175 const char* loc = x.get_random_string(15, 15); // locator
177 out << "6\n15\t" << loc << "\n";
179 x.random_string(out, 10, 50); // short title
180 x.random_string(out, 10, 100); // long title
182 //fprintf(stderr, "%d\n", (void*)(b_ptr -> get_base_name()));
184 handler * y = (b_ptr -> get_obj_dict()).get_handler(
185 form("%s.%s", b_ptr -> get_base_name(), "sgml.dict")
188 x.random_string_to_be_compressed(out, 0, 0, y -> its_oid()); // content
189 x.random_string(out, 15, 15); // locator
193 mixed_out << "1010\n";
194 mixed_out << "15\t" << loc << "\n"; // locator
196 x.random_string(mixed_out, min_len, max_len, false); // content
200 void generate_sgml_instance(random_gen& x, ostream& out, int min_len, int max_len)
203 x.random_string(out, 15, 15); // locator
204 x.random_string(out, min_len, max_len); // content