TestDataOutputFileHandler.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/TestDataOutputFileHandler.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 
00039 #include <DataOutputFileHandler.h>
00040 #include <DataOutputFileHandler.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   int numColumns = 5;
00056   char *columns[numColumns];
00057   char column1[] = "col1";
00058   char column2[] = "col2";
00059   char column3[] = "col3";
00060   char column4[] = "col4";
00061   char column5[] = "col5";
00062   columns[0] = column1;
00063   columns[1] = column2;
00064   columns[2] = column3;
00065   columns[3] = column4;
00066   columns[4] = column5;
00067   int result, result1, result2, result3, result4;
00068 
00069   Vector data1(numColumns);
00070   Vector data2(numColumns-1);
00071   for (int i=0; i<numColumns; i++)
00072     data1(i) = i+1;
00073   for (int i=0; i<numColumns-1; i++)
00074     data2(i) = i+1;
00075 
00076 
00077 
00078   opserr << " *******************************************************************\n";
00079   opserr << "                        DataOutputFileHandler unit test\n";
00080   opserr << " *******************************************************************\n\n";
00081   opserr << " The DataOutputFile class provides implements 2 methods \n";
00082   opserr << "    open() - to open a connection to the o/p stream";
00083   opserr << "    write() - to send the contents of a vector to this stream\n\n";
00084   opserr << " *******************************************************************\n";
00085 
00086   //
00087   //  first test we can create DataOutputFile object to test.
00088   //
00089 
00090   opserr << "TEST: Creation of DataOutputFile object - will create 3 objects 1,2, & 3\n";
00091   
00092   DataOutputFileHandler *theHandler1  = new DataOutputFileHandler("UnitTest1");
00093   DataOutputFileHandler *theHandler2  = new DataOutputFileHandler("UnitTest2", DATA_FILE);
00094   DataOutputFileHandler *theHandler3  = new DataOutputFileHandler("UnitTest3", XML_FILE, APPEND);
00095   DataOutputFileHandler *theHandler4  = new DataOutputFileHandler(0);
00096 
00097   if (theHandler1 != 0 && theHandler2 != 0 && theHandler3 != 0 && theHandler4 != 0) 
00098     opserr << "PASS: Creation of DataOutputFileHandler object\n\n";    
00099   else {
00100     opserr << "FAIL: Creation of DataOutputFileHandler object\n\n";
00101     exit(-1);
00102   }
00103 
00104   //
00105   // test open() method
00106   //
00107 
00108   opserr << "Now We Test open()\n\t 1. invoke open() on our 3 objects (only 2nd will print the headings)\n";
00109 
00110   opserr << "Invoking on handler 1\n";
00111   result1 = theHandler1->open(columns, numColumns);
00112   opserr << "Invoking on handler 2\n";
00113   result2 = theHandler2->open(columns, numColumns);
00114   opserr << "Invoking on handler 3\n";
00115   result3 = theHandler3->open(columns, numColumns-1);
00116   
00117   if (result1 == 0 && result2 == 0 && result3 == 0) 
00118     opserr << "PASS: open() method  with VALID args\n\n";    
00119   else {
00120     opserr << "FAIL: open() method  with VALID args\n\n";    
00121   }
00122 
00123   //
00124   //  a number of tests to test open() 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: open() method with bad column descriptions\n";
00129   result = theHandler1->open(0, 2);
00130   if (result != 0) 
00131     opserr << "PASS: open() method with bad column descriptors\n\n"; 
00132   else {
00133     opserr << "FAIL: open() method with bad column descriptors\n\n"; 
00134   }
00135 
00136   opserr << "TEST: open() method with negative number of columns\n";
00137   result = theHandler1->open(columns, -1);
00138   if (result != 0) 
00139     opserr << "PASS: open() method with negative columns\n\n"; 
00140   else {
00141     opserr << "FAIL: open() method with negative columns\n\n"; 
00142   }
00143 
00144 
00145   //
00146   // test write() method
00147   //
00148 
00149   opserr << "Now We Test write()\n\t 1. invoke write() 3 times with valid args on both handler1, handler2 and handler3\n";
00150   opserr << "\t 2. invoke write() with invalid args a number of times\n\n";
00151 
00152   //
00153   //  test we can insert data into the file
00154   //     expected result: should return 0 and append line to <tableName>.out file
00155   //
00156 
00157 
00158   for (int i=0; i<3; i++) {
00159     result1 += theHandler1->write(data1);
00160     result1 += theHandler2->write(data1);
00161     result3 += theHandler3->write(data2);
00162     data1 += numColumns;
00163     data2 += numColumns-1;
00164   }
00165   
00166   // check the files exist and of correct size, UnitTest1.out should have 3 lines.
00167   if (result1 == 0 && result2 == 0 && result3 == 0) 
00168     opserr << "PASS: write() method  with VALID args\n\n";    
00169   else {
00170     opserr << "FAIL: write() method  with VALID args\n\n";    
00171   }
00172 
00173   //
00174   //  a number of tests to test the insert data will fail if data invalied
00175   //     expected result: all should return negative values & possible warning messages
00176   //
00177 
00178   opserr << "TEST: call write() method with incorrect vector size\n";
00179   result = theHandler3->write(data1);
00180 
00181   if (result != 0) 
00182     opserr << "PASS: write() method  with incorrect vector size\n\n";
00183   else {
00184     opserr << "FAIL: write() method  with incorrect vector size\n\n";
00185   }
00186 
00187 
00188   opserr << "TEST: call write() method on handler which has not been set\n";
00189   result = theHandler4->write(data1);
00190 
00191   if (result != 0) 
00192     opserr << "PASS: write() method to handler where open has not been called\n\n";
00193   else {
00194     opserr << "FAIL: write() method to handler where open has not been called\n\n";
00195   }
00196 
00197   //
00198   //  finally test we can destroy a DataOutputFileHandler object.
00199   //
00200 
00201   opserr << "TEST: Destruction of DataOutputFileHandler object\n";
00202   delete theHandler1;
00203   delete theHandler2;
00204   delete theHandler3;
00205   delete theHandler4;
00206 
00207   // if get to here without a segmentation fault destructor passes
00208   opserr << "PASS: Destruction of DataOutputFileHandler object\n\n";    
00209   exit(0);
00210 }       
00211         

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