示例#1
0
bool config_success_WithCarrigeReturnAtEOF()
{
	SPConfig config = NULL;
	SP_CONFIG_MSG msg;

	ASSERT_TRUE(true == runConfigTest(SUCCESS, /* test type */
										8, /* file index */
										0,	/* line of the error */
										&config)
				);


	char imgPath[100];
	msg = spConfigGetImagePath(imgPath, config, 4);
	ASSERT_TRUE( 0 == strcmp(imgPath, "./images/img4.png") );
	if(!checkMsgSuccess_AndRevertMsgToNonSuccess(&msg))
	{
		printf("error line %d", __LINE__);
		return false;
	}

	ASSERT_TRUE(16 == spConfigGetNumOfImages(config, &msg));
	if(!checkMsgSuccess_AndRevertMsgToNonSuccess(&msg))
	{
		printf("error line %d", __LINE__);
		return false;
	}

	spConfigDestroy(config);

	return true;
}
示例#2
0
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");
	}

}
示例#3
0
bool config_success_PlusSign()
{
	SPConfig config = NULL;
	SP_CONFIG_MSG msg;

	ASSERT_TRUE(true == runConfigTest(SUCCESS, /* test type */
										2, /* file index */
										0,	/* line of the error */
										&config)
				);

	ASSERT_TRUE(16 == spConfigGetNumOfImages(config, &msg));

	spConfigDestroy(config);

	return true;
}
示例#4
0
SP_CONFIG_MSG loadRelevantSettingsData(const SPConfig config, int* numOfImages,
		int* numOfSimilar, bool* extractFlag, bool* GUIFlag) {
	SP_CONFIG_MSG rslt = SP_CONFIG_SUCCESS;
	assert(config != NULL);

	*numOfImages = spConfigGetNumOfImages(config, &rslt);
	spVal(rslt == SP_CONFIG_SUCCESS, ERROR_READING_SETTINGS, rslt);

	*numOfSimilar = spConfigGetNumOfSimilarImages(config, &rslt);
	spVal(rslt == SP_CONFIG_SUCCESS, ERROR_READING_SETTINGS, rslt);

	*extractFlag = spConfigIsExtractionMode(config , &rslt);
	spVal(rslt == SP_CONFIG_SUCCESS, ERROR_READING_SETTINGS, rslt);

	*GUIFlag = spConfigMinimalGui(config, &rslt);
	spVal(rslt == SP_CONFIG_SUCCESS, ERROR_READING_SETTINGS, rslt);

	return rslt;
}
示例#5
0
文件: KDTree.c 项目: orrbarkat/c
int* spFindImages(SPPoint* queryFeatures, const int querySize,
		const SPKDTreeNode root, const SPConfig config, SP_CONFIG_MSG *msg){
    int i, knn, numOfSimilarImg, numOfImages;
    int *imageCounter, *res;
    SPListElement element;
    knn = spConfigGetKNN(config, msg);

    SPBPQueue q = spBPQueueCreate(knn);
    if(!q){
        spLoggerPrintError(ALLOC_FAIL, __FILE__, __FUNCTION__, __LINE__);
        return NULL;
    }
    numOfImages = spConfigGetNumOfImages(config, msg);
    numOfSimilarImg = spConfigGetNumOfSimilarImages(config, msg);
    imageCounter = (int*)calloc(numOfImages, sizeof(int));
    if(!imageCounter){
        spLoggerPrintError(ALLOC_FAIL, __FILE__, __FUNCTION__, __LINE__);
        spBPQueueDestroy(q);
        return NULL;
    }
    /* count the num of neighbours of every
     * image for all features of the query */
    for(i=0; i<querySize; i++){
        spBPQueueClear(q);
        spKNNSearch(queryFeatures[i], root, q);
        while((element = spBPQueuePeek(q))!=NULL){
            imageCounter[spListElementGetIndex(element)]+=1;
            spListElementDestroy(element);
            spBPQueueDequeue(q);
        }
    }
    spBPQueueClear(q);
    spBPQueueDestroy(q);
    res = getTopImagesFromArray(imageCounter, numOfImages, numOfSimilarImg);
    free(imageCounter);
    return res;
}
示例#6
0
int main(char * args){
//Make sure that the logger was set at the beginning of the main function


//start

// COMMAND LINE ARGUMENT with the Error messages
	char * configFilename;
	if (args == NULL){
		configFilename = "spcbir.config";
	}
	else{
		configFilename = args;
	}
	//“Invalid command line : use -c <config_filename>” - check

//init from config
	SP_CONFIG_MSG spConfigMsg;
	SPConfig configFile = spConfigCreate(configFilename,spConfigMsg);  //should destroy it
	if (spConfigMsg == SP_CONFIG_CANNOT_OPEN_FILE){
		if (configFilename == "spcbir.config" ){
			//“The default configuration file spcbir.config couldn’t be open” +new line + exit?
		}
		else{
			//#2 “The configuration file <filename> couldn’t be open” + new line +exit?
		}
	}


	//variables

	int NumOfImages = spConfigGetNumOfImages(configFile,spConfigMsg);
	char * imagePath =(char*) malloc (1024*sizeof(char));  // should free it
	int spKNN = spConfigGetspKNN(configFile,spConfigMsg);
	int NumOfFeatures =  spConfigGetNumOfFeatures(configFile,spConfigMsg);
	int * imgArray = (int*)malloc (sizeof(int)*configFile,spConfigMsg); // should free it
	int NumOfSimilarImages=spConfigGetNumOfSimilarImages(configFile,spConfigMsg);
	int * SimilarImagesArr = (int*)malloc (NumOfSimilarImages*sizeof(int)); // should free it
	int i=0;
	for (i=0;i<NumOfSimilarImages;i++){
		SimilarImagesArr[i]=0;
	}
	i=0;
	for (i=0; i<NumOfImages;i++){
		imgArray[i]=0;
	}
	i=0;
	SPPoint * queryFeatures = (SPPoint*) malloc (NumOfFeatures*sizeof (SPPoint)); // should free it
	char * queryImgPath =(char*)  malloc (1024*sizeof(char)); // should free it

	int max=0;
	int j=0;
// extract mode?
	if (spConfigIsExtractionMode(configFile,spConfigMsg)){
		// yes:

		//extract features

		// done?

		// no: repeat

		// yes: save to directory

	}
	else{
		//no:

		//	extract from file
	}

// init data structures

// recive command

// query?
	query:

    printf("Please enter an image path:\n");
    scanf("%s", queryImgPath);

// no: exit
if (queryImgPath== '<>'){
	goto ending;
}

// get query features
queryFeatures = getImageFeatures(queryImgPath,int index,int* numOfFeats);
for (i=0;i<NumOfFeatures;i++){
	spKNNSearch( tree,  queryFeatures[i],  spKNN, imgArray);
}
i=0;

// get most similar images
for (i=0;i<NumOfSimilarImages;i++){
	for (j=0;j<NumOfFeatures;j++){
		if (imgArray[j]>imgArray[max]){
			max = j;
		}
	}
	SimilarImagesArr[i]= max;
	imgArray[max] =-1;
}

i=0;

// show results
if(spConfigMinimalGui(configFile,spConfigMsg)){

	for (i=0;i<NumOfSimilarImages;i++){
		spConfigGetImagePath(imagePath, configFile, SimilarImagesArr[i]);
		showImage(imagePath);
		//wait
	}
}
else{
	printf("Best candidates for - %d - are:\n",queryImgPath);
	for (i=0;i<NumOfSimilarImages;i++){
		spConfigGetImagePath(imagePath, configFile, SimilarImagesArr[i]);
		printf ("%d\n",imagePath);

	}
}
goto query;
ending:
// ending
//frees ();

spConfigDestroy (configFilename);
free (imagePath);
free (SimilarImagesArr);
free (queryFeatures);
free (queryImgPath);
free (imgArray);

return 0;




};
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 testHandler() {
	SPConfig config = (SPConfig)calloc(1, spConfigGetConfigStructSize());
	SP_CONFIG_MSG msg = SP_CONFIG_SUCCESS;

	ASSERT_TRUE(config != NULL);

	ASSERT_FALSE(handleVariable(config, "a", 1, "spImagesDirectori", "C:\\MyDocuments\\",
			&msg));
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_LINE);
	msg = SP_CONFIG_SUCCESS;

	ASSERT_FALSE(handleVariable(config, "a", 1, "spImagesDirectory", "C:\\My Documents\\",
			&msg));
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_STRING);
	msg = SP_CONFIG_SUCCESS;

	ASSERT_FALSE(handleVariable(config, "a", 1, "spImagesPrefix", "my image", &msg));
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_STRING);
	msg = SP_CONFIG_SUCCESS;

	ASSERT_FALSE(handleVariable(config, "a", 1, "spImagesSuffix", ".jpj", &msg));
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_STRING);
	msg = SP_CONFIG_SUCCESS;

	ASSERT_FALSE(handleVariable(config, "a", 1, "spNumOfImages", "-9000", &msg));
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_INTEGER);
	msg = SP_CONFIG_SUCCESS;

	// check that a valid int is according to the rules in the forum (next 4 tests)
	ASSERT_TRUE(handleVariable(config, "a", 1, "spNumOfImages", "014", &msg));
	ASSERT_TRUE(msg == SP_CONFIG_SUCCESS);
	ASSERT_TRUE(spConfigGetNumOfImages(config, &msg) == 14);
	msg = SP_CONFIG_SUCCESS;

	ASSERT_TRUE(handleVariable(config, "a", 1, "spNumOfImages", "+1", &msg));
	ASSERT_TRUE(msg == SP_CONFIG_SUCCESS);
	ASSERT_TRUE(spConfigGetNumOfImages(config, &msg) == 1);
	msg = SP_CONFIG_SUCCESS;

	ASSERT_FALSE(handleVariable(config, "a", 1, "spNumOfImages", "1.0", &msg));
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_INTEGER);
	msg = SP_CONFIG_SUCCESS;

	ASSERT_FALSE(handleVariable(config, "a", 1, "spNumOfImages", "20 40", &msg));
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_INTEGER);
	msg = SP_CONFIG_SUCCESS;

	ASSERT_FALSE(handleVariable(config, "a", 1, "spNumOfSimilarImages", "0", &msg));
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_INTEGER);
	msg = SP_CONFIG_SUCCESS;

	ASSERT_FALSE(handleVariable(config, "a", 1, "spKNN", "aaa", &msg));
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_INTEGER);
	msg = SP_CONFIG_SUCCESS;

	ASSERT_FALSE(handleVariable(config, "a", 1, "spLoggerLevel", "5", &msg));
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_INTEGER);
	msg = SP_CONFIG_SUCCESS;

	ASSERT_FALSE(handleVariable(config, "a", 1, "spPCADimension", "9", &msg));
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_INTEGER);
	msg = SP_CONFIG_SUCCESS;

	ASSERT_FALSE(handleVariable(config, "a", 1, "spPCADimension", "30", &msg));
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_INTEGER);
	msg = SP_CONFIG_SUCCESS;

	ASSERT_FALSE(handleVariable(config, "a", 1, "spKDTreeSplitMethod", "something", &msg));
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_KDTREE_SPLIT_METHOD);
	msg = SP_CONFIG_SUCCESS;

	ASSERT_FALSE(handleVariable(config, "a", 1, "spExtractionMode", "tru", &msg));
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_BOOLEAN);
	msg = SP_CONFIG_SUCCESS;

	ASSERT_FALSE(handleVariable(config, "a", 1, "spMinimalGUI", "fal", &msg));
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_BOOLEAN);
	msg = SP_CONFIG_SUCCESS;

	ASSERT_TRUE(handleVariable(config, "a", 1, "spImagesDirectory", "C:\\Documents\\",
			&msg));
	ASSERT_TRUE(msg == SP_CONFIG_SUCCESS);
	ASSERT_TRUE(!strcmp(spConfigGetImagesDirectory(config, &msg), "C:\\Documents\\"));

	ASSERT_TRUE(handleVariable(config, "a", 1, "spImagesSuffix", ".bmp",
			&msg));
	ASSERT_TRUE(msg == SP_CONFIG_SUCCESS);
	ASSERT_TRUE(!strcmp(spConfigGetImagesSuffix(config, &msg), ".bmp"));

	ASSERT_TRUE(handleVariable(config, "a", 1, "spNumOfFeatures", "80",
			&msg));
	ASSERT_TRUE(msg == SP_CONFIG_SUCCESS);
	ASSERT_TRUE(spConfigGetNumOfFeatures(config, &msg) == 80);

	ASSERT_TRUE(handleVariable(config, "a", 1, "spPCADimension", "19",
			&msg));
	ASSERT_TRUE(msg == SP_CONFIG_SUCCESS);
	ASSERT_TRUE(spConfigGetPCADim(config, &msg) == 19);

	ASSERT_TRUE(handleVariable(config, "a", 1, "spExtractionMode", "true",
			&msg));
	ASSERT_TRUE(msg == SP_CONFIG_SUCCESS);
	ASSERT_TRUE(spConfigIsExtractionMode(config, &msg));

	ASSERT_TRUE(handleVariable(config, "a", 1, "spKDTreeSplitMethod", "INCREMENTAL",
			&msg));
	ASSERT_TRUE(msg == SP_CONFIG_SUCCESS);
	ASSERT_TRUE(spConfigGetSplitMethod(config, &msg) == INCREMENTAL);

	spConfigDestroy(config);
	return true;
}
bool testDefault() {
	char imagePath[100], *loggerFilename = NULL, *pcaFilename = NULL;
	SPConfig config = (SPConfig)calloc(1, spConfigGetConfigStructSize());
	SP_CONFIG_MSG msg = SP_CONFIG_SUCCESS;

	ASSERT_TRUE(config != NULL);

	initConfigToDefault(config);

	ASSERT_TRUE(spConfigGetImagesDirectory(config, &msg) == NULL);
	ASSERT_TRUE(spConfigGetImagesPrefix(config, &msg) == NULL);
	ASSERT_TRUE(spConfigGetImagesSuffix(config, &msg) == NULL);
	ASSERT_TRUE(spConfigGetNumOfImages(config, &msg) == 0);

	ASSERT_TRUE(parameterSetCheck(config, &msg, "a", 1, NULL) == NULL);
	ASSERT_TRUE(msg == SP_CONFIG_MISSING_DIR);
	msg = SP_CONFIG_SUCCESS;

	config = (SPConfig)calloc(1, spConfigGetConfigStructSize());
	ASSERT_TRUE(config != NULL);
	initConfigToDefault(config);
	spConfigSetImagesDirectory(config, duplicateString("./bla/bla/"));
	ASSERT_TRUE(parameterSetCheck(config, &msg, "a", 1, NULL) == NULL);
	ASSERT_TRUE(msg == SP_CONFIG_MISSING_PREFIX);
	msg = SP_CONFIG_SUCCESS;

	config = (SPConfig)calloc(1, spConfigGetConfigStructSize());
	ASSERT_TRUE(config != NULL);
	initConfigToDefault(config);
	spConfigSetImagesDirectory(config, duplicateString("./bla/bla/"));
	spConfigSetImagesPrefix(config, duplicateString("whatever"));
	ASSERT_TRUE(parameterSetCheck(config, &msg, "a", 1, NULL) == NULL);
	ASSERT_TRUE(msg == SP_CONFIG_MISSING_SUFFIX);
	msg = SP_CONFIG_SUCCESS;

	config = (SPConfig)calloc(1, spConfigGetConfigStructSize());
	ASSERT_TRUE(config != NULL);
	initConfigToDefault(config);
	spConfigSetImagesDirectory(config, duplicateString("./bla/bla/"));
	spConfigSetImagesPrefix(config, duplicateString("whatever"));
	spConfigSetImagesSuffix(config, duplicateString(".jpg"));
	ASSERT_TRUE(parameterSetCheck(config, &msg, "a", 1, NULL) == NULL);
	ASSERT_TRUE(msg == SP_CONFIG_MISSING_NUM_IMAGES);
	msg = SP_CONFIG_SUCCESS;

	config = (SPConfig)calloc(1, spConfigGetConfigStructSize());
	ASSERT_TRUE(config != NULL);
	initConfigToDefault(config);
	spConfigSetImagesDirectory(config, duplicateString("./bla/bla/"));
	spConfigSetImagesPrefix(config, duplicateString("whatever"));
	spConfigSetImagesSuffix(config, duplicateString(".jpg"));
	spConfigSetImagesNum(config, 9000);
	ASSERT_TRUE(parameterSetCheck(config, &msg, "a", 1, NULL) == config);
	ASSERT_TRUE(msg == SP_CONFIG_SUCCESS);

	ASSERT_TRUE(spConfigGetImagePath(imagePath, config, 4444) == SP_CONFIG_SUCCESS);
	ASSERT_TRUE(!strcmp(imagePath, "./bla/bla/whatever4444.jpg"));

	ASSERT_TRUE(checkAndSetDefIfNeeded(&loggerFilename, "stdout", &msg));
	ASSERT_TRUE(!strcmp(loggerFilename, "stdout"));
	ASSERT_TRUE(msg == SP_CONFIG_SUCCESS);
	free(loggerFilename);

	loggerFilename = duplicateString("/tmp/whatever");
	ASSERT_TRUE(checkAndSetDefIfNeeded(&loggerFilename, "stdout", &msg));
	ASSERT_TRUE(!strcmp(loggerFilename, "/tmp/whatever"));
	ASSERT_TRUE(msg == SP_CONFIG_SUCCESS);
	free(loggerFilename);

	ASSERT_TRUE(checkAndSetDefIfNeeded(&pcaFilename, "pca.yml", &msg));
	ASSERT_TRUE(!strcmp(pcaFilename, "pca.yml"));
	ASSERT_TRUE(msg == SP_CONFIG_SUCCESS);
	free(pcaFilename);

	pcaFilename = duplicateString("/tmp/whatever2");
	ASSERT_TRUE(checkAndSetDefIfNeeded(&pcaFilename, "pca.yml", &msg));
	ASSERT_TRUE(!strcmp(pcaFilename, "/tmp/whatever2"));
	ASSERT_TRUE(msg == SP_CONFIG_SUCCESS);
	free(pcaFilename);

	spConfigDestroy(config);
	return true;
}
示例#10
0
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;
}
示例#11
0
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;
}