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

« back to all changes in this revision

Viewing changes to kdecore/tests/kdatetimeformattertest.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:
 
1
/*
 
2
    Copyright 2010 John Layt <john@layt.net>
 
3
 
 
4
    This library is free software; you can redistribute it and/or
 
5
    modify it under the terms of the GNU Library General Public
 
6
    License as published by the Free Software Foundation; either
 
7
    version 2 of the License, or (at your option) any later version.
 
8
 
 
9
    This library is distributed in the hope that it will be useful,
 
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
    Library General Public License for more details.
 
13
 
 
14
    You should have received a copy of the GNU Library General Public License
 
15
    along with this library; see the file COPYING.LIB.  If not, write to
 
16
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
17
    Boston, MA 02110-1301, USA.
 
18
*/
 
19
 
 
20
#include "kdatetimeformattertest.h"
 
21
 
 
22
#include <locale.h>
 
23
 
 
24
#include "config.h"
 
25
 
 
26
#include <QtCore/QString>
 
27
 
 
28
#include "qtest_kde.h"
 
29
#include "kdatetime.h"
 
30
#include "kcalendarsystem.h"
 
31
#include "kdatetimeformatter_p.h"
 
32
#include "klocale.h"
 
33
#include "kglobal.h"
 
34
#include "kdebug.h"
 
35
#include "kstandarddirs.h"
 
36
#include "kconfiggroup.h"
 
37
 
 
38
#include "kdatetimeformattertest.moc"
 
39
 
 
40
QTEST_KDEMAIN_CORE_WITH_COMPONENTNAME( KDateTimeFormatterTest, "kdecalendarsystems" /*so that the .po exists*/ )
 
41
 
 
42
void KDateTimeFormatterTest::testFormatDateTimePosix()
 
