IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 7778


Ignore:
Timestamp:
Jun 30, 2006, 5:51:56 PM (20 years ago)
Author:
magnier
Message:

more updates to tap_psVector.c

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/mathtypes/tap_psVector.c

    r7777 r7778  
    55int main (void)
    66{
    7     plan_tests(11);
     7    plan_tests(39);
    88
    99    {
     
    4444    }
    4545
    46     return exit_status();
    47 }
    48 
    49 #if 0
    50 psS32 testVectorRealloc(void)
    51 {
    52     // create new psVector
    53     psVector *psVec = psVectorAlloc(5, PS_TYPE_S32);
    54     if (psVec == NULL) {
    55         fprintf(stderr,"ERROR: Return is NULL\n");
    56         return 30;
    57     }
    58     for(psS32 i = 0; i < 5; i++) {
    59         psVec->data.S32[i] = i*10;
    60         psVec->n++;
    61     }
    62 
    63     // Test C - Reallocate S32 vector bigger
    64     psVec = psVectorRealloc(psVec,10);
    65     if (psVec == NULL) {
    66         fprintf(stderr,"ERROR: Return is NULL\n");
    67         return 1;
    68     }
    69     if (psVec->nalloc != 10) {
    70         fprintf(stderr,"Vector size = %ld\n", psVec->nalloc);
    71         return 1;
    72     }
    73     if (psVec->n != 5) {
    74         fprintf(stderr,"Vector population = %ld\n", psVec->n);
    75         return 2;
    76     }
    77 
    78     if (psVec->type.type != PS_TYPE_S32) {
    79         fprintf(stderr,"Vector type = %d\n", psVec->type.type);
    80         return 3;
    81     }
    82     if (psVec->type.dimen != PS_DIMEN_VECTOR) {
    83         fprintf(stderr,"Vector dimen = %d\n", psVec->type.dimen);
    84         return 4;
    85     }
    86 
    87     for(psS32 i = 5; i < 10; i++) {
    88         psVec->data.S32[i] = i*10;
    89         psVec->n++;
    90     }
    91 
    92     for(psS32 i = 0; i < 10; i++) {
    93         if (psVec->data.S32[i] != i*10) {
    94             fprintf(stderr,"Elem %d = %d, expected %d\n", i,
    95                     psVec->data.S32[i], i*10);
    96             return 5;
    97         }
    98     }
    99 
    100     // Test D - Reallocate S32 vector smaller
    101     psVec = psVectorRealloc(psVec,3);
    102     if (psVec == NULL) {
    103         fprintf(stderr,"ERROR: Return is NULL\n");
    104         return 9;
    105     }
    106     if (psVec->nalloc != 3) {
    107         fprintf(stderr,"Vector size = %ld\n", psVec->nalloc);
    108         return 10;
    109     }
    110     if (psVec->n != 3) {
    111         fprintf(stderr,"Vector population = %ld\n", psVec->n);
    112         return 11;
    113     }
    114 
    115     for(psS32 i = 0; i < 3; i++) {
    116         if (psVec->data.S32[i] != i*10) {
    117             fprintf(stderr,"Elem %d = %d, expected %d\n", i,
    118                     psVec->data.S32[i], i*10);
    119             return 12;
    120         }
    121     }
    122 
    123     psVec = psVectorRealloc(psVec,0);
    124     if (psVec == NULL) {
    125         fprintf(stderr,"ERROR: Return is NULL\n");
    126         return 20;
    127     }
    128     if (psVec->nalloc != 0) {
    129         fprintf(stderr,"Vector size = %ld\n", psVec->nalloc);
    130         return 21;
    131     }
    132     if (psVec->n != 0) {
    133         fprintf(stderr,"Vector population = %ld\n", psVec->n);
    134         return 22;
    135     }
    136 
    137     psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message");
    138     psVector* vecBogus = psVectorRealloc(NULL, 6);
    139     if (vecBogus != NULL) {
    140         fprintf(stderr,"Huh!  bogus type generated a psVector?");
    141         return 25;
    142     }
    143 
    144     // Test E - Free S32 vector
    145     psFree(psVec);
    146 
    147     return 0;
    148 }
     46    {
     47        // create new psVector
     48        psVector *psVec = psVectorAlloc(5, PS_TYPE_S32);
     49
     50        diag("psVector Realloc tests");
     51        ok (psVec != NULL, "test vector allocated");
     52
     53        // generate first part of vector
     54        for(psS32 i = 0; i < 5; i++) {
     55            psVec->data.S32[i] = i*10;
     56            psVec->n++;
     57        }
     58
     59        // Test C - Reallocate S32 vector bigger
     60        psVec = psVectorRealloc(psVec,10);
     61        ok (psVec != NULL, "test vector reallocated to bigger size");
     62        ok (psVec->nalloc == 10, "Vector size = %ld", psVec->nalloc);
     63        ok (psVec->n == 5, "Vector population = %ld", psVec->n);
     64        ok (psVec->type.type == PS_TYPE_S32, "Vector type = %d", psVec->type.type);
     65        ok (psVec->type.dimen == PS_DIMEN_VECTOR, "Vector dimen = %d", psVec->type.dimen);
     66
     67        // generate test data values
     68        for(psS32 i = 5; i < 10; i++) {
     69            psVec->data.S32[i] = i*10;
     70            psVec->n++;
     71        }
     72
     73        // test data values
     74        for(psS32 i = 0; i < 10; i++) {
     75            ok (psVec->data.S32[i] == i*10, "Elem %d = %d, expected %d", i, psVec->data.S32[i], i*10);
     76        }
     77
     78        // Test D - Reallocate S32 vector smaller
     79        psVec = psVectorRealloc(psVec,3);
     80        ok (psVec != NULL, "test vector reallocated to smaller size");
     81        ok (psVec->nalloc == 3, "Vector size = %ld", psVec->nalloc);
     82        ok (psVec->n == 3, "Vector population = %ld", psVec->n);
     83
     84        // test data values
     85        for(psS32 i = 0; i < 3; i++) {
     86            ok (psVec->data.S32[i] == i*10, "Elem %d = %d, expected %d", i, psVec->data.S32[i], i*10);
     87        }
     88
     89        // reallocate to 0 length
     90        psVec = psVectorRealloc(psVec,0);
     91        ok (psVec != NULL, "test vector reallocated to zero length");
     92        ok (psVec->nalloc == 0, "Vector size = %ld", psVec->nalloc);
     93        ok (psVec->n == 0, "Vector population = %ld", psVec->n);
     94
     95        // Test E - Free S32 vector
     96        // XXX not really a test...
     97        psFree(psVec);
     98    }
     99
     100    {
     101        psVector* vecBogus = psVectorRealloc(NULL, 6);
     102
     103        ok(vecBogus == NULL, "psVectorAlloc() doesn't not accept bogus type");
     104        psErr *err = psErrorLast();
     105
     106        skip_start(err == NULL, 2, "Skipping 2 tests because psVectorAlloc() didn't fail as expect");
     107        ok(strstr(err->name, "psVectorRealloc"), "alloc failure - got error name %s", err->name);
     108        ok(err->code == PS_ERR_BAD_PARAMETER_NULL, "alloc failure - got error code %d", err->code);
     109        skip_end();
     110
     111        psFree(vecBogus);
     112
     113        return exit_status();
     114    }
     115}
     116
     117# if 0
    149118
    150119psS32 testVectorExtend(void)
Note: See TracChangeset for help on using the changeset viewer.