url-parser.c

URL parsing library
git clone git://git.finwo.net/lib/url-parser.c
Log | Files | Refs | README | LICENSE

empty-host.test.c (1851B)


      1 #include "url-parser.h"
      2 #include "test.h"
      3 
      4 void test_tcp_empty_host_with_port() {
      5     struct parsed_url *purl = parse_url("tcp://:6379");
      6     ASSERT("tcp empty host with port", purl != NULL);
      7     ASSERT_STRING_EQUALS("tcp", purl->scheme);
      8     ASSERT_EQUALS(NULL, purl->host);
      9     ASSERT_STRING_EQUALS("6379", purl->port);
     10     ASSERT_STRING_EQUALS(NULL, purl->path);
     11     parsed_url_free(purl);
     12 }
     13 
     14 void test_redis_empty_host_with_port() {
     15     struct parsed_url *purl = parse_url("redis://:6379");
     16     ASSERT("redis empty host with port", purl != NULL);
     17     ASSERT_STRING_EQUALS("redis", purl->scheme);
     18     ASSERT_EQUALS(NULL, purl->host);
     19     ASSERT_STRING_EQUALS("6379", purl->port);
     20     parsed_url_free(purl);
     21 }
     22 
     23 void test_http_empty_host_with_port() {
     24     struct parsed_url *purl = parse_url("http://:8080");
     25     ASSERT("http empty host with port", purl != NULL);
     26     ASSERT_STRING_EQUALS("http", purl->scheme);
     27     ASSERT_EQUALS(NULL, purl->host);
     28     ASSERT_STRING_EQUALS("8080", purl->port);
     29     parsed_url_free(purl);
     30 }
     31 
     32 void test_empty_host_no_port() {
     33     struct parsed_url *purl = parse_url("tcp://:");
     34     ASSERT("tcp empty host no port", purl != NULL);
     35     ASSERT_STRING_EQUALS("tcp", purl->scheme);
     36     ASSERT_EQUALS(NULL, purl->host);
     37     ASSERT_STRING_EQUALS(NULL, purl->port);
     38     parsed_url_free(purl);
     39 }
     40 
     41 void test_empty_host_only_slashes() {
     42     struct parsed_url *purl = parse_url("tcp://");
     43     ASSERT("tcp only slashes", purl != NULL);
     44     ASSERT_STRING_EQUALS("tcp", purl->scheme);
     45     ASSERT_EQUALS(NULL, purl->host);
     46     ASSERT_STRING_EQUALS(NULL, purl->port);
     47     parsed_url_free(purl);
     48 }
     49 
     50 int main() {
     51     RUN(test_tcp_empty_host_with_port);
     52     RUN(test_redis_empty_host_with_port);
     53     RUN(test_http_empty_host_with_port);
     54     RUN(test_empty_host_no_port);
     55     RUN(test_empty_host_only_slashes);
     56     return TEST_REPORT();
     57 }