18
18
#include < stdio.h>
19
19
#include < stdlib.h>
20
20
#include < string.h>
21
+ #include < cinttypes>
21
22
#include < cmath>
22
23
#include < math.h>
23
24
#include < string_view>
@@ -73,25 +74,25 @@ UCharToUnicodeString(char16_t c) { return {c}; }
73
74
// [rtg] Just to get things working
74
75
UnicodeString
75
76
operator +(const UnicodeString& left,
76
- long num)
77
+ int64_t num)
77
78
{
78
79
char buffer[64 ]; // nos changed from 10 to 64
79
80
char danger = ' p' ; // guard against overrunning the buffer (rtg)
80
81
81
- snprintf (buffer, sizeof (buffer), " %ld " , num);
82
+ snprintf (buffer, sizeof (buffer), " %" PRId64 , num);
82
83
assert (danger == ' p' );
83
84
84
85
return left + buffer;
85
86
}
86
87
87
88
UnicodeString
88
89
operator +(const UnicodeString& left,
89
- unsigned long num)
90
+ uint64_t num)
90
91
{
91
92
char buffer[64 ]; // nos changed from 10 to 64
92
93
char danger = ' p' ; // guard against overrunning the buffer (rtg)
93
94
94
- snprintf (buffer, sizeof (buffer), " %lu " , num);
95
+ snprintf (buffer, sizeof (buffer), " %" PRIu64 , num);
95
96
assert (danger == ' p' );
96
97
97
98
return left + buffer;
@@ -103,11 +104,7 @@ Int64ToUnicodeString(int64_t num)
103
104
char buffer[64 ]; // nos changed from 10 to 64
104
105
char danger = ' p' ; // guard against overrunning the buffer (rtg)
105
106
106
- #if defined(_MSC_VER)
107
- snprintf (buffer, sizeof (buffer), " %I64d" , num);
108
- #else
109
- snprintf (buffer, sizeof (buffer), " %lld" , static_cast <long long >(num));
110
- #endif
107
+ snprintf (buffer, sizeof (buffer), " %" PRId64, num);
111
108
assert (danger == ' p' );
112
109
113
110
return buffer;
@@ -143,14 +140,6 @@ operator+(const UnicodeString& left,
143
140
return left + buffer;
144
141
}
145
142
146
- #if 0
147
- UnicodeString
148
- operator+(const UnicodeString& left,
149
- int64_t num) {
150
- return left + Int64ToUnicodeString(num);
151
- }
152
- #endif
153
-
154
143
#if !UCONFIG_NO_FORMATTING
155
144
156
145
/* *
@@ -232,13 +221,18 @@ UnicodeString toString(const Formattable& f) {
232
221
233
222
// useful when operator+ won't cooperate
234
223
UnicodeString toString (int32_t n) {
235
- return UnicodeString () + static_cast <long >(n);
224
+ return UnicodeString () + static_cast <int64_t >(n);
236
225
}
237
226
238
227
239
228
240
229
UnicodeString toString (UBool b) {
241
- return b ? UnicodeString (" true" ):UnicodeString (" false" );
230
+ return b ? b != 1 ? UnicodeString (" static_cast<UBool>(" ) + b + " )" : UnicodeString (" true" )
231
+ : UnicodeString (" false" );
232
+ }
233
+
234
+ UnicodeString toString (bool b) {
235
+ return b ? UnicodeString (" true" ) : UnicodeString (" false" );
242
236
}
243
237
244
238
UnicodeString toString (const UnicodeSet& uniset, UErrorCode& status) {
@@ -249,17 +243,17 @@ UnicodeString toString(const UnicodeSet& uniset, UErrorCode& status) {
249
243
250
244
// stephen - cleaned up 05/05/99
251
245
UnicodeString operator +(const UnicodeString& left, char num)
252
- { return left + static_cast <long >(num); }
246
+ { return left + static_cast <int64_t >(num); }
253
247
UnicodeString operator +(const UnicodeString& left, short num)
254
- { return left + static_cast <long >(num); }
248
+ { return left + static_cast <int64_t >(num); }
255
249
UnicodeString operator +(const UnicodeString& left, int num)
256
- { return left + static_cast <long >(num); }
250
+ { return left + static_cast <int64_t >(num); }
257
251
UnicodeString operator +(const UnicodeString& left, unsigned char num)
258
- { return left + static_cast <unsigned long >(num); }
252
+ { return left + static_cast <uint64_t >(num); }
259
253
UnicodeString operator +(const UnicodeString& left, unsigned short num)
260
- { return left + static_cast <unsigned long >(num); }
254
+ { return left + static_cast <uint64_t >(num); }
261
255
UnicodeString operator +(const UnicodeString& left, unsigned int num)
262
- { return left + static_cast <unsigned long >(num); }
256
+ { return left + static_cast <uint64_t >(num); }
263
257
UnicodeString operator +(const UnicodeString& left, float num)
264
258
{ return left + static_cast <double >(num); }
265
259
@@ -2091,12 +2085,22 @@ UBool IntlTest::assertEquals(const char* message, std::u16string_view expected,
2091
2085
possibleDataError);
2092
2086
}
2093
2087
2094
- UBool IntlTest::assertEquals (const char * message,
2095
- int32_t expected,
2096
- int32_t actual) {
2088
+ bool IntlTest::assertSigned64Equals (const char *message, int64_t expected, int64_t actual) {
2097
2089
if (expected != actual) {
2098
- errln (UnicodeString (" FAIL: " ) + message + " ; got " +
2099
- actual + " =0x" + toHex (actual) +
2090
+ errln (UnicodeString (" FAIL: " ) + message + " ; got " + actual + " ; expected " + expected);
2091
+ return false ;
2092
+ }
2093
+ #ifdef VERBOSE_ASSERTIONS
2094
+ else {
2095
+ logln (UnicodeString (" Ok: " ) + message + " ; got " + actual);
2096
+ }
2097
+ #endif
2098
+ return true ;
2099
+ }
2100
+
2101
+ bool IntlTest::assertSigned32Equals (const char *message, int32_t expected, int32_t actual) {
2102
+ if (expected != actual) {
2103
+ errln (UnicodeString (" FAIL: " ) + message + " ; got " + actual + " =0x" + toHex (actual) +
2100
2104
" ; expected " + expected + " =0x" + toHex (expected));
2101
2105
return false ;
2102
2106
}
@@ -2108,18 +2112,18 @@ UBool IntlTest::assertEquals(const char* message,
2108
2112
return true ;
2109
2113
}
2110
2114
2111
- UBool IntlTest::assertEquals (const char * message,
2112
- int64_t expected,
2113
- int64_t actual) {
2115
+ bool IntlTest::assertCodePointEquals (const char *message, char32_t expected, char32_t actual) {
2114
2116
if (expected != actual) {
2115
- errln (UnicodeString (" FAIL: " ) + message + " ; got int64 " +
2116
- Int64ToUnicodeString (actual) +
2117
- " ; expected " + Int64ToUnicodeString (expected) );
2117
+ errln (UnicodeString (" FAIL: " ) + message + " ; got U+" + toHex (actual, actual <= 0xFFFF ? 4 : -1 ) +
2118
+ " " + UnicodeString (static_cast <UChar32>(actual)) + " ; expected U+" +
2119
+ toHex (expected, expected <= 0xFFFF ? 4 : -1 ) + +" " +
2120
+ UnicodeString (static_cast <UChar32>(expected)));
2118
2121
return false ;
2119
2122
}
2120
2123
#ifdef VERBOSE_ASSERTIONS
2121
2124
else {
2122
- logln (UnicodeString (" Ok: " ) + message + " ; got int64 " + Int64ToUnicodeString (actual));
2125
+ logln (UnicodeString (" Ok: " ) + message + " ; got U+" + toHex (actual, actual <= 0xFFFF ? 4 : -1 ) +
2126
+ " " + UnicodeString (static_cast <UChar32>(actual)));
2123
2127
}
2124
2128
#endif
2125
2129
return true ;
@@ -2143,18 +2147,29 @@ UBool IntlTest::assertEquals(const char* message,
2143
2147
return true ;
2144
2148
}
2145
2149
2146
- UBool IntlTest::assertEquals (const char * message,
2147
- UBool expected,
2148
- UBool actual) {
2150
+ bool IntlTest::assertBooleanEquals (const char *message, int8_t expected, int8_t actual) {
2149
2151
if (expected != actual) {
2150
- errln (UnicodeString (" FAIL: " ) + message + " ; got " +
2151
- toString (actual) +
2152
- " ; expected " + toString (expected));
2152
+ errln (UnicodeString (" FAIL: " ) + message + " ; got " + toString (actual) + " ; expected " +
2153
+ toString (expected));
2153
2154
return false ;
2154
2155
}
2155
2156
#ifdef VERBOSE_ASSERTIONS
2156
2157
else {
2157
- logln (UnicodeString (" Ok: " ) + message + " ; got " + toString (actual));
2158
+ logln (UnicodeString (" Ok: " ) + message + " ; got " + toString (actual));
2159
+ }
2160
+ #endif
2161
+ return true ;
2162
+ }
2163
+
2164
+ bool IntlTest::assertBooleanNotEquals (const char *message, int8_t expected, int8_t actual) {
2165
+ if (expected == actual) {
2166
+ errln (UnicodeString (" FAIL: " ) + message + " ; got " + toString (actual) + " ; expected != " +
2167
+ toString (expected));
2168
+ return false ;
2169
+ }
2170
+ #ifdef VERBOSE_ASSERTIONS
2171
+ else {
2172
+ logln (UnicodeString (" Ok: " ) + message + " ; got " + toString (actual));
2158
2173
}
2159
2174
#endif
2160
2175
return true ;
@@ -2259,9 +2274,22 @@ UBool IntlTest::assertEquals(const char* message,
2259
2274
return true ;
2260
2275
}
2261
2276
2262
- UBool IntlTest::assertNotEquals (const char * message,
2263
- int32_t expectedNot,
2264
- int32_t actual) {
2277
+ bool IntlTest::assertSigned64NotEquals (const char *message, int64_t expected, int64_t actual) {
2278
+ if (expected == actual) {
2279
+ errln (UnicodeString (" FAIL: " ) + message + " ; got " + actual + " ; expected != " + expected);
2280
+ return false ;
2281
+ }
2282
+ #ifdef VERBOSE_ASSERTIONS
2283
+ else {
2284
+ logln (UnicodeString (" Ok: " ) + message + " ; got " + actual);
2285
+ }
2286
+ #endif
2287
+ return true ;
2288
+ }
2289
+
2290
+ bool IntlTest::assertSigned32NotEquals (const char * message,
2291
+ int32_t expectedNot,
2292
+ int32_t actual) {
2265
2293
if (expectedNot == actual) {
2266
2294
errln (UnicodeString (" FAIL: " ) + message + " ; got " + actual + " =0x" + toHex (actual) +
2267
2295
" ; expected != " + expectedNot);
@@ -2276,6 +2304,23 @@ UBool IntlTest::assertNotEquals(const char* message,
2276
2304
return true ;
2277
2305
}
2278
2306
2307
+ bool IntlTest::assertCodePointNotEquals (const char *message, char32_t expected, char32_t actual) {
2308
+ if (expected == actual) {
2309
+ errln (UnicodeString (" FAIL: " ) + message + " ; got U+" + toHex (actual, actual <= 0xFFFF ? 4 : -1 ) +
2310
+ " " + UnicodeString (static_cast <UChar32>(actual)) + " ; expected != U+" +
2311
+ toHex (expected, expected <= 0xFFFF ? 4 : -1 ) + +" " +
2312
+ UnicodeString (static_cast <UChar32>(expected)));
2313
+ return false ;
2314
+ }
2315
+ #ifdef VERBOSE_ASSERTIONS
2316
+ else {
2317
+ logln (UnicodeString (" Ok: " ) + message + " ; got U+" + toHex (actual, actual <= 0xFFFF ? 4 : -1 ) +
2318
+ " " + UnicodeString (static_cast <UChar32>(actual)));
2319
+ }
2320
+ #endif
2321
+ return true ;
2322
+ }
2323
+
2279
2324
UBool IntlTest::assertEqualsNear (const char * message,
2280
2325
double expected,
2281
2326
double actual,
@@ -2308,7 +2353,7 @@ UBool IntlTest::assertEqualsNear(const char* message,
2308
2353
2309
2354
static char ASSERT_BUF[256 ];
2310
2355
2311
- static const char * extractToAssertBuf (std::u16string_view message) {
2356
+ const char * IntlTest:: extractToAssertBuf (std::u16string_view message) {
2312
2357
UnicodeString buf;
2313
2358
escape (message, buf);
2314
2359
buf.extract (0 , 0x7FFFFFFF , ASSERT_BUF, sizeof (ASSERT_BUF) - 1 , nullptr );
@@ -2340,21 +2385,7 @@ UBool IntlTest::assertEquals(std::u16string_view message,
2340
2385
const char * actual) {
2341
2386
return assertEquals (extractToAssertBuf (message), expected, actual);
2342
2387
}
2343
- UBool IntlTest::assertEquals (std::u16string_view message,
2344
- UBool expected,
2345
- UBool actual) {
2346
- return assertEquals (extractToAssertBuf (message), expected, actual);
2347
- }
2348
- UBool IntlTest::assertEquals (std::u16string_view message,
2349
- int32_t expected,
2350
- int32_t actual) {
2351
- return assertEquals (extractToAssertBuf (message), expected, actual);
2352
- }
2353
- UBool IntlTest::assertEquals (std::u16string_view message,
2354
- int64_t expected,
2355
- int64_t actual) {
2356
- return assertEquals (extractToAssertBuf (message), expected, actual);
2357
- }
2388
+
2358
2389
UBool IntlTest::assertEquals (std::u16string_view message,
2359
2390
double expected,
2360
2391
double actual) {
@@ -2375,11 +2406,6 @@ UBool IntlTest::assertEquals(std::u16string_view message,
2375
2406
const std::vector<std::string>& actual) {
2376
2407
return assertEquals (extractToAssertBuf (message), expected, actual);
2377
2408
}
2378
- UBool IntlTest::assertNotEquals (std::u16string_view message,
2379
- int32_t expectedNot,
2380
- int32_t actual) {
2381
- return assertNotEquals (extractToAssertBuf (message), expectedNot, actual);
2382
- }
2383
2409
UBool IntlTest::assertEqualsNear (std::u16string_view message,
2384
2410
double expected,
2385
2411
double actual,
0 commit comments