You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2006/10/24 19:44:14 UTC

svn commit: r467401 - in /lucene/lucy/trunk/charmonizer: charm_test.c src/Charmonizer/Test/FuncMacro.charm src/Charmonizer/Test/Integers.charm src/Charmonizer/Test/TestHandler.charm src/Charmonizer/Test/TestHandler.harm

Author: marvin
Date: Tue Oct 24 10:44:13 2006
New Revision: 467401

URL: http://svn.apache.org/viewvc?view=rev&rev=467401
Log:
Add support for testing Charmonizer.

Added:
    lucene/lucy/trunk/charmonizer/charm_test.c
    lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/FuncMacro.charm
    lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/Integers.charm
    lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/TestHandler.charm
    lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/TestHandler.harm

Added: lucene/lucy/trunk/charmonizer/charm_test.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/charm_test.c?view=auto&rev=467401
==============================================================================
--- lucene/lucy/trunk/charmonizer/charm_test.c (added)
+++ lucene/lucy/trunk/charmonizer/charm_test.c Tue Oct 24 10:44:13 2006
@@ -0,0 +1,47 @@
+#include <stdio.h>
+#include "Charmonizer/Test/TestHandler.h"
+
+typedef void
+(*t_func)(int *num_tests, int *num_passed, int *num_failed, int *num_skipped);
+
+typedef struct TestGroup {
+    const char *name;
+    t_func func;
+} TestGroup;
+
+TestGroup tests[] = {
+    { "FuncMacro", chaz_TestHand_test_FuncMacro },
+    { "Integers", chaz_TestHand_test_Integers },
+    { NULL, NULL }
+};
+
+int main() {
+    int num_tests, num_passed, num_failed, num_skipped;
+    int total_tests   = 0;
+    int total_passed  = 0;
+    int total_failed  = 0;
+    int total_skipped = 0;
+    int i;
+
+    for (i = 0; tests[i].name != NULL; i++) {
+        t_func test_func = tests[i].func;
+        const char *name = tests[i].name;
+        printf("=========================\n");
+        printf("%s\n=========================\n", name);
+        test_func(&num_tests, &num_passed, &num_failed, &num_skipped);
+        total_tests    += num_tests;
+        total_passed   += num_passed;
+        total_failed   += num_failed;
+        total_skipped  += num_skipped;
+        printf("-------------------------\n");
+        printf("Tests:   %d\nPassed:  %d\nFailed:  %d\nSkipped: %d\n\n",
+            num_tests, num_passed, num_failed, num_skipped);
+    }
+    
+    printf("=============================\n");
+    printf("TOTAL TESTS: %d\nTOTAL PASSED: %d\nTOTAL FAILED: %d\n"
+        "TOTAL SKIPPED: %d\n", 
+        total_tests, total_passed, total_failed, total_skipped);
+    return 0;
+}
+

