[cosmetics] update date in GPL header
[vuplus_xbmc] / xbmc / utils / test / TestHttpParser.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://www.xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #include "utils/HttpParser.h"
22 #include "utils/StdString.h"
23
24 #include "gtest/gtest.h"
25
26 TEST(TestHttpParser, General)
27 {
28   HttpParser a;
29   CStdString str = "POST /path/script.cgi HTTP/1.0\r\n"
30                    "From: amejia@xbmc.org\r\n"
31                    "User-Agent: XBMC/snapshot (compatible; MSIE 5.5; Windows NT"
32                      " 4.0)\r\n"
33                    "Content-Type: application/x-www-form-urlencoded\r\n"
34                    "Content-Length: 35\r\n"
35                    "\r\n"
36                    "home=amejia&favorite+flavor=orange\r\n";
37   CStdString refstr, varstr;
38
39   EXPECT_EQ(a.Done, a.addBytes(str.c_str(), str.length()));
40
41   refstr = "POST";
42   varstr = a.getMethod();
43   EXPECT_STREQ(refstr.c_str(), varstr.c_str());
44
45   refstr = "/path/script.cgi";
46   varstr = a.getUri();
47   EXPECT_STREQ(refstr.c_str(), varstr.c_str());
48
49   refstr = "";
50   varstr = a.getQueryString();
51   EXPECT_STREQ(refstr.c_str(), varstr.c_str());
52
53   refstr = "home=amejia&favorite+flavor=orange\r\n";
54   varstr = a.getBody();
55   EXPECT_STREQ(refstr.c_str(), varstr.c_str());
56
57   refstr = "application/x-www-form-urlencoded";
58   varstr = a.getValue("content-type");
59   EXPECT_STREQ(refstr.c_str(), varstr.c_str());
60
61   EXPECT_EQ((unsigned)35, a.getContentLength());
62 }