void printVariableValuesOfConfig(SPConfig config){ SP_CONFIG_MSG msg = SP_CONFIG_SUCCESS; char imagePath[1024]; char pcaPath[1024]; printf("***********printing config values***********\n"); if(config == NULL){ printf("config is NULL\n"); return; } SP_CONFIG_MSG getImagePathMSG = spConfigGetImagePath(imagePath, config, 1); SP_CONFIG_MSG getPCAPathMSG = spConfigGetPCAPath(pcaPath, config); printf("spImagesDirectory = %s\n",spConfigGetspImageDirectory(config)); printf("spImagesPrefix = %s\n",spConfigGetspImagesPrefix(config)); printf("spImagesSuffix = %s\n",spConfigGetspImagesSuffix(config)); printf("spNumOfImages = %d\n",spConfigGetNumOfImages(config, &msg)); //X printf("spPCADimension = %d\n",spConfigGetPCADim(config, &msg)); //V printf("spPCAFilename = %s\n",spConfigGetspPCAFilename(config)); //V printf("spNumOfFeatures = %d\n",spConfigGetNumOfFeatures(config, &msg)); //V printf("spNumOfSimilarImages = %d\n",spConfigGetspNumOfSimilarImages(config)); //V printf("spKNN = %d\n",spConfigGetspKNN(config)); //V printf("spLoggerLevel = %d\n",spConfigGetspLoggerLevel(config)); //V printf("spLoggerFilename = %s\n",spConfigGetspLoggerFilename(config)); //V if(spConfigGetspKDTreeSplitMethod(config) == MAX_SPREAD){ printf("spKDTreeSplitMethod = MAX_SPREAD\n"); }else if(spConfigGetspKDTreeSplitMethod(config) == RANDOM){ printf("spKDTreeSplitMethod = RANDOM\n"); }else if(spConfigGetspKDTreeSplitMethod(config) == INCREMENTAL){ printf("spKDTreeSplitMethod = INCREMENTAL\n"); }else { printf("spConfigGetspKDTreeSplitMethod not working\n"); } if(spConfigIsExtractionMode(config,&msg) == true){ printf("spExtractionMode = %s\n","true"); }else if(spConfigIsExtractionMode(config,&msg) == false){ printf("spExtractionMode = %s\n","false"); }else{ printf("spConfigIsExtractionMode not working\n"); } if(spConfigMinimalGui(config,&msg) == true){ printf("spMinimalGUI = %s\n","true"); }else if(spConfigMinimalGui(config,&msg) == false){ printf("spMinimalGUI = %s\n","false"); }else{ printf("spConfigMinimalGui not working\n"); } }
bool verifyImagesFiles(SPConfig config, int numOfImages, bool extractFlag) { char tempPath[MAX_PATH_LEN]; int i; SP_CONFIG_MSG msg = SP_CONFIG_SUCCESS; bool isImagePathValid; //verify PCA file spVal((msg = spConfigGetPCAPath(tempPath, config)) == SP_CONFIG_SUCCESS, ERROR_AT_PCA_FILE_PATH, false); spLoggerSafePrintDebug(DEBUG_PCA_PATH_IS_VERIFIED, __FILE__, __FUNCTION__, __LINE__); //verify images files for (i = 0; i < numOfImages; i++) { isImagePathValid = (msg = spConfigGetImagePath(tempPath, config, i)) == SP_CONFIG_SUCCESS && verifyPathAndAvailableFile(tempPath); if (extractFlag) { spVal(isImagePathValid, PROBLEM_WITH_IMAGES_FILE_PATH, false); spLoggerSafePrintDebugWithIndex(DEBUG_IMAGE_FILE_IS_VERIFIED_AT_INDEX, i, __FILE__, __FUNCTION__, __LINE__); } else { spValWarning((msg = spConfigGetImagePathFeats(tempPath, config, i, true)) == SP_CONFIG_SUCCESS && verifyPathAndAvailableFile(tempPath), WARNING_AT_IMAGES_FEATURES_FILE_PATH, continue, spLoggerSafePrintDebugWithIndex( DEBUG_IMAGE_FEAT_FILE_IS_VERIFIED_AT_INDEX, i, __FILE__, __FUNCTION__, __LINE__)); if (!isImagePathValid) { spLoggerSafePrintWarning(PROBLEM_WITH_IMAGES_FILE_PATH, __FILE__, __FUNCTION__, __LINE__); } } } return true; }
bool config_funcFailure_nullCheck() { SP_CONFIG_MSG msg; char path[100]; SPConfig config = NULL; ASSERT_TRUE(true == runConfigTest(SUCCESS, /* test type */ 1, /* file index */ 0, /* line of the error */ &config) ); ASSERT_TRUE(false == spConfigIsExtractionMode(NULL, &msg)); checkMsgInvalidArg_AndRevertMsgToSuccess(&msg); ASSERT_TRUE(false == spConfigMinimalGui(NULL,&msg)); checkMsgInvalidArg_AndRevertMsgToSuccess(&msg); ASSERT_TRUE(-1 == spConfigGetNumOfImages(NULL, &msg)); checkMsgInvalidArg_AndRevertMsgToSuccess(&msg); ASSERT_TRUE(-1 == spConfigGetNumOfFeatures(NULL, &msg)); checkMsgInvalidArg_AndRevertMsgToSuccess(&msg); ASSERT_TRUE(-1 == spConfigGetPCADim(NULL, &msg)); checkMsgInvalidArg_AndRevertMsgToSuccess(&msg); msg = spConfigGetImagePath(path, NULL, 1); checkMsgInvalidArg_AndRevertMsgToSuccess(&msg); msg = spConfigGetImagePath(NULL, config , 1); checkMsgInvalidArg_AndRevertMsgToSuccess(&msg); msg = spConfigGetFeatsPath(path, NULL, 1); checkMsgInvalidArg_AndRevertMsgToSuccess(&msg); msg = spConfigGetFeatsPath(NULL, config, 1); checkMsgInvalidArg_AndRevertMsgToSuccess(&msg); msg = spConfigGetPCAPath(path,NULL); checkMsgInvalidArg_AndRevertMsgToSuccess(&msg); msg = spConfigGetPCAPath(NULL,config); checkMsgInvalidArg_AndRevertMsgToSuccess(&msg); ASSERT_TRUE(-1 == spConfigGetNumOfSimilarImages(NULL, &msg)); checkMsgInvalidArg_AndRevertMsgToSuccess(&msg); spConfigGetKDTreeSplitMethod(NULL, &msg); checkMsgInvalidArg_AndRevertMsgToSuccess(&msg); ASSERT_TRUE(-1 == spConfigGetKNN(NULL, &msg)); checkMsgInvalidArg_AndRevertMsgToSuccess(&msg); spConfigGetLoggerLevel(NULL, &msg); checkMsgInvalidArg_AndRevertMsgToSuccess(&msg); msg = spConfigGetLoggerFilename(path,NULL); checkMsgInvalidArg_AndRevertMsgToSuccess(&msg); msg = spConfigGetLoggerFilename(NULL,config); checkMsgInvalidArg_AndRevertMsgToSuccess(&msg); spConfigDestroy(config); return true; }
bool testGivenConfFile() { char imagePath[100], pcaPath[100]; SP_CONFIG_MSG msg = SP_CONFIG_SUCCESS; SPConfig config = spConfigCreate("./unit_tests/spcbirTestCase1.config", &msg); ASSERT_TRUE(config != NULL); ASSERT_TRUE(msg == SP_CONFIG_SUCCESS); ASSERT_TRUE(!strcmp(spConfigGetImagesDirectory(config, &msg), "./images/")); ASSERT_TRUE(msg == SP_CONFIG_SUCCESS); ASSERT_TRUE(spConfigGetImagesDirectory(NULL, &msg) == NULL); ASSERT_TRUE(msg == SP_CONFIG_INVALID_ARGUMENT); ASSERT_TRUE(!strcmp(spConfigGetImagesPrefix(config, &msg), "img")); ASSERT_TRUE(msg == SP_CONFIG_SUCCESS); ASSERT_TRUE(spConfigGetImagesPrefix(NULL, &msg) == NULL); ASSERT_TRUE(msg == SP_CONFIG_INVALID_ARGUMENT); ASSERT_TRUE(!strcmp(spConfigGetImagesSuffix(config, &msg), ".png")); ASSERT_TRUE(msg == SP_CONFIG_SUCCESS); ASSERT_TRUE(spConfigGetImagesSuffix(NULL, &msg) == NULL); ASSERT_TRUE(msg == SP_CONFIG_INVALID_ARGUMENT); ASSERT_TRUE(!strcmp(spConfigGetPCAFilename(config, &msg), "pca.yml")); ASSERT_TRUE(msg == SP_CONFIG_SUCCESS); ASSERT_TRUE(spConfigGetPCAFilename(NULL, &msg) == NULL); ASSERT_TRUE(msg == SP_CONFIG_INVALID_ARGUMENT); ASSERT_TRUE(spConfigIsExtractionMode(config, &msg) == true); ASSERT_TRUE(msg == SP_CONFIG_SUCCESS); ASSERT_TRUE(spConfigIsExtractionMode(NULL, &msg) == false); ASSERT_TRUE(msg == SP_CONFIG_INVALID_ARGUMENT); ASSERT_TRUE(spConfigMinimalGui(config, &msg) == false); ASSERT_TRUE(msg == SP_CONFIG_SUCCESS); ASSERT_TRUE(spConfigMinimalGui(NULL, &msg) == false); ASSERT_TRUE(msg == SP_CONFIG_INVALID_ARGUMENT); ASSERT_TRUE(spConfigGetNumOfImages(config, &msg) == 22); ASSERT_TRUE(msg == SP_CONFIG_SUCCESS); ASSERT_TRUE(spConfigGetNumOfImages(NULL, &msg) == -1); ASSERT_TRUE(msg == SP_CONFIG_INVALID_ARGUMENT); ASSERT_TRUE(spConfigGetNumOfFeatures(config, &msg) == 100); ASSERT_TRUE(msg == SP_CONFIG_SUCCESS); ASSERT_TRUE(spConfigGetNumOfFeatures(NULL, &msg) == -1); ASSERT_TRUE(msg == SP_CONFIG_INVALID_ARGUMENT); ASSERT_TRUE(spConfigGetPCADim(config, &msg) == 20); ASSERT_TRUE(msg == SP_CONFIG_SUCCESS); ASSERT_TRUE(spConfigGetPCADim(NULL, &msg) == -1); ASSERT_TRUE(msg == SP_CONFIG_INVALID_ARGUMENT); ASSERT_TRUE(spConfigGetNumOfSimilarImages(config, &msg) == 5); ASSERT_TRUE(msg == SP_CONFIG_SUCCESS); ASSERT_TRUE(spConfigGetNumOfSimilarImages(NULL, &msg) == -1); ASSERT_TRUE(msg == SP_CONFIG_INVALID_ARGUMENT); ASSERT_TRUE(spConfigGetKNN(config, &msg) == 5); ASSERT_TRUE(msg == SP_CONFIG_SUCCESS); ASSERT_TRUE(spConfigGetKNN(NULL, &msg) == -1); ASSERT_TRUE(msg == SP_CONFIG_INVALID_ARGUMENT); ASSERT_TRUE(spConfigGetSplitMethod(config, &msg) == MAX_SPREAD); ASSERT_TRUE(msg == SP_CONFIG_SUCCESS); ASSERT_TRUE(spConfigGetSplitMethod(NULL, &msg) == MAX_SPREAD); ASSERT_TRUE(msg == SP_CONFIG_INVALID_ARGUMENT); ASSERT_TRUE(spConfigGetLoggerLevel(config, &msg) == SP_LOGGER_DEBUG_INFO_WARNING_ERROR_LEVEL); ASSERT_TRUE(msg == SP_CONFIG_SUCCESS); ASSERT_TRUE(spConfigGetLoggerLevel(NULL, &msg) == SP_LOGGER_INFO_WARNING_ERROR_LEVEL); ASSERT_TRUE(msg == SP_CONFIG_INVALID_ARGUMENT); ASSERT_TRUE(!strcmp(spConfigGetLoggerFilename(config, &msg), "stdout")); ASSERT_TRUE(msg == SP_CONFIG_SUCCESS); ASSERT_TRUE(spConfigGetLoggerFilename(NULL, &msg) == NULL); ASSERT_TRUE(msg == SP_CONFIG_INVALID_ARGUMENT); ASSERT_TRUE(spConfigGetImagePath(imagePath, config, 13) == SP_CONFIG_SUCCESS); ASSERT_TRUE(!strcmp(imagePath, "./images/img13.png")); ASSERT_TRUE(spConfigGetImagePath(imagePath, config, 22) == SP_CONFIG_INDEX_OUT_OF_RANGE); ASSERT_TRUE(spConfigGetImagePath(NULL, config, 1) == SP_CONFIG_INVALID_ARGUMENT); ASSERT_TRUE(spConfigGetImagePath(imagePath, NULL, 1) == SP_CONFIG_INVALID_ARGUMENT); ASSERT_TRUE(spConfigGetImagePath(NULL, NULL, 1) == SP_CONFIG_INVALID_ARGUMENT); ASSERT_TRUE(spConfigGetPCAPath(pcaPath, config) == SP_CONFIG_SUCCESS); ASSERT_TRUE(!strcmp(pcaPath, "./images/pca.yml")); ASSERT_TRUE(spConfigGetPCAPath(NULL, config) == SP_CONFIG_INVALID_ARGUMENT); ASSERT_TRUE(spConfigGetPCAPath(pcaPath, NULL) == SP_CONFIG_INVALID_ARGUMENT); ASSERT_TRUE(spConfigGetPCAPath(NULL, NULL) == SP_CONFIG_INVALID_ARGUMENT); spConfigDestroy(config); return true; }
bool config_success_checkDefaults() { SPConfig config = NULL; SP_CONFIG_MSG msg; ASSERT_TRUE(true == runConfigTest(SUCCESS, /* test type */ 7, /* file index */ 0, /* line of the error */ &config) ); char featurePath[100]; msg = spConfigGetFeatsPath(featurePath, config, 2); ASSERT_TRUE( 0 == strcmp(featurePath, "./images10/myImg2.feats") ); if(!checkMsgSuccess_AndRevertMsgToNonSuccess(&msg)) { printf("error line %d", __LINE__); return false; } char imgPath[100]; msg = spConfigGetImagePath(imgPath, config, 4); ASSERT_TRUE( 0 == strcmp(imgPath, "./images10/myImg4.gif") ); if(!checkMsgSuccess_AndRevertMsgToNonSuccess(&msg)) { printf("error line %d", __LINE__); return false; } ASSERT_TRUE(SPLIT_METHOD_MAXSPREAD == spConfigGetKDTreeSplitMethod(config, &msg)); if(!checkMsgSuccess_AndRevertMsgToNonSuccess(&msg)) { printf("error line %d", __LINE__); return false; } ASSERT_TRUE(1 == spConfigGetKNN(config, &msg)); if(!checkMsgSuccess_AndRevertMsgToNonSuccess(&msg)) { printf("error line %d", __LINE__); return false; } char loggerFile[100]; msg = spConfigGetLoggerFilename(loggerFile, config); ASSERT_TRUE( 0 == strcmp(loggerFile, "stdout") ); if(!checkMsgSuccess_AndRevertMsgToNonSuccess(&msg)) { printf("error line %d", __LINE__); return false; } ASSERT_TRUE(SP_LOGGER_INFO_WARNING_ERROR_LEVEL == spConfigGetLoggerLevel(config, &msg)); if(!checkMsgSuccess_AndRevertMsgToNonSuccess(&msg)) { printf("error line %d", __LINE__); return false; } ASSERT_TRUE(100 == spConfigGetNumOfFeatures(config, &msg)); if(!checkMsgSuccess_AndRevertMsgToNonSuccess(&msg)) { printf("error line %d", __LINE__); return false; } ASSERT_TRUE(10 == spConfigGetNumOfImages(config, &msg)); if(!checkMsgSuccess_AndRevertMsgToNonSuccess(&msg)) { printf("error line %d", __LINE__); return false; } ASSERT_TRUE(1 == spConfigGetNumOfSimilarImages(config, &msg)); if(!checkMsgSuccess_AndRevertMsgToNonSuccess(&msg)) { printf("error line %d", __LINE__); return false; } ASSERT_TRUE(20 == spConfigGetPCADim(config, &msg)); if(!checkMsgSuccess_AndRevertMsgToNonSuccess(&msg)) { printf("error line %d", __LINE__); return false; } char pcaPath[100]; msg = spConfigGetPCAPath(pcaPath, config); ASSERT_TRUE( 0 == strcmp(pcaPath, "./images10/pca.yml") ); if(!checkMsgSuccess_AndRevertMsgToNonSuccess(&msg)) { printf("error line %d", __LINE__); return false; } ASSERT_TRUE( true == spConfigIsExtractionMode(config, &msg)); if(!checkMsgSuccess_AndRevertMsgToNonSuccess(&msg)) { printf("error line %d", __LINE__); return false; } ASSERT_TRUE( false == spConfigMinimalGui(config, &msg)); if(!checkMsgSuccess_AndRevertMsgToNonSuccess(&msg)) { printf("error line %d", __LINE__); return false; } spConfigDestroy(config); return true; }