LCOV - code coverage report
Current view: top level - svl/qa/unit - test_INetContentType.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 48 48 100.0 %
Date: 2014-11-03 Functions: 12 13 92.3 %
Legend: Lines: hit not hit

          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          18 : class Test: public CppUnit::TestFixture {
      26             : public:
      27             :     void testBad();
      28             : 
      29             :     void testFull();
      30             : 
      31             :     void testFollow();
      32             : 
      33           4 :     CPPUNIT_TEST_SUITE(Test);
      34           2 :     CPPUNIT_TEST(testBad);
      35           2 :     CPPUNIT_TEST(testFull);
      36           2 :     CPPUNIT_TEST(testFollow);
      37           4 :     CPPUNIT_TEST_SUITE_END();
      38             : };
      39             : 
      40           2 : void Test::testBad() {
      41           2 :     OUString in("foo=bar");
      42           4 :     CPPUNIT_ASSERT_EQUAL(
      43             :         static_cast<sal_Unicode const *>(0),
      44           2 :         INetMIME::scanContentType(in.getStr(), in.getStr() + in.getLength()));
      45           4 :     OUString t;
      46           4 :     OUString s;
      47           4 :     INetContentTypeParameterList ps;
      48           2 :     CPPUNIT_ASSERT(!INetContentTypes::parse(in, t, s, &ps));
      49           2 :     CPPUNIT_ASSERT(t.isEmpty());
      50           2 :     CPPUNIT_ASSERT(s.isEmpty());
      51           4 :     CPPUNIT_ASSERT_EQUAL(
      52           4 :         static_cast<INetContentTypeParameter const *>(0), ps.find("foo"));
      53           2 : }
      54             : 
      55           2 : void Test::testFull() {
      56           2 :     OUString in("foo/bar;baz=boz");
      57           4 :     CPPUNIT_ASSERT_EQUAL(
      58             :         in.getStr() + in.getLength(),
      59           2 :         INetMIME::scanContentType(in.getStr(), in.getStr() + in.getLength()));
      60           4 :     OUString t;
      61           4 :     OUString s;
      62           4 :     INetContentTypeParameterList ps;
      63           2 :     CPPUNIT_ASSERT(INetContentTypes::parse(in, t, s, &ps));
      64           2 :     CPPUNIT_ASSERT_EQUAL(OUString("foo"), t);
      65           2 :     CPPUNIT_ASSERT_EQUAL(OUString("bar"), s);
      66           2 :     INetContentTypeParameter const * p = ps.find("baz");
      67           2 :     CPPUNIT_ASSERT(p != 0);
      68           4 :     CPPUNIT_ASSERT_EQUAL(OUString("boz"), p->m_sValue);
      69           2 : }
      70             : 
      71           2 : void Test::testFollow() {
      72           2 :     OUString in("foo/bar;baz=boz;base64,");
      73           4 :     CPPUNIT_ASSERT_EQUAL(
      74             :         in.getStr() + std::strlen("foo/bar;baz=boz"),
      75           2 :         INetMIME::scanContentType(in.getStr(), in.getStr() + in.getLength()));
      76           4 :     OUString t;
      77           4 :     OUString s;
      78           4 :     INetContentTypeParameterList ps;
      79           2 :     CPPUNIT_ASSERT(!INetContentTypes::parse(in, t, s));
      80           2 :     CPPUNIT_ASSERT(t.isEmpty());
      81           2 :     CPPUNIT_ASSERT(s.isEmpty());
      82           4 :     CPPUNIT_ASSERT_EQUAL(
      83           4 :         static_cast<INetContentTypeParameter const *>(0), ps.find("baz"));
      84           2 : }
      85             : 
      86           2 : CPPUNIT_TEST_SUITE_REGISTRATION(Test);
      87             : 
      88             : }
      89             : 
      90           8 : CPPUNIT_PLUGIN_IMPLEMENT();
      91             : 
      92             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10