File: test_utils.cpp

package info (click to toggle)
libmusicbrainz3 3.0.1-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 848 kB
  • ctags: 977
  • sloc: cpp: 7,302; xml: 882; ansic: 455; makefile: 10
file content (93 lines) | stat: -rw-r--r-- 2,924 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <string>
#include <cppunit/extensions/HelperMacros.h>
#include <musicbrainz3/model.h>
#include <musicbrainz3/utils.h>

using namespace std;
using namespace MusicBrainz;

class UtilsTest : public CppUnit::TestFixture
{
	CPPUNIT_TEST_SUITE(UtilsTest);
	CPPUNIT_TEST(testExtractUuidArtist);
	CPPUNIT_TEST(testExtractUuidRelease);
	CPPUNIT_TEST(testExtractUuidTrack);
	CPPUNIT_TEST(testExtractFragment);
	CPPUNIT_TEST(testGetCountryName);
	CPPUNIT_TEST(testGetLanguageName);
	CPPUNIT_TEST(testGetScriptName);
	CPPUNIT_TEST(testGetReleaseTypeName);
	CPPUNIT_TEST_SUITE_END();
	
protected:

	void testExtractUuidArtist()
	{
		string artistPrefix = "http://musicbrainz.org/artist/";
		string uuid = "c0b2500e-0cef-4130-869d-732b23ed9df5";
		string mbid = artistPrefix + uuid;
		CPPUNIT_ASSERT_EQUAL(string(), extractUuid(string()));
		CPPUNIT_ASSERT_EQUAL(uuid, extractUuid(uuid));
		CPPUNIT_ASSERT_EQUAL(uuid, extractUuid(mbid));
	}

	void testExtractUuidRelease()
	{
		string artistPrefix = "http://musicbrainz.org/release/";
		string uuid = "c0b2500e-0cef-4130-869d-732b23ed9df5";
		string mbid = artistPrefix + uuid;
		CPPUNIT_ASSERT_EQUAL(string(), extractUuid(string()));
		CPPUNIT_ASSERT_EQUAL(uuid, extractUuid(uuid));
		CPPUNIT_ASSERT_EQUAL(uuid, extractUuid(mbid));
	}

    void testExtractUuidTrack()
	{
		string artistPrefix = "http://musicbrainz.org/track/";
		string uuid = "c0b2500e-0cef-4130-869d-732b23ed9df5";
		string mbid = artistPrefix + uuid;
		CPPUNIT_ASSERT_EQUAL(string(), extractUuid(string()));
		CPPUNIT_ASSERT_EQUAL(uuid, extractUuid(uuid));
		CPPUNIT_ASSERT_EQUAL(uuid, extractUuid(mbid));
	}

	void testExtractFragment()
	{
		string fragment = "Album";
		string uri = NS_MMD_1 + fragment;
		CPPUNIT_ASSERT_EQUAL(string(), extractFragment(string()));
		CPPUNIT_ASSERT_EQUAL(fragment, extractFragment(fragment));
		CPPUNIT_ASSERT_EQUAL(fragment, extractFragment(uri));
	}
	
	void testGetCountryName()
	{
		CPPUNIT_ASSERT_EQUAL(string(), getCountryName("00"));
		CPPUNIT_ASSERT_EQUAL(string("Slovakia"), getCountryName("SK"));
		CPPUNIT_ASSERT_EQUAL(string("Czechoslovakia (historical, 1918-1992)"), getCountryName("XC"));
	}
	
	void testGetLanguageName()
	{
		CPPUNIT_ASSERT_EQUAL(string(), getLanguageName("000"));
		CPPUNIT_ASSERT_EQUAL(string("Slovak"), getLanguageName("SLK"));
		CPPUNIT_ASSERT_EQUAL(string("Czech"), getLanguageName("CES"));
	}
	
	void testGetScriptName()
	{
		CPPUNIT_ASSERT_EQUAL(string(), getScriptName("-"));
		CPPUNIT_ASSERT_EQUAL(string("Latin"), getScriptName("Latn"));
		CPPUNIT_ASSERT_EQUAL(string("Cyrillic"), getScriptName("Cyrl"));
	}
	
	void testGetReleaseTypeName()
	{
		CPPUNIT_ASSERT_EQUAL(string(), getReleaseTypeName("-"));
		CPPUNIT_ASSERT_EQUAL(string("Album"), getReleaseTypeName(Release::TYPE_ALBUM));
		CPPUNIT_ASSERT_EQUAL(string("Compilation"), getReleaseTypeName(Release::TYPE_COMPILATION));
	}
};

CPPUNIT_TEST_SUITE_REGISTRATION(UtilsTest);