~ubuntu-branches/ubuntu/natty/kde4libs/natty-proposed

« back to all changes in this revision

Viewing changes to kdecore/tests/kcalendartest.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell, Scott Kitterman, Jonathan Riddell
  • Date: 2010-11-22 17:59:02 UTC
  • mfrom: (1.6.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101122175902-yubxubd0pg6hn11z
Tags: 4:4.5.80a-0ubuntu1
[ Scott Kitterman ]
* New upstream beta release
  - Refreshed all patches
  - Updated debian/patches/10_make_libkdeinit4_private.diff to use Qfile
    instead of Qstring in kdecore/kernel/kstandarddirs_unix.cpp
  - Updated debian/patches/kubuntu_01_kubuntu_useragent.diff to provide
    Kubuntu in the Konqueror user agen string with the changes in
    kio/kio/kprotocolmanager.cpp
  - Partially updated debian/patches/kubuntu_05_langpack_desktop_files.diff
    and left the balance in kdecore/localization/klocale.cpp.rej for later
    revision
  - Update debian/patches/kubuntu_06_user_disk_mounting.diff for changes in
    solid/solid/backends/hal/halstorageaccess.cpp
  - Remove debian/patches/kubuntu_71_backport_plasma_webview_changes.diff
    (backported from upstream, so already present now)
  - Add minimum version for libattica-dev of 0.1.90 to build-depends
  - Bump minimum version for libsoprano-dev build-depend to 2.5.60
  - Add minimum version for shared-desktop-ontologies of 0.5 in build-dep

[ Jonathan Riddell ]
* Add build-depends on grantlee, libudev-dev, hupnp (FIXME needs packaging fixes)
* Update kubuntu_04_add_langpack_path.diff 28_find_old_kde4_html_documentation.diff
  22_hack_in_etc_kde4_in_kstandarddirs.diff for QT_NO_CAST_FROM_ASCII
* Update kubuntu_05_langpack_desktop_files.diff for new upstream code
* Add kubuntu_78_solid_trunk.diff to fix solid linking
* Add libnepomukutils4 package for new library
* Don't install kcm_ssl for now, e-mailed upstream to suggest moving to kdebase
* Add kubuntu_79_knewstuff_fix.diff to fix compile broken by non-trunk commit
  http://websvn.kde.org/?view=revision&revision=1199825
* kdelibs5-data replaces old kdebase-runtime-data due to moved file
* Add kubuntu_80_find_hupnp.diff to find hupnp include files, committed upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 
9
9
#include "qtest_kde.h"
10
10
#include "kcalendarsystem.h"
 
11
#include "klocalizeddate.h"
11
12
#include "kglobal.h"
12
13
#include "kdebug.h"
13
14
#include "kstandarddirs.h"
20
21
void KCalendarTest::testTypes()
21
22
{
22
23
    const KCalendarSystem *calendar;
 
24
    calendar = KCalendarSystem::create( "coptic" );
 
25
    QCOMPARE( calendar->calendarType(), QString("coptic") );
 
26
    QCOMPARE( calendar->calendarSystem(), KLocale::CopticCalendar );
 
27
    delete calendar;
 
28
    calendar = KCalendarSystem::create( "ethiopian" );
 
29
    QCOMPARE( calendar->calendarType(), QString("ethiopian") );
 
30
    QCOMPARE( calendar->calendarSystem(), KLocale::EthiopianCalendar );
 
31
    delete calendar;
23
32
    calendar = KCalendarSystem::create( "gregorian" );
24
33
    QCOMPARE( calendar->calendarType(), QString("gregorian") );
 
34
    QCOMPARE( calendar->calendarSystem(), KLocale::QDateCalendar );
25
35
    delete calendar;
26
36
    calendar = KCalendarSystem::create( "gregorian-proleptic" );
27
37
    QCOMPARE( calendar->calendarType(), QString("gregorian-proleptic") );
 
38
    QCOMPARE( calendar->calendarSystem(), KLocale::GregorianCalendar );
28
39
    delete calendar;
29
40
    calendar = KCalendarSystem::create( "hebrew" );
30
41
    QCOMPARE( calendar->calendarType(), QString("hebrew") );
 
42
    QCOMPARE( calendar->calendarSystem(), KLocale::HebrewCalendar );
31
43
    delete calendar;
32
44
    calendar = KCalendarSystem::create( "hijri" );
33
45
    QCOMPARE( calendar->calendarType(), QString("hijri") );
 
46
    QCOMPARE( calendar->calendarSystem(), KLocale::IslamicCivilCalendar );
34
47
    delete calendar;
35
48
    calendar = KCalendarSystem::create( "indian-national" );
36
49
    QCOMPARE( calendar->calendarType(), QString("indian-national") );
 
50
    QCOMPARE( calendar->calendarSystem(), KLocale::IndianNationalCalendar );
37
51
    delete calendar;
38
52
    calendar = KCalendarSystem::create( "jalali" );
39
53
    QCOMPARE( calendar->calendarType(), QString("jalali") );
 
54
    QCOMPARE( calendar->calendarSystem(), KLocale::JalaliCalendar );
40
55
    delete calendar;
41
56
    calendar = KCalendarSystem::create( "japanese" );
42
57
    QCOMPARE( calendar->calendarType(), QString("japanese") );
 
58
    QCOMPARE( calendar->calendarSystem(), KLocale::JapaneseCalendar );
43
59
    delete calendar;
44
60
    calendar = KCalendarSystem::create( "julian" );
45
61
    QCOMPARE( calendar->calendarType(), QString("julian") );
 
62
    QCOMPARE( calendar->calendarSystem(), KLocale::JulianCalendar );
46
63
    delete calendar;
47
64
    calendar = KCalendarSystem::create( "minguo" );
48
65
    QCOMPARE( calendar->calendarType(), QString("minguo") );
 
66
    QCOMPARE( calendar->calendarSystem(), KLocale::MinguoCalendar );
49
67
    delete calendar;
50
68
    calendar = KCalendarSystem::create( "thai" );
51
69
    QCOMPARE( calendar->calendarType(), QString("thai") );
 
70
    QCOMPARE( calendar->calendarSystem(), KLocale::ThaiCalendar );
52
71
    delete calendar;
53
72
    calendar = KCalendarSystem::create( "invalid" );
54
73
    QCOMPARE( calendar->calendarType(), QString("gregorian") );
 
74
    QCOMPARE( calendar->calendarSystem(), KLocale::QDateCalendar );
55
75
    delete calendar;
56
76
    calendar = KCalendarSystem::create( QString() );
57
77
    QCOMPARE( calendar->calendarType(), QString("gregorian") );
 
78
    QCOMPARE( calendar->calendarSystem(), KLocale::QDateCalendar );
 
79
    delete calendar;
 
80
 
 
81
    calendar = KCalendarSystem::create( KLocale::QDateCalendar );
 
82
    QCOMPARE( calendar->calendarType(), QString("gregorian") );
 
83
    QCOMPARE( calendar->calendarSystem(), KLocale::QDateCalendar );
 
84
    delete calendar;
 
85
    calendar = KCalendarSystem::create( KLocale::CopticCalendar );
 
86
    QCOMPARE( calendar->calendarType(), QString("coptic") );
 
87
    QCOMPARE( calendar->calendarSystem(), KLocale::CopticCalendar );
 
88
    delete calendar;
 
89
    calendar = KCalendarSystem::create( KLocale::EthiopianCalendar );
 
90
    QCOMPARE( calendar->calendarType(), QString("ethiopian") );
 
91
    QCOMPARE( calendar->calendarSystem(), KLocale::EthiopianCalendar );
 
92
    delete calendar;
 
93
    calendar = KCalendarSystem::create( KLocale::GregorianCalendar );
 
94
    QCOMPARE( calendar->calendarType(), QString("gregorian-proleptic") );
 
95
    QCOMPARE( calendar->calendarSystem(), KLocale::GregorianCalendar );
 
96
    delete calendar;
 
97
    calendar = KCalendarSystem::create( KLocale::HebrewCalendar );
 
98
    QCOMPARE( calendar->calendarType(), QString("hebrew") );
 
99
    QCOMPARE( calendar->calendarSystem(), KLocale::HebrewCalendar );
 
100
    delete calendar;
 
101
    calendar = KCalendarSystem::create( KLocale::IslamicCivilCalendar );
 
102
    QCOMPARE( calendar->calendarType(), QString("hijri") );
 
103
    QCOMPARE( calendar->calendarSystem(), KLocale::IslamicCivilCalendar );
 
104
    delete calendar;
 
105
    calendar = KCalendarSystem::create( KLocale::IndianNationalCalendar );
 
106
    QCOMPARE( calendar->calendarType(), QString("indian-national") );
 
107
    QCOMPARE( calendar->calendarSystem(), KLocale::IndianNationalCalendar );
 
108
    delete calendar;
 
109
    calendar = KCalendarSystem::create( KLocale::JalaliCalendar );
 
110
    QCOMPARE( calendar->calendarType(), QString("jalali") );
 
111
    QCOMPARE( calendar->calendarSystem(), KLocale::JalaliCalendar );
 
112
    delete calendar;
 
113
    calendar = KCalendarSystem::create( KLocale::JapaneseCalendar );
 
114
    QCOMPARE( calendar->calendarType(), QString("japanese") );
 
115
    QCOMPARE( calendar->calendarSystem(), KLocale::JapaneseCalendar );
 
116
    delete calendar;
 
117
    calendar = KCalendarSystem::create( KLocale::JulianCalendar );
 
118
    QCOMPARE( calendar->calendarType(), QString("julian") );
 
119
    QCOMPARE( calendar->calendarSystem(), KLocale::JulianCalendar );
 
120
    delete calendar;
 
121
    calendar = KCalendarSystem::create( KLocale::MinguoCalendar );
 
122
    QCOMPARE( calendar->calendarType(), QString("minguo") );
 
123
    QCOMPARE( calendar->calendarSystem(), KLocale::MinguoCalendar );
 
124
    delete calendar;
 
125
    calendar = KCalendarSystem::create( KLocale::ThaiCalendar );
 
126
    QCOMPARE( calendar->calendarType(), QString("thai") );
 
127
    QCOMPARE( calendar->calendarSystem(), KLocale::ThaiCalendar );
58
128
    delete calendar;
59
129
 
60
130
    QStringList lst = KCalendarSystem::calendarSystems();
 
131
    QCOMPARE( lst.count(), 11 );
 
132
    QVERIFY( lst.contains( "coptic" ) );
 
133
    QVERIFY( lst.contains( "ethiopian" ) );
61
134
    QVERIFY( lst.contains( "gregorian" ) );
62
135
    QVERIFY( lst.contains( "hebrew" ) );
63
136
    QVERIFY( lst.contains( "hijri" ) );
68
141
    QVERIFY( lst.contains( "minguo" ) );
69
142
    QVERIFY( lst.contains( "thai" ) );
70
143
 
 
144
    QList<KLocale::CalendarSystem> list = KCalendarSystem::calendarSystemsList();
 
145
    QCOMPARE( list.count(), 12 );
 
146
    QVERIFY( list.contains( KLocale::QDateCalendar ) );
 
147
    QVERIFY( list.contains( KLocale::CopticCalendar ) );
 
148
    QVERIFY( list.contains( KLocale::EthiopianCalendar ) );
 
149
    QVERIFY( list.contains( KLocale::GregorianCalendar ) );
 
150
    QVERIFY( list.contains( KLocale::HebrewCalendar ) );
 
151
    QVERIFY( list.contains( KLocale::IslamicCivilCalendar ) );
 
152
    QVERIFY( list.contains( KLocale::IndianNationalCalendar ) );
 
153
    QVERIFY( list.contains( KLocale::JalaliCalendar ) );
 
154
    QVERIFY( list.contains( KLocale::JapaneseCalendar ) );
 
155
    QVERIFY( list.contains( KLocale::JulianCalendar ) );
 
156
    QVERIFY( list.contains( KLocale::MinguoCalendar ) );
 
157
    QVERIFY( list.contains( KLocale::ThaiCalendar ) );
 
158
 
 
159
    QCOMPARE( KCalendarSystem::calendarLabel( "coptic" ),              QString( "Coptic" ) );
 
160
    QCOMPARE( KCalendarSystem::calendarLabel( "ethiopian" ),           QString( "Ethiopian" ) );
71
161
    QCOMPARE( KCalendarSystem::calendarLabel( "gregorian" ),           QString( "Gregorian" ) );
72
162
    QCOMPARE( KCalendarSystem::calendarLabel( "gregorian-proleptic" ), QString( "Gregorian (Proleptic)" ) );
73
163
    QCOMPARE( KCalendarSystem::calendarLabel( "hebrew" ),              QString( "Hebrew" ) );
74
 
    QCOMPARE( KCalendarSystem::calendarLabel( "hijri" ),               QString( "Hijri" ) );
 
164
    QCOMPARE( KCalendarSystem::calendarLabel( "hijri" ),               QString( "Islamic / Hijri (Civil)" ) );
75
165
    QCOMPARE( KCalendarSystem::calendarLabel( "indian-national" ),     QString( "Indian National" ) );
76
166
    QCOMPARE( KCalendarSystem::calendarLabel( "jalali" ),              QString( "Jalali" ) );
77
167
    QCOMPARE( KCalendarSystem::calendarLabel( "japanese" ),            QString( "Japanese" ) );
78
168
    QCOMPARE( KCalendarSystem::calendarLabel( "julian" ),              QString( "Julian" ) );
79
169
    QCOMPARE( KCalendarSystem::calendarLabel( "minguo" ),              QString( "Taiwanese" ) );
80
170
    QCOMPARE( KCalendarSystem::calendarLabel( "thai" ),                QString( "Thai" ) );
81
 
}
82
 
 
83
 
void KCalendarTest::testLocale()
84
 
{
85
 
    KGlobal::locale()->setCalendar( "gregorian" );
86
 
    const KCalendarSystem *calendar = KGlobal::locale()->calendar();
87
 
    QCOMPARE( calendar->calendarType(), QString( "gregorian"  ) );
88
 
    KGlobal::locale()->setCalendar( "gregorian-proleptic");
89
 
    calendar = KGlobal::locale()->calendar();
90
 
    QCOMPARE( calendar->calendarType(), QString( "gregorian-proleptic" ) );
91
 
    KGlobal::locale()->setCalendar( "hebrew" );
92
 
    calendar = KGlobal::locale()->calendar();
93
 
    QCOMPARE( calendar->calendarType(), QString( "hebrew" ) );
94
 
    KGlobal::locale()->setCalendar( "hijri" );
95
 
    calendar = KGlobal::locale()->calendar();
96
 
    QCOMPARE( calendar->calendarType(), QString( "hijri" ) );
97
 
    KGlobal::locale()->setCalendar( "indian-national" );
98
 
    calendar = KGlobal::locale()->calendar();
99
 
    QCOMPARE( calendar->calendarType(), QString( "indian-national" ) );
100
 
    KGlobal::locale()->setCalendar( "jalali" );
101
 
    calendar = KGlobal::locale()->calendar();
102
 
    QCOMPARE( calendar->calendarType(), QString( "jalali" ) );
103
 
    KGlobal::locale()->setCalendar( "japanese" );
104
 
    calendar = KGlobal::locale()->calendar();
105
 
    QCOMPARE( calendar->calendarType(), QString( "japanese" ) );
106
 
    KGlobal::locale()->setCalendar( "julian" );
107
 
    calendar = KGlobal::locale()->calendar();
108
 
    QCOMPARE( calendar->calendarType(), QString( "julian" ) );
109
 
    KGlobal::locale()->setCalendar( "minguo" );
110
 
    calendar = KGlobal::locale()->calendar();
111
 
    QCOMPARE( calendar->calendarType(), QString( "minguo" ) );
112
 
    KGlobal::locale()->setCalendar( "thai" );
113
 
    calendar = KGlobal::locale()->calendar();
114
 
    QCOMPARE( calendar->calendarType(), QString( "thai" ) );
 
171
 
 
172
    QCOMPARE( KCalendarSystem::calendarLabel( KLocale::QDateCalendar ),          QString( "Gregorian" ) );
 
173
    QCOMPARE( KCalendarSystem::calendarLabel( KLocale::CopticCalendar ),         QString( "Coptic" ) );
 
174
    QCOMPARE( KCalendarSystem::calendarLabel( KLocale::EthiopianCalendar ),      QString( "Ethiopian" ) );
 
175
    QCOMPARE( KCalendarSystem::calendarLabel( KLocale::GregorianCalendar ),      QString( "Gregorian (Proleptic)" ) );
 
176
    QCOMPARE( KCalendarSystem::calendarLabel( KLocale::HebrewCalendar ),         QString( "Hebrew" ) );
 
177
    QCOMPARE( KCalendarSystem::calendarLabel( KLocale::IslamicCivilCalendar ),   QString( "Islamic / Hijri (Civil)" ) );
 
178
    QCOMPARE( KCalendarSystem::calendarLabel( KLocale::IndianNationalCalendar ), QString( "Indian National" ) );
 
179
    QCOMPARE( KCalendarSystem::calendarLabel( KLocale::JalaliCalendar ),         QString( "Jalali" ) );
 
180
    QCOMPARE( KCalendarSystem::calendarLabel( KLocale::JapaneseCalendar ),       QString( "Japanese" ) );
 
181
    QCOMPARE( KCalendarSystem::calendarLabel( KLocale::JulianCalendar ),         QString( "Julian" ) );
 
182
    QCOMPARE( KCalendarSystem::calendarLabel( KLocale::MinguoCalendar ),         QString( "Taiwanese" ) );
 
183
    QCOMPARE( KCalendarSystem::calendarLabel( KLocale::ThaiCalendar ),           QString( "Thai" ) );
 
184
 
115
185
}
116
186
 
117
187
void KCalendarTest::testFormatDate()
118
188
{
119
189
    KLocale *locale = new KLocale( *KGlobal::locale() );
120
190
    locale->setDateFormatShort( "%y-%m-%d" );
121
 
    const KCalendarSystem *calendar = KCalendarSystem::create( "gregorian", locale );
 
191
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::QDateCalendar, locale );
122
192
 
123
193
    //Test default settings
124
194
    QDate testDate( 2005, 10, 20 );
304
374
    QCOMPARE( calendar->formatDate( testDate, "%-Y" ), QString( "-9" ) );
305
375
    QCOMPARE( calendar->formatDate( testDate, "%-C" ), QString( "-0" ) );
306
376
    QCOMPARE( calendar->formatDate( testDate, "%-y" ), QString( "-9" ) );
307
 
    QCOMPARE( calendar->formatDate( testDate, "%_Y" ), QString( "-   9" ) );
308
 
    QCOMPARE( calendar->formatDate( testDate, "%_C" ), QString( "- 0" ) );
309
 
    QCOMPARE( calendar->formatDate( testDate, "%_y" ), QString( "- 9" ) );
 
377
    QCOMPARE( calendar->formatDate( testDate, "%_Y" ), QString( "  -9" ) );
 
378
    QCOMPARE( calendar->formatDate( testDate, "%_C" ), QString( "-0" ) );
 
379
    QCOMPARE( calendar->formatDate( testDate, "%_y" ), QString( "-9" ) );
310
380
    QCOMPARE( calendar->formatDate( testDate, "%0Y" ), QString( "-0009" ) );
311
381
    QCOMPARE( calendar->formatDate( testDate, "%0C" ), QString( "-00" ) );
312
382
    QCOMPARE( calendar->formatDate( testDate, "%0y" ), QString( "-09" ) );
321
391
    QCOMPARE( calendar->formatDate( testDate, "%-Y" ), QString( "-89" ) );
322
392
    QCOMPARE( calendar->formatDate( testDate, "%-C" ), QString( "-0" ) );
323
393
    QCOMPARE( calendar->formatDate( testDate, "%-y" ), QString( "-89" ) );
324
 
    QCOMPARE( calendar->formatDate( testDate, "%_Y" ), QString( "-  89" ) );
325
 
    QCOMPARE( calendar->formatDate( testDate, "%_C" ), QString( "- 0" ) );
 
394
    QCOMPARE( calendar->formatDate( testDate, "%_Y" ), QString( " -89" ) );
 
395
    QCOMPARE( calendar->formatDate( testDate, "%_C" ), QString( "-0" ) );
326
396
    QCOMPARE( calendar->formatDate( testDate, "%_y" ), QString( "-89" ) );
327
397
    QCOMPARE( calendar->formatDate( testDate, "%0Y" ), QString( "-0089" ) );
328
398
    QCOMPARE( calendar->formatDate( testDate, "%0C" ), QString( "-00" ) );
338
408
    QCOMPARE( calendar->formatDate( testDate, "%-Y" ), QString( "-789" ) );
339
409
    QCOMPARE( calendar->formatDate( testDate, "%-C" ), QString( "-7" ) );
340
410
    QCOMPARE( calendar->formatDate( testDate, "%-y" ), QString( "-89" ) );
341
 
    QCOMPARE( calendar->formatDate( testDate, "%_Y" ), QString( "- 789" ) );
342
 
    QCOMPARE( calendar->formatDate( testDate, "%_C" ), QString( "- 7" ) );
 
411
    QCOMPARE( calendar->formatDate( testDate, "%_Y" ), QString( "-789" ) );
 
412
    QCOMPARE( calendar->formatDate( testDate, "%_C" ), QString( "-7" ) );
343
413
    QCOMPARE( calendar->formatDate( testDate, "%_y" ), QString( "-89" ) );
344
414
    QCOMPARE( calendar->formatDate( testDate, "%0Y" ), QString( "-0789" ) );
345
415
    QCOMPARE( calendar->formatDate( testDate, "%0C" ), QString( "-07" ) );
355
425
    QCOMPARE( calendar->formatDate( testDate, "%-Y" ), QString( "-709" ) );
356
426
    QCOMPARE( calendar->formatDate( testDate, "%-C" ), QString( "-7" ) );
357
427
    QCOMPARE( calendar->formatDate( testDate, "%-y" ), QString( "-9" ) );
358
 
    QCOMPARE( calendar->formatDate( testDate, "%_Y" ), QString( "- 709" ) );
359
 
    QCOMPARE( calendar->formatDate( testDate, "%_C" ), QString( "- 7" ) );
360
 
    QCOMPARE( calendar->formatDate( testDate, "%_y" ), QString( "- 9" ) );
 
428
    QCOMPARE( calendar->formatDate( testDate, "%_Y" ), QString( "-709" ) );
 
429
    QCOMPARE( calendar->formatDate( testDate, "%_C" ), QString( "-7" ) );
 
430
    QCOMPARE( calendar->formatDate( testDate, "%_y" ), QString( "-9" ) );
361
431
    QCOMPARE( calendar->formatDate( testDate, "%0Y" ), QString( "-0709" ) );
362
432
    QCOMPARE( calendar->formatDate( testDate, "%0C" ), QString( "-07" ) );
363
433
    QCOMPARE( calendar->formatDate( testDate, "%0y" ), QString( "-09" ) );
391
461
    QCOMPARE( calendar->formatDate( testDate, "%-y" ), QString( "-9" ) );
392
462
    QCOMPARE( calendar->formatDate( testDate, "%_Y" ), QString( "-1709" ) );
393
463
    QCOMPARE( calendar->formatDate( testDate, "%_C" ), QString( "-17" ) );
394
 
    QCOMPARE( calendar->formatDate( testDate, "%_y" ), QString( "- 9" ) );
 
464
    QCOMPARE( calendar->formatDate( testDate, "%_y" ), QString( "-9" ) );
395
465
    QCOMPARE( calendar->formatDate( testDate, "%0Y" ), QString( "-1709" ) );
396
466
    QCOMPARE( calendar->formatDate( testDate, "%0C" ), QString( "-17" ) );
397
467
    QCOMPARE( calendar->formatDate( testDate, "%0y" ), QString( "-09" ) );
414
484
{
415
485
    KLocale *locale = new KLocale( *KGlobal::locale() );
416
486
    locale->setDateFormatShort( "%y-%m-%d" );
417
 
    const KCalendarSystem *calendar = KCalendarSystem::create( "gregorian", locale );
 
487
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::QDateCalendar, locale );
418
488
 
419
489
    QDate testDate( 2005, 10, 20 );
420
490
    compareFormatUnicode( calendar, testDate, "yyyy" );
452
522
{
453
523
    KLocale *locale = new KLocale( *KGlobal::locale() );
454
524
    locale->setDateFormatShort( "%y-%m-%d" );
455
 
    const KCalendarSystem *calendar = KCalendarSystem::create( "gregorian", locale );
 
525
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::QDateCalendar, locale );
456
526
    int currentYear = QDate::currentDate().year();
457
527
 
458
528
    //Test default settings
615
685
{
616
686
    KLocale *locale = new KLocale( *KGlobal::locale() );
617
687
    locale->setDigitSet( testDigitSet );
618
 
    const KCalendarSystem *calendar = KCalendarSystem::create( "gregorian", locale );
 
688
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::QDateCalendar, locale );
619
689
 
620
690
    //Test default settings
621
691
    QDate testDate( 2005, 1, 3 );
684
754
void KCalendarTest::testIsoWeekDate()
685
755
{
686
756
    KLocale *locale = new KLocale( *KGlobal::locale() );
687
 
    const KCalendarSystem *calendar = KCalendarSystem::create( "gregorian", locale );
 
757
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::QDateCalendar, locale );
688
758
 
689
759
    int earliestValidYear = calendar->year( calendar->earliestValidDate() );
690
760
    int latestValidYear = calendar->year( calendar->latestValidDate() );
785
855
    locale->setLanguage(QStringList() << "he");
786
856
    locale->insertCatalog("kdecalendarsystems");
787
857
    locale->setDateFormat( "%d %B %Y" );
788
 
    const KCalendarSystem *calendar = KCalendarSystem::create( "hebrew", locale );
 
858
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::HebrewCalendar, locale );
789
859
    if ( locale->language() == "he" ) {
790
860
        QDate testDate;
791
861
        QString yearString, monthString, dayString, testString, resultString;
822
892
void KCalendarTest::testDayOfYearDate()
823
893
{
824
894
    KLocale *locale = new KLocale( *KGlobal::locale() );
825
 
    const KCalendarSystem *calendar = KCalendarSystem::create( "gregorian", locale );
 
895
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::QDateCalendar, locale );
826
896
 
827
897
    int earliestValidYear = calendar->year( calendar->earliestValidDate() );
828
898
    int latestValidYear = calendar->year( calendar->latestValidDate() );
870
940
 
871
941
void KCalendarTest::testDateDifference()
872
942
{
873
 
    const KCalendarSystem *calendar = KCalendarSystem::create( "gregorian" );
 
943
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::QDateCalendar );
874
944
    QDate testDate1, testDate2;
875
945
 
876
946
    // Date Difference
996
1066
    }
997
1067
}
998
1068
 
 
1069
void KCalendarTest::testFirstLast()
 
1070
{
 
1071
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::QDateCalendar );
 
1072
    QDate testDate = QDate( 2010, 6, 15 );
 
1073
 
 
1074
    QCOMPARE( calendar->firstDayOfYear( testDate ),  QDate( 2010,  1, 1 ) );
 
1075
    QCOMPARE( calendar->lastDayOfYear( testDate ),   QDate( 2010, 12, 31 ) );
 
1076
    QCOMPARE( calendar->firstDayOfYear( 2010 ),      QDate( 2010,  1,  1 ) );
 
1077
    QCOMPARE( calendar->lastDayOfYear( 2010 ),       QDate( 2010, 12, 31 ) );
 
1078
    QCOMPARE( calendar->firstDayOfMonth( testDate ), QDate( 2010,  6,  1 ) );
 
1079
    QCOMPARE( calendar->lastDayOfMonth( testDate ),  QDate( 2010,  6, 30 ) );
 
1080
    QCOMPARE( calendar->firstDayOfMonth( 2010, 6 ),  QDate( 2010,  6,  1 ) );
 
1081
    QCOMPARE( calendar->lastDayOfMonth( 2010, 6 ),   QDate( 2010,  6, 30 ) );
 
