Merge pull request #2065 from sandsmark/master
[vuplus_xbmc] / xbmc / utils / test / TestHttpHeader.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/HttpHeader.h"
22
23 #include "gtest/gtest.h"
24
25 TEST(TestHttpHeader, General)
26 {
27   CHttpHeader a;
28   CStdString str = "Host: xbmc.org\r\n"
29                    "Accept: text/*, text/html, text/html;level=1, */*\r\n"
30                    "Accept-Language: en\r\n"
31                    "Accept-Encoding: gzip, deflate\r\n"
32                    "Content-Type: text/html; charset=ISO-8859-4\r\n"
33                    "User-Agent: XBMC/snapshot (compatible; MSIE 5.5; Windows NT"
34                      " 4.0)\r\n"
35                    "Connection: Keep-Alive\r\n";
36   CStdString refstr, varstr;
37
38   a.Parse(str);
39
40   refstr = "accept: text/*, text/html, text/html;level=1, */*\n"
41            "accept-encoding: gzip, deflate\n"
42            "accept-language: en\n"
43            "connection: Keep-Alive\n"
44            "content-type: text/html; charset=ISO-8859-4\n"
45            "host: xbmc.org\n"
46            "user-agent: XBMC/snapshot (compatible; MSIE 5.5; Windows NT 4.0)\n"
47            "\n";
48   varstr.clear();
49   a.GetHeader(varstr);
50   EXPECT_STREQ(refstr.c_str(), varstr.c_str());
51
52   refstr = "XBMC/snapshot (compatible; MSIE 5.5; Windows NT 4.0)";
53   varstr = a.GetValue("User-Agent");
54   EXPECT_STREQ(refstr.c_str(), varstr.c_str());
55
56   refstr = "text/html; charset=ISO-8859-4";
57   varstr = a.GetMimeType();
58   EXPECT_STREQ(refstr.c_str(), varstr.c_str());
59
60   refstr = "";
61   varstr = a.GetProtoLine();
62   EXPECT_STREQ(refstr.c_str(), varstr.c_str());
63
64   a.Clear();
65   refstr = "";
66   varstr = a.GetMimeType();
67   EXPECT_STREQ(refstr.c_str(), varstr.c_str());
68 }