]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/cintltst/cintltst.c
ICU-64260.0.1.tar.gz
[apple/icu.git] / icuSources / test / cintltst / cintltst.c
index a09b2392d938021d75b108385af8fee1dae61ba9..aaa187f6bdb14c22c5fb68c17e677f8d5c9fb8c3 100644 (file)
@@ -1,6 +1,8 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
 /********************************************************************
  * COPYRIGHT:
- * Copyright (c) 1997-2010, International Business Machines Corporation and
+ * Copyright (c) 1997-2015, International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
 /********************************************************************************
@@ -22,7 +24,6 @@
 #include "unicode/putil.h"
 #include "cstring.h"
 #include "cintltst.h"
-#include "umutex.h"
 #include "uassert.h"
 #include "cmemory.h"
 #include "unicode/uchar.h"
 #   include <console.h>
 #endif
 
+#define CTST_MAX_ALLOC 8192
+/* Array used as a queue */
+static void * ctst_allocated_stuff[CTST_MAX_ALLOC] = {0};
+static int ctst_allocated = 0;
+static UBool ctst_free = FALSE;
+static int ctst_allocated_total = 0;
+
 #define CTST_LEAK_CHECK 1
+
 #ifdef CTST_LEAK_CHECK
-U_CFUNC void ctst_freeAll(void);
+static void ctst_freeAll(void);
 #endif
 
 static char* _testDataPath=NULL;
@@ -66,6 +75,10 @@ void ctest_setICU_DATA(void);
 static int gOrigArgc;
 static const char* const * gOrigArgv;
 
