IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 4317


Ignore:
Timestamp:
Jun 17, 2005, 5:22:43 PM (21 years ago)
Author:
evanalst
Message:

Update test case for psDBDumpRows.

File:
1 edited

Legend:

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

    r4310 r4317  
    99 *  @author Aaron Culliney, MHPCC
    1010 *
    11  *  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2005-06-18 00:52:17 $
     11 *  @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2005-06-18 03:22:43 $
    1313 *
    1414 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3737#define B_1 TRUE
    3838#define B_2 FALSE
     39
     40#define ERROR_TOL   0.001
    3941
    4042#define CONST_ROW_1_STR      "randrow1"
     
    6567static psMetadata *_get_update_values(const char *val0, psS32 val1, psF32 val2, psF64 val3, psBool val4);
    6668static void _print_row( psMetadata *row );
     69static bool _check_row(psMetadata* row);
     70static bool _check_const_row1(psMetadata* row);
     71static bool _check_const_row2(psMetadata* row);
    6772
    6873//static psS32 TPDBCreate( void );
     
    9297                              {TPDBInsertOneRow,   848,  "dbInsertOneRow",    0, false},
    9398                              {TPDBInsertRows,     849,  "dbInsertRows",      0, false},
    94                               {TPDBDumpRows,        -10, "dbDumpRows",        0, false},
     99                              {TPDBDumpRows,       850, "dbDumpRows",        0, false},
    95100                              {TPDBDumpCols,        -11, "dbDumpCols",        0, false},
    96101                              {TPDBUpdateRows,      -12, "dbUpdateRows",      0, false},
     
    271276{
    272277    return _get_RowMetadataValues(val0, val1, val2, val3, val4);
     278}
     279
     280bool _check_row(psMetadata* row)
     281{
     282    bool              returnValue = true;
     283    psMetadataItem*   item        = NULL;
     284
     285    item = psMetadataLookup(row,"key_string");
     286    if((item==NULL) || (strcmp(item->data.V,STR_1)!=0)) {
     287        psError(PS_ERR_UNKNOWN,true,"Column key_string item %s not as expected %s",
     288                item->data.V,STR_1);
     289        return false;
     290    }
     291
     292    item = psMetadataLookup(row,"key_s32");
     293    if((item==NULL) || (item->data.S32 != S32_1)) {
     294        psError(PS_ERR_UNKNOWN,true,"Column key_s32 item %d not as expected %d",
     295                item->data.S32, S32_1);
     296        return false;
     297    }
     298
     299    item = psMetadataLookup(row,"key_f32");
     300    if((item==NULL) || (fabs(item->data.F32-F32_1)>ERROR_TOL)) {
     301        psError(PS_ERR_UNKNOWN,true,"Column key_f32 item %f not as expected %f",
     302                item->data.F32, F32_1);
     303        return false;
     304    }
     305
     306    item = psMetadataLookup(row,"key_f64");
     307    if((item==NULL) || (fabs(item->data.F64-F64_1)>ERROR_TOL)) {
     308        psError(PS_ERR_UNKNOWN,true,"Column key_f64 item %lf not as expected %lf",
     309                item->data.F64,F64_1);
     310        return false;
     311    }
     312
     313    item = psMetadataLookup(row,"key_bool");
     314    if((item==NULL) || (item->data.B != B_1)) {
     315        psError(PS_ERR_UNKNOWN,true,"Column key_bool item %d not as expected %d",
     316                item->data.B, B_1);
     317        return false;
     318    }
     319
     320    return returnValue;
     321}
     322
     323bool _check_const_row1(psMetadata* row)
     324{
     325    bool              returnValue = true;
     326    psMetadataItem*   item        = NULL;
     327
     328    item = psMetadataLookup(row,"key_string");
     329    if((item==NULL) || (strcmp(item->data.V,CONST_ROW_1_STR)!=0)) {
     330        psError(PS_ERR_UNKNOWN,true,"Column key_string item %s not as expected %s",
     331                item->data.V,CONST_ROW_1_STR);
     332        return false;
     333    }
     334
     335    item = psMetadataLookup(row,"key_s32");
     336    if((item==NULL) || (item->data.S32 != CONST_ROW_1_S32)) {
     337        psError(PS_ERR_UNKNOWN,true,"Column key_s32 item %d not as expected %d",
     338                item->data.S32, CONST_ROW_1_S32);
     339        return false;
     340    }
     341
     342    item = psMetadataLookup(row,"key_f32");
     343    if((item==NULL) || (fabs(item->data.F32-CONST_ROW_1_F32)>ERROR_TOL)) {
     344        psError(PS_ERR_UNKNOWN,true,"Column key_f32 item %f not as expected %f",
     345                item->data.F32, CONST_ROW_1_F32);
     346        return false;
     347    }
     348
     349    item = psMetadataLookup(row,"key_f64");
     350    if((item==NULL) || (fabs(item->data.F64-CONST_ROW_1_F64)>ERROR_TOL)) {
     351        psError(PS_ERR_UNKNOWN,true,"Column key_f64 item %lf not as expected %lf",
     352                item->data.F64,CONST_ROW_1_F64);
     353        return false;
     354    }
     355
     356    item = psMetadataLookup(row,"key_bool");
     357    if((item==NULL) || (item->data.B != CONST_ROW_1_BOOL)) {
     358        psError(PS_ERR_UNKNOWN,true,"Column key_bool item %d not as expected %d",
     359                item->data.B, CONST_ROW_1_BOOL);
     360        return false;
     361    }
     362
     363    return returnValue;
     364}
     365
     366bool _check_const_row2(psMetadata* row)
     367{
     368    bool              returnValue = true;
     369    psMetadataItem*   item        = NULL;
     370
     371    item = psMetadataLookup(row,"key_string");
     372    if((item==NULL) || (strcmp(item->data.V,CONST_ROW_2_STR)!=0)) {
     373        psError(PS_ERR_UNKNOWN,true,"Column key_string item %s not as expected %s",
     374                item->data.V,CONST_ROW_2_STR);
     375        return false;
     376    }
     377
     378    item = psMetadataLookup(row,"key_s32");
     379    if((item==NULL) || (item->data.S32 != CONST_ROW_2_S32)) {
     380        psError(PS_ERR_UNKNOWN,true,"Column key_s32 item %d not as expected %d",
     381                item->data.S32, CONST_ROW_2_S32);
     382        return false;
     383    }
     384
     385    item = psMetadataLookup(row,"key_f32");
     386    if((item==NULL) || (fabs(item->data.F32-CONST_ROW_2_F32)>ERROR_TOL)) {
     387        psError(PS_ERR_UNKNOWN,true,"Column key_f32 item %f not as expected %f",
     388                item->data.F32, CONST_ROW_2_F32);
     389        return false;
     390    }
     391
     392    item = psMetadataLookup(row,"key_f64");
     393    if((item==NULL) || (fabs(item->data.F64-CONST_ROW_2_F64)>ERROR_TOL)) {
     394        psError(PS_ERR_UNKNOWN,true,"Column key_f64 item %lf not as expected %lf",
     395                item->data.F64,CONST_ROW_2_F64);
     396        return false;
     397    }
     398
     399    item = psMetadataLookup(row,"key_bool");
     400    if((item==NULL) || (item->data.B != CONST_ROW_2_BOOL)) {
     401        psError(PS_ERR_UNKNOWN,true,"Column key_bool item %d not as expected %d",
     402                item->data.B, CONST_ROW_2_BOOL);
     403        return false;
     404    }
     405
     406    return returnValue;
    273407}
    274408
     
    12371371}
    12381372
    1239 // Testpoint #XXX, TPDBDumpRows shall dump all rows from a test table ...
     1373// Testpoint #850, TPDBDumpRows shall dump all rows from a test table ...
    12401374psS32 TPDBDumpRows( void )
    12411375{
    1242     psS32 failed = 0;
    12431376    psDB *dbh = NULL;
    12441377    const char* table = "table8";
    12451378    psArray *ary = NULL;
     1379
     1380    // Create table definition metadata
    12461381    psMetadata *row=NULL, *md = _get_CreateTableMetadata();
    1247     psMetadataItem *item=NULL;
    1248 
     1382
     1383    // Initialize database connection
    12491384    dbh = _init_psDB();
    12501385    if (dbh == NULL) {
     1386        psError(PS_ERR_UNKNOWN,true,"Did not expect return NULL from initializing database");
    12511387        return 1;
    12521388    }
    12531389
    1254     psLogMsg( __func__, PS_LOG_INFO, "psDBDumpRows shall dump all rows from a test table.\n" );
    1255 
    1256     failed = ! psDBCreateTable(dbh, table, md);
    1257     if (!failed) {
    1258 
    1259         row = _get_const_row1();
    1260         psDBInsertOneRow(dbh, table, row);
    1261         psFree(row);
    1262 
    1263         row = _get_const_row2();
    1264         psDBInsertOneRow(dbh, table, row);
    1265         psFree(row);
    1266 
    1267         row = _get_row();
    1268         failed = ! psDBInsertOneRow(dbh, table, row);
    1269         psFree(row);
    1270 
    1271         if (!failed) {
    1272             ary = psDBDumpRows(dbh, table);
    1273             if (ary == NULL) {
    1274                 failed = 1;
    1275             } else {
    1276 
    1277                 _print_row((psMetadata*)psArrayGet(ary, 2));
    1278                 _print_row((psMetadata*)psArrayGet(ary, 1));
    1279                 row = (psMetadata*)psArrayGet(ary, 0);
    1280                 _print_row(row);
    1281 
    1282                 item = psMetadataLookup(row, "key_s32");
    1283                 if ((item == NULL) || (item->data.S32 != S32_1)) {
    1284                     psLogMsg( __func__, PS_LOG_INFO, "oops, did not find expected output!\n" );
    1285                     failed = 1;
    1286                 } else {
    1287                     psLogMsg( __func__, PS_LOG_INFO, "found expected output.\n" );
    1288                 }
    1289 
    1290                 item = psMetadataLookup(row, "key_bool");
    1291                 if ((item == NULL) || (item->data.B != B_1)) {
    1292                     psLogMsg( __func__, PS_LOG_INFO, "oops, did not find expected output!\n" );
    1293                     failed = 1;
    1294                 } else {
    1295                     psLogMsg( __func__, PS_LOG_INFO, "found expected output.\n" );
    1296                 }
    1297 
    1298                 psFree(ary);
    1299             }
    1300         }
    1301 
    1302         psDBDropTable(dbh, table);
    1303     }
     1390    // Create table for testing
     1391    if(!psDBCreateTable(dbh, table, md)) {
     1392        psError(PS_ERR_UNKNOWN,true,"Did not expect return false from creating table");
     1393        psDBCleanup(dbh);
     1394        return 2;
     1395    }
     1396
     1397    // Insert known data rows into table
     1398    row = _get_const_row1();
     1399    psDBInsertOneRow(dbh, table, row);
     1400    psFree(row);
     1401
     1402    row = _get_const_row2();
     1403    psDBInsertOneRow(dbh, table, row);
     1404    psFree(row);
     1405
     1406    row = _get_row();
     1407    psDBInsertOneRow(dbh, table, row);
     1408    psFree(row);
     1409
     1410    // Dump row with valid parameters
     1411    ary = psDBDumpRows(dbh, table);
     1412    if (ary == NULL) {
     1413        psError(PS_ERR_UNKNOWN,true,"Did not expect return NULL for dump rows");
     1414        psDBDropTable(dbh,table);
     1415        psDBCleanup(dbh);
     1416        return 3;
     1417    }
     1418    if(ary->n != 3) {
     1419        psError(PS_ERR_UNKNOWN,true,"Rows dumped %d not as expected %d",
     1420                ary->n, 3);
     1421        psDBDropTable(dbh,table);
     1422        psDBCleanup(dbh);
     1423        return 4;
     1424    }
     1425
     1426    row = (psMetadata*)psArrayGet(ary, 0);
     1427    if(!_check_row(row)) {
     1428        psDBDropTable(dbh,table);
     1429        psDBCleanup(dbh);
     1430        return 5;
     1431    }
     1432    row = (psMetadata*)psArrayGet(ary, 1);
     1433    if(!_check_const_row2(row)) {
     1434        psDBDropTable(dbh,table);
     1435        psDBCleanup(dbh);
     1436        return 6;
     1437    }
     1438    row = (psMetadata*)psArrayGet(ary, 2);
     1439    if(!_check_const_row1(row)) {
     1440        psDBDropTable(dbh,table);
     1441        psDBCleanup(dbh);
     1442        return 7;
     1443    }
     1444
     1445    psFree(ary);
     1446
     1447    psDBDropTable(dbh, table);
    13041448
    13051449    psFree(md);
    13061450    psDBCleanup(dbh);
    13071451
    1308     return failed;
     1452    return 0;
    13091453}
    13101454
Note: See TracChangeset for help on using the changeset viewer.