1082
}
 
1083
 
999
1084
void KCalendarTest::testEra()
1000
1085
{
1001
1086
    KConfigGroup cg( KGlobal::config(), QString( "KCalendarSystem %1" ).arg( "gregorian" ) );
1002
1087
    cg.deleteGroup( KConfigGroup::Normal );
1003
1088
    cg.deleteGroup( KConfigGroup::Global );
1004
1089
 
1005
 
    const KCalendarSystem *calendar = KCalendarSystem::create( "gregorian" );
 
1090
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::QDateCalendar );
1006
1091
 
1007
1092
    int earliestValidYear = calendar->year( calendar->earliestValidDate() );
1008
1093
    int latestValidYear = calendar->year( calendar->latestValidDate() );
1085
1170
 
1086
1171
void KCalendarTest::testGregorian()
1087
1172
{
1088
 
    const KCalendarSystem *calendar = KCalendarSystem::create( "gregorian" );
 
1173
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::QDateCalendar );
1089
1174
    QDate testDate( 2005, 9, 10 );
1090
1175
 
1091
1176
    QCOMPARE( calendar->dayOfYear( testDate ), 253 );
1115
1200
 
1116
1201
void KCalendarTest::testHebrew()
1117
1202
{
1118
 
    const KCalendarSystem *calendar = KCalendarSystem::create( "hebrew" );
 
1203
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::HebrewCalendar );
1119
1204
    QDate testDate( 2005, 9, 10 ); // 5756-13-06
