xref: /haiku/src/tests/kits/locale/LanguageTest.cpp (revision 866b1c0efe28571c400feb1792bef43e5e8a6c74)
1d7f449e9SAdrien Destugues /*
2564de192SAndrew Lindesay  * Copyright 2014-2021 Haiku, Inc.
3d7f449e9SAdrien Destugues  * Distributed under the terms of the MIT License.
4d7f449e9SAdrien Destugues  */
5d7f449e9SAdrien Destugues 
6d7f449e9SAdrien Destugues 
7d7f449e9SAdrien Destugues #include "LanguageTest.h"
8d7f449e9SAdrien Destugues 
9d7f449e9SAdrien Destugues #include "Language.h"
10d7f449e9SAdrien Destugues 
11d7f449e9SAdrien Destugues #include <cppunit/TestCaller.h>
12d7f449e9SAdrien Destugues #include <cppunit/TestSuite.h>
13d7f449e9SAdrien Destugues 
14d7f449e9SAdrien Destugues 
LanguageTest()15d7f449e9SAdrien Destugues LanguageTest::LanguageTest()
16d7f449e9SAdrien Destugues {
17d7f449e9SAdrien Destugues }
18d7f449e9SAdrien Destugues 
19d7f449e9SAdrien Destugues 
~LanguageTest()20d7f449e9SAdrien Destugues LanguageTest::~LanguageTest()
21d7f449e9SAdrien Destugues {
22d7f449e9SAdrien Destugues }
23d7f449e9SAdrien Destugues 
24d7f449e9SAdrien Destugues 
25d7f449e9SAdrien Destugues void
TestLanguageParseJapanese()26*866b1c0eSAndrew Lindesay LanguageTest::TestLanguageParseJapanese()
27*866b1c0eSAndrew Lindesay {
28*866b1c0eSAndrew Lindesay 	// GIVEN
29*866b1c0eSAndrew Lindesay 
30*866b1c0eSAndrew Lindesay 	// WHEN
31*866b1c0eSAndrew Lindesay 	BLanguage language("jp");
32*866b1c0eSAndrew Lindesay 
33*866b1c0eSAndrew Lindesay 	// THEN
34*866b1c0eSAndrew Lindesay 	CPPUNIT_ASSERT_EQUAL(BString("jp"), language.ID());
35*866b1c0eSAndrew Lindesay 	CPPUNIT_ASSERT_EQUAL(BString("jp"), language.Code());
36*866b1c0eSAndrew Lindesay 	CPPUNIT_ASSERT_EQUAL(BString(""), language.ScriptCode());
37*866b1c0eSAndrew Lindesay 	CPPUNIT_ASSERT_EQUAL(BString(""), language.CountryCode());
38*866b1c0eSAndrew Lindesay }
39*866b1c0eSAndrew Lindesay 
40*866b1c0eSAndrew Lindesay 
41*866b1c0eSAndrew Lindesay void
TestLanguageParseFrenchWithCountry()42*866b1c0eSAndrew Lindesay LanguageTest::TestLanguageParseFrenchWithCountry()
43*866b1c0eSAndrew Lindesay {
44*866b1c0eSAndrew Lindesay 	// GIVEN
45*866b1c0eSAndrew Lindesay 
46*866b1c0eSAndrew Lindesay 	// WHEN
47*866b1c0eSAndrew Lindesay 	BLanguage language("fr_FR");
48*866b1c0eSAndrew Lindesay 
49*866b1c0eSAndrew Lindesay 	// THEN
50*866b1c0eSAndrew Lindesay 	CPPUNIT_ASSERT_EQUAL(BString("fr_FR"), language.ID());
51*866b1c0eSAndrew Lindesay 	CPPUNIT_ASSERT_EQUAL(BString("fr"), language.Code());
52*866b1c0eSAndrew Lindesay 	CPPUNIT_ASSERT_EQUAL(BString(""), language.ScriptCode());
53*866b1c0eSAndrew Lindesay 	CPPUNIT_ASSERT_EQUAL(BString("FR"), language.CountryCode());
54*866b1c0eSAndrew Lindesay }
55*866b1c0eSAndrew Lindesay 
56*866b1c0eSAndrew Lindesay 
57*866b1c0eSAndrew Lindesay void
TestLanguageParseSerbianScriptAndCountry()58*866b1c0eSAndrew Lindesay LanguageTest::TestLanguageParseSerbianScriptAndCountry()
59*866b1c0eSAndrew Lindesay {
60*866b1c0eSAndrew Lindesay 	// GIVEN
61*866b1c0eSAndrew Lindesay 
62*866b1c0eSAndrew Lindesay 	// WHEN
63*866b1c0eSAndrew Lindesay 	BLanguage language("sr_Latn_BA");
64*866b1c0eSAndrew Lindesay 
65*866b1c0eSAndrew Lindesay 	// THEN
66*866b1c0eSAndrew Lindesay 	CPPUNIT_ASSERT_EQUAL(BString("sr_Latn_BA"), language.ID());
67*866b1c0eSAndrew Lindesay 	CPPUNIT_ASSERT_EQUAL(BString("sr"), language.Code());
68*866b1c0eSAndrew Lindesay 	CPPUNIT_ASSERT_EQUAL(BString("BA"), language.CountryCode());
69*866b1c0eSAndrew Lindesay 	CPPUNIT_ASSERT_EQUAL(BString("Latn"), language.ScriptCode());
70*866b1c0eSAndrew Lindesay }
71*866b1c0eSAndrew Lindesay 
72*866b1c0eSAndrew Lindesay 
73*866b1c0eSAndrew Lindesay void
TestLanguageParseSerbianScriptAndCountryHyphens()74*866b1c0eSAndrew Lindesay LanguageTest::TestLanguageParseSerbianScriptAndCountryHyphens()
75*866b1c0eSAndrew Lindesay {
76*866b1c0eSAndrew Lindesay 	// GIVEN
77*866b1c0eSAndrew Lindesay 
78*866b1c0eSAndrew Lindesay 	// WHEN
79*866b1c0eSAndrew Lindesay 	BLanguage language("sr-Latn-BA");
80*866b1c0eSAndrew Lindesay 
81*866b1c0eSAndrew Lindesay 	// THEN
82*866b1c0eSAndrew Lindesay 	CPPUNIT_ASSERT_EQUAL(BString("sr_Latn_BA"), language.ID());
83*866b1c0eSAndrew Lindesay 	CPPUNIT_ASSERT_EQUAL(BString("sr"), language.Code());
84*866b1c0eSAndrew Lindesay 	CPPUNIT_ASSERT_EQUAL(BString("BA"), language.CountryCode());
85*866b1c0eSAndrew Lindesay 	CPPUNIT_ASSERT_EQUAL(BString("Latn"), language.ScriptCode());
86*866b1c0eSAndrew Lindesay }
87*866b1c0eSAndrew Lindesay 
88*866b1c0eSAndrew Lindesay 
89*866b1c0eSAndrew Lindesay void
TestLanguageNameFrenchInEnglish()90564de192SAndrew Lindesay LanguageTest::TestLanguageNameFrenchInEnglish()
91d7f449e9SAdrien Destugues {
92564de192SAndrew Lindesay 	// GIVEN
93564de192SAndrew Lindesay 	BLanguage languageFrench("fr_FR");
94564de192SAndrew Lindesay 	BLanguage languageEnglish("en_US");
95d7f449e9SAdrien Destugues 	BString name;
96564de192SAndrew Lindesay 
97564de192SAndrew Lindesay 	// WHEN
98564de192SAndrew Lindesay 	languageFrench.GetName(name, &languageEnglish);
99564de192SAndrew Lindesay 		// get the name of French in English
100564de192SAndrew Lindesay 
101564de192SAndrew Lindesay 	// THEN
102564de192SAndrew Lindesay 	CPPUNIT_ASSERT_EQUAL(BString("French (France)"), name);
103564de192SAndrew Lindesay }
104564de192SAndrew Lindesay 
105564de192SAndrew Lindesay 
106564de192SAndrew Lindesay void
TestLanguageNameFrenchInFrench()107564de192SAndrew Lindesay LanguageTest::TestLanguageNameFrenchInFrench()
108564de192SAndrew Lindesay {
109564de192SAndrew Lindesay 	// GIVEN
110564de192SAndrew Lindesay 	BLanguage languageFrench("fr_FR");
111564de192SAndrew Lindesay 	BString name;
112564de192SAndrew Lindesay 
113564de192SAndrew Lindesay 	// WHEN
114564de192SAndrew Lindesay 	languageFrench.GetName(name, &languageFrench);
115564de192SAndrew Lindesay 		// get the name of French in French
116564de192SAndrew Lindesay 
117564de192SAndrew Lindesay 	// THEN
118d7f449e9SAdrien Destugues 	CPPUNIT_ASSERT_EQUAL(BString("français (France)"), name);
119564de192SAndrew Lindesay }
120564de192SAndrew Lindesay 
121564de192SAndrew Lindesay 
122564de192SAndrew Lindesay void
TestLanguagePropertiesFrench()123564de192SAndrew Lindesay LanguageTest::TestLanguagePropertiesFrench()
124564de192SAndrew Lindesay {
125564de192SAndrew Lindesay 	// GIVEN
126564de192SAndrew Lindesay 	BLanguage language("fr_FR");
127564de192SAndrew Lindesay 
128564de192SAndrew Lindesay 	// WHEN
129564de192SAndrew Lindesay 
130564de192SAndrew Lindesay 	// THEN
131d7f449e9SAdrien Destugues 	CPPUNIT_ASSERT_EQUAL(BString("fr"), language.Code());
132d7f449e9SAdrien Destugues 	CPPUNIT_ASSERT(language.Direction() == B_LEFT_TO_RIGHT);
133d7f449e9SAdrien Destugues }
134d7f449e9SAdrien Destugues 
135d7f449e9SAdrien Destugues 
136d7f449e9SAdrien Destugues /*static*/ void
AddTests(BTestSuite & parent)137d7f449e9SAdrien Destugues LanguageTest::AddTests(BTestSuite& parent)
138d7f449e9SAdrien Destugues {
139d7f449e9SAdrien Destugues 	CppUnit::TestSuite& suite = *new CppUnit::TestSuite("LanguageTest");
140d7f449e9SAdrien Destugues 
141d7f449e9SAdrien Destugues 	suite.addTest(new CppUnit::TestCaller<LanguageTest>(
142*866b1c0eSAndrew Lindesay 		"LanguageTest::TestLanguageParseJapanese",
143*866b1c0eSAndrew Lindesay 		&LanguageTest::TestLanguageParseJapanese));
144*866b1c0eSAndrew Lindesay 	suite.addTest(new CppUnit::TestCaller<LanguageTest>(
145*866b1c0eSAndrew Lindesay 		"LanguageTest::TestLanguageParseFrenchWithCountry",
146*866b1c0eSAndrew Lindesay 		&LanguageTest::TestLanguageParseFrenchWithCountry));
147*866b1c0eSAndrew Lindesay 	suite.addTest(new CppUnit::TestCaller<LanguageTest>(
148*866b1c0eSAndrew Lindesay 		"LanguageTest::TestLanguageParseSerbianScriptAndCountry",
149*866b1c0eSAndrew Lindesay 		&LanguageTest::TestLanguageParseSerbianScriptAndCountry));
150*866b1c0eSAndrew Lindesay 	suite.addTest(new CppUnit::TestCaller<LanguageTest>(
151*866b1c0eSAndrew Lindesay 		"LanguageTest::TestLanguageParseSerbianScriptAndCountryHyphens",
152*866b1c0eSAndrew Lindesay 		&LanguageTest::TestLanguageParseSerbianScriptAndCountryHyphens));
153*866b1c0eSAndrew Lindesay 
154*866b1c0eSAndrew Lindesay 	suite.addTest(new CppUnit::TestCaller<LanguageTest>(
155564de192SAndrew Lindesay 		"LanguageTest::TestLanguageNameFrenchInEnglish",
156564de192SAndrew Lindesay 		&LanguageTest::TestLanguageNameFrenchInEnglish));
157564de192SAndrew Lindesay 	suite.addTest(new CppUnit::TestCaller<LanguageTest>(
158564de192SAndrew Lindesay 		"LanguageTest::TestLanguageNameFrenchInFrench",
159564de192SAndrew Lindesay 		&LanguageTest::TestLanguageNameFrenchInFrench));
160564de192SAndrew Lindesay 	suite.addTest(new CppUnit::TestCaller<LanguageTest>(
161564de192SAndrew Lindesay 		"LanguageTest::TestLanguagePropertiesFrench",
162564de192SAndrew Lindesay 		&LanguageTest::TestLanguagePropertiesFrench));
163d7f449e9SAdrien Destugues 
164d7f449e9SAdrien Destugues 	parent.addTest("LanguageTest", &suite);
165d7f449e9SAdrien Destugues }
166