Files
harbour-core/harbour/contrib/hbbtree/tests/ctest.c
Viktor Szakats 003fd7c41e 2010-01-14 18:01 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)
* src/rtl/strclear.c
    + HB_STRCLEAR() return value will now precisely inform about
      successful clear operation. Thanks to Mindaugas.

  * src/vm/hashfunc.c
  * src/vm/macro.c
  * src/vm/strapi.c
  * src/vm/runner.c
  * src/vm/estack.c
  * src/vm/codebloc.c
  * src/vm/hashes.c
  * src/vm/maindll.c
  * src/vm/dynsym.c
  * src/vm/debug.c
  * src/vm/itemapi.c
  * src/vm/garbage.c
  * src/vm/asort.c
  * src/vm/hvm.c
  * src/vm/cmdarg.c
  * src/vm/mainstd.c
  * src/vm/maindllp.c
  * src/vm/arrays.c
  * src/vm/task.c
  * src/vm/fm.c
  * src/vm/proc.c
  * src/vm/thread.c
  * src/vm/memvars.c
  * src/vm/arrayshb.c
  * src/vm/eval.c
  * src/vm/extend.c
  * src/vm/dynlibhb.c
  * src/vm/set.c
  * src/vm/classes.c
  * src/debug/dbgentry.c
  * src/common/hbgete.c
  * src/common/hbffind.c
  * src/common/hbver.c
  * src/common/hbprintf.c
  * src/common/hbfsapi.c
  * src/common/hbstr.c
  * src/common/expropt1.c
  * src/common/expropt2.c
  * src/common/hbdate.c
  * src/common/strwild.c
  * src/common/hbhash.c
  * src/rtl/gtdos/gtdos.c
  * src/rtl/fscopy.c
  * src/rtl/run.c
  * src/rtl/gtwin/gtwin.c
  * src/rtl/gtxwc/gtxwc.h
  * src/rtl/gtxwc/gtxwc.c
  * src/rtl/math.c
  * src/rtl/empty.c
  * src/rtl/gtcrs/gtcrs.c
  * src/rtl/trim.c
  * src/rtl/filehb.c
  * src/rtl/hbtoken.c
  * src/rtl/fstemp.c
  * src/rtl/gtchrmap.c
  * src/rtl/strmatch.c
  * src/rtl/gtstd/gtstd.c
  * src/rtl/gttrm/gttrm.c
  * src/rtl/padr.c
  * src/rtl/hbstrfmt.c
  * src/rtl/transfrm.c
  * src/rtl/fserr.c
  * src/rtl/minmax.c
  * src/rtl/hbfeof.c
  * src/rtl/dates.c
  * src/rtl/padc.c
  * src/rtl/gtcgi/gtcgi.c
  * src/rtl/errapi.c
  * src/rtl/version.c
  * src/rtl/hbregexc.c
  * src/rtl/hbrandom.c
  * src/rtl/strtran.c
  * src/rtl/hbprocfn.c
  * src/rtl/hbsocket.c
  * src/rtl/hbinet.c
  * src/rtl/copyfile.c
  * src/rtl/errintlo.c
  * src/rtl/gtapi.c
  * src/rtl/filesys.c
  * src/rtl/padl.c
  * src/rtl/hbregex.c
  * src/rtl/hbbit.c
  * src/rtl/isprint.c
  * src/rtl/saverest.c
  * src/rtl/diskspac.c
  * src/rtl/console.c
  * src/rtl/spfiles.c
  * src/rtl/gtos2/gtos2.c
  * src/rtl/philes.c
  * src/rtl/hbbffnc.c
  * src/rtl/hbgtcore.c
  * src/rtl/cdpapi.c
  * src/rtl/dirdrive.c
  * src/rtl/hbi18n1.c
  * src/rtl/gtclip.c
  * src/rtl/mlcfunc.c
  * src/rtl/gtapiu.c
  * src/rtl/accept.c
  * src/rtl/idle.c
  * src/rtl/itemseri.c
  * src/rtl/hbrunfun.c
  * src/rtl/setcolor.c
  * src/rtl/setkey.c
  * src/rtl/gtsln/mousesln.c
  * src/rtl/gtsln/gtsln.c
  * src/rtl/gtsln/kbsln.c
  * src/rtl/gtsln/gtsln.h
  * src/rtl/disksphb.c
  * src/rtl/strc.c
  * src/rtl/gtpca/gtpca.c
  * src/rtl/gtgui/gtgui.c
  * src/rtl/hbhex.c
  * src/rtl/trace.c
  * src/rtl/gt_tpl/gt_tpl.c
  * src/rtl/inkeyapi.c
  * src/rtl/filebuf.c
  * src/rtl/gete.c
  * src/rtl/setcurs.c
  * src/rtl/hbproces.c
  * src/rtl/langapi.c
  * src/rtl/gtwvt/gtwvt.h
  * src/rtl/gtwvt/gtwvt.c
  * src/rtl/mouse53.c
  * src/rtl/fssize.c
  * src/rtl/hbbyte.c
  * src/rtl/mouseapi.c
  * src/rtl/memofile.c
  * src/rtl/valtostr.c
  * src/rtl/file.c
  * src/rtl/val.c
  * src/rtl/rat.c
  * src/rdd/hbsix/sxcompr.c
  * include/hbvmpub.h
  * include/hbset.h
  * include/hbapicdp.h
  * include/hbstack.h
  * include/hbapilng.h
  * include/hbgtcore.h
  * include/hbapifs.h
  * include/hbthread.h
  * include/hbxvm.h
  * include/hbmacro.h
  * include/hbtypes.h
  * include/hbapi.h
  * include/hbapiitm.h
  * include/hbznet.h
  * include/hbvm.h
  * include/hbapidbg.h
  * include/hbcomp.h
  * include/hbsxfunc.h
  * include/hbcompdf.h
  * include/hbmather.h
  * include/hbapistr.h
  * include/hbwmain.c
  * include/hbexpra.c
  * include/hbexprop.h
  * include/hbsocket.h
  * include/hbapigt.h
  * include/hbapicls.h
  * include/hbhash.h
  * include/hbregex.h
  * include/hbexprb.c
  * include/hbdate.h
  * contrib/gtalleg/gtalleg.c
  * contrib/xhb/hboutdbg.c
  * contrib/xhb/hbserv.h
  * contrib/xhb/bkgtsks.c
  * contrib/xhb/dbf2txt.c
  * contrib/xhb/xhbis.c
  * contrib/xhb/fparse.c
  * contrib/xhb/xhb.h
  * contrib/xhb/xhbsave.c
  * contrib/xhb/xhbmsgs.c
  * contrib/xhb/freadlin.c
  * contrib/xhb/txtline.c
  * contrib/xhb/dbgfxc.c
  * contrib/xhb/xhberrc.c
  * contrib/xhb/filestat.c
  * contrib/xhb/xhbcopyf.c
  * contrib/xhb/hbnxs.h
  * contrib/xhb/hbserv.c
  * contrib/xhb/cstructc.c
  * contrib/xhb/xhbfunc.c
  * contrib/hbmzip/hbmzip.c
  * contrib/gtqtc/gtqtc.cpp
  * contrib/gtwvg/gtwvg.c
  * contrib/gtwvg/gtwvg.h
  * contrib/gtwvg/wvggui.c
  * contrib/gtwvg/wvgcuig.c
  * contrib/gtwvg/wvggui.h
  * contrib/gtwvg/wvgwin.c
  * contrib/gtwvg/wvgutils.c
  * contrib/gtwvg/wvgcore.c
  * contrib/gtwvg/wvgwing.c
  * contrib/hbmisc/hb_f.c
  * contrib/hbmisc/dates2.c
  * contrib/hbwin/hbwapi.h
  * contrib/hbbtree/tests/ctest.c
    * BOOL  -> HB_BOOL
    * TRUE  -> HB_TRUE
    * FALSE -> HB_FALSE
    ; If possible please try to verify me, at least your own are of interest
      or expertise. Look for HB_BOOL/HB_TRUE/HB_FALSE usage in WINAPI calls,
      if you see such thing, it's wrong. Also some, HB_BOOL WINAPI BOOL
      implicit conversions may need to be cleaned.
    ; I didn't touch PP, RDD, SDD and compiler parts yet.
    ; In few places it's possible that some in-line comments are disaligned
      after this operation.
