IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 4280


Ignore:
Timestamp:
Jun 15, 2005, 3:49:23 PM (21 years ago)
Author:
evanalst
Message:

Update test case for psDBSelectColumn.

Location:
trunk/psLib/test/dataIO
Files:
2 edited

Legend:

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

    r4272 r4280  
    99 *  @author Aaron Culliney, MHPCC
    1010 *
    11  *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2005-06-15 19:53:05 $
     11 *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2005-06-16 01:49:23 $
    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 CONST_ROW_1_STR      "randrow1"
     41#define CONST_ROW_1_S32      12345
     42#define CONST_ROW_1_F32      9876.5
     43#define CONST_ROW_1_F64      456.75
     44#define CONST_ROW_1_BOOL     TRUE
     45
     46#define CONST_ROW_2_STR      "randrow2"
     47#define CONST_ROW_2_S32      2345
     48#define CONST_ROW_2_F32      876.5
     49#define CONST_ROW_2_F64      56.75
     50#define CONST_ROW_2_BOOL     FALSE
    3951
    4052static psDB *_init_psDB( void );
     
    7486                              {TPDBCreateTable,    843,  "dbCreateTable",     0, false},
    7587                              {TPDBDropTable,      844,  "dbDropTable",       0, false},
    76                               {TPDBSelectColumn,    -5,  "dbSelectColumn",    0, false},
     88                              {TPDBSelectColumn,   845,  "dbSelectColumn",    0, false},
    7789                              {TPDBSelectColumnNum, -6,  "dbSelectColumnNum", 0, false},
    7890                              {TPDBSelectRows,      -7,  "dbSelectRows",      0, false},
     
    186198{
    187199    char buf[32];
    188     snprintf(buf, 32, "%s","randrow1" );
     200    snprintf(buf, 32, "%s", CONST_ROW_1_STR );
    189201    return _get_RowMetadata(
    190202               "key_string", "comment-string", buf,
    191                //               "key_s32",    "comment-s32",    rand(),
    192                "key_s32",    "comment-s32",    12345,
    193                //               "key_f32",    "comment-f32",    (double)rand()/RAND_MAX,
    194                "key_f32",    "comment-f32",    9876.5,
    195                //               "key_f64",    "comment-f64",    (double)rand()/RAND_MAX,
    196                "key_f64",    "comment-f64",    456.75,
    197                //               "key_bool",   "comment-bool",   round((double)rand()/RAND_MAX),
    198                "key_bool",   "comment-bool",   true,
     203               "key_s32",    "comment-s32",    CONST_ROW_1_S32,
     204               "key_f32",    "comment-f32",    CONST_ROW_1_F32,
     205               "key_f64",    "comment-f64",    CONST_ROW_1_F64,
     206               "key_bool",   "comment-bool",   CONST_ROW_1_BOOL,
    199207               NULL,         NULL,             0.0);
    200208}
     
    203211{
    204212    char buf[32];
    205     snprintf(buf, 32, "%s","randrow2");
     213    snprintf(buf, 32, "%s",CONST_ROW_2_STR);
    206214    return _get_RowMetadata(
    207215               "key_string", "comment-string", buf,
    208                //               "key_s32",    "comment-s32",    rand(),
    209                "key_s32",    "comment-s32",    2345,
    210                //               "key_f32",    "comment-f32",    (double)rand()/RAND_MAX,
    211                "key_f32",    "comment-f32",    876.5,
    212                //               "key_f64",    "comment-f64",    (double)rand()/RAND_MAX,
    213                "key_f64",    "comment-f64",    56.75,
    214                //               "key_bool",   "comment-bool",   round((double)rand()/RAND_MAX),
    215                "key_bool",   "comment-bool",   false,
     216               "key_s32",    "comment-s32",    CONST_ROW_2_S32,
     217               "key_f32",    "comment-f32",    CONST_ROW_2_F32,
     218               "key_f64",    "comment-f64",    CONST_ROW_2_F64,
     219               "key_bool",   "comment-bool",   CONST_ROW_2_BOOL,
    216220               NULL,         NULL,             0.0);
    217221}
     
    408412psS32 TPDBDropTable( void )
    409413{
    410     psS32 failed = 0;
    411414    psDB *dbh = NULL;
    412415    const char* table = "table2";
     
    423426
    424427    // Create table in database
    425     failed = ! psDBCreateTable(dbh, table, md);
    426     if (!failed) {
     428    if(psDBCreateTable(dbh, table, md)) {
    427429
    428430        // Drop table with valid arguments
    429         failed = ! psDBDropTable(dbh, table);
     431        if(!psDBDropTable(dbh, table)) {
     432            psError(PS_ERR_UNKNOWN,true,"Did not expect return false for valid arguments");
     433            return 2;
     434        }
    430435
    431436        // insert should fail since the table has been drop from database
     
    433438        row = _get_row();
    434439        if (psDBInsertOneRow(dbh, table, row)) {
    435             psLogMsg( __func__, PS_LOG_INFO, "oops, insert unexpectedly succeeded!\n" );
    436             failed = 1;
     440            psError(PS_ERR_UNKNOWN,true,"Did not expect to successfully insert row into dropped table");
     441            return 3;
    437442        }
    438443        psFree(row);
     444    } else {
     445        psError(PS_ERR_UNKNOWN,true,"Did not expect return false to create table");
     446        return 4;
    439447    }
    440448
     
    443451    if(psDBDropTable(NULL,table)) {
    444452        psError(PS_ERR_UNKNOWN,true,"Did not return false as expected for NULL database object");
    445         return 2;
     453        return 5;
    446454    }
    447455
     
    450458    if(psDBDropTable(dbh,"table99")) {
    451459        psError(PS_ERR_UNKNOWN,true,"Did not return false as expected for invalid table");
    452         return 3;
     460        return 6;
    453461    }
    454462
     
    457465    if(psDBDropTable(dbh,NULL)) {
    458466        psError(PS_ERR_UNKNOWN,true,"Did not return false as expected for NULL table");
    459         return 4;
     467        return 7;
    460468    }
    461469
     
    463471    psDBCleanup(dbh);
    464472
    465     return failed;
    466 }
    467 
    468 // Testpoint #XXX, TPDBSelectColumn shall write/select a column from a test table ...
     473    return 0;
     474}
     475
     476// Testpoint #845, TPDBSelectColumn shall write/select a column from a test table ...
    469477psS32 TPDBSelectColumn( void )
    470478{
    471     psS32 failed = 0;
    472479    psDB *dbh = NULL;
    473480    const char* table = "table3";
    474481    psArray *ary = NULL;
     482    char *ptr=NULL;
     483
     484    // Create table definition metadata
    475485    psMetadata *row=NULL, *md = _get_CreateTableMetadata();
    476     char *ptr=NULL;
    477 
     486
     487    // Initialize database connection
    478488    dbh = _init_psDB();
    479489    if (dbh == NULL) {
     490        psError(PS_ERR_UNKNOWN,true,"Did not expect return NULL to initialize database connection");
    480491        return 1;
    481492    }
    482493
    483     psLogMsg( __func__, PS_LOG_INFO, "psDBSelectColumn shall select data from a test table.\n" );
    484 
    485     failed = ! psDBCreateTable(dbh, table, md);
    486     if (!failed) {
    487 
    488         row = _get_const_row1();
    489         psDBInsertOneRow(dbh, table, row);
    490         psFree(row);
    491 
    492         row = _get_const_row2();
    493         psDBInsertOneRow(dbh, table, row);
    494         psFree(row);
    495 
    496         row = _get_row();
    497         psDBInsertOneRow(dbh, table, row);
    498         psFree(row);
    499 
    500         ary = psDBSelectColumn(dbh, table, "key_string", 0);
    501         if (ary == NULL) {
    502             failed = 1;
    503         } else {
    504             ptr = psArrayGet(ary, 2);
    505             psLogMsg( __func__, PS_LOG_INFO, "psDBSelectColumn: [%s]\n", ptr );
    506 
    507             ptr = psArrayGet(ary, 1);
    508             psLogMsg( __func__, PS_LOG_INFO, "psDBSelectColumn: [%s]\n", ptr );
    509 
    510             ptr = psArrayGet(ary, 0);
    511             psLogMsg( __func__, PS_LOG_INFO, "psDBSelectColumn: [%s]\n", ptr );
    512 
    513             if (strcmp(ptr, STR_1)) {
    514                 psLogMsg( __func__, PS_LOG_INFO, "oops, did not find expected string output!\n" );
    515                 failed = 1;
    516             } else {
    517                 psLogMsg( __func__, PS_LOG_INFO, "found expected string output.\n" );
    518             }
    519 
    520             psFree(ary);
    521         }
    522 
    523         ary = psDBSelectColumn(dbh, table, "key_bool", 0);
    524         if (ary == NULL) {
    525             failed = 1;
    526         } else {
    527             ptr = psArrayGet(ary, 2);
    528             psLogMsg( __func__, PS_LOG_INFO, "psDBSelectColumn: [%s]\n", ptr );
    529 
    530             ptr = psArrayGet(ary, 1);
    531             psLogMsg( __func__, PS_LOG_INFO, "psDBSelectColumn: [%s]\n", ptr );
    532 
    533             ptr = psArrayGet(ary, 0);
    534             psLogMsg( __func__, PS_LOG_INFO, "psDBSelectColumn: [%s]\n", ptr );
    535 
    536             if (atoi(ptr) != B_1) {
    537                 psLogMsg( __func__, PS_LOG_INFO, "oops, did not find expected output [%d] != [%d]!\n",
    538                           atoi(ptr), B_1 );
    539                 failed = 1;
    540             } else {
    541                 psLogMsg( __func__, PS_LOG_INFO, "found expected string output.\n" );
    542             }
    543 
    544             psFree(ary);
    545         }
    546 
    547         psDBDropTable(dbh, table);
    548     }
    549 
     494    // Create database table
     495    if(!psDBCreateTable(dbh,table,md)) {
     496        psError(PS_ERR_UNKNOWN,true,"Unable to create database table for testing");
     497        psDBCleanup(dbh);
     498        return 2;
     499    }
     500
     501    // Insert known constant row #1
     502    row = _get_const_row1();
     503    if(!psDBInsertOneRow(dbh, table, row)) {
     504        psError(PS_ERR_UNKNOWN,true,"Unable to add rows to test database");
     505        psDBDropTable(dbh, table);
     506        psDBCleanup(dbh);
     507        return 3;
     508    }
     509    psFree(row);
     510
     511    // Insert known constant row #2
     512    row = _get_const_row2();
     513    if(!psDBInsertOneRow(dbh, table, row)) {
     514        psError(PS_ERR_UNKNOWN,true,"Unable to add rows to test database");
     515        psDBDropTable(dbh, table);
     516        psDBCleanup(dbh);
     517        return 4;
     518    }
     519    psFree(row);
     520
     521    // Insert known row
     522    row = _get_row();
     523    if(!psDBInsertOneRow(dbh, table, row)) {
     524        psError(PS_ERR_UNKNOWN,true,"Unable to add rows to test database");
     525        psDBDropTable(dbh, table);
     526        psDBCleanup(dbh);
     527        return 5;
     528    }
     529    psFree(row);
     530
     531    // Select all items in column key_string with valid arguments
     532    ary = psDBSelectColumn(dbh, table, "key_string", 0);
     533    if (ary == NULL) {
     534        psError(PS_ERR_UNKNOWN,true,"Did not expect return value of NULL");
     535        psDBDropTable(dbh, table);
     536        psDBCleanup(dbh);
     537        return 6;
     538    }
     539
     540    // Verify array contents
     541    if(ary->n != 3) {
     542        psError(PS_ERR_UNKNOWN,true,"Array number of items %d not equal to expected %d",
     543                ary->n, 3);
     544        psDBDropTable(dbh, table);
     545        psDBCleanup(dbh);
     546        return 60;
     547    }
     548    ptr = psArrayGet(ary, 2);
     549    if (strcmp(ptr, CONST_ROW_1_STR)) {
     550        psError(PS_ERR_UNKNOWN,true,"key_str column entry[%d] = %s not as expected %s",
     551                2,CONST_ROW_1_STR,ptr);
     552        psDBDropTable(dbh, table);
     553        psDBCleanup(dbh);
     554        return 7;
     555    }
     556    ptr = psArrayGet(ary, 1);
     557    if (strcmp(ptr, CONST_ROW_2_STR)) {
     558        psError(PS_ERR_UNKNOWN,true,"key_str column entry[%d] = %s not as expected %s",
     559                1,CONST_ROW_2_STR,ptr);
     560        psDBDropTable(dbh, table);
     561        psDBCleanup(dbh);
     562        return 8;
     563    }
     564    ptr = psArrayGet(ary, 0);
     565    if (strcmp(ptr, STR_1)) {
     566        psError(PS_ERR_UNKNOWN,true,"key_str column entry[%d] = %s not as expected %s",
     567                0,STR_1,ptr);
     568        psDBDropTable(dbh, table);
     569        psDBCleanup(dbh);
     570        return 9;
     571    }
     572    psFree(ary);
     573
     574    // Select items in column key_bool with limit 10 and valid arguments
     575    ary = psDBSelectColumn(dbh, table, "key_bool", 10);
     576    if (ary == NULL) {
     577        psError(PS_ERR_UNKNOWN,true,"Did not expect return value of NULL");
     578        psDBDropTable(dbh, table);
     579        psDBCleanup(dbh);
     580        return 10;
     581    }
     582
     583    // Verify array contents
     584    if(ary->n != 3) {
     585        psError(PS_ERR_UNKNOWN,true,"Array number of items %d not equal to expected %d",
     586                ary->n, 3);
     587        psDBDropTable(dbh, table);
     588        psDBCleanup(dbh);
     589        return 100;
     590    }
     591    ptr = psArrayGet(ary, 2);
     592    if(atoi(ptr) != CONST_ROW_1_BOOL) {
     593        psError(PS_ERR_UNKNOWN,true,"key_bool column entry[%d] = %d not as expected %d",
     594                2,CONST_ROW_1_BOOL,atoi(ptr));
     595        psDBDropTable(dbh, table);
     596        psDBCleanup(dbh);
     597        return 11;
     598    }
     599    ptr = psArrayGet(ary, 1);
     600    if(atoi(ptr) != CONST_ROW_2_BOOL) {
     601        psError(PS_ERR_UNKNOWN,true,"key_bool column entry[%d] = %d not as expected %d",
     602                1,CONST_ROW_2_BOOL,atoi(ptr));
     603        psDBDropTable(dbh, table);
     604        psDBCleanup(dbh);
     605        return 12;
     606    }
     607    ptr = psArrayGet(ary, 0);
     608    if(atoi(ptr) != B_1) {
     609        psError(PS_ERR_UNKNOWN,true,"key_bool column entry[%d] = %d not as expected %d",
     610                0,B_1,atoi(ptr));
     611        psDBDropTable(dbh, table);
     612        psDBCleanup(dbh);
     613        return 13;
     614    }
     615    psFree(ary);
     616
     617    // Attempt to select columns from NULL database object
     618    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for NULL database");
     619    if(psDBSelectColumn(NULL,table,"key_str",10) != NULL) {
     620        psError(PS_ERR_UNKNOWN,true,"Did not expect non-NULL return for selecting from NULL database");
     621        psDBDropTable(dbh, table);
     622        psDBCleanup(dbh);
     623        return 14;
     624    }
     625
     626    // Attempt to select column from NULL table
     627    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for NULL table");
     628    if(psDBSelectColumn(dbh,NULL,"key_str",10) != NULL) {
     629        psError(PS_ERR_UNKNOWN,true,"Did not expect non-NULL return for NULL table");
     630        psDBDropTable(dbh, table);
     631        psDBCleanup(dbh);
     632        return 15;
     633    }
     634
     635    // Attempt to select column from invalid table
     636    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for invalid table");
     637    if(psDBSelectColumn(dbh,"table99","key_str",10) != NULL) {
     638        psError(PS_ERR_UNKNOWN,true,"Did not expect non-NULL return for invalid table");
     639        psDBDropTable(dbh, table);
     640        psDBCleanup(dbh);
     641        return 16;
     642    }
     643
     644    // Attempt to select invalid column from valid database object and valid table
     645    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for invalid column");
     646    if(psDBSelectColumn(dbh,table,"key_null",10) != NULL) {
     647        psError(PS_ERR_UNKNOWN,true,"Did not expect non-NULL return for invalid column");
     648        psDBDropTable(dbh, table);
     649        psDBCleanup(dbh);
     650        return 17;
     651    }
     652
     653    // Attempt to select NULL column from valid database object and valid table
     654    //    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for NULL column");
     655    //    if(psDBSelectColumn(dbh,table,NULL,10) != NULL) {
     656    //        psError(PS_ERR_UNKNOWN,true,"Did not expect non-NULL return for NULL column");
     657    //        return 18;
     658    //    }
     659
     660    // Clean up table and memory
     661    psDBDropTable(dbh, table);
    550662    psFree(md);
    551663    psDBCleanup(dbh);
    552664
    553     return failed;
     665    return 0;
    554666}
    555667
  • trunk/psLib/test/dataIO/verified/tst_psDB.stderr

    r4272 r4280  
    9292
    9393<DATE><TIME>|<HOST>|I|TPDBSelectColumn
    94     psDBSelectColumn shall select data from a test table.
     94    Following should generate error message for NULL database
     95<DATE><TIME>|<HOST>|E|p_psDBRunQuery (FILE:LINENO)
     96    Invalid psDB has been specified.
     97<DATE><TIME>|<HOST>|E|psDBSelectColumn (FILE:LINENO)
     98    Failed to select column.
    9599<DATE><TIME>|<HOST>|I|TPDBSelectColumn
    96     psDBSelectColumn: [randrow1]
     100    Following should generate error message for NULL table
     101<DATE><TIME>|<HOST>|E|p_psDBRunQuery (FILE:LINENO)
     102    Failed to execute SQL query.  Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'null) LIMIT 10' at line 1
     103<DATE><TIME>|<HOST>|E|psDBSelectColumn (FILE:LINENO)
     104    Failed to select column.
    97105<DATE><TIME>|<HOST>|I|TPDBSelectColumn
    98     psDBSelectColumn: [randrow2]
     106    Following should generate error message for invalid table
     107<DATE><TIME>|<HOST>|E|p_psDBRunQuery (FILE:LINENO)
     108    Failed to execute SQL query.  Error: Table 'test.table99' doesn't exist
     109<DATE><TIME>|<HOST>|E|psDBSelectColumn (FILE:LINENO)
     110    Failed to select column.
    99111<DATE><TIME>|<HOST>|I|TPDBSelectColumn
    100     psDBSelectColumn: [hello world!]
    101 <DATE><TIME>|<HOST>|I|TPDBSelectColumn
    102     found expected string output.
    103 <DATE><TIME>|<HOST>|I|TPDBSelectColumn
    104     psDBSelectColumn: [1]
    105 <DATE><TIME>|<HOST>|I|TPDBSelectColumn
    106     psDBSelectColumn: [0]
    107 <DATE><TIME>|<HOST>|I|TPDBSelectColumn
    108     psDBSelectColumn: [1]
    109 <DATE><TIME>|<HOST>|I|TPDBSelectColumn
    110     found expected string output.
     112    Following should generate error message for invalid column
     113<DATE><TIME>|<HOST>|E|p_psDBRunQuery (FILE:LINENO)
     114    Failed to execute SQL query.  Error: Unknown column 'key_null' in 'field list'
     115<DATE><TIME>|<HOST>|E|psDBSelectColumn (FILE:LINENO)
     116    Failed to select column.
    111117
    112118---> TESTPOINT PASSED (psDB{dbSelectColumn} | tst_psDB.c)
Note: See TracChangeset for help on using the changeset viewer.