test: add test framework
This commit is contained in:
@@ -19,6 +19,10 @@
|
||||
#ifndef _DNS_HEAD_H
|
||||
#define _DNS_HEAD_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /*__cplusplus */
|
||||
|
||||
#define DNS_RR_A_LEN 4
|
||||
#define DNS_RR_AAAA_LEN 16
|
||||
#define DNS_MAX_CNAME_LEN 256
|
||||
@@ -310,4 +314,7 @@ struct dns_update_param {
|
||||
|
||||
int dns_packet_update(unsigned char *data, int size, struct dns_update_param *param);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /*__cplusplus */
|
||||
#endif
|
||||
|
||||
@@ -646,7 +646,21 @@ static int _smartdns_init_pre(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
#define smartdns_test_notify(retval) smartdns_test_notify_func(fd_notify, retval)
|
||||
static void smartdns_test_notify_func(int fd_notify, uint64_t retval) {
|
||||
/* notify parent kickoff */
|
||||
if (fd_notify > 0) {
|
||||
write(fd_notify, &retval, sizeof(retval));
|
||||
}
|
||||
}
|
||||
|
||||
int smartdns_main(int argc, char *argv[], int fd_notify);
|
||||
int smartdns_main(int argc, char *argv[], int fd_notify)
|
||||
#else
|
||||
#define smartdns_test_notify(retval)
|
||||
int main(int argc, char *argv[])
|
||||
#endif
|
||||
{
|
||||
int ret = 0;
|
||||
int is_foreground = 0;
|
||||
@@ -732,10 +746,11 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
atexit(_smartdns_exit);
|
||||
smartdns_test_notify(1);
|
||||
|
||||
return _smartdns_run();
|
||||
|
||||
errout:
|
||||
|
||||
smartdns_test_notify(2);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -401,7 +401,7 @@ int check_is_ipaddr(const char *ip)
|
||||
return -1;
|
||||
}
|
||||
|
||||
int parse_uri(char *value, char *scheme, char *host, int *port, char *path)
|
||||
int parse_uri(const char *value, char *scheme, char *host, int *port, char *path)
|
||||
{
|
||||
return parse_uri_ext(value, scheme, NULL, NULL, host, port, path);
|
||||
}
|
||||
@@ -442,16 +442,16 @@ void urldecode(char *dst, const char *src)
|
||||
*dst++ = '\0';
|
||||
}
|
||||
|
||||
int parse_uri_ext(char *value, char *scheme, char *user, char *password, char *host, int *port, char *path)
|
||||
int parse_uri_ext(const char *value, char *scheme, char *user, char *password, char *host, int *port, char *path)
|
||||
{
|
||||
char *scheme_end = NULL;
|
||||
int field_len = 0;
|
||||
char *process_ptr = value;
|
||||
const char *process_ptr = value;
|
||||
char user_pass_host_part[PATH_MAX];
|
||||
char *user_password = NULL;
|
||||
char *host_part = NULL;
|
||||
|
||||
char *host_end = NULL;
|
||||
const char *host_end = NULL;
|
||||
|
||||
scheme_end = strstr(value, "://");
|
||||
if (scheme_end) {
|
||||
|
||||
@@ -69,9 +69,9 @@ int parse_ip(const char *value, char *ip, int *port);
|
||||
|
||||
int check_is_ipaddr(const char *ip);
|
||||
|
||||
int parse_uri(char *value, char *scheme, char *host, int *port, char *path);
|
||||
int parse_uri(const char *value, char *scheme, char *host, int *port, char *path);
|
||||
|
||||
int parse_uri_ext(char *value, char *scheme, char *user, char *password, char *host, int *port, char *path);
|
||||
int parse_uri_ext(const char *value, char *scheme, char *user, char *password, char *host, int *port, char *path);
|
||||
|
||||
void urldecode(char *dst, const char *src);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user