Repository: lucy-charmonizer Updated Branches: refs/heads/rework_tests [created] 6adc79779
http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/6adc7977/tests/charmonizer.main ---------------------------------------------------------------------- diff --git a/tests/charmonizer.main b/tests/charmonizer.main new file mode 100644 index 0000000..919365d --- /dev/null +++ b/tests/charmonizer.main @@ -0,0 +1,235 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +/* Source fragment for the Charmonizer tests' charmonizer.c. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "Charmonizer/Probe.h" +#include "Charmonizer/Probe/AtomicOps.h" +#include "Charmonizer/Probe/DirManip.h" +#include "Charmonizer/Probe/Floats.h" +#include "Charmonizer/Probe/FuncMacro.h" +#include "Charmonizer/Probe/Headers.h" +#include "Charmonizer/Probe/Booleans.h" +#include "Charmonizer/Probe/Integers.h" +#include "Charmonizer/Probe/LargeFiles.h" +#include "Charmonizer/Probe/Memory.h" +#include "Charmonizer/Probe/SymbolVisibility.h" +#include "Charmonizer/Probe/UnusedVars.h" +#include "Charmonizer/Probe/VariadicMacros.h" +#include "Charmonizer/Core/CLI.h" +#include "Charmonizer/Core/Compiler.h" +#include "Charmonizer/Core/ConfWriter.h" +#include "Charmonizer/Core/ConfWriterC.h" +#include "Charmonizer/Core/ConfWriterPerl.h" +#include "Charmonizer/Core/ConfWriterRuby.h" +#include "Charmonizer/Core/HeaderChecker.h" +#include "Charmonizer/Core/Make.h" +#include "Charmonizer/Core/OperatingSystem.h" +#include "Charmonizer/Core/Util.h" + +typedef struct SourceFileContext { + chaz_MakeVar *var; +} SourceFileContext; + +static const char chaztest_version[] = "0.1.0"; +static const char chaztest_major_version[] = "0.1"; + +static void +S_write_makefile(void); + +static void +S_c_file_callback(const char *dir, char *file, void *context); + +static int +S_ends_with(const char *string, const char *postfix); + +int main(int argc, const char **argv) { + /* Initialize. */ + { + chaz_CLI *cli = chaz_CLI_new(argv[0], NULL); + int result = chaz_Probe_parse_cli_args(argc, argv, cli); + if (!result) { + fprintf(stderr, "%s", chaz_CLI_help(cli)); + exit(1); + } + chaz_Probe_init(cli); + chaz_CLI_destroy(cli); + } + + /* Run probe modules. */ + chaz_DirManip_run(); + chaz_Headers_run(); + chaz_AtomicOps_run(); + chaz_FuncMacro_run(); + chaz_Booleans_run(); + chaz_Integers_run(); + chaz_Floats_run(); + chaz_LargeFiles_run(); + chaz_Memory_run(); + chaz_SymbolVisibility_run(); + chaz_UnusedVars_run(); + chaz_VariadicMacros_run(); + + /* Create Makefile. */ + S_write_makefile(); + + /* Write custom postamble. */ + chaz_ConfWriter_append_conf( + "#ifdef CHY_HAS_SYS_TYPES_H\n" + " #include <sys/types.h>\n" + "#endif\n\n" + ); + chaz_ConfWriter_append_conf( + "#ifdef CHY_HAS_ALLOCA_H\n" + " #include <alloca.h>\n" + "#elif defined(CHY_HAS_MALLOC_H)\n" + " #include <malloc.h>\n" + "#elif defined(CHY_ALLOCA_IN_STDLIB_H)\n" + " #include <stdlib.h>\n" + "#endif\n\n" + ); + chaz_ConfWriter_append_conf( + "#ifdef CHY_HAS_WINDOWS_H\n" + " /* Target Windows XP. */\n" + " #ifndef WINVER\n" + " #define WINVER 0x0500\n" + " #endif\n" + " #ifndef _WIN32_WINNT\n" + " #define _WIN32_WINNT 0x0500\n" + " #endif\n" + "#endif\n\n" + ); + + /* Clean up. */ + chaz_Probe_clean_up(); + + return 0; +} + +static void +S_write_makefile() { + SourceFileContext sfc; + + chaz_MakeFile *makefile; + chaz_MakeVar *var; + chaz_MakeRule *rule; + chaz_Lib *shared_lib; + chaz_CFlags *cflags; + + const char *dir_sep = chaz_OS_dir_sep(); + const char *exe_ext = chaz_OS_exe_ext(); + + char *shared_lib_filename; + char *test_exe; + char *scratch; + + makefile = chaz_MakeFile_new(); + + /* Compiler flags. */ + cflags = chaz_CC_new_cflags(); + if (chaz_Probe_gcc_version_num()) { + chaz_CFlags_add_define(cflags, "_LARGEFILE64_SOURCE", NULL); + } + chaz_CFlags_add_include_dir(cflags, "."); + chaz_CFlags_add_include_dir(cflags, "src"); + var = chaz_MakeFile_add_var(makefile, "CFLAGS", NULL); + chaz_MakeVar_append(var, chaz_CFlags_get_string(cflags)); + chaz_MakeVar_append(var, chaz_CC_get_cflags()); + chaz_CFlags_destroy(cflags); + + /* Object files. */ + sfc.var = chaz_MakeFile_add_var(makefile, "OBJECTS", NULL); + chaz_Make_list_files("src", "c", S_c_file_callback, &sfc); + + /* Shared library. */ + shared_lib = chaz_Lib_new("chaztest", chaz_Lib_SHARED, chaztest_version, + chaztest_major_version); + shared_lib_filename = chaz_Lib_filename(shared_lib); + + /* 'all' target. */ + chaz_MakeFile_add_rule(makefile, "all", shared_lib_filename); + + /* Rule for shared library. */ + chaz_MakeFile_add_shared_lib(makefile, shared_lib, "$(OBJECTS)", NULL); + + /* Rule for test executable. */ + test_exe = chaz_Util_join("", "tests", dir_sep, "test", exe_ext, NULL); + scratch = chaz_Util_join(dir_sep, "tests", "test.c", NULL); + cflags = chaz_CC_new_cflags(); + chaz_CFlags_add_include_dir(cflags, "src"); + chaz_CFlags_add_library(cflags, shared_lib); + rule = chaz_MakeFile_add_compiled_exe(makefile, test_exe, scratch, cflags); + chaz_MakeRule_add_prereq(rule, shared_lib_filename); + free(scratch); + chaz_CFlags_destroy(cflags); + + /* 'test' target. */ + rule = chaz_MakeFile_add_rule(makefile, "test", test_exe); + if (strcmp(chaz_OS_shared_lib_ext(), ".so") == 0) { + scratch = chaz_Util_join(" ", "LD_LIBRARY_PATH=.", test_exe, NULL); + } + else { + scratch = chaz_Util_strdup(test_exe); + } + chaz_MakeRule_add_command(rule, scratch); + free(scratch); + + /* 'clean' target. */ + rule = chaz_MakeFile_clean_rule(makefile); + chaz_MakeRule_add_rm_command(rule, "$(OBJECTS)"); + + /* Write Makefile. */ + chaz_MakeFile_write(makefile); + + /* Clean up. */ + chaz_Lib_destroy(shared_lib); + chaz_MakeFile_destroy(makefile); + free(shared_lib_filename); + free(test_exe); +} + +static void +S_c_file_callback(const char *dir, char *file, void *context) { + SourceFileContext *sfc = (SourceFileContext*)context; + const char *dir_sep = chaz_OS_dir_sep(); + const char *obj_ext = chaz_CC_obj_ext(); + size_t file_len = strlen(file); + char *obj_file; + + /* Strip extension */ + if (!S_ends_with(file, ".c")) { + chaz_Util_die("Unexpected C filename: %s", file); + } + file[file_len-2] = '\0'; + + obj_file = chaz_Util_join("", "src", dir_sep, file, obj_ext, NULL); + chaz_MakeVar_append(sfc->var, obj_file); + free(obj_file); +} + +static int +S_ends_with(const char *string, const char *postfix) { + size_t len = strlen(string); + size_t postfix_len = strlen(postfix); + return len >= postfix_len + && memcmp(string + len - postfix_len, postfix, postfix_len) == 0; +} + + http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/6adc7977/tests/configure ---------------------------------------------------------------------- diff --git a/tests/configure b/tests/configure new file mode 100755 index 0000000..ba1281f --- /dev/null +++ b/tests/configure @@ -0,0 +1,47 @@ +#!/bin/sh + +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. + +probe_clang() { clang -v; } +probe_gcc() { gcc -v; } + +if [ -z "$CC" ]; then + case $(uname) in + Darwin*) compilers="clang gcc";; + *) compilers="gcc clang";; + esac + + for compiler in $compilers; do + if probe_$compiler >/dev/null 2>&1; then + CC=$compiler + break + fi + done + + if [ -z "$CC" ]; then + CC=cc + fi +fi + +echo "Using C compiler '$CC'" + +command="$CC charmonizer.c -o charmonizer" +echo $command +$command || exit + +echo Running charmonizer +./charmonizer --cc=$CC --enable-c --enable-makefile "$@" + http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/6adc7977/tests/configure.bat ---------------------------------------------------------------------- diff --git a/tests/configure.bat b/tests/configure.bat new file mode 100644 index 0000000..cf65d36 --- /dev/null +++ b/tests/configure.bat @@ -0,0 +1,46 @@ +@echo off + +rem Licensed to the Apache Software Foundation (ASF) under one or more +rem contributor license agreements. See the NOTICE file distributed with +rem this work for additional information regarding copyright ownership. +rem The ASF licenses this file to You under the Apache License, Version 2.0 +rem (the "License"); you may not use this file except in compliance with +rem the License. You may obtain a copy of the License at +rem +rem http://www.apache.org/licenses/LICENSE-2.0 +rem +rem Unless required by applicable law or agreed to in writing, software +rem distributed under the License is distributed on an "AS IS" BASIS, +rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +rem See the License for the specific language governing permissions and +rem limitations under the License. + +setlocal +set CL= +cl >nul 2>nul +endlocal +if not errorlevel 1 goto found_cl + +gcc -v >nul 2>nul +if not errorlevel 1 goto found_gcc + +echo No C compiler found +exit /b 1 + +:found_cl +echo Using C compiler 'cl' +echo cl /nologo charmonizer.c +cl /nologo charmonizer.c +if errorlevel 1 exit /b 1 +echo Running charmonizer +charmonizer.exe --cc=cl --enable-c --enable-makefile %* +exit /b + +:found_gcc +echo Using C compiler 'gcc' +echo gcc charmonizer.c -o charmonizer.exe +gcc charmonizer.c -o charmonizer.exe +if errorlevel 1 exit /b 1 +echo Running charmonizer +charmonizer.exe --cc=gcc --enable-c --enable-makefile %* +exit /b http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/6adc7977/tests/src/Charmonizer/Test.c ---------------------------------------------------------------------- diff --git a/tests/src/Charmonizer/Test.c b/tests/src/Charmonizer/Test.c new file mode 100644 index 0000000..868375b --- /dev/null +++ b/tests/src/Charmonizer/Test.c @@ -0,0 +1,205 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "Charmonizer/Test.h" + +struct chaz_TestBatch { + unsigned test_num; + unsigned num_tests; + unsigned num_passed; + unsigned num_failed; + unsigned num_skipped; +}; + +chaz_TestBatch* +chaz_Test_current = NULL; + +void +chaz_Test_init(void) { + /* Unbuffer stdout. */ + int check_val = setvbuf(stdout, NULL, _IONBF, 0); + if (check_val != 0) { + fprintf(stderr, "Failed when trying to unbuffer stdout\n"); + } +} + +chaz_TestBatch* +chaz_Test_new_batch(unsigned num_tests) { + chaz_TestBatch *batch = (chaz_TestBatch*)malloc(sizeof(chaz_TestBatch)); + if (!batch) { + fprintf(stderr, "Out of memory\n"); + return NULL; + } + + /* Assign. */ + batch->num_tests = num_tests; + + /* Initialize. */ + batch->test_num = 0; + batch->num_passed = 0; + batch->num_failed = 0; + batch->num_skipped = 0; + + return batch; +} + +chaz_TestBatch* +chaz_Test_start(unsigned num_tests) { + if (chaz_Test_current) { + fprintf(stderr, "Already started testing\n"); + return NULL; + } + chaz_Test_init(); + chaz_Test_current = chaz_Test_new_batch(num_tests); + CHAZ_TEST_PLAN(chaz_Test_current); + return chaz_Test_current; +} + +int +chaz_Test_finish(void) { + int remainder = chaz_Test_current->num_tests + - chaz_Test_current->num_passed + - chaz_Test_current->num_skipped; + free(chaz_Test_current); + chaz_Test_current = NULL; + return !remainder; +} + +void +chaz_Test_plan(chaz_TestBatch *batch) { + printf("1..%u\n", batch->num_tests); +} + +void +chaz_Test_ok(chaz_TestBatch *batch, int value, const char *message) { + /* Increment test number. */ + batch->test_num++; + + /* Test condition and pass or fail. */ + if (value) { + printf("ok %u - %s\n", batch->test_num, message); + batch->num_passed++; + } + else { + printf("not ok %u - %s\n", batch->test_num, message); + batch->num_failed++; + } +} + +void +chaz_Test_str_eq(chaz_TestBatch *batch, const char *got, + const char *expected, const char *message) { + /* Increment test number. */ + batch->test_num++; + + /* Test condition and pass or fail. */ + if (strcmp(expected, got) == 0) { + printf("ok %u - %s\n", batch->test_num, message); + batch->num_passed++; + } + else { + printf("not ok %u - Expected '%s', got '%s'\n # %s\n", + batch->test_num, expected, got, message); + batch->num_failed++; + } +} + + +void +chaz_Test_pass(chaz_TestBatch *batch, const char *message) { + /* Increment test number. */ + batch->test_num++; + + /* Indicate pass, update pass counter. */ + printf("ok %u - %s\n", batch->test_num, message); + batch->num_passed++; +} + +void +chaz_Test_fail(chaz_TestBatch *batch, const char *message) { + /* Increment test number. */ + batch->test_num++; + + /* Indicate failure, update pass counter. */ + printf("not ok %u - %s\n", batch->test_num, message); + batch->num_failed++; +} + +void +chaz_Test_long_eq(chaz_TestBatch *batch, long got, long expected, + const char *message) { + /* Increment test number. */ + batch->test_num++; + + if (expected == got) { + printf("ok %u - %s\n", batch->test_num, message); + batch->num_passed++; + } + else { + printf("not ok %u - Expected '%ld', got '%ld'\n # %s", + batch->test_num, expected, got, message); + batch->num_failed++; + } +} + +void +chaz_Test_double_eq(chaz_TestBatch *batch, double got, double expected, + double slop, const char *message) { + double diff = expected - got; + if (diff < 0) { + diff = 0 - diff; + } + + /* Increment test number. */ + batch->test_num++; + + /* Evaluate condition and pass or fail. */ + if (diff < slop) { + printf("ok %u - %s\n", batch->test_num, message); + batch->num_passed++; + } + else { + printf("not ok %u - Expected '%f', got '%f'\n # %s\n", + batch->test_num, expected, got, message); + batch->num_failed++; + } +} + +void +chaz_Test_skip(chaz_TestBatch *batch, const char *message) { + /* Increment test number. */ + batch->test_num++; + + /* Indicate that test is being skipped, update pass counter. */ + printf("ok %u # SKIP %s\n", batch->test_num, message); + batch->num_skipped++; +} + +void +chaz_Test_skip_remaining(chaz_TestBatch *batch, const char *message) { + unsigned remaining = batch->num_tests - batch->test_num; + + /* Indicate that tests are being skipped, update skip counter. */ + printf("# Skipping all %u remaining tests: %s\n", remaining, message); + while (batch->test_num < batch->num_tests) { + chaz_Test_skip(batch, ""); + } +} + + http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/6adc7977/tests/src/Charmonizer/Test.h ---------------------------------------------------------------------- diff --git a/tests/src/Charmonizer/Test.h b/tests/src/Charmonizer/Test.h new file mode 100644 index 0000000..c53b981 --- /dev/null +++ b/tests/src/Charmonizer/Test.h @@ -0,0 +1,160 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +/* Charmonizer/Test.h - test Charmonizer's output. + */ + +#ifndef H_CHAZ_TEST +#define H_CHAZ_TEST + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef true + #define true 1 + #define false 0 +#endif + +typedef struct chaz_TestBatch chaz_TestBatch; + +/* Test functions. + */ +int +chaz_Test_test_dir_manip(void); +int +chaz_Test_test_func_macro(void); +int +chaz_Test_test_headers(void); +int +chaz_Test_test_integers(void); +int +chaz_Test_test_large_files(void); +int +chaz_Test_test_unused_vars(void); +int +chaz_Test_test_variadic_macros(void); + +/* Begin a test run. + */ +chaz_TestBatch* +chaz_Test_start(unsigned num_tests); + +/* End a test run. Returns true if all tests were run and there were no + * failures, false otherwise. + */ +int +chaz_Test_finish(void); + +/* Unbuffer stdout. Perform any other setup needed. + */ +void +chaz_Test_init(void); + +/* Constructor for TestBatch. + */ +chaz_TestBatch* +chaz_Test_new_batch(unsigned num_tests); + +#define CHAZ_TEST_PLAN chaz_Test_plan +void +chaz_Test_plan(chaz_TestBatch *batch); + +#define CHAZ_TEST_OK(_expression, _message) \ + chaz_Test_ok(chaz_Test_current, (_expression), (_message)) +void +chaz_Test_ok(chaz_TestBatch *batch, int expression, const char *message); + +#define CHAZ_TEST_STR_EQ(_got, _expected, _message) \ + chaz_Test_str_eq(chaz_Test_current, (_got), (_expected), (_message)) +void +chaz_Test_str_eq(chaz_TestBatch *batch, const char *got, + const char *expected, const char *message); + +#define CHAZ_TEST_PASS(_message) \ + chaz_Test_pass(chaz_Test_current, (_message)) +void +chaz_Test_pass(chaz_TestBatch *batch, const char *message); + +#define CHAZ_TEST_FAIL(_message) \ + chaz_Test_fail(chaz_Test_current, (_message)) +void +chaz_Test_fail(chaz_TestBatch *batch, const char *message); + +#define CHAZ_TEST_LONG_EQ(_got, _expected, _message) \ + chaz_Test_long_eq(chaz_Test_current, (_got), (_expected), (_message)) +void +chaz_Test_long_eq(chaz_TestBatch *batch, long got, long expected, + const char *message); + +#define CHAZ_TEST_DOUBLE_EQ(_got, _expected, _slop, _message) \ + chaz_Test_double_eq(chaz_Test_current, (_got), (_expected), (_slop), \ + (_message)) +void +chaz_Test_double_eq(chaz_TestBatch *batch, double got, double expected, + double slop, const char *message); + +/* Print a message indicating that a test was skipped and update batch. + */ +#define CHAZ_TEST_SKIP(_message) \ + chaz_Test_skip(chaz_Test_current, (_message)) +void +chaz_Test_skip(chaz_TestBatch *batch, const char *message); + +/* Print a message indicating that all remaining tests will be skipped and + * then call SKIP once for each. + */ +#define CHAZ_TEST_SKIP_REMAINING(_message) \ + chaz_Test_skip_remaining(chaz_Test_current, (_message)) +void +chaz_Test_skip_remaining(chaz_TestBatch* batch, const char *message); + +/* Global TestBatch implicitly accessed by testing macros. */ +extern chaz_TestBatch *chaz_Test_current; + +#ifdef CHAZ_USE_SHORT_NAMES + #define Test_start chaz_Test_start + #define Test_finish chaz_Test_finish + #define OK CHAZ_TEST_OK + #define STR_EQ CHAZ_TEST_STR_EQ + #define LONG_EQ CHAZ_TEST_LONG_EQ + #define DOUBLE_EQ CHAZ_TEST_DOUBLE_EQ + #define PASS CHAZ_TEST_PASS + #define FAIL CHAZ_TEST_FAIL + #define SKIP CHAZ_TEST_SKIP + #define SKIP_REMAINING CHAZ_TEST_SKIP_REMAINING + #define TestBatch chaz_TestBatch + #define Test_init chaz_Test_init + #define Test_new_batch chaz_Test_new_batch + #define Test_plan chaz_Test_plan + #define PLAN CHAZ_TEST_PLAN + #define Test_str_eq chaz_Test_str_eq + #define Test_long_eq chaz_Test_long_eq + #define Test_double_eq chaz_Test_double_eq + #define Test_pass chaz_Test_pass + #define Test_fail chaz_Test_fail + #define Test_skip chaz_Test_skip + #define Test_skip_remaining chaz_Test_skip_remaining +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* H_CHAZ_TEST */ + + + http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/6adc7977/tests/src/Charmonizer/Test/TestDirManip.c ---------------------------------------------------------------------- diff --git a/tests/src/Charmonizer/Test/TestDirManip.c b/tests/src/Charmonizer/Test/TestDirManip.c new file mode 100644 index 0000000..445b70e --- /dev/null +++ b/tests/src/Charmonizer/Test/TestDirManip.c @@ -0,0 +1,72 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +#define CHAZ_USE_SHORT_NAMES + +#include "Charmonizer/Test.h" +#include <stdio.h> +#include <string.h> +#include "charmony.h" +#ifdef HAS_DIRENT_H + #include <dirent.h> +#endif +#ifdef HAS_SYS_STAT_H + #include <sys/stat.h> +#endif +#ifdef HAS_SYS_TYPES_H + #include <sys/stat.h> +#endif +#ifdef HAS_UNISTD_H + #include <unistd.h> +#endif +#ifdef HAS_DIRECT_H + #include <direct.h> +#endif + +static void +S_run_tests(void) { + LONG_EQ(0, makedir("_chaz_test_dir", 0777), "makedir"); + LONG_EQ(0, makedir("_chaz_test_dir" DIR_SEP "deep", 0777), + "makedir with DIR_SEP"); + LONG_EQ(0, rmdir("_chaz_test_dir" DIR_SEP "deep"), "rmdir with DIR_SEP"); + LONG_EQ(0, rmdir("_chaz_test_dir"), "rmdir"); +#ifdef CHY_HAS_DIRENT_D_NAMLEN + { + struct dirent entry; + entry.d_namlen = 5; + LONG_EQ(5, entry.d_namlen, "d_namlen"); + } +#else + SKIP("no d_namlen member on this platform"); +#endif +#ifdef CHY_HAS_DIRENT_D_TYPE + { + struct dirent entry; + entry.d_type = 5; + LONG_EQ(5, entry.d_type, "d_type"); + } +#else + SKIP("no d_type member on this platform"); +#endif +} + +int +chaz_Test_test_dir_manip() { + Test_start(6); + S_run_tests(); + return Test_finish(); +} + http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/6adc7977/tests/src/Charmonizer/Test/TestFuncMacro.c ---------------------------------------------------------------------- diff --git a/tests/src/Charmonizer/Test/TestFuncMacro.c b/tests/src/Charmonizer/Test/TestFuncMacro.c new file mode 100644 index 0000000..c51142e --- /dev/null +++ b/tests/src/Charmonizer/Test/TestFuncMacro.c @@ -0,0 +1,64 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +#define CHAZ_USE_SHORT_NAMES + +#include "charmony.h" +#include <string.h> +#include "Charmonizer/Test.h" + +#ifdef INLINE +static INLINE const char* S_inline_function() { + return "inline works"; +} +#endif + +static void +S_run_tests(void) { + +#ifdef HAS_FUNC_MACRO + STR_EQ(FUNC_MACRO, "S_run_tests", "FUNC_MACRO"); +#else + SKIP("no FUNC_MACRO"); +#endif + +#ifdef HAS_ISO_FUNC_MACRO + STR_EQ(__func__, "S_run_tests", "HAS_ISO_FUNC_MACRO"); +#else + SKIP("no ISO_FUNC_MACRO"); +#endif + +#ifdef HAS_GNUC_FUNC_MACRO + STR_EQ(__FUNCTION__, "S_run_tests", "HAS_GNUC_FUNC_MACRO"); +#else + SKIP("no GNUC_FUNC_MACRO"); +#endif + +#ifdef INLINE + PASS(S_inline_function()); +#else + SKIP("no INLINE functions"); +#endif +} + + +int +chaz_Test_test_func_macro() { + Test_start(4); + S_run_tests(); + return Test_finish(); +} + http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/6adc7977/tests/src/Charmonizer/Test/TestHeaders.c ---------------------------------------------------------------------- diff --git a/tests/src/Charmonizer/Test/TestHeaders.c b/tests/src/Charmonizer/Test/TestHeaders.c new file mode 100644 index 0000000..b2bae35 --- /dev/null +++ b/tests/src/Charmonizer/Test/TestHeaders.c @@ -0,0 +1,165 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +#define CHAZ_USE_SHORT_NAMES + +#include "charmony.h" +#include <string.h> +#include "Charmonizer/Test.h" + +#ifdef HAS_ASSERT_H + #include <assert.h> +#endif +#ifdef HAS_CTYPE_H + #include <ctype.h> +#endif +#ifdef HAS_ERRNO_H + #include <errno.h> +#endif +#ifdef HAS_FLOAT_H + #include <float.h> +#endif +#ifdef HAS_LIMITS_H + #include <limits.h> +#endif +#ifdef HAS_LOCALE_H + #include <locale.h> +#endif +#ifdef HAS_MATH_H + #include <math.h> +#endif +#ifdef HAS_SETJMP_H + #include <setjmp.h> +#endif +#ifdef HAS_SIGNAL_H + #include <signal.h> +#endif +#ifdef HAS_STDARG_H + #include <stdarg.h> +#endif +#ifdef HAS_STDDEF_H + #include <stddef.h> +#endif +#ifdef HAS_STDIO_H + #include <stdio.h> +#endif +#ifdef HAS_STDLIB_H + #include <stdlib.h> +#endif +#ifdef HAS_STRING_H + #include <string.h> +#endif +#ifdef HAS_TIME_H + #include <time.h> +#endif + +#ifdef HAS_CPIO_H + #include <cpio.h> +#endif +#ifdef HAS_DIRENT_H + #include <dirent.h> +#endif +#ifdef HAS_FCNTL_H + #include <fcntl.h> +#endif +#ifdef HAS_GRP_H + #include <grp.h> +#endif +#ifdef HAS_PWD_H + #include <pwd.h> +#endif +#ifdef HAS_SYS_STAT_H + #include <sys/stat.h> +#endif +#ifdef HAS_SYS_TIMES_H + #include <sys/times.h> +#endif +#ifdef HAS_SYS_TYPES_H + #include <sys/types.h> +#endif +#ifdef HAS_SYS_UTSNAME_H + #include <sys/utsname.h> +#endif +#ifdef HAS_WAIT_H + #include <wait.h> +#endif +#ifdef HAS_TAR_H + #include <tar.h> +#endif +#ifdef HAS_TERMIOS_H + #include <termios.h> +#endif +#ifdef HAS_UNISTD_H + #include <unistd.h> +#endif +#ifdef HAS_UTIME_H + #include <utime.h> +#endif + +#if defined(HAS_C89) || defined(HAS_C90) + #include <assert.h> + #include <ctype.h> + #include <errno.h> + #include <float.h> + #include <limits.h> + #include <locale.h> + #include <math.h> + #include <setjmp.h> + #include <signal.h> + #include <stdarg.h> + #include <stddef.h> + #include <stdio.h> + #include <stdlib.h> + #include <string.h> + #include <time.h> +#endif + +#ifdef HAS_POSIX + #include <cpio.h> + #include <dirent.h> + #include <fcntl.h> + #include <grp.h> + #include <pwd.h> + #include <sys/stat.h> + #include <sys/times.h> + #include <sys/types.h> + #include <sys/utsname.h> + #include <sys/wait.h> + #include <tar.h> + #include <termios.h> + #include <unistd.h> + #include <utime.h> +#endif + +static void +S_run_tests(void) { + PASS("Compiled successfully with all detected headers"); + + /* Don't bother checking all -- just use stdio as an example. */ +#ifdef HAS_STDIO_H + PASS("stdio.h should have been detected"); +#else + FAIL("stdio.h should have been detected"); +#endif +} + +int +chaz_Test_test_headers() { + Test_start(2); + S_run_tests(); + return Test_finish(); +} + http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/6adc7977/tests/src/Charmonizer/Test/TestIntegers.c ---------------------------------------------------------------------- diff --git a/tests/src/Charmonizer/Test/TestIntegers.c b/tests/src/Charmonizer/Test/TestIntegers.c new file mode 100644 index 0000000..9ffb370 --- /dev/null +++ b/tests/src/Charmonizer/Test/TestIntegers.c @@ -0,0 +1,128 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +#define CHAZ_USE_SHORT_NAMES +#define CHY_EMPLOY_BOOLEANS +#define CHY_EMPLOY_INTEGERTYPES +#define CHY_EMPLOY_INTEGERLITERALS +#define CHY_EMPLOY_INTEGERFORMATSTRINGS + +#include "Charmonizer/Test.h" +#include "charmony.h" +#include <stdio.h> +#include <string.h> + +static void +S_run_tests(TestBatch *batch) { + { + long one = 1; + long big_endian = !(*((char *)(&one))); +#ifdef BIG_END + OK(big_endian, "BIG_END"); +#else + #if defined(LITTLE_END) + OK(!big_endian, "LITTLE_END"); + #else + FAIL("Either BIG_END or LITTLE_END should be defined"); + #endif +#endif + } + + LONG_EQ(SIZEOF_CHAR, sizeof(char), "SIZEOF_CHAR"); + LONG_EQ(SIZEOF_SHORT, sizeof(short), "SIZEOF_SHORT"); + LONG_EQ(SIZEOF_INT, sizeof(int), "SIZEOF_INT"); + LONG_EQ(SIZEOF_LONG, sizeof(long), "SIZEOF_LONG"); + LONG_EQ(SIZEOF_PTR, sizeof(void*), "SIZEOF_PTR"); + +#ifdef HAS_LONG_LONG + LONG_EQ(SIZEOF_LONG_LONG, sizeof(long long), + "HAS_LONG_LONG and SIZEOF_LONG_LONG"); +#else + SKIP("No 'long long' type"); +#endif + + { + bool the_truth = true; + OK(the_truth, "bool true"); + OK(!false, "false is false"); + } +#ifdef HAS_INT8_T + { + int8_t foo = -100; + uint8_t bar = 200; + LONG_EQ(foo, -100, "int8_t is signed"); + LONG_EQ(bar, 200, "uint8_t is unsigned"); + LONG_EQ(sizeof(int8_t), 1, "i8_t is 1 byte"); + LONG_EQ(sizeof(uint8_t), 1, "u8_t is 1 byte"); + LONG_EQ(INT8_MAX, 127, "INT8_MAX"); + LONG_EQ(INT8_MIN, -128, "INT8_MIN"); + LONG_EQ(UINT8_MAX, 255, "UINT8_MAX"); + } +#endif +#ifdef HAS_INT16_T + { + int16_t foo = -100; + uint16_t bar = 30000; + LONG_EQ(foo, -100, "int16_t is signed"); + LONG_EQ(bar, 30000, "uint16_t is unsigned"); + LONG_EQ(sizeof(int16_t), 2, "int16_t is 2 bytes"); + LONG_EQ(sizeof(uint16_t), 2, "uint16_t is 2 bytes"); + LONG_EQ(INT16_MAX, 32767, "INT16_MAX"); + LONG_EQ(INT16_MIN, -32768, "INT16_MIN"); + LONG_EQ(UINT16_MAX, 65535, "UINT16_MAX"); + } +#endif +#ifdef HAS_INT32_T + { + int32_t foo = -100; + uint32_t bar = 4000000000UL; + OK((foo == -100), "int32_t is signed"); + OK((bar == 4000000000UL), "uint32_t is unsigned"); + OK((sizeof(int32_t) == 4), "int32_t is 4 bytes"); + OK((sizeof(uint32_t) == 4), "uint32_t is 4 bytes"); + OK((INT32_MAX == INT32_C(2147483647)), "INT32_MAX"); + /* The (-2147483647 - 1) avoids a compiler warning. */ + OK((INT32_MIN == -INT32_C(2147483647) - 1), "INT32_MIN"); + OK((UINT32_MAX == UINT32_C(4294967295)), "UINT32_MAX"); + } +#endif +#ifdef HAS_INT64_T + { + char buf[100]; + int64_t foo = -100; + uint64_t bar = UINT64_C(18000000000000000000); + OK((foo == -100), "int64_t is signed"); + OK((bar == UINT64_C(18000000000000000000)), "uint64_t is unsigned"); + OK((sizeof(int64_t) == 8), "int64_t is 8 bytes"); + OK((sizeof(uint64_t) == 8), "uint64_t is 8 bytes"); + OK((INT64_MAX == INT64_C(0x7FFFFFFFFFFFFFFF)), "INT64_MAX"); + OK((INT64_MIN == -INT64_C(0x7FFFFFFFFFFFFFFF) - 1), "INT64_MIN"); + OK((UINT64_MAX == UINT64_C(0xFFFFFFFFFFFFFFFF)), "UINT64_MAX"); + sprintf(buf, "%"PRId64, foo); + STR_EQ(buf, "-100", "PRId64"); + sprintf(buf, "%"PRIu64, bar); + STR_EQ(buf, "18000000000000000000", "PRIu64"); + } +#endif +} + +int +chaz_Test_test_integers() { + TestBatch *batch = Test_start(39); + S_run_tests(batch); + return Test_finish(); +} + http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/6adc7977/tests/src/Charmonizer/Test/TestLargeFiles.c ---------------------------------------------------------------------- diff --git a/tests/src/Charmonizer/Test/TestLargeFiles.c b/tests/src/Charmonizer/Test/TestLargeFiles.c new file mode 100644 index 0000000..c914e85 --- /dev/null +++ b/tests/src/Charmonizer/Test/TestLargeFiles.c @@ -0,0 +1,282 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +#define CHAZ_USE_SHORT_NAMES +#define CHY_EMPLOY_INTEGERLITERALS + +#include "charmony.h" +#include <string.h> +#include <errno.h> + +#ifdef CHAZ_HAS_SYS_TYPES_H + #include <sys/types.h> +#endif +#ifdef CHAZ_HAS_FCNTL_H + #include <fcntl.h> /* open, fcntl flags */ +#endif +#ifdef CHY_HAS_UNISTD_H + #include <unistd.h> /* close */ +#endif +#ifdef CHAZ_HAS_IO_H + #include <io.h> +#endif + +#include <stdio.h> +#include "Charmonizer/Test.h" + +#if (defined(HAS_64BIT_STDIO) \ + && defined(CHAZ_HAS_STAT_ST_SIZE) \ + && defined(CHAZ_HAS_STAT_ST_BLOCKS)) +#define STAT_TESTS_ENABLED + +#include <sys/stat.h> + +/* Determine whether we can use sparse files. + */ +static int +S_check_sparse_files(void); + +/* Helper for check_sparse_files(). + */ +static int +S_test_sparse_file(long offset, struct stat *st); + +/* See if trying to write a 5 GB file in a subprocess bombs out. If it + * doesn't, then the test suite can safely verify large file support. + */ +static int +S_can_create_big_files(void); + +#endif /* criteria for defining STAT_TESTS_ENABLED */ + +#ifdef O_LARGEFILE + #define LARGEFILE_OPEN_FLAG O_LARGEFILE +#else + #define LARGEFILE_OPEN_FLAG 0 +#endif + +static void +S_run_tests(void) { + FILE *fh; + off64_t offset; + int check_val; + char check_char; + int fd; + + /* A little over 4 GB, and a little over 2 GB. */ + off64_t gb4_plus = ((off64_t)0x7FFFFFFF << 1) + 100; + off64_t gb2_plus = (off64_t)0x7FFFFFFF + 200; + + LONG_EQ(sizeof(off64_t), 8, "off64_t type has 8 bytes"); + +#ifndef HAS_64BIT_STDIO + SKIP_REMAINING("No stdio large file support"); + return; +#endif +#ifndef STAT_TESTS_ENABLED + SKIP_REMAINING("Need stat with st_size and st_blocks"); + return; +#else + /* Check for sparse files. */ + if (!S_check_sparse_files()) { + SKIP_REMAINING("Can't verify large file support " + "without sparse files"); + return; + } + if (!S_can_create_big_files()) { + SKIP_REMAINING("Unsafe to create 5GB sparse files on this system"); + return; + } + + fh = fopen64("_charm_large_file_test", "w+"); + if (fh == NULL) { + SKIP_REMAINING("Failed to open file"); + return; + } + + check_val = fseeko64(fh, gb4_plus, SEEK_SET); + LONG_EQ(check_val, 0, "fseeko64 above 4 GB"); + + offset = ftello64(fh); + OK((offset == gb4_plus), "ftello64 above 4 GB"); + + check_val = fprintf(fh, "X"); + LONG_EQ(check_val, 1, "print above 4 GB"); + + check_val = fseeko64(fh, gb2_plus, SEEK_SET); + LONG_EQ(check_val, 0, "fseeko64 above 2 GB"); + + offset = ftello64(fh); + OK((offset == gb2_plus), "ftello64 above 2 GB"); + + check_val = fseeko64(fh, -1, SEEK_END); + LONG_EQ(check_val, 0, "seek to near end"); + + check_char = fgetc(fh); + LONG_EQ(check_char, 'X', "read value after multiple seeks"); + + check_val = fclose(fh); + LONG_EQ(check_val, 0, "fclose succeeds after all that"); + + /* Truncate, just in case the call to remove fails. */ + fh = fopen64("_charm_large_file_test", "w+"); + if (fh != NULL) { + fclose(fh); + } + remove("_charm_large_file_test"); + +#ifndef HAS_64BIT_LSEEK + SKIP_REMAINING("No 64-bit lseek"); + return; +#else + fd = open("_charm_large_file_test", + O_RDWR | O_CREAT | LARGEFILE_OPEN_FLAG, 0666); + if (fd == -1) { + FAIL("open failed"); + SKIP_REMAINING("open failed"); + return; + } + + offset = lseek64(fd, gb4_plus, SEEK_SET); + OK(offset == gb4_plus, "lseek64 above 4 GB"); + + offset = lseek64(fd, 0, SEEK_CUR); + OK(offset == gb4_plus, "lseek64 in place above 4 GB"); + + check_val = write(fd, "X", 1); + LONG_EQ(check_val, 1, "write() above 4 GB"); + + offset = lseek64(fd, gb2_plus, SEEK_SET); + OK(offset == gb2_plus, "lseek64 above 2 GB"); + + offset = lseek64(fd, 0, SEEK_CUR); + OK((offset == gb2_plus), "lseek64 in place above 2 GB"); + + offset = lseek64(fd, -1, SEEK_END); + OK(offset == gb4_plus, "seek to near end"); + + check_val = read(fd, &check_char, 1); + LONG_EQ(check_val, 1, "read() after multiple lseek64 calls"); + LONG_EQ(check_char, 'X', + "read() correct data after multiple lseek64 calls"); +#ifdef HAS_64BIT_PREAD + check_char = 0; + check_val = pread64(fd, &check_char, 1, gb4_plus); + LONG_EQ(check_val, 1, "pread64"); + LONG_EQ(check_char, 'X', "pread64() correct data"); +#else + SKIP("no pread64"); + SKIP("no pread64"); +#endif + + check_val = close(fd); + LONG_EQ(check_val, 0, "close succeeds after all that"); +#endif + + /* Truncate, just in case the call to remove fails. */ + fh = fopen64("_charm_large_file_test", "w+"); + if (fh != NULL) { + fclose(fh); + } + remove("_charm_large_file_test"); +#endif /* STAT_TESTS_ENABLED */ +} + +#ifdef STAT_TESTS_ENABLED + +static int +S_check_sparse_files(void) { + struct stat st_a, st_b; + + /* Write and stat a 1 MB file and a 2 MB file, both of them sparse. */ + if (!S_test_sparse_file(1000000, &st_a)) { return false; } + if (!S_test_sparse_file(2000000, &st_b)) { return false; } + if (st_a.st_size != 1000001 || st_b.st_size != 2000001) { + return false; + } + + /* See if two files with very different lengths have the same block size. */ + return st_a.st_blocks == st_b.st_blocks ? true : false; +} + +static int +S_test_sparse_file(long offset, struct stat *st) { + FILE *sparse_fh; + int result = false; + + /* Make sure the file's not there, then open. */ + remove("_charm_sparse"); + if ((sparse_fh = fopen64("_charm_sparse", "w+")) == NULL) { + return false; + } + + /* Seek fh to [offset], write a byte, close file. */ + if ((fseeko64(sparse_fh, offset, SEEK_SET)) != -1) { + if ((fprintf(sparse_fh, "X")) == 1) { + result = true; + } + } + if (fclose(sparse_fh)) { + result = false; + } + + /* Stat the file. */ + stat("_charm_sparse", st); + + remove("_charm_sparse"); + return result; +} + +static int +S_can_create_big_files(void) { + int result = 0; + FILE *fh = fopen64("_charm_large_file_test", "w+"); + if (!fh) { + return false; + } + else { + /* Bail unless seek succeeds. */ + int64_t check_seek = fseeko64(fh, INT64_C(5000000000), SEEK_SET); + if (check_seek != -1) { + /* Bail unless we write successfully. */ + if (fprintf(fh, "X") == 1) { + result = true; + } + } + if (fclose(fh)) { + result = false; + } + } + + /* Truncate, just in case the call to remove fails. */ + fh = fopen64("_charm_large_file_test", "w"); + if (fh != NULL) { + fclose(fh); + } + remove("_charm_large_file_test"); + + return result; +} + +#endif /* STAT_TESTS_ENABLED */ + +int +chaz_Test_test_large_files() { + Test_start(20); + S_run_tests(); + return Test_finish(); +} + http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/6adc7977/tests/src/Charmonizer/Test/TestUnusedVars.c ---------------------------------------------------------------------- diff --git a/tests/src/Charmonizer/Test/TestUnusedVars.c b/tests/src/Charmonizer/Test/TestUnusedVars.c new file mode 100644 index 0000000..5325427 --- /dev/null +++ b/tests/src/Charmonizer/Test/TestUnusedVars.c @@ -0,0 +1,43 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +#define CHAZ_USE_SHORT_NAMES + +#include "charmony.h" +#include "Charmonizer/Test.h" + +static void +S_run_tests(void) { +#ifdef UNUSED_VAR + PASS("UNUSED_VAR macro is defined"); +#else + FAIL("UNUSED_VAR macro is defined"); +#endif + +#ifdef UNREACHABLE_RETURN + PASS("UNREACHABLE_RETURN macro is defined"); +#else + FAIL("UNREACHABLE_RETURN macro is defined"); +#endif +} + +int +chaz_Test_test_unused_vars() { + Test_start(2); + S_run_tests(); + return Test_finish(); +} + http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/6adc7977/tests/src/Charmonizer/Test/TestVariadicMacros.c ---------------------------------------------------------------------- diff --git a/tests/src/Charmonizer/Test/TestVariadicMacros.c b/tests/src/Charmonizer/Test/TestVariadicMacros.c new file mode 100644 index 0000000..1fef323 --- /dev/null +++ b/tests/src/Charmonizer/Test/TestVariadicMacros.c @@ -0,0 +1,70 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +#define CHAZ_USE_SHORT_NAMES + +#include "charmony.h" +#include <string.h> +#include <stdio.h> +#include "Charmonizer/Test.h" + +static void +S_run_tests(void) { + char buf[10]; + int really_has_var_macs = false; + +#if defined(HAS_ISO_VARIADIC_MACROS) || defined(HAS_GNUC_VARIADIC_MACROS) + #ifdef HAS_VARIADIC_MACROS + PASS("#defines agree"); + #else + FAIL(0, "#defines agree"); + #endif +#else + SKIP_REMAINING("No variadic macro support"); + return; +#endif + + +#ifdef HAS_ISO_VARIADIC_MACROS + #define ISO_TEST(buffer, fmt, ...) \ + sprintf(buffer, fmt, __VA_ARGS__) + really_has_var_macs = true; + ISO_TEST(buf, "%s", "iso"); + STR_EQ(buf, "iso", "ISO variadic macros work"); +#else + SKIP("No ISO variadic macros"); +#endif + +#ifdef HAS_GNUC_VARIADIC_MACROS + #define GNU_TEST(buffer, fmt, args...) \ + sprintf(buffer, fmt, ##args ) + really_has_var_macs = true; + GNU_TEST(buf, "%s", "gnu"); + STR_EQ(buf, "gnu", "GNUC variadic macros work"); +#else + SKIP("No GNUC variadic macros"); +#endif + + OK(really_has_var_macs, "either ISO or GNUC"); +} + +int +chaz_Test_test_variadic_macros() { + Test_start(4); + S_run_tests(); + return Test_finish(); +} + http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/6adc7977/tests/tests/test.c ---------------------------------------------------------------------- diff --git a/tests/tests/test.c b/tests/tests/test.c new file mode 100644 index 0000000..2022db6 --- /dev/null +++ b/tests/tests/test.c @@ -0,0 +1,32 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +#include "Charmonizer/Test.h" + +int +main() { + int success = + chaz_Test_test_dir_manip() && + chaz_Test_test_func_macro() && + chaz_Test_test_headers() && + chaz_Test_test_integers() && + chaz_Test_test_large_files() && + chaz_Test_test_unused_vars() && + chaz_Test_test_variadic_macros(); + + return success ? 0 : 1; +} +