+#ifdef UNISTR_COUNT_FINAL_STRING_LENGTHS
+U_CAPI void unistr_printLengths();
+#endif
+
 int main(int argc, const char* const argv[])
 {
     int nerrors = 0;
@@ -210,6 +223,10 @@ int main(int argc, const char* const argv[])
         ctst_freeAll();
         /* To check for leaks */
         u_cleanup(); /* nuke the hashtable.. so that any still-open cnvs are leaked */
+        
+        if(getTestOption(VERBOSITY_OPTION) && ctst_allocated_total>0) {
+          fprintf(stderr,"ctst_freeAll():  cleaned up after %d allocations (queue of %d)\n", ctst_allocated_total, CTST_MAX_ALLOC);
+        }
 #ifdef URES_DEBUG
         if(ures_dumpCacheContents()) {
           fprintf(stderr, "Error: After final u_cleanup, RB cache was not empty.\n");
@@ -222,10 +239,10 @@ int main(int argc, const char* const argv[])
 
     }  /* End of loop that repeats the entire test, if requested.  (Normally doesn't loop)  */
 
-    if (ALLOCATION_COUNT > 0) {
-        fprintf(stderr, "There were %d blocks leaked!\n", ALLOCATION_COUNT);
-        nerrors++;
-    }
+#ifdef UNISTR_COUNT_FINAL_STRING_LENGTHS
+    unistr_printLengths();
+#endif
+
     endTime = uprv_getRawUTCtime();
     diffTime = (int32_t)(endTime - startTime);
     printf("Elapsed Time: %02d:%02d:%02d.%03d\n",
@@ -494,7 +511,7 @@ char *aescstrdup(const UChar* unichars,int32_t length){
     const void *p;
     UErrorCode errorCode = U_ZERO_ERROR;
 #if U_CHARSET_FAMILY==U_EBCDIC_FAMILY
-#   ifdef OS390
+#   if U_PLATFORM == U_PF_OS390
         static const char convName[] = "ibm-1047";
 #   else
         static const char convName[] = "ibm-37";
@@ -612,13 +629,9 @@ U_CFUNC void ctest_resetTimeZone(void) {
 #endif
 }
 
-#define CTST_MAX_ALLOC 8192
-/* Array used as a queue */
-static void * ctst_allocated_stuff[CTST_MAX_ALLOC] = {0};
-static int ctst_allocated = 0;
-static UBool ctst_free = FALSE;
 
 void *ctst_malloc(size_t size) {
+  ctst_allocated_total++;
     if(ctst_allocated >= CTST_MAX_ALLOC - 1) {
         ctst_allocated = 0;
         ctst_free = TRUE;
@@ -630,14 +643,14 @@ void *ctst_malloc(size_t size) {
 }
 
 #ifdef CTST_LEAK_CHECK
-void ctst_freeAll() {
+static void ctst_freeAll() {
     int i;
-    if(ctst_free == 0) {
+    if(ctst_free == FALSE) { /* only free up to the allocated mark */
         for(i=0; i<ctst_allocated; i++) {
             free(ctst_allocated_stuff[i]);
             ctst_allocated_stuff[i] = NULL;
         }
-    } else {
+    } else { /* free all */
         for(i=0; i<CTST_MAX_ALLOC; i++) {
             free(ctst_allocated_stuff[i]);
             ctst_allocated_stuff[i] = NULL;
@@ -649,15 +662,24 @@ void ctst_freeAll() {
 
 #define VERBOSE_ASSERTIONS
 
-U_CFUNC UBool assertSuccess(const char* msg, UErrorCode* ec) {
+U_CFUNC UBool assertSuccessCheck(const char* msg, UErrorCode* ec, UBool possibleDataError) {
     U_ASSERT(ec!=NULL);
     if (U_FAILURE(*ec)) {
-        log_err_status(*ec, "FAIL: %s (%s)\n", msg, u_errorName(*ec));
+        if (possibleDataError) {
+            log_data_err("FAIL: %s (%s)\n", msg, u_errorName(*ec));
+        } else {
+            log_err_status(*ec, "FAIL: %s (%s)\n", msg, u_errorName(*ec));
+        }
         return FALSE;
     }
     return TRUE;
 }
 
+U_CFUNC UBool assertSuccess(const char* msg, UErrorCode* ec) {
+    U_ASSERT(ec!=NULL);
+    return assertSuccessCheck(msg, ec, FALSE);
+}
+
 /* if 'condition' is a UBool, the compiler complains bitterly about
    expressions like 'a > 0' which it evaluates as int */
 U_CFUNC UBool assertTrue(const char* msg, int /*not UBool*/ condition) { 
@@ -686,15 +708,39 @@ U_CFUNC UBool assertEquals(const char* message, const char* expected,
 #endif
     return TRUE;
 }
-/*--------------------------------------------------------------------
- * Time bomb - allows temporary behavior that expires at a given
- *             release
- *--------------------------------------------------------------------
- */
 
-U_CFUNC UBool isICUVersionAtLeast(const UVersionInfo x) {
-    UVersionInfo v;
-    u_getVersion(v);
-    return (uprv_memcmp(v, x, U_MAX_VERSION_LENGTH) >= 0);
+U_CFUNC UBool assertUEquals(const char* message, const UChar* expected,
+                            const UChar* actual) {
+    for (int32_t i=0;; i++) {
+        if (expected[i] != actual[i]) {
+            log_err("FAIL: %s; got \"%s\"; expected \"%s\"\n",
+                    message, austrdup(actual), austrdup(expected));
+            return FALSE;
+        }
+        UChar curr = expected[i];
+        U_ASSERT(curr == actual[i]);
+        if (curr == 0) {
+            break;
+        }
+    }
+#ifdef VERBOSE_ASSERTIONS
+    log_verbose("Ok: %s; got \"%s\"\n", message, austrdup(actual));
+#endif
+    return TRUE;
+}
+
+U_CFUNC UBool assertIntEquals(const char* message, int64_t expected, int64_t actual) {
+    if (expected != actual) {
+        log_err("FAIL: %s; got \"%d\"; expected \"%d\"\n",
+                message, actual, expected);
+        return FALSE;
+    }
+#ifdef VERBOSE_ASSERTIONS
+    else {
+        log_verbose("Ok: %s; got \"%d\"\n", message, actual);
+    }
+#endif
+    return TRUE;
 }
+
 #endif