Add tests for config
I have started writing tests for the config functions. This has resulted in a few changes to the config code (tests working I guess) I have also added a special "all" config file which (as the name suggests) runs all test suites In the makefile I have added the compiled test files to the clean target and added targets for building and running tests
This commit is contained in:
parent
c046ac37a9
commit
e42705280c
4 changed files with 159 additions and 8 deletions
13
src/config.c
13
src/config.c
|
@ -14,18 +14,19 @@ static bool path_exists(const char *path) {
|
|||
*/
|
||||
static char* resolveTilde(const char *path) {
|
||||
static glob_t globbuf;
|
||||
static char *ret = NULL;
|
||||
|
||||
int res = glob(path, GLOB_TILDE, NULL, &globbuf);
|
||||
/* no match, or many wildcard matches are bad */
|
||||
if (res == GLOB_NOMATCH)
|
||||
return strdup(path);
|
||||
ret = strdup(path);
|
||||
else if (res != 0) {
|
||||
printf("glob() failed\n");
|
||||
return NULL;
|
||||
} else {
|
||||
return strdup(globbuf.gl_pathv[0]);
|
||||
ret = strdup(globbuf.gl_pathv[0]);
|
||||
}
|
||||
globfree(&globbuf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -36,7 +37,7 @@ Config* configDefaults(){
|
|||
conf->database = "proxy.sqlite";
|
||||
conf->port = 8080;
|
||||
conf->localConfig = "proxy.conf";
|
||||
conf->userConfig = getDefaultUserConfigLoc();
|
||||
//conf->userConfig = getDefaultUserConfigLoc();
|
||||
|
||||
return conf;
|
||||
}
|
||||
|
@ -51,7 +52,7 @@ char* getConfigDir(){
|
|||
|
||||
char* getDefaultUserConfigLoc(){
|
||||
char *configDir = getConfigDir();
|
||||
char *configFile[strlen(configDir) + 11];
|
||||
char configFile[strlen(configDir) + 11];
|
||||
|
||||
memset(configFile, '\0', strlen(configDir) + 11);
|
||||
|
||||
|
@ -59,6 +60,6 @@ char* getDefaultUserConfigLoc(){
|
|||
|
||||
strcat( configFile, configDir );
|
||||
|
||||
return configFile;
|
||||
return strdup(configFile);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue