bump product version to 5.0.4.1
[LibreOffice.git] / svl / qa / unit / test_INetContentType.cxx
blobb7aa71cd6e66dce92013a1adfb75665d32d4fd25
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include <sal/config.h>
12 #include <cstring>
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>
23 namespace {
25 class Test: public CppUnit::TestFixture {
26 public:
27 void testBad();
29 void testFull();
31 void testFollow();
33 CPPUNIT_TEST_SUITE(Test);
34 CPPUNIT_TEST(testBad);
35 CPPUNIT_TEST(testFull);
36 CPPUNIT_TEST(testFollow);
37 CPPUNIT_TEST_SUITE_END();
40 void Test::testBad() {
41 OUString in("foo=bar");
42 CPPUNIT_ASSERT_EQUAL(
43 static_cast<sal_Unicode const *>(0),
44 INetMIME::scanContentType(in.getStr(), in.getStr() + in.getLength()));
45 OUString t;
46 OUString s;
47 INetContentTypeParameterList ps;
48 CPPUNIT_ASSERT(!INetContentTypes::parse(in, t, s, &ps));
49 CPPUNIT_ASSERT(t.isEmpty());
50 CPPUNIT_ASSERT(s.isEmpty());
51 CPPUNIT_ASSERT_EQUAL(
52 static_cast<INetContentTypeParameter const *>(0), ps.find("foo"));
55 void Test::testFull() {
56 OUString in("foo/bar;baz=boz");
57 CPPUNIT_ASSERT_EQUAL(
58 in.getStr() + in.getLength(),
59 INetMIME::scanContentType(in.getStr(), in.getStr() + in.getLength()));
60 OUString t;
61 OUString s;
62 INetContentTypeParameterList ps;
63 CPPUNIT_ASSERT(INetContentTypes::parse(in, t, s, &ps));
64 CPPUNIT_ASSERT_EQUAL(OUString("foo"), t);
65 CPPUNIT_ASSERT_EQUAL(OUString("bar"), s);
66 INetContentTypeParameter const * p = ps.find("baz");
67 CPPUNIT_ASSERT(p != 0);
68 CPPUNIT_ASSERT_EQUAL(OUString("boz"), p->m_sValue);
71 void Test::testFollow() {
72 OUString in("foo/bar;baz=boz;base64,");
73 CPPUNIT_ASSERT_EQUAL(
74 in.getStr() + std::strlen("foo/bar;baz=boz"),
75 INetMIME::scanContentType(in.getStr(), in.getStr() + in.getLength()));
76 OUString t;
77 OUString s;
78 INetContentTypeParameterList ps;
79 CPPUNIT_ASSERT(!INetContentTypes::parse(in, t, s));
80 CPPUNIT_ASSERT(t.isEmpty());
81 CPPUNIT_ASSERT(s.isEmpty());
82 CPPUNIT_ASSERT_EQUAL(
83 static_cast<INetContentTypeParameter const *>(0), ps.find("baz"));
86 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
90 CPPUNIT_PLUGIN_IMPLEMENT();
92 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */