Mercurial
annotate mrjunejune/test/integration_test.c @ 156:cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Mon, 12 Jan 2026 15:20:39 -0800 |
| parents | 7eb79fd91c7e |
| children | f3084bca7317 |
| rev | line source |
|---|---|
|
128
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
126
diff
changeset
|
1 #include "mrjunejune/test/test.h" |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
2 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
3 // Test case structure |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
4 typedef struct { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
5 const char *path; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
6 int expected_status; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
7 const char *expected_content; // Loaded from file |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
8 char *expected_file_path; // Path to expected snapshot file |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
9 char *actual_response; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
10 size_t response_len; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
11 } TestCase; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
12 |
|
128
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
126
diff
changeset
|
13 void debug_diff(const char *expected, const char *actual) |
|
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
126
diff
changeset
|
14 { |
|
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
126
diff
changeset
|
15 printf("\n--- DIFF (Expected vs Actual) ---\n"); |
|
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
126
diff
changeset
|
16 |
|
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
126
diff
changeset
|
17 // Create copies to use with strtok (strtok modifies the string) |
|
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
126
diff
changeset
|
18 char *exp_copy = strdup(expected); |
|
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
126
diff
changeset
|
19 char *act_copy = strdup(actual); |
|
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
126
diff
changeset
|
20 |
|
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
126
diff
changeset
|
21 char *exp_line = strtok(exp_copy, "\n"); |
|
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
126
diff
changeset
|
22 char *act_line = strtok(act_copy, "\n"); |
|
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
126
diff
changeset
|
23 |
|
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
126
diff
changeset
|
24 int line_num = 1; |
|
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
126
diff
changeset
|
25 while (exp_line != NULL || act_line != NULL) { |
|
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
126
diff
changeset
|
26 if (exp_line && act_line && strcmp(exp_line, act_line) == 0) { |
|
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
126
diff
changeset
|
27 // Lines match - optional: print nothing or a dot |
|
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
126
diff
changeset
|
28 } else { |
|
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
126
diff
changeset
|
29 printf("Line %d mismatch:\n", line_num); |
|
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
126
diff
changeset
|
30 printf(" EXP: [%s]\n", exp_line ? exp_line : "(end of string)"); |
|
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
126
diff
changeset
|
31 printf(" ACT: [%s]\n", act_line ? act_line : "(end of string)"); |
|
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
126
diff
changeset
|
32 printf(" -----------------------------------\n"); |
|
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
126
diff
changeset
|
33 } |
|
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
126
diff
changeset
|
34 |
|
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
126
diff
changeset
|
35 exp_line = strtok(NULL, "\n"); |
|
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
126
diff
changeset
|
36 act_line = strtok(NULL, "\n"); |
|
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
126
diff
changeset
|
37 line_num++; |
|
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
126
diff
changeset
|
38 } |
|
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
126
diff
changeset
|
39 |
|
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
126
diff
changeset
|
40 free(exp_copy); |
|
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
126
diff
changeset
|
41 free(act_copy); |
|
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
126
diff
changeset
|
42 } |
|
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
126
diff
changeset
|
43 |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
44 // Helper: Convert URL path to filename |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
45 // "/" -> "root.snapshot" |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
46 // "/index.html" -> "index.html.snapshot" |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
47 // "/api/users" -> "api_users.snapshot" |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
48 void path_to_filename(const char *path, char *filename, size_t max_len) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
49 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
50 if (strcmp(path, "/") == 0) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
51 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
52 snprintf(filename, max_len, "root.snapshot"); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
53 return; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
54 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
55 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
56 // Remove leading slash and convert remaining slashes to underscores |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
57 const char *p = path; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
58 if (*p == '/') |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
59 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
60 p++; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
61 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
62 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
63 char *out = filename; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
64 size_t remaining = max_len - 1; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
65 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
66 while (*p && remaining > 0) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
67 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
68 if (*p == '/') |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
69 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
70 *out++ = '_'; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
71 remaining--; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
72 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
73 else |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
74 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
75 *out++ = *p; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
76 remaining--; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
77 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
78 p++; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
79 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
80 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
81 // Add .snapshot extension |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
82 snprintf(out, remaining, ".snapshot"); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
83 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
84 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
85 // Helper: Read file contents into buffer |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
86 char* read_file(const char *filepath, size_t *size_out) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
87 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
88 FILE *f = fopen(filepath, "rb"); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
89 if (!f) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
90 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
91 return NULL; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
92 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
93 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
94 fseek(f, 0, SEEK_END); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
95 long fsize = ftell(f); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
96 fseek(f, 0, SEEK_SET); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
97 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
98 char *buffer = malloc(fsize + 1); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
99 if (!buffer) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
100 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
101 fclose(f); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
102 return NULL; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
103 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
104 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
105 size_t read_size = fread(buffer, 1, fsize, f); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
106 buffer[read_size] = '\0'; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
107 fclose(f); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
108 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
109 if (size_out) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
110 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
111 *size_out = read_size; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
112 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
113 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
114 return buffer; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
115 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
116 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
117 // Helper: Load expected content for a test case |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
118 int load_expected_content(TestCase *test) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
119 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
120 if (!test->expected_file_path) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
121 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
122 return -1; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
123 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
124 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
125 size_t size; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
126 test->expected_content = read_file(test->expected_file_path, &size); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
127 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
128 if (!test->expected_content) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
129 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
130 return -1; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
131 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
132 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
133 return 0; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
134 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
135 |
| 126 | 136 int execute_test_case(TestCase *test, pid_t server_pid) |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
137 { |
| 126 | 138 printf(" Testing: GET %s (expecting %d)\n", test->path, test->expected_status); |
| 139 | |
| 140 int32 max_url_length = 1024*3; | |
| 141 char *url = malloc(sizeof(char)*max_url_length); | |
| 142 snprintf(url, max_url_length, "%s%s", TEST_URL, test->path); | |
| 143 Seobeo_Client_Request *p_req = Seobeo_Client_Request_Create(url); | |
| 144 if (!p_req) | |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
145 { |
| 126 | 146 printf("Can't create requests"); |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
147 return -1; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
148 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
149 |
| 126 | 150 Seobeo_Client_Response *p_resp = Seobeo_Client_Request_Execute(p_req); |
| 151 if (!p_resp) | |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
152 { |
| 126 | 153 printf("No response"); |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
154 return -1; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
155 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
156 |
| 126 | 157 if (p_resp->status_code != test->expected_status) |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
158 { |
| 126 | 159 printf(" ✗ Status mismatch: expected %d, got %d\n", |
| 160 test->expected_status, p_resp->status_code); | |
| 161 Seobeo_Client_Response_Destroy(p_resp); | |
| 162 Seobeo_Client_Request_Destroy(p_req); | |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
163 return -1; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
164 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
165 |
| 126 | 166 printf(" ✓ Status code: %d\n", p_resp->status_code); |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
167 |
| 126 | 168 if (p_resp->status_code == 200) |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
169 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
170 if (!test->expected_content) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
171 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
172 printf(" ✗ No expected snapshot found: %s\n", test->expected_file_path); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
173 printf(" → Run: bazel run //mrjunejune:create_snapshots\n"); |
| 126 | 174 Seobeo_Client_Response_Destroy(p_resp); |
| 175 Seobeo_Client_Request_Destroy(p_req); | |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
176 return -1; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
177 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
178 |
| 126 | 179 if (strcmp(p_resp->body, test->expected_content) != 0) |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
180 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
181 printf(" ✗ Response does not match expected snapshot\n"); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
182 printf(" Expected file: %s\n", test->expected_file_path); |
|
128
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
126
diff
changeset
|
183 debug_diff(p_resp->body, test->expected_content); |
| 126 | 184 Seobeo_Client_Response_Destroy(p_resp); |
| 185 Seobeo_Client_Request_Destroy(p_req); | |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
186 return -1; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
187 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
188 |
| 126 | 189 printf(" ✓ Response matches snapshot (%zu bytes)\n", p_resp->body_length); |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
190 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
191 |
| 126 | 192 Seobeo_Client_Response_Destroy(p_resp); |
| 193 Seobeo_Client_Request_Destroy(p_req); | |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
194 return 0; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
195 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
196 |
| 126 | 197 int send_post_file(Seobeo_Handle *p_req, const char *path, const char *file_data, size_t file_size) |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
198 { |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
199 char request_buffer[8192]; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
200 int header_len = snprintf( |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
201 request_buffer, sizeof(request_buffer), |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
202 "POST %s HTTP/1.1\r\n" |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
203 "Host: %s\r\n" |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
204 "Content-Type: application/octet-stream\r\n" |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
205 "Content-Length: %zu\r\n" |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
206 "Connection: close\r\n" |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
207 "\r\n", |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
208 path, TEST_HOST, file_size |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
209 ); |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
210 |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
211 if (header_len < 0 || header_len >= sizeof(request_buffer)) |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
212 { |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
213 fprintf(stderr, "Request header too large\n"); |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
214 return -1; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
215 } |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
216 |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
217 // Send headers |
| 126 | 218 Seobeo_Handle_Queue(p_req, (uint8*)request_buffer, (uint32)header_len); |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
219 |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
220 // Send file data in chunks if needed |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
221 size_t remaining = file_size; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
222 const char *ptr = file_data; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
223 while (remaining > 0) |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
224 { |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
225 size_t chunk_size = remaining > 4096 ? 4096 : remaining; |
| 126 | 226 Seobeo_Handle_Queue(p_req, (uint8*)ptr, (uint32)chunk_size); |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
227 ptr += chunk_size; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
228 remaining -= chunk_size; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
229 } |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
230 |
| 126 | 231 return Seobeo_Handle_Flush(p_req); |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
232 } |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
233 |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
234 char* extract_json_field(const char *json, const char *field, char *buffer, size_t buffer_size) |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
235 { |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
236 char search_pattern[256]; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
237 snprintf(search_pattern, sizeof(search_pattern), "\"%s\":\"", field); |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
238 |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
239 const char *start = strstr(json, search_pattern); |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
240 if (!start) |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
241 { |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
242 return NULL; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
243 } |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
244 |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
245 start += strlen(search_pattern); |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
246 const char *end = strchr(start, '"'); |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
247 if (!end) |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
248 { |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
249 return NULL; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
250 } |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
251 |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
252 size_t len = end - start; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
253 if (len >= buffer_size) |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
254 { |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
255 len = buffer_size - 1; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
256 } |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
257 |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
258 memcpy(buffer, start, len); |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
259 buffer[len] = '\0'; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
260 |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
261 return buffer; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
262 } |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
263 |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
264 int test_file_conversion(const char *endpoint, const char *test_file_path, |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
265 const char *expected_format, pid_t server_pid) |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
266 { |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
267 printf(" Testing: POST %s\n", endpoint); |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
268 |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
269 // Read test file |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
270 size_t file_size; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
271 char *file_data = read_file(test_file_path, &file_size); |
| 126 | 272 if (!file_data) { |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
273 printf(" ✗ Failed to read test file: %s\n", test_file_path); |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
274 return -1; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
275 } |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
276 |
| 126 | 277 char url[1024]; |
| 278 snprintf(url, sizeof(url), "%s%s", TEST_URL, endpoint); | |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
279 |
| 126 | 280 Seobeo_Client_Request *p_req = Seobeo_Client_Request_Create(url); |
| 281 Seobeo_Client_Request_Set_Method(p_req, "POST"); | |
| 282 Seobeo_Client_Request_Set_Body(p_req, (uint8*)file_data, (uint32)file_size); | |
| 283 Seobeo_Client_Request_Add_Header_Array(p_req, "Content-Type: application/octet-stream"); | |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
284 |
| 126 | 285 Seobeo_Client_Response *p_resp = Seobeo_Client_Request_Execute(p_req); |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
286 free(file_data); |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
287 |
| 126 | 288 if (!p_resp || p_resp->status_code != 200) { |
| 289 printf(" ✗ Conversion failed with status: %d\n", p_resp ? p_resp->status_code : 0); | |
| 290 if (p_resp) Seobeo_Client_Response_Destroy(p_resp); | |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
291 |
| 126 | 292 Seobeo_Client_Response_Destroy(p_resp); |
| 293 Seobeo_Client_Request_Destroy(p_req); | |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
294 return -1; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
295 } |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
296 |
| 126 | 297 // Extract download URL from JSON body |
| 298 char download_url_path[512]; | |
| 299 if (!extract_json_field((char*)p_resp->body, "download_url", download_url_path, sizeof(download_url_path))) { | |
| 300 printf(" ✗ Failed to extract download_url\n"); | |
| 301 Seobeo_Client_Response_Destroy(p_resp); | |
| 302 Seobeo_Client_Request_Destroy(p_req); | |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
303 return -1; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
304 } |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
305 |
| 126 | 306 printf(" ✓ Conversion succeeded. Download URL: %s\n", download_url_path); |
| 307 Seobeo_Client_Response_Destroy(p_resp); | |
| 308 Seobeo_Client_Request_Destroy(p_req); | |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
309 |
| 126 | 310 printf(" → Testing download: GET %s\n", download_url_path); |
| 311 char full_download_url[1024]; | |
| 312 snprintf(full_download_url, sizeof(full_download_url), "%s%s", TEST_URL, download_url_path); | |
| 313 | |
| 314 p_req = Seobeo_Client_Request_Create(full_download_url); | |
| 315 p_resp = Seobeo_Client_Request_Execute(p_req); | |
| 316 | |
| 317 if (!p_resp || p_resp->status_code != 200) | |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
318 { |
| 126 | 319 printf(" ✗ Download failed\n"); |
| 320 if (p_resp) Seobeo_Client_Response_Destroy(p_resp); | |
| 321 Seobeo_Client_Request_Destroy(p_req); | |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
322 return -1; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
323 } |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
324 |
| 126 | 325 printf(" ✓ Downloaded converted file (%u bytes)\n", p_resp->body_length); |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
326 |
| 126 | 327 Seobeo_Client_Response_Destroy(p_resp); |
| 328 Seobeo_Client_Request_Destroy(p_req); | |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
329 return 0; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
330 } |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
331 |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
332 // Helper: Initialize test case with snapshot file |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
333 void init_test_case(TestCase *test) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
334 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
335 char filename[256]; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
336 path_to_filename(test->path, filename, sizeof(filename)); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
337 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
338 test->expected_file_path = malloc(512); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
339 snprintf(test->expected_file_path, 512, "%s/%s", SNAPSHOT_DIR, filename); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
340 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
341 // Load expected content from snapshot file |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
342 load_expected_content(test); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
343 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
344 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
345 // Helper: Cleanup test case |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
346 void cleanup_test_case(TestCase *test) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
347 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
348 if (test->actual_response) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
349 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
350 free(test->actual_response); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
351 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
352 if (test->expected_file_path) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
353 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
354 free(test->expected_file_path); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
355 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
356 if (test->expected_content) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
357 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
358 free((void*)test->expected_content); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
359 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
360 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
361 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
362 // Main integration test |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
363 int test_server_client_integration(const char *server_binary) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
364 { |
| 126 | 365 printf("=== Server-p_req Integration Test ===\n"); |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
366 printf("MODE: Verifying Against Snapshots\n\n"); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
367 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
368 char cwd[1024]; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
369 if (getcwd(cwd, sizeof(cwd)) != NULL) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
370 printf("Working directory: %s\n", cwd); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
371 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
372 if (access(server_binary, X_OK) != 0) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
373 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
374 printf("Server binary not found: %s\n", server_binary); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
375 perror("access"); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
376 return -1; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
377 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
378 printf("Server binary: %s\n", server_binary); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
379 printf("Snapshot directory: %s\n\n", SNAPSHOT_DIR); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
380 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
381 pid_t server_pid = start_test_server(server_binary); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
382 if (server_pid < 0) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
383 return -1; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
384 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
385 int failed_tests = 0; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
386 int passed_tests = 0; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
387 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
388 TestCase success_tests[] = { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
389 {"/", 200, NULL, NULL, NULL, 0}, |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
390 {"/resume", 200, NULL, NULL, NULL, 0}, |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
391 {"/tools", 200, NULL, NULL, NULL, 0}, |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
392 {"/tools/markdown_to_html", 200, NULL, NULL, NULL, 0}, |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
393 {"/tools/file_converter", 200, NULL, NULL, NULL, 0}, |
|
128
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
126
diff
changeset
|
394 {"/talk", 200, NULL, NULL, NULL, 0}, |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
395 }; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
396 int num_success_tests = sizeof(success_tests) / sizeof(success_tests[0]); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
397 |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
398 TestCase redirect_tests[] = { |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
399 {"/index.html", 301, NULL, NULL, NULL, 0}, |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
400 {"/resume/index.html", 301, NULL, NULL, NULL, 0}, |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
401 {"/tools/index.html", 301, NULL, NULL, NULL, 0}, |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
402 {"/tools/markdown_to_html/index.html", 301, NULL, NULL, NULL, 0}, |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
403 {"/tools/file_converter/index.html", 301, NULL, NULL, NULL, 0}, |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
404 }; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
405 int num_redirect_tests = sizeof(redirect_tests) / sizeof(redirect_tests[0]); |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
406 |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
407 TestCase failure_tests[] = { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
408 {"/nonexistent", 404, NULL, NULL, NULL, 0}, |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
409 {"/does/not/exist", 404, NULL, NULL, NULL, 0}, |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
410 {"/missing.html", 404, NULL, NULL, NULL, 0}, |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
411 }; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
412 int num_failure_tests = sizeof(failure_tests) / sizeof(failure_tests[0]); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
413 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
414 for (int i = 0; i < num_success_tests; i++) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
415 init_test_case(&success_tests[i]); |
| 126 | 416 |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
417 for (int i = 0; i < num_redirect_tests; i++) |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
418 init_test_case(&redirect_tests[i]); |
| 126 | 419 |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
420 for (int i = 0; i < num_failure_tests; i++) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
421 init_test_case(&failure_tests[i]); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
422 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
423 printf("Running tests for paths that should succeed:\n"); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
424 for (int i = 0; i < num_success_tests; i++) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
425 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
426 if (execute_test_case(&success_tests[i], server_pid) == 0) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
427 passed_tests++; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
428 else |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
429 failed_tests++; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
430 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
431 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
432 printf("\n"); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
433 |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
434 printf("Running tests for paths that should redirect:\n"); |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
435 for (int i = 0; i < num_redirect_tests; i++) |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
436 { |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
437 if (execute_test_case(&redirect_tests[i], server_pid) == 0) |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
438 passed_tests++; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
439 else |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
440 failed_tests++; |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
441 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
442 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
443 printf("\n"); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
444 |
| 126 | 445 printf("Running tests for paths that should fail:\n"); |
| 446 for (int i = 0; i < num_failure_tests; i++) | |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
447 { |
| 126 | 448 if (execute_test_case(&failure_tests[i], server_pid) == 0) |
| 449 passed_tests++; | |
| 450 else | |
| 451 failed_tests++; | |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
452 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
453 |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
454 printf("\n"); |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
455 |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
456 printf("Running tests for POST conversion endpoints:\n"); |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
457 if (test_file_conversion("/api/convert/image-to-webp", |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
458 "mrjunejune/test/shiba.webp", |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
459 "image/webp", |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
460 server_pid) == 0) |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
461 passed_tests++; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
462 else |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
463 failed_tests++; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
464 |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
465 printf("\n"); |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
466 |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
467 if (test_file_conversion("/api/convert/video-to-mp4", |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
468 "mrjunejune/test/test_avi.avi", |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
469 "video/mp4", |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
470 server_pid) == 0) |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
471 passed_tests++; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
472 else |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
473 failed_tests++; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
474 |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
475 for (int i = 0; i < num_success_tests; i++) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
476 cleanup_test_case(&success_tests[i]); |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
477 for (int i = 0; i < num_redirect_tests; i++) |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
478 cleanup_test_case(&redirect_tests[i]); |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
479 for (int i = 0; i < num_failure_tests; i++) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
480 cleanup_test_case(&failure_tests[i]); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
481 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
482 stop_test_server(server_pid); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
483 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
484 printf("\n=== Test Summary ===\n"); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
485 printf("Passed: %d\n", passed_tests); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
486 printf("Failed: %d\n", failed_tests); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
487 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
488 return (failed_tests == 0) ? 0 : -1; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
489 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
490 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
491 int main(int argc, char *argv[]) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
492 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
493 printf("=== Seobeo Integration Tests ===\n\n"); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
494 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
495 const char *server_binary = "./mrjunejune_server"; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
496 if (argc > 1) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
497 server_binary = argv[1]; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
498 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
499 int result = test_server_client_integration(server_binary); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
500 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
501 if (result == 0) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
502 printf("\n✓ All tests passed!\n"); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
503 else |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
504 printf("\n✗ Some tests failed\n"); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
505 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
506 return result; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
507 } |