1 /*
2  pblSetTest.c - pbl set test frame
3 
4  Copyright (C) 2008   Peter Graf
5 
6    This file is part of PBL - The Program Base Library.
7    PBL is free software.
8 
9     This program is free software; you can redistribute it and/or modify
10     it under the terms of the GNU General Public License as published by
11     the Free Software Foundation; either version 2 of the License, or
12     (at your option) any later version.
13 
14     This program is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17     GNU General Public License for more details.
18 
19     You should have received a copy of the GNU General Public License
20     along with this program; if not, write to the Free Software
21     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22 
23    For more information on the Program Base Library or Peter Graf,
24    please see: http://www.mission-base.com/.
25 
26     $Log: pblSetTest.c,v $
27     Revision 1.21  2010/08/14 20:10:30  peter
28     Cleanup during linux tests of pblPriorityQueue interface.
29 
30     Revision 1.20  2010/05/19 22:38:45  peter
31     Testing the map.
32 
33     Revision 1.19  2009/11/26 18:45:55  peter
34     activated set test
35 
36     Revision 1.18  2009/10/20 21:08:00  peter
37     Added the pblHtCurrentKey function.
38 
39     Revision 1.17  2009/09/03 20:48:59  peter
40     Just some cleanup on sets.
41 
42     Revision 1.16  2009/03/27 23:56:23  peter
43     Some cleanup
44 
45     Revision 1.15  2009/03/11 23:48:44  peter
46     More tests and clean up.
47 
48     Revision 1.14  2009/03/08 20:56:50  peter
49     port to gcc (Ubuntu 4.3.2-1ubuntu12) 4.3.2.
50     Exposing the hash set and tree set interfaces.
51 
52 
53 
54 */
55 
56 /*
57  * make sure "strings <exe> | grep Id | sort -u" shows the source file versions
58  */
59 char* pblSetTest_c_id = "$Id: pblSetTest.c,v 1.21 2010/08/14 20:10:30 peter Exp $";
60 
61 #include <stdio.h>
62 #include <string.h>
63 #include <errno.h>
64 #include <stdlib.h>
65 
66 #include "pbl.h"
67 
68 static FILE * log;
69 static FILE * infile;
70 
putChar(int c)71 static void putChar( int c )
72 {
73    static int last = 0;
74 
75    if( last == '\n' && c == '\n' )
76        return;
77 
78    last = c;
79    ( void ) putc( last, log );
80 }
81 
getChar(void)82 static int getChar( void )
83 {
84     int c;
85     c = getc( infile );
86 
87     /*
88      * a '#' starts a comment for the rest of the line
89      */
90     if( c == '#')
91     {
92        while( c != '\n' && c != EOF )
93        {
94            c = getc( infile );
95        }
96     }
97 
98     if( c != EOF )
99         putChar( c );
100 
101     return( c );
102 }
103 
104 
getWord(char * buffer)105 static void getWord( char * buffer )
106 {
107     int c;
108 
109     /*
110      * skip preceeding blanks
111      */
112     c = ' ';
113     while( c== '\t' || c == ' ' || c == '\n' )
114         c = getChar();
115 
116     /*
117      * read one word
118      */
119     for(;; c = getChar())
120     {
121         if( c == EOF )
122         {
123             exit( 0 );
124         }
125 
126         if( c== '\t' || c == ' ' || c == '\n' )
127         {
128             *buffer = '\0';
129             return;
130         }
131 
132         *buffer++ = c;
133     }
134 }
135 
136 static char * items[] = {
137         "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
138         "10", "11", "12", "13", "14", "15", "16", "17", "18", "19",
139         "20", "21", "22", "23", "24", "25", "26", "27", "28", "29"
140 };
141 
142 #if 0
143 int isPrime( unsigned int number )
144 {
145     unsigned int i;
146     for( i = 3; i < number / 2; i += 2 )
147     {
148         if( number / i * i == number )
149         {
150             return 0;
151         }
152     }
153 
154     return 1;
155 }
156 
157 void printPower2Primes()
158 {
159     unsigned int i = 1;
160     unsigned int j;
161     for( j = ( 1 << i++ ) + 1; i < 30; j = ( 1 << i++ ) + 1 )
162     {
163         unsigned int number = 0;
164         for( number = j; number < 0xfffffff; number += 2 )
165         {
166             if( isPrime( number ))
167             {
168                 printf( "%u\n", number );
169                 break;
170             }
171         }
172     }
173     exit( 0 );
174 }
175 #endif
176 
177 typedef struct pblTestAggregationContext
178 {
179     int counter;
180     FILE * log;
181     FILE * out;
182 } pblTestAggregationContext;
183 
aggregation(void * context,int index,void * element)184 static int aggregation              /** Test aggregation function. */
185     (
186         void * context,      /** The application context passed.                              */
187         int index,           /** The index of the element passed.                             */
188         void * element       /** The collection element to aggregate.                         */
189     )
190 {
191     pblTestAggregationContext * pblTestContext = (pblTestAggregationContext *)context;
192 
193     if( pblTestContext->counter <= 0 )
194     {
195         return 1; /* break the aggregation */
196     }
197 
198     fprintf( pblTestContext->out, "# aggregation counter %d, i %d, element %s\n", pblTestContext->counter, index, (char*)element );
199     fprintf( pblTestContext->log, "# aggregation counter %d, i %d, element %s\n", pblTestContext->counter, index, (char*)element );
200 
201     pblTestContext->counter--;
202 
203     return 0; /* continue aggregation */
204 }
205 
206 /**
207  * test frame for the library
208  */
pblSet_TestFrame(int argc,char * argv[])209 int pblSet_TestFrame( int argc, char * argv[] )
210 {
211     char command[ 2048 ];
212     char filename [ 2048 ];
213     char buffer [ 2048 ];
214     int  ival;
215     int  dowork = 1;
216     long rc;
217     int  i;
218 
219     char * ptr;
220 
221     PblSet * testCollection = ( PblSet *) 0;
222     PblIterator * testIterator = (PblIterator *) 0;
223 
224 #if 0
225     printPower2Primes();
226 #endif
227 
228     infile = stdin;
229     if( argc > 1 )
230     {
231         infile = fopen( argv[ 1 ], "r" );
232         if( !infile )
233         {
234             fprintf( stderr, "Failed to open %s, %s\n",
235                      argv[ 1 ], strerror( errno ));
236             exit( -1 );
237         }
238     }
239 
240     log = fopen( "./pblSetTest.log", "w" );
241     if( !log )
242     {
243         fprintf( stderr, "cant open logfile, .\\pblSetTest.log\n" );
244         exit( 1 );
245     }
246 
247     while( dowork )
248     {
249         memset( command, 0, sizeof( command ));
250         memset( filename, 0, sizeof( filename ));
251         memset( buffer, 0, sizeof( buffer ));
252 
253         errno = 0;
254 
255         printf( "\n##command: \n" );
256         fprintf( log, "\n##command: \n" );
257 
258         getWord( command );
259 
260         if( command[0] == 'q' || command[0] == 'Q' )
261         {
262             dowork = 0;
263         }
264 
265         else if( !strcmp( command, "createTreeSet" ))
266         {
267             printf( "# pblSetNewTreeSet( void )\n" );
268             fprintf( log, "# pblSetNewTreeSet( void )\n" );
269 
270             if( testCollection )
271             {
272                 ( void ) pblSetFree( testCollection );
273             }
274 
275             testCollection = pblSetNewTreeSet( );
276 
277             if( testCollection )
278             {
279                 printf( "# ok!\n" );
280                 fprintf( log, "# ok!\n" );
281             }
282             else
283             {
284                 printf( "# pbl_errno %d\n", pbl_errno );
285                 fprintf( log, "# pbl_errno %d\n", pbl_errno );
286             }
287         }
288 
289         else if( !strcmp( command, "createHashSet" ))
290         {
291             printf( "# pblSetNewHashSet( void )\n" );
292             fprintf( log, "# pblSetNewHashSet( void )\n" );
293 
294             if( testCollection )
295             {
296                 ( void ) pblSetFree( testCollection );
297             }
298 
299             testCollection = pblSetNewHashSet( );
300 
301             if( testCollection )
302             {
303                 printf( "# ok!\n" );
304                 fprintf( log, "# ok!\n" );
305             }
306             else
307             {
308                 printf( "# pbl_errno %d\n", pbl_errno );
309                 fprintf( log, "# pbl_errno %d\n", pbl_errno );
310             }
311         }
312 
313         else if( !strcmp( command, "aggregate" ))
314         {
315             pblTestAggregationContext pblTestContext;
316 
317             if( !testCollection )
318                 continue;
319 
320             printf( "# aggregate counter\n" );
321             fprintf( log, "# aggregate counter\n" );
322 
323             getWord( buffer );
324             pblTestContext.counter = atoi( buffer );
325             pblTestContext.log = log;
326             pblTestContext.out = stdout;
327 
328             printf( "# pblCollectionAggregate( %d )\n", pblTestContext.counter );
329             fprintf( log, "# pblCollectionAggregate( %d )\n", pblTestContext.counter );
330 
331             rc = pblCollectionAggregate( testCollection, &pblTestContext, aggregation );
332 
333             printf( "# rc %ld\n", rc );
334             fprintf( log, "# rc %ld\n", rc );
335         }
336 
337 
338         else if( !strcmp( command, "free" ))
339         {
340             if( !testCollection )
341                 continue;
342 
343             printf( "# pblSetFree( %d )\n", 1 );
344             fprintf( log, "# pblSetFree( %d )\n", 1 );
345 
346             pblSetFree( testCollection );
347             testCollection = ( PblSet * ) 0;
348 
349             printf( "# ok" );
350             fprintf( log, "# ok\n" );
351         }
352 
353         else if( !strcmp( command, "add" ))
354         {
355             if( !testCollection )
356                 continue;
357 
358             printf( "# add itemIndex\n" );
359             fprintf( log, "# add itemIndex\n" );
360 
361             getWord( buffer );
362             ival = atoi( buffer );
363             if( ival < 0)
364             {
365                 ptr = NULL;
366             }
367             else
368             {
369                 ptr = items[ ival ];
370             }
371 
372             printf( "# pblSetAdd( %s )\n",
373                     ptr ? ptr : "NULL" );
374 
375             fprintf( log, "# pblSetAdd( %s )\n",
376                      ptr ? ptr : "NULL" );
377 
378             rc = pblSetAdd( testCollection, ptr );
379 
380             if( rc < 0 )
381             {
382                 printf( "# rc %ld, pbl_errno %d\n",
383                         rc, pbl_errno );
384                 fprintf( log, "# rc %ld, pbl_errno %d\n",
385                         rc, pbl_errno );
386                 break;
387             }
388 
389             printf( "# rc %ld\n", rc );
390             fprintf( log, "# rc %ld\n", rc );
391         }
392 
393         else if( !strcmp( command, "addAll" ))
394         {
395             PblSet * clone = ( PblSet *) 0;
396 
397             if( !testCollection )
398                 continue;
399 
400             printf( "# pblSetAddAll( %d )\n", 1 );
401             fprintf( log, "# pblSetAddAll( %d )\n", 1 );
402 
403             clone = pblSetCloneRange( testCollection, 0, 0 );
404             if( !clone )
405             {
406                 printf( "# rc %ld, pbl_errno %d\n",
407                         (long)-1, pbl_errno );
408                 fprintf( log, "# rc %ld, pbl_errno %d\n",
409                         (long)-1, pbl_errno );
410                 break;
411             }
412 
413             rc = pblSetAddAll( clone, testCollection );
414 
415             if( rc < 0 )
416             {
417                 printf( "# rc %ld, pbl_errno %d\n",
418                         rc, pbl_errno );
419                 fprintf( log, "# rc %ld, pbl_errno %d\n",
420                         rc, pbl_errno );
421                 pblSetFree( clone );
422                 break;
423             }
424 
425             pblSetPrint( stdout, clone );
426             pblSetPrint( log, clone );
427 
428             printf( "# rc %ld\n", rc );
429             fprintf( log, "# rc %ld\n", rc );
430             pblSetFree( clone );
431         }
432 
433         else if( !strcmp( command, "clear" ))
434         {
435             if( !testCollection )
436                 continue;
437 
438             printf( "# pblSetClear( %d )\n", 1 );
439             fprintf( log, "# pblSetClear( %d )\n", 1 );
440 
441             pblSetClear( testCollection );
442 
443             printf( "# ok" );
444             fprintf( log, "# ok\n" );
445         }
446 
447         else if( !strcmp( command, "clone" ) )
448         {
449             PblSet * clone;
450 
451             if( !testCollection )
452                 continue;
453 
454             printf( "# pblSetClone( %d )\n", 1 );
455             fprintf( log, "# pblSetClone( %d )\n", 1 );
456 
457             clone = pblSetClone( testCollection );
458             if( !clone )
459             {
460                 printf( "# NULL, pbl_errno %d\n", pbl_errno );
461                 fprintf( log, "# NULL, pbl_errno %d\n", pbl_errno );
462                 break;
463             }
464 
465             printf( "# ok size %d", 1 );
466             fprintf( log, "# ok size %d\n", 1 );
467 
468             pblSetFree( clone );
469         }
470 
471         else if( !strcmp( command, "cloneRange" ))
472         {
473             PblSet * clone;
474             char ** array;
475 
476             if( !testCollection )
477                 continue;
478 
479             printf( "# cloneRange from to \n" );
480             fprintf( log, "# cloneRange from to\n" );
481 
482             getWord( buffer );
483             ival = atoi( buffer );
484 
485             getWord( command );
486             i = atoi( command );
487 
488             printf( "# pblSetCloneRange( %d, %d )\n", ival, i );
489             fprintf( log, "# pblSetCloneRange( %d, %d )\n",ival, i );
490 
491             clone = pblSetCloneRange( testCollection, ival, i );
492             if( !clone )
493             {
494                 printf( "# NULL, pbl_errno %d\n", pbl_errno );
495                 fprintf( log, "# NULL, pbl_errno %d\n", pbl_errno );
496                 continue;
497             }
498 
499             if( pblSetSize( clone ) == 0 )
500             {
501                 printf( "# OK size %d\n", pblSetSize( clone ) );
502                 fprintf( log, "# OK size %d\n", pblSetSize( clone ) );
503                 pblSetFree( clone );
504                 continue;
505             }
506 
507             printf( "# pblSetToArray( clone )\n" );
508             fprintf( log, "# pblSetToArray( clone )\n" );
509 
510             array = (char**)pblSetToArray( clone );
511             if( array == NULL )
512             {
513                 printf( "# NULL, pbl_errno %d\n",
514                         pbl_errno );
515                 fprintf( log, "# NULL, pbl_errno %d\n",
516                         pbl_errno );
517                 pblSetFree( clone );
518                 continue;
519             }
520 
521             printf( "# OK size %d\n", pblSetSize( clone ) );
522             fprintf( log, "# OK size %d\n", pblSetSize( clone ) );
523 
524             for( i = 0; i < pblSetSize( clone ); i++ )
525             {
526                 char * item =  array[i];
527 
528                 printf( "# OK i %d, %s\n", i, item != NULL ? item : "NULL" );
529                 fprintf( log, "# OK i %d, %s\n", i, item != NULL ? item : "NULL" );
530             }
531 
532             PBL_FREE(array );
533 
534             printf( "# Clone Iteration DONE\n" );
535             fprintf( log, "# Clone Iteration DONE\n" );
536 
537             pblSetFree( clone );
538         }
539 
540         else if( !strcmp( command, "contains" ))
541         {
542             if( !testCollection )
543                 continue;
544 
545             printf( "# contains itemIndex\n" );
546             fprintf( log, "# contains itemIndex\n" );
547 
548             getWord( buffer );
549             ival = atoi( buffer );
550             if( ival < 0)
551             {
552                 ptr = NULL;
553             }
554             else
555             {
556                 ptr = items[ ival ];
557             }
558 
559             printf( "# pblSetContains( %s )\n",
560                     ptr ? ptr : "NULL" );
561 
562             fprintf( log, "# pblSetContains( %s )\n",
563                      ptr ? ptr : "NULL" );
564 
565             rc = pblSetContains( testCollection, ptr );
566 
567             printf( "# rc %ld\n", rc );
568             fprintf( log, "# rc %ld\n", rc );
569         }
570 
571         else if( !strcmp( command, "containsAll" ) )
572         {
573             PblSet * clone;
574 
575             if( !testCollection )
576                 continue;
577 
578             printf( "# pblSetPrint( original )\n" );
579             fprintf( log, "# pblSetPrint( original )\n" );
580 
581             pblSetPrint( stdout, testCollection );
582             pblSetPrint( log, testCollection );
583 
584             printf( "# pblSetClone( %d )\n", 1 );
585             fprintf( log, "# pblSetClone( %d )\n", 1 );
586 
587             clone = pblSetClone( testCollection );
588             if( !clone )
589             {
590                 printf( "# NULL, pbl_errno %d\n", pbl_errno );
591                 fprintf( log, "# NULL, pbl_errno %d\n", pbl_errno );
592                 break;
593             }
594 
595             printf( "# pblSetPrint( clone )\n" );
596             fprintf( log, "# pblSetPrint( clone )\n" );
597 
598             pblSetPrint( stdout, clone );
599             pblSetPrint( log, clone );
600 
601             printf( "\n# pblSetContainsAll( %d, YES )\n", 1 );
602             fprintf( log, "# pblSetContainsAll( %d, YES )\n", 1 );
603 
604             rc = pblSetContainsAll( testCollection, clone );
605             if( rc < 0 )
606             {
607                 printf( "# rc %ld, pbl_errno %d\n", rc, pbl_errno );
608                 fprintf( log, "# rc %ld, pbl_errno %d\n", rc, pbl_errno );
609                 break;
610             }
611 
612             printf( "# rc %ld\n", rc );
613             fprintf( log, "# rc %ld\n", rc );
614 
615             printf( "# pblSetAdd( %d, NotFound )\n", 1 );
616             fprintf( log, "# pblSetAdd( %d, NotFound )\n", 1 );
617 
618             rc = pblSetAdd(clone, "NotFound" );
619             if( rc < 0 )
620             {
621                 printf( "# rc %ld, pbl_errno %d\n", rc, pbl_errno );
622                 fprintf( log, "# rc %ld, pbl_errno %d\n", rc, pbl_errno );
623                 break;
624             }
625 
626             printf( "# pblSetContainsAll( %d, NO )\n", 1 );
627             fprintf( log, "# pblSetContainsAll( %d, NO )\n", 1 );
628 
629             rc = pblSetContainsAll( testCollection, clone );
630             if( rc < 0 )
631             {
632                 printf( "# rc %ld, pbl_errno %d\n", rc, pbl_errno );
633                 fprintf( log, "# rc %ld, pbl_errno %d\n", rc, pbl_errno );
634                 break;
635             }
636 
637             printf( "# rc %ld\n", rc );
638             fprintf( log, "# rc %ld\n", rc );
639 
640             pblSetFree( clone );
641         }
642 
643         else if( !strcmp( command, "difference" ) )
644         {
645             PblSet * clone;
646             PblSet * result;
647 
648             if( !testCollection )
649                 continue;
650 
651             printf( "# pblSetClone( %d )\n", 1 );
652             fprintf( log, "# pblSetClone( %d )\n", 1 );
653 
654             clone = pblSetClone( testCollection );
655             if( !clone )
656             {
657                 printf( "# NULL, pbl_errno %d\n", pbl_errno );
658                 fprintf( log, "# NULL, pbl_errno %d\n", pbl_errno );
659                 break;
660             }
661 
662             printf( "# ok size %d", pblSetSize( clone ) );
663             fprintf( log, "# ok size %d\n", pblSetSize( clone ) );
664 
665             printf( "\n# pblSetDifference( testSet, clone )\n" );
666             fprintf( log, "# pblSetDifference( testSet, clone )\n" );
667 
668             result = pblSetDifference( testCollection, clone );
669             if( !result )
670             {
671                 printf( "# result NULL, pbl_errno %d\n", pbl_errno );
672                 fprintf( log, "# result NULL, pbl_errno %d\n", pbl_errno );
673                 break;
674             }
675 
676             printf( "# pblSetPrint( difference )\n" );
677             fprintf( log, "# pblSetPrint( difference )\n" );
678 
679             pblSetPrint( stdout, result );
680             pblSetPrint( log, result );
681             pblSetFree( result );
682 
683             printf( "# pblSetRemoveFirst( clone )\n" );
684             fprintf( log, "# pblSetRemoveFirst( clone )\n" );
685 
686             ptr = pblSetRemoveFirst( clone );
687             if( !ptr )
688             {
689                 printf( "# result NULL, pbl_errno %d\n", pbl_errno );
690                 fprintf( log, "# result NULL, pbl_errno %d\n", pbl_errno );
691                 break;
692             }
693 
694             printf( "# OK %s\n", ptr );
695             fprintf( log, "# OK %s\n", ptr );
696 
697             printf( "# pblSetRemoveLast( clone )\n" );
698             fprintf( log, "# pblSetRemoveLast( clone )\n" );
699 
700             ptr = pblSetRemoveLast( clone );
701             if( !ptr )
702             {
703                 printf( "# result NULL, pbl_errno %d\n", pbl_errno );
704                 fprintf( log, "# result NULL, pbl_errno %d\n", pbl_errno );
705                 break;
706             }
707 
708             printf( "# OK %s\n", ptr );
709             fprintf( log, "# OK %s\n", ptr );
710 
711             printf( "\n# pblSetDifference( testSet, clone )\n" );
712             fprintf( log, "# pblSetDifference( testSet, clone )\n" );
713 
714             result = pblSetDifference( testCollection, clone );
715             if( !result )
716             {
717                 printf( "# result NULL, pbl_errno %d\n", pbl_errno );
718                 fprintf( log, "# result NULL, pbl_errno %d\n", pbl_errno );
719                 break;
720             }
721 
722             printf( "# pblSetPrint( difference )\n" );
723             fprintf( log, "# pblSetPrint( difference )\n" );
724 
725             pblSetPrint( stdout, result );
726             pblSetPrint( log, result );
727             pblSetFree( result );
728 
729             printf( "\n# pblSetDifference( clone, testSet )\n" );
730             fprintf( log, "# pblSetDifference( clone, testSet )\n" );
731 
732             result = pblSetDifference( clone, testCollection );
733             if( !result )
734             {
735                 printf( "# result NULL, pbl_errno %d\n", pbl_errno );
736                 fprintf( log, "# result NULL, pbl_errno %d\n", pbl_errno );
737                 break;
738             }
739 
740             printf( "# pblSetPrint( difference )\n" );
741             fprintf( log, "# pblSetPrint( difference )\n" );
742 
743             pblSetPrint( stdout, result );
744             pblSetPrint( log, result );
745 
746             pblSetFree( result );
747             pblSetFree( clone );
748         }
749 
750         else if( !strcmp( command, "element" ) )
751         {
752             if( !testCollection )
753                 continue;
754 
755             printf( "# pblSetElement( %d )\n", 1 );
756             fprintf( log, "# pblSetElement( %d )\n", 1 );
757 
758             ptr = pblSetElement( testCollection );
759             if( !ptr )
760             {
761                 printf( "# NOT FOUND, pbl_errno %d\n", pbl_errno );
762                 fprintf( log, "# NOT FOUND, pbl_errno %d\n", pbl_errno );
763             }
764             else
765             {
766                 printf( "# first %s", ptr );
767                 fprintf( log, "# first %s\n", ptr );
768             }
769         }
770 
771         else if( !strcmp( command, "ensureCapacity" ))
772         {
773             if( !testCollection )
774                 continue;
775 
776             printf( "# ensureCapacity minCapacity\n" );
777             fprintf( log, "# ensureCapacity minCapacity\n" );
778 
779             getWord( buffer );
780             ival = atoi( buffer );
781 
782             printf( "# ensureCapacity( %d )\n",
783                     ival );
784 
785             fprintf( log, "# ensureCapacity( %d )\n",
786                      ival );
787 
788             rc = pblSetEnsureCapacity( testCollection, ival );
789             if( rc < 0 )
790             {
791                 printf( "# rc %ld, pbl_errno %d\n", rc, pbl_errno );
792                 fprintf( log, "# rc %ld, pbl_errno %d\n", rc, pbl_errno );
793                 break;
794             }
795 
796             printf( "# rc %ld\n", rc );
797             fprintf( log, "# rc %ld\n", rc );
798         }
799 
800         else if( !strcmp( command, "equals" ) )
801         {
802             PblSet * clone;
803 
804             if( !testCollection )
805                 continue;
806 
807             printf( "# pblSetClone( %d )\n", 1 );
808             fprintf( log, "# pblSetClone( %d )\n", 1 );
809 
810             clone = pblSetClone( testCollection );
811             if( !clone )
812             {
813                 printf( "# NULL, pbl_errno %d\n", pbl_errno );
814                 fprintf( log, "# NULL, pbl_errno %d\n", pbl_errno );
815                 break;
816             }
817 
818             printf( "# ok size %d", pblSetSize( clone ) );
819             fprintf( log, "# ok size %d\n", pblSetSize( clone ) );
820 
821             printf( "\n# pblSetEquals( %d, YES )\n", 1 );
822             fprintf( log, "# pblSetEquals( %d, YES )\n", 1 );
823 
824             rc = pblSetEquals( testCollection, testCollection );
825             if( rc < 0 )
826             {
827                 printf( "# rc %ld, pbl_errno %d\n", rc, pbl_errno );
828                 fprintf( log, "# rc %ld, pbl_errno %d\n", rc, pbl_errno );
829                 break;
830             }
831 
832             printf( "# rc %ld\n", rc );
833             fprintf( log, "# rc %ld\n", rc );
834 
835             printf( "\n# pblSetEquals( %d, YES )\n", 1 );
836             fprintf( log, "# pblSetEquals( %d, YES )\n", 1 );
837 
838             rc = pblSetEquals( testCollection, clone );
839             if( rc < 0 )
840             {
841                 printf( "# rc %ld, pbl_errno %d\n", rc, pbl_errno );
842                 fprintf( log, "# rc %ld, pbl_errno %d\n", rc, pbl_errno );
843                 break;
844             }
845 
846             printf( "# rc %ld\n", rc );
847             fprintf( log, "# rc %ld\n", rc );
848 
849             printf( "# pblSetAdd( %d, NotFound )\n", 1 );
850             fprintf( log, "# pblSetAdd( %d, NotFound )\n", 1 );
851 
852             rc = pblSetAdd(clone, "NotFound" );
853             if( rc < 0 )
854             {
855                 printf( "# rc %ld, pbl_errno %d\n", rc, pbl_errno );
856                 fprintf( log, "# rc %ld, pbl_errno %d\n", rc, pbl_errno );
857                 break;
858             }
859 
860             printf( "# pblSetEquals( %d, NO )\n", 1 );
861             fprintf( log, "# pblSetEquals( %d, NO )\n", 1 );
862 
863             rc = pblSetEquals( testCollection, clone );
864             if( rc < 0 )
865             {
866                 printf( "# rc %ld, pbl_errno %d\n", rc, pbl_errno );
867                 fprintf( log, "# rc %ld, pbl_errno %d\n", rc, pbl_errno );
868                 break;
869             }
870 
871             printf( "# rc %ld\n", rc );
872             fprintf( log, "# rc %ld\n", rc );
873 
874             pblSetFree( clone );
875 
876             printf( "# pblCollectionConvertToArrayList( collection )\n");
877             fprintf( log, "# pblCollectionConvertToArrayList( collection )\n" );
878 
879             clone = pblCollectionConvertToArrayList( testCollection );
880             if( !clone )
881             {
882                 printf( "# NULL, pbl_errno %d\n", pbl_errno );
883                 fprintf( log, "# NULL, pbl_errno %d\n", pbl_errno );
884                 break;
885             }
886 
887             printf( "# ok size %d", pblSetSize( clone ) );
888             fprintf( log, "# ok size %d\n", pblSetSize( clone ) );
889 
890             printf( "\n# pblSetEquals( testcollection, clone ) YES\n" );
891             fprintf( log, "# pblSetEquals( testcollection, clone ) YES\n" );
892 
893             rc = pblSetEquals( testCollection, clone );
894             if( rc < 0 )
895             {
896                 printf( "# rc %ld, pbl_errno %d\n", rc, pbl_errno );
897                 fprintf( log, "# rc %ld, pbl_errno %d\n", rc, pbl_errno );
898                 break;
899             }
900 
901             printf( "# rc %ld\n", rc );
902             fprintf( log, "# rc %ld\n", rc );
903 
904             printf( "\n# pblSetEquals( clone, testcollection ) YES\n" );
905             fprintf( log, "# pblSetEquals( clone, testcollection ) YES\n" );
906 
907             rc = pblSetEquals( clone, testCollection );
908             if( rc < 0 )
909             {
910                 printf( "# rc %ld, pbl_errno %d\n", rc, pbl_errno );
911                 fprintf( log, "# rc %ld, pbl_errno %d\n", rc, pbl_errno );
912                 break;
913             }
914 
915             printf( "# rc %ld\n", rc );
916             fprintf( log, "# rc %ld\n", rc );
917 
918             pblSetFree( clone );
919 
920             printf( "# pblCollectionConvertToLinkedList( collection )\n");
921             fprintf( log, "# pblCollectionConvertToLinkedList( collection )\n" );
922 
923             clone = pblCollectionConvertToLinkedList( testCollection );
924             if( !clone )
925             {
926                 printf( "# NULL, pbl_errno %d\n", pbl_errno );
927                 fprintf( log, "# NULL, pbl_errno %d\n", pbl_errno );
928                 break;
929             }
930 
931             printf( "# ok size %d", pblSetSize( clone ) );
932             fprintf( log, "# ok size %d\n", pblSetSize( clone ) );
933 
934             printf( "\n# pblSetEquals( testcollection, clone ) YES\n" );
935             fprintf( log, "# pblSetEquals( testcollection, clone ) YES\n" );
936 
937             rc = pblSetEquals( testCollection, clone );
938             if( rc < 0 )
939             {
940                 printf( "# rc %ld, pbl_errno %d\n", rc, pbl_errno );
941                 fprintf( log, "# rc %ld, pbl_errno %d\n", rc, pbl_errno );
942                 break;
943             }
944 
945             printf( "# rc %ld\n", rc );
946             fprintf( log, "# rc %ld\n", rc );
947 
948             printf( "\n# pblSetEquals( clone, testcollection ) YES\n" );
949             fprintf( log, "# pblSetEquals( clone, testcollection ) YES\n" );
950 
951             rc = pblSetEquals( clone, testCollection );
952             if( rc < 0 )
953             {
954                 printf( "# rc %ld, pbl_errno %d\n", rc, pbl_errno );
955                 fprintf( log, "# rc %ld, pbl_errno %d\n", rc, pbl_errno );
956                 break;
957             }
958 
959             printf( "# rc %ld\n", rc );
960             fprintf( log, "# rc %ld\n", rc );
961 
962             pblSetFree( clone );
963 
964             printf( "# pblCollectionConvertToHashSet( collection )\n");
965             fprintf( log, "# pblCollectionConvertToHashSet( collection )\n" );
966 
967             clone = pblCollectionConvertToHashSet( testCollection, NULL );
968             if( !clone )
969             {
970                 printf( "# NULL, pbl_errno %d\n", pbl_errno );
971                 fprintf( log, "# NULL, pbl_errno %d\n", pbl_errno );
972                 break;
973             }
974 
975             printf( "# ok size %d", pblSetSize( clone ) );
976             fprintf( log, "# ok size %d\n", pblSetSize( clone ) );
977 
978             printf( "\n# pblSetEquals( testcollection, clone ) YES\n" );
979             fprintf( log, "# pblSetEquals( testcollection, clone ) YES\n" );
980 
981             rc = pblSetEquals( testCollection, clone );
982             if( rc < 0 )
983             {
984                 printf( "# rc %ld, pbl_errno %d\n", rc, pbl_errno );
985                 fprintf( log, "# rc %ld, pbl_errno %d\n", rc, pbl_errno );
986                 break;
987             }
988 
989             printf( "# rc %ld\n", rc );
990             fprintf( log, "# rc %ld\n", rc );
991 
992             printf( "\n# pblSetEquals( clone, testcollection ) YES\n" );
993             fprintf( log, "# pblSetEquals( clone, testcollection ) YES\n" );
994 
995             rc = pblSetEquals( clone, testCollection );
996             if( rc < 0 )
997             {
998                 printf( "# rc %ld, pbl_errno %d\n", rc, pbl_errno );
999                 fprintf( log, "# rc %ld, pbl_errno %d\n", rc, pbl_errno );
1000                 break;
1001             }
1002 
1003             printf( "# rc %ld\n", rc );
1004             fprintf( log, "# rc %ld\n", rc );
1005 
1006             pblSetFree( clone );
1007 
1008             printf( "# pblCollectionConvertToTreeSet( collection )\n");
1009             fprintf( log, "# pblCollectionConvertToTreeSet( collection )\n" );
1010 
1011             clone = pblCollectionConvertToTreeSet( testCollection );
1012             if( !clone )
1013             {
1014                 printf( "# NULL, pbl_errno %d\n", pbl_errno );
1015                 fprintf( log, "# NULL, pbl_errno %d\n", pbl_errno );
1016                 break;
1017             }
1018 
1019             printf( "# ok size %d", pblSetSize( clone ) );
1020             fprintf( log, "# ok size %d\n", pblSetSize( clone ) );
1021 
1022             printf( "\n# pblSetEquals( testcollection, clone ) YES\n" );
1023             fprintf( log, "# pblSetEquals( testcollection, clone ) YES\n" );
1024 
1025             rc = pblSetEquals( testCollection, clone );
1026             if( rc < 0 )
1027             {
1028                 printf( "# rc %ld, pbl_errno %d\n", rc, pbl_errno );
1029                 fprintf( log, "# rc %ld, pbl_errno %d\n", rc, pbl_errno );
1030                 break;
1031             }
1032 
1033             printf( "# rc %ld\n", rc );
1034             fprintf( log, "# rc %ld\n", rc );
1035 
1036             printf( "\n# pblSetEquals( clone, testcollection ) YES\n" );
1037             fprintf( log, "# pblSetEquals( clone, testcollection ) YES\n" );
1038 
1039             rc = pblSetEquals( clone, testCollection );
1040             if( rc < 0 )
1041             {
1042                 printf( "# rc %ld, pbl_errno %d\n", rc, pbl_errno );
1043                 fprintf( log, "# rc %ld, pbl_errno %d\n", rc, pbl_errno );
1044                 break;
1045             }
1046 
1047             printf( "# rc %ld\n", rc );
1048             fprintf( log, "# rc %ld\n", rc );
1049 
1050             pblSetFree( clone );
1051 
1052         }
1053 
1054         else if( !strcmp( command, "get" ))
1055         {
1056             if( !testCollection )
1057                 continue;
1058 
1059             printf( "# get index\n" );
1060             fprintf( log, "# get index\n" );
1061 
1062             getWord( buffer );
1063             ival = atoi( buffer );
1064 
1065             printf( "# pblSetGet( %d )\n", ival );
1066             fprintf( log, "# pblSetGet( %d )\n", ival );
1067 
1068             ptr = pblSetGet( testCollection, ival );
1069             if( ptr == (char *)-1 )
1070             {
1071                 printf( "# NOT FOUND, pbl_errno %d\n", pbl_errno );
1072                 fprintf( log, "# NOT FOUND, pbl_errno %d\n", pbl_errno );
1073             }
1074             else
1075             {
1076                 printf( "# get( %d )  %s", ival, ptr ? ptr : "NULL" );
1077                 fprintf( log, "# get( %d ) %s\n", ival, ptr ? ptr : "NULL" );
1078             }
1079         }
1080 
1081         else if( !strcmp( command, "getCapacity" ))
1082         {
1083             if( !testCollection )
1084                 continue;
1085 
1086             printf( "# getCapacity\n" );
1087             fprintf( log, "# getCapacity\n" );
1088 
1089             rc = pblSetGetCapacity( testCollection );
1090 
1091             if( rc < 0 )
1092             {
1093                 printf( "# rc %ld, pbl_errno %d\n",
1094                         rc, pbl_errno );
1095                 fprintf( log, "# rc %ld, pbl_errno %d\n",
1096                         rc, pbl_errno );
1097                 break;
1098             }
1099 
1100             printf( "# rc %ld\n", rc );
1101             fprintf( log, "# rc %ld\n", rc );
1102         }
1103 
1104         else if( !strcmp( command, "getCompareFunction" ))
1105         {
1106             if( !testCollection )
1107                 continue;
1108 
1109             printf( "# getCompareFunction\n" );
1110             fprintf( log, "# getCompareFunction\n" );
1111 
1112             ptr = pblSetGetCompareFunction( testCollection );
1113 
1114             printf( "# %s\n", ptr ? "FUNCTION SET" : "NULL" );
1115             fprintf( log, "# %s\n", ptr ? "FUNCTION SET" : "NULL" );
1116         }
1117 
1118         else if( !strcmp( command, "getFirst" ) )
1119         {
1120             if( !testCollection )
1121                 continue;
1122 
1123             printf( "# pblSetGetFirst( %d )\n", 1 );
1124             fprintf( log, "# pblSetGetFirst( %d )\n", 1 );
1125 
1126             ptr = pblSetGetFirst( testCollection );
1127             if( ptr == (char *)-1 )
1128             {
1129                 printf( "# NOT FOUND, pbl_errno %d\n", pbl_errno );
1130                 fprintf( log, "# NOT FOUND, pbl_errno %d\n", pbl_errno );
1131             }
1132             else
1133             {
1134                 printf( "# first %s", ptr ? ptr : "NULL" );
1135                 fprintf( log, "# first %s\n", ptr ? ptr : "NULL" );
1136             }
1137         }
1138 
1139         else if( !strcmp( command, "getHashValueFunction" ))
1140         {
1141             if( !testCollection )
1142                 continue;
1143 
1144             printf( "# getHashValueFunction\n" );
1145             fprintf( log, "# getHashValueFunction\n" );
1146 
1147             ptr = pblSetGetHashValueFunction( testCollection );
1148 
1149             printf( "# %s\n", ptr ? "FUNCTION SET" : "NULL" );
1150             fprintf( log, "# %s\n", ptr ? "FUNCTION SET" : "NULL" );
1151         }
1152 
1153         else if( !strcmp( command, "getLast" ) )
1154         {
1155             if( !testCollection )
1156                 continue;
1157 
1158             printf( "# pblSetGetLast(  )\n" );
1159             fprintf( log, "# pblSetGetLast(  )\n" );
1160 
1161             ptr = pblSetGetLast( testCollection );
1162             if( ptr == (char *)-1 )
1163             {
1164                 printf( "# NOT FOUND, pbl_errno %d\n", pbl_errno );
1165                 fprintf( log, "# NOT FOUND, pbl_errno %d\n", pbl_errno );
1166             }
1167             else
1168             {
1169                 printf( "# last %s", ptr ? ptr : "NULL" );
1170                 fprintf( log, "# last %s\n", ptr ? ptr : "NULL" );
1171             }
1172         }
1173 
1174         else if( !strcmp( command, "IndexOf" ))
1175         {
1176             if( !testCollection )
1177                 continue;
1178 
1179             printf( "# IndexOf itemIndex\n" );
1180             fprintf( log, "# IndexOf itemIndex\n" );
1181 
1182             getWord( buffer );
1183             ival = atoi( buffer );
1184             if( ival < 0)
1185             {
1186                 ptr = NULL;
1187             }
1188             else
1189             {
1190                 ptr = items[ ival ];
1191             }
1192 
1193             printf( "# pblSetIndexOf( %s )\n",
1194                     ptr ? ptr : "NULL" );
1195 
1196             fprintf( log, "# pblSetIndexOf( %s )\n",
1197                      ptr ? ptr : "NULL" );
1198 
1199             rc = pblSetIndexOf( testCollection, ptr );
1200 
1201             printf( "# rc %ld\n", rc );
1202             fprintf( log, "# rc %ld\n", rc );
1203         }
1204 
1205         else if( !strcmp( command, "intersection" ) )
1206         {
1207             PblSet * clone;
1208             PblSet * result;
1209 
1210             if( !testCollection )
1211                 continue;
1212 
1213             printf( "# pblSetClone( %d )\n", 1 );
1214             fprintf( log, "# pblSetClone( %d )\n", 1 );
1215 
1216             clone = pblSetClone( testCollection );
1217             if( !clone )
1218             {
1219                 printf( "# NULL, pbl_errno %d\n", pbl_errno );
1220                 fprintf( log, "# NULL, pbl_errno %d\n", pbl_errno );
1221                 break;
1222             }
1223 
1224             printf( "# ok size %d", pblSetSize( clone ) );
1225             fprintf( log, "# ok size %d\n", pblSetSize( clone ) );
1226 
1227             printf( "\n# pblSetIntersection( testSet, clone )\n" );
1228             fprintf( log, "# pblSetIntersection( testSet, clone )\n" );
1229 
1230             result = pblSetIntersection( testCollection, clone );
1231             if( !result )
1232             {
1233                 printf( "# result NULL, pbl_errno %d\n", pbl_errno );
1234                 fprintf( log, "# result NULL, pbl_errno %d\n", pbl_errno );
1235                 break;
1236             }
1237 
1238             printf( "# pblSetPrint( intersection )\n" );
1239             fprintf( log, "# pblSetPrint( intersection )\n" );
1240 
1241             pblSetPrint( stdout, result );
1242             pblSetPrint( log, result );
1243             pblSetFree( result );
1244 
1245             printf( "# pblSetRemoveFirst( clone )\n" );
1246             fprintf( log, "# pblSetRemoveFirst( clone )\n" );
1247 
1248             ptr = pblSetRemoveFirst( clone );
1249             if( !ptr )
1250             {
1251                 printf( "# result NULL, pbl_errno %d\n", pbl_errno );
1252                 fprintf( log, "# result NULL, pbl_errno %d\n", pbl_errno );
1253                 break;
1254             }
1255 
1256             printf( "# OK %s\n", ptr );
1257             fprintf( log, "# OK %s\n", ptr );
1258 
1259             printf( "# pblSetRemoveLast( clone )\n" );
1260             fprintf( log, "# pblSetRemoveLast( clone )\n" );
1261 
1262             ptr = pblSetRemoveLast( clone );
1263             if( !ptr )
1264             {
1265                 printf( "# result NULL, pbl_errno %d\n", pbl_errno );
1266                 fprintf( log, "# result NULL, pbl_errno %d\n", pbl_errno );
1267                 break;
1268             }
1269 
1270             printf( "# OK %s\n", ptr );
1271             fprintf( log, "# OK %s\n", ptr );
1272 
1273             printf( "\n# pblSetIntersection( testSet, clone )\n" );
1274             fprintf( log, "# pblSetIntersection( testSet, clone )\n" );
1275 
1276             result = pblSetIntersection( testCollection, clone );
1277             if( !result )
1278             {
1279                 printf( "# result NULL, pbl_errno %d\n", pbl_errno );
1280                 fprintf( log, "# result NULL, pbl_errno %d\n", pbl_errno );
1281                 break;
1282             }
1283 
1284             printf( "# pblSetPrint( intersection )\n" );
1285             fprintf( log, "# pblSetPrint( intersection )\n" );
1286 
1287             pblSetPrint( stdout, result );
1288             pblSetPrint( log, result );
1289             pblSetFree( result );
1290 
1291             printf( "\n# pblSetIntersection( clone, testSet )\n" );
1292             fprintf( log, "# pblSetIntersection( clone, testSet )\n" );
1293 
1294             result = pblSetIntersection( clone, testCollection );
1295             if( !result )
1296             {
1297                 printf( "# result NULL, pbl_errno %d\n", pbl_errno );
1298                 fprintf( log, "# result NULL, pbl_errno %d\n", pbl_errno );
1299                 break;
1300             }
1301 
1302             printf( "# pblSetPrint( intersection )\n" );
1303             fprintf( log, "# pblSetPrint( intersection )\n" );
1304 
1305             pblSetPrint( stdout, result );
1306             pblSetPrint( log, result );
1307 
1308             pblSetFree( result );
1309             pblSetFree( clone );
1310         }
1311 
1312         else if( !strcmp( command, "IsEmpty" ))
1313         {
1314             if( !testCollection )
1315                 continue;
1316 
1317             printf( "# pblSetIsEmpty( %d )\n", 1 );
1318             fprintf( log, "# pblSetIsEmpty( %d )\n", 1 );
1319 
1320             rc = pblSetIsEmpty( testCollection );
1321 
1322             printf( "# rc %ld\n", rc );
1323             fprintf( log, "# rc %ld\n", rc );
1324         }
1325 
1326         else if( !strcmp( command, "IsHashSet" ))
1327         {
1328             if( !testCollection )
1329                 continue;
1330 
1331             printf( "# pblSetIsHashSet( %d )\n", 1 );
1332             fprintf( log, "# pblSetIsHashSet( %d )\n", 1 );
1333 
1334             rc = pblSetIsHashSet( testCollection );
1335 
1336             printf( "# rc %ld\n", rc );
1337             fprintf( log, "# rc %ld\n", rc );
1338         }
1339 
1340         else if( !strcmp( command, "IsSet" ))
1341         {
1342             if( !testCollection )
1343                 continue;
1344 
1345             printf( "# pblSetIsSet( %d )\n", 1 );
1346             fprintf( log, "# pblSetIsSet( %d )\n", 1 );
1347 
1348             rc = pblSetIsSet( testCollection );
1349 
1350             printf( "# rc %ld\n", rc );
1351             fprintf( log, "# rc %ld\n", rc );
1352         }
1353 
1354         else if( !strcmp( command, "IsSubset" ) )
1355         {
1356             PblSet * clone;
1357 
1358             if( !testCollection )
1359                 continue;
1360 
1361             printf( "# pblSetClone( %d )\n", 1 );
1362             fprintf( log, "# pblSetClone( %d )\n", 1 );
1363 
1364             clone = pblSetClone( testCollection );
1365             if( !clone )
1366             {
1367                 printf( "# NULL, pbl_errno %d\n", pbl_errno );
1368                 fprintf( log, "# NULL, pbl_errno %d\n", pbl_errno );
1369                 break;
1370             }
1371 
1372             printf( "# ok size %d", pblSetSize( clone ) );
1373             fprintf( log, "# ok size %d\n", pblSetSize( clone ) );
1374 
1375             printf( "\n# pblSetIsSubset( testSet, testSet )\n" );
1376             fprintf( log, "# pblSetIsSubset( testSet, testSet )\n" );
1377 
1378             rc = pblSetIsSubset( testCollection, testCollection );
1379             if( rc < 0 )
1380             {
1381                 printf( "# rc %ld, pbl_errno %d\n",
1382                         rc, pbl_errno );
1383                 fprintf( log, "# rc %ld, pbl_errno %d\n",
1384                         rc, pbl_errno );
1385                 break;
1386             }
1387 
1388             printf( "# rc %ld\n", rc );
1389             fprintf( log, "# rc %ld\n", rc );
1390 
1391             printf( "\n# pblSetIsSubset( testSet, clone )\n" );
1392             fprintf( log, "# pblSetIsSubset( testSet, clone )\n" );
1393 
1394             rc = pblSetIsSubset( testCollection, clone );
1395             if( rc < 0 )
1396             {
1397                 printf( "# rc %ld, pbl_errno %d\n",
1398                         rc, pbl_errno );
1399                 fprintf( log, "# rc %ld, pbl_errno %d\n",
1400                         rc, pbl_errno );
1401                 break;
1402             }
1403 
1404             printf( "# rc %ld\n", rc );
1405             fprintf( log, "# rc %ld\n", rc );
1406 
1407             printf( "# pblSetRemoveFirst( clone )\n" );
1408             fprintf( log, "# pblSetRemoveFirst( clone )\n" );
1409 
1410             ptr = pblSetRemoveFirst( clone );
1411             if( !ptr )
1412             {
1413                 printf( "# result NULL, pbl_errno %d\n", pbl_errno );
1414                 fprintf( log, "# result NULL, pbl_errno %d\n", pbl_errno );
1415                 break;
1416             }
1417 
1418             printf( "# OK %s\n", ptr );
1419             fprintf( log, "# OK %s\n", ptr );
1420 
1421             printf( "# pblSetRemoveLast( clone )\n" );
1422             fprintf( log, "# pblSetRemoveLast( clone )\n" );
1423 
1424             ptr = pblSetRemoveLast( clone );
1425             if( !ptr )
1426             {
1427                 printf( "# result NULL, pbl_errno %d\n", pbl_errno );
1428                 fprintf( log, "# result NULL, pbl_errno %d\n", pbl_errno );
1429                 break;
1430             }
1431 
1432             printf( "# OK %s\n", ptr );
1433             fprintf( log, "# OK %s\n", ptr );
1434 
1435             printf( "\n# pblSetIsSubset( testSet, clone )\n" );
1436             fprintf( log, "# pblSetIsSubset( testSet, clone )\n" );
1437 
1438             rc = pblSetIsSubset( testCollection, clone );
1439             if( rc < 0 )
1440             {
1441                 printf( "# rc %ld, pbl_errno %d\n",
1442                         rc, pbl_errno );
1443                 fprintf( log, "# rc %ld, pbl_errno %d\n",
1444                         rc, pbl_errno );
1445                 break;
1446             }
1447 
1448             printf( "# rc %ld\n", rc );
1449             fprintf( log, "# rc %ld\n", rc );
1450 
1451             printf( "\n# pblSetIsSubset( clone, testSet )\n" );
1452             fprintf( log, "# pblSetIsSubset( clone, testSet )\n" );
1453 
1454             rc = pblSetIsSubset( clone, testCollection );
1455             if( rc < 0 )
1456             {
1457                 printf( "# rc %ld, pbl_errno %d\n",
1458                         rc, pbl_errno );
1459                 fprintf( log, "# rc %ld, pbl_errno %d\n",
1460                         rc, pbl_errno );
1461                 break;
1462             }
1463 
1464             printf( "# rc %ld\n", rc );
1465             fprintf( log, "# rc %ld\n", rc );
1466 
1467             pblSetFree( clone );
1468         }
1469 
1470         else if( !strcmp( command, "IsTreeSet" ))
1471         {
1472             if( !testCollection )
1473                 continue;
1474 
1475             printf( "# pblSetIsTreeSet( %d )\n", 1 );
1476             fprintf( log, "# pblSetIsTreeSet( %d )\n", 1 );
1477 
1478             rc = pblSetIsTreeSet( testCollection );
1479 
1480             printf( "# rc %ld\n", rc );
1481             fprintf( log, "# rc %ld\n", rc );
1482         }
1483 
1484         else if( !strcmp( command, "LastIndexOf" ))
1485         {
1486             if( !testCollection )
1487                 continue;
1488 
1489             printf( "# LastIndexOf itemIndex\n" );
1490             fprintf( log, "# LastIndexOf itemIndex\n" );
1491 
1492             getWord( buffer );
1493             ival = atoi( buffer );
1494             if( ival < 0)
1495             {
1496                 ptr = NULL;
1497             }
1498             else
1499             {
1500                 ptr = items[ ival ];
1501             }
1502 
1503             printf( "# pblSetLastIndexOf( %s )\n",
1504                     ptr ? ptr : "NULL" );
1505 
1506             fprintf( log, "# pblSetLastIndexOf( %s )\n",
1507                      ptr ? ptr : "NULL" );
1508 
1509             rc = pblSetLastIndexOf( testCollection, ptr );
1510 
1511             printf( "# rc %ld\n", rc );
1512             fprintf( log, "# rc %ld\n", rc );
1513         }
1514 
1515         else if( !strcmp( command, "peek" ) )
1516         {
1517             if( !testCollection )
1518                 continue;
1519 
1520             printf( "# pblSetPeek( %d )\n", 1 );
1521             fprintf( log, "# pblSetPeek( %d )\n", 1 );
1522 
1523             ptr = pblSetPeek( testCollection );
1524             if( ptr == (char *)-1 )
1525             {
1526                 printf( "# NOT FOUND, pbl_errno %d\n", pbl_errno );
1527                 fprintf( log, "# NOT FOUND, pbl_errno %d\n", pbl_errno );
1528             }
1529             else
1530             {
1531                 printf( "# first %s", ptr ? ptr : "NULL" );
1532                 fprintf( log, "# first %s\n", ptr ? ptr : "NULL" );
1533             }
1534         }
1535 
1536         else if( !strcmp( command, "poll" ) )
1537         {
1538             if( !testCollection )
1539                 continue;
1540 
1541             printf( "# pblSetPoll( %d )\n", 1 );
1542             fprintf( log, "# pblSetPoll( %d )\n", 1 );
1543 
1544             ptr = pblSetPoll( testCollection );
1545             if( ptr == (char *)-1 )
1546             {
1547                 printf( "# NOT FOUND, pbl_errno %d\n", pbl_errno );
1548                 fprintf( log, "# NOT FOUND, pbl_errno %d\n", pbl_errno );
1549             }
1550             else
1551             {
1552                 printf( "# polled first %s", ptr ? ptr : "NULL" );
1553                 fprintf( log, "# polled first %s\n", ptr ? ptr : "NULL" );
1554             }
1555         }
1556 
1557         else if( !strcmp( command, "pop" ) )
1558         {
1559             if( !testCollection )
1560                 continue;
1561 
1562             printf( "# pblSetPop( %d )\n", 1 );
1563             fprintf( log, "# pblSetPop( %d )\n", 1 );
1564 
1565             ptr = pblSetPop( testCollection );
1566             if( ptr == (char *)-1 )
1567             {
1568                 printf( "# NOT FOUND, pbl_errno %d\n", pbl_errno );
1569                 fprintf( log, "# NOT FOUND, pbl_errno %d\n", pbl_errno );
1570             }
1571             else
1572             {
1573                 printf( "# popped last %s", ptr ? ptr : "NULL" );
1574                 fprintf( log, "# popped last %s\n", ptr ? ptr : "NULL" );
1575             }
1576         }
1577 
1578         else if( !strcmp( command, "print" ) )
1579         {
1580             if( !testCollection )
1581                 continue;
1582 
1583             printf( "# pblSetPrint( %d )\n", 1 );
1584             fprintf( log, "# pblSetPrint( %d )\n", 1 );
1585 
1586             pblSetPrint( stdout, testCollection );
1587             pblSetPrint( log, testCollection );
1588         }
1589 
1590         else if( !strcmp( command, "remove" ))
1591         {
1592             if( !testCollection )
1593                 continue;
1594 
1595             printf( "# remove itemIndex\n" );
1596             fprintf( log, "# remove itemIndex\n" );
1597 
1598             getWord( buffer );
1599             ival = atoi( buffer );
1600             if( ival < 0)
1601             {
1602                 ptr = NULL;
1603             }
1604             else
1605             {
1606                 ptr = items[ ival ];
1607             }
1608 
1609             printf( "# pblSetRemoveElement( %s )\n",
1610                     ptr ? ptr : "NULL" );
1611 
1612             fprintf( log, "# pblSetRemoveElement( %s )\n",
1613                      ptr ? ptr : "NULL" );
1614 
1615             rc = pblSetRemoveElement( testCollection, ptr );
1616 
1617             if( rc < 0 )
1618             {
1619                 printf( "# rc %ld, pbl_errno %d\n",
1620                         rc, pbl_errno );
1621                 fprintf( log, "# rc %ld, pbl_errno %d\n",
1622                         rc, pbl_errno );
1623                 break;
1624             }
1625 
1626             printf( "# rc %ld\n", rc );
1627             fprintf( log, "# rc %ld\n", rc );
1628         }
1629 
1630         else if( !strcmp( command, "removeAll" ))
1631         {
1632             PblList * clone = ( PblList *) 0;
1633 
1634             if( !testCollection )
1635                 continue;
1636 
1637             printf( "# pblSetRemoveAll( %d )\n", 1 );
1638             fprintf( log, "# pblSetRemoveAll( %d )\n", 1 );
1639 
1640             clone = pblSetClone( testCollection );
1641             if( !clone )
1642             {
1643                 printf( "# rc %ld, pbl_errno %d\n",
1644                         (long)-1, pbl_errno );
1645                 fprintf( log, "# rc %ld, pbl_errno %d\n",
1646                         (long)-1, pbl_errno );
1647                 break;
1648             }
1649 
1650             rc = pblSetRemoveAll( testCollection, clone );
1651 
1652             if( rc < 0 )
1653             {
1654                 printf( "# rc %ld, pbl_errno %d\n",
1655                         rc, pbl_errno );
1656                 fprintf( log, "# rc %ld, pbl_errno %d\n",
1657                         rc, pbl_errno );
1658                 pblSetFree( clone );
1659                 break;
1660             }
1661 
1662             printf( "# rc %ld\n", rc );
1663             fprintf( log, "# rc %ld\n", rc );
1664             pblSetFree( clone );
1665         }
1666 
1667         else if( !strcmp( command, "removeAt" ))
1668         {
1669             if( !testCollection )
1670                 continue;
1671 
1672             printf( "# removeAt index\n" );
1673             fprintf( log, "# removeAt index\n" );
1674 
1675             getWord( buffer );
1676             ival = atoi( buffer );
1677 
1678             printf( "# pblSetRemoveAt( %d )\n", ival );
1679             fprintf( log, "# pblSetRemoveAt( %d )\n", ival );
1680 
1681             ptr = pblSetRemoveAt( testCollection, ival );
1682             if( ptr == NULL )
1683             {
1684                 printf( "# NOT FOUND, pbl_errno %d\n", pbl_errno );
1685                 fprintf( log, "# NOT FOUND, pbl_errno %d\n", pbl_errno );
1686             }
1687             else
1688             {
1689                 printf( "# removed %d %s", ival, ptr ? ptr : "NULL" );
1690                 fprintf( log, "# removed %d %s\n", ival, ptr ? ptr : "NULL" );
1691             }
1692         }
1693 
1694         else if( !strcmp( command, "removeFirst" ) )
1695         {
1696             if( !testCollection )
1697                 continue;
1698 
1699             printf( "# pblSetRemoveFirst( %d )\n", 1 );
1700             fprintf( log, "# pblSetRemoveFirst( %d )\n", 1 );
1701 
1702             ptr = pblSetRemoveFirst( testCollection );
1703             if( ptr == (char *)-1 )
1704             {
1705                 printf( "# NOT FOUND, pbl_errno %d\n", pbl_errno );
1706                 fprintf( log, "# NOT FOUND, pbl_errno %d\n", pbl_errno );
1707             }
1708             else
1709             {
1710                 printf( "# removed first %s", ptr ? ptr : "NULL" );
1711                 fprintf( log, "# removed first %s\n", ptr ? ptr : "NULL" );
1712             }
1713         }
1714 
1715         else if( !strcmp( command, "removeLast" ) )
1716         {
1717             if( !testCollection )
1718                 continue;
1719 
1720             printf( "# pblSetRemoveLast( %d )\n", 1 );
1721             fprintf( log, "# pblSetRemoveLast( %d )\n", 1 );
1722 
1723             ptr = pblSetRemoveLast( testCollection );
1724             if( ptr == (char *)-1 )
1725             {
1726                 printf( "# NOT FOUND, pbl_errno %d\n", pbl_errno );
1727                 fprintf( log, "# NOT FOUND, pbl_errno %d\n", pbl_errno );
1728             }
1729             else
1730             {
1731                 printf( "# removed last %s", ptr ? ptr : "NULL" );
1732                 fprintf( log, "# removed last %s\n", ptr ? ptr : "NULL" );
1733             }
1734         }
1735 
1736         else if( !strcmp( command, "retainAll" ))
1737         {
1738             PblSet * clone = ( PblSet *) 0;
1739 
1740             if( !testCollection )
1741                 continue;
1742 
1743             printf( "# pblSetClone( %d )\n", 1 );
1744             fprintf( log, "# pblSetClone( %d )\n", 1 );
1745 
1746             clone = pblSetClone( testCollection );
1747             if( !clone )
1748             {
1749                 printf( "# rc %ld, pbl_errno %d\n",
1750                         (long)-1, pbl_errno );
1751                 fprintf( log, "# rc %ld, pbl_errno %d\n",
1752                         (long)-1, pbl_errno );
1753                 break;
1754             }
1755 
1756             printf( "# pblSetRetainAll( original, clone )\n" );
1757             fprintf( log, "# pblSetRetainAll( original, clone )\n" );
1758 
1759             rc = pblSetRetainAll( testCollection, clone );
1760             if( rc < 0 )
1761             {
1762                 printf( "# rc %ld, pbl_errno %d\n",
1763                         rc, pbl_errno );
1764                 fprintf( log, "# rc %ld, pbl_errno %d\n",
1765                         rc, pbl_errno );
1766                 pblSetFree( clone );
1767                 break;
1768             }
1769 
1770 
1771             printf( "# rc %ld\n", rc );
1772             fprintf( log, "# rc %ld\n", rc );
1773 
1774             printf( "# pblSetRemoveFirst( clone )\n" );
1775             fprintf( log, "# pblSetRemoveFirst( clone, )\n" );
1776 
1777             ptr = pblSetRemoveFirst( clone );
1778             if( ptr == (char *)-1 )
1779             {
1780                 printf( "# NOT FOUND, pbl_errno %d\n", pbl_errno );
1781                 fprintf( log, "# NOT FOUND, pbl_errno %d\n", pbl_errno );
1782             }
1783             else
1784             {
1785                 printf( "# removed first %s\n", ptr ? ptr : "NULL" );
1786                 fprintf( log, "# removed first %s\n", ptr ? ptr : "NULL" );
1787             }
1788 
1789             printf( "# pblSetRemoveLast( clone )\n" );
1790             fprintf( log, "# pblSetRemoveLast( clone )\n" );
1791 
1792             ptr = pblSetRemoveLast( clone );
1793             if( ptr == (char *)-1 )
1794             {
1795                 printf( "# NOT FOUND, pbl_errno %d\n", pbl_errno );
1796                 fprintf( log, "# NOT FOUND, pbl_errno %d\n", pbl_errno );
1797             }
1798             else
1799             {
1800                 printf( "# removed last %s\n", ptr ? ptr : "NULL" );
1801                 fprintf( log, "# removed last %s\n", ptr ? ptr : "NULL" );
1802             }
1803 
1804             pblSetPrint( stdout, clone );
1805             pblSetPrint( log, clone );
1806 
1807             printf( "# pblSetRetainAll( %d )\n", 1 );
1808             fprintf( log, "# pblSetRetainAll( %d )\n", 1 );
1809 
1810             rc = pblSetRetainAll( testCollection, clone );
1811             if( rc < 0 )
1812             {
1813                 printf( "# rc %ld, pbl_errno %d\n",
1814                         rc, pbl_errno );
1815                 fprintf( log, "# rc %ld, pbl_errno %d\n",
1816                         rc, pbl_errno );
1817                 pblSetFree( clone );
1818                 break;
1819             }
1820 
1821             printf( "# rc %ld\n", rc );
1822             fprintf( log, "# rc %ld\n", rc );
1823 
1824             pblSetPrint( stdout, testCollection );
1825             pblSetPrint( log, testCollection );
1826 
1827             pblSetFree( clone );
1828         }
1829 
1830         else if( !strcmp( command, "size" ))
1831         {
1832             if( !testCollection )
1833                 continue;
1834 
1835 
1836             printf( "# pblSetSize(  )\n"  );
1837             fprintf( log, "# pblSetSize(  )\n" );
1838 
1839             rc = pblSetSize( testCollection );
1840             if( rc < 0 )
1841             {
1842                 printf( "# rc %ld, pbl_errno %d\n",
1843                         rc, pbl_errno );
1844                 fprintf( log, "# rc %ld, pbl_errno %d\n",
1845                         rc, pbl_errno );
1846                 break;
1847             }
1848             else
1849             {
1850                 printf( "# rc %ld\n", rc );
1851                 fprintf( log, "# rc %ld\n", rc );
1852             }
1853         }
1854 
1855         else if( !strcmp( command, "strcmp" ))
1856         {
1857             if( !testCollection )
1858                 continue;
1859 
1860             printf( "# pblSetSetCompareFunction( %d )\n", 1 );
1861             fprintf( log, "# pblSetSetCompareFunction( %d )\n", 1 );
1862 
1863             ptr = pblSetSetCompareFunction( testCollection, pblCollectionStringCompareFunction );
1864 
1865             printf( "# ok %s", ptr ? "Function was set" : "NULL" );
1866             fprintf( log, "# ok %s\n", ptr ? "Function was set" : "NULL" );
1867         }
1868 
1869 
1870         else if( !strcmp( command, "strhash" ))
1871         {
1872             if( !testCollection )
1873                 continue;
1874 
1875             printf( "# pblSetSetHashValueFunction( %d )\n", 1 );
1876             fprintf( log, "# pblSetSetHashValueFunction( %d )\n", 1 );
1877 
1878             ptr = pblSetSetHashValueFunction( testCollection, pblSetStringHashValue );
1879 
1880             printf( "# ok %s", ptr ? "Function was set" : "NULL" );
1881             fprintf( log, "# ok %s\n", ptr ? "Function was set" : "NULL" );
1882         }
1883 
1884         else if( !strcmp( command, "symmectricDifference" ) )
1885         {
1886             PblSet * clone;
1887             PblSet * result;
1888 
1889             if( !testCollection )
1890                 continue;
1891 
1892             printf( "# pblSetClone( %d )\n", 1 );
1893             fprintf( log, "# pblSetClone( %d )\n", 1 );
1894 
1895             clone = pblSetClone( testCollection );
1896             if( !clone )
1897             {
1898                 printf( "# NULL, pbl_errno %d\n", pbl_errno );
1899                 fprintf( log, "# NULL, pbl_errno %d\n", pbl_errno );
1900                 break;
1901             }
1902 
1903             printf( "# ok size %d", pblSetSize( clone ) );
1904             fprintf( log, "# ok size %d\n", pblSetSize( clone ) );
1905 
1906             printf( "\n# pblSetSymmectricDifference( testSet, clone )\n" );
1907             fprintf( log, "# pblSetSymmectricDifference( testSet, clone )\n" );
1908 
1909             result = pblSetSymmectricDifference( testCollection, clone );
1910             if( !result )
1911             {
1912                 printf( "# result NULL, pbl_errno %d\n", pbl_errno );
1913                 fprintf( log, "# result NULL, pbl_errno %d\n", pbl_errno );
1914                 break;
1915             }
1916 
1917             printf( "# pblSetPrint( SymmectricDifference )\n" );
1918             fprintf( log, "# pblSetPrint( SymmectricDifference )\n" );
1919 
1920             pblSetPrint( stdout, result );
1921             pblSetPrint( log, result );
1922             pblSetFree( result );
1923 
1924             printf( "# pblSetRemoveFirst( clone )\n" );
1925             fprintf( log, "# pblSetRemoveFirst( clone )\n" );
1926 
1927             ptr = pblSetRemoveFirst( clone );
1928             if( !ptr )
1929             {
1930                 printf( "# result NULL, pbl_errno %d\n", pbl_errno );
1931                 fprintf( log, "# result NULL, pbl_errno %d\n", pbl_errno );
1932                 break;
1933             }
1934 
1935             printf( "# OK %s\n", ptr );
1936             fprintf( log, "# OK %s\n", ptr );
1937 
1938             printf( "# pblSetRemoveLast( clone )\n" );
1939             fprintf( log, "# pblSetRemoveLast( clone )\n" );
1940 
1941             ptr = pblSetRemoveLast( clone );
1942             if( !ptr )
1943             {
1944                 printf( "# result NULL, pbl_errno %d\n", pbl_errno );
1945                 fprintf( log, "# result NULL, pbl_errno %d\n", pbl_errno );
1946                 break;
1947             }
1948 
1949             printf( "# OK %s\n", ptr );
1950             fprintf( log, "# OK %s\n", ptr );
1951 
1952             printf( "\n# pblSetSymmectricDifference( testSet, clone )\n" );
1953             fprintf( log, "# pblSetSymmectricDifference( testSet, clone )\n" );
1954 
1955             result = pblSetSymmectricDifference( testCollection, clone );
1956             if( !result )
1957             {
1958                 printf( "# result NULL, pbl_errno %d\n", pbl_errno );
1959                 fprintf( log, "# result NULL, pbl_errno %d\n", pbl_errno );
1960                 break;
1961             }
1962 
1963             printf( "# pblSetPrint( SymmectricDifference )\n" );
1964             fprintf( log, "# pblSetPrint( SymmectricDifference )\n" );
1965 
1966             pblSetPrint( stdout, result );
1967             pblSetPrint( log, result );
1968 
1969             pblSetFree( result );
1970             pblSetFree( clone );
1971         }
1972 
1973         else if( !strcmp( command, "toArray" ))
1974         {
1975             char ** array;
1976             if( !testCollection )
1977                 continue;
1978 
1979             printf( "# pblSetToArray( )\n" );
1980             fprintf( log, "# pblSetToArray( )\n" );
1981 
1982             array = (char**)pblSetToArray( testCollection );
1983             if( array == NULL )
1984             {
1985                 printf( "# NULL, pbl_errno %d\n",
1986                         pbl_errno );
1987                 fprintf( log, "# NULL, pbl_errno %d\n",
1988                         pbl_errno );
1989                 continue;
1990             }
1991 
1992             printf( "# OK\n" );
1993             fprintf( log, "# OK\n" );
1994 
1995             for( i = 0; i < pblSetSize( testCollection ); i++ )
1996             {
1997                 char * item =  array[i];
1998 
1999                 printf( "# OK i %d, %s\n", i, item != NULL ? item : "NULL" );
2000                 fprintf( log, "# OK i %d, %s\n", i, item != NULL ? item : "NULL" );
2001             }
2002 
2003             PBL_FREE(array );
2004             printf( "# Array Iteration DONE\n" );
2005             fprintf( log, "# Array Iteration DONE\n" );
2006         }
2007 
2008         else if( !strcmp( command, "trim" ))
2009         {
2010             if( !testCollection )
2011                 continue;
2012 
2013             printf( "# pblSetTrimToSize( )\n" );
2014             fprintf( log, "# pblSetTrimToSize( )\n" );
2015 
2016             rc = pblSetTrimToSize( testCollection );
2017             if( rc < 0 )
2018             {
2019                 printf( "# rc %ld, pbl_errno %d\n",
2020                         rc, pbl_errno );
2021                 fprintf( log, "# rc %ld, pbl_errno %d\n",
2022                         rc, pbl_errno );
2023             }
2024             else
2025             {
2026                 printf( "# rc %ld\n", rc );
2027                 fprintf( log, "# rc %ld\n", rc );
2028             }
2029         }
2030 
2031         else if( !strcmp( command, "union" ) )
2032         {
2033             PblSet * clone;
2034             PblSet * result;
2035 
2036             if( !testCollection )
2037                 continue;
2038 
2039             printf( "# pblSetCloneRange( set, 0, 0 )\n" );
2040             fprintf( log, "# pblSetCloneRange( set, 0, 0 )\n" );
2041 
2042             clone = pblSetCloneRange( testCollection, 0, 0 );
2043             if( !clone )
2044             {
2045                 printf( "# NULL, pbl_errno %d\n", pbl_errno );
2046                 fprintf( log, "# NULL, pbl_errno %d\n", pbl_errno );
2047                 break;
2048             }
2049 
2050             printf( "# ok size %d", pblSetSize( clone ) );
2051             fprintf( log, "# ok size %d\n", pblSetSize( clone ) );
2052 
2053             printf( "\n# pblSetUnion( testSet, empty )\n" );
2054             fprintf( log, "# pblSetUnion( testSet, empty )\n" );
2055 
2056             result = pblSetUnion( testCollection, clone );
2057             if( !result )
2058             {
2059                 printf( "# result NULL, pbl_errno %d\n", pbl_errno );
2060                 fprintf( log, "# result NULL, pbl_errno %d\n", pbl_errno );
2061                 break;
2062             }
2063 
2064             printf( "# pblSetPrint( Union )\n" );
2065             fprintf( log, "# pblSetPrint( Union )\n" );
2066 
2067             pblSetPrint( stdout, result );
2068             pblSetPrint( log, result );
2069 
2070             pblSetFree( result );
2071             pblSetFree( clone );
2072 
2073             printf( "# pblSetClone( %d )\n", 1 );
2074             fprintf( log, "# pblSetClone( %d )\n", 1 );
2075 
2076             clone = pblSetClone( testCollection );
2077             if( !clone )
2078             {
2079                 printf( "# NULL, pbl_errno %d\n", pbl_errno );
2080                 fprintf( log, "# NULL, pbl_errno %d\n", pbl_errno );
2081                 break;
2082             }
2083 
2084             printf( "# ok size %d", pblSetSize( clone ) );
2085             fprintf( log, "# ok size %d\n", pblSetSize( clone ) );
2086 
2087             printf( "\n# pblSetUnion( testSet, empty )\n" );
2088             fprintf( log, "# pblSetUnion( testSet, empty )\n" );
2089 
2090             result = pblSetUnion( testCollection, clone );
2091             if( !result )
2092             {
2093                 printf( "# result NULL, pbl_errno %d\n", pbl_errno );
2094                 fprintf( log, "# result NULL, pbl_errno %d\n", pbl_errno );
2095                 break;
2096             }
2097 
2098             printf( "# pblSetPrint( Union )\n" );
2099             fprintf( log, "# pblSetPrint( Union )\n" );
2100 
2101             pblSetPrint( stdout, result );
2102             pblSetPrint( log, result );
2103             pblSetFree( result );
2104 
2105             printf( "# pblSetRemoveFirst( clone )\n" );
2106             fprintf( log, "# pblSetRemoveFirst( clone )\n" );
2107 
2108             ptr = pblSetRemoveFirst( clone );
2109 
2110             printf( "# result %s\n", ptr ? ptr :"NULL" );
2111             fprintf( log, "# result %s\n", ptr ? ptr :"NULL" );
2112 
2113             printf( "# pblSetRemoveLast( clone )\n" );
2114             fprintf( log, "# pblSetRemoveLast( clone )\n" );
2115 
2116             ptr = pblSetRemoveLast( clone );
2117 
2118             printf( "# result %s\n", ptr ? ptr :"NULL" );
2119             fprintf( log, "# result %s\n", ptr ? ptr :"NULL" );
2120 
2121             printf( "# pblSetAdd( %d, NotFound )\n", 1 );
2122             fprintf( log, "# pblSetAdd( %d, NotFound )\n", 1 );
2123 
2124             rc = pblSetAdd(clone, "NotFound" );
2125             if( rc < 0 )
2126             {
2127                 printf( "# rc %ld, pbl_errno %d\n", rc, pbl_errno );
2128                 fprintf( log, "# rc %ld, pbl_errno %d\n", rc, pbl_errno );
2129                 break;
2130             }
2131 
2132             printf( "\n# pblSetUnion( testSet, clone )\n" );
2133             fprintf( log, "# pblSetUnion( testSet, clone )\n" );
2134 
2135             result = pblSetUnion( testCollection, clone );
2136             if( !result )
2137             {
2138                 printf( "# result NULL, pbl_errno %d\n", pbl_errno );
2139                 fprintf( log, "# result NULL, pbl_errno %d\n", pbl_errno );
2140                 break;
2141             }
2142 
2143             printf( "# pblSetPrint( Union )\n" );
2144             fprintf( log, "# pblSetPrint( Union )\n" );
2145 
2146             pblSetPrint( stdout, result );
2147             pblSetPrint( log, result );
2148 
2149             pblSetFree( result );
2150             pblSetFree( clone );
2151         }
2152 
2153         else if( !strcmp( command, "iterate" ))
2154         {
2155             PblIterator  * iterator;
2156 
2157             i = 0;
2158 
2159             if( !testCollection )
2160                 continue;
2161 
2162             printf( "# iterate maxIndex\n" );
2163             fprintf( log, "# iterate maxIndex\n" );
2164             getWord( buffer );
2165             ival = atoi( buffer );
2166 
2167             printf( "# pblIteratorNew( %d )\n",
2168                     ival );
2169 
2170             fprintf( log, "# pblIteratorNew( %d )\n",
2171                     ival );
2172 
2173             iterator = pblIteratorNew( (PblCollection*)testCollection );
2174 
2175             if( iterator == NULL )
2176             {
2177                 printf( "# NULL, pbl_errno %d\n",
2178                         pbl_errno );
2179                 fprintf( log, "# NULL, pbl_errno %d\n",
2180                         pbl_errno );
2181                 break;
2182             }
2183 
2184             printf( "# OK\n" );
2185             fprintf( log, "# OK\n" );
2186 
2187 
2188             while( ival-- > 0 && pblIteratorHasNext( iterator ))
2189             {
2190                 char * item =  ( char *) pblIteratorNext( iterator );
2191                 if( item == (void*)-1 )
2192                 {
2193                     printf( "# FAILED i %d, pbl_errno %d\n", i, pbl_errno );
2194                     fprintf( log, "# FAILED i %d, pbl_errno %d\n",
2195                              i, pbl_errno );
2196                     break;
2197                 }
2198 
2199                 printf( "# OK i %d, %s\n", i, item != NULL ? item : "NULL" );
2200                 fprintf( log, "# OK i %d, %s\n", i, item != NULL ? item : "NULL" );
2201                 i++;
2202             }
2203 
2204             pblIteratorFree( iterator );
2205             printf( "# Iteration DONE\n" );
2206             fprintf( log, "# Iteration DONE\n" );
2207 
2208         }
2209 
2210         else if( !strcmp( command, "reverseIterate" ))
2211         {
2212             PblIterator  * iterator;
2213 
2214             i = 0;
2215 
2216             if( !testCollection )
2217                 continue;
2218 
2219             printf( "# reverseIterate maxIndex\n" );
2220             fprintf( log, "# reverseIterate maxIndex\n" );
2221             getWord( buffer );
2222             ival = atoi( buffer );
2223 
2224             printf( "# pblSetReverseIterator( %d )\n",
2225                     ival );
2226 
2227             fprintf( log, "# pblSetReverseIterator( %d )\n",
2228                     ival );
2229 
2230             iterator = pblSetReverseIterator( (PblCollection*)testCollection );
2231 
2232             if( iterator == NULL )
2233             {
2234                 printf( "# NULL, pbl_errno %d\n",
2235                         pbl_errno );
2236                 fprintf( log, "# NULL, pbl_errno %d\n",
2237                         pbl_errno );
2238                 break;
2239             }
2240 
2241             printf( "# OK\n" );
2242             fprintf( log, "# OK\n" );
2243 
2244 
2245             while( ival-- > 0 && pblIteratorHasPrevious( iterator ))
2246             {
2247                 char * item =  ( char *) pblIteratorPrevious( iterator );
2248                 if( item == (void*)-1 )
2249                 {
2250                     printf( "# FAILED i %d, pbl_errno %d\n", i, pbl_errno );
2251                     fprintf( log, "# FAILED i %d, pbl_errno %d\n",
2252                              i, pbl_errno );
2253                     break;
2254                 }
2255 
2256                 printf( "# OK i %d, %s\n", i, item != NULL ? item : "NULL" );
2257                 fprintf( log, "# OK i %d, %s\n", i, item != NULL ? item : "NULL" );
2258                 i++;
2259             }
2260 
2261             pblIteratorFree( iterator );
2262             printf( "# Iteration DONE\n" );
2263             fprintf( log, "# Iteration DONE\n" );
2264 
2265         }
2266 
2267         else if( !strcmp( command, "iterator" ))
2268         {
2269             if( !testCollection )
2270                 continue;
2271 
2272             printf( "# pblSetIterator( 1 )\n" );
2273             fprintf( log, "# pblSetIterator( 1 )\n" );
2274 
2275             testIterator = pblSetIterator( (PblCollection*)testCollection );
2276             if( testIterator == NULL )
2277             {
2278                 printf( "# NULL, pbl_errno %d\n",
2279                         pbl_errno );
2280                 fprintf( log, "# NULL, pbl_errno %d\n",
2281                         pbl_errno );
2282                 break;
2283             }
2284 
2285             printf( "# OK\n" );
2286             fprintf( log, "# OK\n" );
2287         }
2288 
2289         else if( !strcmp( command, "reverseIterator" ))
2290         {
2291             if( !testCollection )
2292                 continue;
2293 
2294             printf( "# pblIteratorReverseNew( 1 )\n" );
2295             fprintf( log, "# pblIteratorReverseNew( 1 )\n" );
2296 
2297             testIterator = pblIteratorReverseNew( (PblCollection*)testCollection );
2298             if( testIterator == NULL )
2299             {
2300                 printf( "# NULL, pbl_errno %d\n",
2301                         pbl_errno );
2302                 fprintf( log, "# NULL, pbl_errno %d\n",
2303                         pbl_errno );
2304                 break;
2305             }
2306 
2307             printf( "# OK\n" );
2308             fprintf( log, "# OK\n" );
2309         }
2310 
2311         else if( !strcmp( command, "iteratorAdd" ))
2312         {
2313             if( !testIterator )
2314                 continue;
2315 
2316             printf( "# iteratorAdd itemIndex\n" );
2317             fprintf( log, "# iteratorAdd itemIndex\n" );
2318 
2319             getWord( buffer );
2320             ival = atoi( buffer );
2321             if( ival < 0)
2322             {
2323                 ptr = NULL;
2324             }
2325             else
2326             {
2327                 ptr = items[ ival ];
2328             }
2329 
2330             printf( "# pblIteratorAdd( %s )\n",
2331                     ptr ? ptr : "NULL" );
2332 
2333             fprintf( log, "# pblIteratorAdd( %s )\n",
2334                      ptr ? ptr : "NULL" );
2335 
2336             rc = pblIteratorAdd( testIterator, ptr );
2337 
2338             if( rc < 0 )
2339             {
2340                 printf( "# rc %ld, pbl_errno %d\n",
2341                         rc, pbl_errno );
2342                 fprintf( log, "# rc %ld, pbl_errno %d\n",
2343                         rc, pbl_errno );
2344                 continue;
2345             }
2346 
2347             printf( "# rc %ld\n", rc );
2348             fprintf( log, "# rc %ld\n", rc );
2349         }
2350 
2351         else if( !strcmp( command, "iteratorFree" ))
2352         {
2353             if( !testIterator )
2354                 continue;
2355 
2356             printf( "# pblIteratorFree( )\n" );
2357             fprintf( log, "# pblIteratorFree()\n" );
2358 
2359             pblIteratorFree( testIterator );
2360             testIterator = NULL;
2361 
2362             printf( "# OK\n" );
2363             fprintf( log, "# OK\n" );
2364         }
2365 
2366         else if( !strcmp( command, "hasNext" ))
2367         {
2368             if( !testIterator )
2369                 continue;
2370 
2371             printf( "# pblIteratorHasNext( )\n" );
2372             fprintf( log, "# pblIteratorHasNext()\n" );
2373 
2374             rc = pblIteratorHasNext( testIterator );
2375             if( rc < 0 )
2376             {
2377                 printf( "# rc %ld, pbl_errno %d\n",
2378                         rc, pbl_errno );
2379                 fprintf( log, "# rc %ld, pbl_errno %d\n",
2380                         rc, pbl_errno );
2381                 continue;
2382             }
2383 
2384             printf( "# rc %ld\n", rc );
2385             fprintf( log, "# rc %ld\n", rc );
2386         }
2387 
2388         else if( !strcmp( command, "hasPrevious" ))
2389         {
2390             if( !testIterator )
2391                 continue;
2392 
2393             printf( "# pblIteratorHasPrevious( )\n" );
2394             fprintf( log, "# pblIteratorHasPrevious()\n" );
2395 
2396             rc = pblIteratorHasPrevious( testIterator );
2397             if( rc < 0 )
2398             {
2399                 printf( "# rc %ld, pbl_errno %d\n",
2400                         rc, pbl_errno );
2401                 fprintf( log, "# rc %ld, pbl_errno %d\n",
2402                         rc, pbl_errno );
2403                 continue;
2404             }
2405 
2406             printf( "# rc %ld\n", rc );
2407             fprintf( log, "# rc %ld\n", rc );
2408         }
2409 
2410         else if( !strcmp( command, "next" ))
2411         {
2412             if( !testIterator )
2413                 continue;
2414 
2415             printf( "# pblIteratorNext( )\n" );
2416             fprintf( log, "# pblIteratorNext()\n" );
2417 
2418             ptr = pblIteratorNext( testIterator );
2419             if( ptr == (char *)-1 )
2420             {
2421                 printf( "# NO NEXT, pbl_errno %d\n", pbl_errno );
2422                 fprintf( log, "# NO NEXT, pbl_errno %d\n", pbl_errno );
2423             }
2424             else
2425             {
2426                 printf( "# next %s", ptr ? ptr : "NULL" );
2427                 fprintf( log, "# next %s\n", ptr ? ptr : "NULL" );
2428             }
2429         }
2430 
2431         else if( !strcmp( command, "nextIndex" ))
2432         {
2433             if( !testIterator )
2434                 continue;
2435 
2436             printf( "# pblIteratorNextIndex( )\n" );
2437             fprintf( log, "# pblIteratorNextIndex()\n" );
2438 
2439             rc = pblIteratorNextIndex( testIterator );
2440             if( rc < 0 )
2441             {
2442                 printf( "# rc %ld, pbl_errno %d\n",
2443                         rc, pbl_errno );
2444                 fprintf( log, "# rc %ld, pbl_errno %d\n",
2445                         rc, pbl_errno );
2446                 continue;
2447             }
2448 
2449             printf( "# rc %ld\n", rc );
2450             fprintf( log, "# rc %ld\n", rc );
2451         }
2452 
2453         else if( !strcmp( command, "previous" ))
2454         {
2455             if( !testIterator )
2456                 continue;
2457 
2458             printf( "# pblIteratorPrevious( )\n" );
2459             fprintf( log, "# pblIteratorPrevious()\n" );
2460 
2461             ptr = pblIteratorPrevious( testIterator );
2462             if( ptr == (char *)-1 )
2463             {
2464                 printf( "# NO PREVIOUS, pbl_errno %d\n", pbl_errno );
2465                 fprintf( log, "# NO PREVIOUS, pbl_errno %d\n", pbl_errno );
2466             }
2467             else
2468             {
2469                 printf( "# previous %s", ptr ? ptr : "NULL" );
2470                 fprintf( log, "# previous %s\n", ptr ? ptr : "NULL" );
2471             }
2472         }
2473 
2474         else if( !strcmp( command, "previousIndex" ))
2475         {
2476             if( !testIterator )
2477                 continue;
2478 
2479             printf( "# pblIteratorPreviousIndex( )\n" );
2480             fprintf( log, "# pblIteratorPreviousIndex()\n" );
2481 
2482             rc = pblIteratorPreviousIndex( testIterator );
2483 
2484             printf( "# rc %ld\n", rc );
2485             fprintf( log, "# rc %ld\n", rc );
2486         }
2487 
2488         else if( !strcmp( command, "iteratorRemove" ))
2489         {
2490             if( !testIterator )
2491                 continue;
2492 
2493             printf( "# pblIteratorRemove( )\n" );
2494             fprintf( log, "# pblIteratorRemove()\n" );
2495 
2496             rc = pblIteratorRemove( testIterator );
2497             if( rc < 0 )
2498             {
2499                 printf( "# rc %ld, pbl_errno %d\n",
2500                         rc, pbl_errno );
2501                 fprintf( log, "# rc %ld, pbl_errno %d\n",
2502                         rc, pbl_errno );
2503                 continue;
2504             }
2505 
2506             printf( "# rc %ld\n", rc );
2507             fprintf( log, "# rc %ld\n", rc );
2508         }
2509 
2510         else if( !strcmp( command, "iteratorSet" ))
2511         {
2512             if( !testIterator )
2513                 continue;
2514 
2515             printf( "# iteratorSet itemIndex\n" );
2516             fprintf( log, "# iteratorSet itemIndex\n" );
2517 
2518             getWord( buffer );
2519             ival = atoi( buffer );
2520             if( ival < 0)
2521             {
2522                 ptr = NULL;
2523             }
2524             else
2525             {
2526                 ptr = items[ ival ];
2527             }
2528 
2529             printf( "# pblIteratorSet( %s )\n",
2530                     ptr ? ptr : "NULL" );
2531 
2532             fprintf( log, "# pblIteratorSet( %s )\n",
2533                      ptr ? ptr : "NULL" );
2534 
2535             ptr = pblIteratorSet( testIterator, ptr );
2536             if( ptr == (char *)-1 )
2537             {
2538                 printf( "# SET FAILED, pbl_errno %d\n", pbl_errno );
2539                 fprintf( log, "# SET FAILED, pbl_errno %d\n", pbl_errno );
2540             }
2541             else
2542             {
2543                 printf( "# set returned %s", ptr ? ptr : "NULL" );
2544                 fprintf( log, "# set returned %s\n", ptr ? ptr : "NULL" );
2545             }
2546         }
2547 
2548         else if( !strcmp( command, "iteratorSize" ))
2549         {
2550             if( !testIterator )
2551                 continue;
2552 
2553             printf( "# pblIteratorSize( )\n" );
2554             fprintf( log, "# pblIteratorSize()\n" );
2555 
2556             rc = pblIteratorSize( testIterator );
2557             if( rc < 0 )
2558             {
2559                 printf( "# rc %ld, pbl_errno %d\n",
2560                         rc, pbl_errno );
2561                 fprintf( log, "# rc %ld, pbl_errno %d\n",
2562                         rc, pbl_errno );
2563                 continue;
2564             }
2565 
2566             printf( "# rc %ld\n", rc );
2567             fprintf( log, "# rc %ld\n", rc );
2568         }
2569 
2570         else
2571         {
2572             printf( "# q       FOR QUIT\n" );
2573         }
2574     }
2575 
2576     return( 0 );
2577 }
2578 
2579 /*
2580  * Eclipse CDT does not like more than one main,
2581  * therefore hide all but one main with this -D option
2582  */
2583 #ifdef _WIN32
2584 #define ALTST_SHOW_MAIN
2585 #endif
2586 
2587 #ifndef CDT_BUILD
2588 #define ALTST_SHOW_MAIN
2589 #endif
2590 
2591 #ifdef PBLTEST
2592 #undef ALTST_SHOW_MAIN
2593 #define ALTST_SHOW_MAIN 1
2594 #endif
2595 
2596 /* #define ALTST_SHOW_MAIN */
2597 #ifdef ALTST_SHOW_MAIN
2598 
main(int argc,char * argv[])2599 int main( int argc, char * argv[] )
2600 {
2601     return( pblSet_TestFrame( argc, argv ));
2602 }
2603 
2604 #endif /* CDT_BUILD */
2605