1120
1205
    QCOMPARE( calendar->dayOfYear( testDate ), 360 );
1121
1206
 
1148
1233
 
1149
1234
void KCalendarTest::testHijri()
1150
1235
{
1151
 
    const KCalendarSystem *calendar = KCalendarSystem::create( "hijri" );
 
1236
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::IslamicCivilCalendar );
1152
1237
 
1153
1238
    QDate testDate( 2008, 12, 29 ); //1430-01-01, jd 2454830, not leap
1154
1239
    QCOMPARE( calendar->year(testDate), 1430 );
1221
1306
 
1222
1307
void KCalendarTest::testIndianNational()
1223
1308
{
1224
 
    const KCalendarSystem *calendar = KCalendarSystem::create( "indian-national" );
 
1309
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::IndianNationalCalendar );
1225
1310
    QDate testDate( 2005, 9, 10 );
1226
1311
 
1227
1312
    calendar->setYMD( testDate, 2000, 1, 1 );
1241
1326
    QCOMPARE( calendar->month( testDate ), 3 );
1242
1327
    QCOMPARE( calendar->day( testDate ), 1 );
1243
1328
 
 
1329
    // Test some key dates
 
1330
    testYmd( calendar,    0,  1,  1, QDate(   78,  3, 24 ).toJulianDay() );
 
1331
    testYmd( calendar,    0, 12, 30, QDate(   79,  3, 23 ).toJulianDay() );
 
1332
    testYmd( calendar, 1922,  1,  1, QDate( 2000,  3, 21 ).toJulianDay() );
 
1333
    testYmd( calendar, 1922, 12, 30, QDate( 2001,  3, 21 ).toJulianDay() );
 
1334
    testYmd( calendar, 1932,  1,  1, QDate( 2010,  3, 22 ).toJulianDay() );
 
