int main(void) { char *empty = (char *)""; wget_info_printf("%d\n", wget_base64_is_string("")); // base64.c wget_buffer_alloc(0); // buffer.c wget_buffer_printf((wget_buffer_t *)1, "%s", ""); // buffer_printf.c strlcpy((char *)"", "", 0); // strlcpy.c wget_css_parse_buffer((const char *)1, 0, NULL, NULL, NULL); // css.c wget_decompress_close(NULL); // decompressor.c wget_hashmap_create(0, 0, NULL, NULL); // hashmap.c wget_fdgetline(&empty, (size_t *)1, 0); // io.c wget_iri_parse("", NULL); // iri.c wget_list_free((wget_list_t **)1); // list.c wget_debug_write("", 0); // log.c wget_logger_set_file(NULL, ""); // logger.c wget_tcp_set_connect_timeout(NULL, 0); // net.c wget_netrc_deinit(NULL); // netrc.c wget_strdup(""); // mem.c // wget_popenf("r", "%s", ""); // pipe.c // wget_bsprintf(NULL, NULL, "%s", ""); // printf.c wget_ssl_set_config_int(0, 0); // ssl_[gnutls].c wget_stringmap_create(0); // stringmap.c if (wget_strcmp("", "")) {}; // utils.c wget_vector_set_destructor(NULL, NULL); // vector.c wget_malloc(1); // xalloc.c wget_xml_parse_buffer("", NULL, NULL, 0); // xml.c }
static void test_stringmap(void) { wget_stringmap_t *m; char key[128], value[128], *val; int run, it; size_t valuesize; // the initial size of 16 forces the internal reshashing function to be called twice m = wget_stringmap_create(16); for (run = 0; run < 2; run++) { if (run) { wget_stringmap_clear(m); wget_stringmap_sethashfunc(m, hash_txt); } for (it = 0; it < 26; it++) { sprintf(key, "http://www.example.com/subdir/%d.html", it); valuesize = sprintf(value, "%d.html", it); if (wget_stringmap_put(m, key, value, valuesize + 1)) { failed++; info_printf("stringmap_put(%s) returns unexpected old value\n", key); } else ok++; } if ((it = wget_stringmap_size(m)) != 26) { failed++; info_printf("stringmap_size() returned %d (expected %d)\n", it, 26); } else ok++; // now, look up every single entry for (it = 0; it < 26; it++) { sprintf(key, "http://www.example.com/subdir/%d.html", it); sprintf(value, "%d.html", it); if (!(val = wget_stringmap_get(m, key))) { failed++; info_printf("stringmap_get(%s) didn't find entry\n", key); } else if (strcmp(val, value)) { failed++; info_printf("stringmap_get(%s) found '%s' (expected '%s')\n", key, val, value); } else ok++; } wget_stringmap_clear(m); if ((it = wget_stringmap_size(m)) != 0) { failed++; info_printf("stringmap_size() returned %d (expected 0)\n", it); } else ok++; for (it = 0; it < 26; it++) { sprintf(key, "http://www.example.com/subdir/%d.html", it); valuesize = sprintf(value, "%d.html", it); if (wget_stringmap_put(m, key, value, valuesize + 1)) { failed++; info_printf("stringmap_put(%s) returns unexpected old value\n", key); } else ok++; } if ((it = wget_stringmap_size(m)) != 26) { failed++; info_printf("stringmap_size() returned %d (expected %d)\n", it, 26); } else ok++; // now, remove every single entry for (it = 0; it < 26; it++) { sprintf(key, "http://www.example.com/subdir/%d.html", it); sprintf(value, "%d.html", it); wget_stringmap_remove(m, key); } if ((it = wget_stringmap_size(m)) != 0) { failed++; info_printf("stringmap_size() returned %d (expected 0)\n", it); } else ok++; for (it = 0; it < 26; it++) { sprintf(key, "http://www.example.com/subdir/%d.html", it); valuesize = sprintf(value, "%d.html", it); if (wget_stringmap_put(m, key, value, valuesize + 1)) { failed++; info_printf("stringmap_put(%s) returns unexpected old value\n", key); } else ok++; } if ((it = wget_stringmap_size(m)) != 26) { failed++; info_printf("stringmap_size() returned %d (expected %d)\n", it, 26); } else ok++; } // testing alloc/free in stringmap/hashmap wget_stringmap_clear(m); wget_stringmap_put(m, "thekey", NULL, 0) ? failed++ : ok++; wget_stringmap_put(m, "thekey", NULL, 0) ? ok++ : failed++; wget_stringmap_put(m, "thekey", "thevalue", 9) ? ok++ : failed++; wget_stringmap_put(m, "thekey", "thevalue", 9) ? ok++ : failed++; wget_stringmap_put(m, "thekey", NULL, 0) ? ok++ : failed++; // testing key/value identity alloc/free in stringmap/hashmap wget_stringmap_clear(m); wget_stringmap_put(m, "thekey", NULL, 0) ? failed++ : ok++; wget_stringmap_put(m, "thekey", NULL, 0) ? ok++ : failed++; wget_stringmap_put(m, "thekey", "thevalue", 9) ? ok++ : failed++; wget_stringmap_put(m, "thekey", NULL, 0) ? ok++ : failed++; wget_stringmap_free(&m); wget_http_challenge_t challenge; wget_http_parse_challenge("Basic realm=\"test realm\"", &challenge); wget_http_free_challenge(&challenge); wget_vector_t *challenges; challenges = wget_vector_create(2, 2, NULL); wget_vector_set_destructor(challenges, (void(*)(void *))wget_http_free_challenge); wget_http_parse_challenge("Basic realm=\"test realm\"", &challenge); wget_vector_add(challenges, &challenge, sizeof(challenge)); wget_http_free_challenges(&challenges); char *response_text = strdup( "HTTP/1.1 401 Authorization Required\r\n"\ "Date: Sun, 23 Dec 2012 21:03:45 GMT\r\n"\ "Server: Apache/2.2.22 (Debian)\r\n"\ "WWW-Authenticate: Digest realm=\"therealm\", nonce=\"Ip6MaovRBAA=c4af733c51270698260f5d357724c2cbce20fa3d\", algorithm=MD5, domain=\"/prot_digest_md5\", qop=\"auth\"\r\n"\ "Vary: Accept-Encoding\r\n"\ "Content-Length: 476\r\n"\ "Keep-Alive: timeout=5, max=99\r\n"\ "Connection: Keep-Alive\r\n"\ "Content-Type: text/html; charset=iso-8859-1\r\n\r\n"); wget_iri_t *iri = wget_iri_parse("http://localhost/prot_digest_md5/", NULL); wget_http_request_t *req = wget_http_create_request(iri, "GET"); wget_http_response_t *resp = wget_http_parse_response_header(response_text); wget_http_add_credentials(req, wget_vector_get(resp->challenges, 0), "tim", "123"); // for (it=0;it<vec_size(req->lines);it++) { // info_printf("%s\n", (char *)vec_get(req->lines, it)); // } wget_http_free_response(&resp); wget_http_free_request(&req); wget_iri_free(&iri); xfree(response_text); // Authorization: Digest username="******", realm="therealm", nonce="Ip6MaovRBAA=c4af733c51270698260f5d357724c2cbce20fa3d", uri="/prot_digest_md5/", response="a99e2012d507a73dd46eb044d3f4641c", qop=auth, nc=00000001, cnonce="3d20faa1" }