123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302 |
- /*
- * CDE - Common Desktop Environment
- *
- * Copyright (c) 1993-2012, The Open Group. All rights reserved.
- *
- * These libraries and programs are free software; you can
- * redistribute them and/or modify them under the terms of the GNU
- * Lesser General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * These libraries and programs are distributed in the hope that
- * they will be useful, but WITHOUT ANY WARRANTY; without even the
- * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU Lesser General Public License for more
- * details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with these libraries and programs; if not, write
- * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
- * Floor, Boston, MA 02110-1301 USA
- */
- // $XConsortium: c_api_test.cc /main/4 1996/06/11 17:28:13 cde-hal $
- #include "oliasdb/DtMmdb.h"
- #include "oliasdb/mmdb.h"
- #include "oliasdb/c_api_common.h"
- #include <stdio.h>
- #include <stdlib.h>
- void showBookCaseInfo(int i);
- int showInfoLibInfo(int i)
- {
- int n = 0;
- int j;
- DtMmdbInfoLibInfo* info = DtMmdbInfoLibGetInfo(i);
- if ( info ) {
- if ( info -> path )
- fprintf(stderr, "infolibInfo: path= %s\n", info -> path);
- if ( info -> name )
- fprintf(stderr, "infolibInfo: name= %s\n", info -> name);
- fprintf(stderr, "infolibInfo: num_bookcases= %d\n", info -> num_bookcases);
- n = info -> num_bookcases;
- DtMmdbInfoLibFreeInfo(info);
- } else
- fprintf(stderr, "no infolibInfo\n");
- return n;
- }
- void showBookCaseInfo(int i)
- {
- if ( i <= -1 ) {
- fprintf(stderr, "bad bookcase descriptor %d\n", i);
- } else {
- DtMmdbBookCaseInfo* info = DtMmdbBookCaseGetInfo(i);
- if ( info ) {
- if ( info -> name )
- fprintf(stderr, " bookcaseInfo: name= %s\n", info -> name);
- fprintf(stderr, " bookcaseInfo: num_bookcases= %d\n", info -> num_books);
- DtMmdbBookCaseFreeInfo(info);
- } else
- fprintf(stderr, "no bookcase info\n");
- }
- }
- // automatica test cases
- extern int auto_test(int argc, char** argv, OLIAS_DB& db);
- extern "C"
- int auto_test_c_api(int argc, char** argv)
- {
- OLIAS_DB db;
- return auto_test(argc, argv, db);
- }
- // test cases that require manual inspection
- extern "C"
- int test0(int argc, char** argv)
- {
- int j = 0;
- int n = 0;
- int i = -1;
- switch ( argc ) {
- case 4:
- i = DtMmdbOpenInfoLib(argv[2], argv[3], DtMmdbFalse);
- n = showInfoLibInfo(i);
- for ( j=0; j<n; j++ )
- showBookCaseInfo(DtMmdbGetBookCaseByIndex(i, j));
- break;
- case 3:
- i = DtMmdbOpenInfoLib(argv[2], 0, DtMmdbFalse);
- showInfoLibInfo(i);
- n = showInfoLibInfo(i);
- for ( j=0; j<n; j++ )
- showBookCaseInfo(DtMmdbGetBookCaseByIndex(i, j));
- break;
- default:
- fprintf(stderr, "bad argument list\n");
- }
- fprintf(stderr, "infolib desc=%d\n", i);
- return 0;
- }
- extern "C"
- int test1(int argc, char** argv)
- {
- int j = 0;
- int n = 0;
- int i = -1;
- switch ( argc ) {
- case 5:
- i = DtMmdbOpenInfoLib(argv[2], argv[3], DtMmdbFalse);
- n = showInfoLibInfo(i);
- for ( j=0; j<n; j++ )
- showBookCaseInfo(DtMmdbGetBookCaseByLoc(i, argv[4]));
- break;
- default:
- fprintf(stderr, "bad argument list\n");
- }
- fprintf(stderr, "infolib desc=%d\n", i);
- return 0;
- }
- DtMmdbInfoRequest* newDtMmdbInfoRequestWithLoc(int bc_id, char* loc)
- {
- DtMmdbInfoRequest* x =
- (DtMmdbInfoRequest*) malloc(sizeof(DtMmdbInfoRequest));
-
- x -> bookcase_descriptor = bc_id ;
- x -> locator_ptr = loc;
- return x;
- }
- DtMmdbInfoRequest* newDtMmdbInfoRequestWithPrimaryOid(int bc_id, char* oid_str)
- {
- DtMmdbInfoRequest* x =
- (DtMmdbInfoRequest*) malloc(sizeof(DtMmdbInfoRequest));
-
- x -> bookcase_descriptor = bc_id ;
- x -> primary_oid = newDtMmdbHandle(oid_t(oid_str, true, false));
- return x;
- }
- char* DtMmdbHandleToString(DtMmdbHandle* x)
- {
- static char buf[100];
- if ( x -> oid_ptr) {
- oid_t *z = (oid_t*)(x -> oid_ptr);
- snprintf(buf, sizeof(buf), "%d.%d", z -> ccode(), z -> icode());
- } else
- buf[0] = 0;
- return buf;
- }
- void showSection(DtMmdbInfoRequest* req)
- {
- if ( req == 0 ) return ;
- const char* str = DtMmdbSectionGetLongTitle(req, 0);
- if (str) {
- fprintf(stderr, " SectionInfo: LongTitle=%s\n", str);
- }
- str = DtMmdbSectionGetShortTitle(req, 0);
- if (str) {
- fprintf(stderr, " SectionInfo: ShortTitle=%s\n", str);
- }
- str = DtMmdbSectionGetData(req, 0);
- if (str) {
- fprintf(stderr, " SectionInfo: data=%s\n", str);
- }
- int size = DtMmdbSectionGetDataSize(req);
- fprintf(stderr, " SectionInfo: dataSize=%d\n", size);
- str = DtMmdbSectionGetTocLoc(req);
- if (str) {
- fprintf(stderr, " SectionInfo: TocLoc=%s\n", str);
- }
- DtMmdbHandle* id = DtMmdbSectionGetBookId(req);
- if (id) {
- fprintf(stderr, " SectionInfo: BookId=%s\n", DtMmdbHandleToString(id));
- }
- id = DtMmdbSectionGetStyleSheetId(req);
- if (id) {
- fprintf(stderr, " SectionInfo: StyleSheetId=%s\n", DtMmdbHandleToString(id));
- }
- }
- void showTOC(DtMmdbInfoRequest* req)
- {
- if ( req == 0 ) return ;
- DtMmdbHandle* id = DtMmdbTocGetParentId(req);
- if (id)
- fprintf(stderr, " TOC: parentId=%s\n", DtMmdbHandleToString(id));
-
- unsigned int ct = 0;
- DtMmdbHandle** ids = DtMmdbTocGetChildIds(req, &ct);
- if ( ids ) {
- fprintf(stderr, "ct=%d\n", ct);
- for ( int i=0; i<ct; i++ )
- fprintf(stderr, " TOC: childid[%d]=%s\n", i, DtMmdbHandleToString(ids[i]));
- }
- int i = DtMmdbTocGetNumOfChildren(req);
- fprintf(stderr, " TOC: NumOfChildren=%d\n", i);
- }
- extern "C"
- int test2(int argc, char** argv)
- {
- int j = 0;
- int n = 0;
- int i = -1;
- const char* str;
- switch ( argc ) {
- case 5:
- {
- i = DtMmdbOpenInfoLib(argv[2], argv[3], DtMmdbFalse);
- j = DtMmdbGetBookCaseByLoc(i, argv[4]);
- DtMmdbInfoRequest* req = newDtMmdbInfoRequestWithLoc(j, argv[4]);
- showSection(req);
- break;
- }
- default:
- fprintf(stderr, "invalid arguments\n");
- }
- fprintf(stderr, "infolib desc=%d\n", i);
- return 0;
- }
- extern "C"
- int test3(int argc, char** argv)
- {
- int j = 0;
- int n = 0;
- int i = -1;
- const char* str;
- switch ( argc ) {
- case 5:
- {
- i = DtMmdbOpenInfoLib(argv[2], argv[3], DtMmdbFalse);
- j = DtMmdbGetBookCaseByName(i, argv[3]);
- DtMmdbInfoRequest* req = newDtMmdbInfoRequestWithPrimaryOid(j, argv[4]);
- showSection(req);
- break;
- }
- default:
- fprintf(stderr, "invalid arguments\n");
- }
- fprintf(stderr, "infolib desc=%d\n", i);
- return 0;
- }
- extern "C"
- int test4(int argc, char** argv)
- {
- int j = 0;
- int i = 0;
- const char* str;
- switch ( argc ) {
- case 5:
- {
- i = DtMmdbOpenInfoLib(argv[2], argv[3], DtMmdbFalse);
- j = DtMmdbGetBookCaseByName(i, argv[3]);
- DtMmdbInfoRequest* req = newDtMmdbInfoRequestWithPrimaryOid(j, argv[4]);
- showTOC(req);
- break;
- }
- default:
- fprintf(stderr, "invalid arguments\n");
- }
- fprintf(stderr, "infolib desc=%d\n", i);
- return 0;
- }
|