Added: lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/FuncMacro.charm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/FuncMacro.charm?view=auto&rev=467401
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/FuncMacro.charm (added)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/FuncMacro.charm Tue Oct 24 10:44:13 2006
@@ -0,0 +1,47 @@
+#define CHAZ_USE_SHORT_NAMES
+
+#include "_charm_test.h"
+#include "Charmonizer/Test/TestHandler.h"
+
+void 
+chaz_TestHand_test_FuncMacro(int *num_tests, int *num_passed, 
+                             int *num_failed, int *num_skipped)
+{
+    int test_num  = 0;
+    *num_tests    = 3;
+    *num_passed   = 0;
+    *num_failed   = 0;
+    *num_skipped  = *num_tests;
+
+#ifdef HAS_FUNC_MACRO
+    Assert_True((strcmp(Func_Macro, "chaz_TestHand_test_FuncMacro") == 0), 
+        "Func_Macro");
+#endif
+
+#ifdef HAS_ISO_FUNC_MACRO
+    Assert_True((strcmp(__func__, "chaz_TestHand_test_FuncMacro") == 0),
+        "HAS_ISO_FUNC_MACRO");
+#endif
+
+#ifdef HAS_GNUC_FUNC_MACRO
+    Assert_True((strcmp(__FUNCTION__, "chaz_TestHand_test_FuncMacro") == 0), 
+        "HAS_GNUC_FUNC_MACRO");
+#endif
+}
+
+/**
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+

Added: lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/Integers.charm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/Integers.charm?view=auto&rev=467401
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/Integers.charm (added)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/Integers.charm Tue Oct 24 10:44:13 2006
@@ -0,0 +1,113 @@
+#define CHAZ_USE_SHORT_NAMES
+
+#include "Charmonizer/Test/TestHandler.h"
+#include "_charm_test.h"
+
+
+void 
+chaz_TestHand_test_Integers(int *num_tests, int *num_passed, int *num_failed, 
+                            int *num_skipped)
+{
+    int test_num  = 0;
+    *num_tests    = 27;
+    *num_passed   = 0;
+    *num_failed   = 0;
+    *num_skipped  = *num_tests;
+
+    {
+        long one= 1;
+        long big_endian = !(*((char *)(&one)));
+#ifdef BIG_ENDIAN
+    Assert_True(big_endian, "BIG_ENDIAN");
+#else
+ #if defined(LITTLE_ENDIAN)
+    Assert_True(!big_endian, "LITTLE_ENDIAN");
+ #else
+    Assert_True(0, "Either BIG_ENDIAN nor LITTLE_ENDIAN should be defined");
+ #endif
+#endif
+    }
+    
+    Assert_True((SIZEOF_CHAR  == sizeof(char)),  "SIZEOF_CHAR");
+    Assert_True((SIZEOF_SHORT == sizeof(short)), "SIZEOF_SHORT");
+    Assert_True((SIZEOF_INT   == sizeof(int)),   "SIZEOF_INT");
+    Assert_True((SIZEOF_LONG  == sizeof(long)),  "SIZEOF_LONG");
+    Assert_True((SIZEOF_PTR   == sizeof(void*)), "SIZEOF_PTR");
+
+#ifdef HAS_LONG_LONG
+    Assert_True((SIZEOF_LONG_LONG == sizeof(long long)), 
+        "HAS_LONG_LONG and SIZEOF_LONG_LONG");
+#endif
+    
+#ifdef HAS_INTTYPES_H
+    #include <inttypes.h>
+    Assert_True((sizeof(int8_t) == 1), "HAS_INTTYPES_H");
+#endif
+    
+    {
+        bool_t the_truth = true;
+        Assert_True(the_truth, "bool_t true");
+        Assert_True(!false, "false is false");
+    }
+#ifdef HAS_I8_T
+    {
+        i8_t foo = -100;
+        u8_t bar = 200;
+        Assert_True((foo == -100), "i8_t is signed");
+        Assert_True((bar == 200), "u8_t is unsigned");
+        Assert_True((sizeof(i8_t) == 1), "i8_t is 1 byte");
+        Assert_True((sizeof(u8_t) == 1), "u8_t is 1 byte");
+    }
+#endif
+#ifdef HAS_I16_T
+    {
+        i16_t foo = -100;
+        u16_t bar = 30000;
+        Assert_True((foo == -100), "i16_t is signed");
+        Assert_True((bar == 30000), "u16_t is unsigned");
+        Assert_True((sizeof(i16_t) == 2), "i16_t is 2 bytes");
+        Assert_True((sizeof(u16_t) == 2), "u16_t is 2 bytes");
+    }
+#endif
+#ifdef HAS_I32_T
+    {
+        i32_t foo = -100;
+        u32_t bar = (u32_t)4000000000;
+        Assert_True((foo == -100), "i32_t is signed");
+        Assert_True((bar == (u32_t)4000000000), "u32_t is unsigned");
+        Assert_True((sizeof(i32_t) == 4), "i32_t is 4 bytes");
+        Assert_True((sizeof(u32_t) == 4), "u32_t is 4 bytes");
+    }
+#endif
+#ifdef HAS_I64_T
+    {
+        char buf[100];
+        i64_t foo = -100;
+        u64_t bar = (u64_t)18000000000000000000;
+        Assert_True((foo == -100), "i64_t is signed");
+        Assert_True((bar == (u64_t)18000000000000000000), 
+            "u64_t is unsigned");
+        Assert_True((sizeof(i64_t) == 8), "i64_t is 8 bytes");
+        Assert_True((sizeof(u64_t) == 8), "u64_t is 8 bytes");
+        sprintf(buf, U64P, bar);
+        Assert_True(strcmp(buf, "18000000000000000000"), "U64P");
+    }
+#endif
+}
+
+/**
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+

Added: lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/TestHandler.charm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/TestHandler.charm?view=auto&rev=467401
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/TestHandler.charm (added)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/TestHandler.charm Tue Oct 24 10:44:13 2006
@@ -0,0 +1,34 @@
+#define CHAZ_USE_SHORT_NAMES
+
+#include <stdio.h>
+#include "Charmonizer/Test/TestHandler.h"
+
+chaz_bool_t
+chaz_TestHand_report(int value, const char *message, int test_num)
+{
+    if (value) {
+        printf("%-4d pass: %s\n", test_num, message);
+        return true;
+    }
+    else {
+        printf("%-4d fail: %s\n", test_num, message);
+        return false;
+    }
+}
+
+/**
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+

Added: lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/TestHandler.harm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/TestHandler.harm?view=auto&rev=467401
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/TestHandler.harm (added)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/TestHandler.harm Tue Oct 24 10:44:13 2006
@@ -0,0 +1,93 @@
+/* Charmonizer/Test/TestHandler.h - test Charmonizer's output.
+ */
+
+#ifndef H_CHAZ_TEST_HANDLER
+#define H_CHAZ_TEST_HANDLER
+
+#include "Charmonizer/Defines.h"
+
+/* These tests all require the file _charm_test.h.  See the documentation for
+ * Charmonizer.h for instructions on how to produce it.
+ *
+ * No other header files should be included other than _charm_test.h and this
+ * one.
+ * 
+ * Since Charmonizer conditionally defines many symbols, it is difficult to
+ * tell whether a symbol is missing because it should not have been generated,
+ * or whether it is missing because an error occurred.  These test functions
+ * make the assumption that any missing symbols have a good excuse for their
+ * absence, and test only defined symbols.  This may result in undetected
+ * failure some of the time.  However, missing symbols required by your
+ * application will trigger compile time errors, so the problem is less severe
+ * than it appears, affecting only fallbacks.
+ *
+ * Each test function accepts four arguments: pointers to integers which the
+ * function will modify. All diagnostic information is printed to stderr.
+ */
+void 
+chaz_TestHand_test_FuncMacro(
+    int *num_tests, int *num_passed, int *num_failed, int *num_skipped);
+
+void 
+chaz_TestHand_test_Integers(
+    int *num_tests, int *num_passed, int *num_failed, int *num_skipped);
+
+void 
+chaz_TestHand_test_LargeFiles(
+    int *num_tests, int *num_passed, int *num_failed, int *num_skipped);
+
+void 
+chaz_TestHand_test_UnusedVars(
+    int *num_tests, int *num_passed, int *num_failed, int *num_skipped);
+
+void 
+chaz_TestHand_test_VariadicMacros(
+    int *num_tests, int *num_passed, int *num_failed, int *num_skipped);
+
+/* Print a message to stderr indicating pass/fail based on [value].
+ */
+chaz_bool_t
+chaz_TestHand_report(int value, const char *message, int test_num);
+
+/* Wrap a call to report(), incrementing tallies based on the results of the
+ * test.
+ */
+#define Chaz_TestHand_Assert_True(expression, message) \
+     do { \
+         test_num++; \
+         (*num_skipped)--; \
+         if (chaz_TestHand_report(expression, message, test_num)) \
+             (*num_passed)++; \
+         else \
+             (*num_failed)++; \
+     } while (0)
+
+#ifdef CHAZ_USE_SHORT_NAMES
+# define TestHand_test_FuncMacro        chaz_TestHand_test_FuncMacro
+# define TestHand_test_Integers         chaz_TestHand_test_Integers
+# define TestHand_test_LargeFiles       chaz_TestHand_test_LargeFiles
+# define TestHand_test_UnusedVars       chaz_TestHand_test_UnusedVars
+# define TestHand_test_VariadicMacros   chaz_TestHand_test_VariadicMacros
+# define TestHand_report                chaz_TestHand_report
+# define Assert_True                    Chaz_TestHand_Assert_True
+#endif
+
+#endif /* H_CHAZ_TEST_HANDLER */
+
+
+/**
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+