IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 265


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

Moved test code to tst_*.c

Location:
trunk/archive/pslib/src/Utils
Files:
4 edited

Legend:

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

    r164 r265  
    3636    my_psVoidPtrArrayFree(arr);
    3737}
    38 
    39 /*****************************************************************************/
    40 #if 0                                   // testing
    41 
    42 typedef struct {
    43     int x, y;
    44 } psXY;
    45 
    46 psXY *psXYAlloc(void)
    47 {
    48     return psAlloc(sizeof(psXY));
    49 }
    50 
    51 void psXYFree(psXY *xy)
    52 {
    53     psFree(xy);
    54 }
    55 
    56 PS_DECLARE_ARRAY_TYPE(psXY);
    57 PS_CREATE_ARRAY_TYPE(psXY);
    58 
    59 PS_DECLARE_ARRAY_PTR_TYPE(psXY);
    60 PS_CREATE_ARRAY_PTR_TYPE(psXY);
    61 
    62 int main(void)
    63 {
    64     psXYArray *t = psXYArrayAlloc(10, 15);
    65     psXYPtrArray *pt = psXYPtrArrayAlloc(10, 10);
    66 
    67     for (int i = 0; i < t->n; i++) {
    68         t->arr[i].x = i;
    69         pt->arr[i]->y = 10*i;
    70     }
    71 
    72     t = psXYArrayRealloc(t, 5);
    73     t = psXYArrayRealloc(t, 8);
    74 
    75     for (int i = 0; i < t->n; i++) {
    76         printf("%d %d  ", t->arr[i].x, pt->arr[i]->y);
    77     }
    78     printf("\n");
    79    
    80     psXYArrayFree(t);
    81 
    82     psXY *xy = psMemDecrRefCounter(pt->arr[0]);
    83     pt->arr[0] = NULL;
    84     psXYFree(xy);   
    85    
    86     psXYPtrArrayFree(pt);
    87 
    88     psMemCheckLeaks(0, NULL, stderr);
    89 
    90     return 0;
    91 }
    92 #endif
  • 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
  • trunk/archive/pslib/src/Utils/hash.c

    r173 r265  
    224224    return doHashWork(table, key, NULL, 1, NULL);
    225225}
    226 
    227 /*****************************************************************************/
    228 #if 0                                   // testing
    229 
    230 typedef struct { char *name; } ID;
    231 static ID *IdAlloc(const char *name)
    232 {
    233     ID *id = psAlloc(sizeof(ID));
    234     id->name = psStringCopy(name);
    235 
    236     return id;
    237 }
    238 
    239 static void IdFree(ID *id)
    240 {
    241     if (psMemGetRefCounter(id) > 1) {
    242         psMemDecrRefCounter(id);
    243         return;
    244     }
    245 
    246     psFree(id->name);
    247     psFree(id);
    248 }
    249 
    250 int main(void)
    251 {
    252     psSetTraceLevel("utils.hash", 3);
    253     long memId0 = psMemGetId();
    254 
    255     psHash *hash = psHashAlloc(16);
    256 
    257     psHashInsert(hash, "Lynda", IdAlloc("Lee"), (void (*)(void *))IdFree);
    258     psHashInsert(hash, "Lynda", IdAlloc("Lee"), (void (*)(void *))IdFree);
    259     psHashInsert(hash, "Robert", IdAlloc("Lupton"), (void (*)(void *))IdFree);
    260     psHashInsert(hash, "Robert", IdAlloc("the Good"), (void (*)(void *))IdFree);
    261 
    262     char *names[] = {"Robert", "Lynda", "Rowan", NULL};
    263     for (char **name = names; *name != NULL; name++) {
    264         ID *id = psHashLookup(hash, *name);
    265         printf("%s's surname is:\t%s\n", *name,
    266                ((id == NULL) ? "(unknown)" : id->name));
    267     }
    268 
    269     psHashFree(hash, (void (*)(void *))IdFree);
    270     /*
    271      * Check for memory leaks
    272      */
    273     fprintf(stderr,"Checking for memory leaks:\n");
    274     psMemCheckLeaks(memId0, NULL, stderr);
    275 
    276     return 0;
    277 }
    278    
    279 #endif
  • trunk/archive/pslib/src/Utils/logmsg.c

    r174 r265  
    226226    va_end(ap);
    227227}
    228 
    229 /*****************************************************************************/
    230 #if 0                                   // testing
    231 
    232 int main(void)
    233 {
    234     psSetTraceLevel("utils.logMsg", 1);
    235    
    236     psSetLogDestination(PS_LOG_TO_STDERR);
    237     psSetLogLevel(PS_LOG_INFO);
    238     psSetLogFormat("NM");
    239    
    240     psLogMsg("aaa", PS_LOG_INFO, "Hello World\n");
    241     psAbort("bbb", "I'm in Hawai`i");
    242 
    243     return 0;
    244 }
    245 #endif
Note: See TracChangeset for help on using the changeset viewer.