Revision: 14651
Author: adrian.chadd
Date: Wed May 12 22:13:05 2010
Log: refactor out the common code in testing a specific http header set for parsing.


http://code.google.com/p/lusca-cache/source/detail?r=14651

Modified:
 /branches/LUSCA_HEAD/test-suite/atf/libhttp.c

=======================================
--- /branches/LUSCA_HEAD/test-suite/atf/libhttp.c       Wed May 12 21:26:39 2010
+++ /branches/LUSCA_HEAD/test-suite/atf/libhttp.c       Wed May 12 22:13:05 2010
@@ -52,26 +52,40 @@

extern int hh_check_content_length(HttpHeader *hdr, const char *val, int vlen);

-ATF_TC_WITH_CLEANUP(libhttp_parse_1);
-
-ATF_TC_HEAD(libhttp_parse_1, tc)
-{
-       atf_tc_set_md_var(tc, "descr", "libhttp_parse_1");
-}
-
-ATF_TC_BODY(libhttp_parse_1, tc)
+static void
+libhttp_test_parser(const char *str, int ret)
 {
        HttpHeader hdr;
- const char *hdrs = "Host: www.creative.net.au\r\nContent-type: text/html\r\nFoo: bar\r\n\r\n";

        test_core_init();
        httpHeaderInitLibrary();
-       ATF_REQUIRE(test_core_parse_header(&hdr, hdrs) == 1);
+       ATF_CHECK_EQ(test_core_parse_header(&hdr, str), ret);
        httpHeaderClean(&hdr);
 }

-ATF_TC_CLEANUP(libhttp_parse_1, tc)
-{
+extern int hh_check_content_length(HttpHeader *hdr, const char *val, int vlen);
+
+static int
+test_http_content_length(HttpHeader *hdr, const char *str)
+{
+       int r;
+
+       /* XXX remember; this may delete items from the header entry array! */
+       r = hh_check_content_length(hdr, str, strlen(str));
+       return r;
+}
+
+/* *** */
+
+ATF_TC(libhttp_parse_1);
+ATF_TC_HEAD(libhttp_parse_1, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "libhttp_parse_1");
+}
+
+ATF_TC_BODY(libhttp_parse_1, tc)
+{
+ libhttp_test_parser("Host: www.creative.net.au\r\nContent-type: text/html\r\nFoo: bar\r\n\r\n", 1);
 }

 ATF_TC(libhttp_parse_2);
@@ -82,14 +96,7 @@

 ATF_TC_BODY(libhttp_parse_2, tc)
 {
-       HttpHeader hdr;
- const char *hdrs = "Host: www.creative.net.au\r\nContent-Length: 12345\r\nContent-type: text/html\r\nFoo: bar\r\n\r\n";
-
-       test_core_init();
-       httpHeaderInitLibrary();
-       httpHeaderInit(&hdr, hoRequest);
-       ATF_REQUIRE(test_core_parse_header(&hdr, hdrs) == 1);
-       httpHeaderClean(&hdr);
+ libhttp_test_parser("Host: www.creative.net.au\r\nContent-Length: 12345\r\nContent-type: text/html\r\nFoo: bar\r\n\r\n", 1);
 }

 /* ** */
@@ -102,14 +109,7 @@

 ATF_TC_BODY(libhttp_parse_3, tc)
 {
-       HttpHeader hdr;
- const char *hdrs = "Host: www.creative.net.au\r\nContent-Length: b12345\r\nContent-type: text/html\r\nFoo: bar\r\n\r\n";
-
-       test_core_init();
-       httpHeaderInitLibrary();
-       httpHeaderInit(&hdr, hoRequest);
-       ATF_REQUIRE(test_core_parse_header(&hdr, hdrs) == 0);
-       httpHeaderClean(&hdr);
+ libhttp_test_parser("Host: www.creative.net.au\r\nContent-Length: b12345\r\nContent-type: text/html\r\nFoo: bar\r\n\r\n", 0);
 }

 /* *** */
@@ -123,28 +123,11 @@
 ATF_TC_BODY(libhttp_parse_4, tc)
 {
        HttpHeader hdr;
- const char *hdrs = "Host: www.creative.net.au\r\nContent-Length: 12345\r\nContent-type: text/html\r\nFoo: bar\r\nContent-Length: 23456\r\n";
-
-       test_core_init();
-       httpHeaderInitLibrary();
-       httpHeaderInit(&hdr, hoRequest);
-       ATF_REQUIRE(test_core_parse_header(&hdr, hdrs) == 0);
-       httpHeaderClean(&hdr);
+ libhttp_test_parser("Host: www.creative.net.au\r\nContent-Length: 12345\r\nContent-type: text/html\r\nFoo: bar\r\nContent-Length: 23456\r\n", 0);
 }

 /* *** */

-extern int hh_check_content_length(HttpHeader *hdr, const char *val, int vlen);
-
-static int
-test_http_content_length(HttpHeader *hdr, const char *str)
-{
-       int r;
-
-       /* XXX remember; this may delete items from the header entry array! */
-       r = hh_check_content_length(hdr, str, strlen(str));
-       return r;
-}

 ATF_TC_WITH_CLEANUP(libhttp_parse_content_length_1);

--
You received this message because you are subscribed to the Google Groups 
"lusca-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/lusca-commit?hl=en.

Reply via email to