OpenIndiana and Solaris port
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / oliasdb / stylesheet_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: stylesheet_test.cc /main/4 1996/07/18 16:03:49 drk $ */
24
25 #ifdef REGRESSION_TEST
26
27 #include "oliasdb/stylesheet_test.h"
28
29 #define LARGE_BUFSIZ 2048
30
31 void print_stylesheet(stylesheet_smart_ptr& x, ostream& out)
32 {
33    out << "name=" << x.name();
34    out << "online_data_size=" << x.online_data_size();
35    out << "online_data=" << x.online_data();
36    out << "hardcopy_data_size=" << x.hardcopy_data_size();
37    out << "hardcopy_data_size=" << x.hardcopy_data();
38 }
39
40 int compare_stylesheet(stylesheet_smart_ptr& pattern, info_base* base_ptr)
41 {
42    char pattern_buf[LARGE_BUFSIZ];
43    ostringstream pattern_out(pattern_buf, LARGE_BUFSIZ, ios::out);
44    print_stylesheet(pattern, pattern_out);
45
46    char loc[BUFSIZ];
47    int len = MIN(strlen(pattern.name()), BUFSIZ - 1);
48    *((char *) memcpy(loc, pattern.name(), len) + len) = '\0';
49
50    stylesheet_smart_ptr x( base_ptr, loc );
51    char db_buf[LARGE_BUFSIZ];
52    ostringstream db_out(db_buf, LARGE_BUFSIZ, ios::out);
53    print_stylesheet(x, db_out);
54
55    return compare_stream(pattern_out, db_out);
56 }
57
58 void update_stylesheet_test(char* filename, info_base* base_ptr, char* locator)
59 {
60    char buf[LBUFSIZ];
61    char st_buf[LBUFSIZ];
62    fstream in(filename, ios::in);
63    while (in) {
64       in.getline(buf, LBUFSIZ);
65       int slen = strlen(st_buf);
66       int len = MIN(strlen(buf), LBUFSIZ - 1 - slen);
67       *((char *) memcpy(st_buf + slen, buf, len) + len) = '\0';
68    }
69    stylesheet_smart_ptr st(base_ptr, locator);
70    st.update_online_data(st_buf, strlen(st_buf));
71 }
72
73 int stylesheet_test_loc( info_lib* infolib_ptr, const char* base_name, const char* loc )
74 {
75    stylesheet_smart_ptr x( infolib_ptr, base_name, loc );
76    cerr << form("info of stylesheet object with loc %s:\n", loc);
77    print_stylesheet(x, cerr);
78    return 0;
79 }
80
81 int stylesheet_test_oid( info_lib* infolib_ptr, const char* base_name, const char* oid_str)
82 {
83    oid_t id((char*)oid_str, true, false);
84    stylesheet_smart_ptr x( infolib_ptr, base_name, id );
85
86    cerr << form("info of stylesheet object with id : ");
87    debug(cerr, id);
88    debug(cerr, x.name());
89    debug(cerr, x.online_data_size());
90    debug(cerr, x.online_data());
91    debug(cerr, x.hardcopy_data_size());
92    debug(cerr, x.hardcopy_data());
93
94    x.its_oid().asciiOut(cerr); cerr << "\n";
95
96    return 0;
97 }
98
99 void generate_stylesheet_instance(random_gen& x, ostream& out, int min_len, int max_len)
100 {
101    out << "1011\n";
102    out << "3\n";
103    x.random_string(out, 15, 15); // name
104    x.random_string(out, min_len, max_len); // sheet1
105    x.random_string(out, min_len, max_len); // sheet2
106 }
107
108 #endif