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

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

    From e1b5d850d44a0ced79e225a41fd68674da0155b1 Mon Sep 17 00:00:00 2001
    From: Akshay Agarwal <agarwal.akshay.akshay8@gmail.com>
    Date: Thu, 31 Aug 2017 02:12:26 +0530
    Subject: [PATCH 2/2] BDateFormatTest: Add tests for day and month names for
     all format syles.
    
    ---
     src/tests/kits/locale/DateFormatTest.cpp | 120 +++++++++++++++++++++++++++++++
     src/tests/kits/locale/DateFormatTest.h   |   1 +
     2 files changed, 121 insertions(+)
    
    diff --git a/src/tests/kits/locale/DateFormatTest.cpp b/src/tests/kits/locale/DateFormatTest.cpp
    index 856ecd4..20905f3 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_FULL_DATE_FORMAT);
     223
     224    CPPUNIT_ASSERT_EQUAL(BString("January"), buffer);
     225    CPPUNIT_ASSERT_EQUAL(B_OK, result);
     226
     227    buffer.Truncate(0);
     228    result = format.GetMonthName(12, buffer, B_FULL_DATE_FORMAT);
     229
     230    CPPUNIT_ASSERT_EQUAL(BString("December"), buffer);
     231    CPPUNIT_ASSERT_EQUAL(B_OK, result);
     232
     233    buffer.Truncate(0);
     234    result = format.GetMonthName(1, buffer, B_LONG_DATE_FORMAT);
     235
     236    CPPUNIT_ASSERT_EQUAL(BString("Jan"), buffer);
     237    CPPUNIT_ASSERT_EQUAL(B_OK, result);
     238
     239    buffer.Truncate(0);
     240    result = format.GetMonthName(12, buffer, B_LONG_DATE_FORMAT);
     241
     242    CPPUNIT_ASSERT_EQUAL(BString("Dec"), buffer);
     243    CPPUNIT_ASSERT_EQUAL(B_OK, result);
     244
     245    buffer.Truncate(0);
     246    result = format.GetMonthName(1, buffer, B_MEDIUM_DATE_FORMAT);
     247
     248    CPPUNIT_ASSERT_EQUAL(BString("Jan"), buffer);
     249    CPPUNIT_ASSERT_EQUAL(B_OK, result);
     250
     251    buffer.Truncate(0);
     252    result = format.GetMonthName(12, buffer, B_MEDIUM_DATE_FORMAT);
     253
     254    CPPUNIT_ASSERT_EQUAL(BString("Dec"), buffer);
     255    CPPUNIT_ASSERT_EQUAL(B_OK, result);
     256
     257    buffer.Truncate(0);
     258    result = format.GetMonthName(1, buffer, B_SHORT_DATE_FORMAT);
     259
     260    CPPUNIT_ASSERT_EQUAL(BString("J"), buffer);
     261    CPPUNIT_ASSERT_EQUAL(B_OK, result);
     262
     263    buffer.Truncate(0);
     264    result = format.GetMonthName(12, buffer, B_SHORT_DATE_FORMAT);
     265
     266    CPPUNIT_ASSERT_EQUAL(BString("D"), buffer);
     267    CPPUNIT_ASSERT_EQUAL(B_OK, result);
     268
     269}
     270
     271
     272void
     273DateFormatTest::TestDayNames()
     274{
     275    BLanguage language("en");
     276    BFormattingConventions formatting("en_US");
     277    BDateFormat format(language, formatting);
     278
     279    BString buffer;
     280    status_t result = format.GetDayName(1, buffer);
     281
     282    CPPUNIT_ASSERT_EQUAL(BString("Sunday"), buffer);
     283    CPPUNIT_ASSERT_EQUAL(B_OK, result);
     284
     285    buffer.Truncate(0);
     286    result = format.GetDayName(2, buffer);
     287
     288    CPPUNIT_ASSERT_EQUAL(BString("Monday"), buffer);
     289    CPPUNIT_ASSERT_EQUAL(B_OK, result);
     290
     291    buffer.Truncate(0);
     292    result = format.GetDayName(1, buffer, B_FULL_DATE_FORMAT);
     293
     294    CPPUNIT_ASSERT_EQUAL(BString("Sunday"), buffer);
     295    CPPUNIT_ASSERT_EQUAL(B_OK, result);
     296
     297    buffer.Truncate(0);
     298    result = format.GetDayName(2, buffer, B_FULL_DATE_FORMAT);
     299
     300    CPPUNIT_ASSERT_EQUAL(BString("Monday"), buffer);
     301    CPPUNIT_ASSERT_EQUAL(B_OK, result);
     302
     303    buffer.Truncate(0);
     304    result = format.GetDayName(1, buffer, B_LONG_DATE_FORMAT);
     305
     306    CPPUNIT_ASSERT_EQUAL(BString("Sun"), buffer);
     307    CPPUNIT_ASSERT_EQUAL(B_OK, result);
     308
     309    buffer.Truncate(0);
     310    result = format.GetDayName(2, buffer, B_LONG_DATE_FORMAT);
     311
     312    CPPUNIT_ASSERT_EQUAL(BString("Mon"), buffer);
     313    CPPUNIT_ASSERT_EQUAL(B_OK, result);
     314
     315    buffer.Truncate(0);
     316    result = format.GetDayName(1, buffer, B_MEDIUM_DATE_FORMAT);
     317
     318    CPPUNIT_ASSERT_EQUAL(BString("Su"), buffer);
     319    CPPUNIT_ASSERT_EQUAL(B_OK, result);
     320
     321    buffer.Truncate(0);
     322    result = format.GetDayName(2, buffer, B_MEDIUM_DATE_FORMAT);
     323
     324    CPPUNIT_ASSERT_EQUAL(BString("Mo"), buffer);
     325    CPPUNIT_ASSERT_EQUAL(B_OK, result);
     326
     327    buffer.Truncate(0);
     328    result = format.GetDayName(1, buffer, B_SHORT_DATE_FORMAT);
     329
     330    CPPUNIT_ASSERT_EQUAL(BString("S"), buffer);
     331    CPPUNIT_ASSERT_EQUAL(B_OK, result);
     332
     333    buffer.Truncate(0);
     334    result = format.GetDayName(2, buffer, B_SHORT_DATE_FORMAT);
     335
     336    CPPUNIT_ASSERT_EQUAL(BString("M"), buffer);
     337    CPPUNIT_ASSERT_EQUAL(B_OK, result);
    220338}
    221339
    222340
    DateFormatTest::AddTests(BTestSuite& parent)  
    320438    suite.addTest(new CppUnit::TestCaller<DateFormatTest>(
    321439        "DateFormatTest::TestMonthNames", &DateFormatTest::TestMonthNames));
    322440    suite.addTest(new CppUnit::TestCaller<DateFormatTest>(
     441        "DateFormatTest::TestDayNames", &DateFormatTest::TestDayNames));
     442    suite.addTest(new CppUnit::TestCaller<DateFormatTest>(
    323443        "DateFormatTest::TestParseDate", &DateFormatTest::TestParseDate));
    324444    suite.addTest(new CppUnit::TestCaller<DateFormatTest>(
    325445        "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