Hash :
3ba01362
Author :
Date :
2013-03-20T11:46:03
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
#include "clar_libgit2.h"
#include "netops.h"
char *host, *port, *user, *pass;
void test_network_urlparse__initialize(void)
{
host = port = user = pass = NULL;
}
void test_network_urlparse__cleanup(void)
{
#define FREE_AND_NULL(x) if (x) { git__free(x); x = NULL; }
FREE_AND_NULL(host);
FREE_AND_NULL(port);
FREE_AND_NULL(user);
FREE_AND_NULL(pass);
}
void test_network_urlparse__trivial(void)
{
cl_git_pass(gitno_extract_url_parts(&host, &port, &user, &pass,
"example.com/resource", "8080"));
cl_assert_equal_s(host, "example.com");
cl_assert_equal_s(port, "8080");
cl_assert_equal_p(user, NULL);
cl_assert_equal_p(pass, NULL);
}
void test_network_urlparse__user(void)
{
cl_git_pass(gitno_extract_url_parts(&host, &port, &user, &pass,
"user@example.com/resource", "8080"));
cl_assert_equal_s(host, "example.com");
cl_assert_equal_s(port, "8080");
cl_assert_equal_s(user, "user");
cl_assert_equal_p(pass, NULL);
}
void test_network_urlparse__user_pass(void)
{
/* user:pass@hostname.tld/resource */
cl_git_pass(gitno_extract_url_parts(&host, &port, &user, &pass,
"user:pass@example.com/resource", "8080"));
cl_assert_equal_s(host, "example.com");
cl_assert_equal_s(port, "8080");
cl_assert_equal_s(user, "user");
cl_assert_equal_s(pass, "pass");
}
void test_network_urlparse__port(void)
{
/* hostname.tld:port/resource */
cl_git_pass(gitno_extract_url_parts(&host, &port, &user, &pass,
"example.com:9191/resource", "8080"));
cl_assert_equal_s(host, "example.com");
cl_assert_equal_s(port, "9191");
cl_assert_equal_p(user, NULL);
cl_assert_equal_p(pass, NULL);
}
void test_network_urlparse__user_port(void)
{
/* user@hostname.tld:port/resource */
cl_git_pass(gitno_extract_url_parts(&host, &port, &user, &pass,
"user@example.com:9191/resource", "8080"));
cl_assert_equal_s(host, "example.com");
cl_assert_equal_s(port, "9191");
cl_assert_equal_s(user, "user");
cl_assert_equal_p(pass, NULL);
}
void test_network_urlparse__user_pass_port(void)
{
/* user:pass@hostname.tld:port/resource */
cl_git_pass(gitno_extract_url_parts(&host, &port, &user, &pass,
"user:pass@example.com:9191/resource", "8080"));
cl_assert_equal_s(host, "example.com");
cl_assert_equal_s(port, "9191");
cl_assert_equal_s(user, "user");
cl_assert_equal_s(pass, "pass");
}