-
-
Save leehambley/99a9de3275f38a7835d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "libwatchedit/configuration.h" | |
#include "stdlib.h" | |
#include "string.h" | |
#define DEFAULT_CONFIGURATION_FILENAME ".watched.it.yml" | |
char *wit_configuration_file_path() { | |
char *home_directory; | |
home_directory = getenv("HOME"); | |
if(home_directory == NULL) { | |
return NULL; | |
} else { | |
char *configuration_file_path; | |
int configuration_file_path_length = strlen(home_directory) + strlen(DEFAULT_CONFIGURATION_FILENAME) + 1; | |
configuration_file_path = (char*) malloc(configuration_file_path_length); | |
if ( configuration_file_path == NULL ) { | |
return NULL; | |
} else { | |
strcpy(configuration_file_path, home_directory); | |
strcat(configuration_file_path, DEFAULT_CONFIGURATION_FILENAME); | |
return configuration_file_path; | |
} | |
} | |
} | |
int wit_load_configuration(wit_configuration configuration) { | |
set_log_context("libwatchedit.configuration.wit_load_configuration"); | |
char* filename; | |
filename = wit_configuration_file_path(); | |
log_debug("Loading"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef HAVE_LIBWATCHEDIT_CONFIGURATION_H | |
#define HAVE_LIBWATCHEDIT_CONFIGURATION_H | |
#include "libwatchedit.h" | |
struct wit_configuration_struct { | |
char *api_key; | |
struct wit_server_struct *server; | |
}; | |
typedef struct wit_configuration_struct *wit_configuration; | |
char* wit_configuration_file_path(); | |
int wit_load_configuration(wit_configuration); | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdarg.h> | |
#include <stddef.h> | |
#include <setjmp.h> | |
#include <google/cmockery.h> | |
#include "libwatchedit/configuration.h" | |
extern char* wit_configuration_file_path(); | |
char* wit_configuration_file_path() { | |
return (char*) mock(); | |
} | |
void test_test(void **state) { | |
assert_true(1); | |
} | |
void test_something_else(void **state) { | |
assert_true(1); | |
} | |
void test_can_load_a_correctly_formed_configuration_file(void **state) { | |
/* Stub Known Good Configuration */ | |
will_return(wit_configuration_file_path, "./fixtures/known_good_configuration.yml"); | |
wit_configuration configuration; | |
assert_true(wit_load_configuration(configuration)); | |
} | |
int main(int argc, char* argv[]) { | |
UnitTest tests[] = { | |
unit_test(test_test), | |
unit_test(test_something_else), | |
unit_test(test_can_load_a_correctly_formed_configuration_file) | |
}; | |
return run_tests(tests); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment