secret
Created

  • Download Gist
configuration.c
C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#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");
}
configuration.h
C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#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
configuration_test.c
C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
#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);
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.