Browse Source

initial commit of test program for getline.h functions

master
T. Meissner 11 years ago
parent
commit
5477ad3b09
1 changed files with 54 additions and 0 deletions
  1. +54
    -0
      c_pointers/getline_test.c

+ 54
- 0
c_pointers/getline_test.c View File

@ -0,0 +1,54 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "minunit.h"
#include "getline.h"
#define STRING_LENGTH 14
int tests_run = 0;
// unit test function for trim()
static char *test_trim() {
char *foo = malloc(STRING_LENGTH + 1 * sizeof(*foo));
int wurst = snprintf(foo, STRING_LENGTH + 1, "%s", " hallo welt");
assertf(wurst <= STRING_LENGTH, "buffer overflow");
mu_assert("error", !(strcmp(trim(foo), "hallo welt")));
return 0;
}
// function to run all tests
static char *all_tests() {
mu_run_test(test_trim);
return 0;
}
int main(void) {
char *result = all_tests();
if (result != 0) {
printf("%s\n", result);
} else {
printf("ALL TESTS PASSED\n");
}
printf("Tests run: %d\n", tests_run);
return result != 0;
}

Loading…
Cancel
Save