00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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
00038 #include <DataOutputFileHandler.h>
00039 #include <DataOutputStreamHandler.h>
00040
00041
00042 StandardStream sserr;
00043 OPS_Stream &opserr = sserr;
00044 double ops_Dt =0;
00045 Domain *ops_TheActiveDomain =0;
00046 Element *ops_TheActiveElement =0;
00047
00048 int main(int argc, char **argv)
00049 {
00050
00051
00052
00053 int numColumns = 5;
00054 char *columns[numColumns];
00055 char column1[] = "col1";
00056 char column2[] = "col2";
00057 char column3[] = "col3";
00058 char column4[] = "col4";
00059 char column5[] = "col5";
00060 columns[0] = column1;
00061 columns[1] = column2;
00062 columns[2] = column3;
00063 columns[3] = column4;
00064 columns[4] = column5;
00065 int result, result1, result2, result3, result4;
00066
00067 Vector data1(numColumns);
00068 Vector data2(numColumns-1);
00069 for (int i=0; i<numColumns; i++)
00070 data1(i) = i+1;
00071 for (int i=0; i<numColumns-1; i++)
00072 data2(i) = i+1;
00073
00074
00075
00076 opserr << " *******************************************************************\n";
00077 opserr << " DataOutputStreamHandler unit test\n";
00078 opserr << " *******************************************************************\n\n";
00079 opserr << " The DataOutputStream class provides implements 2 methods \n";
00080 opserr << " open() - to open a connection to the o/p stream";
00081 opserr << " write() - to send the contents of a vector to this stream\n\n";
00082 opserr << " *******************************************************************\n";
00083
00084
00085
00086
00087
00088 opserr << "TEST: Creation of DataOutputStream object - will create 3 objects 1,2, & 3\n";
00089
00090 DataOutputStreamHandler *theHandler1 = new DataOutputStreamHandler();
00091 DataOutputStreamHandler *theHandler2 = new DataOutputStreamHandler(true);
00092 DataOutputStreamHandler *theHandler3 = new DataOutputStreamHandler(false);
00093 DataOutputStreamHandler *theHandler4 = new DataOutputStreamHandler();
00094
00095 if (theHandler1 != 0 && theHandler2 != 0 && theHandler3 != 0)
00096 opserr << "PASS: Creation of DataOutputStreamHandler object\n\n";
00097 else {
00098 opserr << "FAIL: Creation of DataOutputStreamHandler object\n\n";
00099 exit(-1);
00100 }
00101
00102
00103
00104
00105
00106 opserr << "Now We Test open()\n\t 1. invoke open() on our 3 objects (only 2nd will print the headings)\n";
00107
00108 opserr << "Invonking on handler 1\n";
00109 result1 = theHandler1->open(columns, numColumns);
00110 opserr << "Invonking on handler 2\n";
00111 result2 = theHandler2->open(columns, numColumns);
00112 opserr << "Invonking on handler 3\n";
00113 result3 = theHandler3->open(columns, numColumns-1);
00114
00115 if (result1 == 0 && result2 == 0 && result3 == 0)
00116 opserr << "PASS: open() method with VALID args\n\n";
00117 else {
00118 opserr << "FAIL: open() method with VALID args\n\n";
00119 exit(-1);
00120 }
00121
00122
00123
00124
00125
00126
00127 opserr << "TEST: open() method with bad num columns\n";
00128 opserr << "TEST: open() method with negative number of columns\n";
00129 result = theHandler1->open(columns, -1);
00130 if (result != 0)
00131 opserr << "PASS: open() method with negative columns\n\n";
00132 else {
00133 opserr << "FAIL: open() method with negative columns\n\n";
00134 }
00135
00136
00137
00138
00139
00140 opserr << "Now We Test write()\n\t 1. invoke write() 3 times with valid args on both handler1, handler2 and handler3\n";
00141 opserr << "\t 2. invoke write() with invalid args a number of times\n\n";
00142
00143
00144
00145
00146
00147
00148
00149 for (int i=0; i<3; i++) {
00150 result1 += theHandler1->write(data1);
00151 result1 += theHandler2->write(data1);
00152 result3 += theHandler3->write(data2);
00153 data1 += numColumns;
00154 data2 += numColumns-1;
00155 }
00156
00157
00158 if (result1 == 0 && result2 == 0 && result3 == 0)
00159 opserr << "PASS: write() method with VALID args\n\n";
00160 else {
00161 opserr << "FAIL: write() method with VALID args\n\n";
00162 }
00163
00164
00165
00166
00167
00168
00169 opserr << "TEST: call write() method with incorrect vector size\n";
00170 result = theHandler3->write(data1);
00171
00172 if (result != 0)
00173 opserr << "PASS: write() method with incorrect vector size\n\n";
00174 else {
00175 opserr << "FAIL: write() method with incorrect vector size\n\n";
00176 }
00177
00178 opserr << "TEST: call write() method on handler which has not been set\n";
00179 result = theHandler4->write(data1);
00180
00181 if (result != 0)
00182 opserr << "PASS: write() method to handler where open has not been called\n\n";
00183 else {
00184 opserr << "FAIL: write() method to handler where open has not been called\n\n";
00185 }
00186
00187
00188
00189
00190
00191 opserr << "TEST: Destruction of DataOutputStreamHandler object\n";
00192 delete theHandler1;
00193 delete theHandler2;
00194 delete theHandler3;
00195 delete theHandler4;
00196
00197
00198 opserr << "PASS: Destruction of DataOutputStreamHandler object\n\n";
00199 exit(0);
00200 }
00201