Add tests for BDurationFormat and BTimeUnitFormat.
This commit is contained in:
@@ -0,0 +1,99 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2014 Haiku, Inc.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "DurationFormatTest.h"
|
||||||
|
|
||||||
|
#include <DurationFormat.h>
|
||||||
|
#include <Locale.h>
|
||||||
|
|
||||||
|
#include <cppunit/TestCaller.h>
|
||||||
|
#include <cppunit/TestSuite.h>
|
||||||
|
|
||||||
|
|
||||||
|
DurationFormatTest::DurationFormatTest()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DurationFormatTest::~DurationFormatTest()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
DurationFormatTest::TestDuration()
|
||||||
|
{
|
||||||
|
BDurationFormat format;
|
||||||
|
BString buffer;
|
||||||
|
BString expected;
|
||||||
|
|
||||||
|
BFormattingConventions englishFormat("en_US");
|
||||||
|
BLanguage englishLanguage("en");
|
||||||
|
|
||||||
|
BFormattingConventions frenchFormat("fr_FR");
|
||||||
|
BLanguage frenchLanguage("fr");
|
||||||
|
|
||||||
|
format.SetFormattingConventions(englishFormat);
|
||||||
|
format.SetLanguage(englishLanguage);
|
||||||
|
status_t result = format.Format(0, 800000000000ll, &buffer);
|
||||||
|
|
||||||
|
expected << "1 week, 2 days, 6 hours, 13 minutes, 20 seconds";
|
||||||
|
CPPUNIT_ASSERT_EQUAL(B_OK, result);
|
||||||
|
CPPUNIT_ASSERT_EQUAL(expected, buffer);
|
||||||
|
|
||||||
|
format.SetFormattingConventions(frenchFormat);
|
||||||
|
format.SetLanguage(frenchLanguage);
|
||||||
|
result = format.Format(0, 800000000000ll, &buffer);
|
||||||
|
|
||||||
|
// We check that the passed BString is not truncated.
|
||||||
|
expected << "1 semaine, 2 jours, 6 heures, 13 minutes, 20 secondes";
|
||||||
|
CPPUNIT_ASSERT_EQUAL(B_OK, result);
|
||||||
|
CPPUNIT_ASSERT_EQUAL(expected, buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
DurationFormatTest::TestTimeUnit()
|
||||||
|
{
|
||||||
|
BTimeUnitFormat format;
|
||||||
|
BString buffer;
|
||||||
|
|
||||||
|
BFormattingConventions englishFormat("en_US");
|
||||||
|
BLanguage englishLanguage("en");
|
||||||
|
|
||||||
|
BFormattingConventions frenchFormat("fr_FR");
|
||||||
|
BLanguage frenchLanguage("fr");
|
||||||
|
|
||||||
|
format.SetFormattingConventions(englishFormat);
|
||||||
|
format.SetLanguage(englishLanguage);
|
||||||
|
status_t result = format.Format(5, B_TIME_UNIT_HOUR, &buffer);
|
||||||
|
|
||||||
|
CPPUNIT_ASSERT_EQUAL(B_OK, result);
|
||||||
|
CPPUNIT_ASSERT_EQUAL(BString("5 hours"), buffer);
|
||||||
|
|
||||||
|
format.SetFormattingConventions(frenchFormat);
|
||||||
|
format.SetLanguage(frenchLanguage);
|
||||||
|
result = format.Format(5, B_TIME_UNIT_HOUR, &buffer);
|
||||||
|
|
||||||
|
CPPUNIT_ASSERT_EQUAL(B_OK, result);
|
||||||
|
// We check that the passed BString is not truncated. This makes it easy
|
||||||
|
// to append several units to the same string, as BDurationFormat does.
|
||||||
|
CPPUNIT_ASSERT_EQUAL(BString("5 hours5 heures"), buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*static*/ void
|
||||||
|
DurationFormatTest::AddTests(BTestSuite& parent)
|
||||||
|
{
|
||||||
|
CppUnit::TestSuite& suite = *new CppUnit::TestSuite("DurationFormatTest");
|
||||||
|
|
||||||
|
suite.addTest(new CppUnit::TestCaller<DurationFormatTest>(
|
||||||
|
"DurationFormatTest::TestDuration", &DurationFormatTest::TestDuration));
|
||||||
|
suite.addTest(new CppUnit::TestCaller<DurationFormatTest>(
|
||||||
|
"DurationFormatTest::TestTimeUnit", &DurationFormatTest::TestTimeUnit));
|
||||||
|
|
||||||
|
parent.addTest("DurationFormatTest", &suite);
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2014 Haiku, Inc.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef DURATION_FORMAT_TEST_H
|
||||||
|
#define DURATION_FORMAT_TEST_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <TestCase.h>
|
||||||
|
#include <TestSuite.h>
|
||||||
|
|
||||||
|
|
||||||
|
class DurationFormatTest: public BTestCase {
|
||||||
|
public:
|
||||||
|
DurationFormatTest();
|
||||||
|
virtual ~DurationFormatTest();
|
||||||
|
|
||||||
|
void TestDuration();
|
||||||
|
void TestTimeUnit();
|
||||||
|
|
||||||
|
static void AddTests(BTestSuite& suite);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -51,6 +51,7 @@ UnitTestLib localekittest.so :
|
|||||||
|
|
||||||
CollatorTest.cpp
|
CollatorTest.cpp
|
||||||
DateFormatTest.cpp
|
DateFormatTest.cpp
|
||||||
|
DurationFormatTest.cpp
|
||||||
LanguageTest.cpp
|
LanguageTest.cpp
|
||||||
UnicodeCharTest.cpp
|
UnicodeCharTest.cpp
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include "CollatorTest.h"
|
#include "CollatorTest.h"
|
||||||
#include "DateFormatTest.h"
|
#include "DateFormatTest.h"
|
||||||
|
#include "DurationFormatTest.h"
|
||||||
#include "LanguageTest.h"
|
#include "LanguageTest.h"
|
||||||
#include "UnicodeCharTest.h"
|
#include "UnicodeCharTest.h"
|
||||||
|
|
||||||
@@ -20,6 +21,7 @@ getTestSuite()
|
|||||||
|
|
||||||
CollatorTest::AddTests(*suite);
|
CollatorTest::AddTests(*suite);
|
||||||
DateFormatTest::AddTests(*suite);
|
DateFormatTest::AddTests(*suite);
|
||||||
|
DurationFormatTest::AddTests(*suite);
|
||||||
LanguageTest::AddTests(*suite);
|
LanguageTest::AddTests(*suite);
|
||||||
UnicodeCharTest::AddTests(*suite);
|
UnicodeCharTest::AddTests(*suite);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user