]> git.ipfire.org Git - thirdparty/squid.git/blame - src/tests/testHttpRequestMethod.cc
Author: Alexey Veselovsky <alexey.veselovsky@eykontech.com>
[thirdparty/squid.git] / src / tests / testHttpRequestMethod.cc
CommitLineData
985c86bc 1#include "squid.h"
2#include <sstream>
3#include <cppunit/TestAssert.h>
4
5#include "Mem.h"
6#include "testHttpRequestMethod.h"
7#include "HttpRequestMethod.h"
8
9
10CPPUNIT_TEST_SUITE_REGISTRATION( testHttpRequestMethod );
11
12
13/*
14 * We should be able to make an HttpRequestMethod straight from a string.
15 */
16void
17testHttpRequestMethod::testConstructCharStart()
18{
19 /* parse an empty string -> METHOD_NONE */
20 CPPUNIT_ASSERT(METHOD_NONE == HttpRequestMethod(NULL));
21 /* parsing a literal should work */
22 CPPUNIT_ASSERT(METHOD_GET == HttpRequestMethod("GET", NULL));
60745f24 23 CPPUNIT_ASSERT(METHOD_OTHER == HttpRequestMethod("QWERTY", NULL));
985c86bc 24}
25
26/*
27 * We can also parse precise ranges of characters
28 */
29void
30testHttpRequestMethod::testConstructCharStartEnd()
31{
32 char const * buffer;
33 /* parse an empty string -> METHOD_NONE */
34 CPPUNIT_ASSERT(METHOD_NONE == HttpRequestMethod(NULL, NULL));
35 /* parsing a literal should work */
36 CPPUNIT_ASSERT(METHOD_GET == HttpRequestMethod("GET", NULL));
37 /* parsing with an explicit end should work */
38 buffer = "POSTPLUS";
39 CPPUNIT_ASSERT(METHOD_POST == HttpRequestMethod(buffer, buffer + 4));
40}
41
42/*
43 * we should be able to assign a method_t to a HttpRequestMethod
44 */
45void
46testHttpRequestMethod::testAssignFrommethod_t()
47{
48 HttpRequestMethod method;
49 method = METHOD_NONE;
50 CPPUNIT_ASSERT_EQUAL(HttpRequestMethod(METHOD_NONE), method);
51 method = METHOD_POST;
52 CPPUNIT_ASSERT_EQUAL(HttpRequestMethod(METHOD_POST), method);
53}
54
55/*
56 * a default constructed HttpRequestMethod is == METHOD_NONE
57 */
58void
59testHttpRequestMethod::testDefaultConstructor()
60{
41030a36 61 HttpRequestMethod lhs;
62 HttpRequestMethod rhs(METHOD_NONE);
63 CPPUNIT_ASSERT_EQUAL(lhs, rhs);
985c86bc 64}
65
66/*
67 * we should be able to construct a HttpRequestMethod from a method_t
68 */
69void
70testHttpRequestMethod::testConstructmethod_t()
71{
72 CPPUNIT_ASSERT_EQUAL(HttpRequestMethod(METHOD_NONE), HttpRequestMethod(METHOD_NONE));
73 CPPUNIT_ASSERT_EQUAL(HttpRequestMethod(METHOD_POST), HttpRequestMethod(METHOD_POST));
74 CPPUNIT_ASSERT(HttpRequestMethod(METHOD_NONE) != HttpRequestMethod(METHOD_POST));
75}
76
77/*
78 * we should be able to get a char const * version of the method.
79 */
80void
81testHttpRequestMethod::testConst_str()
82{
30abd221 83 CPPUNIT_ASSERT_EQUAL(String("POST"), String(HttpRequestMethod("post").const_str()));
985c86bc 84}
85
86/*
87 * an HttpRequestMethod should be comparable to a method_t without false
88 * matches
89 */
90void
91testHttpRequestMethod::testEqualmethod_t()
92{
93 CPPUNIT_ASSERT(HttpRequestMethod(METHOD_NONE) == METHOD_NONE);
94 CPPUNIT_ASSERT(not (HttpRequestMethod(METHOD_POST) == METHOD_GET));
95 CPPUNIT_ASSERT(METHOD_GET == HttpRequestMethod(METHOD_GET));
96 CPPUNIT_ASSERT(not (METHOD_SEARCH == HttpRequestMethod(METHOD_TRACE)));
97}
98
99/*
100 * an HttpRequestMethod should testable for inequality without fail maatches
101 */
102void
103testHttpRequestMethod::testNotEqualmethod_t()
104{
105 CPPUNIT_ASSERT(HttpRequestMethod(METHOD_NONE) != METHOD_GET);
106 CPPUNIT_ASSERT(not (HttpRequestMethod(METHOD_POST) != METHOD_POST));
107 CPPUNIT_ASSERT(METHOD_NONE != HttpRequestMethod(METHOD_GET));
108 CPPUNIT_ASSERT(not (METHOD_SEARCH != HttpRequestMethod(METHOD_SEARCH)));
109}
110
111/*
112 * we should be able to send it to a stream and get the normalised version
113 */
114void
115testHttpRequestMethod::testStream()
116{
117 std::ostringstream buffer;
118 buffer << HttpRequestMethod("get");
30abd221 119 CPPUNIT_ASSERT_EQUAL(String("GET"), String(buffer.str().c_str()));
985c86bc 120}