hrev51375 adds 1 changeset to branch 'master'
old head: 1e4ab34cd7fa368bfb8cb7f9a25c984e004e1344
new head: cf911230410f2d40ba1a118ad6be5085a49470f4
overview:
http://cgit.haiku-os.org/haiku/log/?qt=range&q=cf911230410f+%5E1e4ab34cd7fa
----------------------------------------------------------------------------
cf911230410f: Add unit tests for BRelativeDateTimeFormat.
Signed-off-by: Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
[ Akshay Agarwal <agarwal.akshay.akshay8@xxxxxxxxx> ]
----------------------------------------------------------------------------
Revision: hrev51375
Commit: cf911230410f2d40ba1a118ad6be5085a49470f4
URL: http://cgit.haiku-os.org/haiku/commit/?id=cf911230410f
Author: Akshay Agarwal <agarwal.akshay.akshay8@xxxxxxxxx>
Date: Sat Aug 26 04:48:10 2017 UTC
Committer: Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
Commit-Date: Sat Aug 26 07:02:52 2017 UTC
----------------------------------------------------------------------------
4 files changed, 155 insertions(+)
src/tests/kits/locale/Jamfile | 1 +
src/tests/kits/locale/LocaleKitTestAddon.cpp | 2 +
.../kits/locale/RelativeDateTimeFormatTest.cpp | 124 +++++++++++++++++++
.../kits/locale/RelativeDateTimeFormatTest.h | 28 +++++
----------------------------------------------------------------------------
diff --git a/src/tests/kits/locale/Jamfile b/src/tests/kits/locale/Jamfile
index 2184393..20e1e4b 100644
--- a/src/tests/kits/locale/Jamfile
+++ b/src/tests/kits/locale/Jamfile
@@ -51,6 +51,7 @@ UnitTestLib localekittest.so :
DurationFormatTest.cpp
LanguageTest.cpp
MessageFormatTest.cpp
+ RelativeDateTimeFormatTest.cpp
UnicodeCharTest.cpp
: be [ TargetLibstdc++ ]
diff --git a/src/tests/kits/locale/LocaleKitTestAddon.cpp
b/src/tests/kits/locale/LocaleKitTestAddon.cpp
index 2d04a79..01ea7d2 100644
--- a/src/tests/kits/locale/LocaleKitTestAddon.cpp
+++ b/src/tests/kits/locale/LocaleKitTestAddon.cpp
@@ -12,6 +12,7 @@
#include "DurationFormatTest.h"
#include "LanguageTest.h"
#include "MessageFormatTest.h"
+#include "RelativeDateTimeFormatTest.h"
#include "UnicodeCharTest.h"
@@ -25,6 +26,7 @@ getTestSuite()
DurationFormatTest::AddTests(*suite);
LanguageTest::AddTests(*suite);
MessageFormatTest::AddTests(*suite);
+ RelativeDateTimeFormatTest::AddTests(*suite);
UnicodeCharTest::AddTests(*suite);
return suite;
diff --git a/src/tests/kits/locale/RelativeDateTimeFormatTest.cpp
b/src/tests/kits/locale/RelativeDateTimeFormatTest.cpp
new file mode 100644
index 0000000..9307b4b
--- /dev/null
+++ b/src/tests/kits/locale/RelativeDateTimeFormatTest.cpp
@@ -0,0 +1,124 @@
+/*
+ * Copyright 2017, Haiku, Inc. All Rights Reserved.
+ * Distributed under the terms of the MIT License.
+ *
+ * Authors:
+ * Akshay Agarwal <agarwal.akshay.akshay8@xxxxxxxxx>
+ */
+
+#include "RelativeDateTimeFormatTest.h"
+
+#include <time.h>
+
+#include <Locale.h>
+#include <RelativeDateTimeFormat.h>
+
+#include <cppunit/TestCaller.h>
+#include <cppunit/TestSuite.h>
+
+
+const int kMonthsPerYear = 12;
+const int kMaxDaysPerMonth = 31;
+const int kDaysPerWeek = 7;
+const int kHoursPerDay = 24;
+const int kMinutesPerHour = 60;
+const int kSecondsPerMinute = 60;
+
+
+RelativeDateTimeFormatTest::RelativeDateTimeFormatTest()
+{
+}
+
+
+RelativeDateTimeFormatTest::~RelativeDateTimeFormatTest()
+{
+}
+
+
+void
+RelativeDateTimeFormatTest::TestDefault()
+{
+ BRelativeDateTimeFormat format;
+ BString buffer;
+ BString expected;
+
+ status_t result = format.Format(buffer, time(NULL));
+ 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
+RelativeDateTimeFormatTest::TestFormat()
+{
+ struct Value {
+ const char* language;
+ const char* convention;
+ time_t timeDelta;
+ const char* relativeDate;
+ };
+
+ static const Value values[] = {
+ {"en", "en_US", 0, "in 0 seconds"},
+ {"en", "en_US", 20, "in 20 seconds"},
+ {"en", "en_US", -20, "20 seconds ago"},
+ {"en", "en_US", 5 * kSecondsPerMinute, "in 5 minutes"},
+ {"en", "en_US", -5 * kSecondsPerMinute, "5 minutes ago"},
+ {"en", "en_US", 2 * kMinutesPerHour * kSecondsPerMinute, "in 2
hours"},
+ {"en", "en_US", -2 * kMinutesPerHour * kSecondsPerMinute, "2
hours ago"},
+ {"fr", "fr_FR", 2 * kMinutesPerHour * kSecondsPerMinute, "dans
2 heures"},
+ {"fr", "fr_FR", -2 * kMinutesPerHour * kSecondsPerMinute, "il y
a 2 heures"},
+ {"en", "en_US", 5 * kHoursPerDay * kMinutesPerHour *
kSecondsPerMinute,
+ "in 5 days"},
+ {"en", "en_US", -5 * kHoursPerDay * kMinutesPerHour *
kSecondsPerMinute,
+ "5 days ago"},
+ {"de", "de_DE", 5 * kHoursPerDay * kMinutesPerHour *
kSecondsPerMinute,
+ "in 5 Tagen"},
+ {"de", "de_DE", -5 * kHoursPerDay * kMinutesPerHour *
kSecondsPerMinute,
+ "vor 5 Tagen"},
+ {"en", "en_US", 3 * kDaysPerWeek * kHoursPerDay *
kMinutesPerHour
+ * kSecondsPerMinute, "in 3 weeks"},
+ {"en", "en_US", -3 * kDaysPerWeek * kHoursPerDay *
kMinutesPerHour
+ * kSecondsPerMinute, "3 weeks ago"},
+ {"en", "en_US", 4 * kMaxDaysPerMonth * kHoursPerDay *
kMinutesPerHour
+ * kSecondsPerMinute, "in 4 months"},
+ {"en", "en_US", -4 * kMaxDaysPerMonth * kHoursPerDay *
kMinutesPerHour
+ * kSecondsPerMinute, "4 months ago"},
+ {"en", "en_US", 2 * kMonthsPerYear * kMaxDaysPerMonth *
kHoursPerDay
+ * kMinutesPerHour * kSecondsPerMinute, "in 2 years"},
+ {"en", "en_US", -2 * kMonthsPerYear * kMaxDaysPerMonth *
kHoursPerDay
+ * kMinutesPerHour * kSecondsPerMinute, "2 years ago"},
+ {NULL}
+ };
+
+ status_t result;
+
+ for (int i = 0; values[i].language != NULL; i++) {
+ NextSubTest();
+
+ BString output;
+ BLanguage language(values[i].language);
+ BFormattingConventions formatting(values[i].convention);
+ BRelativeDateTimeFormat format(language, formatting);
+
+ result = format.Format(output, time(NULL) +
values[i].timeDelta);
+ CPPUNIT_ASSERT_EQUAL(B_OK, result);
+ CPPUNIT_ASSERT_EQUAL(BString(values[i].relativeDate), output);
+ }
+}
+
+
+/*static*/ void
+RelativeDateTimeFormatTest::AddTests(BTestSuite& parent)
+{
+ CppUnit::TestSuite& suite = *new
CppUnit::TestSuite("RelativeDateTimeFormatTest");
+
+ suite.addTest(new CppUnit::TestCaller<RelativeDateTimeFormatTest>(
+ "RelativeDateTimeFormatTest::TestDefault",
&RelativeDateTimeFormatTest::TestDefault));
+ suite.addTest(new CppUnit::TestCaller<RelativeDateTimeFormatTest>(
+ "RelativeDateTimeFormatTest::TestFormat",
&RelativeDateTimeFormatTest::TestFormat));
+ parent.addTest("RelativeDateTimeFormatTest", &suite);
+}
diff --git a/src/tests/kits/locale/RelativeDateTimeFormatTest.h
b/src/tests/kits/locale/RelativeDateTimeFormatTest.h
new file mode 100644
index 0000000..adaa13c
--- /dev/null
+++ b/src/tests/kits/locale/RelativeDateTimeFormatTest.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2017, Haiku, Inc. All Rights Reserved.
+ * Distributed under the terms of the MIT License.
+ *
+ * Authors:
+ * Akshay Agarwal <agarwal.akshay.akshay8@xxxxxxxxx>
+ */
+#ifndef RELATIVE_DATE_TIME_FORMAT_TEST_H
+#define RELATIVE_DATE_TIME_FORMAT_TEST_H
+
+
+#include <TestCase.h>
+#include <TestSuite.h>
+
+
+class RelativeDateTimeFormatTest: public BTestCase {
+public:
+ RelativeDateTimeFormatTest();
+ virtual ~RelativeDateTimeFormatTest();
+
+ void TestDefault();
+ void TestFormat();
+
+ static void AddTests(BTestSuite& suite);
+};
+
+
+#endif