-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from sinemetu1/test-separation
maint - adding tests that mock curl calls, separating integration tests, updated README
- Loading branch information
Showing
15 changed files
with
524 additions
and
192 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,3 +60,4 @@ stamp-h1 | |
test-drive | ||
src/test/test_reply | ||
src/test/test_twitc | ||
src/test/integration |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ AC_SUBST([CFLAGS]) | |
|
||
AC_PROG_CC | ||
AM_PROG_CC_C_O | ||
AC_PROG_CC_C99 | ||
AM_PROG_AR | ||
AC_LANG([C]) | ||
LT_INIT | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,49 @@ | ||
/* file: minunit.h */ | ||
/* taken from http://www.jera.com/techinfo/jtns/jtn002.html#Source_Code */ | ||
/* file: minunit.h | ||
* taken and modified from http://www.jera.com/techinfo/jtns/jtn002.html#Source_Code | ||
*/ | ||
|
||
#include <stdlib.h> | ||
#include <stdarg.h> | ||
|
||
#define mu_assert(message, test) do { if (!(test)) return message; } while (0) | ||
#define mu_run_test(file, line, func, test) do { \ | ||
char *message = test(); \ | ||
int ret_length = 1024; \ | ||
char *toRet = malloc(ret_length); \ | ||
memset(toRet, 0, ret_length); \ | ||
tests_run++; \ | ||
if (message) { \ | ||
|
||
#define mu_run_test(file, line, func, test) do { \ | ||
char *message = test(); \ | ||
tests_run++; \ | ||
if (message) { \ | ||
int ret_length = 1024; \ | ||
char *toRet = malloc(ret_length); \ | ||
memset(toRet, 0, ret_length); \ | ||
sprintf(toRet, "Failed %s at line %d: %s", __FILE__, __LINE__, message); \ | ||
return toRet; \ | ||
} \ | ||
return toRet; \ | ||
} \ | ||
} while (0) | ||
|
||
/** | ||
* Tests actual for equality with processed string. | ||
*/ | ||
#define mu_assert_str(message, actual, format, ...) do { \ | ||
char local[BUFSIZ] = ""; \ | ||
snprintf(local, sizeof(local), format, __VA_ARGS__);\ | ||
int cmp = strcmp(local, actual); \ | ||
if (cmp != 0) { \ | ||
printf("%s != %s\n", local, actual); \ | ||
return message; \ | ||
} \ | ||
} while (0) | ||
|
||
/** | ||
* Tests actual for containment of processed string. | ||
*/ | ||
#define mu_assert_strcspn(message, actual, format, ...) do {\ | ||
char local[BUFSIZ] = ""; \ | ||
snprintf(local, BUFSIZ, format, __VA_ARGS__); \ | ||
char *cmp = strstr(actual, local); \ | ||
if (cmp == NULL) { \ | ||
printf("didn't find %s in actual\n", local); \ | ||
printf("actual: %s\n", actual); \ | ||
return message; \ | ||
} \ | ||
} while (0) | ||
|
||
extern int tests_run; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* @file test.h | ||
* @author Sam Garrett <samdgarrett@gmail.com> | ||
*/ | ||
#ifndef TEST_TWITC_H | ||
#define TEST_TWITC_H | ||
|
||
#include <curl/curl.h> | ||
|
||
void print_tracked_params(void); | ||
void free_tracked_params(void); | ||
|
||
/** | ||
* NOTE: will not work if using in multi-threaded tests | ||
* because of global vars below. | ||
*/ | ||
#define test_curl_easy_setopt(handle, option, paremeter, track) do { \ | ||
curl_easy_setopt(handle, option, paremeter); \ | ||
int length = strlen(paremeter) + 1; \ | ||
if (track == NULL) { \ | ||
track = malloc(length); \ | ||
if (track == NULL) { \ | ||
fprintf(stderr, "not enough memory (malloc returned NULL)\n"); \ | ||
exit(1); \ | ||
} \ | ||
} else { \ | ||
track = realloc(track, length); \ | ||
if (track == NULL) { \ | ||
fprintf(stderr, "not enough memory (realloc returned NULL)\n");\ | ||
exit(1); \ | ||
} \ | ||
} \ | ||
snprintf(track, length, "%s", paremeter); \ | ||
} while (0) | ||
|
||
/** | ||
* Can't really have a drop-in replacement for curl_easy_perform | ||
* since it's return value is used, thus this one with an extra param. | ||
*/ | ||
#define test_curl_easy_perform(handle, curl_res) do { \ | ||
test_curl_perform_called++; \ | ||
curl_res = CURLE_OK; \ | ||
} while (0) | ||
|
||
int test_curl_perform_called = 0; | ||
char *test_curl_url; | ||
char *test_curl_post_data; | ||
char *test_curl_header; | ||
|
||
void | ||
print_tracked_params(void) | ||
{ | ||
printf("perform_called: %d\ncalled_url: %s\nposted_data: %s\ntest_curl_header: %s\n", | ||
test_curl_perform_called, test_curl_url, test_curl_post_data, | ||
test_curl_header); | ||
} | ||
|
||
void | ||
free_tracked_params(void) | ||
{ | ||
if (test_curl_url) { free(test_curl_url); } | ||
if (test_curl_post_data) { free(test_curl_post_data); } | ||
if (test_curl_header) { free(test_curl_header); } | ||
} | ||
|
||
#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
Oops, something went wrong.