MimeTypeTest.hxx 1.46 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Unit tests for src/util/
 */

#include "check.h"
#include "util/MimeType.hxx"

#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>

#include <string.h>

class MimeTypeTest : public CppUnit::TestFixture {
	CPPUNIT_TEST_SUITE(MimeTypeTest);
	CPPUNIT_TEST(TestBase);
16
	CPPUNIT_TEST(TestParameters);
17 18 19 20 21 22 23 24 25 26 27 28
	CPPUNIT_TEST_SUITE_END();

public:
	void TestBase() {
		CPPUNIT_ASSERT("" == GetMimeTypeBase(""));
		CPPUNIT_ASSERT("" == GetMimeTypeBase(";"));
		CPPUNIT_ASSERT("foo" == GetMimeTypeBase("foo"));
		CPPUNIT_ASSERT("foo/bar" == GetMimeTypeBase("foo/bar"));
		CPPUNIT_ASSERT("foo/bar" == GetMimeTypeBase("foo/bar;"));
		CPPUNIT_ASSERT("foo/bar" == GetMimeTypeBase("foo/bar; x=y"));
		CPPUNIT_ASSERT("foo/bar" == GetMimeTypeBase("foo/bar;x=y"));
	}
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

	void TestParameters() {
		CPPUNIT_ASSERT(ParseMimeTypeParameters("").empty());
		CPPUNIT_ASSERT(ParseMimeTypeParameters("foo/bar").empty());
		CPPUNIT_ASSERT(ParseMimeTypeParameters("foo/bar;").empty());
		CPPUNIT_ASSERT(ParseMimeTypeParameters("foo/bar;garbage").empty());
		CPPUNIT_ASSERT(ParseMimeTypeParameters("foo/bar; garbage").empty());

		auto p = ParseMimeTypeParameters("foo/bar;a=b");
		CPPUNIT_ASSERT(!p.empty());
		CPPUNIT_ASSERT(p["a"] == "b");
		CPPUNIT_ASSERT(p.size() == 1);

		p = ParseMimeTypeParameters("foo/bar; a=b;c;d=e ; f=g ");
		CPPUNIT_ASSERT(!p.empty());
		CPPUNIT_ASSERT(p["a"] == "b");
		CPPUNIT_ASSERT(p["d"] == "e");
		CPPUNIT_ASSERT(p["f"] == "g");
		CPPUNIT_ASSERT(p.size() == 3);
	}
49
};