OpenIndiana and Solaris port
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / oliasdb / doc_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: doc_test.cc /main/4 1996/07/18 16:02:13 drk $ */
24
25 #ifdef REGRESSION_TEST
26
27 #include "oliasdb/doc_test.h"
28
29 #define LARGE_BUFSIZ 2048
30
31
32 void print_doc(doc_smart_ptr& x, ostream& out, Boolean out_it_oid, Boolean out_tag_list)
33 {
34    if ( out_it_oid == true )
35      out << "its_oid=" << x.its_oid();
36
37    out << "short_title=" << x.short_title();
38    out << "long_title=" << x.long_title();
39    out << "seq_num=" << x.seq_num();
40
41
42    if ( x.license_terms()) {
43      const char* w = x.license_terms();
44      int u = x.license_terms_size();
45      for (int i=0; i<u; i++ )
46         out << w[i];
47      out << "\n";
48    }
49
50    out << "license_terms_size=" <<  x.license_terms_size();
51
52    if ( out_tag_list == true ) {
53       cerr << "tag list of the doc";
54       short_list_handler* z = x.tab_list();
55       (*z) -> asciiOut(cerr); cerr << "\n";
56       delete z;
57    }
58 }
59
60 int compare_doc(doc_smart_ptr& pattern, info_base* base_ptr)
61 {
62    char pattern_buf[LARGE_BUFSIZ];
63    ostringstream pattern_out(pattern_buf, LARGE_BUFSIZ, ios::out);
64    print_doc(pattern, pattern_out, false, false);
65
66    doc_smart_ptr x( base_ptr, pattern.seq_num());
67    char db_buf[LARGE_BUFSIZ];
68    ostringstream db_out(db_buf, LARGE_BUFSIZ, ios::out);
69    print_doc(x, db_out, false, false);
70
71    return compare_stream(pattern_out, db_out);
72 }
73
74 int doc_test_oid( info_lib* infolib_ptr, const char* base_name, const char* oid_str )
75 {
76    oid_t id((char*)oid_str, true, false);
77    doc_smart_ptr x( infolib_ptr, base_name, id);
78    print_doc(x, cerr, true, true);
79
80    return 0;
81 }
82
83 int doc_test_doc_oid( info_lib* infolib_ptr, const char* base_name, const char* oid_str )
84 {
85    oid_t id((char*)oid_str, true, false);
86    doc_smart_ptr x(id, infolib_ptr, base_name);
87    print_doc(x, cerr, true, true);
88
89    return 0;
90 }
91
92 int 
93 doc_test_int(info_lib* infolib_ptr, 
94              const char* base_name, 
95              const char* seq_num_str)
96 {
97
98    doc_smart_ptr x( infolib_ptr, base_name, atoi(seq_num_str));
99    print_doc(x, cerr, true, true);
100
101    return 0;
102 }
103
104 void generate_doc_instance(random_gen& x, ostream& out, int seq_num, int min_tabs, int max_tabs)
105 {
106    out << "1000\n";
107    out << "6\n";
108    x.random_oid(out, 1001, 0); // id
109    x.random_string(out, 10, 20); // title
110    x.random_string(out, 10, 40); // title
111    x.random_integer(out, seq_num); // seq number
112
113    out << "105\n";
114    out << "#\n";
115
116    int tabs = x.pick_a_value(min_tabs, max_tabs);
117
118    for ( int i=0; i<tabs; i++ )
119       x.random_string(out, 10, 40); // tab node locator
120      
121    out << "#\n";
122
123    x.random_string(out, 10, 100); // license term
124 }
125
126 #endif