| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#include <stdlib.h> |
| 24 |
|
| 25 |
#include "testutils.h" |
| 26 |
#include "url_encode.h" |
| 27 |
|
| 28 |
#define NPL_TESTING |
| 29 |
|
| 30 |
#include "../lib/url_encode.c" |
| 31 |
|
| 32 |
typedef struct test_data |
| 33 |
{ |
| 34 |
char * url; |
| 35 |
char * expect_value; |
| 36 |
} test_data; |
| 37 |
|
| 38 |
static int |
| 39 |
test_url_encoding (const void *tdata) |
| 40 |
{ |
| 41 |
const struct test_data *data = tdata; |
| 42 |
int ret = 0; |
| 43 |
char *encoded_url = url_encode (data->url); |
| 44 |
|
| 45 |
TEST_ASSERT_EQUAL_STRING (encoded_url, data->expect_value); |
| 46 |
free (encoded_url); |
| 47 |
return ret; |
| 48 |
} |
| 49 |
|
| 50 |
static int |
| 51 |
mymain (void) |
| 52 |
{ |
| 53 |
int ret = 0; |
| 54 |
|
| 55 |
#define DO_TEST(URL, EXPECT_VALUE) \ |
| 56 |
do \ |
| 57 |
{ \ |
| 58 |
test_data data = { \ |
| 59 |
.url = URL, \ |
| 60 |
.expect_value = EXPECT_VALUE, \ |
| 61 |
}; \ |
| 62 |
if (test_run("check url encoding for " URL, \ |
| 63 |
test_url_encoding, (&data)) < 0) \ |
| 64 |
ret = -1; \ |
| 65 |
} \ |
| 66 |
while (0) |
| 67 |
|
| 68 |
DO_TEST ("?test=true", "%3ftest%3dtrue"); |
| 69 |
DO_TEST ("?test=true&debug=false", "%3ftest%3dtrue%26debug%3dfalse"); |
| 70 |
DO_TEST ("{\"status\":{\"running\":true}}", |
| 71 |
"%7b%22status%22%3a%7b%22running%22%3atrue%7d%7d"); |
| 72 |
|
| 73 |
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; |
| 74 |
} |
| 75 |
|
| 76 |
TEST_MAIN (mymain); |