1 /* 2 * Copyright 2021 Haiku, Inc. 3 * Distributed under the terms of the MIT License. 4 */ 5 #include "NumberFormatTest.h" 6 7 #include <NumberFormat.h> 8 #include <Locale.h> 9 10 #include <cppunit/TestCaller.h> 11 #include <cppunit/TestSuite.h> 12 13 14 NumberFormatTest::NumberFormatTest() 15 { 16 } 17 18 19 NumberFormatTest::~NumberFormatTest() 20 { 21 } 22 23 24 void 25 NumberFormatTest::TestPercentTurkish() 26 { 27 _TestGeneralPercent("tr", "%2"); 28 } 29 30 31 void 32 NumberFormatTest::TestPercentEnglish() 33 { 34 _TestGeneralPercent("en_US", "2%"); 35 } 36 37 38 void 39 NumberFormatTest::TestPercentGerman() 40 { 41 _TestGeneralPercent("de", "2\xc2\xa0%"); 42 // 2<non-breaking-space>% 43 } 44 45 46 void 47 NumberFormatTest::_TestGeneralPercent(const char* languageCode, 48 const char* expected) 49 { 50 // GIVEN 51 BLanguage turkishLanguage(languageCode); 52 BFormattingConventions formattingConventions(languageCode); 53 BLocale turkishLocale(&turkishLanguage, &formattingConventions); 54 BNumberFormat numberFormat(&turkishLocale); 55 BString output; 56 double input = 0.025; 57 58 // WHEN 59 status_t result = numberFormat.FormatPercent(output, input); 60 61 // THEN 62 CPPUNIT_ASSERT_EQUAL(B_OK, result); 63 CPPUNIT_ASSERT_EQUAL(BString(expected), output); 64 } 65 66 67 /*static*/ void 68 NumberFormatTest::AddTests(BTestSuite& parent) 69 { 70 CppUnit::TestSuite& suite = *new CppUnit::TestSuite("NumberFormatTest"); 71 72 suite.addTest(new CppUnit::TestCaller<NumberFormatTest>( 73 "NumberFormatTest::TestPercentTurkish", 74 &NumberFormatTest::TestPercentTurkish)); 75 suite.addTest(new CppUnit::TestCaller<NumberFormatTest>( 76 "NumberFormatTest::TestPercentEnglish", 77 &NumberFormatTest::TestPercentEnglish)); 78 suite.addTest(new CppUnit::TestCaller<NumberFormatTest>( 79 "NumberFormatTest::TestPercentGerman", 80 &NumberFormatTest::TestPercentGerman)); 81 82 parent.addTest("NumberFormatTest", &suite); 83 } 84