Changeset 4280
- Timestamp:
- Jun 15, 2005, 3:49:23 PM (21 years ago)
- Location:
- trunk/psLib/test/dataIO
- Files:
-
- 2 edited
-
tst_psDB.c (modified) (12 diffs)
-
verified/tst_psDB.stderr (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/dataIO/tst_psDB.c
r4272 r4280 9 9 * @author Aaron Culliney, MHPCC 10 10 * 11 * @version $Revision: 1.1 6$ $Name: not supported by cvs2svn $12 * @date $Date: 2005-06-1 5 19:53:05$11 * @version $Revision: 1.17 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2005-06-16 01:49:23 $ 13 13 * 14 14 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 37 37 #define B_1 TRUE 38 38 #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 39 51 40 52 static psDB *_init_psDB( void ); … … 74 86 {TPDBCreateTable, 843, "dbCreateTable", 0, false}, 75 87 {TPDBDropTable, 844, "dbDropTable", 0, false}, 76 {TPDBSelectColumn, -5, "dbSelectColumn", 0, false},88 {TPDBSelectColumn, 845, "dbSelectColumn", 0, false}, 77 89 {TPDBSelectColumnNum, -6, "dbSelectColumnNum", 0, false}, 78 90 {TPDBSelectRows, -7, "dbSelectRows", 0, false}, … … 186 198 { 187 199 char buf[32]; 188 snprintf(buf, 32, "%s", "randrow1");200 snprintf(buf, 32, "%s", CONST_ROW_1_STR ); 189 201 return _get_RowMetadata( 190 202 "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, 199 207 NULL, NULL, 0.0); 200 208 } … … 203 211 { 204 212 char buf[32]; 205 snprintf(buf, 32, "%s", "randrow2");213 snprintf(buf, 32, "%s",CONST_ROW_2_STR); 206 214 return _get_RowMetadata( 207 215 "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, 216 220 NULL, NULL, 0.0); 217 221 } … … 408 412 psS32 TPDBDropTable( void ) 409 413 { 410 psS32 failed = 0;411 414 psDB *dbh = NULL; 412 415 const char* table = "table2"; … … 423 426 424 427 // Create table in database 425 failed = ! psDBCreateTable(dbh, table, md); 426 if (!failed) { 428 if(psDBCreateTable(dbh, table, md)) { 427 429 428 430 // 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 } 430 435 431 436 // insert should fail since the table has been drop from database … … 433 438 row = _get_row(); 434 439 if (psDBInsertOneRow(dbh, table, row)) { 435 ps LogMsg( __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; 437 442 } 438 443 psFree(row); 444 } else { 445 psError(PS_ERR_UNKNOWN,true,"Did not expect return false to create table"); 446 return 4; 439 447 } 440 448 … … 443 451 if(psDBDropTable(NULL,table)) { 444 452 psError(PS_ERR_UNKNOWN,true,"Did not return false as expected for NULL database object"); 445 return 2;453 return 5; 446 454 } 447 455 … … 450 458 if(psDBDropTable(dbh,"table99")) { 451 459 psError(PS_ERR_UNKNOWN,true,"Did not return false as expected for invalid table"); 452 return 3;460 return 6; 453 461 } 454 462 … … 457 465 if(psDBDropTable(dbh,NULL)) { 458 466 psError(PS_ERR_UNKNOWN,true,"Did not return false as expected for NULL table"); 459 return 4;467 return 7; 460 468 } 461 469 … … 463 471 psDBCleanup(dbh); 464 472 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 ... 469 477 psS32 TPDBSelectColumn( void ) 470 478 { 471 psS32 failed = 0;472 479 psDB *dbh = NULL; 473 480 const char* table = "table3"; 474 481 psArray *ary = NULL; 482 char *ptr=NULL; 483 484 // Create table definition metadata 475 485 psMetadata *row=NULL, *md = _get_CreateTableMetadata(); 476 char *ptr=NULL; 477 486 487 // Initialize database connection 478 488 dbh = _init_psDB(); 479 489 if (dbh == NULL) { 490 psError(PS_ERR_UNKNOWN,true,"Did not expect return NULL to initialize database connection"); 480 491 return 1; 481 492 } 482 493 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); 550 662 psFree(md); 551 663 psDBCleanup(dbh); 552 664 553 return failed;665 return 0; 554 666 } 555 667 -
trunk/psLib/test/dataIO/verified/tst_psDB.stderr
r4272 r4280 92 92 93 93 <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. 95 99 <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. 97 105 <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. 99 111 <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. 111 117 112 118 ---> TESTPOINT PASSED (psDB{dbSelectColumn} | tst_psDB.c)
Note:
See TracChangeset
for help on using the changeset viewer.
