#include "DurationFormatTest.h"
#include <DurationFormat.h>
#include <Locale.h>
#include <cppunit/TestCaller.h>
#include <cppunit/TestSuite.h>
DurationFormatTest::DurationFormatTest()
{
}
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);
CPPUNIT_ASSERT(buffer.Length() > 0);
}
void
DurationFormatTest::TestDuration()
{
BString buffer;
BString expected;
status_t result;
BFormattingConventions englishFormat("en_US");
BLanguage englishLanguage("en");
BFormattingConventions frenchFormat("fr_FR");
BLanguage frenchLanguage("fr");
{
BDurationFormat format(englishLanguage, englishFormat);
status_t result = format.Format(buffer, 0, 800000000000ll);
expected << "1 week, 2 days, 6 hours, 13 minutes, 20 seconds";
CPPUNIT_ASSERT_EQUAL(B_OK, result);
CPPUNIT_ASSERT_EQUAL(expected, buffer);
}
{
BDurationFormat format(frenchLanguage, frenchFormat);
result = format.Format(buffer, 0, 800000000000ll);
expected << "1\xc2\xa0semaine, 2\xc2\xa0jours, 6\xc2\xa0heures, "
"13 minutes, 20\xc2\xa0secondes";
CPPUNIT_ASSERT_EQUAL(B_OK, result);
CPPUNIT_ASSERT_EQUAL(expected, buffer);
}
{
BDurationFormat format(englishLanguage, englishFormat,
":", B_TIME_UNIT_ABBREVIATED);
status_t result = format.Format(buffer, 0, 800000000000ll);
expected << "1 wk:2 days:6 hr:13 min:20 sec";
CPPUNIT_ASSERT_EQUAL(B_OK, result);
CPPUNIT_ASSERT_EQUAL(expected, buffer);
}
{
BDurationFormat format(frenchLanguage, frenchFormat,
":", B_TIME_UNIT_ABBREVIATED);
result = format.Format(buffer, 0, 800000000000ll);
expected << "1\xe2\x80\xafsem.:2\xe2\x80\xafj:6\xe2\x80\xafh:"
"13\xc2\xa0min:20\xe2\x80\xafs";
CPPUNIT_ASSERT_EQUAL(B_OK, result);
CPPUNIT_ASSERT_EQUAL(expected, buffer);
}
}
void
DurationFormatTest::TestTimeUnit()
{
BString buffer;
status_t result;
BFormattingConventions englishFormat("en_US");
BLanguage englishLanguage("en");
BFormattingConventions frenchFormat("fr_FR");
BLanguage frenchLanguage("fr");
{
BTimeUnitFormat format(englishLanguage, englishFormat);
result = format.Format(buffer, 5, B_TIME_UNIT_HOUR);
CPPUNIT_ASSERT_EQUAL(B_OK, result);
CPPUNIT_ASSERT_EQUAL(BString("5 hours"), buffer);
}
{
BTimeUnitFormat format(frenchLanguage, frenchFormat);
result = format.Format(buffer, 5, B_TIME_UNIT_HOUR);
CPPUNIT_ASSERT_EQUAL(B_OK, result);
CPPUNIT_ASSERT_EQUAL(BString("5 hours5\xc2\xa0heures"), buffer);
}
}
void
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>(
"DurationFormatTest::TestTimeUnit", &DurationFormatTest::TestTimeUnit));
parent.addTest("DurationFormatTest", &suite);
}