Merge pull request #1225 from thebandit/trust-scraper
[vuplus_xbmc] / xbmc / utils / test / TestHttpHeader.cpp
1 /*
2  *      Copyright (C) 2005-2012 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, write to
17  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18  *  http://www.gnu.org/copyleft/gpl.html
19  *
20  */
21
22 #include "utils/HttpHeader.h"
23
24 #include "gtest/gtest.h"
25
26 TEST(TestHttpHeader, General)
27 {
28   CHttpHeader a;
29   CStdString str = "Host: xbmc.org\r\n"
30                    "Accept: text/*, text/html, text/html;level=1, */*\r\n"
31                    "Accept-Language: en\r\n"
32                    "Accept-Encoding: gzip, deflate\r\n"
33                    "Content-Type: text/html; charset=ISO-8859-4\r\n"
34                    "User-Agent: XBMC/snapshot (compatible; MSIE 5.5; Windows NT"
35                      " 4.0)\r\n"
36                    "Connection: Keep-Alive\r\n";
37   CStdString refstr, varstr;
38
39   a.Parse(str);
40
41   refstr = "accept: text/*, text/html, text/html;level=1, */*\n"
42            "accept-encoding: gzip, deflate\n"
43            "accept-language: en\n"
44            "connection: Keep-Alive\n"
45            "content-type: text/html; charset=ISO-8859-4\n"
46            "host: xbmc.org\n"
47            "user-agent: XBMC/snapshot (compatible; MSIE 5.5; Windows NT 4.0)\n"
48            "\n";
49   varstr.clear();
50   a.GetHeader(varstr);
51   EXPECT_STREQ(refstr.c_str(), varstr.c_str());
52
53   refstr = "XBMC/snapshot (compatible; MSIE 5.5; Windows NT 4.0)";
54   varstr = a.GetValue("User-Agent");
55   EXPECT_STREQ(refstr.c_str(), varstr.c_str());
56
57   refstr = "text/html; charset=ISO-8859-4";
58   varstr = a.GetMimeType();
59   EXPECT_STREQ(refstr.c_str(), varstr.c_str());
60
61   refstr = "";
62   varstr = a.GetProtoLine();
63   EXPECT_STREQ(refstr.c_str(), varstr.c_str());
64
65   a.Clear();
66   refstr = "";
67   varstr = a.GetMimeType();
68   EXPECT_STREQ(refstr.c_str(), varstr.c_str());
69 }