aboutsummaryrefslogtreecommitdiff
path: root/header.h
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-11-02 01:27:45 +0100
committerCharles <sircharlesaze@gmail.com>2019-11-02 01:27:45 +0100
commitfb41e23423854a865201c0803803191d1f65c8fa (patch)
tree515ba48b4bc97f1e7b550e46a4dbff6e5de12a92 /header.h
parent762ff2fcaf45d6b94fb580e168baf3f01ebd61e1 (diff)
downloadft_printf_test-fb41e23423854a865201c0803803191d1f65c8fa.tar.gz
ft_printf_test-fb41e23423854a865201c0803803191d1f65c8fa.tar.bz2
ft_printf_test-fb41e23423854a865201c0803803191d1f65c8fa.zip
Fixed false positive, basic prettier, more test from pft
Diffstat (limited to 'header.h')
-rw-r--r--header.h96
1 files changed, 47 insertions, 49 deletions
diff --git a/header.h b/header.h
index 31bfa81..e002077 100644
--- a/header.h
+++ b/header.h
@@ -8,12 +8,12 @@
# include <string.h>
# include <stdbool.h>
-# define BUF_SIZE 2048
+# define BUF_SIZE 2048 * 10
int pid;
bool signaled;
-bool origin_signaled;
-bool user_signaled;
+static bool origin_signaled = false;
+static bool user_signaled = false;
int origin_ret;
int user_ret;
char *origin_buf;
@@ -27,55 +27,53 @@ void print_signaled_ko(char *msg);
void print_ok(void);
void print_ko(void);
-/* moulitest functions */
-void capture_close_saved_stdout(void);
-void capture_stdout(void);
-char *capture_stdout_get_buf(void);
-void capture_stdout_destroy(void);
+void test_setup(void);
+void test_tear_down(void);
+char *read_stdout_buf(void);
-# define TEST_SEGFAULT(x) do { \
- if ((pid = fork()) < 0) \
- exit(EXIT_FAILURE); \
- if (pid == 0) { \
- do { x } while(0); \
- exit(EXIT_SUCCESS); \
- } \
- wait(&pid); \
- signaled = WIFSIGNALED(pid); \
+# define TEST_SEGFAULT(x) do { \
+ if ((pid = fork()) < 0) \
+ exit(EXIT_FAILURE); \
+ if (pid == 0) { \
+ do { x } while(0); \
+ exit(EXIT_SUCCESS); \
+ } else { \
+ wait(&pid); \
+ signaled = WIFSIGNALED(pid); \
+ } \
} while(0);
-# define TEST_PRINTF(...) do { \
- capture_stdout(); \
- TEST_SEGFAULT( \
- origin_ret = printf(__VA_ARGS__); \
- origin_buf = strdup(capture_stdout_get_buf()); \
- ); \
- origin_signaled = signaled; \
- TEST_SEGFAULT( \
- user_ret = ft_printf(__VA_ARGS__); \
- user_buf = strdup(capture_stdout_get_buf()); \
- ); \
- capture_stdout_destroy(); \
- user_signaled = signaled; \
-} while (0);
+# define TEST_PRINTF(...) do { \
+ test_setup(); \
+ TEST_SEGFAULT(\
+ origin_ret = printf(__VA_ARGS__); \
+ );\
+ origin_buf = strdup(read_stdout_buf()); \
+ origin_signaled = signaled; \
+ TEST_SEGFAULT(\
+ user_ret = ft_printf(__VA_ARGS__); \
+ );\
+ user_buf = strdup(read_stdout_buf()); \
+ user_signaled = signaled; \
+ test_tear_down(); \
+} while (0)
-# define ASSERT_PRINTF(...) do { \
- TEST_PRINTF(__VA_ARGS__); \
- if (!origin_signaled) \
- if (user_signaled) \
- print_signaled_ko(#__VA_ARGS__); \
- else \
- print_ok(); \
- else { \
- if (strcmp(origin_buf, user_buf) != 0) \
- print_buf_ko(#__VA_ARGS__); \
- else if (origin_ret != user_ret) \
- print_ret_ko(#__VA_ARGS__); \
- else \
- print_ko(); \
- } \
- free(origin_buf); \
- free(user_buf); \
-} while (0);
+# define ASSERT_PRINTF(...) do { \
+ TEST_PRINTF(__VA_ARGS__); \
+ if (!origin_signaled && user_signaled) \
+ print_signaled_ko(#__VA_ARGS__); \
+ else if (origin_signaled && user_signaled) \
+ print_ok(); \
+ else if (!origin_signaled && !user_signaled) { \
+ if (strcmp(origin_buf, user_buf) != 0) \
+ print_buf_ko(#__VA_ARGS__); \
+ else if (origin_ret != user_ret) \
+ print_ret_ko(#__VA_ARGS__); \
+ else \
+ print_ok(); \
+ } \
+ if (!origin_signaled) free(origin_buf); \
+ if (!user_signaled) free(user_buf); \
+} while(0);
#endif