IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 19, 2004, 9:14:22 AM (22 years ago)
Author:
rhl
Message:

Moved test code to tst_*.c

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/archive/pslib/src/Utils/dlist.c

    r169 r265  
    342342    return list;
    343343}
    344 
    345 /*****************************************************************************/
    346 #if 0                                   // testing
    347 
    348 typedef struct { int i; } X;
    349 static X *xAlloc(int i) { X *x = psAlloc(sizeof(X)); x->i = i; return x; }
    350 static void xFree(X *x) { psFree(x); }
    351 
    352 int main(void)
    353 {
    354     psDlist *list = psDlistAlloc(NULL); // list of metadata
    355 
    356     psDlistAppend(list, xAlloc(1));
    357     psDlistAppend(list, xAlloc(2));
    358     psDlistAppend(list, xAlloc(3));
    359     /*
    360      * Print that data
    361      */
    362     for (psDlistElem *ptr = list->head; ptr != NULL; ptr = ptr->next) {
    363         printf("%d ", ((X *)(ptr->data))->i);
    364     }
    365     printf("\n");
    366     /*
    367      * Print it again
    368      */
    369     (void)psDlistGet(list, PS_DLIST_TAIL); // initialise iterator
    370     X *x = NULL;
    371     while ((x = psDlistGet(list, PS_DLIST_PREV)) != NULL) {
    372         printf("%d ", x->i);
    373     }
    374     printf("\n");
    375 #if 1
    376     /*
    377      * Convert to an array
    378      */
    379     psVoidPtrArray *arr = psDlistToArray(list);
    380     list = NULL;                        // it's been freed
    381 
    382     for (int i = 0; i < arr->n; i++) {
    383         printf("%d ", ((X *)(arr->arr[i]))->i);
    384     }
    385     printf("\n");
    386 #if 1
    387     /*
    388      * Convert back to a list
    389      */
    390     list = psArrayToDlist(arr);
    391     arr = NULL;                         // it's been freed
    392 
    393     (void)psDlistGet(list, PS_DLIST_TAIL); // initialise iterator
    394     while ((x = psDlistGet(list, PS_DLIST_PREV)) != NULL) {
    395         printf("%d ", x->i);
    396     }
    397     printf("\n");
    398 #endif
    399     psVoidPtrArrayFree(arr, (void (*)(void *))xFree);
    400 #endif
    401 
    402 #if 1
    403     list = psArrayToDlist(psDlistToArray(list));
    404 
    405     (void)psDlistGet(list, PS_DLIST_TAIL); // initialise iterator
    406     while ((x = psDlistGet(list, PS_DLIST_PREV)) != NULL) {
    407         printf("%d ", x->i);
    408     }
    409     printf("\n");
    410 #endif
    411     /*
    412      * Clean up
    413      */
    414     psDlistFree(list, (void (*)(void *))xFree);
    415     /*
    416      * Check for memory leaks
    417      */
    418     fprintf(stderr,"Checking for memory leaks:\n");
    419     psMemCheckLeaks(0, NULL, stderr);
    420    
    421     return 0;
    422 }
    423 #endif
Note: See TracChangeset for help on using the changeset viewer.