mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-08 06:53:45 +00:00
ICU-3090 add JUnit-like assert methods and ctou()
X-SVN-Rev: 14488
This commit is contained in:
parent
05643c4b10
commit
6d5aaf8514
2 changed files with 65 additions and 0 deletions
|
@ -1275,6 +1275,10 @@ UnicodeString CharsToUnicodeString(const char* chars)
|
|||
return str.unescape();
|
||||
}
|
||||
|
||||
UnicodeString ctou(const char* chars) {
|
||||
return CharsToUnicodeString(chars);
|
||||
}
|
||||
|
||||
#define RAND_M (714025)
|
||||
#define RAND_IA (1366)
|
||||
#define RAND_IC (150889)
|
||||
|
@ -1319,6 +1323,57 @@ float IntlTest::random() {
|
|||
return random(&RAND_SEED);
|
||||
}
|
||||
|
||||
#define VERBOSE_ASSERTIONS
|
||||
|
||||
UBool IntlTest::assertTrue(const char* message, UBool condition) {
|
||||
if (!condition) {
|
||||
errln("FAIL: assertTrue() failed: %s", message);
|
||||
}
|
||||
#ifdef VERBOSE_ASSERTIONS
|
||||
else {
|
||||
logln("Ok: %s", message);
|
||||
}
|
||||
#endif
|
||||
return condition;
|
||||
}
|
||||
|
||||
UBool IntlTest::assertFalse(const char* message, UBool condition) {
|
||||
if (condition) {
|
||||
errln("FAIL: assertFalse() failed: %s", message);
|
||||
}
|
||||
#ifdef VERBOSE_ASSERTIONS
|
||||
else {
|
||||
logln("Ok: %s", message);
|
||||
}
|
||||
#endif
|
||||
return !condition;
|
||||
}
|
||||
|
||||
UBool IntlTest::assertSuccess(const char* message, UErrorCode ec) {
|
||||
if (U_FAILURE(ec)) {
|
||||
errln("FAIL: %s (%s)", message, u_errorName(ec));
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
UBool IntlTest::assertEquals(const char* message,
|
||||
const UnicodeString& expected,
|
||||
const UnicodeString& actual) {
|
||||
if (expected != actual) {
|
||||
errln((UnicodeString)"FAIL: " + message + "; got " +
|
||||
prettify(actual) +
|
||||
"; expected " + prettify(expected));
|
||||
return FALSE;
|
||||
}
|
||||
#ifdef VERBOSE_ASSERTIONS
|
||||
else {
|
||||
logln((UnicodeString)"Ok: " + message + "; got " + prettify(actual));
|
||||
}
|
||||
#endif
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Hey, Emacs, please set the following:
|
||||
*
|
||||
|
|
|
@ -130,6 +130,13 @@ public:
|
|||
static float random();
|
||||
|
||||
protected:
|
||||
/* JUnit-like assertions. Each returns TRUE if it succeeds. */
|
||||
UBool assertTrue(const char* message, UBool condition);
|
||||
UBool assertFalse(const char* message, UBool condition);
|
||||
UBool assertSuccess(const char* message, UErrorCode ec);
|
||||
UBool assertEquals(const char* message, const UnicodeString& expected,
|
||||
const UnicodeString& actual);
|
||||
|
||||
virtual void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par = NULL ); // overide !
|
||||
|
||||
virtual UBool runTestLoop( char* testname, char* par );
|
||||
|
@ -202,4 +209,7 @@ void it_errln( UnicodeString message );
|
|||
*/
|
||||
extern UnicodeString CharsToUnicodeString(const char* chars);
|
||||
|
||||
/* alias for CharsToUnicodeString */
|
||||
extern UnicodeString ctou(const char* chars);
|
||||
|
||||
#endif // _INTLTEST
|
||||
|
|
Loading…
Add table
Reference in a new issue