TestDataOutputDatabaseHandler.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/11/13 00:54:54 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/handler/TestDataOutputDatabaseHandler.cpp,v $
00024                                                                         
00025                                                                         
00026 // Written: fmk 11/04
00027 // Revised:
00028 //
00029 // Purpose: This file is a driver to test the DataOutputHandler concrete subclasses.
00030 
00031 #include <stdlib.h>
00032 
00033 #include <OPS_Globals.h>
00034 #include <Domain.h>
00035 #include <Vector.h>
00036 #include <FEM_ObjectBroker.h>
00037 #include <StandardStream.h>
00038 #include <FileDatastore.h>
00039 
00040 #include <DataOutputDatabaseHandler.h>
00041 
00042 // global variables
00043 
00044 StandardStream sserr;
00045 OPS_Stream &opserr = sserr;
00046 double   ops_Dt =0;                
00047 Domain  *ops_TheActiveDomain  =0;   
00048 Element *ops_TheActiveElement =0;  
00049 
00050 int main(int argc, char **argv)
00051 {
00052   //
00053   // local variables used in test
00054   //
00055   Domain theDomain;
00056   FEM_ObjectBroker theBroker;
00057 
00058   int numColumns = 5;
00059   char *columns[numColumns];
00060   char column1[] = "col1";
00061   char column2[] = "col2";
00062   char column3[] = "col3";
00063   char column4[] = "col4";
00064   char column5[] = "col5";
00065   columns[0] = column1;
00066   columns[1] = column2;
00067   columns[2] = column3;
00068   columns[3] = column4;
00069   columns[4] = column5;
00070   int result, result1, result2, result3, result4;
00071 
00072   Vector data1(numColumns);
00073   Vector data2(numColumns-1);
00074   for (int i=0; i<numColumns; i++)
00075     data1(i) = i+1;
00076   for (int i=0; i<numColumns-1; i++)
00077     data2(i) = i+1;
00078 
00079   FileDatastore theDatabase("testDatabase", theDomain, theBroker);
00080 
00081 
00082   opserr << " *******************************************************************\n";
00083   opserr << "                        DataOutputDatabaseHandler unit test\n";
00084   opserr << " *******************************************************************\n\n";
00085   opserr << " The DataOutputFile class provides implements 2 methods \n";
00086   opserr << "    open() - to open a connection to the o/p stream";
00087   opserr << "    write() - to send the contents of a vector to this stream\n\n";
00088   opserr << " *******************************************************************\n";
00089 
00090   //
00091   //  first test we can create DataOutputFile object to test.
00092   //
00093 
00094   opserr << "TEST: Creation of DataOutputFile object - will create 4 objects 1,2,3 and 4 (3,4 have no assigned database)\n";
00095   
00096   DataOutputDatabaseHandler *theHandler1  = new DataOutputDatabaseHandler(&theDatabase, "UnitTest1");
00097   DataOutputDatabaseHandler *theHandler2  = new DataOutputDatabaseHandler(&theDatabase, "UnitTest2");
00098   DataOutputDatabaseHandler *theHandler3  = new DataOutputDatabaseHandler(0, "UnitTest3");
00099   DataOutputDatabaseHandler *theHandler4  = new DataOutputDatabaseHandler(0, 0);
00100 
00101   if (theHandler1 != 0 && theHandler2 != 0 && theHandler3 != 0 && theHandler4 != 0) 
00102     opserr << "PASS: Creation of DataOutputDatabaseHandler object\n\n";    
00103   else {
00104     opserr << "FAIL: Creation of DataOutputDatabaseHandler object\n\n";
00105     exit(-1);
00106   }
00107 
00108   //
00109   // test open() method
00110   //
00111 
00112   opserr << "Now We Test open()\n\t 1. invoke open() on 1 and 2\n";
00113 
00114   opserr << "Invoking on handler 1\n";
00115   result1 = theHandler1->open(columns, numColumns);
00116   opserr << "Invoking on handler 2\n";
00117   result2 = theHandler2->open(columns, numColumns);
00118   
00119   if (result1 == 0 && result2 == 0) 
00120     opserr << "PASS: open() method  with VALID args\n\n";    
00121   else {
00122     opserr << "FAIL: open() method  with VALID args\n\n";    
00123   }
00124 
00125   //
00126   //  a number of tests to test open() method will fail if invalid args passed
00127   //     expected result: should fail, print out an error message and return != 0 for all following tests.
00128   //  
00129 
00130   opserr << "TEST: open() method with valid args but no database set\n";
00131   result = theHandler4->open(columns, numColumns-1);
00132   if (result != 0) 
00133     opserr << "PASS: open() method with valid args but no database set\n\n"; 
00134   else {
00135     opserr << "FAIL: open() method with valid args but no database set\n\n"; 
00136   }
00137 
00138   opserr << "TEST: open() method with bad column descriptions\n";
00139   result = theHandler1->open(0, 2);
00140   if (result != 0) 
00141     opserr << "PASS: open() method with bad column descriptors\n\n"; 
00142   else {
00143     opserr << "FAIL: open() method with bad column descriptors\n\n"; 
00144   }
00145 
00146   opserr << "TEST: open() method with negative number of columns\n";
00147   result = theHandler1->open(columns, -1);
00148   if (result != 0) 
00149     opserr << "PASS: open() method with negative columns\n\n"; 
00150   else {
00151     opserr << "FAIL: open() method with negative columns\n\n"; 
00152   }
00153 
00154   //
00155   // test setDatabase() 
00156   //
00157 
00158   opserr << "Now We Test setDatabase & open after setDatabase on handler 2\n";
00159   result = theHandler3->setDatabase(theDatabase, "UnitTest3");
00160   result += theHandler3->open(columns, numColumns-1);
00161   if (result == 0) 
00162     opserr << "PASS: setDatabase() then open()\n\n"; 
00163   else {
00164     opserr << "FAIL: setDatabase() then open()\n\n"; 
00165   }
00166 
00167   //
00168   //  test we can insert data into the file
00169   //     expected result: should return 0 and append line to <tableName>.out file
00170   //
00171 
00172 
00173   //
00174   // test: write()
00175   //
00176 
00177   opserr << "Now We Test write()\n\t 1. invoke write() 3 times with valid args on both handler1, handler2 and handler3\n";
00178   opserr << "\t 2. invoke write() with invalid args a number of times\n\n";
00179 
00180   //
00181   //  test we can insert data into the file
00182   //     expected result: should return 0 and append line to <tableName>.out file
00183   //
00184 
00185   result1 = 0; result2 = 0; result3 = 0;
00186   for (int i=0; i<3; i++) {
00187     result1 += theHandler1->write(data1);
00188     result1 += theHandler2->write(data1);
00189     result3 += theHandler3->write(data2);
00190     data1 += numColumns;
00191     data2 += numColumns-1;
00192   }
00193   
00194   // check the files exist and of correct size, UnitTest1.out should have 3 lines.
00195   if (result1 == 0 && result2 == 0 && result3 == 0) 
00196     opserr << "PASS: write() method  with VALID args\n\n";    
00197   else {
00198     opserr << "FAIL: write() method  with VALID args\n\n";    
00199   }
00200 
00201   //
00202   //  a number of tests to test the insert data will fail if data invalied
00203   //     expected result: all should return negative values & possible warning messages
00204   //
00205 
00206   opserr << "TEST: call write() method with incorrect vector size\n";
00207   result = theHandler3->write(data1);
00208 
00209   if (result != 0) 
00210     opserr << "PASS: write() method  with incorrect vector size\n\n";
00211   else {
00212     opserr << "FAIL: write() method  with incorrect vector size\n\n";
00213   }
00214 
00215   opserr << "TEST: call write() method on handler which has not been set\n";
00216   result = theHandler4->write(data1);
00217 
00218   if (result != 0) 
00219     opserr << "PASS: write() method to handler where open has not been called\n\n";
00220   else {
00221     opserr << "FAIL: write() method to handler where open has not been called\n\n";
00222   }
00223 
00224   //
00225   //  finally test we can destroy a DataOutputDatabaseHandler object.
00226   //
00227 
00228   opserr << "TEST: Destruction of DataOutputDatabaseHandler object\n";
00229   delete theHandler1;
00230   delete theHandler2;
00231   delete theHandler3;
00232   delete theHandler4;
00233 
00234   // if get to here without a segmentation fault destructor passes
00235   opserr << "PASS: Destruction of DataOutputDatabaseHandler object\n\n";    
00236   exit(0);
00237 }       
00238         

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