Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : */
9 :
10 : #include <sal/config.h>
11 :
12 : #include <cstring>
13 :
14 : #include <cppunit/TestAssert.h>
15 : #include <cppunit/TestFixture.h>
16 : #include <cppunit/TestSuite.h>
17 : #include <cppunit/extensions/HelperMacros.h>
18 : #include <cppunit/plugin/TestPlugIn.h>
19 : #include <rtl/ustring.hxx>
20 : #include <svl/inettype.hxx>
21 : #include <tools/inetmime.hxx>
22 :
23 : namespace {
24 :
25 9 : class Test: public CppUnit::TestFixture {
26 : public:
27 : void testBad();
28 :
29 : void testFull();
30 :
31 : void testFollow();
32 :
33 2 : CPPUNIT_TEST_SUITE(Test);
34 1 : CPPUNIT_TEST(testBad);
35 1 : CPPUNIT_TEST(testFull);
36 1 : CPPUNIT_TEST(testFollow);
37 5 : CPPUNIT_TEST_SUITE_END();
38 : };
39 :
40 1 : void Test::testBad() {
41 1 : OUString in("foo=bar");
42 2 : CPPUNIT_ASSERT_EQUAL(
43 : static_cast<sal_Unicode const *>(0),
44 1 : INetMIME::scanContentType(in.getStr(), in.getStr() + in.getLength()));
45 2 : OUString t;
46 2 : OUString s;
47 2 : INetContentTypeParameterList ps;
48 1 : CPPUNIT_ASSERT(!INetContentTypes::parse(in, t, s, &ps));
49 1 : CPPUNIT_ASSERT(t.isEmpty());
50 1 : CPPUNIT_ASSERT(s.isEmpty());
51 2 : CPPUNIT_ASSERT_EQUAL(
52 2 : static_cast<INetContentTypeParameter const *>(0), ps.find("foo"));
53 1 : }
54 :
55 1 : void Test::testFull() {
56 1 : OUString in("foo/bar;baz=boz");
57 2 : CPPUNIT_ASSERT_EQUAL(
58 : in.getStr() + in.getLength(),
59 1 : INetMIME::scanContentType(in.getStr(), in.getStr() + in.getLength()));
60 2 : OUString t;
61 2 : OUString s;
62 2 : INetContentTypeParameterList ps;
63 1 : CPPUNIT_ASSERT(INetContentTypes::parse(in, t, s, &ps));
64 1 : CPPUNIT_ASSERT_EQUAL(OUString("foo"), t);
65 1 : CPPUNIT_ASSERT_EQUAL(OUString("bar"), s);
66 1 : INetContentTypeParameter const * p = ps.find("baz");
67 1 : CPPUNIT_ASSERT(p != 0);
68 2 : CPPUNIT_ASSERT_EQUAL(OUString("boz"), p->m_sValue);
69 1 : }
70 :
71 1 : void Test::testFollow() {
72 1 : OUString in("foo/bar;baz=boz;base64,");
73 2 : CPPUNIT_ASSERT_EQUAL(
74 : in.getStr() + std::strlen("foo/bar;baz=boz"),
75 1 : INetMIME::scanContentType(in.getStr(), in.getStr() + in.getLength()));
76 2 : OUString t;
77 2 : OUString s;
78 2 : INetContentTypeParameterList ps;
79 1 : CPPUNIT_ASSERT(!INetContentTypes::parse(in, t, s));
80 1 : CPPUNIT_ASSERT(t.isEmpty());
81 1 : CPPUNIT_ASSERT(s.isEmpty());
82 2 : CPPUNIT_ASSERT_EQUAL(
83 2 : static_cast<INetContentTypeParameter const *>(0), ps.find("baz"));
84 1 : }
85 :
86 1 : CPPUNIT_TEST_SUITE_REGISTRATION(Test);
87 :
88 : }
89 :
90 4 : CPPUNIT_PLUGIN_IMPLEMENT();
91 :
92 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|