OpenIndiana and Solaris port
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / oliasdb / node_test.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
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
22  */
23 /* $XConsortium: node_test.cc /main/4 1996/07/18 16:03:28 drk $ */
24
25 #ifdef REGRESSION_TEST
26
27 #include "oliasdb/node_test.h"
28
29 #define LARGE_BUFSIZ 2048
30
31 void print_node(node_smart_ptr& x, ostream& out, Boolean get_data, Boolean get_doc_id)
32 {
33    out << "locator=" << x.locator() << "\n";
34    out << "long_title=" << x.long_title() << "\n";
35    out << "short_title=" << x.short_title() << "\n";
36
37    if ( get_data == true ) {
38       out << "data_size=" << x.data_size() << "\n";
39       out << "data=" << x.data() << "\n";
40    }
41
42    out << "toc_node_loc=" << x.toc_node_loc() << "\n";
43
44    if ( get_data == true ) {
45       out << "doc_id=" << x.doc_id() << "\n";
46    }
47
48    out << "stylesheet_id=" << x.stylesheet_id() << "\n";
49 }
50
51 int compare_node(node_smart_ptr& pattern, info_base* base_ptr)
52 {
53    char pattern_buf[LARGE_BUFSIZ];
54    ostringstream pattern_out(pattern_buf, LARGE_BUFSIZ, ios::out);
55    print_node(pattern, pattern_out, false, false);
56
57    char loc[BUFSIZ];
58    int len = MIN(strlen(pattern.locator()), BUFSIZ - 1);
59    *((char *) memcpy(loc, pattern.locator(), len) + len) = '\0';
60
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);
65
66    return compare_stream(pattern_out, db_out);
67 }
68
69
70 int compare_SGML_content(istream& in, info_base* base_ptr, Boolean doingTest)
71 {
72    int ok = 0;
73
74    int loc_size;
75    char loc[BUFSIZ];
76    in >> loc_size; in.get(); 
77
78    for ( int i=0; i<loc_size; i++ )
79       loc[i] = (char)in.get();
80
81    loc[i] = 0;
82 /*
83 MESSAGE(cerr, "compare_SGML_content():");
84 debug(cerr, loc);
85 debug(cerr, loc_size);
86 */
87
88    in.get();
89
90    char* db_buf;
91    int data_size ;
92    ostringstream* db_out;
93
94    if ( doingTest ) {
95       node_smart_ptr x( base_ptr, loc );
96       data_size = x.data_size();
97    
98       db_buf = new char[data_size+1];
99       db_out = new ostringstream(db_buf, data_size+1, ios::out);
100    
101       const char* z = x.data();
102       for ( int i=0; i<data_size; i++ )
103          db_out -> put(z[i]);
104    }
105
106    in >> data_size; in.get(); 
107
108    char* pattern_buf = new char[data_size+1];
109    ostringstream pattern_out(pattern_buf, data_size+1, ios::out);
110
111    for ( i=0; i<data_size; i++ )
112       pattern_out.put((char)in.get());
113
114    in.get();
115
116    if ( doingTest ) {
117       ok = compare_stream(pattern_out, *db_out);
118       delete db_out;
119       delete db_buf;
120    }
121
122    delete pattern_buf;
123
124    return ok;
125 }
126
127 int node_test_loc( info_lib* infolib_ptr, const char* base_name, const char* loc )
128 {
129    node_smart_ptr x( infolib_ptr, base_name, loc );
130
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);
134
135    return 0;
136 }
137
138 int node_test_oid( info_lib* infolib_ptr, const char* base_name, const char* oid_str)
139 {
140    oid_t id((char*)oid_str, true, false);
141    node_smart_ptr x( infolib_ptr, base_name, id );
142
143    cerr << form("info of node with oid string %s:\n", oid_str);
144    print_node(x, cerr, true, true);
145
146    return 0;
147 }
148
149 /*
150 1001
151 7
152 6
153 15      y3THnmB0oYn87oL
154 6
155 19      Component Test Book
156 6
157 19      Component Test Book
158 11
159 503.16387
160 0
161 6
162 15      y3THnmB0oYn87oL
163 7
164 0.0
165 7
166 1011.212994
167 */
168
169 void generate_node_instance(info_base* b_ptr, random_gen& x, ostream& out, 
170         ostream& mixed_out, int min_len, int max_len)
171 {
172    out << "1001\n";
173    out << "7\n";
174
175    const char* loc = x.get_random_string(15, 15); // locator
176
177    out << "6\n15\t" << loc << "\n";
178
179    x.random_string(out, 10, 50); // short title
180    x.random_string(out, 10, 100); // long title
181
182 //fprintf(stderr, "%d\n", (void*)(b_ptr -> get_base_name()));
183
184    handler * y = (b_ptr -> get_obj_dict()).get_handler(
185         form("%s.%s", b_ptr -> get_base_name(), "sgml.dict")
186                                                       );
187
188    x.random_string_to_be_compressed(out, 0, 0, y -> its_oid()); // content
189    x.random_string(out, 15, 15); // locator
190    x.random_oid(out); 
191    x.random_oid(out); 
192
193    mixed_out << "1010\n";
194    mixed_out << "15\t" << loc << "\n"; // locator
195
196    x.random_string(mixed_out, min_len, max_len, false); // content
197 }
198
199 /*
200 void generate_sgml_instance(random_gen& x, ostream& out, int min_len, int max_len)
201 {
202    out << "1010\n";
203    x.random_string(out, 15, 15); // locator
204    x.random_string(out, min_len, max_len); // content
205 }
206 */
207 #endif