r24685: Don't warn about iconv tests not being usable until they're actually being...
authorJelmer Vernooij <jelmer@samba.org>
Sun, 26 Aug 2007 22:15:44 +0000 (22:15 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 20:02:42 +0000 (15:02 -0500)
(This used to be commit df34e606981c3a9fe5b9ac846dbf40d36500bd6b)

source4/torture/local/iconv.c

index 6d318f2d91f8fbc02b6c61d49466f8f6e5cf0856..c543aa7c8fe93ab348722d853f5b50bc76182466 100644 (file)
 #include "torture/util.h"
 
 #if HAVE_NATIVE_ICONV
+
+static bool iconv_untestable(struct torture_context *tctx)
+{
+       iconv_t cd;
+
+       if (!lp_parm_bool(-1, "iconv", "native", true))
+               torture_skip(tctx, "system iconv disabled - skipping test");
+
+       cd = iconv_open("UTF-16LE", "UCS-4LE");
+       if (cd == (iconv_t)-1)
+               torture_skip(tctx, "unable to test - system iconv library does not support UTF-16LE -> UCS-4LE");
+       iconv_close(cd);
+
+       cd = iconv_open("UTF-16LE", "CP850");
+       if (cd == (iconv_t)-1)
+               torture_skip(tctx, "unable to test - system iconv library does not support UTF-16LE -> CP850\n");
+       iconv_close(cd);
+
+       return false;
+}
+
 /*
   generate a UTF-16LE buffer for a given unicode codepoint
 */
@@ -292,6 +313,9 @@ static bool test_codepoint(struct torture_context *tctx, unsigned int codepoint)
 
 static bool test_next_codepoint(struct torture_context *tctx)
 {
+       if (iconv_untestable(tctx))
+               return true;
+
        unsigned int codepoint;
        for (codepoint=0;codepoint<(1<<20);codepoint++) {
                if (!test_codepoint(tctx, codepoint))
@@ -306,6 +330,9 @@ static bool test_first_1m(struct torture_context *tctx)
        size_t size;
        unsigned char inbuf[1000];
 
+       if (iconv_untestable(tctx))
+               return true;
+
        for (codepoint=0;codepoint<(1<<20);codepoint++) {
                if (gen_codepoint_utf16(codepoint, (char *)inbuf, &size) != 0) {
                        continue;
@@ -328,6 +355,10 @@ static bool test_random_5m(struct torture_context *tctx)
 {
        unsigned char inbuf[1000];
        unsigned int i;
+
+       if (iconv_untestable(tctx))
+               return true;
+
        for (i=0;i<500000;i++) {
                size_t size;
                unsigned int c;
@@ -368,30 +399,8 @@ static bool test_random_5m(struct torture_context *tctx)
 
 struct torture_suite *torture_local_iconv(TALLOC_CTX *mem_ctx)
 {
-       static iconv_t cd;
        struct torture_suite *suite = torture_suite_create(mem_ctx, "ICONV");
 
-       if (!lp_parm_bool(-1, "iconv", "native", True)) {
-               printf("system iconv disabled - skipping test\n");
-               return NULL;
-       }
-
-       cd = iconv_open("UTF-16LE", "UCS-4LE");
-       if (cd == (iconv_t)-1) {
-               printf("unable to test - system iconv library does not support UTF-16LE -> UCS-4LE\n");
-               return NULL;
-       }
-       iconv_close(cd);
-
-       cd = iconv_open("UTF-16LE", "CP850");
-       if (cd == (iconv_t)-1) {
-               printf("unable to test - system iconv library does not support UTF-16LE -> CP850\n");
-               return NULL;
-       }
-       iconv_close(cd);
-
-       srandom(time(NULL));
-
        torture_suite_add_simple_test(suite, "next_codepoint()",
                                                                   test_next_codepoint);