[tests] fix HttpHeader test
[vuplus_xbmc] / xbmc / utils / test / TestHttpHeader.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://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/HttpHeader.h"
22 #include "gtest/gtest.h"
23
24 TEST(TestHttpHeader, General)
25 {
26   CHttpHeader a;
27   std::string str = "Host: xbmc.org\r\n"
28                    "Accept: text/*, text/html, text/html;level=1, */*\r\n"
29                    "Accept-Language: en\r\n"
30                    "Accept-Encoding: gzip, deflate\r\n"
31                    "Content-Type: text/html; charset=ISO-8859-4\r\n"
32                    "User-Agent: XBMC/snapshot (compatible; MSIE 5.5; Windows NT"
33                      " 4.0)\r\n"
34                    "Connection: Keep-Alive\r\n"
35                    "\r\n";
36   std::string refstr, varstr;
37
38   a.Parse(str);
39
40   /* Should be in the same order as above */
41   refstr = "\n"
42            "host: xbmc.org\n"
43            "accept: text/*, text/html, text/html;level=1, */*\n"
44            "accept-language: en\n"
45            "accept-encoding: gzip, deflate\n"
46            "content-type: text/html; charset=ISO-8859-4\n"
47            "user-agent: XBMC/snapshot (compatible; MSIE 5.5; Windows NT 4.0)\n"
48            "connection: Keep-Alive\n"
49            "\n";
50   varstr.clear();
51   varstr = a.GetHeader();
52   EXPECT_STREQ(refstr.c_str(), varstr.c_str());
53
54   refstr = "XBMC/snapshot (compatible; MSIE 5.5; Windows NT 4.0)";
55   varstr = a.GetValue("User-Agent");
56   EXPECT_STREQ(refstr.c_str(), varstr.c_str());
57
58   /* No charset should be here */
59   refstr = "text/html";
60   varstr = a.GetMimeType();
61   EXPECT_STREQ(refstr.c_str(), varstr.c_str());
62
63   refstr = "";
64   varstr = a.GetProtoLine();
65   EXPECT_STREQ(refstr.c_str(), varstr.c_str());
66
67   a.Clear();
68   refstr = "";
69   varstr = a.GetMimeType();
70   EXPECT_STREQ(refstr.c_str(), varstr.c_str());
71 }