1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
10 #include <sal/config.h>
14 #include <cppunit/TestAssert.h>
15 #include <cppunit/TestFixture.h>
16 #include <cppunit/extensions/HelperMacros.h>
17 #include <cppunit/plugin/TestPlugIn.h>
18 #include <rtl/ustring.hxx>
19 #include <svl/inettype.hxx>
20 #include <tools/inetmime.hxx>
24 class Test
: public CppUnit::TestFixture
{
32 CPPUNIT_TEST_SUITE(Test
);
33 CPPUNIT_TEST(testBad
);
34 CPPUNIT_TEST(testFull
);
35 CPPUNIT_TEST(testFollow
);
36 CPPUNIT_TEST_SUITE_END();
39 void Test::testBad() {
40 OUString
in("foo=bar");
42 static_cast<void const *>(nullptr),
43 static_cast<void const *>(INetMIME::scanContentType(in
)));
46 INetContentTypeParameterList ps
;
47 CPPUNIT_ASSERT(!INetContentTypes::parse(in
, t
, s
, &ps
));
48 CPPUNIT_ASSERT(t
.isEmpty());
49 CPPUNIT_ASSERT(s
.isEmpty());
50 CPPUNIT_ASSERT(bool(ps
.end() == ps
.find("foo"_ostr
)));
53 void Test::testFull() {
54 OUString
in("foo/bar;baz=boz");
56 static_cast<void const *>(in
.getStr() + in
.getLength()),
57 static_cast<void const *>(INetMIME::scanContentType(in
)));
60 INetContentTypeParameterList ps
;
61 CPPUNIT_ASSERT(INetContentTypes::parse(in
, t
, s
, &ps
));
62 CPPUNIT_ASSERT_EQUAL(OUString("foo"), t
);
63 CPPUNIT_ASSERT_EQUAL(OUString("bar"), s
);
64 auto iter
= ps
.find("baz"_ostr
);
65 CPPUNIT_ASSERT(iter
!= ps
.end());
66 CPPUNIT_ASSERT_EQUAL(OUString("boz"), iter
->second
.m_sValue
);
69 void Test::testFollow() {
70 OUString
in("foo/bar;baz=boz;base64,");
72 static_cast<void const *>(in
.getStr() + std::strlen("foo/bar;baz=boz")),
73 static_cast<void const *>(INetMIME::scanContentType(in
)));
76 INetContentTypeParameterList ps
;
77 CPPUNIT_ASSERT(!INetContentTypes::parse(in
, t
, s
));
78 CPPUNIT_ASSERT(t
.isEmpty());
79 CPPUNIT_ASSERT(s
.isEmpty());
80 CPPUNIT_ASSERT(bool(ps
.end() == ps
.find("baz"_ostr
)));
83 CPPUNIT_TEST_SUITE_REGISTRATION(Test
);
87 CPPUNIT_PLUGIN_IMPLEMENT();
89 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */