Add GNU LGPL headers to all .c .C and .h files
[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    ostrstream pattern_out(pattern_buf, LARGE_BUFSIZ, ios::out);
44    print_stylesheet(pattern, pattern_out);
45
46    char loc[BUFSIZ];
47    strcpy(loc, pattern.name());
48
49    stylesheet_smart_ptr x( base_ptr, loc );
50    char db_buf[LARGE_BUFSIZ];
51    ostrstream db_out(db_buf, LARGE_BUFSIZ, ios::out);
52    print_stylesheet(x, db_out);
53
54    return compare_stream(pattern_out, db_out);
55 }
56
57 void update_stylesheet_test(char* filename, info_base* base_ptr, char* locator)
58 {
59    char buf[LBUFSIZ];
60    char st_buf[LBUFSIZ];
61    fstream in(filename, ios::in);
62    while (in) {
63       in.getline(buf, LBUFSIZ);
64       strcat(st_buf, buf);
65    }
66    stylesheet_smart_ptr st(base_ptr, locator);
67    st.update_online_data(st_buf, strlen(st_buf));
68 }
69
70 int stylesheet_test_loc( info_lib* infolib_ptr, const char* base_name, const char* loc )
71 {
72    stylesheet_smart_ptr x( infolib_ptr, base_name, loc );
73    cerr << form("info of stylesheet object with loc %s:\n", loc);
74    print_stylesheet(x, cerr);
75    return 0;
76 }
77
78 int stylesheet_test_oid( info_lib* infolib_ptr, const char* base_name, const char* oid_str)
79 {
80    oid_t id((char*)oid_str, true, false);
81    stylesheet_smart_ptr x( infolib_ptr, base_name, id );
82
83    cerr << form("info of stylesheet object with id : ");
84    debug(cerr, id);
85    debug(cerr, x.name());
86    debug(cerr, x.online_data_size());
87    debug(cerr, x.online_data());
88    debug(cerr, x.hardcopy_data_size());
89    debug(cerr, x.hardcopy_data());
90
91    x.its_oid().asciiOut(cerr); cerr << "\n";
92
93    return 0;
94 }
95
96 void generate_stylesheet_instance(random_gen& x, ostream& out, int min_len, int max_len)
97 {
98    out << "1011\n";
99    out << "3\n";
100    x.random_string(out, 15, 15); // name
101    x.random_string(out, min_len, max_len); // sheet1
102    x.random_string(out, min_len, max_len); // sheet2
103 }
104
105 #endif