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 <NEESData.h>
00035 #include <Domain.h>
00036 #include <Vector.h>
00037 #include <FEM_ObjectBroker.h>
00038 #include <StandardStream.h>
00039
00040
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
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
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
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
00110
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
00125
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
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
00163
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
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
00186
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
00209
00210
00211 opserr << "TEST: Destruction of NEESData object\n";
00212 delete theDatabase;
00213
00214
00215 opserr << "PASS: Destruction of NEESData object\n\n";
00216 exit(0);
00217 }
00218