2010-01-14 17:59:30 +00:00

225 lines
10 KiB
C

/*
* $Id$
*/
/*
* Harbour Project source code:
* hb_BTree api test
*
* Copyright 2000 April White <april@users.sourceforge.net>
* www - http://www.harbour-project.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version, with one exception:
*
* The exception is that if you link the Harbour Runtime Library (HRL)
* and/or the Harbour Virtual Machine (HVM) with other files to produce
* an executable, this does not by itself cause the resulting executable
* to be covered by the GNU General Public License. Your use of that
* executable is in no way restricted on account of linking the HRL
* and/or HVM code into it.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA (or visit
* their web site at http://www.gnu.org/).
*
*/
#include "hbapi.h"
#include "hbapiitm.h"
#include "hb_btree.h"
static void display( const char *cKey, LONG lData, HB_BOOL NewLine )
{
int n;
char buffer[ 80 ];
if( *cKey )
n = hb_snprintf( buffer, sizeof( buffer ), "%s %ld", cKey, lData );
else
n = hb_snprintf( buffer, sizeof( buffer ), "%ld", lData );
hb_conOutStd( buffer, n );
if( NewLine )
hb_conOutStd( hb_conNewLine(), strlen( hb_conNewLine() ) );
}
static void insertdata( struct hb_BTree * pBTree )
{
PHB_ITEM data = hb_itemNew( NULL );
hb_BTreeInsert( pBTree, "fuweqgsz", hb_itemPutNL( data, 1 ) );
hb_BTreeInsert( pBTree, "sjruexrd", hb_itemPutNL( data, 2 ) );
hb_BTreeInsert( pBTree, "fvveitnz", hb_itemPutNL( data, 3 ) );
hb_BTreeInsert( pBTree, "aqgksjxe", hb_itemPutNL( data, 4 ) );
hb_BTreeInsert( pBTree, "oonrehvj", hb_itemPutNL( data, 5 ) );
hb_BTreeInsert( pBTree, "gvowjwtr", hb_itemPutNL( data, 6 ) );
hb_BTreeInsert( pBTree, "xxidwtvn", hb_itemPutNL( data, 7 ) );
hb_BTreeInsert( pBTree, "rwjbxesd", hb_itemPutNL( data, 8 ) );
hb_BTreeInsert( pBTree, "yaznsaek", hb_itemPutNL( data, 9 ) );
hb_BTreeInsert( pBTree, "wbdhfkfy", hb_itemPutNL( data, 10 ) );
hb_BTreeInsert( pBTree, "lryaezia", hb_itemPutNL( data, 11 ) );
hb_BTreeInsert( pBTree, "tspmnrvk", hb_itemPutNL( data, 12 ) );
hb_BTreeInsert( pBTree, "hpxryhdj", hb_itemPutNL( data, 13 ) );
hb_BTreeInsert( pBTree, "sztcqaby", hb_itemPutNL( data, 14 ) );
hb_BTreeInsert( pBTree, "fcyzsqja", hb_itemPutNL( data, 15 ) );
hb_BTreeInsert( pBTree, "uccxumvg", hb_itemPutNL( data, 16 ) );
hb_BTreeInsert( pBTree, "amwuoout", hb_itemPutNL( data, 17 ) );
hb_BTreeInsert( pBTree, "yaytseln", hb_itemPutNL( data, 18 ) );
hb_BTreeInsert( pBTree, "sfiiozej", hb_itemPutNL( data, 19 ) );
hb_BTreeInsert( pBTree, "xuvsoljy", hb_itemPutNL( data, 20 ) );
hb_BTreeInsert( pBTree, "qmqjbedm", hb_itemPutNL( data, 21 ) );
hb_BTreeInsert( pBTree, "cctzzrkz", hb_itemPutNL( data, 22 ) );
hb_BTreeInsert( pBTree, "ikytgdon", hb_itemPutNL( data, 23 ) );
hb_BTreeInsert( pBTree, "pksobcwu", hb_itemPutNL( data, 24 ) );
hb_BTreeInsert( pBTree, "vmurindj", hb_itemPutNL( data, 25 ) );
hb_BTreeInsert( pBTree, "elvybqwg", hb_itemPutNL( data, 26 ) );
hb_BTreeInsert( pBTree, "ixchaztx", hb_itemPutNL( data, 27 ) );
hb_BTreeInsert( pBTree, "nzpztlhd", hb_itemPutNL( data, 28 ) );
hb_BTreeInsert( pBTree, "aucrchiw", hb_itemPutNL( data, 29 ) );
hb_BTreeInsert( pBTree, "munrytse", hb_itemPutNL( data, 30 ) );
hb_BTreeInsert( pBTree, "kqkhcmls", hb_itemPutNL( data, 31 ) );
hb_BTreeInsert( pBTree, "abqhurbi", hb_itemPutNL( data, 32 ) );
hb_BTreeInsert( pBTree, "ymrldckr", hb_itemPutNL( data, 33 ) );
hb_BTreeInsert( pBTree, "rhsmfflc", hb_itemPutNL( data, 34 ) );
hb_BTreeInsert( pBTree, "apyfkvee", hb_itemPutNL( data, 35 ) );
hb_BTreeInsert( pBTree, "cdntyzrf", hb_itemPutNL( data, 36 ) );
hb_BTreeInsert( pBTree, "iacblqrh", hb_itemPutNL( data, 37 ) );
hb_BTreeInsert( pBTree, "xvewqana", hb_itemPutNL( data, 38 ) );
hb_BTreeInsert( pBTree, "xmybqytj", hb_itemPutNL( data, 39 ) );
hb_BTreeInsert( pBTree, "dnowympf", hb_itemPutNL( data, 40 ) );
hb_BTreeInsert( pBTree, "smloihft", hb_itemPutNL( data, 41 ) );
hb_BTreeInsert( pBTree, "zumppmis", hb_itemPutNL( data, 42 ) );
hb_BTreeInsert( pBTree, "jirucnxu", hb_itemPutNL( data, 43 ) );
hb_BTreeInsert( pBTree, "ecdzikcv", hb_itemPutNL( data, 44 ) );
hb_BTreeInsert( pBTree, "slbwvnpg", hb_itemPutNL( data, 45 ) );
hb_BTreeInsert( pBTree, "yaftlkmz", hb_itemPutNL( data, 46 ) );
hb_BTreeInsert( pBTree, "blcepksd", hb_itemPutNL( data, 47 ) );
hb_BTreeInsert( pBTree, "xufowlpl", hb_itemPutNL( data, 48 ) );
hb_BTreeInsert( pBTree, "xegtjtqc", hb_itemPutNL( data, 49 ) );
hb_BTreeInsert( pBTree, "yplcqumq", hb_itemPutNL( data, 50 ) );
hb_BTreeInsert( pBTree, "vdoycauz", hb_itemPutNL( data, 51 ) );
hb_BTreeInsert( pBTree, "uhqkjuph", hb_itemPutNL( data, 52 ) );
hb_BTreeInsert( pBTree, "prllaeyi", hb_itemPutNL( data, 53 ) );
hb_BTreeInsert( pBTree, "ybzgmwzm", hb_itemPutNL( data, 54 ) );
hb_BTreeInsert( pBTree, "kkvyllnp", hb_itemPutNL( data, 55 ) );
hb_BTreeInsert( pBTree, "nberwsrb", hb_itemPutNL( data, 56 ) );
hb_BTreeInsert( pBTree, "wgetahua", hb_itemPutNL( data, 57 ) );
hb_BTreeInsert( pBTree, "yxcyehcv", hb_itemPutNL( data, 58 ) );
hb_BTreeInsert( pBTree, "oacormks", hb_itemPutNL( data, 59 ) );
hb_BTreeInsert( pBTree, "mcadkdxo", hb_itemPutNL( data, 60 ) );
hb_BTreeInsert( pBTree, "ycsalwqw", hb_itemPutNL( data, 61 ) );
hb_BTreeInsert( pBTree, "qmpysvjl", hb_itemPutNL( data, 62 ) );
hb_BTreeInsert( pBTree, "iqikamew", hb_itemPutNL( data, 63 ) );
hb_BTreeInsert( pBTree, "iaparrva", hb_itemPutNL( data, 64 ) );
hb_BTreeInsert( pBTree, "casbvtay", hb_itemPutNL( data, 65 ) );
hb_BTreeInsert( pBTree, "blaksexr", hb_itemPutNL( data, 66 ) );
hb_BTreeInsert( pBTree, "tbosrbql", hb_itemPutNL( data, 67 ) );
hb_BTreeInsert( pBTree, "ifkywsyt", hb_itemPutNL( data, 68 ) );
hb_BTreeInsert( pBTree, "gvklwevy", hb_itemPutNL( data, 69 ) );
hb_BTreeInsert( pBTree, "krpmpbud", hb_itemPutNL( data, 70 ) );
hb_BTreeInsert( pBTree, "rdvlwbwm", hb_itemPutNL( data, 71 ) );
hb_BTreeInsert( pBTree, "apnvdkww", hb_itemPutNL( data, 72 ) );
hb_BTreeInsert( pBTree, "euqdocvm", hb_itemPutNL( data, 73 ) );
hb_BTreeInsert( pBTree, "ksmkjcwp", hb_itemPutNL( data, 74 ) );
hb_BTreeInsert( pBTree, "bztgclzc", hb_itemPutNL( data, 75 ) );
hb_BTreeInsert( pBTree, "awkdnuxa", hb_itemPutNL( data, 76 ) );
hb_BTreeInsert( pBTree, "abavnpod", hb_itemPutNL( data, 77 ) );
hb_BTreeInsert( pBTree, "dvwvhjmh", hb_itemPutNL( data, 78 ) );
hb_BTreeInsert( pBTree, "dmfmivqb", hb_itemPutNL( data, 79 ) );
hb_BTreeInsert( pBTree, "ewsxanon", hb_itemPutNL( data, 80 ) );
hb_itemRelease( data );
}
HB_FUNC( CTEST )
{
struct hb_BTree * pBTree;
display( "Harbour API test", 0, HB_TRUE );
pBTree = hb_BTreeNew( "test_3.out", 2048, 90, HB_BTREE_UNIQUE, 0 );
if ( pBTree != NULL )
{
/*
a := hb_BTreeInfo( pBTree );
display( "File", a[ hb_BTreeINFO_FILENAME ], HB_FALSE );
display( "Page", a[ hb_BTreeINFO_PAGESIZE ], HB_FALSE );
display( "Key ", a[ hb_BTreeINFO_KEYSIZE ], HB_FALSE );
display( "Max ", a[ hb_BTreeINFO_MAXKEYS ], HB_FALSE );
display( "Min ", a[ hb_BTreeINFO_MINKEYS ], HB_FALSE );
display( "Flag", a[ hb_BTreeINFO_FLAGS ], HB_FALSE );
display( "Keys", a[ hb_BTreeINFO_KEYCOUNT ], HB_TRUE );
*/
insertdata( pBTree );
/*
display( "Keys", hb_BTreeInfo( pBTree, hb_BTreeINFO_KEYCOUNT ), HB_TRUE );
*/
display( "Forward traversal", 0, HB_TRUE );
hb_BTreeGoTop( pBTree );
while ( HB_TRUE )
{
display( ( char * ) hb_BTreeKey( pBTree ), hb_BTreeData( pBTree ), HB_TRUE );
if ( 1 != hb_BTreeSkip( pBTree, 1 ) )
break;
}
hb_conOutStd( hb_conNewLine(), strlen( hb_conNewLine() ) );
display( "Reverse traversal", 0, HB_TRUE );
hb_BTreeGoBottom( pBTree );
while ( HB_TRUE )
{
display( ( char * ) hb_BTreeKey( pBTree ), hb_BTreeData( pBTree ), HB_TRUE );
if ( -1 != hb_BTreeSkip( pBTree, -1 ) )
break;
}
hb_conOutStd( hb_conNewLine(), strlen( hb_conNewLine() ) );
display( "Test SEEK", 0, HB_TRUE );
display( hb_BTreeSeek( pBTree, "cdntyzrf", 36, HB_FALSE ) == 1 ? ".T." : ".F.", 0, HB_TRUE );
display( ( char * ) hb_BTreeKey( pBTree ), hb_BTreeData( pBTree ), HB_TRUE );
hb_BTreeSkip( pBTree, 1 );
display( ( char * ) hb_BTreeKey( pBTree ), hb_BTreeData( pBTree ), HB_FALSE );
display( " dmfmivqb ?", 0, HB_TRUE );
hb_conOutStd( hb_conNewLine(), strlen( hb_conNewLine() ) );
display( "Test soft SEEK of a short key", 0, HB_TRUE );
display( hb_BTreeSeek( pBTree, "cd", 0, HB_TRUE ) == 1 ? ".T." : ".F.", 0, HB_TRUE );
display( ( char * ) hb_BTreeKey( pBTree ), hb_BTreeData( pBTree ), HB_TRUE );
hb_BTreeSkip( pBTree, 1 );
display( ( char * ) hb_BTreeKey( pBTree ), hb_BTreeData( pBTree ), HB_FALSE );
display( " dmfmivqb ?", 0, HB_TRUE );
hb_conOutStd( hb_conNewLine(), strlen( hb_conNewLine() ) );
display( "Test soft SEEK of an existing key", 0, HB_TRUE );
display( hb_BTreeSeek( pBTree, "cdntyzrf", 0, HB_TRUE ) == 1 ? ".T." : ".F.", 0, HB_TRUE );
display( ( char * ) hb_BTreeKey( pBTree ), hb_BTreeData( pBTree ), HB_TRUE );
hb_BTreeSkip( pBTree, 1 );
display( ( char * ) hb_BTreeKey( pBTree ), hb_BTreeData( pBTree ), HB_FALSE );
display( " dmfmivqb ?", 0, HB_TRUE );
hb_conOutStd( hb_conNewLine(), strlen( hb_conNewLine() ) );
display( "Test soft SEEK of a missing key, that should force EOF", 0, HB_TRUE );
display( hb_BTreeSeek( pBTree, "zzzzzz", 0, HB_FALSE ) == 1 ? ".T." : ".F.", 0, HB_TRUE );
display( ( char * ) hb_BTreeKey( pBTree ), hb_BTreeData( pBTree ), HB_TRUE );
hb_BTreeSkip( pBTree, 1 );
display( ( char * ) hb_BTreeKey( pBTree ), hb_BTreeData( pBTree ), HB_FALSE );
display( " dmfmivqb ?", 0, HB_TRUE );
hb_conOutStd( hb_conNewLine(), strlen( hb_conNewLine() ) );
hb_BTreeClose( pBTree );
}
else
display( "error / failure", 0, HB_TRUE );
}