Changeset 4317
- Timestamp:
- Jun 17, 2005, 5:22:43 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/dataIO/tst_psDB.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/dataIO/tst_psDB.c
r4310 r4317 9 9 * @author Aaron Culliney, MHPCC 10 10 * 11 * @version $Revision: 1.2 2$ $Name: not supported by cvs2svn $12 * @date $Date: 2005-06-18 0 0:52:17$11 * @version $Revision: 1.23 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2005-06-18 03:22:43 $ 13 13 * 14 14 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 37 37 #define B_1 TRUE 38 38 #define B_2 FALSE 39 40 #define ERROR_TOL 0.001 39 41 40 42 #define CONST_ROW_1_STR "randrow1" … … 65 67 static psMetadata *_get_update_values(const char *val0, psS32 val1, psF32 val2, psF64 val3, psBool val4); 66 68 static void _print_row( psMetadata *row ); 69 static bool _check_row(psMetadata* row); 70 static bool _check_const_row1(psMetadata* row); 71 static bool _check_const_row2(psMetadata* row); 67 72 68 73 //static psS32 TPDBCreate( void ); … … 92 97 {TPDBInsertOneRow, 848, "dbInsertOneRow", 0, false}, 93 98 {TPDBInsertRows, 849, "dbInsertRows", 0, false}, 94 {TPDBDumpRows, -10,"dbDumpRows", 0, false},99 {TPDBDumpRows, 850, "dbDumpRows", 0, false}, 95 100 {TPDBDumpCols, -11, "dbDumpCols", 0, false}, 96 101 {TPDBUpdateRows, -12, "dbUpdateRows", 0, false}, … … 271 276 { 272 277 return _get_RowMetadataValues(val0, val1, val2, val3, val4); 278 } 279 280 bool _check_row(psMetadata* row) 281 { 282 bool returnValue = true; 283 psMetadataItem* item = NULL; 284 285 item = psMetadataLookup(row,"key_string"); 286 if((item==NULL) || (strcmp(item->data.V,STR_1)!=0)) { 287 psError(PS_ERR_UNKNOWN,true,"Column key_string item %s not as expected %s", 288 item->data.V,STR_1); 289 return false; 290 } 291 292 item = psMetadataLookup(row,"key_s32"); 293 if((item==NULL) || (item->data.S32 != S32_1)) { 294 psError(PS_ERR_UNKNOWN,true,"Column key_s32 item %d not as expected %d", 295 item->data.S32, S32_1); 296 return false; 297 } 298 299 item = psMetadataLookup(row,"key_f32"); 300 if((item==NULL) || (fabs(item->data.F32-F32_1)>ERROR_TOL)) { 301 psError(PS_ERR_UNKNOWN,true,"Column key_f32 item %f not as expected %f", 302 item->data.F32, F32_1); 303 return false; 304 } 305 306 item = psMetadataLookup(row,"key_f64"); 307 if((item==NULL) || (fabs(item->data.F64-F64_1)>ERROR_TOL)) { 308 psError(PS_ERR_UNKNOWN,true,"Column key_f64 item %lf not as expected %lf", 309 item->data.F64,F64_1); 310 return false; 311 } 312 313 item = psMetadataLookup(row,"key_bool"); 314 if((item==NULL) || (item->data.B != B_1)) { 315 psError(PS_ERR_UNKNOWN,true,"Column key_bool item %d not as expected %d", 316 item->data.B, B_1); 317 return false; 318 } 319 320 return returnValue; 321 } 322 323 bool _check_const_row1(psMetadata* row) 324 { 325 bool returnValue = true; 326 psMetadataItem* item = NULL; 327 328 item = psMetadataLookup(row,"key_string"); 329 if((item==NULL) || (strcmp(item->data.V,CONST_ROW_1_STR)!=0)) { 330 psError(PS_ERR_UNKNOWN,true,"Column key_string item %s not as expected %s", 331 item->data.V,CONST_ROW_1_STR); 332 return false; 333 } 334 335 item = psMetadataLookup(row,"key_s32"); 336 if((item==NULL) || (item->data.S32 != CONST_ROW_1_S32)) { 337 psError(PS_ERR_UNKNOWN,true,"Column key_s32 item %d not as expected %d", 338 item->data.S32, CONST_ROW_1_S32); 339 return false; 340 } 341 342 item = psMetadataLookup(row,"key_f32"); 343 if((item==NULL) || (fabs(item->data.F32-CONST_ROW_1_F32)>ERROR_TOL)) { 344 psError(PS_ERR_UNKNOWN,true,"Column key_f32 item %f not as expected %f", 345 item->data.F32, CONST_ROW_1_F32); 346 return false; 347 } 348 349 item = psMetadataLookup(row,"key_f64"); 350 if((item==NULL) || (fabs(item->data.F64-CONST_ROW_1_F64)>ERROR_TOL)) { 351 psError(PS_ERR_UNKNOWN,true,"Column key_f64 item %lf not as expected %lf", 352 item->data.F64,CONST_ROW_1_F64); 353 return false; 354 } 355 356 item = psMetadataLookup(row,"key_bool"); 357 if((item==NULL) || (item->data.B != CONST_ROW_1_BOOL)) { 358 psError(PS_ERR_UNKNOWN,true,"Column key_bool item %d not as expected %d", 359 item->data.B, CONST_ROW_1_BOOL); 360 return false; 361 } 362 363 return returnValue; 364 } 365 366 bool _check_const_row2(psMetadata* row) 367 { 368 bool returnValue = true; 369 psMetadataItem* item = NULL; 370 371 item = psMetadataLookup(row,"key_string"); 372 if((item==NULL) || (strcmp(item->data.V,CONST_ROW_2_STR)!=0)) { 373 psError(PS_ERR_UNKNOWN,true,"Column key_string item %s not as expected %s", 374 item->data.V,CONST_ROW_2_STR); 375 return false; 376 } 377 378 item = psMetadataLookup(row,"key_s32"); 379 if((item==NULL) || (item->data.S32 != CONST_ROW_2_S32)) { 380 psError(PS_ERR_UNKNOWN,true,"Column key_s32 item %d not as expected %d", 381 item->data.S32, CONST_ROW_2_S32); 382 return false; 383 } 384 385 item = psMetadataLookup(row,"key_f32"); 386 if((item==NULL) || (fabs(item->data.F32-CONST_ROW_2_F32)>ERROR_TOL)) { 387 psError(PS_ERR_UNKNOWN,true,"Column key_f32 item %f not as expected %f", 388 item->data.F32, CONST_ROW_2_F32); 389 return false; 390 } 391 392 item = psMetadataLookup(row,"key_f64"); 393 if((item==NULL) || (fabs(item->data.F64-CONST_ROW_2_F64)>ERROR_TOL)) { 394 psError(PS_ERR_UNKNOWN,true,"Column key_f64 item %lf not as expected %lf", 395 item->data.F64,CONST_ROW_2_F64); 396 return false; 397 } 398 399 item = psMetadataLookup(row,"key_bool"); 400 if((item==NULL) || (item->data.B != CONST_ROW_2_BOOL)) { 401 psError(PS_ERR_UNKNOWN,true,"Column key_bool item %d not as expected %d", 402 item->data.B, CONST_ROW_2_BOOL); 403 return false; 404 } 405 406 return returnValue; 273 407 } 274 408 … … 1237 1371 } 1238 1372 1239 // Testpoint # XXX, TPDBDumpRows shall dump all rows from a test table ...1373 // Testpoint #850, TPDBDumpRows shall dump all rows from a test table ... 1240 1374 psS32 TPDBDumpRows( void ) 1241 1375 { 1242 psS32 failed = 0;1243 1376 psDB *dbh = NULL; 1244 1377 const char* table = "table8"; 1245 1378 psArray *ary = NULL; 1379 1380 // Create table definition metadata 1246 1381 psMetadata *row=NULL, *md = _get_CreateTableMetadata(); 1247 psMetadataItem *item=NULL; 1248 1382 1383 // Initialize database connection 1249 1384 dbh = _init_psDB(); 1250 1385 if (dbh == NULL) { 1386 psError(PS_ERR_UNKNOWN,true,"Did not expect return NULL from initializing database"); 1251 1387 return 1; 1252 1388 } 1253 1389 1254 psLogMsg( __func__, PS_LOG_INFO, "psDBDumpRows shall dump all rows from a test table.\n" ); 1255 1256 failed = ! psDBCreateTable(dbh, table, md); 1257 if (!failed) { 1258 1259 row = _get_const_row1(); 1260 psDBInsertOneRow(dbh, table, row); 1261 psFree(row); 1262 1263 row = _get_const_row2(); 1264 psDBInsertOneRow(dbh, table, row); 1265 psFree(row); 1266 1267 row = _get_row(); 1268 failed = ! psDBInsertOneRow(dbh, table, row); 1269 psFree(row); 1270 1271 if (!failed) { 1272 ary = psDBDumpRows(dbh, table); 1273 if (ary == NULL) { 1274 failed = 1; 1275 } else { 1276 1277 _print_row((psMetadata*)psArrayGet(ary, 2)); 1278 _print_row((psMetadata*)psArrayGet(ary, 1)); 1279 row = (psMetadata*)psArrayGet(ary, 0); 1280 _print_row(row); 1281 1282 item = psMetadataLookup(row, "key_s32"); 1283 if ((item == NULL) || (item->data.S32 != S32_1)) { 1284 psLogMsg( __func__, PS_LOG_INFO, "oops, did not find expected output!\n" ); 1285 failed = 1; 1286 } else { 1287 psLogMsg( __func__, PS_LOG_INFO, "found expected output.\n" ); 1288 } 1289 1290 item = psMetadataLookup(row, "key_bool"); 1291 if ((item == NULL) || (item->data.B != B_1)) { 1292 psLogMsg( __func__, PS_LOG_INFO, "oops, did not find expected output!\n" ); 1293 failed = 1; 1294 } else { 1295 psLogMsg( __func__, PS_LOG_INFO, "found expected output.\n" ); 1296 } 1297 1298 psFree(ary); 1299 } 1300 } 1301 1302 psDBDropTable(dbh, table); 1303 } 1390 // Create table for testing 1391 if(!psDBCreateTable(dbh, table, md)) { 1392 psError(PS_ERR_UNKNOWN,true,"Did not expect return false from creating table"); 1393 psDBCleanup(dbh); 1394 return 2; 1395 } 1396 1397 // Insert known data rows into table 1398 row = _get_const_row1(); 1399 psDBInsertOneRow(dbh, table, row); 1400 psFree(row); 1401 1402 row = _get_const_row2(); 1403 psDBInsertOneRow(dbh, table, row); 1404 psFree(row); 1405 1406 row = _get_row(); 1407 psDBInsertOneRow(dbh, table, row); 1408 psFree(row); 1409 1410 // Dump row with valid parameters 1411 ary = psDBDumpRows(dbh, table); 1412 if (ary == NULL) { 1413 psError(PS_ERR_UNKNOWN,true,"Did not expect return NULL for dump rows"); 1414 psDBDropTable(dbh,table); 1415 psDBCleanup(dbh); 1416 return 3; 1417 } 1418 if(ary->n != 3) { 1419 psError(PS_ERR_UNKNOWN,true,"Rows dumped %d not as expected %d", 1420 ary->n, 3); 1421 psDBDropTable(dbh,table); 1422 psDBCleanup(dbh); 1423 return 4; 1424 } 1425 1426 row = (psMetadata*)psArrayGet(ary, 0); 1427 if(!_check_row(row)) { 1428 psDBDropTable(dbh,table); 1429 psDBCleanup(dbh); 1430 return 5; 1431 } 1432 row = (psMetadata*)psArrayGet(ary, 1); 1433 if(!_check_const_row2(row)) { 1434 psDBDropTable(dbh,table); 1435 psDBCleanup(dbh); 1436 return 6; 1437 } 1438 row = (psMetadata*)psArrayGet(ary, 2); 1439 if(!_check_const_row1(row)) { 1440 psDBDropTable(dbh,table); 1441 psDBCleanup(dbh); 1442 return 7; 1443 } 1444 1445 psFree(ary); 1446 1447 psDBDropTable(dbh, table); 1304 1448 1305 1449 psFree(md); 1306 1450 psDBCleanup(dbh); 1307 1451 1308 return failed;1452 return 0; 1309 1453 } 1310 1454
Note:
See TracChangeset
for help on using the changeset viewer.
