diff options
author | Nicolas Noble <nicolasnoble@users.noreply.github.com> | 2016-03-31 17:08:17 -0700 |
---|---|---|
committer | Nicolas Noble <nicolasnoble@users.noreply.github.com> | 2016-03-31 17:08:17 -0700 |
commit | 38d812077be28f9837a5bf3ffd42a86396cb9d98 (patch) | |
tree | 50a648b662e55d1c6b4e67cf9c21fa8227403fa2 /test/core | |
parent | 6a362747571b6a47c3a84c8e2df25814230a53a7 (diff) | |
parent | f341374f6f903fff231df71298c30a4a973ea792 (diff) |
Merge pull request #6034 from dgquintas/uri_query_parts
Added & and = to URI queries
Diffstat (limited to 'test/core')
-rw-r--r-- | test/core/client_config/uri_parser_test.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/test/core/client_config/uri_parser_test.c b/test/core/client_config/uri_parser_test.c index e5d0c378ba..37b82aeded 100644 --- a/test/core/client_config/uri_parser_test.c +++ b/test/core/client_config/uri_parser_test.c @@ -56,6 +56,56 @@ static void test_fails(const char *uri_text) { GPR_ASSERT(NULL == grpc_uri_parse(uri_text, 0)); } +static void test_query_parts() { + { + const char *uri_text = "http://foo/path?a&b=B&c=&#frag"; + grpc_uri *uri = grpc_uri_parse(uri_text, 0); + GPR_ASSERT(uri); + + GPR_ASSERT(0 == strcmp("http", uri->scheme)); + GPR_ASSERT(0 == strcmp("foo", uri->authority)); + GPR_ASSERT(0 == strcmp("/path", uri->path)); + GPR_ASSERT(0 == strcmp("a&b=B&c=&", uri->query)); + GPR_ASSERT(4 == uri->num_query_parts); + + GPR_ASSERT(0 == strcmp("a", uri->query_parts[0])); + GPR_ASSERT(NULL == uri->query_parts_values[0]); + + GPR_ASSERT(0 == strcmp("b", uri->query_parts[1])); + GPR_ASSERT(0 == strcmp("B", uri->query_parts_values[1])); + + GPR_ASSERT(0 == strcmp("c", uri->query_parts[2])); + GPR_ASSERT(0 == strcmp("", uri->query_parts_values[2])); + + GPR_ASSERT(0 == strcmp("", uri->query_parts[3])); + GPR_ASSERT(NULL == uri->query_parts_values[3]); + + GPR_ASSERT(NULL == grpc_uri_get_query_arg(uri, "a")); + GPR_ASSERT(0 == strcmp("B", grpc_uri_get_query_arg(uri, "b"))); + GPR_ASSERT(0 == strcmp("", grpc_uri_get_query_arg(uri, "c"))); + GPR_ASSERT(NULL == grpc_uri_get_query_arg(uri, "")); + + GPR_ASSERT(0 == strcmp("frag", uri->fragment)); + grpc_uri_destroy(uri); + } + { + /* empty query */ + const char *uri_text = "http://foo/path"; + grpc_uri *uri = grpc_uri_parse(uri_text, 0); + GPR_ASSERT(uri); + + GPR_ASSERT(0 == strcmp("http", uri->scheme)); + GPR_ASSERT(0 == strcmp("foo", uri->authority)); + GPR_ASSERT(0 == strcmp("/path", uri->path)); + GPR_ASSERT(0 == strcmp("", uri->query)); + GPR_ASSERT(0 == uri->num_query_parts); + GPR_ASSERT(NULL == uri->query_parts); + GPR_ASSERT(NULL == uri->query_parts_values); + GPR_ASSERT(0 == strcmp("", uri->fragment)); + grpc_uri_destroy(uri); + } +} + int main(int argc, char **argv) { grpc_test_init(argc, argv); test_succeeds("http://www.google.com", "http", "www.google.com", "", "", ""); @@ -82,5 +132,6 @@ int main(int argc, char **argv) { test_fails("http://foo?x[bar]"); test_fails("http://foo?bar#lol#"); + test_query_parts(); return 0; } |