Ticket #13688: 0002-BDateFormatTest-Add-tests-for-day-and-month-names-fo.patch

File 0002-BDateFormatTest-Add-tests-for-day-and-month-names-fo.patch, 4.0 KB (added by akshay, 7 years ago)
  • src/tests/kits/locale/DateFormatTest.cpp

    From b48abf612e8df9bdf538732def6d620d96d4fd76 Mon Sep 17 00:00:00 2001
    From: Akshay Agarwal <agarwal.akshay.akshay8@gmail.com>
    Date: Thu, 31 Aug 2017 01:20:09 +0530
    Subject: [PATCH 2/2] BDateFormatTest: Add tests for day and month names for
     all format syles.
    
    ---
     src/tests/kits/locale/DateFormatTest.cpp | 85 ++++++++++++++++++++++++++++++++
     src/tests/kits/locale/DateFormatTest.h   |  1 +
     2 files changed, 86 insertions(+)
    
    diff --git a/src/tests/kits/locale/DateFormatTest.cpp b/src/tests/kits/locale/DateFormatTest.cpp
    index 856ecd4..f33743f 100644
    a b DateFormatTest::TestMonthNames()  
    217217
    218218    CPPUNIT_ASSERT_EQUAL(BString("December"), buffer);
    219219    CPPUNIT_ASSERT_EQUAL(B_OK, result);
     220
     221    buffer.Truncate(0);
     222    result = format.GetMonthName(1, buffer, B_LONG_DATE_FORMAT);
     223
     224    CPPUNIT_ASSERT_EQUAL(BString("Jan"), buffer);
     225    CPPUNIT_ASSERT_EQUAL(B_OK, result);
     226
     227    buffer.Truncate(0);
     228    result = format.GetMonthName(12, buffer, B_LONG_DATE_FORMAT);
     229
     230    CPPUNIT_ASSERT_EQUAL(BString("Dec"), buffer);
     231    CPPUNIT_ASSERT_EQUAL(B_OK, result);
     232
     233    buffer.Truncate(0);
     234    result = format.GetMonthName(1, buffer, B_SHORT_DATE_FORMAT);
     235
     236    CPPUNIT_ASSERT_EQUAL(BString("J"), buffer);
     237    CPPUNIT_ASSERT_EQUAL(B_OK, result);
     238
     239    buffer.Truncate(0);
     240    result = format.GetMonthName(12, buffer, B_SHORT_DATE_FORMAT);
     241
     242    CPPUNIT_ASSERT_EQUAL(BString("D"), buffer);
     243    CPPUNIT_ASSERT_EQUAL(B_OK, result);
     244
    220245}
    221246
    222247
     248void
     249DateFormatTest::TestDayNames()
     250{
     251    BLanguage language("en");
     252    BFormattingConventions formatting("en_US");
     253    BDateFormat format(language, formatting);
     254
     255    BString buffer;
     256    status_t result = format.GetDayName(1, buffer);
     257
     258    CPPUNIT_ASSERT_EQUAL(BString("Sunday"), buffer);
     259    CPPUNIT_ASSERT_EQUAL(B_OK, result);
     260
     261    buffer.Truncate(0);
     262    result = format.GetDayName(2, buffer);
     263
     264    CPPUNIT_ASSERT_EQUAL(BString("Monday"), buffer);
     265    CPPUNIT_ASSERT_EQUAL(B_OK, result);
     266
     267    buffer.Truncate(0);
     268    result = format.GetDayName(1, buffer, B_LONG_DATE_FORMAT);
     269
     270    CPPUNIT_ASSERT_EQUAL(BString("Sun"), buffer);
     271    CPPUNIT_ASSERT_EQUAL(B_OK, result);
     272
     273    buffer.Truncate(0);
     274    result = format.GetDayName(2, buffer, B_LONG_DATE_FORMAT);
     275
     276    CPPUNIT_ASSERT_EQUAL(BString("Mon"), buffer);
     277    CPPUNIT_ASSERT_EQUAL(B_OK, result);
     278
     279    buffer.Truncate(0);
     280    result = format.GetDayName(1, buffer, B_MEDIUM_DATE_FORMAT);
     281
     282    CPPUNIT_ASSERT_EQUAL(BString("Su"), buffer);
     283    CPPUNIT_ASSERT_EQUAL(B_OK, result);
     284
     285    buffer.Truncate(0);
     286    result = format.GetDayName(2, buffer, B_MEDIUM_DATE_FORMAT);
     287
     288    CPPUNIT_ASSERT_EQUAL(BString("Mo"), buffer);
     289    CPPUNIT_ASSERT_EQUAL(B_OK, result);
     290
     291    buffer.Truncate(0);
     292    result = format.GetDayName(1, buffer, B_SHORT_DATE_FORMAT);
     293
     294    CPPUNIT_ASSERT_EQUAL(BString("S"), buffer);
     295    CPPUNIT_ASSERT_EQUAL(B_OK, result);
     296
     297    buffer.Truncate(0);
     298    result = format.GetDayName(2, buffer, B_SHORT_DATE_FORMAT);
     299
     300    CPPUNIT_ASSERT_EQUAL(BString("M"), buffer);
     301    CPPUNIT_ASSERT_EQUAL(B_OK, result);
     302}
     303
     304
     305
    223306std::ostream& operator<<(std::ostream& stream, const BDate& date)
    224307{
    225308    stream << date.Year();
    DateFormatTest::AddTests(BTestSuite& parent)  
    320403    suite.addTest(new CppUnit::TestCaller<DateFormatTest>(
    321404        "DateFormatTest::TestMonthNames", &DateFormatTest::TestMonthNames));
    322405    suite.addTest(new CppUnit::TestCaller<DateFormatTest>(
     406        "DateFormatTest::TestDayNames", &DateFormatTest::TestDayNames));
     407    suite.addTest(new CppUnit::TestCaller<DateFormatTest>(
    323408        "DateFormatTest::TestParseDate", &DateFormatTest::TestParseDate));
    324409    suite.addTest(new CppUnit::TestCaller<DateFormatTest>(
    325410        "DateFormatTest::TestParseTime", &DateFormatTest::TestParseTime));
  • src/tests/kits/locale/DateFormatTest.h

    diff --git a/src/tests/kits/locale/DateFormatTest.h b/src/tests/kits/locale/DateFormatTest.h
    index 9c99ff6..6217bc8 100644
    a b public:  
    1919            void    TestFormat();
    2020            void    TestFormatDate();
    2121            void    TestMonthNames();
     22            void    TestDayNames();
    2223            void    TestParseDate();
    2324            void    TestParseTime();
    2425