NeesDataTest.cpp

Go to the documentation of this file.
00001 /* ****************************************************************** **
00002 **    OpenSees - Open System for Earthquake Engineering Simulation    **
00003 **          Pacific Earthquake Engineering Research Center            **
00004 **                                                                    **
00005 **                                                                    **
00006 ** (C) Copyright 1999, The Regents of the University of California    **
00007 ** All Rights Reserved.                                               **
00008 **                                                                    **
00009 ** Commercial use of this program without express permission of the   **
00010 ** University of California, Berkeley, is strictly prohibited.  See   **
00011 ** file 'COPYRIGHT'  in main directory for information on usage and   **
00012 ** redistribution,  and for a DISCLAIMER OF ALL WARRANTIES.           **
00013 **                                                                    **
00014 ** Developed by:                                                      **
00015 **   Frank McKenna (fmckenna@ce.berkeley.edu)                         **
00016 **   Gregory L. Fenves (fenves@ce.berkeley.edu)                       **
00017 **   Filip C. Filippou (filippou@ce.berkeley.edu)                     **
00018 **                                                                    **
00019 ** ****************************************************************** */
00020                                                                         
00021 // $Revision: 1.1 $
00022 // $Date: 2004/07/13 23:13:57 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/database/NeesDataTest.cpp,v $
00024                                                                         
00025                                                                         
00026 // Written: fmk 12/95
00027 // Revised:
00028 //
00029 // Purpose: This file is a driver to unitetest the NEESData class.
00030 
00031 #include <stdlib.h>
00032 
00033 #include <OPS_Globals.h>
00034 #include <NEESData.h>
00035 #include <Domain.h>
00036 #include <Vector.h>
00037 #include <FEM_ObjectBroker.h>
00038 #include <StandardStream.h>
00039 
00040 // global variables
00041 StandardStream sserr;
00042 OPS_Stream &opserr = sserr;
00043 double   ops_Dt =0;                
00044 Domain  *ops_TheActiveDomain  =0;   
00045 Element *ops_TheActiveElement =0;  
00046 
00047 int main(int argc, char **argv)
00048 {
00049   //
00050   // local variables used in test
00051   //
00052   int numColumns = 5;
00053   char *columns[numColumns];
00054   char column1[] = "col1";
00055   char column2[] = "col2";
00056   char column3[] = "col3";
00057   char column4[] = "col4";
00058   char column5[] = "col5";
00059   columns[0] = column1;
00060   columns[1] = column2;
00061   columns[2] = column3;
00062   columns[3] = column4;
00063   columns[4] = column5;
00064   int result, result1, result2;
00065 
00066   Vector data1(numColumns);
00067   Vector data2(numColumns-1);
00068   for (int i=0; i<numColumns; i++)
00069     data1(i) = i+1;
00070   for (int i=0; i<numColumns-1; i++)
00071     data2(i) = i+1;
00072 
00073 
00074 
00075   opserr << " *******************************************************************\n";
00076   opserr << "                        NEESData unit test\n";
00077   opserr << " *******************************************************************\n\n";
00078   opserr << " The NEESData class provides implements 2 methods \n";
00079   opserr << "    createTable() - to create a table, for NEESData this is 2 files,\n";
00080   opserr << "                    a <tableName>.out and a <tableName>.xml\n";
00081   opserr << "    insertData()  - to place data into the <tableName>.out file\n\n";
00082   opserr << " *******************************************************************\n";
00083 
00084   //
00085   //  first test we can create NEESData object to test.
00086   //
00087 
00088   opserr << "TEST: Creation of NEESData object\n";
00089   FEM_ObjectBroker theBroker;
00090   Domain *theDomain = new Domain();
00091   
00092   NEESData *theDatabase  = new NEESData("UnitTest",*theDomain,theBroker);
00093   if (theDatabase != 0) 
00094     opserr << "PASS: Creation of NEESData object\n\n";    
00095   else {
00096     opserr << "FAIL: Creation of NEESData object\n\n";
00097     exit(-1);
00098   }
00099 
00100 
00101   //
00102   // test createTable() method
00103   //
00104 
00105   opserr << "Now We Test createTable()\n\t 1. invoke createTable() twice to create tables UnitTest1 and UnitTest2\n";
00106   opserr << "\t 2. invoke createTable() with invalid args a number of times\n\n";
00107 
00108   //
00109   //  test we can create table; try it twice with different file names
00110   //     expected result: should return 0 and create 2 files for each createTable
00111   //
00112 
00113   opserr << "TEST: createTable() method  with VALID args (2 tables should be created, UnitTest1 and UnitTest2)\n";
00114   result1 = theDatabase->createTable("UnitTest1", numColumns, columns);
00115   result2 = theDatabase->createTable("UnitTest2", numColumns-1, columns);
00116   
00117   if (result1 == 0 && result2 == 0) 
00118     opserr << "PASS: createTable() method  with VALID args\n\n";    
00119   else {
00120     opserr << "FAIL: createTable() method  with VALID args\n\n";    
00121   }
00122 
00123   //
00124   //  a number of tests to test createTable() method will fail if invalid args passed
00125   //     expected result: should fail, print out an error message and return != 0 for all following tests.
00126   //  
00127 
00128   opserr << "TEST: createTable() method with bad fileName\n";
00129   result = theDatabase->createTable("/UnitTest", 3, columns);
00130   if (result != 0) 
00131     opserr << "PASS: createTable() method with bad fileName\n\n"; 
00132   else {
00133     opserr << "FAIL: createTable() method with bad fileName\n\n"; 
00134     opserr << " *** ARE YOU RUNNING THIS AS ROOOT -- YOU SHOULDN'T BE, su AND TRY AGAIN *** \n\n";    
00135   }
00136 
00137   opserr << "TEST: createTable() method with duplicate fileName\n";
00138   result = theDatabase->createTable("UnitTest1", 3, columns);
00139   if (result != 0) 
00140     opserr << "PASS: createTable() method with duplicate tableName\n\n"; 
00141   else {
00142     opserr << "FAIL: createTable() method with duplicate tableName\n\n"; 
00143   }
00144 
00145   opserr << "TEST: createTable() method with 0 columns\n";
00146   result = theDatabase->createTable("UnitTestFail", 0, columns);
00147   if (result != 0) 
00148     opserr << "PASS: createTable() method with 0 columns\n\n"; 
00149   else {
00150     opserr << "FAIL: createTable() method with 0 columns\n\n"; 
00151   }
00152 
00153 
00154   //
00155   // test insertData() method
00156   //
00157 
00158   opserr << "Now We Test insertData()\n\t 1. invoke insertData() 3 times with valid args on both UnitTest1 and UnitTest2\n";
00159   opserr << "\t 2. invoke insertData() with invalid args a number of times\n\n";
00160 
00161   //
00162   //  test we can insert data into the file
00163   //     expected result: should return 0 and append line to <tableName>.out file
00164   //
00165 
00166   opserr << "TEST: call insertData() method  with VALID args 3 times on both UNitTest1 and UnitTest2\n";
00167   for (int i=0; i<3; i++) {
00168     result1 = theDatabase->insertData("UnitTest1", columns, 1, data1);
00169     result2 = theDatabase->insertData("UnitTest2", columns, 1, data2);
00170     data1 += numColumns;
00171     data2 += numColumns-1;
00172   }
00173   
00174   // check the files exist and of correct size, UnitTest1.out should have 3 lines.
00175   if (result1 == 0 && result2 == 0) {
00176     
00177   }
00178   if (result1 == 0 && result2 == 0) 
00179     opserr << "PASS: insertData() method  with VALID args\n\n";    
00180   else {
00181     opserr << "FAIL: insertData() method  with VALID args\n\n";    
00182   }
00183 
00184   //
00185   //  a number of tests to test the insert data will fail if data invalied
00186   //     expected result: all should retuen != 0 and <tableName>.out should be unmodified
00187   //
00188 
00189   opserr << "TEST: call insertData() method with incorrect vector size\n";
00190   result = theDatabase->insertData("UnitTest2", columns, 1, data1);
00191 
00192   if (result != 0) 
00193     opserr << "PASS: insertData() method  with incorrect vector size\n\n";
00194   else {
00195     opserr << "FAIL: insertData() method  with incorrect vector size\n\n";
00196   }
00197 
00198   opserr << "TEST: call insertData() method to a table not yet created\n";
00199   result = theDatabase->insertData("UnitTest", columns, 1, data1);
00200 
00201   if (result != 0) 
00202     opserr << "PASS: insertData() method to a table not yet created\n\n";
00203   else {
00204     opserr << "FAIL: insertData() method to a table not yet created\n\n";
00205   }
00206 
00207   //
00208   //  finally test we can destroy a NEESData object.
00209   //
00210 
00211   opserr << "TEST: Destruction of NEESData object\n";
00212   delete theDatabase;
00213 
00214   // if get to here without a segmentation fault destructor passes
00215   opserr << "PASS: Destruction of NEESData object\n\n";    
00216   exit(0);
00217 }       
00218         

Generated on Mon Oct 23 15:05:00 2006 for OpenSees by doxygen 1.5.0