Mercurial
annotate mrjunejune/test/integration_test.c @ 126:e7899c93da77
Remove playground.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Thu, 08 Jan 2026 18:03:34 -0800 |
| parents | 96628cf126a0 |
| children | 7eb79fd91c7e |
| rev | line source |
|---|---|
| 126 | 1 #include "seobeo/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 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
13 // Helper: Convert URL path to filename |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
14 // "/" -> "root.snapshot" |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
15 // "/index.html" -> "index.html.snapshot" |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
16 // "/api/users" -> "api_users.snapshot" |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
17 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
|
18 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
19 if (strcmp(path, "/") == 0) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
20 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
21 snprintf(filename, max_len, "root.snapshot"); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
22 return; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
23 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
24 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
25 // 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
|
26 const char *p = path; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
27 if (*p == '/') |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
28 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
29 p++; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
30 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
31 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
32 char *out = filename; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
33 size_t remaining = max_len - 1; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
34 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
35 while (*p && remaining > 0) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
36 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
37 if (*p == '/') |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
38 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
39 *out++ = '_'; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
40 remaining--; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
41 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
42 else |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
43 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
44 *out++ = *p; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
45 remaining--; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
46 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
47 p++; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
48 } |
|
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 // Add .snapshot extension |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
51 snprintf(out, remaining, ".snapshot"); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
52 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
53 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
54 // Helper: Read file contents into buffer |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
55 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
|
56 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
57 FILE *f = fopen(filepath, "rb"); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
58 if (!f) |
|
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 return NULL; |
|
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 fseek(f, 0, SEEK_END); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
64 long fsize = ftell(f); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
65 fseek(f, 0, SEEK_SET); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
66 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
67 char *buffer = malloc(fsize + 1); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
68 if (!buffer) |
|
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 fclose(f); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
71 return NULL; |
|
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 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
74 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
|
75 buffer[read_size] = '\0'; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
76 fclose(f); |
|
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 if (size_out) |
|
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 *size_out = read_size; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
81 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
82 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
83 return buffer; |
|
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 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
86 // 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
|
87 int load_expected_content(TestCase *test) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
88 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
89 if (!test->expected_file_path) |
|
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 -1; |
|
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 size_t size; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
95 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
|
96 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
97 if (!test->expected_content) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
98 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
99 return -1; |
|
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 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
102 return 0; |
|
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 |
| 126 | 105 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
|
106 { |
| 126 | 107 printf(" Testing: GET %s (expecting %d)\n", test->path, test->expected_status); |
| 108 | |
| 109 int32 max_url_length = 1024*3; | |
| 110 char *url = malloc(sizeof(char)*max_url_length); | |
| 111 snprintf(url, max_url_length, "%s%s", TEST_URL, test->path); | |
| 112 Seobeo_Client_Request *p_req = Seobeo_Client_Request_Create(url); | |
| 113 if (!p_req) | |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
114 { |
| 126 | 115 printf("Can't create requests"); |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
116 return -1; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
117 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
118 |
| 126 | 119 Seobeo_Client_Response *p_resp = Seobeo_Client_Request_Execute(p_req); |
| 120 if (!p_resp) | |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
121 { |
| 126 | 122 printf("No response"); |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
123 return -1; |
|
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 |
| 126 | 126 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
|
127 { |
| 126 | 128 printf(" ✗ Status mismatch: expected %d, got %d\n", |
| 129 test->expected_status, p_resp->status_code); | |
| 130 Seobeo_Client_Response_Destroy(p_resp); | |
| 131 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
|
132 return -1; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
133 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
134 |
| 126 | 135 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
|
136 |
| 126 | 137 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
|
138 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
139 if (!test->expected_content) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
140 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
141 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
|
142 printf(" → Run: bazel run //mrjunejune:create_snapshots\n"); |
| 126 | 143 Seobeo_Client_Response_Destroy(p_resp); |
| 144 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
|
145 return -1; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
146 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
147 |
| 126 | 148 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
|
149 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
150 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
|
151 printf(" Expected file: %s\n", test->expected_file_path); |
| 126 | 152 Seobeo_Client_Response_Destroy(p_resp); |
| 153 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
|
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 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
|
158 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
159 |
| 126 | 160 Seobeo_Client_Response_Destroy(p_resp); |
| 161 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
|
162 return 0; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
163 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
164 |
| 126 | 165 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
|
166 { |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
167 char request_buffer[8192]; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
168 int header_len = snprintf( |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
169 request_buffer, sizeof(request_buffer), |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
170 "POST %s HTTP/1.1\r\n" |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
171 "Host: %s\r\n" |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
172 "Content-Type: application/octet-stream\r\n" |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
173 "Content-Length: %zu\r\n" |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
174 "Connection: close\r\n" |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
175 "\r\n", |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
176 path, TEST_HOST, file_size |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
177 ); |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
178 |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
179 if (header_len < 0 || header_len >= sizeof(request_buffer)) |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
180 { |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
181 fprintf(stderr, "Request header too large\n"); |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
182 return -1; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
183 } |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
184 |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
185 // Send headers |
| 126 | 186 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
|
187 |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
188 // Send file data in chunks if needed |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
189 size_t remaining = file_size; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
190 const char *ptr = file_data; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
191 while (remaining > 0) |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
192 { |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
193 size_t chunk_size = remaining > 4096 ? 4096 : remaining; |
| 126 | 194 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
|
195 ptr += chunk_size; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
196 remaining -= chunk_size; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
197 } |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
198 |
| 126 | 199 return Seobeo_Handle_Flush(p_req); |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
200 } |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
201 |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
202 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
|
203 { |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
204 char search_pattern[256]; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
205 snprintf(search_pattern, sizeof(search_pattern), "\"%s\":\"", field); |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
206 |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
207 const char *start = strstr(json, search_pattern); |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
208 if (!start) |
|
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 return NULL; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
211 } |
|
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 start += strlen(search_pattern); |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
214 const char *end = strchr(start, '"'); |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
215 if (!end) |
|
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 return NULL; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
218 } |
|
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 size_t len = end - start; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
221 if (len >= buffer_size) |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
222 { |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
223 len = buffer_size - 1; |
|
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 |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
226 memcpy(buffer, start, len); |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
227 buffer[len] = '\0'; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
228 |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
229 return buffer; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
230 } |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
231 |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
232 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
|
233 const char *expected_format, pid_t server_pid) |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
234 { |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
235 printf(" Testing: POST %s\n", endpoint); |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
236 |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
237 // Read test file |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
238 size_t file_size; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
239 char *file_data = read_file(test_file_path, &file_size); |
| 126 | 240 if (!file_data) { |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
241 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
|
242 return -1; |
|
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 |
| 126 | 245 char url[1024]; |
| 246 snprintf(url, sizeof(url), "%s%s", TEST_URL, endpoint); | |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
247 |
| 126 | 248 Seobeo_Client_Request *p_req = Seobeo_Client_Request_Create(url); |
| 249 Seobeo_Client_Request_Set_Method(p_req, "POST"); | |
| 250 Seobeo_Client_Request_Set_Body(p_req, (uint8*)file_data, (uint32)file_size); | |
| 251 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
|
252 |
| 126 | 253 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
|
254 free(file_data); |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
255 |
| 126 | 256 if (!p_resp || p_resp->status_code != 200) { |
| 257 printf(" ✗ Conversion failed with status: %d\n", p_resp ? p_resp->status_code : 0); | |
| 258 if (p_resp) Seobeo_Client_Response_Destroy(p_resp); | |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
259 |
| 126 | 260 Seobeo_Client_Response_Destroy(p_resp); |
| 261 Seobeo_Client_Request_Destroy(p_req); | |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
262 return -1; |
|
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 |
| 126 | 265 // Extract download URL from JSON body |
| 266 char download_url_path[512]; | |
| 267 if (!extract_json_field((char*)p_resp->body, "download_url", download_url_path, sizeof(download_url_path))) { | |
| 268 printf(" ✗ Failed to extract download_url\n"); | |
| 269 Seobeo_Client_Response_Destroy(p_resp); | |
| 270 Seobeo_Client_Request_Destroy(p_req); | |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
271 return -1; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
272 } |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
273 |
| 126 | 274 printf(" ✓ Conversion succeeded. Download URL: %s\n", download_url_path); |
| 275 Seobeo_Client_Response_Destroy(p_resp); | |
| 276 Seobeo_Client_Request_Destroy(p_req); | |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
277 |
| 126 | 278 printf(" → Testing download: GET %s\n", download_url_path); |
| 279 char full_download_url[1024]; | |
| 280 snprintf(full_download_url, sizeof(full_download_url), "%s%s", TEST_URL, download_url_path); | |
| 281 | |
| 282 p_req = Seobeo_Client_Request_Create(full_download_url); | |
| 283 p_resp = Seobeo_Client_Request_Execute(p_req); | |
| 284 | |
| 285 if (!p_resp || p_resp->status_code != 200) | |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
286 { |
| 126 | 287 printf(" ✗ Download failed\n"); |
| 288 if (p_resp) Seobeo_Client_Response_Destroy(p_resp); | |
| 289 Seobeo_Client_Request_Destroy(p_req); | |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
290 return -1; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
291 } |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
292 |
| 126 | 293 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
|
294 |
| 126 | 295 Seobeo_Client_Response_Destroy(p_resp); |
| 296 Seobeo_Client_Request_Destroy(p_req); | |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
297 return 0; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
298 } |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
299 |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
300 pid_t start_test_server(const char *server_binary) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
301 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
302 pid_t server_pid = fork(); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
303 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
304 if (server_pid < 0) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
305 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
306 perror("fork"); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
307 return -1; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
308 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
309 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
310 if (server_pid == 0) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
311 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
312 printf("Starting server on port %s...\n", TEST_PORT); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
313 execl(server_binary, server_binary, NULL); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
314 perror("execl failed"); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
315 exit(1); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
316 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
317 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
318 printf("Server started (PID: %d)\n", server_pid); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
319 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
320 usleep(100000); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
321 int status; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
322 pid_t result = waitpid(server_pid, &status, WNOHANG); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
323 if (result != 0) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
324 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
325 if (WIFEXITED(status)) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
326 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
327 fprintf(stderr, "Server exited immediately with code: %d\n", WEXITSTATUS(status)); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
328 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
329 else if (WIFSIGNALED(status)) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
330 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
331 fprintf(stderr, "Server was killed by signal: %d\n", WTERMSIG(status)); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
332 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
333 return -1; |
|
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 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
336 sleep(2); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
337 printf("Server ready\n\n"); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
338 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
339 return server_pid; |
|
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 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
342 // Helper: Stop test server |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
343 void stop_test_server(pid_t server_pid) |
|
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 if (server_pid > 0) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
346 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
347 printf("\nStopping server (PID: %d)...\n", server_pid); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
348 kill(server_pid, SIGTERM); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
349 waitpid(server_pid, NULL, 0); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
350 printf("Server stopped\n"); |
|
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 } |
|
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 // 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
|
355 void init_test_case(TestCase *test) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
356 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
357 char filename[256]; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
358 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
|
359 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
360 test->expected_file_path = malloc(512); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
361 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
|
362 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
363 // Load expected content from snapshot file |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
364 load_expected_content(test); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
365 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
366 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
367 // Helper: Cleanup test case |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
368 void cleanup_test_case(TestCase *test) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
369 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
370 if (test->actual_response) |
|
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 free(test->actual_response); |
|
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 if (test->expected_file_path) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
375 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
376 free(test->expected_file_path); |
|
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 if (test->expected_content) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
379 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
380 free((void*)test->expected_content); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
381 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
382 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
383 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
384 // Main integration test |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
385 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
|
386 { |
| 126 | 387 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
|
388 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
|
389 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
390 char cwd[1024]; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
391 if (getcwd(cwd, sizeof(cwd)) != NULL) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
392 printf("Working directory: %s\n", cwd); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
393 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
394 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
|
395 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
396 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
|
397 perror("access"); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
398 return -1; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
399 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
400 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
|
401 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
|
402 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
403 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
|
404 if (server_pid < 0) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
405 return -1; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
406 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
407 int failed_tests = 0; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
408 int passed_tests = 0; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
409 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
410 TestCase success_tests[] = { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
411 {"/", 200, NULL, NULL, NULL, 0}, |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
412 {"/resume", 200, NULL, NULL, NULL, 0}, |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
413 {"/tools", 200, NULL, NULL, NULL, 0}, |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
414 {"/tools/markdown_to_html", 200, NULL, NULL, NULL, 0}, |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
415 {"/tools/file_converter", 200, NULL, NULL, NULL, 0}, |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
416 }; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
417 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
|
418 |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
419 TestCase redirect_tests[] = { |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
420 {"/index.html", 301, NULL, NULL, NULL, 0}, |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
421 {"/resume/index.html", 301, NULL, NULL, NULL, 0}, |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
422 {"/tools/index.html", 301, NULL, NULL, NULL, 0}, |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
423 {"/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
|
424 {"/tools/file_converter/index.html", 301, NULL, NULL, NULL, 0}, |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
425 }; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
426 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
|
427 |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
428 TestCase failure_tests[] = { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
429 {"/nonexistent", 404, NULL, NULL, NULL, 0}, |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
430 {"/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
|
431 {"/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
|
432 }; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
433 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
|
434 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
435 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
|
436 init_test_case(&success_tests[i]); |
| 126 | 437 |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
438 for (int i = 0; i < num_redirect_tests; i++) |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
439 init_test_case(&redirect_tests[i]); |
| 126 | 440 |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
441 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
|
442 init_test_case(&failure_tests[i]); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
443 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
444 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
|
445 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
|
446 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
447 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
|
448 passed_tests++; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
449 else |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
450 failed_tests++; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
451 } |
|
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 printf("\n"); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
454 |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
455 printf("Running tests for paths that should redirect:\n"); |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
456 for (int i = 0; i < num_redirect_tests; i++) |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
457 { |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
458 if (execute_test_case(&redirect_tests[i], server_pid) == 0) |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
459 passed_tests++; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
460 else |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
461 failed_tests++; |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
462 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
463 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
464 printf("\n"); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
465 |
| 126 | 466 printf("Running tests for paths that should fail:\n"); |
| 467 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
|
468 { |
| 126 | 469 if (execute_test_case(&failure_tests[i], server_pid) == 0) |
| 470 passed_tests++; | |
| 471 else | |
| 472 failed_tests++; | |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
473 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
474 |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
475 printf("\n"); |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
476 |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
477 printf("Running tests for POST conversion endpoints:\n"); |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
478 if (test_file_conversion("/api/convert/image-to-webp", |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
479 "mrjunejune/test/shiba.webp", |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
480 "image/webp", |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
481 server_pid) == 0) |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
482 passed_tests++; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
483 else |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
484 failed_tests++; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
485 |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
486 printf("\n"); |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
487 |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
488 if (test_file_conversion("/api/convert/video-to-mp4", |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
489 "mrjunejune/test/test_avi.avi", |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
490 "video/mp4", |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
491 server_pid) == 0) |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
492 passed_tests++; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
493 else |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
494 failed_tests++; |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
495 |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
496 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
|
497 cleanup_test_case(&success_tests[i]); |
|
94
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
498 for (int i = 0; i < num_redirect_tests; i++) |
|
092afa595764
[MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
499 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
|
500 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
|
501 cleanup_test_case(&failure_tests[i]); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
502 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
503 stop_test_server(server_pid); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
504 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
505 printf("\n=== Test Summary ===\n"); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
506 printf("Passed: %d\n", passed_tests); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
507 printf("Failed: %d\n", failed_tests); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
508 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
509 return (failed_tests == 0) ? 0 : -1; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
510 } |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
511 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
512 int main(int argc, char *argv[]) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
513 { |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
514 printf("=== Seobeo Integration Tests ===\n\n"); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
515 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
516 const char *server_binary = "./mrjunejune_server"; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
517 if (argc > 1) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
518 server_binary = argv[1]; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
519 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
520 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
|
521 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
522 if (result == 0) |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
523 printf("\n✓ All tests passed!\n"); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
524 else |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
525 printf("\n✗ Some tests failed\n"); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
526 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
527 return result; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
528 } |