1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /********************************************************************
4 * COPYRIGHT:
5 * Copyright (c) 1997-2015, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 ********************************************************************/
8 /********************************************************************************
9 *
10 * File CINTLTST.C
11 *
12 * Modification History:
13 * Name Description
14 * Madhu Katragadda Creation
15 *********************************************************************************
16 */
17
18 /*The main root for C API tests*/
19
20 #include <stdbool.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include "unicode/utypes.h"
25 #include "unicode/putil.h"
26 #include "cstring.h"
27 #include "cintltst.h"
28 #include "uassert.h"
29 #include "cmemory.h"
30 #include "unicode/uchar.h"
31 #include "unicode/ustring.h"
32 #include "unicode/ucnv.h"
33 #include "unicode/ures.h"
34 #include "unicode/uclean.h"
35 #include "unicode/ucal.h"
36 #include "uoptions.h"
37 #include "putilimp.h" /* for uprv_getRawUTCtime() */
38 #ifdef URES_DEBUG
39 #include "uresimp.h" /* for ures_dumpCacheContents() */
40 #endif
41
42 #ifdef XP_MAC_CONSOLE
43 # include <console.h>
44 #endif
45
46 #define CTST_MAX_ALLOC 8192
47 /* Array used as a queue */
48 static void * ctst_allocated_stuff[CTST_MAX_ALLOC] = {0};
49 static int ctst_allocated = 0;
50 static UBool ctst_free = false;
51 static int ctst_allocated_total = 0;
52
53 #define CTST_LEAK_CHECK 1
54
55 #ifdef CTST_LEAK_CHECK
56 static void ctst_freeAll(void);
57 #endif
58
59 /*
60 * Forward Declarations
61 */
62 void ctest_setICU_DATA(void);
63
64
65
66 #if UCONFIG_NO_LEGACY_CONVERSION
67 # define TRY_CNV_1 "iso-8859-1"
68 # define TRY_CNV_2 "ibm-1208"
69 #else
70 # define TRY_CNV_1 "iso-8859-7"
71 # define TRY_CNV_2 "sjis"
72 #endif
73
74 static int gOrigArgc;
75 static const char* const * gOrigArgv;
76
77 #ifdef UNISTR_COUNT_FINAL_STRING_LENGTHS
78 U_CAPI void unistr_printLengths();
79 #endif
80
main(int argc,const char * const argv[])81 int main(int argc, const char* const argv[])
82 {
83 int nerrors = 0;
84 UBool defaultDataFound;
85 TestNode *root;
86 const char *warnOrErr = "Failure";
87 UDate startTime, endTime;
88 int32_t diffTime;
89
90 /* initial check for the default converter */
91 UErrorCode errorCode = U_ZERO_ERROR;
92 UResourceBundle *rb;
93 UConverter *cnv;
94
95 U_MAIN_INIT_ARGS(argc, argv);
96
97 startTime = uprv_getRawUTCtime();
98
99 gOrigArgc = argc;
100 gOrigArgv = argv;
101 if (!initArgs(argc, argv, NULL, NULL)) {
102 /* Error already displayed. */
103 return -1;
104 }
105
106 /* Check whether ICU will initialize without forcing the build data directory into
107 * the ICU_DATA path. Success here means either the data dll contains data, or that
108 * this test program was run with ICU_DATA set externally. Failure of this check
109 * is normal when ICU data is not packaged into a shared library.
110 *
111 * Whether or not this test succeeds, we want to cleanup and reinitialize
112 * with a data path so that data loading from individual files can be tested.
113 */
114 defaultDataFound = true;
115 u_init(&errorCode);
116 if (U_FAILURE(errorCode)) {
117 fprintf(stderr,
118 "#### Note: ICU Init without build-specific setDataDirectory() failed. %s\n", u_errorName(errorCode));
119 defaultDataFound = false;
120 }
121 u_cleanup();
122 #ifdef URES_DEBUG
123 fprintf(stderr, "After initial u_cleanup: RB cache %s empty.\n", ures_dumpCacheContents()?"WAS NOT":"was");
124 #endif
125
126 while (getTestOption(REPEAT_TESTS_OPTION) > 0) { /* Loop runs once per complete execution of the tests
127 * used for -r (repeat) test option. */
128 if (!initArgs(argc, argv, NULL, NULL)) {
129 /* Error already displayed. */
130 return -1;
131 }
132 errorCode = U_ZERO_ERROR;
133
134 /* Initialize ICU */
135 if (!defaultDataFound) {
136 ctest_setICU_DATA(); /* u_setDataDirectory() must happen Before u_init() */
137 }
138 u_init(&errorCode);
139 if (U_FAILURE(errorCode)) {
140 fprintf(stderr,
141 "#### ERROR! %s: u_init() failed with status = \"%s\".\n"
142 "*** Check the ICU_DATA environment variable and \n"
143 "*** check that the data files are present.\n", argv[0], u_errorName(errorCode));
144 if(!getTestOption(WARN_ON_MISSING_DATA_OPTION)) {
145 fprintf(stderr, "*** Exiting. Use the '-w' option if data files were\n*** purposely removed, to continue test anyway.\n");
146 u_cleanup();
147 return 1;
148 }
149 }
150
151
152
153 /* try more data */
154 cnv = ucnv_open(TRY_CNV_2, &errorCode);
155 if(cnv != 0) {
156 /* ok */
157 ucnv_close(cnv);
158 } else {
159 fprintf(stderr,
160 "*** %s! The converter for " TRY_CNV_2 " cannot be opened.\n"
161 "*** Check the ICU_DATA environment variable and \n"
162 "*** check that the data files are present.\n", warnOrErr);
163 if(!getTestOption(WARN_ON_MISSING_DATA_OPTION)) {
164 fprintf(stderr, "*** Exiting. Use the '-w' option if data files were\n*** purposely removed, to continue test anyway.\n");
165 u_cleanup();
166 return 1;
167 }
168 }
169
170 rb = ures_open(NULL, "en", &errorCode);
171 if(U_SUCCESS(errorCode)) {
172 /* ok */
173 ures_close(rb);
174 } else {
175 fprintf(stderr,
176 "*** %s! The \"en\" locale resource bundle cannot be opened.\n"
177 "*** Check the ICU_DATA environment variable and \n"
178 "*** check that the data files are present.\n", warnOrErr);
179 if(!getTestOption(WARN_ON_MISSING_DATA_OPTION)) {
180 fprintf(stderr, "*** Exiting. Use the '-w' option if data files were\n*** purposely removed, to continue test anyway.\n");
181 u_cleanup();
182 return 1;
183 }
184 }
185
186 errorCode = U_ZERO_ERROR;
187 rb = ures_open(NULL, NULL, &errorCode);
188 if(U_SUCCESS(errorCode)) {
189 /* ok */
190 if (errorCode == U_USING_DEFAULT_WARNING || errorCode == U_USING_FALLBACK_WARNING) {
191 fprintf(stderr,
192 "#### Note: The default locale %s is not available\n", uloc_getDefault());
193 }
194 ures_close(rb);
195 } else {
196 fprintf(stderr,
197 "*** %s! Can not open a resource bundle for the default locale %s\n", warnOrErr, uloc_getDefault());
198 if(!getTestOption(WARN_ON_MISSING_DATA_OPTION)) {
199 fprintf(stderr, "*** Exiting. Use the '-w' option if data files were\n"
200 "*** purposely removed, to continue test anyway.\n");
201 u_cleanup();
202 return 1;
203 }
204 }
205 fprintf(stdout, "Default locale for this run is %s\n", uloc_getDefault());
206
207 /* Build a tree of all tests.
208 * Subsequently will be used to find / iterate the tests to run */
209 root = NULL;
210 addAllTests(&root);
211
212 /* Tests actually run HERE. TODO: separate command line option parsing & setting from test execution!! */
213 nerrors = runTestRequest(root, argc, argv);
214
215 setTestOption(REPEAT_TESTS_OPTION, DECREMENT_OPTION_VALUE);
216 if (getTestOption(REPEAT_TESTS_OPTION) > 0) {
217 printf("Repeating tests %d more time(s)\n", getTestOption(REPEAT_TESTS_OPTION));
218 }
219 cleanUpTestTree(root);
220
221 #ifdef CTST_LEAK_CHECK
222 ctst_freeAll();
223 /* To check for leaks */
224 u_cleanup(); /* nuke the hashtable.. so that any still-open cnvs are leaked */
225
226 if(getTestOption(VERBOSITY_OPTION) && ctst_allocated_total>0) {
227 fprintf(stderr,"ctst_freeAll(): cleaned up after %d allocations (queue of %d)\n", ctst_allocated_total, CTST_MAX_ALLOC);
228 }
229 #ifdef URES_DEBUG
230 if(ures_dumpCacheContents()) {
231 fprintf(stderr, "Error: After final u_cleanup, RB cache was not empty.\n");
232 nerrors++;
233 } else {
234 fprintf(stderr,"OK: After final u_cleanup, RB cache was empty.\n");
235 }
236 #endif
237 #endif
238
239 } /* End of loop that repeats the entire test, if requested. (Normally doesn't loop) */
240
241 #ifdef UNISTR_COUNT_FINAL_STRING_LENGTHS
242 unistr_printLengths();
243 #endif
244
245 endTime = uprv_getRawUTCtime();
246 diffTime = (int32_t)(endTime - startTime);
247 printf("Elapsed Time: %02d:%02d:%02d.%03d\n",
248 (int)((diffTime%U_MILLIS_PER_DAY)/U_MILLIS_PER_HOUR),
249 (int)((diffTime%U_MILLIS_PER_HOUR)/U_MILLIS_PER_MINUTE),
250 (int)((diffTime%U_MILLIS_PER_MINUTE)/U_MILLIS_PER_SECOND),
251 (int)(diffTime%U_MILLIS_PER_SECOND));
252
253 #ifdef ZERO_EXIT_CODE_FOR_FAILURES
254 return 0;
255 #else
256 return nerrors ? 1 : 0;
257 #endif
258 }
259
260 /*
261 static void ctest_appendToDataDirectory(const char *toAppend)
262 {
263 const char *oldPath ="";
264 char newBuf [1024];
265 char *newPath = newBuf;
266 int32_t oldLen;
267 int32_t newLen;
268
269 if((toAppend == NULL) || (*toAppend == 0)) {
270 return;
271 }
272
273 oldPath = u_getDataDirectory();
274 if( (oldPath==NULL) || (*oldPath == 0)) {
275 u_setDataDirectory(toAppend);
276 } else {
277 oldLen = strlen(oldPath);
278 newLen = strlen(toAppend)+1+oldLen;
279
280 if(newLen > 1022)
281 {
282 newPath = (char *)ctst_malloc(newLen);
283 }
284
285 strcpy(newPath, oldPath);
286 strcpy(newPath+oldLen, U_PATH_SEP_STRING);
287 strcpy(newPath+oldLen+1, toAppend);
288
289 u_setDataDirectory(newPath);
290
291 if(newPath != newBuf)
292 {
293 free(newPath);
294 }
295 }
296 }
297 */
298
299 /* ctest_setICU_DATA - if the ICU_DATA environment variable is not already
300 * set, try to deduce the directory in which ICU was built,
301 * and set ICU_DATA to "icu/source/data" in that location.
302 * The intent is to allow the tests to have a good chance
303 * of running without requiring that the user manually set
304 * ICU_DATA. Common data isn't a problem, since it is
305 * picked up via a static (build time) reference, but the
306 * tests dynamically load some data.
307 */
ctest_setICU_DATA()308 void ctest_setICU_DATA() {
309 // Android-changed: Do not u_setDataDirectory because libicuuc.so initializes itself.
310 #if !defined(ANDROID_USE_ICU_REG)
311 u_setDataDirectory(ctest_dataOutDir());
312 #endif
313 }
314
315 /* These tests do cleanup and reinitialize ICU in the course of their operation.
316 * The ICU data directory must be preserved across these operations.
317 * Here is a helper function to assist with that.
318 */
safeGetICUDataDirectory(void)319 static char *safeGetICUDataDirectory(void) {
320 const char *dataDir = u_getDataDirectory(); /* Returned string vanashes with u_cleanup */
321 char *retStr = NULL;
322 if (dataDir != NULL) {
323 retStr = (char *)malloc(strlen(dataDir)+1);
324 strcpy(retStr, dataDir);
325 }
326 return retStr;
327 }
328
ctest_resetICU(void)329 UBool ctest_resetICU(void) {
330 UErrorCode status = U_ZERO_ERROR;
331 char *dataDir = safeGetICUDataDirectory();
332
333 u_cleanup();
334 if (!initArgs(gOrigArgc, gOrigArgv, NULL, NULL)) {
335 /* Error already displayed. */
336 return false;
337 }
338 ctest_setICU_DATA();
339 free(dataDir);
340 u_init(&status);
341 if (U_FAILURE(status)) {
342 log_err_status(status, "u_init failed with %s\n", u_errorName(status));
343 return false;
344 }
345 return true;
346 }
347
CharsToUChars(const char * str)348 UChar* CharsToUChars(const char* str) {
349 /* Might be faster to just use uprv_strlen() as the preflight len - liu */
350 int32_t len = u_unescape(str, 0, 0); /* preflight */
351 /* Do NOT use malloc() - we are supposed to be acting like user code! */
352 UChar *buf = (UChar*) malloc(sizeof(UChar) * (len + 1));
353 u_unescape(str, buf, len + 1);
354 return buf;
355 }
356
austrdup(const UChar * unichars)357 char *austrdup(const UChar* unichars)
358 {
359 int length;
360 char *newString;
361
362 length = u_strlen ( unichars );
363 /*newString = (char*)malloc ( sizeof( char ) * 4 * ( length + 1 ) );*/ /* this leaks for now */
364 newString = (char*)ctst_malloc ( sizeof( char ) * 4 * ( length + 1 ) ); /* this shouldn't */
365
366 if ( newString == NULL )
367 return NULL;
368
369 u_austrcpy ( newString, unichars );
370
371 return newString;
372 }
373
aescstrdup(const UChar * unichars,int32_t length)374 char *aescstrdup(const UChar* unichars,int32_t length){
375 char *newString,*targetLimit,*target;
376 UConverterFromUCallback cb;
377 const void *p;
378 UErrorCode errorCode = U_ZERO_ERROR;
379 #if U_CHARSET_FAMILY==U_EBCDIC_FAMILY
380 # if U_PLATFORM == U_PF_OS390
381 static const char convName[] = "ibm-1047";
382 # else
383 static const char convName[] = "ibm-37";
384 # endif
385 #else
386 static const char convName[] = "US-ASCII";
387 #endif
388 UConverter* conv = ucnv_open(convName, &errorCode);
389 if(length==-1){
390 length = u_strlen( unichars);
391 }
392 newString = (char*)ctst_malloc ( sizeof(char) * 8 * (length +1));
393 target = newString;
394 targetLimit = newString+sizeof(char) * 8 * (length +1);
395 ucnv_setFromUCallBack(conv, UCNV_FROM_U_CALLBACK_ESCAPE, UCNV_ESCAPE_C, &cb, &p, &errorCode);
396 ucnv_fromUnicode(conv,&target,targetLimit, &unichars, (UChar*)(unichars+length),NULL,true,&errorCode);
397 ucnv_close(conv);
398 *target = '\0';
399 return newString;
400 }
401
loadTestData(UErrorCode * err)402 const char* loadTestData(UErrorCode* err){
403 return ctest_loadTestData(err);
404 }
405
406 /**
407 * Returns the path to icu/source/test/testdata/
408 * Note: this function is parallel with C++ getSourceTestData in intltest.cpp
409 */
loadSourceTestData(UErrorCode * err)410 const char *loadSourceTestData(UErrorCode* err) {
411 (void)err;
412 const char *srcDataDir = NULL;
413 #ifdef U_TOPSRCDIR
414 srcDataDir = U_TOPSRCDIR U_FILE_SEP_STRING"test" U_FILE_SEP_STRING "testdata" U_FILE_SEP_STRING;
415 #else
416 srcDataDir = ".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING "test" U_FILE_SEP_STRING "testdata" U_FILE_SEP_STRING;
417 FILE *f = fopen(".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING "test" U_FILE_SEP_STRING "testdata" U_FILE_SEP_STRING "rbbitst.txt", "r");
418 if (f) {
419 /* We're in icu/source/test/intltest/ */
420 fclose(f);
421 }
422 else {
423 /* We're in icu/source/test/intltest/Platform/(Debug|Release) */
424 srcDataDir = ".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING
425 "test" U_FILE_SEP_STRING "testdata" U_FILE_SEP_STRING;
426 }
427 #endif
428 return srcDataDir;
429 }
430
431 #define CTEST_MAX_TIMEZONE_SIZE 256
432 static UChar gOriginalTimeZone[CTEST_MAX_TIMEZONE_SIZE] = {0};
433
434 /**
435 * Call this once to get a consistent timezone. Use ctest_resetTimeZone to set it back to the original value.
436 * @param optionalTimeZone Set this to a requested timezone.
437 * Set to NULL to use the standard test timezone (Pacific Time)
438 */
ctest_setTimeZone(const char * optionalTimeZone,UErrorCode * status)439 U_CFUNC void ctest_setTimeZone(const char *optionalTimeZone, UErrorCode *status) {
440 #if !UCONFIG_NO_FORMATTING
441 UChar zoneID[CTEST_MAX_TIMEZONE_SIZE];
442
443 if (optionalTimeZone == NULL) {
444 optionalTimeZone = "America/Los_Angeles";
445 }
446 if (gOriginalTimeZone[0]) {
447 log_data_err("*** Error: time zone saved twice. New value will be %s (Are you missing data?)\n",
448 optionalTimeZone);
449 }
450 ucal_getDefaultTimeZone(gOriginalTimeZone, CTEST_MAX_TIMEZONE_SIZE, status);
451 if (U_FAILURE(*status)) {
452 log_err("*** Error: Failed to save default time zone: %s\n",
453 u_errorName(*status));
454 *status = U_ZERO_ERROR;
455 }
456
457 u_uastrncpy(zoneID, optionalTimeZone, CTEST_MAX_TIMEZONE_SIZE-1);
458 zoneID[CTEST_MAX_TIMEZONE_SIZE-1] = 0;
459 ucal_setDefaultTimeZone(zoneID, status);
460 if (U_FAILURE(*status)) {
461 log_err("*** Error: Failed to set default time zone to \"%s\": %s\n",
462 optionalTimeZone, u_errorName(*status));
463 }
464 #endif
465 }
466
467 /**
468 * Call this once get back the original timezone
469 */
ctest_resetTimeZone(void)470 U_CFUNC void ctest_resetTimeZone(void) {
471 #if !UCONFIG_NO_FORMATTING
472 UErrorCode status = U_ZERO_ERROR;
473
474 ucal_setDefaultTimeZone(gOriginalTimeZone, &status);
475 if (U_FAILURE(status)) {
476 log_err("*** Error: Failed to reset default time zone: %s\n",
477 u_errorName(status));
478 }
479 /* Set to an empty state */
480 gOriginalTimeZone[0] = 0;
481 #endif
482 }
483
484
ctst_malloc(size_t size)485 void *ctst_malloc(size_t size) {
486 ctst_allocated_total++;
487 if(ctst_allocated >= CTST_MAX_ALLOC - 1) {
488 ctst_allocated = 0;
489 ctst_free = true;
490 }
491 if(ctst_allocated_stuff[ctst_allocated]) {
492 free(ctst_allocated_stuff[ctst_allocated]);
493 }
494 return ctst_allocated_stuff[ctst_allocated++] = malloc(size);
495 }
496
497 #ifdef CTST_LEAK_CHECK
ctst_freeAll(void)498 static void ctst_freeAll(void) {
499 int i;
500 if(ctst_free == false) { /* only free up to the allocated mark */
501 for(i=0; i<ctst_allocated; i++) {
502 free(ctst_allocated_stuff[i]);
503 ctst_allocated_stuff[i] = NULL;
504 }
505 } else { /* free all */
506 for(i=0; i<CTST_MAX_ALLOC; i++) {
507 free(ctst_allocated_stuff[i]);
508 ctst_allocated_stuff[i] = NULL;
509 }
510 }
511 ctst_allocated = 0;
512 }
513
514 #define VERBOSE_ASSERTIONS
515
assertSuccessCheck(const char * msg,UErrorCode * ec,UBool possibleDataError)516 U_CFUNC UBool assertSuccessCheck(const char* msg, UErrorCode* ec, UBool possibleDataError) {
517 U_ASSERT(ec!=NULL);
518 if (U_FAILURE(*ec)) {
519 if (possibleDataError) {
520 log_data_err("FAIL: %s (%s)\n", msg, u_errorName(*ec));
521 } else {
522 log_err_status(*ec, "FAIL: %s (%s)\n", msg, u_errorName(*ec));
523 }
524 return false;
525 }
526 return true;
527 }
528
assertSuccess(const char * msg,UErrorCode * ec)529 U_CFUNC UBool assertSuccess(const char* msg, UErrorCode* ec) {
530 U_ASSERT(ec!=NULL);
531 return assertSuccessCheck(msg, ec, false);
532 }
533
534 /* if 'condition' is a UBool, the compiler complains bitterly about
535 expressions like 'a > 0' which it evaluates as int */
assertTrue(const char * msg,int condition)536 U_CFUNC UBool assertTrue(const char* msg, int /*not UBool*/ condition) {
537 if (!condition) {
538 log_err("FAIL: assertTrue() failed: %s\n", msg);
539 }
540 #ifdef VERBOSE_ASSERTIONS
541 else {
542 log_verbose("Ok: %s\n", msg);
543 }
544 #endif
545 return (UBool)condition;
546 }
547
assertEquals(const char * message,const char * expected,const char * actual)548 U_CFUNC UBool assertEquals(const char* message, const char* expected,
549 const char* actual) {
550 if (expected == NULL) {
551 expected = "(null)";
552 }
553 if (actual == NULL) {
554 actual = "(null)";
555 }
556 if (uprv_strcmp(expected, actual) != 0) {
557 log_err("FAIL: %s; got \"%s\"; expected \"%s\"\n",
558 message, actual, expected);
559 return false;
560 }
561 #ifdef VERBOSE_ASSERTIONS
562 else {
563 log_verbose("Ok: %s; got \"%s\"\n", message, actual);
564 }
565 #endif
566 return true;
567 }
568
assertUEquals(const char * message,const UChar * expected,const UChar * actual)569 U_CFUNC UBool assertUEquals(const char* message, const UChar* expected,
570 const UChar* actual) {
571 if (expected == NULL) {
572 expected = u"(null)";
573 }
574 if (actual == NULL) {
575 actual = u"(null)";
576 }
577 for (int32_t i=0;; i++) {
578 if (expected[i] != actual[i]) {
579 log_err("FAIL: %s; got \"%s\"; expected \"%s\"\n",
580 message, austrdup(actual), austrdup(expected));
581 return false;
582 }
583 UChar curr = expected[i];
584 U_ASSERT(curr == actual[i]);
585 if (curr == 0) {
586 break;
587 }
588 }
589 #ifdef VERBOSE_ASSERTIONS
590 log_verbose("Ok: %s; got \"%s\"\n", message, austrdup(actual));
591 #endif
592 return true;
593 }
594
assertIntEquals(const char * message,int64_t expected,int64_t actual)595 U_CFUNC UBool assertIntEquals(const char* message, int64_t expected, int64_t actual) {
596 if (expected != actual) {
597 log_err("FAIL: %s; got \"%d\"; expected \"%d\"\n",
598 message, actual, expected);
599 return false;
600 }
601 #ifdef VERBOSE_ASSERTIONS
602 else {
603 log_verbose("Ok: %s; got \"%d\"\n", message, actual);
604 }
605 #endif
606 return true;
607 }
608
assertPtrEquals(const char * message,const void * expected,const void * actual)609 U_CFUNC UBool assertPtrEquals(const char* message, const void* expected, const void* actual) {
610 if (expected != actual) {
611 log_err("FAIL: %s; got 0x%llx; expected 0x%llx\n",
612 message, actual, expected);
613 return false;
614 }
615 #ifdef VERBOSE_ASSERTIONS
616 else {
617 log_verbose("Ok: %s; got 0x%llx\n", message, actual);
618 }
619 #endif
620 return true;
621 }
622
assertDoubleEquals(const char * message,double expected,double actual)623 U_CFUNC UBool assertDoubleEquals(const char *message, double expected, double actual) {
624 if (expected != actual) {
625 log_err("FAIL: %s; got \"%f\"; expected \"%f\"\n", message, actual, expected);
626 return false;
627 }
628 #ifdef VERBOSE_ASSERTIONS
629 else {
630 log_verbose("Ok: %s; got \"%f\"\n", message, actual);
631 }
632 #endif
633 return true;
634 }
635
636 #endif
637