00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <spl/Debug.h>
00018 #include <spl/Log.h>
00019 #include <spl/data/RecordSet.h>
00020
00021 #ifdef DEBUG
00022
00023 static void _TestRecordSet1()
00024 {
00025 RecordSet *rs = new RecordSet();
00026 rs->ValidateMem();
00027
00028 DEBUG_CLEAR_MEM_CHECK_POINTS();
00029 DEBUG_NOTE_MEM( rs );
00030 rs->CheckMem();
00031 DEBUG_DUMP_MEM_LEAKS();
00032 UNIT_ASSERT_MEM_NOTED("RecordSet 1.1");
00033
00034 delete rs;
00035 DEBUG_CLEAR_MEM_CHECK_POINTS();
00036 DEBUG_DUMP_MEM_LEAKS();
00037 UNIT_ASSERT_MEM_NOTED("RecordSet 1.2");
00038
00039 Log::SWriteOkFail( "RecordSet 1" );
00040 }
00041
00042 static void _TestRecordSet2()
00043 {
00044 RecordSet *rs = new RecordSet();
00045 rs->ValidateMem();
00046
00047 rs->DefineColumn("c1", DbSqlType::SQL_TYPE_INT32, 4);
00048 rs->ValidateMem();
00049
00050 DEBUG_CLEAR_MEM_CHECK_POINTS();
00051 DEBUG_NOTE_MEM( rs );
00052 rs->CheckMem();
00053 DEBUG_DUMP_MEM_LEAKS();
00054 UNIT_ASSERT_MEM_NOTED("RecordSet 2.1");
00055
00056 delete rs;
00057 DEBUG_CLEAR_MEM_CHECK_POINTS();
00058 DEBUG_DUMP_MEM_LEAKS();
00059 UNIT_ASSERT_MEM_NOTED("RecordSet 2.2");
00060
00061 rs = new RecordSet();
00062 rs->DefineColumn("c1", DbSqlType::SQL_TYPE_DATETIME, 8);
00063 rs->ValidateMem();
00064
00065 DEBUG_CLEAR_MEM_CHECK_POINTS();
00066 DEBUG_NOTE_MEM( rs );
00067 rs->CheckMem();
00068 DEBUG_DUMP_MEM_LEAKS();
00069 UNIT_ASSERT_MEM_NOTED("RecordSet 2.4");
00070
00071 delete rs;
00072 DEBUG_CLEAR_MEM_CHECK_POINTS();
00073 DEBUG_DUMP_MEM_LEAKS();
00074 UNIT_ASSERT_MEM_NOTED("RecordSet 2.5");
00075
00076 Log::SWriteOkFail( "RecordSet 2" );
00077 }
00078
00079 static void _TestRecordSet2a()
00080 {
00081 RecordSet *rs = new RecordSet();
00082 rs->DefineColumn("c1", DbSqlType::SQL_TYPE_INT32, 4);
00083 rs->DefineColumn("c2", DbSqlType::SQL_TYPE_VARCHAR, 32);
00084 rs->ValidateMem();
00085
00086 DEBUG_CLEAR_MEM_CHECK_POINTS();
00087 DEBUG_NOTE_MEM( rs );
00088 rs->CheckMem();
00089 DEBUG_DUMP_MEM_LEAKS();
00090 UNIT_ASSERT_MEM_NOTED("RecordSet 2.1");
00091
00092 delete rs;
00093 DEBUG_CLEAR_MEM_CHECK_POINTS();
00094 DEBUG_DUMP_MEM_LEAKS();
00095 UNIT_ASSERT_MEM_NOTED("RecordSet 2.2");
00096
00097 Log::SWriteOkFail( "RecordSet 2" );
00098 }
00099
00100 static void _TestRecordSet3()
00101 {
00102 RecordSet *rs = new RecordSet();
00103 rs->DefineColumn("c1", DbSqlType::SQL_TYPE_INT32, 4);
00104 rs->DefineColumn("c2", DbSqlType::SQL_TYPE_VARCHAR, 32);
00105 rs->ValidateMem();
00106
00107 DEBUG_CLEAR_MEM_CHECK_POINTS();
00108 DEBUG_NOTE_MEM( rs );
00109 rs->CheckMem();
00110 DEBUG_DUMP_MEM_LEAKS();
00111 UNIT_ASSERT_MEM_NOTED("RecordSet 3.1");
00112
00113 rs->GetColumn("c1")->Append( (int32)42 );
00114 rs->GetColumn("c2")->Append( String("row 1") );
00115 rs->ValidateMem();
00116
00117 DEBUG_CLEAR_MEM_CHECK_POINTS();
00118 DEBUG_NOTE_MEM( rs );
00119 rs->CheckMem();
00120 DEBUG_DUMP_MEM_LEAKS();
00121 UNIT_ASSERT_MEM_NOTED("RecordSet 3.2");
00122
00123 rs->BeginIter();
00124 UNIT_ASSERT( "Should be a record", rs->Next() );
00125 UNIT_ASSERT( "in32 column data", rs->GetColumn("c1")->GetInt32() == 42 );
00126 UNIT_ASSERT( "varchar column data", rs->GetColumn("c2")->GetVarchar()->Equals("row 1") );
00127 UNIT_ASSERT( "Should not be another record", !rs->Next() );
00128 rs->ValidateMem();
00129
00130 DEBUG_CLEAR_MEM_CHECK_POINTS();
00131 DEBUG_NOTE_MEM( rs );
00132 rs->CheckMem();
00133 DEBUG_DUMP_MEM_LEAKS();
00134 UNIT_ASSERT_MEM_NOTED("RecordSet 3.3");
00135
00136 delete rs;
00137 DEBUG_CLEAR_MEM_CHECK_POINTS();
00138 DEBUG_DUMP_MEM_LEAKS();
00139 UNIT_ASSERT_MEM_NOTED("RecordSet 3.4");
00140
00141 Log::SWriteOkFail( "RecordSet 3" );
00142 }
00143
00144 static void _TestRecordSet4()
00145 {
00146 DateTime dtm1(1995, 7, 1);
00147 DateTime dtm2(1984, 9, 11);
00148
00149 RecordSet *rs = new RecordSet();
00150 rs->DefineColumn("c1", DbSqlType::SQL_TYPE_INT8, 1);
00151 rs->DefineColumn("c2", DbSqlType::SQL_TYPE_INT16, 2);
00152 rs->DefineColumn("c3", DbSqlType::SQL_TYPE_INT32, 4);
00153 rs->DefineColumn("c4", DbSqlType::SQL_TYPE_INT64, 8);
00154
00155 rs->DefineColumn("c6", DbSqlType::SQL_TYPE_FLOAT32, 4);
00156 rs->DefineColumn("c7", DbSqlType::SQL_TYPE_FLOAT64, 8);
00157 rs->DefineColumn("c8", DbSqlType::SQL_TYPE_FLAG, 4);
00158 rs->DefineColumn("c9", DbSqlType::SQL_TYPE_TIMESTAMP, 8);
00159 rs->ValidateMem();
00160
00161 rs->DefineColumn("c11", DbSqlType::SQL_TYPE_DATETIME, 8);
00162 rs->DefineColumn("c12", DbSqlType::SQL_TYPE_CHAR, 22);
00163 rs->DefineColumn("c13", DbSqlType::SQL_TYPE_VARCHAR, 22);
00164
00165
00166 rs->ValidateMem();
00167
00168 DEBUG_CLEAR_MEM_CHECK_POINTS();
00169 DEBUG_NOTE_MEM( rs );
00170 rs->CheckMem();
00171 DEBUG_DUMP_MEM_LEAKS();
00172 UNIT_ASSERT_MEM_NOTED("RecordSet 4.1");
00173
00174 rs->GetColumn("c1")->Append( (int8)1 );
00175 rs->GetColumn("c2")->Append( (int16)2 );
00176 rs->GetColumn("c3")->Append( (int32)3 );
00177 rs->GetColumn("c4")->Append( (int64)4 );
00178 rs->GetColumn("c6")->Append( (float32)5 );
00179 rs->GetColumn("c7")->Append( (float64)6 );
00180 rs->GetColumn("c8")->Append( true );
00181 rs->GetColumn("c9")->Append( dtm1 );
00182 rs->GetColumn("c11")->Append( dtm1 );
00183 rs->GetColumn("c12")->Append( String("char") );
00184 rs->GetColumn("c13")->Append( String("varchar") );
00185
00186 rs->GetColumn("c1")->Append( (int8)7 );
00187 rs->GetColumn("c2")->Append( (int16)8 );
00188 rs->GetColumn("c3")->Append( (int32)9 );
00189 rs->GetColumn("c4")->Append( (int64)10 );
00190 rs->GetColumn("c6")->Append( (float32)11 );
00191 rs->GetColumn("c7")->Append( (float64)12 );
00192 rs->GetColumn("c8")->Append( false );
00193 rs->GetColumn("c9")->Append( dtm2 );
00194 rs->GetColumn("c11")->Append( dtm2 );
00195 rs->GetColumn("c12")->Append( String("char2") );
00196 rs->GetColumn("c13")->Append( String("varchar2") );
00197
00198 rs->ValidateMem();
00199
00200 DEBUG_CLEAR_MEM_CHECK_POINTS();
00201 DEBUG_NOTE_MEM( rs );
00202 rs->CheckMem();
00203 DEBUG_DUMP_MEM_LEAKS();
00204 UNIT_ASSERT_MEM_NOTED("RecordSet 4.2");
00205
00206 rs->BeginIter();
00207 UNIT_ASSERT( "Should be a record", rs->Next() );
00208 UNIT_ASSERT( "byte", rs->GetColumn("c1")->GetByte() == 1 );
00209 UNIT_ASSERT( "int16", rs->GetColumn("c2")->GetInt16() == 2 );
00210 UNIT_ASSERT( "int32", rs->GetColumn("c3")->GetInt32() == 3 );
00211 UNIT_ASSERT( "int64", rs->GetColumn("c4")->GetInt64() == 4 );
00212 UNIT_ASSERT( "float32", rs->GetColumn("c6")->GetFloat32() == 5 );
00213 UNIT_ASSERT( "float64", rs->GetColumn("c7")->GetFloat64() == 6 );
00214 UNIT_ASSERT( "bool", rs->GetColumn("c8")->GetBit() == true );
00215 UNIT_ASSERT( "timestamp", rs->GetColumn("c9")->GetDateTime().Equals(dtm1) );
00216 UNIT_ASSERT( "datetime", rs->GetColumn("c11")->GetDateTime().Equals(dtm1) );
00217 UNIT_ASSERT( "char", rs->GetColumn("c12")->GetChar()->Equals( "char" ) );
00218 UNIT_ASSERT( "varchar", rs->GetColumn("c13")->GetChar()->Equals( "varchar" ) );
00219
00220 DEBUG_CLEAR_MEM_CHECK_POINTS();
00221 DEBUG_NOTE_MEM( rs );
00222 rs->CheckMem();
00223 DEBUG_DUMP_MEM_LEAKS();
00224 UNIT_ASSERT_MEM_NOTED("RecordSet 4.3");
00225
00226 UNIT_ASSERT( "Should be a record", rs->Next() );
00227 UNIT_ASSERT( "byte", rs->GetColumn("c1")->GetByte() == 7 );
00228 UNIT_ASSERT( "int16", rs->GetColumn("c2")->GetInt16() == 8 );
00229 UNIT_ASSERT( "int32", rs->GetColumn("c3")->GetInt32() == 9 );
00230 UNIT_ASSERT( "int64", rs->GetColumn("c4")->GetInt64() == 10 );
00231 UNIT_ASSERT( "float32", rs->GetColumn("c6")->GetFloat32() == 11 );
00232 UNIT_ASSERT( "float64", rs->GetColumn("c7")->GetFloat64() == 12 );
00233 UNIT_ASSERT( "bool", rs->GetColumn("c8")->GetBit() == false );
00234 UNIT_ASSERT( "timestamp", rs->GetColumn("c9")->GetDateTime().Equals(dtm2) );
00235 UNIT_ASSERT( "datetime", rs->GetColumn("c11")->GetDateTime().Equals(dtm2) );
00236 UNIT_ASSERT( "char", rs->GetColumn("c12")->GetChar()->Equals( "char2" ) );
00237 UNIT_ASSERT( "varchar", rs->GetColumn("c13")->GetChar()->Equals( "varchar2" ) );
00238
00239 UNIT_ASSERT( "Should not be another record", !rs->Next() );
00240 rs->ValidateMem();
00241
00242 DEBUG_CLEAR_MEM_CHECK_POINTS();
00243 DEBUG_NOTE_MEM( rs );
00244 rs->CheckMem();
00245 DEBUG_DUMP_MEM_LEAKS();
00246 UNIT_ASSERT_MEM_NOTED("RecordSet 4.4");
00247
00248 delete rs;
00249 DEBUG_CLEAR_MEM_CHECK_POINTS();
00250 DEBUG_DUMP_MEM_LEAKS();
00251 UNIT_ASSERT_MEM_NOTED("RecordSet 4.5");
00252
00253 Log::SWriteOkFail( "RecordSet 4" );
00254 }
00255
00256 void TestRecordSet()
00257 {
00258 _TestRecordSet1();
00259 DEBUG_CLEAR_MEM_CHECK_POINTS();
00260 DEBUG_DUMP_MEM_LEAKS();
00261
00262 _TestRecordSet2();
00263 DEBUG_CLEAR_MEM_CHECK_POINTS();
00264 DEBUG_DUMP_MEM_LEAKS();
00265
00266 _TestRecordSet2a();
00267 DEBUG_CLEAR_MEM_CHECK_POINTS();
00268 DEBUG_DUMP_MEM_LEAKS();
00269
00270 _TestRecordSet3();
00271 DEBUG_CLEAR_MEM_CHECK_POINTS();
00272 DEBUG_DUMP_MEM_LEAKS();
00273
00274 _TestRecordSet4();
00275 DEBUG_CLEAR_MEM_CHECK_POINTS();
00276 DEBUG_DUMP_MEM_LEAKS();
00277 }
00278
00279 #endif