]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/cintltst/spreptst.c
ICU-400.37.tar.gz
[apple/icu.git] / icuSources / test / cintltst / spreptst.c
index 9d82c03b7632480bfe56d5870c23601d6273c1dc..8a2fa96805bc509a2908282ccac9b19bb33e2286 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *******************************************************************************
  *
- *   Copyright (C) 2003, International Business Machines
+ *   Copyright (C) 2003-2008, International Business Machines
  *   Corporation and others.  All Rights Reserved.
  *
  *******************************************************************************
@@ -37,6 +37,8 @@ static void Test_nfs4_mixed_prep_data(void);
 static void Test_nfs4_cs_prep(void);
 static void Test_nfs4_cis_prep(void);
 static void Test_nfs4_mixed_prep(void);
+static void TestBEAMWarning(void);
+static void TestCoverage(void);
 
 void 
 addUStringPrepTest(TestNode** root)
@@ -47,11 +49,19 @@ addUStringPrepTest(TestNode** root)
    addTest(root, &Test_nfs4_cs_prep,         "spreptst/Test_nfs4_cs_prep");
    addTest(root, &Test_nfs4_cis_prep,        "spreptst/Test_nfs4_cis_prep");
    addTest(root, &Test_nfs4_mixed_prep,      "spreptst/Test_nfs4_mixed_prep");
+   addTest(root, &TestBEAMWarning,           "spreptst/TestBEAMWarning");
+   addTest(root, &TestCoverage,              "spreptst/TestCoverage");
 }
 
 static void 
 Test_nfs4_cs_prep_data(void){
     UErrorCode errorCode = U_ZERO_ERROR;
+    loadTestData(&errorCode);
+    if(U_FAILURE(errorCode)) {
+        log_data_err("Could not load testdata.dat, status = %s\n", u_errorName(errorCode));
+        return;
+    }
+
     log_verbose("Testing nfs4_cs_prep_ci.txt\n");
     doStringPrepTest("nfscsi","nfs4_cs_prep_ci.txt", USPREP_DEFAULT, &errorCode);
 
@@ -70,6 +80,12 @@ Test_nfs4_cis_prep_data(void){
 static void 
 Test_nfs4_mixed_prep_data(void){
     UErrorCode errorCode = U_ZERO_ERROR;
+    loadTestData(&errorCode);
+    if(U_FAILURE(errorCode)) {
+        log_data_err("Could not load testdata.dat, status = %s\n", u_errorName(errorCode));
+        return;
+    }
+
     log_verbose("Testing nfs4_mixed_prep_s.txt\n");
     doStringPrepTest("nfsmxs","nfs4_mixed_prep_s.txt", USPREP_DEFAULT, &errorCode);
 
@@ -79,7 +95,7 @@ Test_nfs4_mixed_prep_data(void){
 
 }
 
-static struct ConformanceTestCases
+static const struct ConformanceTestCases
    {
      const char *comment;
      const char *in;
@@ -290,6 +306,12 @@ unescapeData(const char* src, int32_t srcLen,
 
 static void Test_nfs4_cis_prep(void){
     int32_t i=0;
+    UErrorCode loadStatus = U_ZERO_ERROR;
+    loadTestData(&loadStatus);
+    if (U_FAILURE(loadStatus)) {
+        log_data_err("Test could not initialize. Got %s\n", u_errorName(loadStatus));
+        return;
+    }
 
     for(i=0;i< (int32_t)(sizeof(conformanceTestCases)/sizeof(conformanceTestCases[0]));i++){
         const char* src = conformanceTestCases[i].in;
@@ -403,6 +425,13 @@ static const char* mixed_prep_data[] ={
 
 static void 
 Test_nfs4_mixed_prep(void){
+    UErrorCode loadStatus = U_ZERO_ERROR;
+    loadTestData(&loadStatus);
+    if (U_FAILURE(loadStatus)) {
+        log_data_err("Test could not initialize. Got %s\n", u_errorName(loadStatus));
+        return;
+    }
+
     {
         int32_t i=0;
         char src[MAX_BUFFER_SIZE];
@@ -453,6 +482,13 @@ Test_nfs4_mixed_prep(void){
 
 static void 
 Test_nfs4_cs_prep(void){
+    UErrorCode errorCode = U_ZERO_ERROR;
+    loadTestData(&errorCode);
+    if(U_FAILURE(errorCode)) {
+        log_data_err("Could not load testdata.dat, status = %s\n", u_errorName(errorCode));
+        return;
+    }
+
     {
         /* BiDi checking is turned off */
         const char *source = "\\uC138\\uACC4\\uC758\\uBAA8\\uB4E0\\uC0AC\\uB78C\\uB4E4\\uC774\\u0644\\u064A\\u0647\\uD55C\\uAD6D\\uC5B4\\uB97C\\uC774\\uD574\\uD55C\\uB2E4\\uBA74";
@@ -550,6 +586,49 @@ Test_nfs4_cs_prep(void){
     }
 }
 
+
+
+static void TestBEAMWarning(){
+    UErrorCode status = U_ZERO_ERROR;
+    UParseError parseError;
+    UStringPrepProfile* profile = NULL;
+    /* get the test data path */
+    const char *testdatapath = NULL;
+    UChar src =0x0000;
+    testdatapath = loadTestData(&status);
+    if(U_FAILURE(status)) {
+        log_data_err("Could not load testdata.dat, status = %s\n", u_errorName(status));
+        return;
+    }
+    /* open the profile */
+    profile = usprep_open(testdatapath, "nfscis",  &status);
+    usprep_prepare(profile,&src , 0, NULL, 0, USPREP_DEFAULT, &parseError, &status);
+
+    usprep_close(profile);
+}
+
+static void TestCoverage(void) {
+    UErrorCode status = U_USELESS_COLLATOR_ERROR;
+    UParseError parseError;
+    
+    usprep_open(NULL, NULL, &status);
+    if (status != U_USELESS_COLLATOR_ERROR) {
+        log_err("usprep_open didn't react correctly to a bad UErrorCode\n");
+    }
+    usprep_prepare(NULL, NULL, 0, NULL, 0, USPREP_DEFAULT, &parseError, &status);
+    if (status != U_USELESS_COLLATOR_ERROR) {
+        log_err("usprep_prepare didn't react correctly to a bad UErrorCode\n");
+    }
+    status = U_ZERO_ERROR;
+    usprep_prepare(NULL, NULL, 0, NULL, 0, USPREP_DEFAULT, &parseError, &status);
+    if (status != U_ILLEGAL_ARGUMENT_ERROR) {
+        log_err("usprep_prepare didn't check its arguments\n");
+    }
+
+    /* Don't crash */
+    usprep_close(NULL);
+}
+
 #endif
 
 /*