OpenIndiana and Solaris port
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / oliasdb / graphic_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: graphic_test.cc /main/4 1996/07/18 16:02:34 drk $ */
24
25 #ifdef REGRESSION_TEST
26
27 #include "oliasdb/graphic_test.h"
28
29 #define LARGE_BUFSIZ 2048
30
31
32 void print_graphic(graphic_smart_ptr& x, ostream& out, Boolean out_misc)
33 {
34    out << "locator=" << x.locator() << "\n";
35    out << "filename=" << x.file_name() << "\n";
36    out << "version=" << x.version() << "\n";
37
38    const char* title = x.title();
39    if ( title )
40       out << "title=" << x.title() << "\n";
41    else
42       out << "no title" << "\n";
43
44    out << "data_size=" << x.data_size() << "\n";
45
46    int l = x.data_size();
47    const char* str = x.data();
48
49    for ( int i=0; i<l; i++ )
50       out << str[i];
51
52    out << "\n";
53
54    if ( out_misc == true ) {
55       out << "type=" << x.type() << "\n";
56       out << "coding=" << x.coding() << "\n";
57       out << "width=" << x.width() << "\n";
58       out << "height=" << x.height() << "\n";
59
60       out << "llx=" << x.llx() << "\n";
61       out << "lly=" << x.lly() << "\n";
62       out << "urx=" << x.urx() << "\n";
63       out << "ury=" << x.ury() << "\n";
64    }
65 }
66
67 int compare_graphic(graphic_smart_ptr& pattern, info_base* base_ptr)
68 {
69    char pattern_buf[LARGE_BUFSIZ];
70    ostringstream pattern_out(pattern_buf, LARGE_BUFSIZ, ios::out);
71    print_graphic(pattern, pattern_out, false);
72
73    char loc[BUFSIZ];
74    int len = MIN(strlen(pattern.locator()), BUFSIZ -1);
75    *((char *) memcpy(loc, pattern.locator(), len) + len) = '\0';
76
77    graphic_smart_ptr x( base_ptr, loc );
78    char db_buf[LARGE_BUFSIZ];
79    ostringstream db_out(db_buf, LARGE_BUFSIZ, ios::out);
80    print_graphic(x, db_out, false);
81
82    return compare_stream(pattern_out, db_out);
83 }
84
85 int graphic_test(info_lib* infolib_ptr, const char* base_name, const char* node_id_str )
86 {
87    graphic_smart_ptr x( infolib_ptr, base_name, node_id_str );
88    cerr << form("info. about graphic %s:\n", node_id_str);
89    print_graphic(x, cerr, true);
90    return 0;
91 }
92
93 void generate_graphic_instance(info_base* b_ptr, random_gen& x, ostream& out, int min_len, int max_len)
94 {
95
96    out << "1009\n";
97    out << "6\n";
98    x.random_string(out, 15, 15); // locator
99    x.random_string(out, 0, 0);   // 
100    x.random_string(out, 2, 2);   // version
101    x.random_string(out, 10, 30);   // misc info
102
103    handler * y = (b_ptr -> get_obj_dict()).get_handler(
104         form("%s.%s", b_ptr -> get_base_name(), "sgml.dict")
105                                                       );
106    x.random_string_to_be_compressed(out, min_len, max_len, y -> its_oid()); // graphic
107    x.random_string(out, 10, 30);   // title
108 }
109
110 #endif