1335
    testYmd( calendar, 1932, 12, 30, QDate( 2011,  3, 21 ).toJulianDay() );
 
1336
 
1244
1337
    delete calendar;
1245
1338
}
1246
1339
 
1247
1340
void KCalendarTest::testGregorianBasic()
1248
1341
{
1249
 
    const KCalendarSystem *calendar = KCalendarSystem::create( "gregorian" );
 
1342
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::QDateCalendar );
1250
1343
 
1251
 
    QCOMPARE( calendar->calendarType(), QString( "gregorian" ) );
1252
 
    QCOMPARE( KCalendarSystem::calendarLabel( QString( "gregorian" ) ), QString( "Gregorian" ) );
 
1344
    testCalendarSystemType( calendar, KLocale::QDateCalendar, "gregorian", "Gregorian" );
1253
1345
 
1254
1346
    QCOMPARE( calendar->epoch(), QDate( 1, 1, 1 ) );
1255
1347
    QCOMPARE( calendar->earliestValidDate(), QDate( -4712, 1, 1 ) );
1296
1388
 
1297
1389
void KCalendarTest::testGregorianYmd()
1298
1390
{
1299
 
    const KCalendarSystem *calendar = KCalendarSystem::create( "gregorian" );
 
1391
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::QDateCalendar );
1300
1392
    testYmd( calendar, 2007, 1, 1, QDate( 2007, 1, 1 ).toJulianDay() );
1301
1393
    delete calendar;
1302
1394
}
1307
1399
    cg.deleteGroup( KConfigGroup::Normal );
1308
1400
    cg.deleteGroup( KConfigGroup::Global );
1309
1401
 
1310
 
    const KCalendarSystem *calendar = KCalendarSystem::create( "gregorian" );
 
1402
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::QDateCalendar );
1311
1403
 
1312
1404
    testEraDate( calendar, QDate( 2010,  1,  1 ), 2010, "2010", "2010", "AD", "Anno Domini" );
1313
1405
    testEraDate( calendar, QDate(   -5,  1,  1 ),    5, "5",    "0005", "BC", "Before Christ" );
1332
1424
 
1333
1425
void KCalendarTest::testGregorianProlepticBasic()
1334
1426
{
1335
 
    const KCalendarSystem *calendar = KCalendarSystem::create( "gregorian-proleptic" );
 
1427
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::GregorianCalendar );
1336
1428
 
1337
 
    QCOMPARE( calendar->calendarType(), QString( "gregorian-proleptic" ) );
1338
 
    QCOMPARE( KCalendarSystem::calendarLabel( QString( "gregorian-proleptic" ) ), QString( "Gregorian (Proleptic)" ) );
 
1429
    testCalendarSystemType( calendar, KLocale::GregorianCalendar, "gregorian-proleptic", "Gregorian (Proleptic)" );
1339
1430
 
1340
1431
    QCOMPARE( calendar->epoch(), QDate::fromJulianDay( 1721426 ) );
1341
1432
    QCOMPARE( calendar->earliestValidDate(), QDate::fromJulianDay( 38 ) );
1385
1476
 
1386
1477
void KCalendarTest::testHebrewBasic()
1387
1478
{
1388
 
    const KCalendarSystem *calendar = KCalendarSystem::create( "hebrew" );
 
1479
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::HebrewCalendar );
1389
1480
    QDate testDate;
1390
1481
 
1391
 
    QCOMPARE( calendar->calendarType(), QString( "hebrew" ) );
1392
 
    QCOMPARE( KCalendarSystem::calendarLabel( QString( "hebrew" ) ), QString( "Hebrew" ) );
 
1482
    testCalendarSystemType( calendar, KLocale::HebrewCalendar, "hebrew", "Hebrew" );
 
1483
 
1393
1484
    testEpoch( calendar,                1,  1,  1,  347998 );
1394
1485
    testEarliestValidDate( calendar, 5344,  1,  1, 2299498 );
1395
1486
    testLatestValidDate(   calendar, 8119, 13, 29, 3313431 );
1437
1528
 
1438
1529
void KCalendarTest::testHebrewYmd()
1439
1530
{
1440
 
//    const KCalendarSystem *calendar = KCalendarSystem::create( "hebrew" );
 
1531
//    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::HebrewCalendar );
1441
1532
//    testYmd( calendar, 2007, 1, 1, QDate( 2007, 1, 1 ).toJulianDay() );
1442
1533
//    delete calendar;
1443
1534
}
1466
1557
 
1467
1558
void KCalendarTest::testHijriBasic()
1468
1559
{
1469
 
    const KCalendarSystem *calendar = KCalendarSystem::create( "hijri" );
 
1560
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::IslamicCivilCalendar );
1470
1561
    QDate testDate;
1471
1562
 
1472
 
    QCOMPARE( calendar->calendarType(), QString( "hijri" ) );
1473
 
    QCOMPARE( KCalendarSystem::calendarLabel( QString( "hijri" ) ), QString( "Hijri" ) );
 
1563
    testCalendarSystemType( calendar, KLocale::IslamicCivilCalendar, "hijri", "Islamic / Hijri (Civil)" );
1474
1564
 
1475
1565
    QCOMPARE( calendar->epoch(), QDate( 622, 7, 16 ) );
1476
1566
    QCOMPARE( calendar->earliestValidDate(), QDate( 622, 7, 16 ) );
1517
1607
 
1518
1608
void KCalendarTest::testHijriYmd()
1519
1609
{
1520
 
    const KCalendarSystem *calendar = KCalendarSystem::create( "hijri" );
 
1610
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::IslamicCivilCalendar );
1521
1611
    testYmd( calendar, 1426, 8, 6, QDate( 2005, 9, 10 ).toJulianDay() );
1522
1612
    delete calendar;
1523
1613
}
1527
1617
 
1528
1618
void KCalendarTest::testJalaliBasic()
1529
1619
{
1530
 
    const KCalendarSystem *calendar = KCalendarSystem::create( "jalali" );
 
1620
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::JalaliCalendar );
1531
1621
    QDate testDate;
1532
1622
 
1533
 
    QCOMPARE( calendar->calendarType(), QString( "jalali" ) );
1534
 
    QCOMPARE( KCalendarSystem::calendarLabel( QString( "jalali" ) ), QString( "Jalali" ) );
 
1623
    testCalendarSystemType( calendar, KLocale::JalaliCalendar, "jalali", "Jalali" );
1535
1624
 
1536
1625
    //Birashk argorithm only good between AP 1244-01-01 to 1530-12-29 (AD 1865 to 2152)
1537
1626
    QCOMPARE( calendar->epoch(), QDate( 622, 3, 19 ) );
1583
1672
 
1584
1673
void KCalendarTest::testJalaliYmd()
1585
1674
{
1586
 
    const KCalendarSystem *calendar = KCalendarSystem::create( QString("jalali") );
 
1675
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::JalaliCalendar );
1587
1676
    testYmd( calendar, 1384, 6, 9, QDate( 2005, 8, 31 ).toJulianDay() );
1588
1677
    delete calendar;
1589
1678
}
1590
1679
 
1591
1680
void KCalendarTest::testJapanese()
1592
1681
{
1593
 
    const KCalendarSystem *calendar = KCalendarSystem::create( "japanese" );
 
1682
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::JapaneseCalendar );
1594
1683
    QDate testDate( 2005, 9, 10 );
1595
1684
 
1596
1685
    QCOMPARE( calendar->dayOfYear( testDate ), 253 );
1620
1709
 
1621
1710
void KCalendarTest::testJapaneseBasic()
1622
1711
{
1623
 
    const KCalendarSystem *calendar = KCalendarSystem::create( "japanese" );
 
1712
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::JapaneseCalendar );
1624
1713
    QDate testDate;
1625
1714
 
1626
 
    QCOMPARE( calendar->calendarType(), QString( "japanese" ) );
1627
 
    QCOMPARE( KCalendarSystem::calendarLabel( QString( "japanese" ) ), QString( "Japanese" ) );
 
