IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 4044


Ignore:
Timestamp:
May 27, 2005, 3:02:08 PM (21 years ago)
Author:
asc
Message:

added tests for bug #419

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/dataIO/tst_psDB.c

    r3963 r4044  
    99 *  @author Aaron Culliney, MHPCC
    1010 *
    11  *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2005-05-18 23:41:06 $
     11 *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2005-05-28 01:02:08 $
    1313 *
    1414 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3535#define F64_1 2.7182818
    3636#define F64_2 1.23456789
     37#define B_1 TRUE
     38#define B_2 FALSE
    3739
    3840static psDB *_init_psDB( void );
    3941static psMetadata *_get_CreateTableMetadata( void );
    40 static psMetadata *_get_RowMetadataValues(const char *val0, psS32 val1, psF32 val2, psF64 val3);
     42static psMetadata *_get_RowMetadataValues(const char *val0, psS32 val1, psF32 val2, psF64 val3, psBool val4);
    4143static psMetadata *_get_RowMetadata(
    4244    const char *key0, const char *comm0, const char *val0,
    43     const char *key1, const char *comm1, psS32 val1,
    44     const char *key2, const char *comm2, psF32 val2,
    45     const char *key3, const char *comm3, psF64 val3,
    46     const char *key4, const char *comm4, psS32 val4);
     45    const char *key1, const char *comm1, psS32  val1,
     46    const char *key2, const char *comm2, psF32  val2,
     47    const char *key3, const char *comm3, psF64  val3,
     48    const char *key4, const char *comm4, psBool val4,
     49    const char *key5, const char *comm5, psS32  val5);
    4750static psMetadata *_get_row( void );
    4851static psMetadata *_get_where( void );
    49 static psMetadata *_get_update_values(const char *val0, psS32 val1, psF32 val2, psF64 val3);
     52static psMetadata *_get_update_values(const char *val0, psS32 val1, psF32 val2, psF64 val3, psBool val4);
    5053static void _print_row( psMetadata *row );
    5154
     
    112115               "key_f32",    "Key",                0.0,
    113116               "key_f64",    "",                   0.0,
     117               "key_bool",   "",                   FALSE,
    114118               "key_s32_0",  "Key,AUTO_INCREMENT", 0);
    115119}
    116120
    117 psMetadata *_get_RowMetadataValues(const char *val0, psS32 val1, psF32 val2, psF64 val3)
     121psMetadata *_get_RowMetadataValues(const char *val0, psS32 val1, psF32 val2, psF64 val3, psBool val4)
    118122{
    119123    return _get_RowMetadata(
     
    122126               "key_f32",    "comment-f32",    val2,
    123127               "key_f64",    "comment-f64",    val3,
     128               "key_bool",   "comment-bool",   val4,
    124129               NULL,         NULL,             0.0);
    125130}
     
    127132psMetadata *_get_RowMetadata(
    128133    const char *key0, const char *comm0, const char *val0,
    129     const char *key1, const char *comm1, psS32 val1,
    130     const char *key2, const char *comm2, psF32 val2,
    131     const char *key3, const char *comm3, psF64 val3,
    132     const char *key4, const char *comm4, psS32 val4)
     134    const char *key1, const char *comm1, psS32  val1,
     135    const char *key2, const char *comm2, psF32  val2,
     136    const char *key3, const char *comm3, psF64  val3,
     137    const char *key4, const char *comm4, psBool val4,
     138    const char *key5, const char *comm5, psS32  val5)
    133139{
    134140    psMetadata *md = NULL;
    135     psMetadataItem *str=NULL, *s32_0=NULL, *s32=NULL, *f32=NULL, *f64=NULL;
     141    psMetadataItem *str=NULL, *s32_0=NULL, *s32=NULL, *f32=NULL, *f64=NULL, *b;
    136142
    137143    md = psMetadataAlloc();
     
    143149        str = psMetadataItemAllocStr(key0, comm0, val0);
    144150    }
    145     if (key4 != NULL) {
    146         s32_0 = psMetadataItemAllocS32(key4, comm4, val4);
    147     }
    148     s32 = psMetadataItemAllocS32(key1, comm1, val1);
    149     f32 = psMetadataItemAllocF32(key2, comm2, val2);
    150     f64 = psMetadataItemAllocF64(key3, comm3, val3);
    151 
    152     if ( ((key0 != NULL) && (str == NULL)) || (s32 == NULL) || (f32 == NULL) || (f64 == NULL) ||
    153             ((key4 != NULL) && (s32_0 == NULL)) ) {
     151    if (key5 != NULL) {
     152        s32_0 = psMetadataItemAllocS32(key5, comm5, val5);
     153    }
     154    s32 = psMetadataItemAllocS32 (key1, comm1, val1);
     155    f32 = psMetadataItemAllocF32 (key2, comm2, val2);
     156    f64 = psMetadataItemAllocF64 (key3, comm3, val3);
     157    b   = psMetadataItemAllocBool(key4, comm4, val4);
     158
     159    if ( ((key0 != NULL) && (str == NULL)) || (s32 == NULL) || (f32 == NULL) || (f64 == NULL) || (b == NULL) ||
     160            ((key5 != NULL) && (s32_0 == NULL)) ) {
    154161        psError(PS_ERR_UNKNOWN, true, "could not create psMetadataItem(s) in %s!", __func__ );
    155162        return NULL;
    156163    }
    157     if ( ((key0 != NULL) && !psMetadataAddItem(md, str, 0, 0)) || !psMetadataAddItem(md, s32, 0, 0) ||
    158             !psMetadataAddItem(md, f32, 0, 0) || !psMetadataAddItem(md, f64, 0, 0) ||
    159             ((key4 != NULL) && !psMetadataAddItem(md, s32_0, 0, 0))) {
     164    if ( ((key0 != NULL) && !psMetadataAddItem(md, str, 0, 0)) ||
     165            !psMetadataAddItem(md, s32, 0, 0) || !psMetadataAddItem(md, f32, 0, 0) ||
     166            !psMetadataAddItem(md, f64, 0, 0) || !psMetadataAddItem(md, b,   0, 0) ||
     167            ((key5 != NULL) && !psMetadataAddItem(md, s32_0, 0, 0))) {
    160168        psError(PS_ERR_UNKNOWN, true, "could not add psMetadataItem(s) to psMetadata in %s!", __func__ );
    161169        return NULL;
     
    168176    psFree(f32);
    169177    psFree(f64);
     178    psFree(b);
    170179    if (s32_0 != NULL) {
    171180        psFree(s32_0);
     
    184193               "key_f32",    "comment-f32",    (double)rand()/RAND_MAX,
    185194               "key_f64",    "comment-f64",    (double)rand()/RAND_MAX,
     195               "key_bool",   "comment-bool",   round((double)rand()/RAND_MAX),
    186196               NULL,         NULL,             0.0);
    187197}
     
    194204               "key_f32",    "comment-f32",    F32_1,
    195205               "key_f64",    "comment-f64",    F64_1,
     206               "key_bool",   "comment-bool",   B_1,
    196207               NULL,         NULL,             0.0);
    197208}
     
    221232}
    222233
    223 psMetadata *_get_update_values(const char *val0, psS32 val1, psF32 val2, psF64 val3)
    224 {
    225     return _get_RowMetadataValues(val0, val1, val2, val3);
     234psMetadata *_get_update_values(const char *val0, psS32 val1, psF32 val2, psF64 val3, psBool val4)
     235{
     236    return _get_RowMetadataValues(val0, val1, val2, val3, val4);
    226237}
    227238
     
    241252        } else if (item->type == PS_META_F64) {
    242253            psLogMsg( __func__, PS_LOG_INFO, "[%s]=[%g]\n", item->name, item->data.F64 );
     254        } else if (item->type == PS_META_BOOL) {
     255            psLogMsg( __func__, PS_LOG_INFO, "[%s]=[%s]\n", item->name, item->data.B ? "Yay" : "Nay" );
    243256        }
    244257    }
     
    409422            psFree(ary);
    410423        }
     424
     425        ary = psDBSelectColumn(dbh, table, "key_bool", 0);
     426        if (ary == NULL) {
     427            failed = 1;
     428        } else {
     429            ptr = psArrayGet(ary, 2);
     430            psLogMsg( __func__, PS_LOG_INFO, "psDBSelectColumn: [%s]\n", ptr );
     431
     432            ptr = psArrayGet(ary, 1);
     433            psLogMsg( __func__, PS_LOG_INFO, "psDBSelectColumn: [%s]\n", ptr );
     434
     435            ptr = psArrayGet(ary, 0);
     436            psLogMsg( __func__, PS_LOG_INFO, "psDBSelectColumn: [%s]\n", ptr );
     437
     438            if (atoi(ptr) != B_1) {
     439                psLogMsg( __func__, PS_LOG_INFO, "oops, did not find expected string output!\n" );
     440                failed = 1;
     441            } else {
     442                psLogMsg( __func__, PS_LOG_INFO, "found expected string output.\n" );
     443            }
     444
     445            psFree(ary);
     446        }
     447
    411448        psDBDropTable(dbh, table);
    412449    }
     
    464501            psFree(vec);
    465502        }
     503
     504        vec = psDBSelectColumnNum(dbh, table, "key_bool", PS_TYPE_BOOL, 0);
     505        if (vec == NULL) {
     506            failed = 1;
     507        } else {
     508            psLogMsg( __func__, PS_LOG_INFO, "bool=[%d]\n", (vec->data.U8)[2] );
     509            psLogMsg( __func__, PS_LOG_INFO, "bool=[%d]\n", (vec->data.U8)[1] );
     510            psLogMsg( __func__, PS_LOG_INFO, "bool=[%d]\n", (vec->data.U8)[0] );
     511            if ((vec->data.U8)[0] != B_1) {
     512                psLogMsg( __func__, PS_LOG_INFO, "oops, did not find expected bool output!\n" );
     513                failed = 1;
     514            } else {
     515                psLogMsg( __func__, PS_LOG_INFO, "found expected bool output.\n" );
     516            }
     517            psFree(vec);
     518        }
     519
    466520        psDBDropTable(dbh, table);
    467521    }
     
    531585                    }
    532586
     587                    item = psMetadataLookup(row, "key_bool");
     588                    if (item == NULL) {
     589                        psLogMsg( __func__, PS_LOG_INFO, "oops, key_bool not found!\n" );
     590                        failed = 1;
     591                    } else if (item->data.B != B_1) {
     592                        psLogMsg( __func__, PS_LOG_INFO, "oops, did not find expected output (%d vs %d)!\n",
     593                                  item->data.B,B_1);
     594                        failed = 1;
     595                    } else {
     596                        psLogMsg( __func__, PS_LOG_INFO, "found expected output.\n" );
     597                    }
     598
    533599                    psFree(ary);
    534600                }
     
    628694            }
    629695
     696            item = psMetadataLookup(row, "key_bool");
     697            if ((item == NULL) || (item->data.B != B_1)) {
     698                psLogMsg( __func__, PS_LOG_INFO, "oops, did not find expected output!\n" );
     699                failed = 1;
     700            } else {
     701                psLogMsg( __func__, PS_LOG_INFO, "found expected output.\n" );
     702            }
     703
    630704            psFree(rowSet);
    631705        }
     
    691765                }
    692766
     767                item = psMetadataLookup(row, "key_bool");
     768                if ((item == NULL) || (item->data.B != B_1)) {
     769                    psLogMsg( __func__, PS_LOG_INFO, "oops, did not find expected output!\n" );
     770                    failed = 1;
     771                } else {
     772                    psLogMsg( __func__, PS_LOG_INFO, "found expected output.\n" );
     773                }
     774
    693775                psFree(ary);
    694776            }
     
    710792    psDB *dbh = NULL;
    711793    const char* table = "table9";
    712     psMetadata *meta=NULL, *md = _get_CreateTableMetadata();
     794    psMetadata *row=NULL, *meta=NULL, *md = _get_CreateTableMetadata();
    713795
    714796    dbh = _init_psDB();
     
    721803    failed = ! psDBCreateTable(dbh, table, md);
    722804    if (!failed) {
     805
     806        row = _get_rand_row();
     807        psDBInsertOneRow(dbh, table, row);
     808        psFree(row);
     809
     810        row = _get_rand_row();
     811        psDBInsertOneRow(dbh, table, row);
     812        psFree(row);
     813
     814        row = _get_row();
     815        failed = ! psDBInsertOneRow(dbh, table, row);
     816        psFree(row);
     817
    723818        meta = psDBDumpCols(dbh, table);
    724819        if (meta == NULL) {
     
    774869        if (!failed) {
    775870            where = _get_where();
    776             updates = _get_update_values(STR_2, S32_2, F32_2, F64_2);
     871            updates = _get_update_values(STR_2, S32_2, F32_2, F64_2, B_2);
    777872            failed = (psDBUpdateRows(dbh, table, where, updates) < 0);
    778873
     
    787882                item = psMetadataLookup(row, "key_s32");
    788883                if ((item == NULL) || (item->data.S32 != S32_2)) {
     884                    psLogMsg( __func__, PS_LOG_INFO, "oops, did not find expected output!\n" );
     885                    failed = 1;
     886                } else {
     887                    psLogMsg( __func__, PS_LOG_INFO, "found expected output.\n" );
     888                }
     889
     890                item = psMetadataLookup(row, "key_bool");
     891                if ((item == NULL) || (item->data.B != B_2)) {
    789892                    psLogMsg( __func__, PS_LOG_INFO, "oops, did not find expected output!\n" );
    790893                    failed = 1;
Note: See TracChangeset for help on using the changeset viewer.