~ubuntu-branches/ubuntu/gutsy/poco/gutsy

« back to all changes in this revision

Viewing changes to Net/testsuite/src/MediaTypeTest.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Krzysztof Burghardt
  • Date: 2007-04-27 18:33:48 UTC
  • Revision ID: james.westby@ubuntu.com-20070427183348-xgnpct0qd6a2ip34
Tags: upstream-1.2.9
ImportĀ upstreamĀ versionĀ 1.2.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// MediaTypeTest.cpp
 
3
//
 
4
// $Id: //poco/1.2/Net/testsuite/src/MediaTypeTest.cpp#1 $
 
5
//
 
6
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
 
7
// and Contributors.
 
8
//
 
9
// Permission is hereby granted, free of charge, to any person or organization
 
10
// obtaining a copy of the software and accompanying documentation covered by
 
11
// this license (the "Software") to use, reproduce, display, distribute,
 
12
// execute, and transmit the Software, and to prepare derivative works of the
 
13
// Software, and to permit third-parties to whom the Software is furnished to
 
14
// do so, all subject to the following:
 
15
// 
 
16
// The copyright notices in the Software and this entire statement, including
 
17
// the above license grant, this restriction and the following disclaimer,
 
18
// must be included in all copies of the Software, in whole or in part, and
 
19
// all derivative works of the Software, unless such copies or derivative
 
20
// works are solely in the form of machine-executable object code generated by
 
21
// a source language processor.
 
22
// 
 
23
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
24
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
25
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
 
26
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
 
27
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
 
28
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 
29
// DEALINGS IN THE SOFTWARE.
 
30
//
 
31
 
 
32
 
 
33
#include "MediaTypeTest.h"
 
34
#include "CppUnit/TestCaller.h"
 
35
#include "CppUnit/TestSuite.h"
 
36
#include "Poco/Net/MediaType.h"
 
37
 
 
38
 
 
39
using Poco::Net::MediaType;
 
40
 
 
41
 
 
42
MediaTypeTest::MediaTypeTest(const std::string& name): CppUnit::TestCase(name)
 
43
{
 
44
}
 
45
 
 
46
 
 
47
MediaTypeTest::~MediaTypeTest()
 
48
{
 
49
}
 
50
 
 
51
 
 
52
void MediaTypeTest::testParse()
 
53
{
 
54
        MediaType mt1("text/plain");
 
55
        assert (mt1.getType() == "text");
 
56
        assert (mt1.getSubType() == "plain");
 
57
        assert (mt1.parameters().empty());
 
58
        
 
59
        MediaType mt2("text/xml;charset=us-ascii");
 
60
        assert (mt2.getType() == "text");
 
61
        assert (mt2.getSubType() == "xml");
 
62
        assert (!mt2.parameters().empty());
 
63
        assert (mt2.getParameter("charset") == "us-ascii");
 
64
        
 
65
        MediaType mt3("application/test; param1=value1; param2=\"value 2\"");
 
66
        assert (mt3.getType() == "application");
 
67
        assert (mt3.getSubType() == "test");
 
68
        assert (!mt3.parameters().empty());
 
69
        assert (mt3.getParameter("param1") == "value1");
 
70
        assert (mt3.getParameter("PARAM2") == "value 2");
 
71
}
 
72
 
 
73
 
 
74
void MediaTypeTest::testToString()
 
75
{
 
76
        MediaType mt1("text", "plain");
 
77
        assert (mt1.toString() == "text/plain");
 
78
        
 
79
        mt1.setParameter("charset", "iso-8859-1");
 
80
        assert (mt1.toString() == "text/plain; charset=iso-8859-1");
 
81
        
 
82
        MediaType mt2("application", "test");
 
83
        mt2.setParameter("param1", "value1");
 
84
        mt2.setParameter("param2", "value 2");
 
85
        assert (mt2.toString() == "application/test; param1=value1; param2=\"value 2\"");
 
86
}
 
87
 
 
88
 
 
89
void MediaTypeTest::testMatch()
 
90
{
 
91
        MediaType mt1("Text/Plain");
 
92
        MediaType mt2("text/plain");
 
93
        MediaType mt3("text/xml");
 
94
        assert (mt1.matches(mt2));
 
95
        assert (!mt1.matches(mt3));
 
96
        assert (mt1.matches("text"));
 
97
        assert (mt2.matches("text"));
 
98
        assert (mt3.matches("text"));
 
99
}
 
100
 
 
101
 
 
102
void MediaTypeTest::setUp()
 
103
{
 
104
}
 
105
 
 
106
 
 
107
void MediaTypeTest::tearDown()
 
108
{
 
109
}
 
110
 
 
111
 
 
112
CppUnit::Test* MediaTypeTest::suite()
 
113
{
 
114
        CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("MediaTypeTest");
 
115
 
 
116
        CppUnit_addTest(pSuite, MediaTypeTest, testParse);
 
117
        CppUnit_addTest(pSuite, MediaTypeTest, testToString);
 
118
        CppUnit_addTest(pSuite, MediaTypeTest, testMatch);
 
119
 
 
120
        return pSuite;
 
121
}