Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / oliasdb / toc_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: toc_test.cc /main/4 1996/07/18 16:04:09 drk $ */
24
25 #ifdef REGRESSION_TEST
26
27 #include "oliasdb/toc_test.h"
28
29 #define LARGE_BUFSIZ 2048
30
31
32 void print_toc(toc_smart_ptr& x, ostream& out)
33 {
34    x.toc_node_oid().asciiOut(out); out << "\n";
35    x.parent().asciiOut(out); out << "\n";
36
37    out << "children of the toc: ";
38    oid_list_handler* y = x.children();
39    (*y) -> asciiOut(out); out << "\n";
40
41    delete y;
42
43    out << "subtree node count: ";
44    out << x.subtree_size() << "\n";
45 }
46
47 int compare_toc(toc_smart_ptr& pattern, info_base* base_ptr)
48 {
49    char pattern_buf[LARGE_BUFSIZ];
50    ostrstream pattern_out(pattern_buf, LARGE_BUFSIZ, ios::out);
51    print_toc(pattern, pattern_out);
52
53    toc_smart_ptr x(base_ptr, pattern.toc_node_oid());
54    char db_buf[LARGE_BUFSIZ];
55    ostrstream db_out(db_buf, LARGE_BUFSIZ, ios::out);
56    print_toc(x, db_out);
57
58    return compare_stream(pattern_out, db_out);
59 }
60
61 int 
62 toc_test(info_lib* infolib_ptr, const char* base_name, const char* node_id_str )
63 {
64    oid_t id((char*)node_id_str, true, false);
65    toc_smart_ptr x( infolib_ptr, base_name, id );
66    print_toc(x, cerr);
67    return 0;
68 }
69
70 void generate_toc_instance(random_gen& x, ostream& out, int instance_num, int min_nodes, int max_nodes)
71 {
72    out << "1003\n";
73    out << "4\n";
74    x.random_oid(out, 1001, instance_num); // toc node id
75    x.random_oid(out, 1001, 0); // parent node id
76    x.random_integer(out); // 
77
78    out << "106\n";
79    out << "#\n";
80
81    int nodes = x.pick_a_value(min_nodes, max_nodes);
82
83    for ( int i=0; i<nodes; i++ )
84       x.random_oid(out, 1001, 0); // id
85
86    out << "#\n";
87 }
88
89 #endif