43
{
 
44
    KGlobal::locale()->setLanguage( QStringList( "en_US" ) );
 
45
    KGlobal::locale()->setCalendar( "gregorian" );
 
46
    KGlobal::locale()->setDateFormatShort( "%y-%m-%d" );
 
47
 
 
48
    KDateTimeFormatter formatter;
 
49
 
 
50
    //Test default settings
 
51
    KDateTime testDate( QDate ( 2005, 10, 20 ) );
 
52
    QCOMPARE( formatter.formatDateTime( testDate, "%Y" ), QString( "2005" ) );
 
53
    QCOMPARE( formatter.formatDateTime( testDate, "%C" ), QString( "20" ) );
 
54
    QCOMPARE( formatter.formatDateTime( testDate, "%y" ), QString( "05" ) );
 
55
    QCOMPARE( formatter.formatDateTime( testDate, "%m" ), QString( "10" ) );
 
56
    QCOMPARE( formatter.formatDateTime( testDate, "%n" ), QString( "10" ) );
 
57
    QCOMPARE( formatter.formatDateTime( testDate, "%d" ), QString( "20" ) );
 
58
    QCOMPARE( formatter.formatDateTime( testDate, "%e" ), QString( "20" ) );
 
59
    QCOMPARE( formatter.formatDateTime( testDate, "%B" ), QString( "October" ) );
 
60
    QCOMPARE( formatter.formatDateTime( testDate, "%b" ), QString( "Oct" ) );
 
61
    QCOMPARE( formatter.formatDateTime( testDate, "%h" ), QString( "Oct" ) );
 
62
    QCOMPARE( formatter.formatDateTime( testDate, "%A" ), QString( "Thursday" ) );
 
63
    QCOMPARE( formatter.formatDateTime( testDate, "%a" ), QString( "Thu" ) );
 
64
    QCOMPARE( formatter.formatDateTime( testDate, "%j" ), QString( "293" ) );
 
65
    QCOMPARE( formatter.formatDateTime( testDate, "%V" ), QString( "42" ) );
 
66
    QCOMPARE( formatter.formatDateTime( testDate, "%G" ), QString( "2005" ) );
 
67
    QCOMPARE( formatter.formatDateTime( testDate, "%g" ), QString( "05" ) );
 
68
    QCOMPARE( formatter.formatDateTime( testDate, "%u" ), QString( "4" ) );
 
69
    QCOMPARE( formatter.formatDateTime( testDate, "%D" ), QString( "10/20/05" ) );
 
70
    QCOMPARE( formatter.formatDateTime( testDate, "%F" ), QString( "2005-10-20" ) );
 
71
    QCOMPARE( formatter.formatDateTime( testDate, "%x" ), QString( "05-10-20" ) );
 
72
    QCOMPARE( formatter.formatDateTime( testDate, "%%" ), QString( "%" ) );
 
73
    QCOMPARE( formatter.formatDateTime( testDate, "%t" ), QString( "\t" ) );
 
74
 
 
75
    QCOMPARE( formatter.formatDateTime( testDate, "-%Y-%C-%y-%m-%n-%d-%e-%B-%b-%h-%A-%a-%j-%V-%G-%g-%u:%D:%F:%x:%%-%t-" ),
 
76
              QString( "-2005-20-05-10-10-20-20-October-Oct-Oct-Thursday-Thu-293-42-2005-05-4:10/20/05:2005-10-20:05-10-20:%-\t-" ) );
 
77
 
 
78
    //Test the minimum widths are respected
 
79
    QCOMPARE( formatter.formatDateTime( testDate, "%1Y" ),  QString( "2005" ) );
 
80
    QCOMPARE( formatter.formatDateTime( testDate, "%1C" ),  QString( "20" ) );
 
81
    QCOMPARE( formatter.formatDateTime( testDate, "%1y" ),  QString( "05" ) );
 
82
    QCOMPARE( formatter.formatDateTime( testDate, "%1m" ),  QString( "10" ) );
 
83
    QCOMPARE( formatter.formatDateTime( testDate, "%1n" ),  QString( "10" ) );
 
84
    QCOMPARE( formatter.formatDateTime( testDate, "%1d" ),  QString( "20" ) );
 
85
    QCOMPARE( formatter.formatDateTime( testDate, "%1e" ),  QString( "20" ) );
 
86
    QCOMPARE( formatter.formatDateTime( testDate, "%01B" ), QString( "October" ) );
 
87
    QCOMPARE( formatter.formatDateTime( testDate, "%01b" ), QString( "Oct" ) );
 
88
    QCOMPARE( formatter.formatDateTime( testDate, "%01h" ), QString( "Oct" ) );
 
89
    QCOMPARE( formatter.formatDateTime( testDate, "%01A" ), QString( "Thursday" ) );
 
90
    QCOMPARE( formatter.formatDateTime( testDate, "%01a" ), QString( "Thu" ) );
 
91
    QCOMPARE( formatter.formatDateTime( testDate, "%1j" ),  QString( "293" ) );
 
92
    QCOMPARE( formatter.formatDateTime( testDate, "%1V" ),  QString( "42" ) );
 
93
    QCOMPARE( formatter.formatDateTime( testDate, "%1G" ),  QString( "2005" ) );
 
94
    QCOMPARE( formatter.formatDateTime( testDate, "%1g" ),  QString( "05" ) );
 
95
    QCOMPARE( formatter.formatDateTime( testDate, "%1u" ),  QString( "4" ) );
 
96
    QCOMPARE( formatter.formatDateTime( testDate, "%1D" ),  QString( "10/20/05" ) );
 
97
    QCOMPARE( formatter.formatDateTime( testDate, "%1F" ),  QString( "2005-10-20" ) );
 
98
    QCOMPARE( formatter.formatDateTime( testDate, "%1x" ),  QString( "05-10-20" ) );
 
99
    QCOMPARE( formatter.formatDateTime( testDate, "%1%" ),  QString( "%" ) );
 
100
    QCOMPARE( formatter.formatDateTime( testDate, "%1t" ),  QString( "\t" ) );
 
101
 
 
102
    testDate.setDate( QDate( 2005, 1, 2 ) );
 
103
 
 
104
    //Test various padding options with minimum width
 
105
    QCOMPARE( formatter.formatDateTime( testDate, "%" ),     QString( "" ) );
 
106
    QCOMPARE( formatter.formatDateTime( testDate, "%m" ),    QString( "01" ) );
 
107
    QCOMPARE( formatter.formatDateTime( testDate, "%n" ),    QString( "1" ) );
 
108
    QCOMPARE( formatter.formatDateTime( testDate, "%d" ),    QString( "02" ) );
 
109
    QCOMPARE( formatter.formatDateTime( testDate, "%e" ),    QString( "2" ) );
 
110
    QCOMPARE( formatter.formatDateTime( testDate, "%j" ),    QString( "002" ) );
 
111
    QCOMPARE( formatter.formatDateTime( testDate, "%_m" ),   QString( " 1" ) );
 
112
    QCOMPARE( formatter.formatDateTime( testDate, "%_n" ),   QString( "1" ) );
 
113
    QCOMPARE( formatter.formatDateTime( testDate, "%_d" ),   QString( " 2" ) );
 
114
    QCOMPARE( formatter.formatDateTime( testDate, "%_e" ),   QString( "2" ) );
 
115
    QCOMPARE( formatter.formatDateTime( testDate, "%_j" ),   QString( "  2" ) );
 
116
    QCOMPARE( formatter.formatDateTime( testDate, "%-m" ),   QString( "1" ) );
 
117
    QCOMPARE( formatter.formatDateTime( testDate, "%-n" ),   QString( "1" ) );
 
118
    QCOMPARE( formatter.formatDateTime( testDate, "%-d" ),   QString( "2" ) );
 
119
    QCOMPARE( formatter.formatDateTime( testDate, "%-e" ),   QString( "2" ) );
 
120
    QCOMPARE( formatter.formatDateTime( testDate, "%-j" ),   QString( "2" ) );
 
121
    QCOMPARE( formatter.formatDateTime( testDate, "%0m" ),   QString( "01" ) );
 
122
    QCOMPARE( formatter.formatDateTime( testDate, "%0n" ),   QString( "1" ) );
 
123
    QCOMPARE( formatter.formatDateTime( testDate, "%0d" ),   QString( "02" ) );
 
124
    QCOMPARE( formatter.formatDateTime( testDate, "%0e" ),   QString( "2" ) );
 
125
    QCOMPARE( formatter.formatDateTime( testDate, "%0j" ),   QString( "002" ) );
 
126
    QCOMPARE( formatter.formatDateTime( testDate, "%-_j" ),  QString( "  2" ) );
 
127
    QCOMPARE( formatter.formatDateTime( testDate, "%_-j" ),  QString( "2" ) );
 
128
    QCOMPARE( formatter.formatDateTime( testDate, "%-_0j" ), QString( "002" ) );
 
129
 
 
130
    //Test various padding options with width override
 
131
    QCOMPARE( formatter.formatDateTime( testDate, "%1m" ),   QString( "01" ) );
 
132
    QCOMPARE( formatter.formatDateTime( testDate, "%-05m" ), QString( "00001" ) );
 
133
    QCOMPARE( formatter.formatDateTime( testDate, "%10m" ),  QString( "0000000001" ) );
 
134
    QCOMPARE( formatter.formatDateTime( testDate, "%15m" ),  QString( "000000000000001" ) );
 
135
    QCOMPARE( formatter.formatDateTime( testDate, "%-5m" ),  QString( "1" ) );
 
136
    QCOMPARE( formatter.formatDateTime( testDate, "%_5m" ),  QString( "    1" ) );
 
137
    QCOMPARE( formatter.formatDateTime( testDate, "%_15m" ), QString( "              1" ) );
 
138
    QCOMPARE( formatter.formatDateTime( testDate, "%1B" ),   QString( "January" ) );
 
139
    QCOMPARE( formatter.formatDateTime( testDate, "%15B" ),  QString( "        January" ) );
 
140
    QCOMPARE( formatter.formatDateTime( testDate, "%-15B" ), QString( "January" ) );
 
141
    QCOMPARE( formatter.formatDateTime( testDate, "%_15B" ), QString( "        January" ) );
 
142
    QCOMPARE( formatter.formatDateTime( testDate, "%015B" ), QString( "00000000January" ) );
 
143
 
 
144
    //Test week number in previous year
 
145
    QCOMPARE( formatter.formatDateTime( testDate, "%V" ), QString( "53" ) );
 
146
    QCOMPARE( formatter.formatDateTime( testDate, "%G" ), QString( "2004" ) );
 
147
    QCOMPARE( formatter.formatDateTime( testDate, "%g" ), QString( "04" ) );
 
148
 
 
149
    //test case overrides
 
150
    QCOMPARE( formatter.formatDateTime( testDate, "%B" ),  QString( "January" ) );
 
151
    QCOMPARE( formatter.formatDateTime( testDate, "%^B" ), QString( "JANUARY" ) );
 
152
    QCOMPARE( formatter.formatDateTime( testDate, "%#B" ), QString( "JANUARY" ) );
 
153
    QCOMPARE( formatter.formatDateTime( testDate, "%m" ),  QString( "01" ) );
 
154
    QCOMPARE( formatter.formatDateTime( testDate, "%^m" ), QString( "01" ) );
 
155
    QCOMPARE( formatter.formatDateTime( testDate, "%#m" ), QString( "01" ) );
 
156
 
 
157
    //Test various year options
 
158
 
 
159
    testDate.setDate( QDate( 789, 1, 1 ) );
 
160
    QCOMPARE( formatter.formatDateTime( testDate, "%Y" ),  QString( "0789" ) );
 
161
    QCOMPARE( formatter.formatDateTime( testDate, "%C" ),  QString( "07" ) );
 
162
    QCOMPARE( formatter.formatDateTime( testDate, "%y" ),  QString( "89" ) );
 
163
    QCOMPARE( formatter.formatDateTime( testDate, "%-Y" ), QString( "789" ) );
 
164
    QCOMPARE( formatter.formatDateTime( testDate, "%-C" ), QString( "7" ) );
 
165
    QCOMPARE( formatter.formatDateTime( testDate, "%-y" ), QString( "89" ) );
 
166
    QCOMPARE( formatter.formatDateTime( testDate, "%_Y" ), QString( " 789" ) );
 
167
    QCOMPARE( formatter.formatDateTime( testDate, "%_C" ), QString( " 7" ) );
 
168
    QCOMPARE( formatter.formatDateTime( testDate, "%_y" ), QString( "89" ) );
 
169
    QCOMPARE( formatter.formatDateTime( testDate, "%0Y" ), QString( "0789" ) );
 
170
    QCOMPARE( formatter.formatDateTime( testDate, "%0C" ), QString( "07" ) );
 
171
    QCOMPARE( formatter.formatDateTime( testDate, "%0y" ), QString( "89" ) );
 
172
    QCOMPARE( formatter.formatDateTime( testDate, "%EC" ), QString( "AD" ) );
 
173
    QCOMPARE( formatter.formatDateTime( testDate, "%Ey" ), QString( "789" ) );
 
174
    QCOMPARE( formatter.formatDateTime( testDate, "%EY" ), QString( "789 AD" ) );
 
175
 
 
176
    testDate.setDate( QDate( 709, 1, 1 ) );
 
177
    QCOMPARE( formatter.formatDateTime( testDate, "%Y" ),  QString( "0709" ) );
 
178
    QCOMPARE( formatter.formatDateTime( testDate, "%C" ),  QString( "07" ) );
 
179
    QCOMPARE( formatter.formatDateTime( testDate, "%y" ),  QString( "09" ) );
 
180
    QCOMPARE( formatter.formatDateTime( testDate, "%-Y" ), QString( "709" ) );
 
181
    QCOMPARE( formatter.formatDateTime( testDate, "%-C" ), QString( "7" ) );
 
182
    QCOMPARE( formatter.formatDateTime( testDate, "%-y" ), QString( "9" ) );
 
183
    QCOMPARE( formatter.formatDateTime( testDate, "%_Y" ), QString( " 709" ) );
 
184
    QCOMPARE( formatter.formatDateTime( testDate, "%_C" ), QString( " 7" ) );
 
185
    QCOMPARE( formatter.formatDateTime( testDate, "%_y" ), QString( " 9" ) );
 
186
    QCOMPARE( formatter.formatDateTime( testDate, "%0Y" ), QString( "0709" ) );
 
187
    QCOMPARE( formatter.formatDateTime( testDate, "%0C" ), QString( "07" ) );
 
188
    QCOMPARE( formatter.formatDateTime( testDate, "%0y" ), QString( "09" ) );
 
189
    QCOMPARE( formatter.formatDateTime( testDate, "%EC" ), QString( "AD" ) );
 
190
    QCOMPARE( formatter.formatDateTime( testDate, "%Ey" ), QString( "709" ) );
 
191
    QCOMPARE( formatter.formatDateTime( testDate, "%EY" ), QString( "709 AD" ) );
 
192
 
 
193
    testDate.setDate( QDate( 89, 1, 1 ) );
 
194
    QCOMPARE( formatter.formatDateTime( testDate, "%Y" ),  QString( "0089" ) );
 
195
    QCOMPARE( formatter.formatDateTime( testDate, "%C" ),  QString( "00" ) );
 
196
    QCOMPARE( formatter.formatDateTime( testDate, "%y" ),  QString( "89" ) );
 
197
    QCOMPARE( formatter.formatDateTime( testDate, "%-Y" ), QString( "89" ) );
 
198
    QCOMPARE( formatter.formatDateTime( testDate, "%-C" ), QString( "0" ) );
 
199
    QCOMPARE( formatter.formatDateTime( testDate, "%-y" ), QString( "89" ) );
 
200
    QCOMPARE( formatter.formatDateTime( testDate, "%_Y" ), QString( "  89" ) );
 
201
    QCOMPARE( formatter.formatDateTime( testDate, "%_C" ), QString( " 0" ) );
 
202
    QCOMPARE( formatter.formatDateTime( testDate, "%_y" ), QString( "89" ) );
 
203
    QCOMPARE( formatter.formatDateTime( testDate, "%0Y" ), QString( "0089" ) );
 
204
    QCOMPARE( formatter.formatDateTime( testDate, "%0C" ), QString( "00" ) );
 
205
    QCOMPARE( formatter.formatDateTime( testDate, "%0y" ), QString( "89" ) );
 
206
    QCOMPARE( formatter.formatDateTime( testDate, "%EC" ), QString( "AD" ) );
 
207
    QCOMPARE( formatter.formatDateTime( testDate, "%Ey" ), QString( "89" ) );
 
208
    QCOMPARE( formatter.formatDateTime( testDate, "%EY" ), QString( "89 AD" ) );
 
209
 
 
210
    testDate.setDate( QDate( 9, 1, 1 ) );
 
211
    QCOMPARE( formatter.formatDateTime( testDate, "%Y" ),  QString( "0009" ) );
 
212
    QCOMPARE( formatter.formatDateTime( testDate, "%C" ),  QString( "00" ) );
 
213
    QCOMPARE( formatter.formatDateTime( testDate, "%y" ),  QString( "09" ) );
 
214
    QCOMPARE( formatter.formatDateTime( testDate, "%-Y" ), QString( "9" ) );
 
215
    QCOMPARE( formatter.formatDateTime( testDate, "%-C" ), QString( "0" ) );
 
216
    QCOMPARE( formatter.formatDateTime( testDate, "%-y" ), QString( "9" ) );
 
217
    QCOMPARE( formatter.formatDateTime( testDate, "%_Y" ), QString( "   9" ) );
 
218
    QCOMPARE( formatter.formatDateTime( testDate, "%_C" ), QString( " 0" ) );
 
219
    QCOMPARE( formatter.formatDateTime( testDate, "%_y" ), QString( " 9" ) );
 
220
    QCOMPARE( formatter.formatDateTime( testDate, "%0Y" ), QString( "0009" ) );
 
221
    QCOMPARE( formatter.formatDateTime( testDate, "%0C" ), QString( "00" ) );
 
222
    QCOMPARE( formatter.formatDateTime( testDate, "%0y" ), QString( "09" ) );
 
223
    QCOMPARE( formatter.formatDateTime( testDate, "%EC" ), QString( "AD" ) );
 
224
    QCOMPARE( formatter.formatDateTime( testDate, "%Ey" ), QString( "9" ) );
 
225
    QCOMPARE( formatter.formatDateTime( testDate, "%EY" ), QString( "9 AD" ) );
 
226
 
 
227
    testDate.setDate( QDate( -9, 1, 1 ) );
 
228
    QCOMPARE( formatter.formatDateTime( testDate, "%Y" ),  QString( "-0009" ) );
 
229
    QCOMPARE( formatter.formatDateTime( testDate, "%C" ),  QString( "-00" ) );
 
230
    QCOMPARE( formatter.formatDateTime( testDate, "%y" ),  QString( "-09" ) );
 
231
    QCOMPARE( formatter.formatDateTime( testDate, "%-Y" ), QString( "-9" ) );
 
232
    QCOMPARE( formatter.formatDateTime( testDate, "%-C" ), QString( "-0" ) );
 
233
    QCOMPARE( formatter.formatDateTime( testDate, "%-y" ), QString( "-9" ) );
 
234
    QCOMPARE( formatter.formatDateTime( testDate, "%_Y" ), QString( "  -9" ) );
 
235
    QCOMPARE( formatter.formatDateTime( testDate, "%_C" ), QString( "-0" ) );
 
236
    QCOMPARE( formatter.formatDateTime( testDate, "%_y" ), QString( "-9" ) );
 
237
    QCOMPARE( formatter.formatDateTime( testDate, "%0Y" ), QString( "-0009" ) );
 
238
    QCOMPARE( formatter.formatDateTime( testDate, "%0C" ), QString( "-00" ) );
 
239
    QCOMPARE( formatter.formatDateTime( testDate, "%0y" ), QString( "-09" ) );
 
240
    QCOMPARE( formatter.formatDateTime( testDate, "%EC" ), QString( "BC" ) );
 
241
    QCOMPARE( formatter.formatDateTime( testDate, "%Ey" ), QString( "9" ) );
 
242
    QCOMPARE( formatter.formatDateTime( testDate, "%EY" ), QString( "9 BC" ) );
 
243
 
 
244
    testDate.setDate( QDate( -89, 1, 1 ) );
 
245
    QCOMPARE( formatter.formatDateTime( testDate, "%Y" ),  QString( "-0089" ) );
 
246
    QCOMPARE( formatter.formatDateTime( testDate, "%C" ),  QString( "-00" ) );
 
247
    QCOMPARE( formatter.formatDateTime( testDate, "%y" ),  QString( "-89" ) );
 
248
    QCOMPARE( formatter.formatDateTime( testDate, "%-Y" ), QString( "-89" ) );
 
249
    QCOMPARE( formatter.formatDateTime( testDate, "%-C" ), QString( "-0" ) );
 
250
    QCOMPARE( formatter.formatDateTime( testDate, "%-y" ), QString( "-89" ) );
 
251
    QCOMPARE( formatter.formatDateTime( testDate, "%_Y" ), QString( " -89" ) );
 
252
    QCOMPARE( formatter.formatDateTime( testDate, "%_C" ), QString( "-0" ) );
 
253
    QCOMPARE( formatter.formatDateTime( testDate, "%_y" ), QString( "-89" ) );
 
254
    QCOMPARE( formatter.formatDateTime( testDate, "%0Y" ), QString( "-0089" ) );
 
255
    QCOMPARE( formatter.formatDateTime( testDate, "%0C" ), QString( "-00" ) );
 
256
    QCOMPARE( formatter.formatDateTime( testDate, "%0y" ), QString( "-89" ) );
 
257
    QCOMPARE( formatter.formatDateTime( testDate, "%EC" ), QString( "BC" ) );
 
258
    QCOMPARE( formatter.formatDateTime( testDate, "%Ey" ), QString( "89" ) );
 
259
    QCOMPARE( formatter.formatDateTime( testDate, "%EY" ), QString( "89 BC" ) );
 
260
 
 
261
    testDate.setDate( QDate( -789, 1, 1 ) );
 
262
    QCOMPARE( formatter.formatDateTime( testDate, "%Y" ),  QString( "-0789" ) );
 
263
    QCOMPARE( formatter.formatDateTime( testDate, "%C" ),  QString( "-07" ) );
 
264
    QCOMPARE( formatter.formatDateTime( testDate, "%y" ),  QString( "-89" ) );
 
265
    QCOMPARE( formatter.formatDateTime( testDate, "%-Y" ), QString( "-789" ) );
 
266
    QCOMPARE( formatter.formatDateTime( testDate, "%-C" ), QString( "-7" ) );
 
267
    QCOMPARE( formatter.formatDateTime( testDate, "%-y" ), QString( "-89" ) );
 
268
    QCOMPARE( formatter.formatDateTime( testDate, "%_Y" ), QString( "-789" ) );
 
269
    QCOMPARE( formatter.formatDateTime( testDate, "%_C" ), QString( "-7" ) );
 
270
    QCOMPARE( formatter.formatDateTime( testDate, "%_y" ), QString( "-89" ) );
 
271
    QCOMPARE( formatter.formatDateTime( testDate, "%0Y" ), QString( "-0789" ) );
 
272
    QCOMPARE( formatter.formatDateTime( testDate, "%0C" ), QString( "-07" ) );
 
273
    QCOMPARE( formatter.formatDateTime( testDate, "%0y" ), QString( "-89" ) );
 
274
    QCOMPARE( formatter.formatDateTime( testDate, "%EC" ), QString( "BC" ) );
 
275
    QCOMPARE( formatter.formatDateTime( testDate, "%Ey" ), QString( "789" ) );
 
276
    QCOMPARE( formatter.formatDateTime( testDate, "%EY" ), QString( "789 BC" ) );
 
277
 
 
278
    testDate.setDate( QDate( -709, 1, 1 ) );
 
279
    QCOMPARE( formatter.formatDateTime( testDate, "%Y" ),  QString( "-0709" ) );
 
280
    QCOMPARE( formatter.formatDateTime( testDate, "%C" ),  QString( "-07" ) );
 
281
    QCOMPARE( formatter.formatDateTime( testDate, "%y" ),  QString( "-09" ) );
 
282
    QCOMPARE( formatter.formatDateTime( testDate, "%-Y" ), QString( "-709" ) );
 
283
    QCOMPARE( formatter.formatDateTime( testDate, "%-C" ), QString( "-7" ) );
 
284
    QCOMPARE( formatter.formatDateTime( testDate, "%-y" ), QString( "-9" ) );
 
285
    QCOMPARE( formatter.formatDateTime( testDate, "%_Y" ), QString( "-709" ) );
 
286
    QCOMPARE( formatter.formatDateTime( testDate, "%_C" ), QString( "-7" ) );
 
287
    QCOMPARE( formatter.formatDateTime( testDate, "%_y" ), QString( "-9" ) );
 
288
    QCOMPARE( formatter.formatDateTime( testDate, "%0Y" ), QString( "-0709" ) );
 
289
    QCOMPARE( formatter.formatDateTime( testDate, "%0C" ), QString( "-07" ) );
 
290
    QCOMPARE( formatter.formatDateTime( testDate, "%0y" ), QString( "-09" ) );
 
291
    QCOMPARE( formatter.formatDateTime( testDate, "%EC" ), QString( "BC" ) );
 
292
    QCOMPARE( formatter.formatDateTime( testDate, "%Ey" ), QString( "709" ) );
 
293
    QCOMPARE( formatter.formatDateTime( testDate, "%EY" ), QString( "709 BC" ) );
 
294
 
 
295
    testDate.setDate( QDate( -1789, 1, 1 ) );
 
296
    QCOMPARE( formatter.formatDateTime( testDate, "%Y" ),  QString( "-1789" ) );
 
297
    QCOMPARE( formatter.formatDateTime( testDate, "%C" ),  QString( "-17" ) );
 
298
    QCOMPARE( formatter.formatDateTime( testDate, "%y" ),  QString( "-89" ) );
 
299
    QCOMPARE( formatter.formatDateTime( testDate, "%-Y" ), QString( "-1789" ) );
 
300
    QCOMPARE( formatter.formatDateTime( testDate, "%-C" ), QString( "-17" ) );
 
301
    QCOMPARE( formatter.formatDateTime( testDate, "%-y" ), QString( "-89" ) );
 
302
    QCOMPARE( formatter.formatDateTime( testDate, "%_Y" ), QString( "-1789" ) );
 
303
    QCOMPARE( formatter.formatDateTime( testDate, "%_C" ), QString( "-17" ) );
 
304
    QCOMPARE( formatter.formatDateTime( testDate, "%_y" ), QString( "-89" ) );
 
305
    QCOMPARE( formatter.formatDateTime( testDate, "%0Y" ), QString( "-1789" ) );
 
306
    QCOMPARE( formatter.formatDateTime( testDate, "%0C" ), QString( "-17" ) );
 
307
    QCOMPARE( formatter.formatDateTime( testDate, "%0y" ), QString( "-89" ) );
 
308
    QCOMPARE( formatter.formatDateTime( testDate, "%EC" ), QString( "BC" ) );
 
309
    QCOMPARE( formatter.formatDateTime( testDate, "%Ey" ), QString( "1789" ) );
 
310
    QCOMPARE( formatter.formatDateTime( testDate, "%EY" ), QString( "1789 BC" ) );
 
311
 
 
312
    testDate.setDate( QDate( -1709, 1, 1 ) );
 
313
    QCOMPARE( formatter.formatDateTime( testDate, "%Y" ),  QString( "-1709" ) );
 
314
    QCOMPARE( formatter.formatDateTime( testDate, "%C" ),  QString( "-17" ) );
 
315
    QCOMPARE( formatter.formatDateTime( testDate, "%y" ),  QString( "-09" ) );
 
316
    QCOMPARE( formatter.formatDateTime( testDate, "%-Y" ), QString( "-1709" ) );
 
317
    QCOMPARE( formatter.formatDateTime( testDate, "%-C" ), QString( "-17" ) );
 
318
    QCOMPARE( formatter.formatDateTime( testDate, "%-y" ), QString( "-9" ) );
 
319
    QCOMPARE( formatter.formatDateTime( testDate, "%_Y" ), QString( "-1709" ) );
 
320
    QCOMPARE( formatter.formatDateTime( testDate, "%_C" ), QString( "-17" ) );
 
321
    QCOMPARE( formatter.formatDateTime( testDate, "%_y" ), QString( "-9" ) );
 
322
    QCOMPARE( formatter.formatDateTime( testDate, "%0Y" ), QString( "-1709" ) );
 
323
    QCOMPARE( formatter.formatDateTime( testDate, "%0C" ), QString( "-17" ) );
 
324
    QCOMPARE( formatter.formatDateTime( testDate, "%0y" ), QString( "-09" ) );
 
325
    QCOMPARE( formatter.formatDateTime( testDate, "%EC" ), QString( "BC" ) );
 
326
    QCOMPARE( formatter.formatDateTime( testDate, "%Ey" ), QString( "1709" ) );
 
327
    QCOMPARE( formatter.formatDateTime( testDate, "%EY" ), QString( "1709 BC" ) );
 
328
/*
 
329
    // Test POSIX format
 
330
    testDate.setDate( QDate( 2010, 1, 2 ) );
 
331
    QCOMPARE( formatter.formatDateTime( testDate, "%Y-%n-%d", KLocale::KdeFormat ),   QString( "2010-1-02" ) );
 
332
    QCOMPARE( formatter.formatDateTime( testDate, "%Y-%n-%d", KLocale::PosixFormat ), QString( "2010-\n-02" ) );
 
333
    QCOMPARE( formatter.formatDateTime( testDate, "%e", KLocale::KdeFormat ),   QString( "2" ) );
 
334
    QCOMPARE( formatter.formatDateTime( testDate, "%e", KLocale::PosixFormat ), QString( " 2" ) );
 
335
*/
 
336
}
 
