IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 4292


Ignore:
Timestamp:
Jun 16, 2005, 1:35:07 PM (21 years ago)
Author:
evanalst
Message:

Update test case for psDBSelectColumnNum.

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

Legend:

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

    r4280 r4292  
    99 *  @author Aaron Culliney, MHPCC
    1010 *
    11  *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2005-06-16 01:49:23 $
     11 *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2005-06-16 23:35:07 $
    1313 *
    1414 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    8787                              {TPDBDropTable,      844,  "dbDropTable",       0, false},
    8888                              {TPDBSelectColumn,   845,  "dbSelectColumn",    0, false},
    89                               {TPDBSelectColumnNum, -6,  "dbSelectColumnNum", 0, false},
     89                              {TPDBSelectColumnNum,846,  "dbSelectColumnNum", 0, false},
    9090                              {TPDBSelectRows,      -7,  "dbSelectRows",      0, false},
    9191                              {TPDBInsertOneRow,    -8,  "dbInsertOneRow",    0, false},
     
    651651    }
    652652
    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 
    660653    // Clean up table and memory
    661654    psDBDropTable(dbh, table);
     
    666659}
    667660
    668 // Testpoint #XXX, TPDBSelectColumnNum shall write/select a column from a test table ...
     661// Testpoint #846, TPDBSelectColumnNum shall write/select a column from a test table ...
    669662psS32 TPDBSelectColumnNum( void )
    670663{
     
    673666    const char* table = "table4";
    674667    psVector *vec = NULL;
     668
     669    // Create table definition metadata
    675670    psMetadata *row=NULL, *md = _get_CreateTableMetadata();
    676671
     672    // Initialize database connection
    677673    dbh = _init_psDB();
    678674    if (dbh == NULL) {
     675        psError(PS_ERR_UNKNOWN,true,"Did not expected NULL return to initialize database");
    679676        return 1;
    680677    }
    681678
    682     psLogMsg( __func__, PS_LOG_INFO, "psDBSelectColumnNum shall select data from a test table.\n" );
    683 
    684     failed = ! psDBCreateTable(dbh, table, md);
    685     if (!failed) {
    686 
    687         row = _get_const_row1();
    688         psDBInsertOneRow(dbh, table, row);
    689         psFree(row);
    690 
    691         row = _get_const_row2();
    692         psDBInsertOneRow(dbh, table, row);
    693         psFree(row);
    694 
    695         row = _get_row();
    696         psDBInsertOneRow(dbh, table, row);
    697         psFree(row);
    698 
    699         vec = psDBSelectColumnNum(dbh, table, "key_s32", PS_TYPE_S32, 0);
    700         if (vec == NULL) {
    701             failed = 1;
    702         } else {
    703             psLogMsg( __func__, PS_LOG_INFO, "str=[%d]\n", (vec->data.S32)[2] );
    704             psLogMsg( __func__, PS_LOG_INFO, "str=[%d]\n", (vec->data.S32)[1] );
    705             psLogMsg( __func__, PS_LOG_INFO, "str=[%d]\n", (vec->data.S32)[0] );
    706             if ((vec->data.S32)[0] != S32_1) {
    707                 psLogMsg( __func__, PS_LOG_INFO, "oops, did not find expected S32 output!\n" );
    708                 failed = 1;
    709             } else {
    710                 psLogMsg( __func__, PS_LOG_INFO, "found expected S32 output.\n" );
    711             }
    712             psFree(vec);
    713         }
    714 
    715         vec = psDBSelectColumnNum(dbh, table, "key_bool", PS_TYPE_BOOL, 0);
    716         if (vec == NULL) {
    717             failed = 1;
    718         } else {
    719             psLogMsg( __func__, PS_LOG_INFO, "bool=[%d]\n", (vec->data.U8)[2] );
    720             psLogMsg( __func__, PS_LOG_INFO, "bool=[%d]\n", (vec->data.U8)[1] );
    721             psLogMsg( __func__, PS_LOG_INFO, "bool=[%d]\n", (vec->data.U8)[0] );
    722             if ((vec->data.U8)[0] != B_1) {
    723                 psLogMsg( __func__, PS_LOG_INFO, "oops, did not find expected bool output!\n" );
    724                 failed = 1;
    725             } else {
    726                 psLogMsg( __func__, PS_LOG_INFO, "found expected bool output.\n" );
    727             }
    728             psFree(vec);
    729         }
    730 
    731         psDBDropTable(dbh, table);
    732     }
    733 
     679    // Create database table for test
     680    if(!psDBCreateTable(dbh, table, md)) {
     681        psError(PS_ERR_UNKNOWN,true,"Did not expect return false for create table");
     682        return 2;
     683    }
     684
     685    // Initialize database table with known rows
     686    row = _get_const_row1();
     687    psDBInsertOneRow(dbh, table, row);
     688    psFree(row);
     689
     690    row = _get_const_row2();
     691    psDBInsertOneRow(dbh, table, row);
     692    psFree(row);
     693
     694    row = _get_row();
     695    psDBInsertOneRow(dbh, table, row);
     696    psFree(row);
     697
     698    // Use valid arguments to select column with numeric values to return vector
     699    vec = psDBSelectColumnNum(dbh, table, "key_s32", PS_TYPE_S32, 0);
     700
     701    // Verify vector returned
     702    if (vec == NULL) {
     703        psError(PS_ERR_UNKNOWN,true,"Did not expect NULL return with valid arguments");
     704        psDBDropTable(dbh,table);
     705        psDBCleanup(dbh);
     706        return 3;
     707    }
     708    // Verify vector values
     709    if(vec->n != 3) {
     710        psError(PS_ERR_UNKNOWN,true,"Did not expect return vector size not equal to 3");
     711        psDBDropTable(dbh,table);
     712        psDBCleanup(dbh);
     713        return 30;
     714    }
     715    if(vec->type.type != PS_TYPE_S32) {
     716        psError(PS_ERR_UNKNOWN,true,"Did not expect return vector type not equal to PS_TYPE_S32");
     717        psDBDropTable(dbh,table);
     718        psDBCleanup(dbh);
     719        return 31;
     720    }
     721    if ((vec->data.S32)[0] != S32_1) {
     722        psError(PS_ERR_UNKNOWN,true,"vector value[%d] = %d not as expected %d",
     723                0,vec->data.S32[0], S32_1);
     724        psDBDropTable(dbh,table);
     725        psDBCleanup(dbh);
     726        return 4;
     727    }
     728    if ((vec->data.S32)[1] != CONST_ROW_2_S32) {
     729        psError(PS_ERR_UNKNOWN,true,"vector value[%d] = %d not as expected %d",
     730                1,vec->data.S32[1], CONST_ROW_2_S32);
     731        psDBDropTable(dbh,table);
     732        psDBCleanup(dbh);
     733        return 5;
     734    }
     735    if ((vec->data.S32)[2] != CONST_ROW_1_S32) {
     736        psError(PS_ERR_UNKNOWN,true,"vector value[%d] = %d not as expected %d",
     737                2,vec->data.S32[2], CONST_ROW_1_S32);
     738        psDBDropTable(dbh,table);
     739        psDBCleanup(dbh);
     740        return 6;
     741    }
     742    psFree(vec);
     743
     744    // Use valid arguments to select column with numeric values to return vector
     745    vec = psDBSelectColumnNum(dbh, table, "key_bool", PS_TYPE_BOOL, 0);
     746
     747    // Verify vector returned
     748    if (vec == NULL) {
     749        psError(PS_ERR_UNKNOWN,true,"Did not expect NULL return with valid arguments");
     750        psDBDropTable(dbh,table);
     751        psDBCleanup(dbh);
     752        return 7;
     753    }
     754    // Verify vector values
     755    if(vec->n != 3) {
     756        psError(PS_ERR_UNKNOWN,true,"Did not expect return vector size not equal to 3");
     757        psDBDropTable(dbh,table);
     758        psDBCleanup(dbh);
     759        return 8;
     760    }
     761    if(vec->type.type != PS_TYPE_BOOL) {
     762        psError(PS_ERR_UNKNOWN,true,"Did not expect return vector type not equal to PS_TYPE_BOOL");
     763        psDBDropTable(dbh,table);
     764        psDBCleanup(dbh);
     765        return 9;
     766    }
     767    if ((vec->data.U8)[0] != B_1) {
     768        psError(PS_ERR_UNKNOWN,true,"vector value[%d] = %d not as expected %d",
     769                0,vec->data.U8[0],B_1);
     770        psDBDropTable(dbh,table);
     771        psDBCleanup(dbh);
     772        return 10;
     773    }
     774    if ((vec->data.U8)[1] != CONST_ROW_2_BOOL) {
     775        psError(PS_ERR_UNKNOWN,true,"vector value[%d] = %d not as expected %d",
     776                0,vec->data.U8[0],CONST_ROW_2_BOOL);
     777        psDBDropTable(dbh,table);
     778        psDBCleanup(dbh);
     779        return 11;
     780    }
     781    if ((vec->data.U8)[2] != CONST_ROW_1_BOOL) {
     782        psError(PS_ERR_UNKNOWN,true,"vector value[%d] = %d not as expected %d",
     783                0,vec->data.U8[0],CONST_ROW_1_BOOL);
     784        psDBDropTable(dbh,table);
     785        psDBCleanup(dbh);
     786        return 12;
     787    }
     788    psFree(vec);
     789
     790    // Attempt to select columns from NULL database
     791    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error for NULL database object");
     792    if(psDBSelectColumnNum(NULL,table,"key_bool",PS_TYPE_BOOL,10) != NULL) {
     793        psError(PS_ERR_UNKNOWN,true,"Did not expect non-NULL return with NULL database object");
     794        psDBDropTable(dbh,table);
     795        psDBCleanup(dbh);
     796        return 13;
     797    }
     798
     799    // Attempt to select columns from NULL table
     800    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error for NULL table");
     801    if(psDBSelectColumnNum(dbh,NULL,"key_bool",PS_TYPE_BOOL,10) != NULL) {
     802        psError(PS_ERR_UNKNOWN,true,"Did not expect non-NULL return with NULL table");
     803        psDBDropTable(dbh,table);
     804        psDBCleanup(dbh);
     805        return 14;
     806    }
     807
     808    // Attempt to select columns from invalid column
     809    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error for invalid column");
     810    if(psDBSelectColumnNum(dbh,table,"key_999",PS_TYPE_BOOL,10) != NULL) {
     811        psError(PS_ERR_UNKNOWN,true,"Did not expect non-NULL return with NULL column");
     812        psDBDropTable(dbh,table);
     813        psDBCleanup(dbh);
     814        return 15;
     815    }
     816
     817    // Attempt to select columns from invalid column
     818    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error for invalid type");
     819    if(psDBSelectColumnNum(dbh,table,"key_string",0,10) != NULL) {
     820        psError(PS_ERR_UNKNOWN,true,"Did not expect non-NULL return with invalid type");
     821        psDBDropTable(dbh,table);
     822        psDBCleanup(dbh);
     823        return 16;
     824    }
     825
     826    psDBDropTable(dbh, table);
    734827    psFree(md);
    735828    psDBCleanup(dbh);
  • trunk/psLib/test/dataIO/verified/tst_psDB.stderr

    r4280 r4292  
    125125
    126126<DATE><TIME>|<HOST>|I|TPDBSelectColumnNum
    127     psDBSelectColumnNum shall select data from a test table.
     127    Following should generate an error for NULL database object
     128<DATE><TIME>|<HOST>|E|p_psDBRunQuery (FILE:LINENO)
     129    Invalid psDB has been specified.
     130<DATE><TIME>|<HOST>|E|psDBSelectColumn (FILE:LINENO)
     131    Failed to select column.
    128132<DATE><TIME>|<HOST>|I|TPDBSelectColumnNum
    129     str=[12345]
     133    Following should generate an error for NULL table
     134<DATE><TIME>|<HOST>|E|p_psDBRunQuery (FILE:LINENO)
     135    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
     136<DATE><TIME>|<HOST>|E|psDBSelectColumn (FILE:LINENO)
     137    Failed to select column.
    130138<DATE><TIME>|<HOST>|I|TPDBSelectColumnNum
    131     str=[2345]
     139    Following should generate an error for invalid column
     140<DATE><TIME>|<HOST>|E|p_psDBRunQuery (FILE:LINENO)
     141    Failed to execute SQL query.  Error: Unknown column 'key_999' in 'field list'
     142<DATE><TIME>|<HOST>|E|psDBSelectColumn (FILE:LINENO)
     143    Failed to select column.
    132144<DATE><TIME>|<HOST>|I|TPDBSelectColumnNum
    133     str=[1974]
    134 <DATE><TIME>|<HOST>|I|TPDBSelectColumnNum
    135     found expected S32 output.
    136 <DATE><TIME>|<HOST>|I|TPDBSelectColumnNum
    137     bool=[1]
    138 <DATE><TIME>|<HOST>|I|TPDBSelectColumnNum
    139     bool=[0]
    140 <DATE><TIME>|<HOST>|I|TPDBSelectColumnNum
    141     bool=[1]
    142 <DATE><TIME>|<HOST>|I|TPDBSelectColumnNum
    143     found expected bool output.
     145    Following should generate an error for invalid type
     146<DATE><TIME>|<HOST>|E|psVectorAlloc (FILE:LINENO)
     147    Input psVector is an unsupported type (0x0).
    144148
    145149---> TESTPOINT PASSED (psDB{dbSelectColumnNum} | tst_psDB.c)
Note: See TracChangeset for help on using the changeset viewer.