1715
    testCalendarSystemType( calendar, KLocale::JapaneseCalendar, "japanese", "Japanese" );
1628
1716
 
1629
1717
    QCOMPARE( calendar->epoch(), QDate::fromJulianDay( 1721426 ) );
1630
1718
    QCOMPARE( calendar->earliestValidDate(), QDate::fromJulianDay( 1721426 ) );
1669
1757
 
1670
1758
void KCalendarTest::testJapaneseYmd()
1671
1759
{
1672
 
    const KCalendarSystem *calendar = KCalendarSystem::create( "japanese" );
 
1760
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::JapaneseCalendar );
1673
1761
    testYmd( calendar, 2007, 1, 1, QDate( 2007, 1, 1 ).toJulianDay() );
1674
1762
    delete calendar;
1675
1763
}
1676
1764
 
1677
1765
void KCalendarTest::testJapaneseSpecialCases()
1678
1766
{
1679
 
    const KCalendarSystem *calendar = KCalendarSystem::create( "japanese" );
 
1767
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::JapaneseCalendar );
1680
1768
 
1681
1769
    // Test Japanese Eras
1682
1770
    // Heisei > 1        1990-01-01 onwards
1719
1807
 
1720
1808
void KCalendarTest::testMinguoBasic()
1721
1809
{
1722
 
    const KCalendarSystem *calendar = KCalendarSystem::create( "minguo" );
 
1810
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::MinguoCalendar );
1723
1811
 
1724
 
    QCOMPARE( calendar->calendarType(), QString( "minguo" ) );
1725
 
    QCOMPARE( KCalendarSystem::calendarLabel( QString( "minguo" ) ), QString( "Taiwanese" ) );
 
1812
    testCalendarSystemType( calendar, KLocale::MinguoCalendar, "minguo", "Taiwanese" );
1726
1813
 
1727
1814
    QCOMPARE( calendar->epoch(), QDate( 1912, 1, 1 ) );
1728
1815
    QCOMPARE( calendar->earliestValidDate(), QDate( 1912, 1, 1 ) );
1769
1856
 
1770
1857
void KCalendarTest::testThaiBasic()
1771
1858
{
1772
 
    const KCalendarSystem *calendar = KCalendarSystem::create( "thai" );
 
1859
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::ThaiCalendar );
1773
1860
 
1774
 
    QCOMPARE( calendar->calendarType(), QString( "thai" ) );
1775
 
    QCOMPARE( KCalendarSystem::calendarLabel( QString( "thai" ) ), QString( "Thai" ) );
 
1861
    testCalendarSystemType( calendar, KLocale::ThaiCalendar, "thai", "Thai" );
1776
1862
 
1777
1863
    QCOMPARE( calendar->epoch(), QDate( -544, 1, 7 ) );
1778
1864
    QCOMPARE( calendar->earliestValidDate(), QDate( -544, 1, 7 ) );
1818
1904
 
1819
1905
 
1820
1906
// generic test functions, call from calendar system specific ones
 
1907
void KCalendarTest::testCalendarSystemType( const KCalendarSystem *calendar,
 
1908
                                            KLocale::CalendarSystem system,
 
1909
                                            const QString &type, const QString &label )
 
1910
{
 
1911
    QCOMPARE( calendar->calendarType(),                 type );
 
1912
    QCOMPARE( calendar->calendarSystem(),               system );
 
1913
    QCOMPARE( calendar->calendarLabel(),                label );
 
1914
    QCOMPARE( KCalendarSystem::calendarLabel( type ),   label );
 
1915
    QCOMPARE( KCalendarSystem::calendarLabel( system ), label );
 
1916
}
1821
1917
 
1822
1918
// Simply tests valid ranges of ymd values, testYmd covers all other dates
1823
1919
void KCalendarTest::testValid( const KCalendarSystem *calendar, int lowInvalidYear, int highInvalidYear,
1981
2077
    QCOMPARE( calendar->monthName( date ), longName );
1982
2078
}
1983
2079
 
1984
 
void KCalendarTest::testRoundTrip( const KCalendarSystem *calendar )
 
