Fix initialization of BTimeUnitFormat

* The default constructor must configure it for the default locale
* Fix uptime not showing in AboutSystem
* Add a testcase for this
This commit is contained in:
Adrien Destugues 2014-10-02 10:23:31 +02:00
parent e3857211d3
commit df4a02e0fa
4 changed files with 21 additions and 3 deletions

View File

@ -10,9 +10,7 @@
BFormat::BFormat()
{
const BLocale* locale = BLocaleRoster::Default()->GetDefaultLocale();
fInitStatus = locale->GetFormattingConventions(&fConventions);
if (fInitStatus == B_OK)
fInitStatus = locale->GetLanguage(&fLanguage);
SetLocale(*locale);
}

View File

@ -39,6 +39,7 @@ BTimeUnitFormat::BTimeUnitFormat()
Inherited(),
fFormatter(NULL)
{
SetLanguage(fLanguage);
}

View File

@ -23,6 +23,22 @@ DurationFormatTest::~DurationFormatTest()
}
void
DurationFormatTest::TestDefault()
{
BDurationFormat format;
BString buffer;
BString expected;
status_t result = format.Format(buffer, 0, 800000000000ll);
CPPUNIT_ASSERT_EQUAL(B_OK, result);
// The exact format and language used depends on the locale settings, but
// we can assume that whatever they are, it should put something in the
// string.
CPPUNIT_ASSERT(buffer.Length() > 0);
}
void
DurationFormatTest::TestDuration()
{
@ -90,6 +106,8 @@ DurationFormatTest::AddTests(BTestSuite& parent)
{
CppUnit::TestSuite& suite = *new CppUnit::TestSuite("DurationFormatTest");
suite.addTest(new CppUnit::TestCaller<DurationFormatTest>(
"DurationFormatTest::TestDefault", &DurationFormatTest::TestDefault));
suite.addTest(new CppUnit::TestCaller<DurationFormatTest>(
"DurationFormatTest::TestDuration", &DurationFormatTest::TestDuration));
suite.addTest(new CppUnit::TestCaller<DurationFormatTest>(

View File

@ -15,6 +15,7 @@ public:
DurationFormatTest();
virtual ~DurationFormatTest();
void TestDefault();
void TestDuration();
void TestTimeUnit();