2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
23 // $XConsortium: c_api_test.cc /main/4 1996/06/11 17:28:13 cde-hal $
25 #include "oliasdb/DtMmdb.h"
26 #include "oliasdb/mmdb.h"
27 #include "oliasdb/c_api_common.h"
32 void showBookCaseInfo(int i);
34 int showInfoLibInfo(int i)
38 DtMmdbInfoLibInfo* info = DtMmdbInfoLibGetInfo(i);
41 fprintf(stderr, "infolibInfo: path= %s\n", info -> path);
43 fprintf(stderr, "infolibInfo: name= %s\n", info -> name);
44 fprintf(stderr, "infolibInfo: num_bookcases= %d\n", info -> num_bookcases);
46 n = info -> num_bookcases;
48 DtMmdbInfoLibFreeInfo(info);
50 fprintf(stderr, "no infolibInfo\n");
55 void showBookCaseInfo(int i)
58 fprintf(stderr, "bad bookcase descriptor %d\n", i);
60 DtMmdbBookCaseInfo* info = DtMmdbBookCaseGetInfo(i);
63 fprintf(stderr, " bookcaseInfo: name= %s\n", info -> name);
64 fprintf(stderr, " bookcaseInfo: num_bookcases= %d\n", info -> num_books);
65 DtMmdbBookCaseFreeInfo(info);
67 fprintf(stderr, "no bookcase info\n");
71 // automatica test cases
73 extern int auto_test(int argc, char** argv, OLIAS_DB& db);
76 int auto_test_c_api(int argc, char** argv)
79 return auto_test(argc, argv, db);
82 // test cases that require manual inspection
84 int test0(int argc, char** argv)
91 i = DtMmdbOpenInfoLib(argv[2], argv[3], DtMmdbFalse);
92 n = showInfoLibInfo(i);
94 showBookCaseInfo(DtMmdbGetBookCaseByIndex(i, j));
97 i = DtMmdbOpenInfoLib(argv[2], 0, DtMmdbFalse);
99 n = showInfoLibInfo(i);
100 for ( j=0; j<n; j++ )
101 showBookCaseInfo(DtMmdbGetBookCaseByIndex(i, j));
104 fprintf(stderr, "bad argment list\n");
107 fprintf(stderr, "infolib desc=%d\n", i);
112 int test1(int argc, char** argv)
119 i = DtMmdbOpenInfoLib(argv[2], argv[3], DtMmdbFalse);
120 n = showInfoLibInfo(i);
121 for ( j=0; j<n; j++ )
122 showBookCaseInfo(DtMmdbGetBookCaseByLoc(i, argv[4]));
125 fprintf(stderr, "bad argment list\n");
128 fprintf(stderr, "infolib desc=%d\n", i);
132 DtMmdbInfoRequest* newDtMmdbInfoRequestWithLoc(int bc_id, char* loc)
134 DtMmdbInfoRequest* x =
135 (DtMmdbInfoRequest*) malloc(sizeof(DtMmdbInfoRequest));
138 x -> bookcase_descriptor = bc_id ;
139 x -> locator_ptr = loc;
143 DtMmdbInfoRequest* newDtMmdbInfoRequestWithPrimaryOid(int bc_id, char* oid_str)
145 DtMmdbInfoRequest* x =
146 (DtMmdbInfoRequest*) malloc(sizeof(DtMmdbInfoRequest));
149 x -> bookcase_descriptor = bc_id ;
150 x -> primary_oid = newDtMmdbHandle(oid_t(oid_str, true, false));
154 char* DtMmdbHandleToString(DtMmdbHandle* x)
156 static char buf[100];
158 oid_t *z = (oid_t*)(x -> oid_ptr);
159 sprintf(buf, "%d.%d", z -> ccode(), z -> icode());
166 void showSection(DtMmdbInfoRequest* req)
168 if ( req == 0 ) return ;
170 const char* str = DtMmdbSectionGetLongTitle(req, 0);
172 fprintf(stderr, " SectionInfo: LongTitle=%s\n", str);
175 str = DtMmdbSectionGetShortTitle(req, 0);
177 fprintf(stderr, " SectionInfo: ShortTitle=%s\n", str);
180 str = DtMmdbSectionGetData(req, 0);
182 fprintf(stderr, " SectionInfo: data=%s\n", str);
185 int size = DtMmdbSectionGetDataSize(req);
186 fprintf(stderr, " SectionInfo: dataSize=%d\n", size);
189 str = DtMmdbSectionGetTocLoc(req);
191 fprintf(stderr, " SectionInfo: TocLoc=%s\n", str);
194 DtMmdbHandle* id = DtMmdbSectionGetBookId(req);
196 fprintf(stderr, " SectionInfo: BookId=%s\n", DtMmdbHandleToString(id));
199 id = DtMmdbSectionGetStyleSheetId(req);
201 fprintf(stderr, " SectionInfo: StyleSheetId=%s\n", DtMmdbHandleToString(id));
205 void showTOC(DtMmdbInfoRequest* req)
207 if ( req == 0 ) return ;
209 DtMmdbHandle* id = DtMmdbTocGetParentId(req);
211 fprintf(stderr, " TOC: parentId=%s\n", DtMmdbHandleToString(id));
215 DtMmdbHandle** ids = DtMmdbTocGetChildIds(req, &ct);
217 fprintf(stderr, "ct=%d\n", ct);
218 for ( int i=0; i<ct; i++ )
219 fprintf(stderr, " TOC: childid[%d]=%s\n", i, DtMmdbHandleToString(ids[i]));
222 int i = DtMmdbTocGetNumOfChildren(req);
223 fprintf(stderr, " TOC: NumOfChildren=%d\n", i);
227 int test2(int argc, char** argv)
236 i = DtMmdbOpenInfoLib(argv[2], argv[3], DtMmdbFalse);
237 j = DtMmdbGetBookCaseByLoc(i, argv[4]);
239 DtMmdbInfoRequest* req = newDtMmdbInfoRequestWithLoc(j, argv[4]);
244 fprintf(stderr, "invalid arguments\n");
247 fprintf(stderr, "infolib desc=%d\n", i);
252 int test3(int argc, char** argv)
261 i = DtMmdbOpenInfoLib(argv[2], argv[3], DtMmdbFalse);
262 j = DtMmdbGetBookCaseByName(i, argv[3]);
264 DtMmdbInfoRequest* req = newDtMmdbInfoRequestWithPrimaryOid(j, argv[4]);
269 fprintf(stderr, "invalid arguments\n");
272 fprintf(stderr, "infolib desc=%d\n", i);
277 int test4(int argc, char** argv)
285 i = DtMmdbOpenInfoLib(argv[2], argv[3], DtMmdbFalse);
286 j = DtMmdbGetBookCaseByName(i, argv[3]);
288 DtMmdbInfoRequest* req = newDtMmdbInfoRequestWithPrimaryOid(j, argv[4]);
293 fprintf(stderr, "invalid arguments\n");
296 fprintf(stderr, "infolib desc=%d\n", i);