Changeset 4292 for trunk/psLib/test/dataIO/tst_psDB.c
- Timestamp:
- Jun 16, 2005, 1:35:07 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/dataIO/tst_psDB.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/dataIO/tst_psDB.c
r4280 r4292 9 9 * @author Aaron Culliney, MHPCC 10 10 * 11 * @version $Revision: 1.1 7$ $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 $ 13 13 * 14 14 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 87 87 {TPDBDropTable, 844, "dbDropTable", 0, false}, 88 88 {TPDBSelectColumn, 845, "dbSelectColumn", 0, false}, 89 {TPDBSelectColumnNum, -6, "dbSelectColumnNum", 0, false},89 {TPDBSelectColumnNum,846, "dbSelectColumnNum", 0, false}, 90 90 {TPDBSelectRows, -7, "dbSelectRows", 0, false}, 91 91 {TPDBInsertOneRow, -8, "dbInsertOneRow", 0, false}, … … 651 651 } 652 652 653 // Attempt to select NULL column from valid database object and valid table654 // 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 653 // Clean up table and memory 661 654 psDBDropTable(dbh, table); … … 666 659 } 667 660 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 ... 669 662 psS32 TPDBSelectColumnNum( void ) 670 663 { … … 673 666 const char* table = "table4"; 674 667 psVector *vec = NULL; 668 669 // Create table definition metadata 675 670 psMetadata *row=NULL, *md = _get_CreateTableMetadata(); 676 671 672 // Initialize database connection 677 673 dbh = _init_psDB(); 678 674 if (dbh == NULL) { 675 psError(PS_ERR_UNKNOWN,true,"Did not expected NULL return to initialize database"); 679 676 return 1; 680 677 } 681 678 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); 734 827 psFree(md); 735 828 psDBCleanup(dbh);
Note:
See TracChangeset
for help on using the changeset viewer.
