GenSVM
test_gensvm_print.c
Go to the documentation of this file.
1 
27 #include "minunit.h"
28 #include "gensvm_print.h"
29 
30 extern FILE *GENSVM_OUTPUT_FILE;
31 extern FILE *GENSVM_ERROR_FILE;
32 
33 char *test_note()
34 {
35  FILE *fid = NULL;
36  GENSVM_OUTPUT_FILE = fopen("./data/test_note_print.txt", "w");
37 
38  // start test code //
39  note("This is some text.\n");
40  note("This is %s with %.2f.\n", "formatted text", 1.231234);
41 
42  // close the output stream
43  fclose(GENSVM_OUTPUT_FILE);
44  GENSVM_OUTPUT_FILE = NULL;
45 
46  note("This is some more text.\n");
47  note("This shouldn't appear in the output file.\n");
48 
49  char buffer[GENSVM_MAX_LINE_LENGTH];
50  fid = fopen("./data/test_note_print.txt", "r");
51 
52  fgets(buffer, GENSVM_MAX_LINE_LENGTH, fid);
53  mu_assert(strcmp(buffer, "This is some text.\n") == 0,
54  "Line doesn't contain expected content (1)");
55 
56  fgets(buffer, GENSVM_MAX_LINE_LENGTH, fid);
57  mu_assert(strcmp(buffer, "This is formatted text with 1.23.\n") == 0,
58  "Line doesn't contain expected content (2)");
59 
60  fclose(fid);
61 
62  // end test code //
63 
64  return NULL;
65 }
66 
67 char *test_err()
68 {
69  FILE *fid = NULL;
70  GENSVM_ERROR_FILE = fopen("./data/test_err_print.txt", "w");
71 
72  // start test code //
73  err("This is some text.\n");
74  err("This is %s with %.2f.\n", "formatted text", 1.231234);
75 
76  // close the output stream
77  fclose(GENSVM_ERROR_FILE);
78  GENSVM_ERROR_FILE = NULL;
79 
80  err("This is some more text.\n");
81  err("This shouldn't appear in the output file.\n");
82 
83  char buffer[GENSVM_MAX_LINE_LENGTH];
84  fid = fopen("./data/test_err_print.txt", "r");
85 
86  fgets(buffer, GENSVM_MAX_LINE_LENGTH, fid);
87  mu_assert(strcmp(buffer, "This is some text.\n") == 0,
88  "Line doesn't contain expected content (1)");
89 
90  fgets(buffer, GENSVM_MAX_LINE_LENGTH, fid);
91  mu_assert(strcmp(buffer, "This is formatted text with 1.23.\n") == 0,
92  "Line doesn't contain expected content (2)");
93 
94  fclose(fid);
95 
96  // end test code //
97  return NULL;
98 }
99 
100 char *all_tests()
101 {
102  mu_suite_start();
105 
106  return NULL;
107 }
108 
Minimal unit testing framework for C.
RUN_TESTS(all_tests)
void err(const char *fmt,...)
Parse a formatted string and write it to standard error.
Definition: gensvm_print.c:84
#define mu_assert(test, message)
Definition: minunit.h:29
#define GENSVM_MAX_LINE_LENGTH
char * all_tests()
#define mu_run_test(test)
Definition: minunit.h:35
FILE * GENSVM_ERROR_FILE
Definition: gensvm_print.c:43
char * test_err()
FILE * GENSVM_OUTPUT_FILE
Definition: gensvm_print.c:33
char * test_note()
#define mu_suite_start()
Definition: minunit.h:24
Header file for gensvm_print.c.
void note(const char *fmt,...)
Parse a formatted string and write to the output stream.
Definition: gensvm_print.c:62