337
 
 
338
void KDateTimeFormatterTest::testFormatUnicode()
 
339
{
 
340
    KGlobal::locale()->setLanguage( QStringList( "en_US" ) );
 
341
    KGlobal::locale()->setCalendar( "gregorian" );
 
342
    KGlobal::locale()->setDateFormatShort( "%y-%m-%d" );
 
343
 
 
344
    KDateTimeFormatter formatter;
 
345
 
 
346
    KDateTime testDateTime( QDate( 2005, 10, 20 ) );
 
347
    compareFormatUnicode( formatter, testDateTime, "yyyy" );
 
348
    compareFormatUnicode( formatter, testDateTime, "yy" );
 
349
    compareFormatUnicode( formatter, testDateTime, "MMMM" );
 
350
    compareFormatUnicode( formatter, testDateTime, "MMM" );
 
351
    compareFormatUnicode( formatter, testDateTime, "MM" );
 
352
    compareFormatUnicode( formatter, testDateTime, "M" );
 
353
    compareFormatUnicode( formatter, testDateTime, "dddd" );
 
354
    compareFormatUnicode( formatter, testDateTime, "ddd" );
 
355
    compareFormatUnicode( formatter, testDateTime, "dd" );
 
356
    compareFormatUnicode( formatter, testDateTime, "d" );
 
357
    compareFormatUnicode( formatter, testDateTime, "yyyy-MM-dd" );
 
358
 
 
359
    testDateTime.setDate( QDate( -2005, 10, 20 ) );
 
360
    compareFormatUnicode( formatter, testDateTime, "yyyy" );
 
361
    compareFormatUnicode( formatter, testDateTime, "yy" );
 
362
    compareFormatUnicode( formatter, testDateTime, "MMMM" );
 
363
    compareFormatUnicode( formatter, testDateTime, "MMM" );
 
364
    compareFormatUnicode( formatter, testDateTime, "MM" );
 
365
    compareFormatUnicode( formatter, testDateTime, "M" );
 
366
    compareFormatUnicode( formatter, testDateTime, "dddd" );
 
367
    compareFormatUnicode( formatter, testDateTime, "ddd" );
 
368
    compareFormatUnicode( formatter, testDateTime, "dd" );
 
369
    compareFormatUnicode( formatter, testDateTime, "d" );
 
370
    compareFormatUnicode( formatter, testDateTime, "yyyy-MM-dd" );
 
371
}
 
372
 
 
373
void KDateTimeFormatterTest::compareFormatUnicode( KDateTimeFormatter formatter, const KDateTime &testDateTime, const QString &testFormat )
 
374
{
 
375
    QCOMPARE( formatter.formatDateTime( testDateTime, testFormat, 0, KGlobal::locale()->calendar(), KGlobal::locale(), KGlobal::locale()->dateTimeDigitSet(), KLocale::UnicodeFormat ), testDateTime.dateTime().toString( testFormat ) );
 
376
}