2080
void KCalendarTest::testRoundTrip( const KCalendarSystem *calendar, bool testFullRange )
1985
2081
{
1986
2082
    kDebug() << "Testing round trip of dates for Calendar System " << calendar->calendarType();
1987
2083
    kDebug() << "This may take some time, or you may have created an infinite loop.";
1991
2087
    QDate testDate;
1992
2088
    // Limit to a short interesting date range for regular testing
1993
2089
    // Later add an Env var to choose full test whenever the formulas are changed.
1994
 
    //QDate loopDate = calendar->earliestValidDate();
1995
 
    //QDate terminateDate = calendar->latestValidDate();
1996
 
    QDate loopDate = qMax(QDate(1990, 1, 1), calendar->earliestValidDate());
1997
 
    QDate terminateDate = qMin(QDate(2020, 1, 1), calendar->latestValidDate());
 
2090
    QDate loopDate, terminateDate;
 
2091
    if ( testFullRange ) {
 
2092
        loopDate = calendar->earliestValidDate();
 
2093
        terminateDate = calendar->latestValidDate();
 
2094
    } else {
 
2095
        loopDate = qMax(QDate(1990, 1, 1), calendar->earliestValidDate());
 
2096
        terminateDate = qMin(QDate(2020, 1, 1), calendar->latestValidDate());
 
2097
    }
1998
2098
    QByteArray msg;
1999
2099
    while ( loopDate <= terminateDate ) {
2000
2100
        testYear = calendar->year( loopDate );
2382
2482
    delete calendar;
2383
2483
}
2384
2484
 
 
2485
void KCalendarTest::testKLocalizedDate()
 
2486
{
 
2487
    KGlobal::locale()->setDateFormatShort( "%y-%m-%d" );
 
2488
    const KCalendarSystem *calendar = KGlobal::locale()->calendar();
 
2489
 
 
2490
    // Set up a bunch of KLocalizedDates and QDates that should be equal
 
2491
    QDate testQDate( 2010, 1, 1 );
 
2492
    KLocalizedDate testKLocalizedDate( testQDate );
 
2493
 
 
2494
    // Test KLocalizedDate output calls not in KCalendarSystem
 
2495
    QCOMPARE( KLocalizedDate().isNull(),        true );
 
2496
    QCOMPARE( KLocalizedDate().isValid(),       false );
 
2497
    QCOMPARE( testKLocalizedDate.isNull(),      testQDate.isNull() );
 
2498
    QCOMPARE( testKLocalizedDate.date(),        testQDate );
 
2499
    QCOMPARE( testKLocalizedDate.toJulianDay(), testQDate.toJulianDay() );
 
2500
    testKLocalizedDate.setDate( QDate( 2010, 6, 1 ) );
 
2501
    testQDate.setDate( 2010, 6, 1 );
 
2502
    QCOMPARE( testKLocalizedDate.date(),        testQDate );
 
2503
 
 
2504
    // Test static KLocalizedDate methods
 
2505
    QCOMPARE( KLocalizedDate::currentDate().date(),           QDate::currentDate() );
 
2506
    QCOMPARE( KLocalizedDate::fromDate( testQDate ).date(),   testQDate );
 
2507
    QCOMPARE( KLocalizedDate::fromJulianDay( 100000 ).date(), QDate::fromJulianDay( 100000 ) );
 
2508
 
 
2509
    // Compare KLocalizedDate output to KCalendarSystem output calls
 
2510
    QCOMPARE( testKLocalizedDate.isValid(),                     calendar->isValid( testQDate ) );
 
2511
    QCOMPARE( testKLocalizedDate.year(),                        calendar->year( testQDate ) );
 
2512
    QCOMPARE( testKLocalizedDate.month(),                       calendar->month( testQDate ) );
 
2513
    QCOMPARE( testKLocalizedDate.day(),                         calendar->day( testQDate ) );
 
2514
    QCOMPARE( testKLocalizedDate.eraName(),                     calendar->eraName( testQDate ) );
 
2515
    QCOMPARE( testKLocalizedDate.eraYear(),                     calendar->eraYear( testQDate ) );
 
2516
    QCOMPARE( testKLocalizedDate.yearInEra(),                   calendar->yearInEra( testQDate ) );
 
2517
    QCOMPARE( testKLocalizedDate.addYears( 5 ).date(),          calendar->addYears( testQDate, 5 ) );
 
2518
    QCOMPARE( testKLocalizedDate.addMonths( 5 ).date(),         calendar->addMonths( testQDate, 5 ) );
 
2519
    QCOMPARE( testKLocalizedDate.addDays( 5 ).date(),           calendar->addDays( testQDate, 5 ) );
 
2520
    QCOMPARE( testKLocalizedDate.monthsInYear(),                calendar->monthsInYear( testQDate ) );
 
2521
    QCOMPARE( testKLocalizedDate.weeksInYear(),                 calendar->weeksInYear( testQDate ) );
 
2522
    QCOMPARE( testKLocalizedDate.daysInYear(),                  calendar->daysInYear( testQDate ) );
 
2523
    QCOMPARE( testKLocalizedDate.daysInMonth(),                 calendar->daysInMonth( testQDate ) );
 
2524
    QCOMPARE( testKLocalizedDate.daysInWeek(),                  calendar->daysInWeek( testQDate ) );
 
2525
    QCOMPARE( testKLocalizedDate.dayOfYear(),                   calendar->dayOfYear( testQDate ) );
 
2526
    QCOMPARE( testKLocalizedDate.dayOfWeek(),                   calendar->dayOfWeek( testQDate ) );
 
2527
    QCOMPARE( testKLocalizedDate.week(),                        calendar->weekNumber( testQDate ) );
 
2528
    QCOMPARE( testKLocalizedDate.isLeapYear(),                  calendar->isLeapYear( testQDate ) );
 
2529
    QCOMPARE( testKLocalizedDate.firstDayOfYear().date(),       calendar->firstDayOfYear( testQDate ) );
 
2530
    QCOMPARE( testKLocalizedDate.lastDayOfYear().date(),        calendar->lastDayOfYear( testQDate ) );
 
2531
    QCOMPARE( testKLocalizedDate.firstDayOfMonth().date(),      calendar->firstDayOfMonth( testQDate ) );
 
2532
    QCOMPARE( testKLocalizedDate.lastDayOfMonth().date(),       calendar->lastDayOfMonth( testQDate ) );
 
2533
 
 
2534
    QCOMPARE( testKLocalizedDate.week(KLocale::IsoWeekNumber),        calendar->weekNumber( testQDate ) );
 
2535
    QCOMPARE( testKLocalizedDate.weeksInYear(KLocale::IsoWeekNumber), calendar->weeksInYear( testQDate ) );
 
2536
 
 
2537
    // Compare KLocalizedDate setDate to KCalendarSystem setDate
 
2538
    testKLocalizedDate.setDate( 2010, 3, 1 );
 
2539
    calendar->setDate( testQDate, 2010, 3, 1 );
 
2540
    QCOMPARE( testKLocalizedDate.date(), testQDate );
 
2541
    testKLocalizedDate.setDate( 2010, 100 );
 
2542
    calendar->setDate( testQDate, 2010, 100 );
 
2543
    QCOMPARE( testKLocalizedDate.date(), testQDate );
 
2544
    testKLocalizedDate.setDate( "AD", 2010, 9, 1 );
 
2545
    calendar->setDate( testQDate, "AD", 2010, 9, 1 );
 
2546
    QCOMPARE( testKLocalizedDate.date(), testQDate );
 
2547
    testKLocalizedDate.setDate( KLocale::IsoWeekNumber, 2010, 15, 1 );
 
2548
    calendar->setDateIsoWeek( testQDate, 2010, 15, 1 );
 
2549
    QCOMPARE( testKLocalizedDate.date(), testQDate );
 
2550
    testKLocalizedDate.setCurrentDate();
 
2551
    testQDate = QDate::currentDate();
 
2552
    QCOMPARE( testKLocalizedDate.date(), testQDate );
 
2553
 
 
2554
    // Compare KLocalizedDate getDate to KCalendarSystem getDate
 
2555
    int ky, km, kd, qy, qm, qd;
 
2556
    testKLocalizedDate.getDate( &ky, &km, &kd );
 
2557
    calendar->getDate( testQDate, &qy, &qm, &qd );
 
2558
    QCOMPARE( ky, qy );
 
2559
    QCOMPARE( km, qm );
 
2560
    QCOMPARE( kd, qd );
 
2561
 
 
2562
    // Compare KLocalizedDate format/read to KCalendarSystem format
 
2563
    QCOMPARE( testKLocalizedDate.formatDate(),           calendar->formatDate( testQDate ) );
 
2564
    QCOMPARE( testKLocalizedDate.formatDate("%d-%m-%y"), calendar->formatDate( testQDate, "%d-%m-%y" ) );
 
2565
    QCOMPARE( testKLocalizedDate.formatDateComponent(KLocale::Year),              calendar->yearString( testQDate ) );
 
2566
    QCOMPARE( testKLocalizedDate.formatDateComponent(KLocale::YearName),          calendar->yearString( testQDate ) );
 
2567
    QCOMPARE( testKLocalizedDate.formatDateComponent(KLocale::Month),             calendar->monthString( testQDate, KCalendarSystem::ShortFormat ) );
 
2568
    QCOMPARE( testKLocalizedDate.formatDateComponent(KLocale::MonthName),         calendar->monthName( testQDate ) );
 
2569
    QCOMPARE( testKLocalizedDate.formatDateComponent(KLocale::Day),               calendar->dayString( testQDate, KCalendarSystem::ShortFormat ) );
 
2570
    QCOMPARE( testKLocalizedDate.formatDateComponent(KLocale::DayName),           calendar->dayString( testQDate, KCalendarSystem::ShortFormat ) );
 
2571
    QCOMPARE( testKLocalizedDate.formatDateComponent(KLocale::JulianDay),         QString::number( testQDate.toJulianDay() ) );
 
2572
    QCOMPARE( testKLocalizedDate.formatDateComponent(KLocale::EraName),           calendar->eraName( testQDate ) );
 
2573
    QCOMPARE( testKLocalizedDate.formatDateComponent(KLocale::EraYear),           calendar->eraYear( testQDate ) );
 
2574
    QCOMPARE( testKLocalizedDate.formatDateComponent(KLocale::YearInEra),         calendar->yearInEraString( testQDate ) );
 
2575
    QCOMPARE( testKLocalizedDate.formatDateComponent(KLocale::DayOfYear),         calendar->dayOfYearString( testQDate ) );
 
2576
    QCOMPARE( testKLocalizedDate.formatDateComponent(KLocale::DayOfYearName),     calendar->dayOfYearString( testQDate ) );
 
2577
    QCOMPARE( testKLocalizedDate.formatDateComponent(KLocale::DayOfWeek),         calendar->dayOfWeekString( testQDate ) );
 
2578
    QCOMPARE( testKLocalizedDate.formatDateComponent(KLocale::DayOfWeekName),     calendar->weekDayName( testQDate ) );
 
2579
    QCOMPARE( testKLocalizedDate.formatDateComponent(KLocale::Week),              calendar->weekNumberString( testQDate ) );
 
2580
    int weekYear;
 
2581
    QDate weekDate;
 
2582
    calendar->weekNumber( testQDate, &weekYear );
 
2583
    calendar->setDate( weekDate, weekYear, 1, 1);
 
2584
    QCOMPARE( testKLocalizedDate.formatDateComponent(KLocale::WeekYear),          calendar->yearString( weekDate ) );
 
2585
    QCOMPARE( testKLocalizedDate.formatDateComponent(KLocale::MonthsInYear),      calendar->monthsInYearString( testQDate ) );
 
2586
    QCOMPARE( testKLocalizedDate.formatDateComponent(KLocale::WeeksInYear),       calendar->weeksInYearString( testQDate ) );
 
2587
    QCOMPARE( testKLocalizedDate.formatDateComponent(KLocale::DaysInYear),        calendar->daysInYearString( testQDate ) );
 
2588
    QCOMPARE( testKLocalizedDate.formatDateComponent(KLocale::DaysInMonth),       calendar->daysInMonthString( testQDate ) );
 
2589
    QCOMPARE( testKLocalizedDate.formatDateComponent(KLocale::DaysInWeek),        calendar->daysInWeekString( testQDate ) );
 
2590
 
 
2591
    // Compare KLocalizedDate format/read to KCalendarSystem read
 
2592
    QCOMPARE( testKLocalizedDate.readDate( "2010-01-01" ).date(),                        calendar->readDate( "2010-01-01" ) );
 
2593
    QCOMPARE( testKLocalizedDate.readDate( "2010-01-01", KLocale::NormalFormat ).date(), calendar->readDate( "2010-01-01", KLocale::NormalFormat ) );
 
2594
    QCOMPARE( testKLocalizedDate.readDate( "2010-01-01", "%y-%m-%d" ).date(),            calendar->readDate( "2010-01-01", "%y-%m-%d" ) );
 
2595
 
 
2596
    // Test new addOn methods
 
2597
    testKLocalizedDate.addYearsTo( 5 );
 
2598
    testQDate = calendar->addYears( testQDate, 5 );
 
2599
    QCOMPARE( testKLocalizedDate.date(), testQDate );
 
2600
    testKLocalizedDate.addMonthsTo( 5 );
 
2601
    testQDate = calendar->addMonths( testQDate, 5 );
 
2602
    QCOMPARE( testKLocalizedDate.date(), testQDate );
 
2603
    testKLocalizedDate.addDaysTo( 5 );
 
2604
    testQDate = calendar->addDays( testQDate, 5 );
 
2605
    QCOMPARE( testKLocalizedDate.date(), testQDate );
 
2606
 
 
2607
    // Set up some dates for comparisons
 
2608
    QDate lowQDate( 2000, 1, 1 );
 
2609
    KLocalizedDate lowKLocalizedDate( lowQDate );
 
2610
    QDate highQDate( 2010, 1, 1 );
 
2611
    KLocalizedDate highKLocalizedDate( highQDate );
 
2612
 
 
2613
    // Compare the difference methods
 
2614
    int kdy, kdm, kdd, kdir, qdy, qdm, qdd, qdir;
 
2615
    lowKLocalizedDate.dateDifference( highKLocalizedDate, &kdy, &kdm, &kdd, &kdir );
 
2616
    calendar->dateDifference( lowKLocalizedDate.date(), highKLocalizedDate.date(), &qdy, &qdm, &qdd, &qdir );
 
2617
    QCOMPARE( kdy, qdy );
 
2618
    QCOMPARE( kdm, qdm );
 
2619
    QCOMPARE( kdd, qdd );
 
2620
    QCOMPARE( kdir, qdir );
 
2621
    lowKLocalizedDate.dateDifference( highQDate, &kdy, &kdm, &kdd, &kdir );
 
2622
    calendar->dateDifference( lowKLocalizedDate.date(), highQDate, &qdy, &qdm, &qdd, &qdir );
 
2623
    QCOMPARE( kdy, qdy );
 
2624
    QCOMPARE( kdm, qdm );
 
2625
    QCOMPARE( kdd, qdd );
 
2626
    QCOMPARE( kdir, qdir );
 
2627
    QCOMPARE( lowKLocalizedDate.yearsDifference( highKLocalizedDate ),  calendar->yearsDifference( lowQDate, highQDate ) );
 
2628
    QCOMPARE( lowKLocalizedDate.yearsDifference( highQDate ),  calendar->yearsDifference( lowQDate, highQDate ) );
 
2629
    QCOMPARE( lowKLocalizedDate.monthsDifference( highKLocalizedDate ), calendar->monthsDifference( lowQDate, highQDate ) );
 
2630
    QCOMPARE( lowKLocalizedDate.monthsDifference( highQDate ), calendar->monthsDifference( lowQDate, highQDate ) );
 
2631
    QCOMPARE( lowKLocalizedDate.daysDifference( highKLocalizedDate ),   calendar->daysDifference( lowQDate, highQDate ) );
 
2632
    QCOMPARE( lowKLocalizedDate.daysDifference( highQDate ),   calendar->daysDifference( lowQDate, highQDate ) );
 
2633
 
 
2634
    // Test new operators
 
2635
    QCOMPARE( lowKLocalizedDate == lowKLocalizedDate,   true );
 
2636
    QCOMPARE( lowKLocalizedDate == highKLocalizedDate,  false );
 
2637
    QCOMPARE( lowKLocalizedDate == lowQDate,   true );
 
2638
    QCOMPARE( lowKLocalizedDate == highQDate,  false );
 
2639
    QCOMPARE( lowKLocalizedDate != lowKLocalizedDate,   false );
 
2640
    QCOMPARE( lowKLocalizedDate != highKLocalizedDate,  true );
 
2641
    QCOMPARE( lowKLocalizedDate != lowQDate,   false );
 
2642
    QCOMPARE( lowKLocalizedDate != highQDate,  true );
 
2643
    QCOMPARE( highKLocalizedDate < lowKLocalizedDate,   false );
 
2644
    QCOMPARE( lowKLocalizedDate  < highKLocalizedDate,  true );
 
2645
    QCOMPARE( highKLocalizedDate < lowQDate,   false );
 
2646
    QCOMPARE( lowKLocalizedDate  < highQDate,  true );
 
2647
    QCOMPARE( highKLocalizedDate <= lowKLocalizedDate,  false );
 
2648
    QCOMPARE( lowKLocalizedDate  <= lowKLocalizedDate,  true );
 
2649
    QCOMPARE( lowKLocalizedDate  <= highKLocalizedDate, true );
 
2650
    QCOMPARE( highKLocalizedDate <= lowQDate,  false );
 
2651
    QCOMPARE( lowKLocalizedDate  <= lowQDate,  true );
 
2652
    QCOMPARE( lowKLocalizedDate  <= highQDate, true );
 
2653
    QCOMPARE( highKLocalizedDate > lowKLocalizedDate,   true );
 
2654
    QCOMPARE( lowKLocalizedDate  > highKLocalizedDate,  false );
 
2655
    QCOMPARE( highKLocalizedDate > lowQDate,   true );
 
2656
    QCOMPARE( lowKLocalizedDate  > highQDate,  false );
 
2657
    QCOMPARE( highKLocalizedDate >= lowKLocalizedDate,  true );
 
2658
    QCOMPARE( lowKLocalizedDate  >= lowKLocalizedDate,  true );
 
2659
    QCOMPARE( lowKLocalizedDate  >= highKLocalizedDate, false );
 
2660
    QCOMPARE( highKLocalizedDate >= lowQDate,  true );
 
2661
    QCOMPARE( lowKLocalizedDate  >= lowQDate,  true );
 
2662
    QCOMPARE( lowKLocalizedDate  >= highQDate, false );
 
2663
 
 
2664
    // Test changing Calendar System
 
2665
    KCalendarSystem *hijri = KCalendarSystem::create( KLocale::IslamicCivilCalendar );
 
2666
    testKLocalizedDate.setCalendarSystem( KLocale::IslamicCivilCalendar );
 
2667
    QCOMPARE( testKLocalizedDate.year(), hijri->year( testQDate ) );
 
2668
 
 
2669
    // Test copy of calendar object
 
2670
    if (true) {
 
2671
        KLocalizedDate test2 = testKLocalizedDate;
 
2672
        test2.day();
 
2673
    }
 
2674
    testKLocalizedDate.day();
 
2675
 
 
2676
    KLocalizedDate newOne = testKLocalizedDate.currentDate();
 
2677
    kDebug() << newOne;
 
2678
    newOne = KLocalizedDate::currentDate();
 
2679
    kDebug() << newOne;
 
2680
}