1
#define SQUID_UNIT_TEST 1
1
#define SQUID_UNIT_TEST 1
5
4
#include <cppunit/TestAssert.h>
8
7
#include "testHttpRequestMethod.h"
9
8
#include "HttpRequestMethod.h"
12
14
CPPUNIT_TEST_SUITE_REGISTRATION( testHttpRequestMethod );
19
21
testHttpRequestMethod::testConstructCharStart()
21
23
/* parse an empty string -> METHOD_NONE */
22
CPPUNIT_ASSERT(METHOD_NONE == HttpRequestMethod(NULL));
24
CPPUNIT_ASSERT(HttpRequestMethod(NULL,NULL) == METHOD_NONE);
23
25
/* parsing a literal should work */
24
CPPUNIT_ASSERT(METHOD_GET == HttpRequestMethod("GET", NULL));
26
CPPUNIT_ASSERT(HttpRequestMethod("GET", NULL) == METHOD_GET);
27
CPPUNIT_ASSERT(HttpRequestMethod("QWERTY", NULL) == METHOD_OTHER);
28
* We can also parse precise ranges of characters
31
* We can also parse precise ranges of characters
31
34
testHttpRequestMethod::testConstructCharStartEnd()
33
36
char const * buffer;
34
37
/* parse an empty string -> METHOD_NONE */
35
CPPUNIT_ASSERT(METHOD_NONE == HttpRequestMethod(NULL, NULL));
38
CPPUNIT_ASSERT(HttpRequestMethod(NULL, NULL) == METHOD_NONE);
36
39
/* parsing a literal should work */
37
CPPUNIT_ASSERT(METHOD_GET == HttpRequestMethod("GET", NULL));
40
CPPUNIT_ASSERT(HttpRequestMethod("GET", NULL) == METHOD_GET);
38
41
/* parsing with an explicit end should work */
39
42
buffer = "POSTPLUS";
40
CPPUNIT_ASSERT(METHOD_POST == HttpRequestMethod(buffer, buffer + 4));
43
CPPUNIT_ASSERT(HttpRequestMethod(buffer, buffer + 4) == METHOD_POST);
79
82
* we should be able to get a char const * version of the method.
82
testHttpRequestMethod::testConst_str()
85
testHttpRequestMethod::testImage()
84
CPPUNIT_ASSERT_EQUAL(String("POST"), String(HttpRequestMethod("post").const_str()));
87
CPPUNIT_ASSERT_EQUAL(String("POST"), String(HttpRequestMethod("post",NULL).image()));
94
97
CPPUNIT_ASSERT(HttpRequestMethod(METHOD_NONE) == METHOD_NONE);
95
98
CPPUNIT_ASSERT(not (HttpRequestMethod(METHOD_POST) == METHOD_GET));
96
CPPUNIT_ASSERT(METHOD_GET == HttpRequestMethod(METHOD_GET));
97
CPPUNIT_ASSERT(not (METHOD_SEARCH == HttpRequestMethod(METHOD_TRACE)));
99
CPPUNIT_ASSERT(HttpRequestMethod(METHOD_GET) == METHOD_GET);
100
CPPUNIT_ASSERT(not (HttpRequestMethod(METHOD_TRACE) == METHOD_SEARCH));
106
109
CPPUNIT_ASSERT(HttpRequestMethod(METHOD_NONE) != METHOD_GET);
107
110
CPPUNIT_ASSERT(not (HttpRequestMethod(METHOD_POST) != METHOD_POST));
108
CPPUNIT_ASSERT(METHOD_NONE != HttpRequestMethod(METHOD_GET));
109
CPPUNIT_ASSERT(not (METHOD_SEARCH != HttpRequestMethod(METHOD_SEARCH)));
111
CPPUNIT_ASSERT(HttpRequestMethod(METHOD_GET) != METHOD_NONE);
112
CPPUNIT_ASSERT(not (HttpRequestMethod(METHOD_SEARCH) != METHOD_SEARCH));
116
119
testHttpRequestMethod::testStream()
118
121
std::ostringstream buffer;
119
buffer << HttpRequestMethod("get");
122
buffer << HttpRequestMethod("get",NULL);
120
123
CPPUNIT_ASSERT_EQUAL(String("GET"), String(buffer.str().c_str()));