turn gb_CustomTarget_get_workdir into error and remove old _repo_targets
[LibreOffice.git] / i18npool / qa / cppunit / test_calendar.cxx
bloba522a4a7423604b97f9570256a74a470d116af49
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9 #include <calendar_hijri.hxx>
10 #include <unotest/bootstrapfixturebase.hxx>
12 using namespace com::sun::star;
14 class TestCalendar : public test::BootstrapFixtureBase
16 public:
17 void testHijriGregorian();
18 void testGetGregorianJulianDay();
20 CPPUNIT_TEST_SUITE(TestCalendar);
21 CPPUNIT_TEST(testHijriGregorian);
22 CPPUNIT_TEST(testGetGregorianJulianDay);
23 CPPUNIT_TEST_SUITE_END();
26 void TestCalendar::testHijriGregorian()
28 // 21-7-1443 (Hijri) == 22-2-2022 (Gregorian)
29 sal_Int32 day = 22, month = 2, year = 2022;
30 i18npool::Calendar_hijri::getHijri(&day, &month, &year);
31 CPPUNIT_ASSERT_EQUAL(sal_Int32(21), day);
32 CPPUNIT_ASSERT_EQUAL(sal_Int32(7), month);
33 CPPUNIT_ASSERT_EQUAL(sal_Int32(1443), year);
35 i18npool::Calendar_hijri::ToGregorian(&day, &month, &year);
36 CPPUNIT_ASSERT_EQUAL(sal_Int32(22), day);
37 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), month);
38 CPPUNIT_ASSERT_EQUAL(sal_Int32(2022), year);
40 // 1-1-1 (Hijri) == 15-7-622 (Gregorian)
41 // NOTE: The calculated date is 15-7-622, as it was with the
42 // previous version of i18npool::Calendar_hijri::ToGregorian()
43 // but in some articles, 15-7-622 is considered the equivalent date
44 // https://en.wikipedia.org/wiki/622
45 // This article states that 15-7-622 is correct:
46 // "On the Origins of the Hijrī Calendar: A Multi-Faceted Perspective
47 // Based on the Covenants of the Prophet and Specific Date Verification"
48 // https://www.mdpi.com/2077-1444/12/1/42/htm
49 day = 15;
50 month = 7;
51 year = 622;
52 i18npool::Calendar_hijri::getHijri(&day, &month, &year);
53 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), day);
54 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), month);
55 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), year);
57 i18npool::Calendar_hijri::ToGregorian(&day, &month, &year);
58 CPPUNIT_ASSERT_EQUAL(sal_Int32(15), day);
59 CPPUNIT_ASSERT_EQUAL(sal_Int32(7), month);
60 CPPUNIT_ASSERT_EQUAL(sal_Int32(622), year);
62 // 1-1-100 (Hijri) == 2-8-718 (Gregorian)
63 // https://habibur.com/hijri/100/
64 day = 2;
65 month = 8;
66 year = 718;
67 i18npool::Calendar_hijri::getHijri(&day, &month, &year);
68 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), day);
69 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), month);
70 CPPUNIT_ASSERT_EQUAL(sal_Int32(100), year);
72 i18npool::Calendar_hijri::ToGregorian(&day, &month, &year);
73 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), day);
74 CPPUNIT_ASSERT_EQUAL(sal_Int32(8), month);
75 CPPUNIT_ASSERT_EQUAL(sal_Int32(718), year);
77 // 1-1-1000 (Hijri) == 19-10-1591 (Gregorian)
78 // NOTE: The calculated date is 18-10-1591, but there is inconsistency
79 // with this website, as it states it should be 19-10-1591
80 // https://habibur.com/hijri/1000/
81 day = 18;
82 month = 10;
83 year = 1591;
84 i18npool::Calendar_hijri::getHijri(&day, &month, &year);
85 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), day);
86 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), month);
87 CPPUNIT_ASSERT_EQUAL(sal_Int32(1000), year);
89 i18npool::Calendar_hijri::ToGregorian(&day, &month, &year);
90 CPPUNIT_ASSERT_EQUAL(sal_Int32(18), day);
91 CPPUNIT_ASSERT_EQUAL(sal_Int32(10), month);
92 CPPUNIT_ASSERT_EQUAL(sal_Int32(1591), year);
94 // 1-1-2000 (Hijri) == 7-1-2562 (Gregorian)
95 // NOTE: The calculated date is 7-1-2562, but there is inconsistency
96 // with this website, as it states it should be 8-1-2562
97 // https://habibur.com/hijri/2000/
98 day = 7;
99 month = 1;
100 year = 2562;
101 i18npool::Calendar_hijri::getHijri(&day, &month, &year);
102 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), day);
103 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), month);
104 CPPUNIT_ASSERT_EQUAL(sal_Int32(2000), year);
106 i18npool::Calendar_hijri::ToGregorian(&day, &month, &year);
107 CPPUNIT_ASSERT_EQUAL(sal_Int32(7), day);
108 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), month);
109 CPPUNIT_ASSERT_EQUAL(sal_Int32(2562), year);
112 void TestCalendar::testGetGregorianJulianDay()
114 // Julian day for 22-2-2022 (Gregorian) == 2459633
115 // https://core2.gsfc.nasa.gov/time/julian.html
116 sal_Int32 lJulianDay, day = 22, month = 2, year = 2022;
117 lJulianDay = i18npool::Calendar_hijri::getJulianDay(day, month, year);
118 CPPUNIT_ASSERT_EQUAL(sal_Int32(2459633), lJulianDay);
120 i18npool::Calendar_hijri::getGregorianDay(lJulianDay, &day, &month, &year);
121 CPPUNIT_ASSERT_EQUAL(sal_Int32(22), day);
122 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), month);
123 CPPUNIT_ASSERT_EQUAL(sal_Int32(2022), year);
126 CPPUNIT_TEST_SUITE_REGISTRATION(TestCalendar);
128 CPPUNIT_PLUGIN_IMPLEMENT();
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */