#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <cmath>
#include "unicode/ctest.h" // for str_timeDelta
#include "unicode/curramt.h"
#include "unicode/ucnv.h"
#include "unicode/unistr.h"
#include "unicode/ures.h"
+#include "unicode/utf16.h"
#include "intltest.h"
return buffer;
}
+UnicodeString
+DoubleToUnicodeString(double num)
+{
+ char buffer[64]; // nos changed from 10 to 64
+ char danger = 'p'; // guard against overrunning the buffer (rtg)
+
+ sprintf(buffer, "%1.14e", num);
+ assert(danger == 'p');
+
+ return buffer;
+}
+
// [LIU] Just to get things working
UnicodeString
operator+(const UnicodeString& left,
return b ? UnicodeString("TRUE"):UnicodeString("FALSE");
}
+UnicodeString toString(const UnicodeSet& uniset, UErrorCode& status) {
+ UnicodeString result;
+ uniset.toPattern(result, status);
+ return result;
+}
+
// stephen - cleaned up 05/05/99
UnicodeString operator+(const UnicodeString& left, char num)
{ return left + (long)num; }
return rval;
}
-// call individual tests, to be overriden to call implementations
+// call individual tests, to be overridden to call implementations
void IntlTest::runIndexedTest( int32_t /*index*/, UBool /*exec*/, const char* & /*name*/, char* /*par*/ )
{
- // to be overriden by a method like:
+ // to be overridden by a method like:
/*
switch (index) {
case 0: name = "First Test"; if (exec) FirstTest( par ); break;
default: name = ""; break;
}
*/
- this->errln("*** runIndexedTest needs to be overriden! ***");
+ this->errln("*** runIndexedTest needs to be overridden! ***");
}
{
// Synchronize this function.
// All error messages generated by tests funnel through here.
- // Multithreaded tests can concurrently generate errors, requiring syncronization
+ // Multithreaded tests can concurrently generate errors, requiring synchronization
// to keep each message together.
Mutex lock(&messageMutex);
return condition;
}
-UBool IntlTest::assertFalse(const char* message, UBool condition, UBool quiet) {
+UBool IntlTest::assertFalse(const char* message, UBool condition, UBool quiet, UBool possibleDataError) {
if (condition) {
- errln("FAIL: assertFalse() failed: %s", message);
+ if (possibleDataError) {
+ dataerrln("FAIL: assertTrue() failed: %s", message);
+ } else {
+ errln("FAIL: assertTrue() failed: %s", message);
+ }
} else if (!quiet) {
logln("Ok: %s", message);
}
UBool IntlTest::assertEquals(const char* message,
double expected,
double actual) {
- if (expected != actual) {
+ bool bothNaN = std::isnan(expected) && std::isnan(actual);
+ if (expected != actual && !bothNaN) {
errln((UnicodeString)"FAIL: " + message + "; got " +
actual +
"; expected " + expected);
return TRUE;
}
+
+UBool IntlTest::assertEquals(const char* message,
+ UErrorCode expected,
+ UErrorCode actual) {
+ if (expected != actual) {
+ errln((UnicodeString)"FAIL: " + message + "; got " +
+ u_errorName(actual) +
+ "; expected " + u_errorName(expected));
+ return FALSE;
+ }
+#ifdef VERBOSE_ASSERTIONS
+ else {
+ logln((UnicodeString)"Ok: " + message + "; got " + u_errorName(actual));
+ }
+#endif
+ return TRUE;
+}
+
+UBool IntlTest::assertEquals(const char* message,
+ const UnicodeSet& expected,
+ const UnicodeSet& actual) {
+ IcuTestErrorCode status(*this, "assertEqualsUniSet");
+ if (expected != actual) {
+ errln((UnicodeString)"FAIL: " + message + "; got " +
+ toString(actual, status) +
+ "; expected " + toString(expected, status));
+ return FALSE;
+ }
+#ifdef VERBOSE_ASSERTIONS
+ else {
+ logln((UnicodeString)"Ok: " + message + "; got " + toString(actual, status));
+ }
+#endif
+ return TRUE;
+}
+
+
#if !UCONFIG_NO_FORMATTING
UBool IntlTest::assertEquals(const char* message,
const Formattable& expected,
return ASSERT_BUF;
}
-UBool IntlTest::assertTrue(const UnicodeString& message, UBool condition, UBool quiet) {
- return assertTrue(extractToAssertBuf(message), condition, quiet);
+UBool IntlTest::assertTrue(const UnicodeString& message, UBool condition, UBool quiet, UBool possibleDataError) {
+ return assertTrue(extractToAssertBuf(message), condition, quiet, possibleDataError);
}
-UBool IntlTest::assertFalse(const UnicodeString& message, UBool condition, UBool quiet) {
- return assertFalse(extractToAssertBuf(message), condition, quiet);
+UBool IntlTest::assertFalse(const UnicodeString& message, UBool condition, UBool quiet, UBool possibleDataError) {
+ return assertFalse(extractToAssertBuf(message), condition, quiet, possibleDataError);
}
UBool IntlTest::assertSuccess(const UnicodeString& message, UErrorCode ec) {
int64_t actual) {
return assertEquals(extractToAssertBuf(message), expected, actual);
}
+UBool IntlTest::assertEquals(const UnicodeString& message,
+ double expected,
+ double actual) {
+ return assertEquals(extractToAssertBuf(message), expected, actual);
+}
+UBool IntlTest::assertEquals(const UnicodeString& message,
+ UErrorCode expected,
+ UErrorCode actual) {
+ return assertEquals(extractToAssertBuf(message), expected, actual);
+}
+UBool IntlTest::assertEquals(const UnicodeString& message,
+ const UnicodeSet& expected,
+ const UnicodeSet& actual) {
+ return assertEquals(extractToAssertBuf(message), expected, actual);
+}
#if !UCONFIG_NO_FORMATTING
UBool IntlTest::assertEquals(const UnicodeString& message,