summaryrefslogtreecommitdiff
path: root/svl/qa
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2014-03-27 18:05:51 +0100
committerStephan Bergmann <sbergman@redhat.com>2014-03-27 18:06:27 +0100
commitc36daa01f444ebad799c1cc7a106f1b4bb3c3d12 (patch)
treedf0326a5b76d4b69b5661a57b64f5c6dd5314523 /svl/qa
parent92ad689bcb3ad16bd35302e6ff4ee45b872c05a0 (diff)
Introduce INetContentType::scan
...for use in <https://gerrit.libreoffice.org/#/c/8737/> "new methodINetURLObject::getData() for data urls." Change-Id: Id381d7c328153fbea44c0efb80532b2961c6c2b7
Diffstat (limited to 'svl/qa')
-rw-r--r--svl/qa/unit/test_INetContentType.cxx92
1 files changed, 92 insertions, 0 deletions
diff --git a/svl/qa/unit/test_INetContentType.cxx b/svl/qa/unit/test_INetContentType.cxx
new file mode 100644
index 000000000000..a2ce362a10a0
--- /dev/null
+++ b/svl/qa/unit/test_INetContentType.cxx
@@ -0,0 +1,92 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <sal/config.h>
+
+#include <cstring>
+
+#include <cppunit/TestAssert.h>
+#include <cppunit/TestFixture.h>
+#include <cppunit/TestSuite.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/plugin/TestPlugIn.h>
+#include <rtl/ustring.hxx>
+#include <svl/inettype.hxx>
+#include <tools/inetmime.hxx>
+
+namespace {
+
+class Test: public CppUnit::TestFixture {
+public:
+ void testBad();
+
+ void testFull();
+
+ void testFollow();
+
+ CPPUNIT_TEST_SUITE(Test);
+ CPPUNIT_TEST(testBad);
+ CPPUNIT_TEST(testFull);
+ CPPUNIT_TEST(testFollow);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+void Test::testBad() {
+ OUString in("foo=bar");
+ CPPUNIT_ASSERT_EQUAL(
+ static_cast<sal_Unicode const *>(0),
+ INetContentTypes::scan(in.getStr(), in.getStr() + in.getLength()));
+ OUString t;
+ OUString s;
+ INetContentTypeParameterList ps;
+ CPPUNIT_ASSERT(!INetContentTypes::parse(in, t, s, &ps));
+ CPPUNIT_ASSERT(t.isEmpty());
+ CPPUNIT_ASSERT(s.isEmpty());
+ CPPUNIT_ASSERT_EQUAL(
+ static_cast<INetContentTypeParameter const *>(0), ps.find("foo"));
+}
+
+void Test::testFull() {
+ OUString in("foo/bar;baz=boz");
+ CPPUNIT_ASSERT_EQUAL(
+ in.getStr() + in.getLength(),
+ INetContentTypes::scan(in.getStr(), in.getStr() + in.getLength()));
+ OUString t;
+ OUString s;
+ INetContentTypeParameterList ps;
+ CPPUNIT_ASSERT(INetContentTypes::parse(in, t, s, &ps));
+ CPPUNIT_ASSERT_EQUAL(OUString("foo"), t);
+ CPPUNIT_ASSERT_EQUAL(OUString("bar"), s);
+ INetContentTypeParameter const * p = ps.find("baz");
+ CPPUNIT_ASSERT(p != 0);
+ CPPUNIT_ASSERT_EQUAL(OUString("boz"), p->m_sValue);
+}
+
+void Test::testFollow() {
+ OUString in("foo/bar;baz=boz;base64,");
+ CPPUNIT_ASSERT_EQUAL(
+ in.getStr() + std::strlen("foo/bar;baz=boz"),
+ INetContentTypes::scan(in.getStr(), in.getStr() + in.getLength()));
+ OUString t;
+ OUString s;
+ INetContentTypeParameterList ps;
+ CPPUNIT_ASSERT(!INetContentTypes::parse(in, t, s));
+ CPPUNIT_ASSERT(t.isEmpty());
+ CPPUNIT_ASSERT(s.isEmpty());
+ CPPUNIT_ASSERT_EQUAL(
+ static_cast<INetContentTypeParameter const *>(0), ps.find("baz"));
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(Test);
+
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */