├── .gitignore ├── .travis.yml ├── CMakeLists.txt ├── CONTRIBUTORS.md ├── LICENSE ├── Makefile ├── README.md ├── cJSON.c ├── cJSON.h ├── cJSONConfig.cmake.in ├── cJSONConfigVersion.cmake.in ├── cJSON_Utils.c ├── cJSON_Utils.h ├── demo.c ├── libcjson.pc.in ├── libcjson_utils.pc.in ├── make.sh ├── test.c ├── test_utils.c └── tests ├── CMakeLists.txt ├── common.c ├── common.h ├── inputs ├── test1 ├── test1.expected ├── test10 ├── test10.expected ├── test11 ├── test11.expected ├── test2 ├── test2.expected ├── test3 ├── test3.expected ├── test4 ├── test4.expected ├── test5 ├── test5.expected ├── test6 ├── test7 ├── test7.expected ├── test8 ├── test8.expected ├── test9 └── test9.expected ├── parse_array.c ├── parse_examples.c ├── parse_hex4.c ├── parse_number.c ├── parse_object.c ├── parse_string.c ├── parse_value.c └── unity ├── .gitattributes ├── .gitignore ├── .travis.yml ├── README.md ├── auto ├── colour_prompt.rb ├── colour_reporter.rb ├── generate_config.yml ├── generate_module.rb ├── generate_test_runner.rb ├── parseOutput.rb ├── stylize_as_junit.rb ├── test_file_filter.rb ├── type_sanitizer.rb ├── unity_test_summary.py ├── unity_test_summary.rb └── unity_to_junit.py ├── docs ├── UnityAssertionsCheatSheetSuitableforPrintingandPossiblyFraming.pdf ├── UnityAssertionsReference.pdf ├── UnityConfigurationGuide.pdf ├── UnityGettingStartedGuide.pdf ├── UnityHelperScriptsGuide.pdf └── license.txt ├── examples ├── example_1 │ ├── makefile │ ├── readme.txt │ ├── src │ │ ├── ProductionCode.c │ │ ├── ProductionCode.h │ │ ├── ProductionCode2.c │ │ └── ProductionCode2.h │ └── test │ │ ├── TestProductionCode.c │ │ ├── TestProductionCode2.c │ │ └── test_runners │ │ ├── TestProductionCode2_Runner.c │ │ └── TestProductionCode_Runner.c ├── example_2 │ ├── makefile │ ├── readme.txt │ ├── src │ │ ├── ProductionCode.c │ │ ├── ProductionCode.h │ │ ├── ProductionCode2.c │ │ └── ProductionCode2.h │ └── test │ │ ├── TestProductionCode.c │ │ ├── TestProductionCode2.c │ │ └── test_runners │ │ ├── TestProductionCode2_Runner.c │ │ ├── TestProductionCode_Runner.c │ │ └── all_tests.c ├── example_3 │ ├── helper │ │ ├── UnityHelper.c │ │ └── UnityHelper.h │ ├── rakefile.rb │ ├── rakefile_helper.rb │ ├── readme.txt │ ├── src │ │ ├── ProductionCode.c │ │ ├── ProductionCode.h │ │ ├── ProductionCode2.c │ │ └── ProductionCode2.h │ ├── target_gcc_32.yml │ └── test │ │ ├── TestProductionCode.c │ │ └── TestProductionCode2.c └── unity_config.h ├── extras ├── eclipse │ └── error_parsers.txt └── fixture │ ├── rakefile.rb │ ├── rakefile_helper.rb │ ├── readme.txt │ ├── src │ ├── unity_fixture.c │ ├── unity_fixture.h │ ├── unity_fixture_internals.h │ └── unity_fixture_malloc_overrides.h │ └── test │ ├── Makefile │ ├── main │ └── AllTests.c │ ├── template_fixture_tests.c │ ├── unity_fixture_Test.c │ ├── unity_fixture_TestRunner.c │ ├── unity_output_Spy.c │ └── unity_output_Spy.h ├── release ├── build.info └── version.info ├── src ├── unity.c ├── unity.h └── unity_internals.h └── test ├── Makefile ├── expectdata ├── testsample_cmd.c ├── testsample_def.c ├── testsample_head1.c ├── testsample_head1.h ├── testsample_mock_cmd.c ├── testsample_mock_def.c ├── testsample_mock_head1.c ├── testsample_mock_head1.h ├── testsample_mock_new1.c ├── testsample_mock_new2.c ├── testsample_mock_param.c ├── testsample_mock_run1.c ├── testsample_mock_run2.c ├── testsample_mock_yaml.c ├── testsample_new1.c ├── testsample_new2.c ├── testsample_param.c ├── testsample_run1.c ├── testsample_run2.c └── testsample_yaml.c ├── rakefile ├── rakefile_helper.rb ├── spec └── generate_module_existing_file_spec.rb ├── targets ├── clang_file.yml ├── clang_strict.yml ├── gcc_32.yml ├── gcc_64.yml ├── gcc_auto_limits.yml ├── gcc_auto_stdint.yml ├── gcc_manual_math.yml ├── hitech_picc18.yml ├── iar_arm_v4.yml ├── iar_arm_v5.yml ├── iar_arm_v5_3.yml ├── iar_armcortex_LM3S9B92_v5_4.yml ├── iar_cortexm3_v5.yml ├── iar_msp430.yml └── iar_sh2a_v6.yml ├── testdata ├── CException.h ├── Defs.h ├── cmock.h ├── mockMock.h ├── testRunnerGenerator.c ├── testRunnerGeneratorSmall.c └── testRunnerGeneratorWithMocks.c └── tests ├── test_generate_test_runner.rb ├── testparameterized.c └── testunity.c /.gitignore: -------------------------------------------------------------------------------- 1 | .svn 2 | test 3 | *.o 4 | *.a 5 | *.so 6 | *.swp 7 | *.patch 8 | tags 9 | *.dylib 10 | build/ 11 | cJSON_test 12 | cJSON_test_utils 13 | libcjson.so.* 14 | libcjson_utils.so.* 15 | *.orig 16 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | dist: trusty 2 | sudo: false 3 | language: c 4 | env: 5 | matrix: 6 | - VALGRIND=On SANITIZERS=Off 7 | - VALGRIND=Off SANITIZERS=Off 8 | - VALGRIND=Off SANITIZERS=On 9 | compiler: 10 | - gcc 11 | - clang 12 | addons: 13 | apt: 14 | packages: 15 | - valgrind 16 | - libasan0 17 | - lib32asan0 18 | # currently not supported on travis: 19 | # - libasan1 20 | # - libasan2 21 | # - libubsan0 22 | - llvm 23 | script: 24 | - mkdir build 25 | - cd build 26 | - cmake .. -DENABLE_CJSON_UTILS=On -DENABLE_VALGRIND="${VALGRIND}" -DENABLE_SANITIZERS="${SANITIZERS}" 27 | - make 28 | - make test CTEST_OUTPUT_ON_FAILURE=On 29 | -------------------------------------------------------------------------------- /CONTRIBUTORS.md: -------------------------------------------------------------------------------- 1 | Contributors 2 | ============ 3 | 4 | * [Ajay Bhargav](https://github.com/ajaybhargav) 5 | * [Alper Akcan](https://github.com/alperakcan) 6 | * [Anton Sergeev](https://github.com/anton-sergeev) 7 | * [Christian Schulze](https://github.com/ChristianSch) 8 | * [Dave Gamble](https://github.com/DaveGamble) 9 | * [dieyushi](https://github.com/dieyushi) 10 | * [Dongwen Huang (黄东文)](https://github.com/DongwenHuang) 11 | * Eswar Yaganti 12 | * [Evan Todd](https://github.com/etodd) 13 | * [Fabrice Fontaine](https://github.com/ffontaine) 14 | * Ian Mobley 15 | * Irwan Djadjadi 16 | * [IvanVoid](https://github.com/npi3pak) 17 | * [Jiri Zouhar](https://github.com/loigu) 18 | * [Jonathan Fether](https://github.com/jfether) 19 | * [Kevin Branigan](https://github.com/kbranigan) 20 | * [Kyle Chisholm](https://github.com/ChisholmKyle) 21 | * [Linus Wallgren](https://github.com/ecksun) 22 | * [Max Bruckner](https://github.com/FSMaxB) 23 | * Mike Pontillo 24 | * Paulo Antonio Alvarez 25 | * [Rafael Leal Dias](https://github.com/rafaeldias) 26 | * [Rod Vagg](https://github.com/rvagg) 27 | * [Roland Meertens](https://github.com/rmeertens) 28 | * [Romain Porte](https://github.com/MicroJoe) 29 | * [Stephan Gatzka](https://github.com/gatzka) 30 | * [Weston Schmidt](https://github.com/schmidtw) 31 | 32 | And probably more people on [SourceForge](https://sourceforge.net/p/cjson/bugs/search/?q=status%3Aclosed-rejected+or+status%3Aclosed-out-of-date+or+status%3Awont-fix+or+status%3Aclosed-fixed+or+status%3Aclosed&page=0) 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 Dave Gamble 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | 21 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | CJSON_OBJ = cJSON.o 2 | UTILS_OBJ = cJSON_Utils.o 3 | CJSON_LIBNAME = libcjson 4 | UTILS_LIBNAME = libcjson_utils 5 | CJSON_TEST = cJSON_test 6 | UTILS_TEST = cJSON_test_utils 7 | 8 | CJSON_TEST_SRC = cJSON.c test.c 9 | UTILS_TEST_SRC = cJSON.c cJSON_Utils.c test_utils.c 10 | 11 | LDLIBS = -lm 12 | 13 | LIBVERSION = 1.3.2 14 | CJSON_SOVERSION = 1 15 | UTILS_SOVERSION = 1 16 | 17 | PREFIX ?= /usr/local 18 | INCLUDE_PATH ?= include/cjson 19 | LIBRARY_PATH ?= lib 20 | 21 | INSTALL_INCLUDE_PATH = $(DESTDIR)$(PREFIX)/$(INCLUDE_PATH) 22 | INSTALL_LIBRARY_PATH = $(DESTDIR)$(PREFIX)/$(LIBRARY_PATH) 23 | 24 | INSTALL ?= cp -a 25 | 26 | R_CFLAGS = -fPIC -std=c89 -pedantic -Wall -Werror -Wstrict-prototypes -Wwrite-strings -Wshadow -Winit-self -Wcast-align -Wformat=2 -Wmissing-prototypes -Wstrict-overflow=2 -Wcast-qual -Wc++-compat -Wundef -Wswitch-default -Wconversion -fstack-protector-strong $(CFLAGS) 27 | 28 | uname := $(shell sh -c 'uname -s 2>/dev/null || echo false') 29 | 30 | #library file extensions 31 | SHARED = so 32 | STATIC = a 33 | 34 | ## create dynamic (shared) library on Darwin (base OS for MacOSX and IOS) 35 | ifeq (Darwin, $(uname)) 36 | SHARED = dylib 37 | endif 38 | 39 | #cJSON library names 40 | CJSON_SHARED = $(CJSON_LIBNAME).$(SHARED) 41 | CJSON_SHARED_VERSION = $(CJSON_LIBNAME).$(SHARED).$(LIBVERSION) 42 | CJSON_SHARED_SO = $(CJSON_LIBNAME).$(SHARED).$(CJSON_SOVERSION) 43 | CJSON_STATIC = $(CJSON_LIBNAME).$(STATIC) 44 | 45 | #cJSON_Utils library names 46 | UTILS_SHARED = $(UTILS_LIBNAME).$(SHARED) 47 | UTILS_SHARED_VERSION = $(UTILS_LIBNAME).$(SHARED).$(LIBVERSION) 48 | UTILS_SHARED_SO = $(UTILS_LIBNAME).$(SHARED).$(UTILS_SOVERSION) 49 | UTILS_STATIC = $(UTILS_LIBNAME).$(STATIC) 50 | 51 | SHARED_CMD = $(CC) -shared -o 52 | 53 | .PHONY: all shared static tests clean install 54 | 55 | all: shared static tests 56 | 57 | shared: $(CJSON_SHARED) $(UTILS_SHARED) 58 | 59 | static: $(CJSON_STATIC) $(UTILS_STATIC) 60 | 61 | tests: $(CJSON_TEST) $(UTILS_TEST) 62 | 63 | test: tests 64 | ./$(CJSON_TEST) 65 | ./$(UTILS_TEST) 66 | 67 | .c.o: 68 | $(CC) -c $(R_CFLAGS) $< 69 | 70 | #tests 71 | #cJSON 72 | $(CJSON_TEST): $(CJSON_TEST_SRC) cJSON.h 73 | $(CC) $(R_CFLAGS) $(CJSON_TEST_SRC) -o $@ $(LDLIBS) -I. 74 | #cJSON_Utils 75 | $(UTILS_TEST): $(UTILS_TEST_SRC) cJSON.h cJSON_Utils.h 76 | $(CC) $(R_CFLAGS) $(UTILS_TEST_SRC) -o $@ $(LDLIBS) -I. 77 | 78 | #static libraries 79 | #cJSON 80 | $(CJSON_STATIC): $(CJSON_OBJ) 81 | $(AR) rcs $@ $< 82 | #cJSON_Utils 83 | $(UTILS_STATIC): $(UTILS_OBJ) 84 | $(AR) rcs $@ $< 85 | 86 | #shared libraries .so.1.0.0 87 | #cJSON 88 | $(CJSON_SHARED_VERSION): $(CJSON_OBJ) 89 | $(CC) -shared -o $@ $< $(LDFLAGS) 90 | #cJSON_Utils 91 | $(UTILS_SHARED_VERSION): $(UTILS_OBJ) 92 | $(CC) -shared -o $@ $< $(LDFLAGS) 93 | 94 | #objects 95 | #cJSON 96 | $(CJSON_OBJ): cJSON.c cJSON.h 97 | #cJSON_Utils 98 | $(UTILS_OBJ): cJSON_Utils.c cJSON_Utils.h 99 | 100 | 101 | #links .so -> .so.1 -> .so.1.0.0 102 | #cJSON 103 | $(CJSON_SHARED_SO): $(CJSON_SHARED_VERSION) 104 | ln -s $(CJSON_SHARED_VERSION) $(CJSON_SHARED_SO) 105 | $(CJSON_SHARED): $(CJSON_SHARED_SO) 106 | ln -s $(CJSON_SHARED_SO) $(CJSON_SHARED) 107 | #cJSON_Utils 108 | $(UTILS_SHARED_SO): $(UTILS_SHARED_VERSION) 109 | ln -s $(UTILS_SHARED_VERSION) $(UTILS_SHARED_SO) 110 | $(UTILS_SHARED): $(UTILS_SHARED_SO) 111 | ln -s $(UTILS_SHARED_SO) $(UTILS_SHARED) 112 | 113 | #install 114 | #cJSON 115 | install-cjson: 116 | mkdir -p $(INSTALL_LIBRARY_PATH) $(INSTALL_INCLUDE_PATH) 117 | $(INSTALL) cJSON.h $(INSTALL_INCLUDE_PATH) 118 | $(INSTALL) $(CJSON_SHARED) $(CJSON_SHARED_SO) $(CJSON_SHARED_VERSION) $(INSTALL_LIBRARY_PATH) 119 | #cJSON_Utils 120 | install-utils: install-cjson 121 | $(INSTALL) cJSON_Utils.h $(INSTALL_INCLUDE_PATH) 122 | $(INSTALL) $(UTILS_SHARED) $(UTILS_SHARED_SO) $(UTILS_SHARED_VERSION) $(INSTALL_LIBRARY_PATH) 123 | 124 | install: install-cjson install-utils 125 | 126 | #uninstall 127 | #cJSON 128 | uninstall-cjson: uninstall-utils 129 | $(RM) $(INSTALL_LIBRARY_PATH)/$(CJSON_SHARED) 130 | $(RM) $(INSTALL_LIBRARY_PATH)/$(CJSON_SHARED_VERSION) 131 | $(RM) $(INSTALL_LIBRARY_PATH)/$(CJSON_SHARED_SO) 132 | rmdir $(INSTALL_LIBRARY_PATH) 133 | $(RM) $(INSTALL_INCLUDE_PATH)/cJSON.h 134 | rmdir $(INSTALL_INCLUDE_PATH) 135 | #cJSON_Utils 136 | uninstall-utils: 137 | $(RM) $(INSTALL_LIBRARY_PATH)/$(UTILS_SHARED) 138 | $(RM) $(INSTALL_LIBRARY_PATH)/$(UTILS_SHARED_VERSION) 139 | $(RM) $(INSTALL_LIBRARY_PATH)/$(UTILS_SHARED_SO) 140 | $(RM) $(INSTALL_INCLUDE_PATH)/cJSON_Utils.h 141 | 142 | uninstall: uninstall-utils uninstall-cjson 143 | 144 | clean: 145 | $(RM) $(CJSON_OBJ) $(UTILS_OBJ) #delete object files 146 | $(RM) $(CJSON_SHARED) $(CJSON_SHARED_VERSION) $(CJSON_SHARED_SO) $(CJSON_STATIC) #delete cJSON 147 | $(RM) $(UTILS_SHARED) $(UTILS_SHARED_VERSION) $(UTILS_SHARED_SO) $(UTILS_STATIC) #delete cJSON_Utils 148 | $(RM) $(CJSON_TEST) $(UTILS_TEST) #delete tests 149 | -------------------------------------------------------------------------------- /cJSONConfig.cmake.in: -------------------------------------------------------------------------------- 1 | # Whether the utils lib was build. 2 | set(CJSON_UTILS_FOUND @ENABLE_CJSON_UTILS@) 3 | 4 | # The include directories used by cJSON 5 | set(CJSON_INCLUDE_DIRS "@prefix@/@includedir@") 6 | set(CJSON_INCLUDE_DIR "@prefix@/@includedir@") 7 | 8 | get_filename_component(_dir "${CMAKE_CURRENT_LIST_FILE}" PATH) 9 | 10 | # The cJSON library 11 | set(CJSON_LIBRARY "@CJSON_LIB@") 12 | if(@ENABLE_TARGET_EXPORT@) 13 | # Include the target 14 | include("${_dir}/cjson.cmake") 15 | endif() 16 | 17 | if(CJSON_UTILS_FOUND) 18 | # The cJSON utils library 19 | set(CJSON_UTILS_LIBRARY @CJSON_UTILS_LIB@) 20 | # All cJSON libraries 21 | set(CJSON_LIBRARIES "@CJSON_UTILS_LIB@" "@CJSON_LIB@") 22 | if(@ENABLE_TARGET_EXPORT@) 23 | # Include the target 24 | include("${_dir}/cjson_utils.cmake") 25 | endif() 26 | else() 27 | # All cJSON libraries 28 | set(CJSON_LIBRARIES "@CJSON_LIB@") 29 | endif() 30 | -------------------------------------------------------------------------------- /cJSONConfigVersion.cmake.in: -------------------------------------------------------------------------------- 1 | set(PACKAGE_VERSION "@PROJECT_VERSION@") 2 | 3 | # Check whether the requested PACKAGE_FIND_VERSION is compatible 4 | if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") 5 | set(PACKAGE_VERSION_COMPATIBLE FALSE) 6 | else() 7 | set(PACKAGE_VERSION_COMPATIBLE TRUE) 8 | if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") 9 | set(PACKAGE_VERSION_EXACT TRUE) 10 | endif() 11 | endif() 12 | -------------------------------------------------------------------------------- /cJSON_Utils.h: -------------------------------------------------------------------------------- 1 | #include "cJSON.h" 2 | 3 | /* Implement RFC6901 (https://tools.ietf.org/html/rfc6901) JSON Pointer spec. */ 4 | cJSON *cJSONUtils_GetPointer(cJSON *object, const char *pointer); 5 | 6 | /* Implement RFC6902 (https://tools.ietf.org/html/rfc6902) JSON Patch spec. */ 7 | cJSON* cJSONUtils_GeneratePatches(cJSON *from, cJSON *to); 8 | /* Utility for generating patch array entries. */ 9 | void cJSONUtils_AddPatchToArray(cJSON *array, const char *op, const char *path, cJSON *val); 10 | /* Returns 0 for success. */ 11 | int cJSONUtils_ApplyPatches(cJSON *object, cJSON *patches); 12 | 13 | /* 14 | // Note that ApplyPatches is NOT atomic on failure. To implement an atomic ApplyPatches, use: 15 | //int cJSONUtils_AtomicApplyPatches(cJSON **object, cJSON *patches) 16 | //{ 17 | // cJSON *modme = cJSON_Duplicate(*object, 1); 18 | // int error = cJSONUtils_ApplyPatches(modme, patches); 19 | // if (!error) 20 | // { 21 | // cJSON_Delete(*object); 22 | // *object = modme; 23 | // } 24 | // else 25 | // { 26 | // cJSON_Delete(modme); 27 | // } 28 | // 29 | // return error; 30 | //} 31 | // Code not added to library since this strategy is a LOT slower. 32 | */ 33 | 34 | /* Implement RFC7386 (https://tools.ietf.org/html/rfc7396) JSON Merge Patch spec. */ 35 | /* target will be modified by patch. return value is new ptr for target. */ 36 | cJSON* cJSONUtils_MergePatch(cJSON *target, cJSON *patch); 37 | /* generates a patch to move from -> to */ 38 | cJSON *cJSONUtils_GenerateMergePatch(cJSON *from, cJSON *to); 39 | 40 | /* Given a root object and a target object, construct a pointer from one to the other. */ 41 | char *cJSONUtils_FindPointerFromObjectTo(cJSON *object, cJSON *target); 42 | 43 | /* Sorts the members of the object into alphabetical order. */ 44 | void cJSONUtils_SortObject(cJSON *object); 45 | -------------------------------------------------------------------------------- /demo.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009 Dave Gamble 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include "cJSON.h" 27 | 28 | void printJson(cJSON *root) 29 | { 30 | if(!root) 31 | { 32 | printf("NULL JSON root.\n"); 33 | return; 34 | } 35 | 36 | printf("Type=0x%02x, %s=%s\n", root->type, root->string, cJSON_Print(root)); 37 | } 38 | 39 | static char * makeJson(void) 40 | { 41 | cJSON *pJsonRoot = NULL; 42 | cJSON *pSubJson = NULL; 43 | char *p = NULL; 44 | 45 | pJsonRoot = cJSON_CreateObject(); 46 | if(NULL == pJsonRoot) 47 | { 48 | printf("%s line=%d NULL\n", __func__, __LINE__); 49 | return NULL; 50 | } 51 | cJSON_AddStringToObject(pJsonRoot, "hello", "hello world"); 52 | cJSON_AddNumberToObject(pJsonRoot, "number", 10010); 53 | cJSON_AddBoolToObject(pJsonRoot, "bool", 1); 54 | pSubJson = cJSON_CreateObject(); 55 | if(NULL == pSubJson) 56 | { 57 | printf("%s line=%d NULL\n", __func__, __LINE__); 58 | cJSON_Delete(pJsonRoot); 59 | return NULL; 60 | } 61 | cJSON_AddStringToObject(pSubJson, "subjsonobj", "a sub json string"); 62 | cJSON_AddItemToObject(pJsonRoot, "subobj", pSubJson); 63 | 64 | p = cJSON_Print(pJsonRoot); 65 | if(NULL == p) 66 | { 67 | printf("%s line=%d NULL\n", __func__, __LINE__); 68 | cJSON_Delete(pJsonRoot); 69 | return NULL; 70 | } 71 | 72 | cJSON_Delete(pJsonRoot); 73 | 74 | return p; 75 | } 76 | 77 | 78 | static void parseJson(char * pMsg) 79 | { 80 | cJSON *pJson; 81 | cJSON *pSub; 82 | cJSON * pSubSub; 83 | 84 | if(NULL == pMsg) 85 | { 86 | return; 87 | } 88 | 89 | pJson = cJSON_Parse(pMsg); 90 | if(NULL == pJson) 91 | { 92 | return ; 93 | } 94 | 95 | pSub = cJSON_GetObjectItem(pJson, "hello"); 96 | printJson(pSub); 97 | 98 | pSub = cJSON_GetObjectItem(pJson, "number"); 99 | printJson(pSub); 100 | 101 | pSub = cJSON_GetObjectItem(pJson, "bool"); 102 | printJson(pSub); 103 | 104 | pSub = cJSON_GetObjectItem(pJson, "subobj"); 105 | printJson(pSub); 106 | 107 | pSubSub = cJSON_GetObjectItem(pSub, "subjsonobj"); 108 | printJson(pSubSub); 109 | 110 | cJSON_Delete(pJson); 111 | } 112 | 113 | int main(void) 114 | { 115 | char *p; 116 | 117 | /* print the version */ 118 | printf("Version: %s\n", cJSON_Version()); 119 | 120 | p = makeJson(); 121 | if(NULL == p) 122 | { 123 | return 0; 124 | } 125 | printf("p = \n%s\n\n", p); 126 | parseJson(p); 127 | free(p); 128 | return 0; 129 | } 130 | -------------------------------------------------------------------------------- /libcjson.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | libdir=${prefix}/@libdir@ 3 | includedir=${prefix}/@includedir@ 4 | 5 | Name: libcjson 6 | Version: @version@ 7 | Description: Ultralightweight JSON parser in ANSI C 8 | URL: https://github.com/DaveGamble/cJSON 9 | Libs: -L${libdir} -lcjson 10 | Libs.Private: -lm 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /libcjson_utils.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | libdir=${prefix}/@libdir@ 3 | includedir=${prefix}/@includedir@ 4 | 5 | Name: libcjson_utils 6 | Version: @version@ 7 | Description: An implementation of JSON Pointer, Patch and Merge Patch based on cJSON. 8 | URL: https://github.com/DaveGamble/cJSON 9 | Libs: -L${libdir} -lcjson_utils 10 | Cflags: -I${includedir} 11 | Requires: libcjson 12 | -------------------------------------------------------------------------------- /make.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #mkdir build 4 | #cd build 5 | #cmake .. -DENABLE_CJSON_UTILS=Off -DENABLE_CJSON_TEST=On -DCMAKE_INSTALL_PREFIX=/usr (生成bin+lib) 6 | #cmake .. -DENABLE_CJSON_UTILS=Off -DENABLE_CJSON_TEST=On -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_SHARED_LIBS=Off (生成bin) 7 | #make 8 | #sudo make install (安装libcjson.so) 9 | #gcc demo.c -o demo -lcjson (build demo.c) 10 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if(ENABLE_CJSON_TEST) 2 | add_library(unity unity/src/unity.c) 3 | 4 | #copy test files 5 | file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/inputs") 6 | file(GLOB test_files "inputs/*") 7 | file(COPY ${test_files} DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/inputs/") 8 | 9 | set(unity_tests 10 | parse_examples 11 | parse_number 12 | parse_hex4 13 | parse_string 14 | parse_array 15 | parse_object 16 | parse_value 17 | ) 18 | 19 | add_library(test-common common.c) 20 | 21 | option(ENABLE_VALGRIND OFF "Enable the valgrind memory checker for the tests.") 22 | if (ENABLE_VALGRIND) 23 | find_program(MEMORYCHECK_COMMAND valgrind) 24 | if ("${MEMORYCHECK_COMMAND}" MATCHES "MEMORYCHECK_COMMAND-NOTFOUND") 25 | message(WARNING "Valgrind couldn't be found.") 26 | unset(MEMORYCHECK_COMMAND) 27 | else() 28 | set(MEMORYCHECK_COMMAND_OPTIONS --trace-children=yes --leak-check=full --error-exitcode=1) 29 | endif() 30 | endif() 31 | 32 | foreach(unity_test ${unity_tests}) 33 | add_executable("${unity_test}" "${unity_test}.c") 34 | target_link_libraries("${unity_test}" "${CJSON_LIB}" unity test-common) 35 | if(MEMORYCHECK_COMMAND) 36 | add_test(NAME "${unity_test}" 37 | COMMAND "${MEMORYCHECK_COMMAND}" ${MEMORYCHECK_COMMAND_OPTIONS} "./${unity_test}") 38 | else() 39 | add_test(NAME "${unity_test}" 40 | COMMAND "./${unity_test}") 41 | endif() 42 | endforeach() 43 | endif() 44 | -------------------------------------------------------------------------------- /tests/common.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009-2017 Dave Gamble and cJSON contributors 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #include "common.h" 24 | 25 | extern void reset(cJSON *item) 26 | { 27 | if ((item != NULL) && (item->child != NULL)) 28 | { 29 | cJSON_Delete(item->child); 30 | } 31 | if ((item->valuestring != NULL) && !(item->type & cJSON_IsReference)) 32 | { 33 | cJSON_free(item->valuestring); 34 | } 35 | if ((item->string != NULL) && !(item->type & cJSON_StringIsConst)) 36 | { 37 | cJSON_free(item->string); 38 | } 39 | 40 | memset(item, 0, sizeof(cJSON)); 41 | } 42 | 43 | extern char *read_file(const char *filename) 44 | { 45 | FILE *file = NULL; 46 | long length = 0; 47 | char *content = NULL; 48 | size_t read_chars = 0; 49 | 50 | /* open in read binary mode */ 51 | file = fopen(filename, "rb"); 52 | if (file == NULL) 53 | { 54 | goto cleanup; 55 | } 56 | 57 | /* get the length */ 58 | if (fseek(file, 0, SEEK_END) != 0) 59 | { 60 | goto cleanup; 61 | } 62 | length = ftell(file); 63 | if (length < 0) 64 | { 65 | goto cleanup; 66 | } 67 | if (fseek(file, 0, SEEK_SET) != 0) 68 | { 69 | goto cleanup; 70 | } 71 | 72 | /* allocate content buffer */ 73 | content = (char*)malloc((size_t)length + sizeof('\0')); 74 | if (content == NULL) 75 | { 76 | goto cleanup; 77 | } 78 | 79 | /* read the file into memory */ 80 | read_chars = fread(content, sizeof(char), (size_t)length, file); 81 | if ((long)read_chars != length) 82 | { 83 | free(content); 84 | content = NULL; 85 | goto cleanup; 86 | } 87 | content[read_chars] = '\0'; 88 | 89 | 90 | cleanup: 91 | if (file != NULL) 92 | { 93 | fclose(file); 94 | } 95 | 96 | return content; 97 | } 98 | -------------------------------------------------------------------------------- /tests/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009-2017 Dave Gamble and cJSON contributors 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #ifndef CJSON_TESTS_COMMON_H 24 | #define CJSON_TESTS_COMMON_H 25 | 26 | #include "../cJSON.c" 27 | 28 | extern void reset(cJSON *item); 29 | extern char *read_file(const char *filename); 30 | extern cjbool assert_is_invalid(cJSON *item); 31 | 32 | /* assertion helper macros */ 33 | #define assert_has_type(item, item_type) TEST_ASSERT_BITS_MESSAGE(0xFF, item_type, item->type, "Item doesn't have expected type.") 34 | #define assert_has_no_reference(item) TEST_ASSERT_BITS_MESSAGE(cJSON_IsReference, 0, item->type, "Item should not have a string as reference.") 35 | #define assert_has_no_const_string(item) TEST_ASSERT_BITS_MESSAGE(cJSON_StringIsConst, 0, item->type, "Item should not have a const string.") 36 | #define assert_has_valuestring(item) TEST_ASSERT_NOT_NULL_MESSAGE(item->valuestring, "Valuestring is NULL.") 37 | #define assert_has_no_valuestring(item) TEST_ASSERT_NULL_MESSAGE(item->valuestring, "Valuestring is not NULL.") 38 | #define assert_has_string(item) TEST_ASSERT_NOT_NULL_MESSAGE(item->string, "String is NULL") 39 | #define assert_has_no_string(item) TEST_ASSERT_NULL_MESSAGE(item->string, "String is not NULL.") 40 | #define assert_not_in_list(item) \ 41 | TEST_ASSERT_NULL_MESSAGE(item->next, "Linked list next pointer is not NULL.");\ 42 | TEST_ASSERT_NULL_MESSAGE(item->prev, "Linked list previous pointer is not NULL.") 43 | #define assert_has_child(item) TEST_ASSERT_NOT_NULL_MESSAGE(item->child, "Item doesn't have a child.") 44 | #define assert_has_no_child(item) TEST_ASSERT_NULL_MESSAGE(item->child, "Item has a child.") 45 | #define assert_is_invalid(item) \ 46 | assert_has_type(item, cJSON_Invalid);\ 47 | assert_not_in_list(item);\ 48 | assert_has_no_child(item);\ 49 | assert_has_no_string(item);\ 50 | assert_has_no_valuestring(item) 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /tests/inputs/test1: -------------------------------------------------------------------------------- 1 | { 2 | "glossary": { 3 | "title": "example glossary", 4 | "GlossDiv": { 5 | "title": "S", 6 | "GlossList": { 7 | "GlossEntry": { 8 | "ID": "SGML", 9 | "SortAs": "SGML", 10 | "GlossTerm": "Standard Generalized Markup Language", 11 | "Acronym": "SGML", 12 | "Abbrev": "ISO 8879:1986", 13 | "GlossDef": { 14 | "para": "A meta-markup language, used to create markup languages such as DocBook.", 15 | "GlossSeeAlso": ["GML", "XML"] 16 | }, 17 | "GlossSee": "markup" 18 | } 19 | } 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/inputs/test1.expected: -------------------------------------------------------------------------------- 1 | { 2 | "glossary": { 3 | "title": "example glossary", 4 | "GlossDiv": { 5 | "title": "S", 6 | "GlossList": { 7 | "GlossEntry": { 8 | "ID": "SGML", 9 | "SortAs": "SGML", 10 | "GlossTerm": "Standard Generalized Markup Language", 11 | "Acronym": "SGML", 12 | "Abbrev": "ISO 8879:1986", 13 | "GlossDef": { 14 | "para": "A meta-markup language, used to create markup languages such as DocBook.", 15 | "GlossSeeAlso": ["GML", "XML"] 16 | }, 17 | "GlossSee": "markup" 18 | } 19 | } 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /tests/inputs/test10: -------------------------------------------------------------------------------- 1 | ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] 2 | -------------------------------------------------------------------------------- /tests/inputs/test10.expected: -------------------------------------------------------------------------------- 1 | ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] -------------------------------------------------------------------------------- /tests/inputs/test11: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Jack (\"Bee\") Nimble", 3 | "format": {"type": "rect", 4 | "width": 1920, 5 | "height": 1080, 6 | "interlace": false,"frame rate": 24 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tests/inputs/test11.expected: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Jack (\"Bee\") Nimble", 3 | "format": { 4 | "type": "rect", 5 | "width": 1920, 6 | "height": 1080, 7 | "interlace": false, 8 | "frame rate": 24 9 | } 10 | } -------------------------------------------------------------------------------- /tests/inputs/test2: -------------------------------------------------------------------------------- 1 | {"menu": { 2 | "id": "file", 3 | "value": "File", 4 | "popup": { 5 | "menuitem": [ 6 | {"value": "New", "onclick": "CreateNewDoc()"}, 7 | {"value": "Open", "onclick": "OpenDoc()"}, 8 | {"value": "Close", "onclick": "CloseDoc()"} 9 | ] 10 | } 11 | }} 12 | -------------------------------------------------------------------------------- /tests/inputs/test2.expected: -------------------------------------------------------------------------------- 1 | { 2 | "menu": { 3 | "id": "file", 4 | "value": "File", 5 | "popup": { 6 | "menuitem": [{ 7 | "value": "New", 8 | "onclick": "CreateNewDoc()" 9 | }, { 10 | "value": "Open", 11 | "onclick": "OpenDoc()" 12 | }, { 13 | "value": "Close", 14 | "onclick": "CloseDoc()" 15 | }] 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /tests/inputs/test3: -------------------------------------------------------------------------------- 1 | {"widget": { 2 | "debug": "on", 3 | "window": { 4 | "title": "Sample Konfabulator Widget", 5 | "name": "main_window", 6 | "width": 500, 7 | "height": 500 8 | }, 9 | "image": { 10 | "src": "Images/Sun.png", 11 | "name": "sun1", 12 | "hOffset": 250, 13 | "vOffset": 250, 14 | "alignment": "center" 15 | }, 16 | "text": { 17 | "data": "Click Here", 18 | "size": 36, 19 | "style": "bold", 20 | "name": "text1", 21 | "hOffset": 250, 22 | "vOffset": 100, 23 | "alignment": "center", 24 | "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;" 25 | } 26 | }} -------------------------------------------------------------------------------- /tests/inputs/test3.expected: -------------------------------------------------------------------------------- 1 | { 2 | "widget": { 3 | "debug": "on", 4 | "window": { 5 | "title": "Sample Konfabulator Widget", 6 | "name": "main_window", 7 | "width": 500, 8 | "height": 500 9 | }, 10 | "image": { 11 | "src": "Images/Sun.png", 12 | "name": "sun1", 13 | "hOffset": 250, 14 | "vOffset": 250, 15 | "alignment": "center" 16 | }, 17 | "text": { 18 | "data": "Click Here", 19 | "size": 36, 20 | "style": "bold", 21 | "name": "text1", 22 | "hOffset": 250, 23 | "vOffset": 100, 24 | "alignment": "center", 25 | "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;" 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /tests/inputs/test4: -------------------------------------------------------------------------------- 1 | {"web-app": { 2 | "servlet": [ 3 | { 4 | "servlet-name": "cofaxCDS", 5 | "servlet-class": "org.cofax.cds.CDSServlet", 6 | "init-param": { 7 | "configGlossary:installationAt": "Philadelphia, PA", 8 | "configGlossary:adminEmail": "ksm@pobox.com", 9 | "configGlossary:poweredBy": "Cofax", 10 | "configGlossary:poweredByIcon": "/images/cofax.gif", 11 | "configGlossary:staticPath": "/content/static", 12 | "templateProcessorClass": "org.cofax.WysiwygTemplate", 13 | "templateLoaderClass": "org.cofax.FilesTemplateLoader", 14 | "templatePath": "templates", 15 | "templateOverridePath": "", 16 | "defaultListTemplate": "listTemplate.htm", 17 | "defaultFileTemplate": "articleTemplate.htm", 18 | "useJSP": false, 19 | "jspListTemplate": "listTemplate.jsp", 20 | "jspFileTemplate": "articleTemplate.jsp", 21 | "cachePackageTagsTrack": 200, 22 | "cachePackageTagsStore": 200, 23 | "cachePackageTagsRefresh": 60, 24 | "cacheTemplatesTrack": 100, 25 | "cacheTemplatesStore": 50, 26 | "cacheTemplatesRefresh": 15, 27 | "cachePagesTrack": 200, 28 | "cachePagesStore": 100, 29 | "cachePagesRefresh": 10, 30 | "cachePagesDirtyRead": 10, 31 | "searchEngineListTemplate": "forSearchEnginesList.htm", 32 | "searchEngineFileTemplate": "forSearchEngines.htm", 33 | "searchEngineRobotsDb": "WEB-INF/robots.db", 34 | "useDataStore": true, 35 | "dataStoreClass": "org.cofax.SqlDataStore", 36 | "redirectionClass": "org.cofax.SqlRedirection", 37 | "dataStoreName": "cofax", 38 | "dataStoreDriver": "com.microsoft.jdbc.sqlserver.SQLServerDriver", 39 | "dataStoreUrl": "jdbc:microsoft:sqlserver://LOCALHOST:1433;DatabaseName=goon", 40 | "dataStoreUser": "sa", 41 | "dataStorePassword": "dataStoreTestQuery", 42 | "dataStoreTestQuery": "SET NOCOUNT ON;select test='test';", 43 | "dataStoreLogFile": "/usr/local/tomcat/logs/datastore.log", 44 | "dataStoreInitConns": 10, 45 | "dataStoreMaxConns": 100, 46 | "dataStoreConnUsageLimit": 100, 47 | "dataStoreLogLevel": "debug", 48 | "maxUrlLength": 500}}, 49 | { 50 | "servlet-name": "cofaxEmail", 51 | "servlet-class": "org.cofax.cds.EmailServlet", 52 | "init-param": { 53 | "mailHost": "mail1", 54 | "mailHostOverride": "mail2"}}, 55 | { 56 | "servlet-name": "cofaxAdmin", 57 | "servlet-class": "org.cofax.cds.AdminServlet"}, 58 | 59 | { 60 | "servlet-name": "fileServlet", 61 | "servlet-class": "org.cofax.cds.FileServlet"}, 62 | { 63 | "servlet-name": "cofaxTools", 64 | "servlet-class": "org.cofax.cms.CofaxToolsServlet", 65 | "init-param": { 66 | "templatePath": "toolstemplates/", 67 | "log": 1, 68 | "logLocation": "/usr/local/tomcat/logs/CofaxTools.log", 69 | "logMaxSize": "", 70 | "dataLog": 1, 71 | "dataLogLocation": "/usr/local/tomcat/logs/dataLog.log", 72 | "dataLogMaxSize": "", 73 | "removePageCache": "/content/admin/remove?cache=pages&id=", 74 | "removeTemplateCache": "/content/admin/remove?cache=templates&id=", 75 | "fileTransferFolder": "/usr/local/tomcat/webapps/content/fileTransferFolder", 76 | "lookInContext": 1, 77 | "adminGroupID": 4, 78 | "betaServer": true}}], 79 | "servlet-mapping": { 80 | "cofaxCDS": "/", 81 | "cofaxEmail": "/cofaxutil/aemail/*", 82 | "cofaxAdmin": "/admin/*", 83 | "fileServlet": "/static/*", 84 | "cofaxTools": "/tools/*"}, 85 | 86 | "taglib": { 87 | "taglib-uri": "cofax.tld", 88 | "taglib-location": "/WEB-INF/tlds/cofax.tld"}}} -------------------------------------------------------------------------------- /tests/inputs/test4.expected: -------------------------------------------------------------------------------- 1 | { 2 | "web-app": { 3 | "servlet": [{ 4 | "servlet-name": "cofaxCDS", 5 | "servlet-class": "org.cofax.cds.CDSServlet", 6 | "init-param": { 7 | "configGlossary:installationAt": "Philadelphia, PA", 8 | "configGlossary:adminEmail": "ksm@pobox.com", 9 | "configGlossary:poweredBy": "Cofax", 10 | "configGlossary:poweredByIcon": "/images/cofax.gif", 11 | "configGlossary:staticPath": "/content/static", 12 | "templateProcessorClass": "org.cofax.WysiwygTemplate", 13 | "templateLoaderClass": "org.cofax.FilesTemplateLoader", 14 | "templatePath": "templates", 15 | "templateOverridePath": "", 16 | "defaultListTemplate": "listTemplate.htm", 17 | "defaultFileTemplate": "articleTemplate.htm", 18 | "useJSP": false, 19 | "jspListTemplate": "listTemplate.jsp", 20 | "jspFileTemplate": "articleTemplate.jsp", 21 | "cachePackageTagsTrack": 200, 22 | "cachePackageTagsStore": 200, 23 | "cachePackageTagsRefresh": 60, 24 | "cacheTemplatesTrack": 100, 25 | "cacheTemplatesStore": 50, 26 | "cacheTemplatesRefresh": 15, 27 | "cachePagesTrack": 200, 28 | "cachePagesStore": 100, 29 | "cachePagesRefresh": 10, 30 | "cachePagesDirtyRead": 10, 31 | "searchEngineListTemplate": "forSearchEnginesList.htm", 32 | "searchEngineFileTemplate": "forSearchEngines.htm", 33 | "searchEngineRobotsDb": "WEB-INF/robots.db", 34 | "useDataStore": true, 35 | "dataStoreClass": "org.cofax.SqlDataStore", 36 | "redirectionClass": "org.cofax.SqlRedirection", 37 | "dataStoreName": "cofax", 38 | "dataStoreDriver": "com.microsoft.jdbc.sqlserver.SQLServerDriver", 39 | "dataStoreUrl": "jdbc:microsoft:sqlserver://LOCALHOST:1433;DatabaseName=goon", 40 | "dataStoreUser": "sa", 41 | "dataStorePassword": "dataStoreTestQuery", 42 | "dataStoreTestQuery": "SET NOCOUNT ON;select test='test';", 43 | "dataStoreLogFile": "/usr/local/tomcat/logs/datastore.log", 44 | "dataStoreInitConns": 10, 45 | "dataStoreMaxConns": 100, 46 | "dataStoreConnUsageLimit": 100, 47 | "dataStoreLogLevel": "debug", 48 | "maxUrlLength": 500 49 | } 50 | }, { 51 | "servlet-name": "cofaxEmail", 52 | "servlet-class": "org.cofax.cds.EmailServlet", 53 | "init-param": { 54 | "mailHost": "mail1", 55 | "mailHostOverride": "mail2" 56 | } 57 | }, { 58 | "servlet-name": "cofaxAdmin", 59 | "servlet-class": "org.cofax.cds.AdminServlet" 60 | }, { 61 | "servlet-name": "fileServlet", 62 | "servlet-class": "org.cofax.cds.FileServlet" 63 | }, { 64 | "servlet-name": "cofaxTools", 65 | "servlet-class": "org.cofax.cms.CofaxToolsServlet", 66 | "init-param": { 67 | "templatePath": "toolstemplates/", 68 | "log": 1, 69 | "logLocation": "/usr/local/tomcat/logs/CofaxTools.log", 70 | "logMaxSize": "", 71 | "dataLog": 1, 72 | "dataLogLocation": "/usr/local/tomcat/logs/dataLog.log", 73 | "dataLogMaxSize": "", 74 | "removePageCache": "/content/admin/remove?cache=pages&id=", 75 | "removeTemplateCache": "/content/admin/remove?cache=templates&id=", 76 | "fileTransferFolder": "/usr/local/tomcat/webapps/content/fileTransferFolder", 77 | "lookInContext": 1, 78 | "adminGroupID": 4, 79 | "betaServer": true 80 | } 81 | }], 82 | "servlet-mapping": { 83 | "cofaxCDS": "/", 84 | "cofaxEmail": "/cofaxutil/aemail/*", 85 | "cofaxAdmin": "/admin/*", 86 | "fileServlet": "/static/*", 87 | "cofaxTools": "/tools/*" 88 | }, 89 | "taglib": { 90 | "taglib-uri": "cofax.tld", 91 | "taglib-location": "/WEB-INF/tlds/cofax.tld" 92 | } 93 | } 94 | } -------------------------------------------------------------------------------- /tests/inputs/test5: -------------------------------------------------------------------------------- 1 | {"menu": { 2 | "header": "SVG Viewer", 3 | "items": [ 4 | {"id": "Open"}, 5 | {"id": "OpenNew", "label": "Open New"}, 6 | null, 7 | {"id": "ZoomIn", "label": "Zoom In"}, 8 | {"id": "ZoomOut", "label": "Zoom Out"}, 9 | {"id": "OriginalView", "label": "Original View"}, 10 | null, 11 | {"id": "Quality"}, 12 | {"id": "Pause"}, 13 | {"id": "Mute"}, 14 | null, 15 | {"id": "Find", "label": "Find..."}, 16 | {"id": "FindAgain", "label": "Find Again"}, 17 | {"id": "Copy"}, 18 | {"id": "CopyAgain", "label": "Copy Again"}, 19 | {"id": "CopySVG", "label": "Copy SVG"}, 20 | {"id": "ViewSVG", "label": "View SVG"}, 21 | {"id": "ViewSource", "label": "View Source"}, 22 | {"id": "SaveAs", "label": "Save As"}, 23 | null, 24 | {"id": "Help"}, 25 | {"id": "About", "label": "About Adobe CVG Viewer..."} 26 | ] 27 | }} 28 | -------------------------------------------------------------------------------- /tests/inputs/test5.expected: -------------------------------------------------------------------------------- 1 | { 2 | "menu": { 3 | "header": "SVG Viewer", 4 | "items": [{ 5 | "id": "Open" 6 | }, { 7 | "id": "OpenNew", 8 | "label": "Open New" 9 | }, null, { 10 | "id": "ZoomIn", 11 | "label": "Zoom In" 12 | }, { 13 | "id": "ZoomOut", 14 | "label": "Zoom Out" 15 | }, { 16 | "id": "OriginalView", 17 | "label": "Original View" 18 | }, null, { 19 | "id": "Quality" 20 | }, { 21 | "id": "Pause" 22 | }, { 23 | "id": "Mute" 24 | }, null, { 25 | "id": "Find", 26 | "label": "Find..." 27 | }, { 28 | "id": "FindAgain", 29 | "label": "Find Again" 30 | }, { 31 | "id": "Copy" 32 | }, { 33 | "id": "CopyAgain", 34 | "label": "Copy Again" 35 | }, { 36 | "id": "CopySVG", 37 | "label": "Copy SVG" 38 | }, { 39 | "id": "ViewSVG", 40 | "label": "View SVG" 41 | }, { 42 | "id": "ViewSource", 43 | "label": "View Source" 44 | }, { 45 | "id": "SaveAs", 46 | "label": "Save As" 47 | }, null, { 48 | "id": "Help" 49 | }, { 50 | "id": "About", 51 | "label": "About Adobe CVG Viewer..." 52 | }] 53 | } 54 | } -------------------------------------------------------------------------------- /tests/inputs/test6: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | Application Error 10 | 11 | 12 | 15 | 16 | -------------------------------------------------------------------------------- /tests/inputs/test7: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "precision": "zip", 4 | "Latitude": 37.7668, 5 | "Longitude": -122.3959, 6 | "Address": "", 7 | "City": "SAN FRANCISCO", 8 | "State": "CA", 9 | "Zip": "94107", 10 | "Country": "US" 11 | }, 12 | { 13 | "precision": "zip", 14 | "Latitude": 37.371991, 15 | "Longitude": -122.026020, 16 | "Address": "", 17 | "City": "SUNNYVALE", 18 | "State": "CA", 19 | "Zip": "94085", 20 | "Country": "US" 21 | } 22 | ] 23 | -------------------------------------------------------------------------------- /tests/inputs/test7.expected: -------------------------------------------------------------------------------- 1 | [{ 2 | "precision": "zip", 3 | "Latitude": 37.766800, 4 | "Longitude": -122.395900, 5 | "Address": "", 6 | "City": "SAN FRANCISCO", 7 | "State": "CA", 8 | "Zip": "94107", 9 | "Country": "US" 10 | }, { 11 | "precision": "zip", 12 | "Latitude": 37.371991, 13 | "Longitude": -122.026020, 14 | "Address": "", 15 | "City": "SUNNYVALE", 16 | "State": "CA", 17 | "Zip": "94085", 18 | "Country": "US" 19 | }] -------------------------------------------------------------------------------- /tests/inputs/test8: -------------------------------------------------------------------------------- 1 | { 2 | "Image": { 3 | "Width": 800, 4 | "Height": 600, 5 | "Title": "View from 15th Floor", 6 | "Thumbnail": { 7 | "Url": "http:/*www.example.com/image/481989943", 8 | "Height": 125, 9 | "Width": "100" 10 | }, 11 | "IDs": [116, 943, 234, 38793] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/inputs/test8.expected: -------------------------------------------------------------------------------- 1 | { 2 | "Image": { 3 | "Width": 800, 4 | "Height": 600, 5 | "Title": "View from 15th Floor", 6 | "Thumbnail": { 7 | "Url": "http:/*www.example.com/image/481989943", 8 | "Height": 125, 9 | "Width": "100" 10 | }, 11 | "IDs": [116, 943, 234, 38793] 12 | } 13 | } -------------------------------------------------------------------------------- /tests/inputs/test9: -------------------------------------------------------------------------------- 1 | [ 2 | [0, -1, 0], 3 | [1, 0, 0], 4 | [0, 0, 1] 5 | ] 6 | -------------------------------------------------------------------------------- /tests/inputs/test9.expected: -------------------------------------------------------------------------------- 1 | [[0, -1, 0], [1, 0, 0], [0, 0, 1]] -------------------------------------------------------------------------------- /tests/parse_array.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009-2017 Dave Gamble and cJSON contributors 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include "unity/examples/unity_config.h" 28 | #include "unity/src/unity.h" 29 | #include "common.h" 30 | 31 | static cJSON item[1]; 32 | 33 | static const unsigned char *error_pointer = NULL; 34 | 35 | static void assert_is_array(cJSON *array_item) 36 | { 37 | TEST_ASSERT_NOT_NULL_MESSAGE(array_item, "Item is NULL."); 38 | 39 | assert_not_in_list(array_item); 40 | assert_has_type(array_item, cJSON_Array); 41 | assert_has_no_reference(array_item); 42 | assert_has_no_const_string(array_item); 43 | assert_has_no_valuestring(array_item); 44 | assert_has_no_string(array_item); 45 | } 46 | 47 | static void assert_not_array(const char *json) 48 | { 49 | TEST_ASSERT_NULL(parse_array(item, (const unsigned char*)json, &error_pointer)); 50 | assert_is_invalid(item); 51 | } 52 | 53 | static void assert_parse_array(const char *json) 54 | { 55 | TEST_ASSERT_NOT_NULL(parse_array(item, (const unsigned char*)json, &error_pointer)); 56 | assert_is_array(item); 57 | } 58 | 59 | static void parse_array_should_parse_empty_arrays(void) 60 | { 61 | assert_parse_array("[]"); 62 | assert_has_no_child(item); 63 | 64 | assert_parse_array("[\n\t]"); 65 | assert_has_no_child(item); 66 | } 67 | 68 | 69 | static void parse_array_should_parse_arrays_with_one_element(void) 70 | { 71 | 72 | assert_parse_array("[1]"); 73 | assert_has_child(item); 74 | assert_has_type(item->child, cJSON_Number); 75 | reset(item); 76 | 77 | assert_parse_array("[\"hello!\"]"); 78 | assert_has_child(item); 79 | assert_has_type(item->child, cJSON_String); 80 | TEST_ASSERT_EQUAL_STRING("hello!", item->child->valuestring); 81 | reset(item); 82 | 83 | assert_parse_array("[[]]"); 84 | assert_has_child(item); 85 | assert_is_array(item->child); 86 | assert_has_no_child(item->child); 87 | reset(item); 88 | 89 | assert_parse_array("[null]"); 90 | assert_has_child(item); 91 | assert_has_type(item->child, cJSON_NULL); 92 | reset(item); 93 | } 94 | 95 | static void parse_array_should_parse_arrays_with_multiple_elements(void) 96 | { 97 | assert_parse_array("[1\t,\n2, 3]"); 98 | assert_has_child(item); 99 | TEST_ASSERT_NOT_NULL(item->child->next); 100 | TEST_ASSERT_NOT_NULL(item->child->next->next); 101 | TEST_ASSERT_NULL(item->child->next->next->next); 102 | assert_has_type(item->child, cJSON_Number); 103 | assert_has_type(item->child->next, cJSON_Number); 104 | assert_has_type(item->child->next->next, cJSON_Number); 105 | reset(item); 106 | 107 | { 108 | size_t i = 0; 109 | cJSON *node = NULL; 110 | int expected_types[7] = 111 | { 112 | cJSON_Number, 113 | cJSON_NULL, 114 | cJSON_True, 115 | cJSON_False, 116 | cJSON_Array, 117 | cJSON_String, 118 | cJSON_Object 119 | }; 120 | assert_parse_array("[1, null, true, false, [], \"hello\", {}]"); 121 | 122 | node = item->child; 123 | for ( 124 | i = 0; 125 | (i < (sizeof(expected_types)/sizeof(int))) 126 | && (node != NULL); 127 | i++, node = node->next) 128 | { 129 | TEST_ASSERT_BITS(0xFF, expected_types[i], node->type); 130 | } 131 | TEST_ASSERT_EQUAL_INT(i, 7); 132 | reset(item); 133 | } 134 | } 135 | 136 | static void parse_array_should_not_parse_non_arrays(void) 137 | { 138 | assert_not_array(""); 139 | assert_not_array("["); 140 | assert_not_array("]"); 141 | assert_not_array("{\"hello\":[]}"); 142 | assert_not_array("42"); 143 | assert_not_array("3.14"); 144 | assert_not_array("\"[]hello world!\n\""); 145 | } 146 | 147 | int main(void) 148 | { 149 | /* initialize cJSON item */ 150 | memset(item, 0, sizeof(cJSON)); 151 | 152 | UNITY_BEGIN(); 153 | RUN_TEST(parse_array_should_parse_empty_arrays); 154 | RUN_TEST(parse_array_should_parse_arrays_with_one_element); 155 | RUN_TEST(parse_array_should_parse_arrays_with_multiple_elements); 156 | RUN_TEST(parse_array_should_not_parse_non_arrays); 157 | return UNITY_END(); 158 | } 159 | -------------------------------------------------------------------------------- /tests/parse_hex4.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009-2017 Dave Gamble and cJSON contributors 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include "unity/examples/unity_config.h" 28 | #include "unity/src/unity.h" 29 | #include "common.h" 30 | 31 | static void parse_hex4_should_parse_all_combinations(void) 32 | { 33 | unsigned int number = 0; 34 | unsigned char digits_lower[5]; 35 | unsigned char digits_upper[5]; 36 | /* test all combinations */ 37 | for (number = 0; number <= 0xFFFF; number++) 38 | { 39 | TEST_ASSERT_EQUAL_INT_MESSAGE(4, sprintf((char*)digits_lower, "%.4x", number), "sprintf failed."); 40 | TEST_ASSERT_EQUAL_INT_MESSAGE(4, sprintf((char*)digits_upper, "%.4X", number), "sprintf failed."); 41 | 42 | TEST_ASSERT_EQUAL_INT_MESSAGE(number, parse_hex4(digits_lower), "Failed to parse lowercase digits."); 43 | TEST_ASSERT_EQUAL_INT_MESSAGE(number, parse_hex4(digits_upper), "Failed to parse uppercase digits."); 44 | } 45 | } 46 | 47 | static void parse_hex4_should_parse_mixed_case(void) 48 | { 49 | TEST_ASSERT_EQUAL_INT(0xBEEF, parse_hex4((const unsigned char*)"beef")); 50 | TEST_ASSERT_EQUAL_INT(0xBEEF, parse_hex4((const unsigned char*)"beeF")); 51 | TEST_ASSERT_EQUAL_INT(0xBEEF, parse_hex4((const unsigned char*)"beEf")); 52 | TEST_ASSERT_EQUAL_INT(0xBEEF, parse_hex4((const unsigned char*)"beEF")); 53 | TEST_ASSERT_EQUAL_INT(0xBEEF, parse_hex4((const unsigned char*)"bEef")); 54 | TEST_ASSERT_EQUAL_INT(0xBEEF, parse_hex4((const unsigned char*)"bEeF")); 55 | TEST_ASSERT_EQUAL_INT(0xBEEF, parse_hex4((const unsigned char*)"bEEf")); 56 | TEST_ASSERT_EQUAL_INT(0xBEEF, parse_hex4((const unsigned char*)"bEEF")); 57 | TEST_ASSERT_EQUAL_INT(0xBEEF, parse_hex4((const unsigned char*)"Beef")); 58 | TEST_ASSERT_EQUAL_INT(0xBEEF, parse_hex4((const unsigned char*)"BeeF")); 59 | TEST_ASSERT_EQUAL_INT(0xBEEF, parse_hex4((const unsigned char*)"BeEf")); 60 | TEST_ASSERT_EQUAL_INT(0xBEEF, parse_hex4((const unsigned char*)"BeEF")); 61 | TEST_ASSERT_EQUAL_INT(0xBEEF, parse_hex4((const unsigned char*)"BEef")); 62 | TEST_ASSERT_EQUAL_INT(0xBEEF, parse_hex4((const unsigned char*)"BEeF")); 63 | TEST_ASSERT_EQUAL_INT(0xBEEF, parse_hex4((const unsigned char*)"BEEf")); 64 | TEST_ASSERT_EQUAL_INT(0xBEEF, parse_hex4((const unsigned char*)"BEEF")); 65 | } 66 | 67 | int main(void) 68 | { 69 | UNITY_BEGIN(); 70 | RUN_TEST(parse_hex4_should_parse_all_combinations); 71 | RUN_TEST(parse_hex4_should_parse_mixed_case); 72 | return UNITY_END(); 73 | } 74 | -------------------------------------------------------------------------------- /tests/parse_number.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009-2017 Dave Gamble and cJSON contributors 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include "unity/examples/unity_config.h" 28 | #include "unity/src/unity.h" 29 | #include "common.h" 30 | 31 | static cJSON item[1]; 32 | 33 | static void assert_is_number(cJSON *number_item) 34 | { 35 | TEST_ASSERT_NOT_NULL_MESSAGE(number_item, "Item is NULL."); 36 | 37 | assert_not_in_list(number_item); 38 | assert_has_no_child(number_item); 39 | assert_has_type(number_item, cJSON_Number); 40 | assert_has_no_reference(number_item); 41 | assert_has_no_const_string(number_item); 42 | assert_has_no_valuestring(number_item); 43 | assert_has_no_string(number_item); 44 | } 45 | 46 | static void assert_parse_number(const char *string, int integer, double real) 47 | { 48 | TEST_ASSERT_NOT_NULL(parse_number(item, (const unsigned char*)string)); 49 | assert_is_number(item); 50 | TEST_ASSERT_EQUAL_INT(integer, item->valueint); 51 | TEST_ASSERT_EQUAL_DOUBLE(real, item->valuedouble); 52 | } 53 | 54 | static void parse_number_should_parse_zero(void) 55 | { 56 | assert_parse_number("0", 0, 0); 57 | assert_parse_number("0.0", 0, 0.0); 58 | assert_parse_number("-0", 0, -0.0); 59 | } 60 | 61 | static void parse_number_should_parse_negative_integers(void) 62 | { 63 | assert_parse_number("-1", -1, -1); 64 | assert_parse_number("-32768", -32768, -32768.0); 65 | assert_parse_number("-2147483648", (int)-2147483648.0, -2147483648.0); 66 | } 67 | 68 | static void parse_number_should_parse_positive_integers(void) 69 | { 70 | assert_parse_number("1", 1, 1); 71 | assert_parse_number("32767", 32767, 32767.0); 72 | assert_parse_number("2147483647", (int)2147483647.0, 2147483647.0); 73 | } 74 | 75 | static void parse_number_should_parse_positive_reals(void) 76 | { 77 | assert_parse_number("0.001", 0, 0.001); 78 | assert_parse_number("10e-10", 0, 10e-10); 79 | assert_parse_number("10E-10", 0, 10e-10); 80 | assert_parse_number("10e10", INT_MAX, 10e10); 81 | assert_parse_number("123e+127", INT_MAX, 123e127); 82 | assert_parse_number("123e-128", 0, 123e-128); 83 | } 84 | 85 | static void parse_number_should_parse_negative_reals(void) 86 | { 87 | assert_parse_number("-0.001", 0, -0.001); 88 | assert_parse_number("-10e-10", 0, -10e-10); 89 | assert_parse_number("-10E-10", 0, -10e-10); 90 | assert_parse_number("-10e20", INT_MIN, -10e20); 91 | assert_parse_number("-123e+127", INT_MIN, -123e127); 92 | assert_parse_number("-123e-128", 0, -123e-128); 93 | } 94 | 95 | int main(void) 96 | { 97 | /* initialize cJSON item */ 98 | memset(item, 0, sizeof(cJSON)); 99 | UNITY_BEGIN(); 100 | RUN_TEST(parse_number_should_parse_zero); 101 | RUN_TEST(parse_number_should_parse_negative_integers); 102 | RUN_TEST(parse_number_should_parse_positive_integers); 103 | RUN_TEST(parse_number_should_parse_positive_reals); 104 | RUN_TEST(parse_number_should_parse_negative_reals); 105 | return UNITY_END(); 106 | } 107 | -------------------------------------------------------------------------------- /tests/parse_string.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009-2017 Dave Gamble and cJSON contributors 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include "unity/examples/unity_config.h" 28 | #include "unity/src/unity.h" 29 | #include "common.h" 30 | 31 | static cJSON item[1]; 32 | 33 | static const unsigned char *error_pointer = NULL; 34 | 35 | static void assert_is_string(cJSON *string_item) 36 | { 37 | TEST_ASSERT_NOT_NULL_MESSAGE(string_item, "Item is NULL."); 38 | 39 | assert_not_in_list(string_item); 40 | assert_has_no_child(string_item); 41 | assert_has_type(string_item, cJSON_String); 42 | assert_has_no_reference(string_item); 43 | assert_has_no_const_string(string_item); 44 | assert_has_valuestring(string_item); 45 | assert_has_no_string(string_item); 46 | } 47 | 48 | static void assert_parse_string(const char *string, const char *expected) 49 | { 50 | TEST_ASSERT_NOT_NULL_MESSAGE(parse_string(item, (const unsigned char*)string, &error_pointer), "Couldn't parse string."); 51 | assert_is_string(item); 52 | TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, item->valuestring, "The parsed result isn't as expected."); 53 | cJSON_free(item->valuestring); 54 | item->valuestring = NULL; 55 | } 56 | 57 | #define assert_not_parse_string(string) \ 58 | TEST_ASSERT_NULL_MESSAGE(parse_string(item, (const unsigned char*)string, &error_pointer), "Malformed string should not be accepted");\ 59 | assert_is_invalid(item) 60 | 61 | 62 | 63 | static void parse_string_should_parse_strings(void) 64 | { 65 | assert_parse_string("\"\"", ""); 66 | assert_parse_string( 67 | "\" !\\\"#$%&'()*+,-./\\/0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_'abcdefghijklmnopqrstuvwxyz{|}~\"", 68 | " !\"#$%&'()*+,-.//0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_'abcdefghijklmnopqrstuvwxyz{|}~"); 69 | assert_parse_string( 70 | "\"\\\"\\\\\\/\\b\\f\\n\\r\\t\\u20AC\\u732b\"", 71 | "\"\\/\b\f\n\r\t€猫"); 72 | reset(item); 73 | assert_parse_string("\"\b\f\n\r\t\"", "\b\f\n\r\t"); 74 | reset(item); 75 | } 76 | 77 | static void parse_string_should_parse_utf16_surrogate_pairs(void) 78 | { 79 | assert_parse_string("\"\\uD83D\\udc31\"", "🐱"); 80 | reset(item); 81 | } 82 | 83 | static void parse_string_should_not_parse_non_strings(void) 84 | { 85 | assert_not_parse_string("this\" is not a string\""); 86 | reset(item); 87 | assert_not_parse_string(""); 88 | reset(item); 89 | } 90 | 91 | static void parse_string_should_not_parse_invalid_backslash(void) 92 | { 93 | assert_not_parse_string("Abcdef\\123"); 94 | reset(item); 95 | assert_not_parse_string("Abcdef\\e23"); 96 | reset(item); 97 | } 98 | 99 | static void parse_string_should_not_overflow_with_closing_backslash(void) 100 | { 101 | assert_not_parse_string("\"000000000000000000\\"); 102 | reset(item); 103 | } 104 | 105 | static void parse_string_should_parse_bug_94(void) 106 | { 107 | const char string[] = "\"~!@\\\\#$%^&*()\\\\\\\\-\\\\+{}[]:\\\\;\\\\\\\"\\\\<\\\\>?/.,DC=ad,DC=com\""; 108 | assert_parse_string(string, "~!@\\#$%^&*()\\\\-\\+{}[]:\\;\\\"\\<\\>?/.,DC=ad,DC=com"); 109 | reset(item); 110 | } 111 | 112 | int main(void) 113 | { 114 | /* initialize cJSON item and error pointer */ 115 | memset(item, 0, sizeof(cJSON)); 116 | 117 | UNITY_BEGIN(); 118 | RUN_TEST(parse_string_should_parse_strings); 119 | RUN_TEST(parse_string_should_parse_utf16_surrogate_pairs); 120 | RUN_TEST(parse_string_should_not_parse_non_strings); 121 | RUN_TEST(parse_string_should_not_parse_invalid_backslash); 122 | RUN_TEST(parse_string_should_parse_bug_94); 123 | RUN_TEST(parse_string_should_not_overflow_with_closing_backslash); 124 | return UNITY_END(); 125 | } 126 | -------------------------------------------------------------------------------- /tests/parse_value.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009-2017 Dave Gamble and cJSON contributors 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include "unity/examples/unity_config.h" 28 | #include "unity/src/unity.h" 29 | #include "common.h" 30 | 31 | static cJSON item[1]; 32 | const unsigned char *error_pointer = NULL; 33 | 34 | static void assert_is_value(cJSON *value_item, int type) 35 | { 36 | TEST_ASSERT_NOT_NULL_MESSAGE(value_item, "Item is NULL."); 37 | 38 | assert_not_in_list(value_item); 39 | assert_has_type(value_item, type); 40 | assert_has_no_reference(value_item); 41 | assert_has_no_const_string(value_item); 42 | assert_has_no_string(value_item); 43 | } 44 | 45 | static void assert_parse_value(const char *string, int type) 46 | { 47 | TEST_ASSERT_NOT_NULL(parse_value(item, (const unsigned char*)string, &error_pointer)); 48 | assert_is_value(item, type); 49 | } 50 | 51 | static void parse_value_should_parse_null(void) 52 | { 53 | assert_parse_value("null", cJSON_NULL); 54 | reset(item); 55 | } 56 | 57 | static void parse_value_should_parse_true(void) 58 | { 59 | assert_parse_value("true", cJSON_True); 60 | reset(item); 61 | } 62 | 63 | static void parse_value_should_parse_false(void) 64 | { 65 | assert_parse_value("false", cJSON_False); 66 | reset(item); 67 | } 68 | 69 | static void parse_value_should_parse_number(void) 70 | { 71 | assert_parse_value("1.5", cJSON_Number); 72 | reset(item); 73 | } 74 | 75 | static void parse_value_should_parse_string(void) 76 | { 77 | assert_parse_value("\"\"", cJSON_String); 78 | reset(item); 79 | assert_parse_value("\"hello\"", cJSON_String); 80 | reset(item); 81 | } 82 | 83 | static void parse_value_should_parse_array(void) 84 | { 85 | assert_parse_value("[]", cJSON_Array); 86 | reset(item); 87 | } 88 | 89 | static void parse_value_should_parse_object(void) 90 | { 91 | assert_parse_value("{}", cJSON_Object); 92 | reset(item); 93 | } 94 | 95 | int main(void) 96 | { 97 | /* initialize cJSON item */ 98 | memset(item, 0, sizeof(cJSON)); 99 | UNITY_BEGIN(); 100 | RUN_TEST(parse_value_should_parse_null); 101 | RUN_TEST(parse_value_should_parse_true); 102 | RUN_TEST(parse_value_should_parse_false); 103 | RUN_TEST(parse_value_should_parse_number); 104 | RUN_TEST(parse_value_should_parse_string); 105 | RUN_TEST(parse_value_should_parse_array); 106 | RUN_TEST(parse_value_should_parse_object); 107 | return UNITY_END(); 108 | } 109 | -------------------------------------------------------------------------------- /tests/unity/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | 3 | # These files are text and should be normalized (convert crlf to lf) 4 | *.rb text 5 | *.test text 6 | *.c text 7 | *.cpp text 8 | *.h text 9 | *.txt text 10 | *.yml text 11 | *.s79 text 12 | *.bat text 13 | *.xcl text 14 | *.inc text 15 | *.info text 16 | *.md text 17 | makefile text 18 | rakefile text 19 | 20 | 21 | #These files are binary and should not be normalized 22 | *.doc binary 23 | *.odt binary 24 | *.pdf binary 25 | *.ewd binary 26 | *.eww binary 27 | *.dni binary 28 | *.wsdt binary 29 | *.dbgdt binary 30 | *.mac binary 31 | -------------------------------------------------------------------------------- /tests/unity/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | test/sandbox 3 | .DS_Store 4 | examples/example_1/test1.exe 5 | examples/example_1/test2.exe 6 | examples/example_2/all_tests.exe 7 | examples/example_1/test1.out 8 | examples/example_1/test2.out 9 | examples/example_2/all_tests.out 10 | -------------------------------------------------------------------------------- /tests/unity/.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | 3 | matrix: 4 | include: 5 | - os: osx 6 | compiler: clang 7 | osx_image: xcode7.3 8 | - os: linux 9 | dist: trusty 10 | compiler: gcc 11 | 12 | before_install: 13 | - if [ "$TRAVIS_OS_NAME" == "osx" ]; then rvm install 2.1 && rvm use 2.1 && ruby -v; fi 14 | - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install --assume-yes --quiet gcc-multilib; fi 15 | install: gem install rspec 16 | script: 17 | - cd test && rake ci 18 | - make -s 19 | - make -s DEBUG=-m32 20 | - cd ../extras/fixture/test && rake ci 21 | - make -s default noStdlibMalloc 22 | - make -s C89 23 | - cd ../../../examples/example_1 && make -s ci 24 | - cd ../example_2 && make -s ci 25 | - cd ../example_3 && rake 26 | -------------------------------------------------------------------------------- /tests/unity/auto/colour_prompt.rb: -------------------------------------------------------------------------------- 1 | # ========================================== 2 | # Unity Project - A Test Framework for C 3 | # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 4 | # [Released under MIT License. Please refer to license.txt for details] 5 | # ========================================== 6 | 7 | if RUBY_PLATFORM =~/(win|w)32$/ 8 | begin 9 | require 'Win32API' 10 | rescue LoadError 11 | puts "ERROR! \"Win32API\" library not found" 12 | puts "\"Win32API\" is required for colour on a windows machine" 13 | puts " try => \"gem install Win32API\" on the command line" 14 | puts 15 | end 16 | # puts 17 | # puts 'Windows Environment Detected...' 18 | # puts 'Win32API Library Found.' 19 | # puts 20 | end 21 | 22 | class ColourCommandLine 23 | def initialize 24 | if RUBY_PLATFORM =~/(win|w)32$/ 25 | get_std_handle = Win32API.new("kernel32", "GetStdHandle", ['L'], 'L') 26 | @set_console_txt_attrb = 27 | Win32API.new("kernel32","SetConsoleTextAttribute",['L','N'], 'I') 28 | @hout = get_std_handle.call(-11) 29 | end 30 | end 31 | 32 | def change_to(new_colour) 33 | if RUBY_PLATFORM =~/(win|w)32$/ 34 | @set_console_txt_attrb.call(@hout,self.win32_colour(new_colour)) 35 | else 36 | "\033[30;#{posix_colour(new_colour)};22m" 37 | end 38 | end 39 | 40 | def win32_colour(colour) 41 | case colour 42 | when :black then 0 43 | when :dark_blue then 1 44 | when :dark_green then 2 45 | when :dark_cyan then 3 46 | when :dark_red then 4 47 | when :dark_purple then 5 48 | when :dark_yellow, :narrative then 6 49 | when :default_white, :default, :dark_white then 7 50 | when :silver then 8 51 | when :blue then 9 52 | when :green, :success then 10 53 | when :cyan, :output then 11 54 | when :red, :failure then 12 55 | when :purple then 13 56 | when :yellow then 14 57 | when :white then 15 58 | else 59 | 0 60 | end 61 | end 62 | 63 | def posix_colour(colour) 64 | # ANSI Escape Codes - Foreground colors 65 | # | Code | Color | 66 | # | 39 | Default foreground color | 67 | # | 30 | Black | 68 | # | 31 | Red | 69 | # | 32 | Green | 70 | # | 33 | Yellow | 71 | # | 34 | Blue | 72 | # | 35 | Magenta | 73 | # | 36 | Cyan | 74 | # | 37 | Light gray | 75 | # | 90 | Dark gray | 76 | # | 91 | Light red | 77 | # | 92 | Light green | 78 | # | 93 | Light yellow | 79 | # | 94 | Light blue | 80 | # | 95 | Light magenta | 81 | # | 96 | Light cyan | 82 | # | 97 | White | 83 | 84 | case colour 85 | when :black then 30 86 | when :red, :failure then 31 87 | when :green, :success then 32 88 | when :yellow then 33 89 | when :blue, :narrative then 34 90 | when :purple, :magenta then 35 91 | when :cyan, :output then 36 92 | when :white, :default_white then 37 93 | when :default then 39 94 | else 95 | 39 96 | end 97 | end 98 | 99 | def out_c(mode, colour, str) 100 | case RUBY_PLATFORM 101 | when /(win|w)32$/ 102 | change_to(colour) 103 | $stdout.puts str if mode == :puts 104 | $stdout.print str if mode == :print 105 | change_to(:default_white) 106 | else 107 | $stdout.puts("#{change_to(colour)}#{str}\033[0m") if mode == :puts 108 | $stdout.print("#{change_to(colour)}#{str}\033[0m") if mode == :print 109 | end 110 | end 111 | end # ColourCommandLine 112 | 113 | def colour_puts(role,str) ColourCommandLine.new.out_c(:puts, role, str) end 114 | def colour_print(role,str) ColourCommandLine.new.out_c(:print, role, str) end 115 | 116 | -------------------------------------------------------------------------------- /tests/unity/auto/colour_reporter.rb: -------------------------------------------------------------------------------- 1 | # ========================================== 2 | # Unity Project - A Test Framework for C 3 | # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 4 | # [Released under MIT License. Please refer to license.txt for details] 5 | # ========================================== 6 | 7 | require "#{File.expand_path(File.dirname(__FILE__))}/colour_prompt" 8 | 9 | $colour_output = true 10 | 11 | def report(message) 12 | if not $colour_output 13 | $stdout.puts(message) 14 | else 15 | message = message.join('\n') if (message.class == Array) 16 | message.each_line do |line| 17 | line.chomp! 18 | colour = case(line) 19 | when /(?:total\s+)?tests:?\s+(\d+)\s+(?:total\s+)?failures:?\s+\d+\s+Ignored:?/i 20 | ($1.to_i == 0) ? :green : :red 21 | when /PASS/ 22 | :green 23 | when /^OK$/ 24 | :green 25 | when /(?:FAIL|ERROR)/ 26 | :red 27 | when /IGNORE/ 28 | :yellow 29 | when /^(?:Creating|Compiling|Linking)/ 30 | :white 31 | else 32 | :silver 33 | end 34 | colour_puts(colour, line) 35 | end 36 | end 37 | $stdout.flush 38 | $stderr.flush 39 | end -------------------------------------------------------------------------------- /tests/unity/auto/generate_config.yml: -------------------------------------------------------------------------------- 1 | #this is a sample configuration file for generate_module 2 | #you would use it by calling generate_module with the -ygenerate_config.yml option 3 | #files like this are useful for customizing generate_module to your environment 4 | :generate_module: 5 | :defaults: 6 | #these defaults are used in place of any missing options at the command line 7 | :path_src: ../src/ 8 | :path_inc: ../src/ 9 | :path_tst: ../test/ 10 | :update_svn: true 11 | :includes: 12 | #use [] for no additional includes, otherwise list the includes on separate lines 13 | :src: 14 | - Defs.h 15 | - Board.h 16 | :inc: [] 17 | :tst: 18 | - Defs.h 19 | - Board.h 20 | - Exception.h 21 | :boilerplates: 22 | #these are inserted at the top of generated files. 23 | #just comment out or remove if not desired. 24 | #use %1$s where you would like the file name to appear (path/extension not included) 25 | :src: | 26 | //------------------------------------------- 27 | // %1$s.c 28 | //------------------------------------------- 29 | :inc: | 30 | //------------------------------------------- 31 | // %1$s.h 32 | //------------------------------------------- 33 | :tst: | 34 | //------------------------------------------- 35 | // Test%1$s.c : Units tests for %1$s.c 36 | //------------------------------------------- 37 | -------------------------------------------------------------------------------- /tests/unity/auto/test_file_filter.rb: -------------------------------------------------------------------------------- 1 | # ========================================== 2 | # Unity Project - A Test Framework for C 3 | # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 4 | # [Released under MIT License. Please refer to license.txt for details] 5 | # ========================================== 6 | 7 | require'yaml' 8 | 9 | module RakefileHelpers 10 | class TestFileFilter 11 | def initialize(all_files = false) 12 | @all_files = all_files 13 | if not @all_files == true 14 | if File.exist?('test_file_filter.yml') 15 | filters = YAML.load_file( 'test_file_filter.yml' ) 16 | @all_files, @only_files, @exclude_files = 17 | filters[:all_files], filters[:only_files], filters[:exclude_files] 18 | end 19 | end 20 | end 21 | attr_accessor :all_files, :only_files, :exclude_files 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /tests/unity/auto/type_sanitizer.rb: -------------------------------------------------------------------------------- 1 | module TypeSanitizer 2 | 3 | def self.sanitize_c_identifier(unsanitized) 4 | # convert filename to valid C identifier by replacing invalid chars with '_' 5 | return unsanitized.gsub(/[-\/\\\.\,\s]/, "_") 6 | end 7 | 8 | end 9 | -------------------------------------------------------------------------------- /tests/unity/auto/unity_test_summary.rb: -------------------------------------------------------------------------------- 1 | # ========================================== 2 | # Unity Project - A Test Framework for C 3 | # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 4 | # [Released under MIT License. Please refer to license.txt for details] 5 | # ========================================== 6 | 7 | #!/usr/bin/ruby 8 | # 9 | # unity_test_summary.rb 10 | # 11 | require 'fileutils' 12 | require 'set' 13 | 14 | class UnityTestSummary 15 | include FileUtils::Verbose 16 | 17 | attr_reader :report, :total_tests, :failures, :ignored 18 | 19 | def initialize(opts = {}) 20 | @report = '' 21 | @total_tests = 0 22 | @failures = 0 23 | @ignored = 0 24 | 25 | 26 | end 27 | 28 | def run 29 | # Clean up result file names 30 | results = @targets.map {|target| target.gsub(/\\/,'/')} 31 | 32 | # Dig through each result file, looking for details on pass/fail: 33 | failure_output = [] 34 | ignore_output = [] 35 | 36 | results.each do |result_file| 37 | lines = File.readlines(result_file).map { |line| line.chomp } 38 | if lines.length == 0 39 | raise "Empty test result file: #{result_file}" 40 | else 41 | output = get_details(result_file, lines) 42 | failure_output << output[:failures] unless output[:failures].empty? 43 | ignore_output << output[:ignores] unless output[:ignores].empty? 44 | tests,failures,ignored = parse_test_summary(lines) 45 | @total_tests += tests 46 | @failures += failures 47 | @ignored += ignored 48 | end 49 | end 50 | 51 | if @ignored > 0 52 | @report += "\n" 53 | @report += "--------------------------\n" 54 | @report += "UNITY IGNORED TEST SUMMARY\n" 55 | @report += "--------------------------\n" 56 | @report += ignore_output.flatten.join("\n") 57 | end 58 | 59 | if @failures > 0 60 | @report += "\n" 61 | @report += "--------------------------\n" 62 | @report += "UNITY FAILED TEST SUMMARY\n" 63 | @report += "--------------------------\n" 64 | @report += failure_output.flatten.join("\n") 65 | end 66 | 67 | @report += "\n" 68 | @report += "--------------------------\n" 69 | @report += "OVERALL UNITY TEST SUMMARY\n" 70 | @report += "--------------------------\n" 71 | @report += "#{@total_tests} TOTAL TESTS #{@failures} TOTAL FAILURES #{@ignored} IGNORED\n" 72 | @report += "\n" 73 | end 74 | 75 | def set_targets(target_array) 76 | @targets = target_array 77 | end 78 | 79 | def set_root_path(path) 80 | @root = path 81 | end 82 | 83 | def usage(err_msg=nil) 84 | puts "\nERROR: " 85 | puts err_msg if err_msg 86 | puts "\nUsage: unity_test_summary.rb result_file_directory/ root_path/" 87 | puts " result_file_directory - The location of your results files." 88 | puts " Defaults to current directory if not specified." 89 | puts " Should end in / if specified." 90 | puts " root_path - Helpful for producing more verbose output if using relative paths." 91 | exit 1 92 | end 93 | 94 | protected 95 | 96 | def get_details(result_file, lines) 97 | results = { :failures => [], :ignores => [], :successes => [] } 98 | lines.each do |line| 99 | src_file,src_line,test_name,status,msg = line.split(/:/) 100 | line_out = ((@root && (@root != 0)) ? "#{@root}#{line}" : line ).gsub(/\//, "\\") 101 | case(status) 102 | when 'IGNORE' then results[:ignores] << line_out 103 | when 'FAIL' then results[:failures] << line_out 104 | when 'PASS' then results[:successes] << line_out 105 | end 106 | end 107 | return results 108 | end 109 | 110 | def parse_test_summary(summary) 111 | if summary.find { |v| v =~ /(\d+) Tests (\d+) Failures (\d+) Ignored/ } 112 | [$1.to_i,$2.to_i,$3.to_i] 113 | else 114 | raise "Couldn't parse test results: #{summary}" 115 | end 116 | end 117 | 118 | def here; File.expand_path(File.dirname(__FILE__)); end 119 | 120 | end 121 | 122 | if $0 == __FILE__ 123 | 124 | #parse out the command options 125 | opts, args = ARGV.partition {|v| v =~ /^--\w+/} 126 | opts.map! {|v| v[2..-1].to_sym } 127 | 128 | #create an instance to work with 129 | uts = UnityTestSummary.new(opts) 130 | 131 | begin 132 | #look in the specified or current directory for result files 133 | args[0] ||= './' 134 | targets = "#{ARGV[0].gsub(/\\/, '/')}**/*.test*" 135 | results = Dir[targets] 136 | raise "No *.testpass, *.testfail, or *.testresults files found in '#{targets}'" if results.empty? 137 | uts.set_targets(results) 138 | 139 | #set the root path 140 | args[1] ||= Dir.pwd + '/' 141 | uts.set_root_path(ARGV[1]) 142 | 143 | #run the summarizer 144 | puts uts.run 145 | rescue Exception => e 146 | uts.usage e.message 147 | end 148 | end 149 | -------------------------------------------------------------------------------- /tests/unity/docs/UnityAssertionsCheatSheetSuitableforPrintingandPossiblyFraming.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arnoldlu/cJSON/324b3dc593f85239a2171eb4ce04eb49970fa965/tests/unity/docs/UnityAssertionsCheatSheetSuitableforPrintingandPossiblyFraming.pdf -------------------------------------------------------------------------------- /tests/unity/docs/UnityAssertionsReference.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arnoldlu/cJSON/324b3dc593f85239a2171eb4ce04eb49970fa965/tests/unity/docs/UnityAssertionsReference.pdf -------------------------------------------------------------------------------- /tests/unity/docs/UnityConfigurationGuide.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arnoldlu/cJSON/324b3dc593f85239a2171eb4ce04eb49970fa965/tests/unity/docs/UnityConfigurationGuide.pdf -------------------------------------------------------------------------------- /tests/unity/docs/UnityGettingStartedGuide.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arnoldlu/cJSON/324b3dc593f85239a2171eb4ce04eb49970fa965/tests/unity/docs/UnityGettingStartedGuide.pdf -------------------------------------------------------------------------------- /tests/unity/docs/UnityHelperScriptsGuide.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arnoldlu/cJSON/324b3dc593f85239a2171eb4ce04eb49970fa965/tests/unity/docs/UnityHelperScriptsGuide.pdf -------------------------------------------------------------------------------- /tests/unity/docs/license.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2007-14 Mike Karlesky, Mark VanderVoord, Greg Williams 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /tests/unity/examples/example_1/makefile: -------------------------------------------------------------------------------- 1 | # ========================================== 2 | # Unity Project - A Test Framework for C 3 | # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 4 | # [Released under MIT License. Please refer to license.txt for details] 5 | # ========================================== 6 | 7 | #We try to detect the OS we are running on, and adjust commands as needed 8 | ifeq ($(OS),Windows_NT) 9 | ifeq ($(shell uname -s),) # not in a bash-like shell 10 | CLEANUP = del /F /Q 11 | MKDIR = mkdir 12 | else # in a bash-like shell, like msys 13 | CLEANUP = rm -f 14 | MKDIR = mkdir -p 15 | endif 16 | TARGET_EXTENSION=.exe 17 | else 18 | CLEANUP = rm -f 19 | MKDIR = mkdir -p 20 | TARGET_EXTENSION=.out 21 | endif 22 | 23 | C_COMPILER=gcc 24 | ifeq ($(shell uname -s), Darwin) 25 | C_COMPILER=clang 26 | endif 27 | 28 | UNITY_ROOT=../.. 29 | 30 | CFLAGS=-std=c89 31 | CFLAGS += -Wall 32 | CFLAGS += -Wextra 33 | CFLAGS += -Wpointer-arith 34 | CFLAGS += -Wcast-align 35 | CFLAGS += -Wwrite-strings 36 | CFLAGS += -Wswitch-default 37 | CFLAGS += -Wunreachable-code 38 | CFLAGS += -Winit-self 39 | CFLAGS += -Wmissing-field-initializers 40 | CFLAGS += -Wno-unknown-pragmas 41 | CFLAGS += -Wstrict-prototypes 42 | CFLAGS += -Wundef 43 | CFLAGS += -Wold-style-definition 44 | 45 | TARGET_BASE1=test1 46 | TARGET_BASE2=test2 47 | TARGET1 = $(TARGET_BASE1)$(TARGET_EXTENSION) 48 | TARGET2 = $(TARGET_BASE2)$(TARGET_EXTENSION) 49 | SRC_FILES1=$(UNITY_ROOT)/src/unity.c src/ProductionCode.c test/TestProductionCode.c test/test_runners/TestProductionCode_Runner.c 50 | SRC_FILES2=$(UNITY_ROOT)/src/unity.c src/ProductionCode2.c test/TestProductionCode2.c test/test_runners/TestProductionCode2_Runner.c 51 | INC_DIRS=-Isrc -I$(UNITY_ROOT)/src 52 | SYMBOLS= 53 | 54 | all: clean default 55 | 56 | default: $(SRC_FILES1) $(SRC_FILES2) 57 | $(C_COMPILER) $(CFLAGS) $(INC_DIRS) $(SYMBOLS) $(SRC_FILES1) -o $(TARGET1) 58 | $(C_COMPILER) $(CFLAGS) $(INC_DIRS) $(SYMBOLS) $(SRC_FILES2) -o $(TARGET2) 59 | - ./$(TARGET1) 60 | ./$(TARGET2) 61 | 62 | test/test_runners/TestProductionCode_Runner.c: test/TestProductionCode.c 63 | ruby $(UNITY_ROOT)/auto/generate_test_runner.rb test/TestProductionCode.c test/test_runners/TestProductionCode_Runner.c 64 | test/test_runners/TestProductionCode2_Runner.c: test/TestProductionCode2.c 65 | ruby $(UNITY_ROOT)/auto/generate_test_runner.rb test/TestProductionCode2.c test/test_runners/TestProductionCode2_Runner.c 66 | 67 | clean: 68 | $(CLEANUP) $(TARGET1) $(TARGET2) 69 | 70 | ci: CFLAGS += -Werror 71 | ci: default 72 | -------------------------------------------------------------------------------- /tests/unity/examples/example_1/readme.txt: -------------------------------------------------------------------------------- 1 | Example 1 2 | ========= 3 | 4 | Close to the simplest possible example of Unity, using only basic features. 5 | Run make to build & run the example tests. -------------------------------------------------------------------------------- /tests/unity/examples/example_1/src/ProductionCode.c: -------------------------------------------------------------------------------- 1 | 2 | #include "ProductionCode.h" 3 | 4 | int Counter = 0; 5 | int NumbersToFind[9] = { 0, 34, 55, 66, 32, 11, 1, 77, 888 }; /* some obnoxious array to search that is 1-based indexing instead of 0. */ 6 | 7 | /* This function is supposed to search through NumbersToFind and find a particular number. 8 | * If it finds it, the index is returned. Otherwise 0 is returned which sorta makes sense since 9 | * NumbersToFind is indexed from 1. Unfortunately it's broken 10 | * (and should therefore be caught by our tests) */ 11 | int FindFunction_WhichIsBroken(int NumberToFind) 12 | { 13 | int i = 0; 14 | while (i <= 8) /* Notice I should have been in braces */ 15 | i++; 16 | if (NumbersToFind[i] == NumberToFind) /* Yikes! I'm getting run after the loop finishes instead of during it! */ 17 | return i; 18 | return 0; 19 | } 20 | 21 | int FunctionWhichReturnsLocalVariable(void) 22 | { 23 | return Counter; 24 | } 25 | -------------------------------------------------------------------------------- /tests/unity/examples/example_1/src/ProductionCode.h: -------------------------------------------------------------------------------- 1 | 2 | int FindFunction_WhichIsBroken(int NumberToFind); 3 | int FunctionWhichReturnsLocalVariable(void); 4 | -------------------------------------------------------------------------------- /tests/unity/examples/example_1/src/ProductionCode2.c: -------------------------------------------------------------------------------- 1 | 2 | #include "ProductionCode2.h" 3 | 4 | char* ThisFunctionHasNotBeenTested(int Poor, char* LittleFunction) 5 | { 6 | (void)Poor; 7 | (void)LittleFunction; 8 | /* Since There Are No Tests Yet, This Function Could Be Empty For All We Know. 9 | * Which isn't terribly useful... but at least we put in a TEST_IGNORE so we won't forget */ 10 | return (char*)0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/unity/examples/example_1/src/ProductionCode2.h: -------------------------------------------------------------------------------- 1 | 2 | char* ThisFunctionHasNotBeenTested(int Poor, char* LittleFunction); 3 | -------------------------------------------------------------------------------- /tests/unity/examples/example_1/test/TestProductionCode.c: -------------------------------------------------------------------------------- 1 | 2 | #include "ProductionCode.h" 3 | #include "unity.h" 4 | 5 | /* sometimes you may want to get at local data in a module. 6 | * for example: If you plan to pass by reference, this could be useful 7 | * however, it should often be avoided */ 8 | extern int Counter; 9 | 10 | void setUp(void) 11 | { 12 | /* This is run before EACH TEST */ 13 | Counter = 0x5a5a; 14 | } 15 | 16 | void tearDown(void) 17 | { 18 | } 19 | 20 | void test_FindFunction_WhichIsBroken_ShouldReturnZeroIfItemIsNotInList_WhichWorksEvenInOurBrokenCode(void) 21 | { 22 | /* All of these should pass */ 23 | TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(78)); 24 | TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(1)); 25 | TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(33)); 26 | TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(999)); 27 | TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(-1)); 28 | } 29 | 30 | void test_FindFunction_WhichIsBroken_ShouldReturnTheIndexForItemsInList_WhichWillFailBecauseOurFunctionUnderTestIsBroken(void) 31 | { 32 | /* You should see this line fail in your test summary */ 33 | TEST_ASSERT_EQUAL(1, FindFunction_WhichIsBroken(34)); 34 | 35 | /* Notice the rest of these didn't get a chance to run because the line above failed. 36 | * Unit tests abort each test function on the first sign of trouble. 37 | * Then NEXT test function runs as normal. */ 38 | TEST_ASSERT_EQUAL(8, FindFunction_WhichIsBroken(8888)); 39 | } 40 | 41 | void test_FunctionWhichReturnsLocalVariable_ShouldReturnTheCurrentCounterValue(void) 42 | { 43 | /* This should be true because setUp set this up for us before this test */ 44 | TEST_ASSERT_EQUAL_HEX(0x5a5a, FunctionWhichReturnsLocalVariable()); 45 | 46 | /* This should be true because we can still change our answer */ 47 | Counter = 0x1234; 48 | TEST_ASSERT_EQUAL_HEX(0x1234, FunctionWhichReturnsLocalVariable()); 49 | } 50 | 51 | void test_FunctionWhichReturnsLocalVariable_ShouldReturnTheCurrentCounterValueAgain(void) 52 | { 53 | /* This should be true again because setup was rerun before this test (and after we changed it to 0x1234) */ 54 | TEST_ASSERT_EQUAL_HEX(0x5a5a, FunctionWhichReturnsLocalVariable()); 55 | } 56 | 57 | void test_FunctionWhichReturnsLocalVariable_ShouldReturnCurrentCounter_ButFailsBecauseThisTestIsActuallyFlawed(void) 58 | { 59 | /* Sometimes you get the test wrong. When that happens, you get a failure too... and a quick look should tell 60 | * you what actually happened...which in this case was a failure to setup the initial condition. */ 61 | TEST_ASSERT_EQUAL_HEX(0x1234, FunctionWhichReturnsLocalVariable()); 62 | } 63 | -------------------------------------------------------------------------------- /tests/unity/examples/example_1/test/TestProductionCode2.c: -------------------------------------------------------------------------------- 1 | 2 | #include "ProductionCode2.h" 3 | #include "unity.h" 4 | 5 | /* These should be ignored because they are commented out in various ways: 6 | #include "whatever.h" 7 | #include "somethingelse.h" 8 | */ 9 | 10 | void setUp(void) 11 | { 12 | } 13 | 14 | void tearDown(void) 15 | { 16 | } 17 | 18 | void test_IgnoredTest(void) 19 | { 20 | TEST_IGNORE_MESSAGE("This Test Was Ignored On Purpose"); 21 | } 22 | 23 | void test_AnotherIgnoredTest(void) 24 | { 25 | TEST_IGNORE_MESSAGE("These Can Be Useful For Leaving Yourself Notes On What You Need To Do Yet"); 26 | } 27 | 28 | void test_ThisFunctionHasNotBeenTested_NeedsToBeImplemented(void) 29 | { 30 | TEST_IGNORE(); /* Like This */ 31 | } 32 | -------------------------------------------------------------------------------- /tests/unity/examples/example_1/test/test_runners/TestProductionCode2_Runner.c: -------------------------------------------------------------------------------- 1 | /* AUTOGENERATED FILE. DO NOT EDIT. */ 2 | 3 | /*=======Test Runner Used To Run Each Test Below=====*/ 4 | #define RUN_TEST(TestFunc, TestLineNum) \ 5 | { \ 6 | Unity.CurrentTestName = #TestFunc; \ 7 | Unity.CurrentTestLineNumber = TestLineNum; \ 8 | Unity.NumberOfTests++; \ 9 | if (TEST_PROTECT()) \ 10 | { \ 11 | setUp(); \ 12 | TestFunc(); \ 13 | } \ 14 | if (TEST_PROTECT()) \ 15 | { \ 16 | tearDown(); \ 17 | } \ 18 | UnityConcludeTest(); \ 19 | } 20 | 21 | /*=======Automagically Detected Files To Include=====*/ 22 | #include "unity.h" 23 | #include 24 | #include 25 | #include "ProductionCode2.h" 26 | 27 | /*=======External Functions This Runner Calls=====*/ 28 | extern void setUp(void); 29 | extern void tearDown(void); 30 | extern void test_IgnoredTest(void); 31 | extern void test_AnotherIgnoredTest(void); 32 | extern void test_ThisFunctionHasNotBeenTested_NeedsToBeImplemented(void); 33 | 34 | 35 | /*=======Test Reset Option=====*/ 36 | void resetTest(void); 37 | void resetTest(void) 38 | { 39 | tearDown(); 40 | setUp(); 41 | } 42 | 43 | 44 | /*=======MAIN=====*/ 45 | int main(void) 46 | { 47 | UnityBegin("test/TestProductionCode2.c"); 48 | RUN_TEST(test_IgnoredTest, 18); 49 | RUN_TEST(test_AnotherIgnoredTest, 23); 50 | RUN_TEST(test_ThisFunctionHasNotBeenTested_NeedsToBeImplemented, 28); 51 | 52 | return (UnityEnd()); 53 | } 54 | -------------------------------------------------------------------------------- /tests/unity/examples/example_1/test/test_runners/TestProductionCode_Runner.c: -------------------------------------------------------------------------------- 1 | /* AUTOGENERATED FILE. DO NOT EDIT. */ 2 | 3 | /*=======Test Runner Used To Run Each Test Below=====*/ 4 | #define RUN_TEST(TestFunc, TestLineNum) \ 5 | { \ 6 | Unity.CurrentTestName = #TestFunc; \ 7 | Unity.CurrentTestLineNumber = TestLineNum; \ 8 | Unity.NumberOfTests++; \ 9 | if (TEST_PROTECT()) \ 10 | { \ 11 | setUp(); \ 12 | TestFunc(); \ 13 | } \ 14 | if (TEST_PROTECT()) \ 15 | { \ 16 | tearDown(); \ 17 | } \ 18 | UnityConcludeTest(); \ 19 | } 20 | 21 | /*=======Automagically Detected Files To Include=====*/ 22 | #include "unity.h" 23 | #include 24 | #include 25 | #include "ProductionCode.h" 26 | 27 | /*=======External Functions This Runner Calls=====*/ 28 | extern void setUp(void); 29 | extern void tearDown(void); 30 | extern void test_FindFunction_WhichIsBroken_ShouldReturnZeroIfItemIsNotInList_WhichWorksEvenInOurBrokenCode(void); 31 | extern void test_FindFunction_WhichIsBroken_ShouldReturnTheIndexForItemsInList_WhichWillFailBecauseOurFunctionUnderTestIsBroken(void); 32 | extern void test_FunctionWhichReturnsLocalVariable_ShouldReturnTheCurrentCounterValue(void); 33 | extern void test_FunctionWhichReturnsLocalVariable_ShouldReturnTheCurrentCounterValueAgain(void); 34 | extern void test_FunctionWhichReturnsLocalVariable_ShouldReturnCurrentCounter_ButFailsBecauseThisTestIsActuallyFlawed(void); 35 | 36 | 37 | /*=======Test Reset Option=====*/ 38 | void resetTest(void); 39 | void resetTest(void) 40 | { 41 | tearDown(); 42 | setUp(); 43 | } 44 | 45 | 46 | /*=======MAIN=====*/ 47 | int main(void) 48 | { 49 | UnityBegin("test/TestProductionCode.c"); 50 | RUN_TEST(test_FindFunction_WhichIsBroken_ShouldReturnZeroIfItemIsNotInList_WhichWorksEvenInOurBrokenCode, 20); 51 | RUN_TEST(test_FindFunction_WhichIsBroken_ShouldReturnTheIndexForItemsInList_WhichWillFailBecauseOurFunctionUnderTestIsBroken, 30); 52 | RUN_TEST(test_FunctionWhichReturnsLocalVariable_ShouldReturnTheCurrentCounterValue, 41); 53 | RUN_TEST(test_FunctionWhichReturnsLocalVariable_ShouldReturnTheCurrentCounterValueAgain, 51); 54 | RUN_TEST(test_FunctionWhichReturnsLocalVariable_ShouldReturnCurrentCounter_ButFailsBecauseThisTestIsActuallyFlawed, 57); 55 | 56 | return (UnityEnd()); 57 | } 58 | -------------------------------------------------------------------------------- /tests/unity/examples/example_2/makefile: -------------------------------------------------------------------------------- 1 | # ========================================== 2 | # Unity Project - A Test Framework for C 3 | # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 4 | # [Released under MIT License. Please refer to license.txt for details] 5 | # ========================================== 6 | 7 | #We try to detect the OS we are running on, and adjust commands as needed 8 | ifeq ($(OS),Windows_NT) 9 | ifeq ($(shell uname -s),) # not in a bash-like shell 10 | CLEANUP = del /F /Q 11 | MKDIR = mkdir 12 | else # in a bash-like shell, like msys 13 | CLEANUP = rm -f 14 | MKDIR = mkdir -p 15 | endif 16 | TARGET_EXTENSION=.exe 17 | else 18 | CLEANUP = rm -f 19 | MKDIR = mkdir -p 20 | TARGET_EXTENSION=.out 21 | endif 22 | 23 | C_COMPILER=gcc 24 | ifeq ($(shell uname -s), Darwin) 25 | C_COMPILER=clang 26 | endif 27 | 28 | UNITY_ROOT=../.. 29 | 30 | CFLAGS=-std=c99 31 | CFLAGS += -Wall 32 | CFLAGS += -Wextra 33 | CFLAGS += -Wpointer-arith 34 | CFLAGS += -Wcast-align 35 | CFLAGS += -Wwrite-strings 36 | CFLAGS += -Wswitch-default 37 | CFLAGS += -Wunreachable-code 38 | CFLAGS += -Winit-self 39 | CFLAGS += -Wmissing-field-initializers 40 | CFLAGS += -Wno-unknown-pragmas 41 | CFLAGS += -Wstrict-prototypes 42 | CFLAGS += -Wundef 43 | CFLAGS += -Wold-style-definition 44 | 45 | TARGET_BASE1=all_tests 46 | TARGET1 = $(TARGET_BASE1)$(TARGET_EXTENSION) 47 | SRC_FILES1=\ 48 | $(UNITY_ROOT)/src/unity.c \ 49 | $(UNITY_ROOT)/extras/fixture/src/unity_fixture.c \ 50 | src/ProductionCode.c \ 51 | src/ProductionCode2.c \ 52 | test/TestProductionCode.c \ 53 | test/TestProductionCode2.c \ 54 | test/test_runners/TestProductionCode_Runner.c \ 55 | test/test_runners/TestProductionCode2_Runner.c \ 56 | test/test_runners/all_tests.c 57 | INC_DIRS=-Isrc -I$(UNITY_ROOT)/src -I$(UNITY_ROOT)/extras/fixture/src 58 | SYMBOLS= 59 | 60 | all: clean default 61 | 62 | default: 63 | $(C_COMPILER) $(CFLAGS) $(INC_DIRS) $(SYMBOLS) $(SRC_FILES1) -o $(TARGET1) 64 | - ./$(TARGET1) -v 65 | 66 | clean: 67 | $(CLEANUP) $(TARGET1) 68 | 69 | ci: CFLAGS += -Werror 70 | ci: default 71 | -------------------------------------------------------------------------------- /tests/unity/examples/example_2/readme.txt: -------------------------------------------------------------------------------- 1 | Example 2 2 | ========= 3 | 4 | Same as the first example, but now using Unity's test fixture to group tests 5 | together. Using the test fixture also makes writing test runners much easier. -------------------------------------------------------------------------------- /tests/unity/examples/example_2/src/ProductionCode.c: -------------------------------------------------------------------------------- 1 | 2 | #include "ProductionCode.h" 3 | 4 | int Counter = 0; 5 | int NumbersToFind[9] = { 0, 34, 55, 66, 32, 11, 1, 77, 888 }; //some obnoxious array to search that is 1-based indexing instead of 0. 6 | 7 | // This function is supposed to search through NumbersToFind and find a particular number. 8 | // If it finds it, the index is returned. Otherwise 0 is returned which sorta makes sense since 9 | // NumbersToFind is indexed from 1. Unfortunately it's broken 10 | // (and should therefore be caught by our tests) 11 | int FindFunction_WhichIsBroken(int NumberToFind) 12 | { 13 | int i = 0; 14 | while (i <= 8) //Notice I should have been in braces 15 | i++; 16 | if (NumbersToFind[i] == NumberToFind) //Yikes! I'm getting run after the loop finishes instead of during it! 17 | return i; 18 | return 0; 19 | } 20 | 21 | int FunctionWhichReturnsLocalVariable(void) 22 | { 23 | return Counter; 24 | } 25 | -------------------------------------------------------------------------------- /tests/unity/examples/example_2/src/ProductionCode.h: -------------------------------------------------------------------------------- 1 | 2 | int FindFunction_WhichIsBroken(int NumberToFind); 3 | int FunctionWhichReturnsLocalVariable(void); 4 | -------------------------------------------------------------------------------- /tests/unity/examples/example_2/src/ProductionCode2.c: -------------------------------------------------------------------------------- 1 | 2 | #include "ProductionCode2.h" 3 | 4 | char* ThisFunctionHasNotBeenTested(int Poor, char* LittleFunction) 5 | { 6 | (void)Poor; 7 | (void)LittleFunction; 8 | //Since There Are No Tests Yet, This Function Could Be Empty For All We Know. 9 | // Which isn't terribly useful... but at least we put in a TEST_IGNORE so we won't forget 10 | return (char*)0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/unity/examples/example_2/src/ProductionCode2.h: -------------------------------------------------------------------------------- 1 | 2 | char* ThisFunctionHasNotBeenTested(int Poor, char* LittleFunction); 3 | -------------------------------------------------------------------------------- /tests/unity/examples/example_2/test/TestProductionCode.c: -------------------------------------------------------------------------------- 1 | #include "ProductionCode.h" 2 | #include "unity.h" 3 | #include "unity_fixture.h" 4 | 5 | TEST_GROUP(ProductionCode); 6 | 7 | //sometimes you may want to get at local data in a module. 8 | //for example: If you plan to pass by reference, this could be useful 9 | //however, it should often be avoided 10 | extern int Counter; 11 | 12 | TEST_SETUP(ProductionCode) 13 | { 14 | //This is run before EACH TEST 15 | Counter = 0x5a5a; 16 | } 17 | 18 | TEST_TEAR_DOWN(ProductionCode) 19 | { 20 | } 21 | 22 | TEST(ProductionCode, FindFunction_WhichIsBroken_ShouldReturnZeroIfItemIsNotInList_WhichWorksEvenInOurBrokenCode) 23 | { 24 | //All of these should pass 25 | TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(78)); 26 | TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(1)); 27 | TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(33)); 28 | TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(999)); 29 | TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(-1)); 30 | } 31 | 32 | TEST(ProductionCode, FindFunction_WhichIsBroken_ShouldReturnTheIndexForItemsInList_WhichWillFailBecauseOurFunctionUnderTestIsBroken) 33 | { 34 | // You should see this line fail in your test summary 35 | TEST_ASSERT_EQUAL(1, FindFunction_WhichIsBroken(34)); 36 | 37 | // Notice the rest of these didn't get a chance to run because the line above failed. 38 | // Unit tests abort each test function on the first sign of trouble. 39 | // Then NEXT test function runs as normal. 40 | TEST_ASSERT_EQUAL(8, FindFunction_WhichIsBroken(8888)); 41 | } 42 | 43 | TEST(ProductionCode, FunctionWhichReturnsLocalVariable_ShouldReturnTheCurrentCounterValue) 44 | { 45 | //This should be true because setUp set this up for us before this test 46 | TEST_ASSERT_EQUAL_HEX(0x5a5a, FunctionWhichReturnsLocalVariable()); 47 | 48 | //This should be true because we can still change our answer 49 | Counter = 0x1234; 50 | TEST_ASSERT_EQUAL_HEX(0x1234, FunctionWhichReturnsLocalVariable()); 51 | } 52 | 53 | TEST(ProductionCode, FunctionWhichReturnsLocalVariable_ShouldReturnTheCurrentCounterValueAgain) 54 | { 55 | //This should be true again because setup was rerun before this test (and after we changed it to 0x1234) 56 | TEST_ASSERT_EQUAL_HEX(0x5a5a, FunctionWhichReturnsLocalVariable()); 57 | } 58 | 59 | TEST(ProductionCode, FunctionWhichReturnsLocalVariable_ShouldReturnCurrentCounter_ButFailsBecauseThisTestIsActuallyFlawed) 60 | { 61 | //Sometimes you get the test wrong. When that happens, you get a failure too... and a quick look should tell 62 | // you what actually happened...which in this case was a failure to setup the initial condition. 63 | TEST_ASSERT_EQUAL_HEX(0x1234, FunctionWhichReturnsLocalVariable()); 64 | } 65 | -------------------------------------------------------------------------------- /tests/unity/examples/example_2/test/TestProductionCode2.c: -------------------------------------------------------------------------------- 1 | #include "ProductionCode2.h" 2 | #include "unity.h" 3 | #include "unity_fixture.h" 4 | 5 | TEST_GROUP(ProductionCode2); 6 | 7 | /* These should be ignored because they are commented out in various ways: 8 | #include "whatever.h" 9 | */ 10 | //#include "somethingelse.h" 11 | 12 | TEST_SETUP(ProductionCode2) 13 | { 14 | } 15 | 16 | TEST_TEAR_DOWN(ProductionCode2) 17 | { 18 | } 19 | 20 | TEST(ProductionCode2, IgnoredTest) 21 | { 22 | TEST_IGNORE_MESSAGE("This Test Was Ignored On Purpose"); 23 | } 24 | 25 | TEST(ProductionCode2, AnotherIgnoredTest) 26 | { 27 | TEST_IGNORE_MESSAGE("These Can Be Useful For Leaving Yourself Notes On What You Need To Do Yet"); 28 | } 29 | 30 | TEST(ProductionCode2, ThisFunctionHasNotBeenTested_NeedsToBeImplemented) 31 | { 32 | TEST_IGNORE(); //Like This 33 | } 34 | -------------------------------------------------------------------------------- /tests/unity/examples/example_2/test/test_runners/TestProductionCode2_Runner.c: -------------------------------------------------------------------------------- 1 | #include "unity.h" 2 | #include "unity_fixture.h" 3 | 4 | TEST_GROUP_RUNNER(ProductionCode2) 5 | { 6 | RUN_TEST_CASE(ProductionCode2, IgnoredTest); 7 | RUN_TEST_CASE(ProductionCode2, AnotherIgnoredTest); 8 | RUN_TEST_CASE(ProductionCode2, ThisFunctionHasNotBeenTested_NeedsToBeImplemented); 9 | } -------------------------------------------------------------------------------- /tests/unity/examples/example_2/test/test_runners/TestProductionCode_Runner.c: -------------------------------------------------------------------------------- 1 | #include "unity.h" 2 | #include "unity_fixture.h" 3 | 4 | TEST_GROUP_RUNNER(ProductionCode) 5 | { 6 | RUN_TEST_CASE(ProductionCode, FindFunction_WhichIsBroken_ShouldReturnZeroIfItemIsNotInList_WhichWorksEvenInOurBrokenCode); 7 | RUN_TEST_CASE(ProductionCode, FindFunction_WhichIsBroken_ShouldReturnTheIndexForItemsInList_WhichWillFailBecauseOurFunctionUnderTestIsBroken); 8 | RUN_TEST_CASE(ProductionCode, FunctionWhichReturnsLocalVariable_ShouldReturnTheCurrentCounterValue); 9 | RUN_TEST_CASE(ProductionCode, FunctionWhichReturnsLocalVariable_ShouldReturnTheCurrentCounterValueAgain); 10 | RUN_TEST_CASE(ProductionCode, FunctionWhichReturnsLocalVariable_ShouldReturnCurrentCounter_ButFailsBecauseThisTestIsActuallyFlawed); 11 | } -------------------------------------------------------------------------------- /tests/unity/examples/example_2/test/test_runners/all_tests.c: -------------------------------------------------------------------------------- 1 | #include "unity_fixture.h" 2 | 3 | static void RunAllTests(void) 4 | { 5 | RUN_TEST_GROUP(ProductionCode); 6 | RUN_TEST_GROUP(ProductionCode2); 7 | } 8 | 9 | int main(int argc, const char * argv[]) 10 | { 11 | return UnityMain(argc, argv, RunAllTests); 12 | } 13 | -------------------------------------------------------------------------------- /tests/unity/examples/example_3/helper/UnityHelper.c: -------------------------------------------------------------------------------- 1 | #include "unity.h" 2 | #include "UnityHelper.h" 3 | #include 4 | #include 5 | 6 | void AssertEqualExampleStruct(const EXAMPLE_STRUCT_T expected, const EXAMPLE_STRUCT_T actual, const unsigned short line) 7 | { 8 | UNITY_TEST_ASSERT_EQUAL_INT(expected.x, actual.x, line, "Example Struct Failed For Field x"); 9 | UNITY_TEST_ASSERT_EQUAL_INT(expected.y, actual.y, line, "Example Struct Failed For Field y"); 10 | } 11 | -------------------------------------------------------------------------------- /tests/unity/examples/example_3/helper/UnityHelper.h: -------------------------------------------------------------------------------- 1 | #ifndef _TESTHELPER_H 2 | #define _TESTHELPER_H 3 | 4 | #include "Types.h" 5 | 6 | void AssertEqualExampleStruct(const EXAMPLE_STRUCT_T expected, const EXAMPLE_STRUCT_T actual, const unsigned short line); 7 | 8 | #define UNITY_TEST_ASSERT_EQUAL_EXAMPLE_STRUCT_T(expected, actual, line, message) AssertEqualExampleStruct(expected, actual, line); 9 | 10 | #define TEST_ASSERT_EQUAL_EXAMPLE_STRUCT_T(expected, actual) UNITY_TEST_ASSERT_EQUAL_EXAMPLE_STRUCT_T(expected, actual, __LINE__, NULL); 11 | 12 | #endif // _TESTHELPER_H 13 | -------------------------------------------------------------------------------- /tests/unity/examples/example_3/rakefile.rb: -------------------------------------------------------------------------------- 1 | HERE = File.expand_path(File.dirname(__FILE__)) + '/' 2 | UNITY_ROOT = File.expand_path(File.dirname(__FILE__)) + '/../..' 3 | 4 | require 'rake' 5 | require 'rake/clean' 6 | require HERE+'rakefile_helper' 7 | 8 | TEMP_DIRS = [ 9 | File.join(HERE, 'build') 10 | ] 11 | 12 | TEMP_DIRS.each do |dir| 13 | directory(dir) 14 | CLOBBER.include(dir) 15 | end 16 | 17 | task :prepare_for_tests => TEMP_DIRS 18 | 19 | include RakefileHelpers 20 | 21 | # Load default configuration, for now 22 | DEFAULT_CONFIG_FILE = 'target_gcc_32.yml' 23 | configure_toolchain(DEFAULT_CONFIG_FILE) 24 | 25 | task :unit => [:prepare_for_tests] do 26 | run_tests get_unit_test_files 27 | end 28 | 29 | desc "Generate test summary" 30 | task :summary do 31 | report_summary 32 | end 33 | 34 | desc "Build and test Unity" 35 | task :all => [:clean, :unit, :summary] 36 | task :default => [:clobber, :all] 37 | task :ci => [:default] 38 | task :cruise => [:default] 39 | 40 | desc "Load configuration" 41 | task :config, :config_file do |t, args| 42 | configure_toolchain(args[:config_file]) 43 | end 44 | -------------------------------------------------------------------------------- /tests/unity/examples/example_3/readme.txt: -------------------------------------------------------------------------------- 1 | Example 3 2 | ========= 3 | 4 | This example project gives an example of some passing, ignored, and failing tests. 5 | It's simple and meant for you to look over and get an idea for what all of this stuff does. 6 | 7 | You can build and test using rake. The rake version will let you test with gcc or a couple 8 | versions of IAR. You can tweak the yaml files to get those versions running. 9 | 10 | Ruby is required if you're using the rake version (obviously). This version shows off most of 11 | Unity's advanced features (automatically creating test runners, fancy summaries, etc.) 12 | Without ruby, you have to maintain your own test runners. Do that for a while and you'll learn 13 | why you really want to start using the Ruby tools. 14 | -------------------------------------------------------------------------------- /tests/unity/examples/example_3/src/ProductionCode.c: -------------------------------------------------------------------------------- 1 | 2 | #include "ProductionCode.h" 3 | 4 | int Counter = 0; 5 | int NumbersToFind[9] = { 0, 34, 55, 66, 32, 11, 1, 77, 888 }; //some obnoxious array to search that is 1-based indexing instead of 0. 6 | 7 | // This function is supposed to search through NumbersToFind and find a particular number. 8 | // If it finds it, the index is returned. Otherwise 0 is returned which sorta makes sense since 9 | // NumbersToFind is indexed from 1. Unfortunately it's broken 10 | // (and should therefore be caught by our tests) 11 | int FindFunction_WhichIsBroken(int NumberToFind) 12 | { 13 | int i = 0; 14 | while (i <= 8) //Notice I should have been in braces 15 | i++; 16 | if (NumbersToFind[i] == NumberToFind) //Yikes! I'm getting run after the loop finishes instead of during it! 17 | return i; 18 | return 0; 19 | } 20 | 21 | int FunctionWhichReturnsLocalVariable(void) 22 | { 23 | return Counter; 24 | } 25 | -------------------------------------------------------------------------------- /tests/unity/examples/example_3/src/ProductionCode.h: -------------------------------------------------------------------------------- 1 | 2 | int FindFunction_WhichIsBroken(int NumberToFind); 3 | int FunctionWhichReturnsLocalVariable(void); 4 | -------------------------------------------------------------------------------- /tests/unity/examples/example_3/src/ProductionCode2.c: -------------------------------------------------------------------------------- 1 | 2 | #include "ProductionCode2.h" 3 | 4 | char* ThisFunctionHasNotBeenTested(int Poor, char* LittleFunction) 5 | { 6 | (void)Poor; 7 | (void)LittleFunction; 8 | //Since There Are No Tests Yet, This Function Could Be Empty For All We Know. 9 | // Which isn't terribly useful... but at least we put in a TEST_IGNORE so we won't forget 10 | return (char*)0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/unity/examples/example_3/src/ProductionCode2.h: -------------------------------------------------------------------------------- 1 | 2 | char* ThisFunctionHasNotBeenTested(int Poor, char* LittleFunction); 3 | -------------------------------------------------------------------------------- /tests/unity/examples/example_3/target_gcc_32.yml: -------------------------------------------------------------------------------- 1 | # Copied from ~Unity/targets/gcc_32.yml 2 | unity_root: &unity_root '../..' 3 | compiler: 4 | path: gcc 5 | source_path: 'src/' 6 | unit_tests_path: &unit_tests_path 'test/' 7 | build_path: &build_path 'build/' 8 | options: 9 | - '-c' 10 | - '-m32' 11 | - '-Wall' 12 | - '-Wno-address' 13 | - '-std=c99' 14 | - '-pedantic' 15 | includes: 16 | prefix: '-I' 17 | items: 18 | - 'src/' 19 | - '../../src/' 20 | - *unit_tests_path 21 | defines: 22 | prefix: '-D' 23 | items: 24 | - UNITY_INCLUDE_DOUBLE 25 | - UNITY_SUPPORT_TEST_CASES 26 | object_files: 27 | prefix: '-o' 28 | extension: '.o' 29 | destination: *build_path 30 | linker: 31 | path: gcc 32 | options: 33 | - -lm 34 | - '-m32' 35 | includes: 36 | prefix: '-I' 37 | object_files: 38 | path: *build_path 39 | extension: '.o' 40 | bin_files: 41 | prefix: '-o' 42 | extension: '.exe' 43 | destination: *build_path 44 | colour: true 45 | :unity: 46 | :plugins: [] 47 | -------------------------------------------------------------------------------- /tests/unity/examples/example_3/test/TestProductionCode.c: -------------------------------------------------------------------------------- 1 | 2 | #include "ProductionCode.h" 3 | #include "unity.h" 4 | 5 | //sometimes you may want to get at local data in a module. 6 | //for example: If you plan to pass by reference, this could be useful 7 | //however, it should often be avoided 8 | extern int Counter; 9 | 10 | void setUp(void) 11 | { 12 | //This is run before EACH TEST 13 | Counter = 0x5a5a; 14 | } 15 | 16 | void tearDown(void) 17 | { 18 | } 19 | 20 | void test_FindFunction_WhichIsBroken_ShouldReturnZeroIfItemIsNotInList_WhichWorksEvenInOurBrokenCode(void) 21 | { 22 | //All of these should pass 23 | TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(78)); 24 | TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(1)); 25 | TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(33)); 26 | TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(999)); 27 | TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(-1)); 28 | } 29 | 30 | void test_FindFunction_WhichIsBroken_ShouldReturnTheIndexForItemsInList_WhichWillFailBecauseOurFunctionUnderTestIsBroken(void) 31 | { 32 | // You should see this line fail in your test summary 33 | TEST_ASSERT_EQUAL(1, FindFunction_WhichIsBroken(34)); 34 | 35 | // Notice the rest of these didn't get a chance to run because the line above failed. 36 | // Unit tests abort each test function on the first sign of trouble. 37 | // Then NEXT test function runs as normal. 38 | TEST_ASSERT_EQUAL(8, FindFunction_WhichIsBroken(8888)); 39 | } 40 | 41 | void test_FunctionWhichReturnsLocalVariable_ShouldReturnTheCurrentCounterValue(void) 42 | { 43 | //This should be true because setUp set this up for us before this test 44 | TEST_ASSERT_EQUAL_HEX(0x5a5a, FunctionWhichReturnsLocalVariable()); 45 | 46 | //This should be true because we can still change our answer 47 | Counter = 0x1234; 48 | TEST_ASSERT_EQUAL_HEX(0x1234, FunctionWhichReturnsLocalVariable()); 49 | } 50 | 51 | void test_FunctionWhichReturnsLocalVariable_ShouldReturnTheCurrentCounterValueAgain(void) 52 | { 53 | //This should be true again because setup was rerun before this test (and after we changed it to 0x1234) 54 | TEST_ASSERT_EQUAL_HEX(0x5a5a, FunctionWhichReturnsLocalVariable()); 55 | } 56 | 57 | void test_FunctionWhichReturnsLocalVariable_ShouldReturnCurrentCounter_ButFailsBecauseThisTestIsActuallyFlawed(void) 58 | { 59 | //Sometimes you get the test wrong. When that happens, you get a failure too... and a quick look should tell 60 | // you what actually happened...which in this case was a failure to setup the initial condition. 61 | TEST_ASSERT_EQUAL_HEX(0x1234, FunctionWhichReturnsLocalVariable()); 62 | } 63 | -------------------------------------------------------------------------------- /tests/unity/examples/example_3/test/TestProductionCode2.c: -------------------------------------------------------------------------------- 1 | 2 | #include "ProductionCode2.h" 3 | #include "unity.h" 4 | 5 | /* These should be ignored because they are commented out in various ways: 6 | #include "whatever.h" 7 | */ 8 | //#include "somethingelse.h" 9 | 10 | void setUp(void) 11 | { 12 | } 13 | 14 | void tearDown(void) 15 | { 16 | } 17 | 18 | void test_IgnoredTest(void) 19 | { 20 | TEST_IGNORE_MESSAGE("This Test Was Ignored On Purpose"); 21 | } 22 | 23 | void test_AnotherIgnoredTest(void) 24 | { 25 | TEST_IGNORE_MESSAGE("These Can Be Useful For Leaving Yourself Notes On What You Need To Do Yet"); 26 | } 27 | 28 | void test_ThisFunctionHasNotBeenTested_NeedsToBeImplemented(void) 29 | { 30 | TEST_IGNORE(); //Like This 31 | } 32 | -------------------------------------------------------------------------------- /tests/unity/extras/eclipse/error_parsers.txt: -------------------------------------------------------------------------------- 1 | Eclipse error parsers 2 | ===================== 3 | 4 | These are a godsend for extracting & quickly navigating to 5 | warnings & error messages from console output. Unforunately 6 | I don't know how to write an Eclipse plugin so you'll have 7 | to add them manually. 8 | 9 | To add a console parser to Eclipse, go to Window --> Preferences 10 | --> C/C++ --> Build --> Settings. Click on the 'Error Parsers' 11 | tab and then click the 'Add...' button. See the table below for 12 | the parser fields to add. 13 | 14 | Eclipse will only parse the console output during a build, so 15 | running your unit tests must be part of your build process. 16 | Either add this to your make/rakefile, or add it as a post- 17 | build step in your Eclipse project settings. 18 | 19 | 20 | Unity unit test error parsers 21 | ----------------------------- 22 | Severity Pattern File Line Description 23 | ------------------------------------------------------------------------------- 24 | Error (\.+)(.*?):(\d+):(.*?):FAIL: (.*) $2 $3 $5 25 | Warning (\.+)(.*?):(\d+):(.*?):IGNORE: (.*) $2 $3 $5 26 | Warning (\.+)(.*?):(\d+):(.*?):IGNORE\s*$ $2 $3 Ignored test 27 | -------------------------------------------------------------------------------- /tests/unity/extras/fixture/rakefile.rb: -------------------------------------------------------------------------------- 1 | # ========================================== 2 | # Unity Project - A Test Framework for C 3 | # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 4 | # [Released under MIT License. Please refer to license.txt for details] 5 | # ========================================== 6 | 7 | HERE = File.expand_path(File.dirname(__FILE__)) + '/' 8 | 9 | require 'rake' 10 | require 'rake/clean' 11 | require 'rake/testtask' 12 | require HERE + 'rakefile_helper' 13 | 14 | TEMP_DIRS = [ 15 | File.join(HERE, 'build') 16 | ] 17 | 18 | TEMP_DIRS.each do |dir| 19 | directory(dir) 20 | CLOBBER.include(dir) 21 | end 22 | 23 | task :prepare_for_tests => TEMP_DIRS 24 | 25 | include RakefileHelpers 26 | 27 | # Load default configuration, for now 28 | DEFAULT_CONFIG_FILE = 'gcc_auto_stdint.yml' 29 | configure_toolchain(DEFAULT_CONFIG_FILE) 30 | 31 | task :unit => [:prepare_for_tests] do 32 | run_tests 33 | end 34 | 35 | desc "Build and test Unity Framework" 36 | task :all => [:clean, :unit] 37 | task :default => [:clobber, :all] 38 | task :ci => [:no_color, :default] 39 | task :cruise => [:no_color, :default] 40 | 41 | desc "Load configuration" 42 | task :config, :config_file do |t, args| 43 | configure_toolchain(args[:config_file]) 44 | end 45 | 46 | task :no_color do 47 | $colour_output = false 48 | end 49 | -------------------------------------------------------------------------------- /tests/unity/extras/fixture/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 James Grenning and Contributed to Unity Project 2 | 3 | Unity Project - A Test Framework for C 4 | Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 5 | [Released under MIT License. Please refer to license.txt for details] 6 | 7 | This Framework is an optional add-on to Unity. By including unity_framework.h in place of unity.h, 8 | you may now work with Unity in a manner similar to CppUTest. This framework adds the concepts of 9 | test groups and gives finer control of your tests over the command line. -------------------------------------------------------------------------------- /tests/unity/extras/fixture/src/unity_fixture.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2010 James Grenning and Contributed to Unity Project 2 | * ========================================== 3 | * Unity Project - A Test Framework for C 4 | * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 5 | * [Released under MIT License. Please refer to license.txt for details] 6 | * ========================================== */ 7 | 8 | #ifndef UNITY_FIXTURE_H_ 9 | #define UNITY_FIXTURE_H_ 10 | 11 | #include "unity.h" 12 | #include "unity_internals.h" 13 | #include "unity_fixture_malloc_overrides.h" 14 | #include "unity_fixture_internals.h" 15 | 16 | int UnityMain(int argc, const char* argv[], void (*runAllTests)(void)); 17 | 18 | 19 | #define TEST_GROUP(group)\ 20 | static const char* TEST_GROUP_##group = #group 21 | 22 | #define TEST_SETUP(group) void TEST_##group##_SETUP(void);\ 23 | void TEST_##group##_SETUP(void) 24 | 25 | #define TEST_TEAR_DOWN(group) void TEST_##group##_TEAR_DOWN(void);\ 26 | void TEST_##group##_TEAR_DOWN(void) 27 | 28 | 29 | #define TEST(group, name) \ 30 | void TEST_##group##_##name##_(void);\ 31 | void TEST_##group##_##name##_run(void);\ 32 | void TEST_##group##_##name##_run(void)\ 33 | {\ 34 | UnityTestRunner(TEST_##group##_SETUP,\ 35 | TEST_##group##_##name##_,\ 36 | TEST_##group##_TEAR_DOWN,\ 37 | "TEST(" #group ", " #name ")",\ 38 | TEST_GROUP_##group, #name,\ 39 | __FILE__, __LINE__);\ 40 | }\ 41 | void TEST_##group##_##name##_(void) 42 | 43 | #define IGNORE_TEST(group, name) \ 44 | void TEST_##group##_##name##_(void);\ 45 | void TEST_##group##_##name##_run(void);\ 46 | void TEST_##group##_##name##_run(void)\ 47 | {\ 48 | UnityIgnoreTest("IGNORE_TEST(" #group ", " #name ")", TEST_GROUP_##group, #name);\ 49 | }\ 50 | void TEST_##group##_##name##_(void) 51 | 52 | /* Call this for each test, insider the group runner */ 53 | #define RUN_TEST_CASE(group, name) \ 54 | { void TEST_##group##_##name##_run(void);\ 55 | TEST_##group##_##name##_run(); } 56 | 57 | /* This goes at the bottom of each test file or in a separate c file */ 58 | #define TEST_GROUP_RUNNER(group)\ 59 | void TEST_##group##_GROUP_RUNNER(void);\ 60 | void TEST_##group##_GROUP_RUNNER(void) 61 | 62 | /* Call this from main */ 63 | #define RUN_TEST_GROUP(group)\ 64 | { void TEST_##group##_GROUP_RUNNER(void);\ 65 | TEST_##group##_GROUP_RUNNER(); } 66 | 67 | /* CppUTest Compatibility Macros */ 68 | #ifndef UNITY_EXCLUDE_CPPUTEST_ASSERTS 69 | /* Sets a pointer and automatically restores it to its old value after teardown */ 70 | #define UT_PTR_SET(ptr, newPointerValue) UnityPointer_Set((void**)&(ptr), (void*)(newPointerValue), __LINE__) 71 | #define TEST_ASSERT_POINTERS_EQUAL(expected, actual) TEST_ASSERT_EQUAL_PTR((expected), (actual)) 72 | #define TEST_ASSERT_BYTES_EQUAL(expected, actual) TEST_ASSERT_EQUAL_HEX8(0xff & (expected), 0xff & (actual)) 73 | #define FAIL(message) TEST_FAIL_MESSAGE((message)) 74 | #define CHECK(condition) TEST_ASSERT_TRUE((condition)) 75 | #define LONGS_EQUAL(expected, actual) TEST_ASSERT_EQUAL_INT((expected), (actual)) 76 | #define STRCMP_EQUAL(expected, actual) TEST_ASSERT_EQUAL_STRING((expected), (actual)) 77 | #define DOUBLES_EQUAL(expected, actual, delta) TEST_ASSERT_DOUBLE_WITHIN((delta), (expected), (actual)) 78 | #endif 79 | 80 | /* You must compile with malloc replacement, as defined in unity_fixture_malloc_overrides.h */ 81 | void UnityMalloc_MakeMallocFailAfterCount(int count); 82 | 83 | #endif /* UNITY_FIXTURE_H_ */ 84 | -------------------------------------------------------------------------------- /tests/unity/extras/fixture/src/unity_fixture_internals.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2010 James Grenning and Contributed to Unity Project 2 | * ========================================== 3 | * Unity Project - A Test Framework for C 4 | * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 5 | * [Released under MIT License. Please refer to license.txt for details] 6 | * ========================================== */ 7 | 8 | #ifndef UNITY_FIXTURE_INTERNALS_H_ 9 | #define UNITY_FIXTURE_INTERNALS_H_ 10 | 11 | #ifdef __cplusplus 12 | extern "C" 13 | { 14 | #endif 15 | 16 | struct UNITY_FIXTURE_T 17 | { 18 | int Verbose; 19 | unsigned int RepeatCount; 20 | const char* NameFilter; 21 | const char* GroupFilter; 22 | }; 23 | extern struct UNITY_FIXTURE_T UnityFixture; 24 | 25 | typedef void unityfunction(void); 26 | void UnityTestRunner(unityfunction* setup, 27 | unityfunction* body, 28 | unityfunction* teardown, 29 | const char* printableName, 30 | const char* group, 31 | const char* name, 32 | const char* file, unsigned int line); 33 | 34 | void UnityIgnoreTest(const char* printableName, const char* group, const char* name); 35 | void UnityMalloc_StartTest(void); 36 | void UnityMalloc_EndTest(void); 37 | int UnityGetCommandLineOptions(int argc, const char* argv[]); 38 | void UnityConcludeFixtureTest(void); 39 | 40 | void UnityPointer_Set(void** ptr, void* newValue, UNITY_LINE_TYPE line); 41 | void UnityPointer_UndoAllSets(void); 42 | void UnityPointer_Init(void); 43 | #ifndef UNITY_MAX_POINTERS 44 | #define UNITY_MAX_POINTERS 5 45 | #endif 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif /* UNITY_FIXTURE_INTERNALS_H_ */ 52 | -------------------------------------------------------------------------------- /tests/unity/extras/fixture/src/unity_fixture_malloc_overrides.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2010 James Grenning and Contributed to Unity Project 2 | * ========================================== 3 | * Unity Project - A Test Framework for C 4 | * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 5 | * [Released under MIT License. Please refer to license.txt for details] 6 | * ========================================== */ 7 | 8 | #ifndef UNITY_FIXTURE_MALLOC_OVERRIDES_H_ 9 | #define UNITY_FIXTURE_MALLOC_OVERRIDES_H_ 10 | 11 | #include 12 | 13 | #ifdef UNITY_EXCLUDE_STDLIB_MALLOC 14 | /* Define this macro to remove the use of stdlib.h, malloc, and free. 15 | * Many embedded systems do not have a heap or malloc/free by default. 16 | * This internal unity_malloc() provides allocated memory deterministically from 17 | * the end of an array only, unity_free() only releases from end-of-array, 18 | * blocks are not coalesced, and memory not freed in LIFO order is stranded. */ 19 | #ifndef UNITY_INTERNAL_HEAP_SIZE_BYTES 20 | #define UNITY_INTERNAL_HEAP_SIZE_BYTES 256 21 | #endif 22 | #endif 23 | 24 | /* These functions are used by the Unity Fixture to allocate and release memory 25 | * on the heap and can be overridden with platform-specific implementations. 26 | * For example, when using FreeRTOS UNITY_FIXTURE_MALLOC becomes pvPortMalloc() 27 | * and UNITY_FIXTURE_FREE becomes vPortFree(). */ 28 | #if !defined(UNITY_FIXTURE_MALLOC) || !defined(UNITY_FIXTURE_FREE) 29 | #define UNITY_FIXTURE_MALLOC(size) malloc(size) 30 | #define UNITY_FIXTURE_FREE(ptr) free(ptr) 31 | #else 32 | extern void* UNITY_FIXTURE_MALLOC(size_t size); 33 | extern void UNITY_FIXTURE_FREE(void* ptr); 34 | #endif 35 | 36 | #define malloc unity_malloc 37 | #define calloc unity_calloc 38 | #define realloc unity_realloc 39 | #define free unity_free 40 | 41 | void* unity_malloc(size_t size); 42 | void* unity_calloc(size_t num, size_t size); 43 | void* unity_realloc(void * oldMem, size_t size); 44 | void unity_free(void * mem); 45 | 46 | #endif /* UNITY_FIXTURE_MALLOC_OVERRIDES_H_ */ 47 | -------------------------------------------------------------------------------- /tests/unity/extras/fixture/test/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | ifeq ($(shell uname -s), Darwin) 3 | CC = clang 4 | endif 5 | #DEBUG = -O0 -g 6 | CFLAGS += -std=c99 -pedantic -Wall -Wextra -Werror 7 | CFLAGS += $(DEBUG) 8 | DEFINES = -D UNITY_OUTPUT_CHAR=UnityOutputCharSpy_OutputChar 9 | SRC = ../src/unity_fixture.c \ 10 | ../../../src/unity.c \ 11 | unity_fixture_Test.c \ 12 | unity_fixture_TestRunner.c \ 13 | unity_output_Spy.c \ 14 | main/AllTests.c 15 | 16 | INC_DIR = -I../src -I../../../src/ 17 | BUILD_DIR = ../build 18 | TARGET = ../build/fixture_tests.exe 19 | 20 | all: default noStdlibMalloc 32bits 21 | 22 | default: $(BUILD_DIR) 23 | $(CC) $(CFLAGS) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET) -D UNITY_SUPPORT_64 24 | @ echo "default build" 25 | ./$(TARGET) 26 | 27 | 32bits: $(BUILD_DIR) 28 | $(CC) $(CFLAGS) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET) -m32 29 | @ echo "32bits build" 30 | ./$(TARGET) 31 | 32 | noStdlibMalloc: $(BUILD_DIR) 33 | $(CC) $(CFLAGS) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET) -D UNITY_EXCLUDE_STDLIB_MALLOC 34 | @ echo "build with noStdlibMalloc" 35 | ./$(TARGET) 36 | 37 | C89: CFLAGS += -D UNITY_EXCLUDE_STDINT_H # C89 did not have type 'long long', 38 | C89: $(BUILD_DIR) 39 | $(CC) $(CFLAGS) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET) -std=c89 && ./$(TARGET) 40 | $(CC) $(CFLAGS) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET) -D UNITY_EXCLUDE_STDLIB_MALLOC -std=c89 41 | ./$(TARGET) 42 | 43 | $(BUILD_DIR): 44 | mkdir -p $(BUILD_DIR) 45 | 46 | clean: 47 | rm -f $(TARGET) $(BUILD_DIR)/*.gc* 48 | 49 | cov: $(BUILD_DIR) 50 | cd $(BUILD_DIR) && \ 51 | $(CC) $(DEFINES) $(foreach i, $(SRC), ../test/$(i)) $(INC_DIR) -o $(TARGET) -fprofile-arcs -ftest-coverage 52 | rm -f $(BUILD_DIR)/*.gcda 53 | ./$(TARGET) > /dev/null ; ./$(TARGET) -v > /dev/null 54 | cd $(BUILD_DIR) && \ 55 | gcov unity_fixture.c | head -3 56 | grep '###' $(BUILD_DIR)/unity_fixture.c.gcov -C2 || true # Show uncovered lines 57 | 58 | # These extended flags DO get included before any target build runs 59 | CFLAGS += -Wbad-function-cast 60 | CFLAGS += -Wcast-qual 61 | CFLAGS += -Wconversion 62 | CFLAGS += -Wformat=2 63 | CFLAGS += -Wmissing-prototypes 64 | CFLAGS += -Wold-style-definition 65 | CFLAGS += -Wpointer-arith 66 | CFLAGS += -Wshadow 67 | CFLAGS += -Wstrict-overflow=5 68 | CFLAGS += -Wstrict-prototypes 69 | CFLAGS += -Wswitch-default 70 | CFLAGS += -Wundef 71 | CFLAGS += -Wno-error=undef # Warning only, this should not stop the build 72 | CFLAGS += -Wunreachable-code 73 | CFLAGS += -Wunused 74 | CFLAGS += -fstrict-aliasing 75 | -------------------------------------------------------------------------------- /tests/unity/extras/fixture/test/main/AllTests.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2010 James Grenning and Contributed to Unity Project 2 | * ========================================== 3 | * Unity Project - A Test Framework for C 4 | * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 5 | * [Released under MIT License. Please refer to license.txt for details] 6 | * ========================================== */ 7 | 8 | #include "unity_fixture.h" 9 | 10 | static void runAllTests(void) 11 | { 12 | RUN_TEST_GROUP(UnityFixture); 13 | RUN_TEST_GROUP(UnityCommandOptions); 14 | RUN_TEST_GROUP(LeakDetection); 15 | RUN_TEST_GROUP(InternalMalloc); 16 | } 17 | 18 | int main(int argc, const char* argv[]) 19 | { 20 | return UnityMain(argc, argv, runAllTests); 21 | } 22 | 23 | -------------------------------------------------------------------------------- /tests/unity/extras/fixture/test/template_fixture_tests.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2010 James Grenning and Contributed to Unity Project 2 | * ========================================== 3 | * Unity Project - A Test Framework for C 4 | * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 5 | * [Released under MIT License. Please refer to license.txt for details] 6 | * ========================================== */ 7 | 8 | #include "unity_fixture.h" 9 | 10 | static int data = -1; 11 | 12 | TEST_GROUP(mygroup); 13 | 14 | TEST_SETUP(mygroup) 15 | { 16 | data = 0; 17 | } 18 | 19 | TEST_TEAR_DOWN(mygroup) 20 | { 21 | data = -1; 22 | } 23 | 24 | TEST(mygroup, test1) 25 | { 26 | TEST_ASSERT_EQUAL_INT(0, data); 27 | } 28 | 29 | TEST(mygroup, test2) 30 | { 31 | TEST_ASSERT_EQUAL_INT(0, data); 32 | data = 5; 33 | } 34 | 35 | TEST(mygroup, test3) 36 | { 37 | data = 7; 38 | TEST_ASSERT_EQUAL_INT(7, data); 39 | } 40 | -------------------------------------------------------------------------------- /tests/unity/extras/fixture/test/unity_fixture_TestRunner.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2010 James Grenning and Contributed to Unity Project 2 | * ========================================== 3 | * Unity Project - A Test Framework for C 4 | * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 5 | * [Released under MIT License. Please refer to license.txt for details] 6 | * ========================================== */ 7 | 8 | #include "unity_fixture.h" 9 | 10 | TEST_GROUP_RUNNER(UnityFixture) 11 | { 12 | RUN_TEST_CASE(UnityFixture, PointerSetting); 13 | RUN_TEST_CASE(UnityFixture, ForceMallocFail); 14 | RUN_TEST_CASE(UnityFixture, ReallocSmallerIsUnchanged); 15 | RUN_TEST_CASE(UnityFixture, ReallocSameIsUnchanged); 16 | RUN_TEST_CASE(UnityFixture, ReallocLargerNeeded); 17 | RUN_TEST_CASE(UnityFixture, ReallocNullPointerIsLikeMalloc); 18 | RUN_TEST_CASE(UnityFixture, ReallocSizeZeroFreesMemAndReturnsNullPointer); 19 | RUN_TEST_CASE(UnityFixture, CallocFillsWithZero); 20 | RUN_TEST_CASE(UnityFixture, PointerSet); 21 | RUN_TEST_CASE(UnityFixture, FreeNULLSafety); 22 | RUN_TEST_CASE(UnityFixture, ConcludeTestIncrementsFailCount); 23 | } 24 | 25 | TEST_GROUP_RUNNER(UnityCommandOptions) 26 | { 27 | RUN_TEST_CASE(UnityCommandOptions, DefaultOptions); 28 | RUN_TEST_CASE(UnityCommandOptions, OptionVerbose); 29 | RUN_TEST_CASE(UnityCommandOptions, OptionSelectTestByGroup); 30 | RUN_TEST_CASE(UnityCommandOptions, OptionSelectTestByName); 31 | RUN_TEST_CASE(UnityCommandOptions, OptionSelectRepeatTestsDefaultCount); 32 | RUN_TEST_CASE(UnityCommandOptions, OptionSelectRepeatTestsSpecificCount); 33 | RUN_TEST_CASE(UnityCommandOptions, MultipleOptions); 34 | RUN_TEST_CASE(UnityCommandOptions, MultipleOptionsDashRNotLastAndNoValueSpecified); 35 | RUN_TEST_CASE(UnityCommandOptions, UnknownCommandIsIgnored); 36 | RUN_TEST_CASE(UnityCommandOptions, GroupOrNameFilterWithoutStringFails); 37 | RUN_TEST_CASE(UnityCommandOptions, GroupFilterReallyFilters); 38 | RUN_TEST_CASE(UnityCommandOptions, TestShouldBeIgnored); 39 | } 40 | 41 | TEST_GROUP_RUNNER(LeakDetection) 42 | { 43 | RUN_TEST_CASE(LeakDetection, DetectsLeak); 44 | RUN_TEST_CASE(LeakDetection, BufferOverrunFoundDuringFree); 45 | RUN_TEST_CASE(LeakDetection, BufferOverrunFoundDuringRealloc); 46 | RUN_TEST_CASE(LeakDetection, BufferGuardWriteFoundDuringFree); 47 | RUN_TEST_CASE(LeakDetection, BufferGuardWriteFoundDuringRealloc); 48 | RUN_TEST_CASE(LeakDetection, PointerSettingMax); 49 | } 50 | 51 | TEST_GROUP_RUNNER(InternalMalloc) 52 | { 53 | RUN_TEST_CASE(InternalMalloc, MallocPastBufferFails); 54 | RUN_TEST_CASE(InternalMalloc, CallocPastBufferFails); 55 | RUN_TEST_CASE(InternalMalloc, MallocThenReallocGrowsMemoryInPlace); 56 | RUN_TEST_CASE(InternalMalloc, ReallocFailDoesNotFreeMem); 57 | } 58 | -------------------------------------------------------------------------------- /tests/unity/extras/fixture/test/unity_output_Spy.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2010 James Grenning and Contributed to Unity Project 2 | * ========================================== 3 | * Unity Project - A Test Framework for C 4 | * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 5 | * [Released under MIT License. Please refer to license.txt for details] 6 | * ========================================== */ 7 | 8 | 9 | #include "unity_output_Spy.h" 10 | #include "unity_fixture.h" 11 | 12 | #include 13 | #include 14 | 15 | static int size; 16 | static int count; 17 | static char* buffer; 18 | static int spy_enable; 19 | 20 | void UnityOutputCharSpy_Create(int s) 21 | { 22 | size = (s > 0) ? s : 0; 23 | count = 0; 24 | spy_enable = 0; 25 | buffer = malloc((size_t)size); 26 | TEST_ASSERT_NOT_NULL_MESSAGE(buffer, "Internal malloc failed in Spy Create():" __FILE__); 27 | memset(buffer, 0, (size_t)size); 28 | } 29 | 30 | void UnityOutputCharSpy_Destroy(void) 31 | { 32 | size = 0; 33 | free(buffer); 34 | } 35 | 36 | void UnityOutputCharSpy_OutputChar(int c) 37 | { 38 | if (spy_enable) 39 | { 40 | if (count < (size-1)) 41 | buffer[count++] = (char)c; 42 | } 43 | else 44 | { 45 | putchar(c); 46 | } 47 | } 48 | 49 | const char * UnityOutputCharSpy_Get(void) 50 | { 51 | return buffer; 52 | } 53 | 54 | void UnityOutputCharSpy_Enable(int enable) 55 | { 56 | spy_enable = enable; 57 | } 58 | -------------------------------------------------------------------------------- /tests/unity/extras/fixture/test/unity_output_Spy.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2010 James Grenning and Contributed to Unity Project 2 | * ========================================== 3 | * Unity Project - A Test Framework for C 4 | * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 5 | * [Released under MIT License. Please refer to license.txt for details] 6 | * ========================================== */ 7 | 8 | #ifndef D_unity_output_Spy_H 9 | #define D_unity_output_Spy_H 10 | 11 | void UnityOutputCharSpy_Create(int s); 12 | void UnityOutputCharSpy_Destroy(void); 13 | void UnityOutputCharSpy_OutputChar(int c); 14 | const char * UnityOutputCharSpy_Get(void); 15 | void UnityOutputCharSpy_Enable(int enable); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /tests/unity/release/build.info: -------------------------------------------------------------------------------- 1 | 120 2 | 3 | -------------------------------------------------------------------------------- /tests/unity/release/version.info: -------------------------------------------------------------------------------- 1 | 2.4.0 2 | 3 | -------------------------------------------------------------------------------- /tests/unity/test/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | ifeq ($(shell uname -s), Darwin) 3 | CC = clang 4 | endif 5 | ifeq ($(findstring clang, $(CC)), clang) 6 | E = -Weverything 7 | CFLAGS += $E -Wno-unknown-warning-option -Wno-missing-prototypes 8 | CFLAGS += -Wno-unused-macros -Wno-padded -Wno-missing-noreturn 9 | endif 10 | CFLAGS += -std=c99 -pedantic -Wall -Wextra -Wconversion -Werror 11 | CFLAGS += -Wno-switch-enum -Wno-double-promotion 12 | CFLAGS += -Wbad-function-cast -Wcast-qual -Wold-style-definition -Wshadow -Wstrict-overflow \ 13 | -Wstrict-prototypes -Wswitch-default -Wundef 14 | #DEBUG = -O0 -g 15 | CFLAGS += $(DEBUG) 16 | DEFINES = -D UNITY_OUTPUT_CHAR=putcharSpy 17 | DEFINES += -D UNITY_SUPPORT_64 -D UNITY_INCLUDE_DOUBLE 18 | SRC = ../src/unity.c tests/testunity.c build/testunityRunner.c 19 | INC_DIR = -I ../src 20 | COV_FLAGS = -fprofile-arcs -ftest-coverage -I ../../src 21 | BUILD_DIR = build 22 | TARGET = build/testunity-cov.exe 23 | 24 | # To generate coverage, call 'make -s', the default target runs. 25 | # For verbose output of all the tests, run 'make test'. 26 | default: coverage 27 | .PHONY: default coverage test clean 28 | coverage: DEFINES += -D UNITY_NO_WEAK 29 | coverage: $(BUILD_DIR)/testunityRunner.c 30 | cd $(BUILD_DIR) && \ 31 | $(CC) $(CFLAGS) $(DEFINES) $(foreach i,$(SRC), ../$i) $(COV_FLAGS) -o ../$(TARGET) 32 | rm -f $(BUILD_DIR)/*.gcda 33 | ./$(TARGET) | grep 'Tests\|]]]' -A1 34 | cd $(BUILD_DIR) && \ 35 | gcov unity.c | head -3 36 | grep '###' $(BUILD_DIR)/unity.c.gcov -C2 || true 37 | 38 | test: $(BUILD_DIR)/testunityRunner.c 39 | $(CC) $(CFLAGS) $(DEFINES) $(INC_DIR) $(SRC) -o $(TARGET) 40 | ./$(TARGET) 41 | 42 | # Compile only, for testing that preprocessor detection works 43 | UNITY_C_ONLY =-c ../src/unity.c -o $(BUILD_DIR)/unity.o 44 | intDetection: 45 | $(CC) $(CFLAGS) $(INC_DIR) $(UNITY_C_ONLY) -D UNITY_EXCLUDE_STDINT_H 46 | $(CC) $(CFLAGS) $(INC_DIR) $(UNITY_C_ONLY) -D UNITY_EXCLUDE_LIMITS_H 47 | 48 | $(BUILD_DIR)/testunityRunner.c: tests/testunity.c | $(BUILD_DIR) 49 | awk $(AWK_SCRIPT) tests/testunity.c > $@ 50 | 51 | AWK_SCRIPT=\ 52 | '/^void test/{ declarations[d++]=$$0; gsub(/\(?void\)? ?/,""); tests[t++]=$$0; line[u++]=NR } \ 53 | END{ print "\#include \"unity.h\" /* Autogenerated by awk in Makefile */" ; \ 54 | for (i=0; i 27 | #include 28 | #include "CException.h" 29 | #include "funky.h" 30 | #include "stanky.h" 31 | #include 32 | 33 | /*=======External Functions This Runner Calls=====*/ 34 | extern void setUp(void); 35 | extern void tearDown(void); 36 | extern void test_TheFirstThingToTest(void); 37 | extern void test_TheSecondThingToTest(void); 38 | extern void test_TheThirdThingToTest(void); 39 | extern void test_TheFourthThingToTest(void); 40 | 41 | 42 | /*=======Test Reset Option=====*/ 43 | void resetTest(void); 44 | void resetTest(void) 45 | { 46 | tearDown(); 47 | setUp(); 48 | } 49 | 50 | 51 | /*=======MAIN=====*/ 52 | int main(void) 53 | { 54 | UnityBegin("testdata/testsample.c"); 55 | RUN_TEST(test_TheFirstThingToTest, 21); 56 | RUN_TEST(test_TheSecondThingToTest, 43); 57 | RUN_TEST(test_TheThirdThingToTest, 53); 58 | RUN_TEST(test_TheFourthThingToTest, 58); 59 | 60 | return (UnityEnd()); 61 | } 62 | -------------------------------------------------------------------------------- /tests/unity/test/expectdata/testsample_def.c: -------------------------------------------------------------------------------- 1 | /* AUTOGENERATED FILE. DO NOT EDIT. */ 2 | 3 | /*=======Test Runner Used To Run Each Test Below=====*/ 4 | #define RUN_TEST(TestFunc, TestLineNum) \ 5 | { \ 6 | Unity.CurrentTestName = #TestFunc; \ 7 | Unity.CurrentTestLineNumber = TestLineNum; \ 8 | Unity.NumberOfTests++; \ 9 | if (TEST_PROTECT()) \ 10 | { \ 11 | setUp(); \ 12 | TestFunc(); \ 13 | } \ 14 | if (TEST_PROTECT() && !TEST_IS_IGNORED) \ 15 | { \ 16 | tearDown(); \ 17 | } \ 18 | UnityConcludeTest(); \ 19 | } 20 | 21 | /*=======Automagically Detected Files To Include=====*/ 22 | #include "unity.h" 23 | #include 24 | #include 25 | #include "funky.h" 26 | #include "stanky.h" 27 | #include 28 | 29 | /*=======External Functions This Runner Calls=====*/ 30 | extern void setUp(void); 31 | extern void tearDown(void); 32 | extern void test_TheFirstThingToTest(void); 33 | extern void test_TheSecondThingToTest(void); 34 | extern void test_TheThirdThingToTest(void); 35 | extern void test_TheFourthThingToTest(void); 36 | 37 | 38 | /*=======Test Reset Option=====*/ 39 | void resetTest(void); 40 | void resetTest(void) 41 | { 42 | tearDown(); 43 | setUp(); 44 | } 45 | 46 | 47 | /*=======MAIN=====*/ 48 | int main(void) 49 | { 50 | UnityBegin("testdata/testsample.c"); 51 | RUN_TEST(test_TheFirstThingToTest, 21); 52 | RUN_TEST(test_TheSecondThingToTest, 43); 53 | RUN_TEST(test_TheThirdThingToTest, 53); 54 | RUN_TEST(test_TheFourthThingToTest, 58); 55 | 56 | return (UnityEnd()); 57 | } 58 | -------------------------------------------------------------------------------- /tests/unity/test/expectdata/testsample_head1.c: -------------------------------------------------------------------------------- 1 | /* AUTOGENERATED FILE. DO NOT EDIT. */ 2 | 3 | /*=======Test Runner Used To Run Each Test Below=====*/ 4 | #define RUN_TEST(TestFunc, TestLineNum) \ 5 | { \ 6 | Unity.CurrentTestName = #TestFunc; \ 7 | Unity.CurrentTestLineNumber = TestLineNum; \ 8 | Unity.NumberOfTests++; \ 9 | if (TEST_PROTECT()) \ 10 | { \ 11 | setUp(); \ 12 | TestFunc(); \ 13 | } \ 14 | if (TEST_PROTECT() && !TEST_IS_IGNORED) \ 15 | { \ 16 | tearDown(); \ 17 | } \ 18 | UnityConcludeTest(); \ 19 | } 20 | 21 | /*=======Automagically Detected Files To Include=====*/ 22 | #include "unity.h" 23 | #include 24 | #include 25 | #include "testsample_head1.h" 26 | 27 | /*=======External Functions This Runner Calls=====*/ 28 | extern void setUp(void); 29 | extern void tearDown(void); 30 | extern void test_TheFirstThingToTest(void); 31 | extern void test_TheSecondThingToTest(void); 32 | extern void test_TheThirdThingToTest(void); 33 | extern void test_TheFourthThingToTest(void); 34 | 35 | 36 | /*=======Test Reset Option=====*/ 37 | void resetTest(void); 38 | void resetTest(void) 39 | { 40 | tearDown(); 41 | setUp(); 42 | } 43 | 44 | 45 | /*=======MAIN=====*/ 46 | int main(void) 47 | { 48 | UnityBegin("testdata/testsample.c"); 49 | RUN_TEST(test_TheFirstThingToTest, 21); 50 | RUN_TEST(test_TheSecondThingToTest, 43); 51 | RUN_TEST(test_TheThirdThingToTest, 53); 52 | RUN_TEST(test_TheFourthThingToTest, 58); 53 | 54 | return (UnityEnd()); 55 | } 56 | -------------------------------------------------------------------------------- /tests/unity/test/expectdata/testsample_head1.h: -------------------------------------------------------------------------------- 1 | /* AUTOGENERATED FILE. DO NOT EDIT. */ 2 | #ifndef _TESTSAMPLE_HEAD1_H 3 | #define _TESTSAMPLE_HEAD1_H 4 | 5 | #include "unity.h" 6 | #include "funky.h" 7 | #include "stanky.h" 8 | #include 9 | 10 | void test_TheFirstThingToTest(void); 11 | void test_TheSecondThingToTest(void); 12 | void test_TheThirdThingToTest(void); 13 | void test_TheFourthThingToTest(void); 14 | #endif 15 | 16 | -------------------------------------------------------------------------------- /tests/unity/test/expectdata/testsample_mock_cmd.c: -------------------------------------------------------------------------------- 1 | /* AUTOGENERATED FILE. DO NOT EDIT. */ 2 | 3 | /*=======Test Runner Used To Run Each Test Below=====*/ 4 | #define RUN_TEST(TestFunc, TestLineNum) \ 5 | { \ 6 | Unity.CurrentTestName = #TestFunc; \ 7 | Unity.CurrentTestLineNumber = TestLineNum; \ 8 | Unity.NumberOfTests++; \ 9 | CMock_Init(); \ 10 | UNITY_CLR_DETAILS(); \ 11 | if (TEST_PROTECT()) \ 12 | { \ 13 | CEXCEPTION_T e; \ 14 | Try { \ 15 | setUp(); \ 16 | TestFunc(); \ 17 | } Catch(e) { TEST_ASSERT_EQUAL_HEX32_MESSAGE(CEXCEPTION_NONE, e, "Unhandled Exception!"); } \ 18 | } \ 19 | if (TEST_PROTECT() && !TEST_IS_IGNORED) \ 20 | { \ 21 | tearDown(); \ 22 | CMock_Verify(); \ 23 | } \ 24 | CMock_Destroy(); \ 25 | UnityConcludeTest(); \ 26 | } 27 | 28 | /*=======Automagically Detected Files To Include=====*/ 29 | #include "unity.h" 30 | #include "cmock.h" 31 | #include 32 | #include 33 | #include "CException.h" 34 | #include "funky.h" 35 | #include 36 | #include "Mockstanky.h" 37 | 38 | /*=======External Functions This Runner Calls=====*/ 39 | extern void setUp(void); 40 | extern void tearDown(void); 41 | extern void test_TheFirstThingToTest(void); 42 | extern void test_TheSecondThingToTest(void); 43 | 44 | 45 | /*=======Mock Management=====*/ 46 | static void CMock_Init(void) 47 | { 48 | Mockstanky_Init(); 49 | } 50 | static void CMock_Verify(void) 51 | { 52 | Mockstanky_Verify(); 53 | } 54 | static void CMock_Destroy(void) 55 | { 56 | Mockstanky_Destroy(); 57 | } 58 | 59 | /*=======Test Reset Option=====*/ 60 | void resetTest(void); 61 | void resetTest(void) 62 | { 63 | CMock_Verify(); 64 | CMock_Destroy(); 65 | tearDown(); 66 | CMock_Init(); 67 | setUp(); 68 | } 69 | 70 | 71 | /*=======MAIN=====*/ 72 | int main(void) 73 | { 74 | UnityBegin("testdata/mocksample.c"); 75 | RUN_TEST(test_TheFirstThingToTest, 21); 76 | RUN_TEST(test_TheSecondThingToTest, 43); 77 | 78 | CMock_Guts_MemFreeFinal(); 79 | return (UnityEnd()); 80 | } 81 | -------------------------------------------------------------------------------- /tests/unity/test/expectdata/testsample_mock_def.c: -------------------------------------------------------------------------------- 1 | /* AUTOGENERATED FILE. DO NOT EDIT. */ 2 | 3 | /*=======Test Runner Used To Run Each Test Below=====*/ 4 | #define RUN_TEST(TestFunc, TestLineNum) \ 5 | { \ 6 | Unity.CurrentTestName = #TestFunc; \ 7 | Unity.CurrentTestLineNumber = TestLineNum; \ 8 | Unity.NumberOfTests++; \ 9 | CMock_Init(); \ 10 | UNITY_CLR_DETAILS(); \ 11 | if (TEST_PROTECT()) \ 12 | { \ 13 | setUp(); \ 14 | TestFunc(); \ 15 | } \ 16 | if (TEST_PROTECT() && !TEST_IS_IGNORED) \ 17 | { \ 18 | tearDown(); \ 19 | CMock_Verify(); \ 20 | } \ 21 | CMock_Destroy(); \ 22 | UnityConcludeTest(); \ 23 | } 24 | 25 | /*=======Automagically Detected Files To Include=====*/ 26 | #include "unity.h" 27 | #include "cmock.h" 28 | #include 29 | #include 30 | #include "funky.h" 31 | #include 32 | #include "Mockstanky.h" 33 | 34 | /*=======External Functions This Runner Calls=====*/ 35 | extern void setUp(void); 36 | extern void tearDown(void); 37 | extern void test_TheFirstThingToTest(void); 38 | extern void test_TheSecondThingToTest(void); 39 | 40 | 41 | /*=======Mock Management=====*/ 42 | static void CMock_Init(void) 43 | { 44 | Mockstanky_Init(); 45 | } 46 | static void CMock_Verify(void) 47 | { 48 | Mockstanky_Verify(); 49 | } 50 | static void CMock_Destroy(void) 51 | { 52 | Mockstanky_Destroy(); 53 | } 54 | 55 | /*=======Test Reset Option=====*/ 56 | void resetTest(void); 57 | void resetTest(void) 58 | { 59 | CMock_Verify(); 60 | CMock_Destroy(); 61 | tearDown(); 62 | CMock_Init(); 63 | setUp(); 64 | } 65 | 66 | 67 | /*=======MAIN=====*/ 68 | int main(void) 69 | { 70 | UnityBegin("testdata/mocksample.c"); 71 | RUN_TEST(test_TheFirstThingToTest, 21); 72 | RUN_TEST(test_TheSecondThingToTest, 43); 73 | 74 | CMock_Guts_MemFreeFinal(); 75 | return (UnityEnd()); 76 | } 77 | -------------------------------------------------------------------------------- /tests/unity/test/expectdata/testsample_mock_head1.c: -------------------------------------------------------------------------------- 1 | /* AUTOGENERATED FILE. DO NOT EDIT. */ 2 | 3 | /*=======Test Runner Used To Run Each Test Below=====*/ 4 | #define RUN_TEST(TestFunc, TestLineNum) \ 5 | { \ 6 | Unity.CurrentTestName = #TestFunc; \ 7 | Unity.CurrentTestLineNumber = TestLineNum; \ 8 | Unity.NumberOfTests++; \ 9 | CMock_Init(); \ 10 | UNITY_CLR_DETAILS(); \ 11 | if (TEST_PROTECT()) \ 12 | { \ 13 | setUp(); \ 14 | TestFunc(); \ 15 | } \ 16 | if (TEST_PROTECT() && !TEST_IS_IGNORED) \ 17 | { \ 18 | tearDown(); \ 19 | CMock_Verify(); \ 20 | } \ 21 | CMock_Destroy(); \ 22 | UnityConcludeTest(); \ 23 | } 24 | 25 | /*=======Automagically Detected Files To Include=====*/ 26 | #include "unity.h" 27 | #include "cmock.h" 28 | #include 29 | #include 30 | #include "testsample_mock_head1.h" 31 | #include "Mockstanky.h" 32 | 33 | /*=======External Functions This Runner Calls=====*/ 34 | extern void setUp(void); 35 | extern void tearDown(void); 36 | extern void test_TheFirstThingToTest(void); 37 | extern void test_TheSecondThingToTest(void); 38 | 39 | 40 | /*=======Mock Management=====*/ 41 | static void CMock_Init(void) 42 | { 43 | Mockstanky_Init(); 44 | } 45 | static void CMock_Verify(void) 46 | { 47 | Mockstanky_Verify(); 48 | } 49 | static void CMock_Destroy(void) 50 | { 51 | Mockstanky_Destroy(); 52 | } 53 | 54 | /*=======Test Reset Option=====*/ 55 | void resetTest(void); 56 | void resetTest(void) 57 | { 58 | CMock_Verify(); 59 | CMock_Destroy(); 60 | tearDown(); 61 | CMock_Init(); 62 | setUp(); 63 | } 64 | 65 | 66 | /*=======MAIN=====*/ 67 | int main(void) 68 | { 69 | UnityBegin("testdata/mocksample.c"); 70 | RUN_TEST(test_TheFirstThingToTest, 21); 71 | RUN_TEST(test_TheSecondThingToTest, 43); 72 | 73 | CMock_Guts_MemFreeFinal(); 74 | return (UnityEnd()); 75 | } 76 | -------------------------------------------------------------------------------- /tests/unity/test/expectdata/testsample_mock_head1.h: -------------------------------------------------------------------------------- 1 | /* AUTOGENERATED FILE. DO NOT EDIT. */ 2 | #ifndef _TESTSAMPLE_MOCK_HEAD1_H 3 | #define _TESTSAMPLE_MOCK_HEAD1_H 4 | 5 | #include "unity.h" 6 | #include "cmock.h" 7 | #include "funky.h" 8 | #include 9 | 10 | void test_TheFirstThingToTest(void); 11 | void test_TheSecondThingToTest(void); 12 | #endif 13 | 14 | -------------------------------------------------------------------------------- /tests/unity/test/expectdata/testsample_mock_new1.c: -------------------------------------------------------------------------------- 1 | /* AUTOGENERATED FILE. DO NOT EDIT. */ 2 | 3 | /*=======Test Runner Used To Run Each Test Below=====*/ 4 | #define RUN_TEST(TestFunc, TestLineNum) \ 5 | { \ 6 | Unity.CurrentTestName = #TestFunc; \ 7 | Unity.CurrentTestLineNumber = TestLineNum; \ 8 | Unity.NumberOfTests++; \ 9 | CMock_Init(); \ 10 | UNITY_CLR_DETAILS(); \ 11 | if (TEST_PROTECT()) \ 12 | { \ 13 | CEXCEPTION_T e; \ 14 | Try { \ 15 | setUp(); \ 16 | TestFunc(); \ 17 | } Catch(e) { TEST_ASSERT_EQUAL_HEX32_MESSAGE(CEXCEPTION_NONE, e, "Unhandled Exception!"); } \ 18 | } \ 19 | if (TEST_PROTECT() && !TEST_IS_IGNORED) \ 20 | { \ 21 | tearDown(); \ 22 | CMock_Verify(); \ 23 | } \ 24 | CMock_Destroy(); \ 25 | UnityConcludeTest(); \ 26 | } 27 | 28 | /*=======Automagically Detected Files To Include=====*/ 29 | #include "unity.h" 30 | #include "cmock.h" 31 | #include 32 | #include 33 | #include "CException.h" 34 | #include "one.h" 35 | #include "two.h" 36 | #include "funky.h" 37 | #include 38 | #include "Mockstanky.h" 39 | 40 | int GlobalExpectCount; 41 | int GlobalVerifyOrder; 42 | char* GlobalOrderError; 43 | 44 | /*=======External Functions This Runner Calls=====*/ 45 | extern void setUp(void); 46 | extern void tearDown(void); 47 | extern void test_TheFirstThingToTest(void); 48 | extern void test_TheSecondThingToTest(void); 49 | 50 | 51 | /*=======Mock Management=====*/ 52 | static void CMock_Init(void) 53 | { 54 | GlobalExpectCount = 0; 55 | GlobalVerifyOrder = 0; 56 | GlobalOrderError = NULL; 57 | Mockstanky_Init(); 58 | } 59 | static void CMock_Verify(void) 60 | { 61 | Mockstanky_Verify(); 62 | } 63 | static void CMock_Destroy(void) 64 | { 65 | Mockstanky_Destroy(); 66 | } 67 | 68 | /*=======Test Reset Option=====*/ 69 | void resetTest(void); 70 | void resetTest(void) 71 | { 72 | CMock_Verify(); 73 | CMock_Destroy(); 74 | tearDown(); 75 | CMock_Init(); 76 | setUp(); 77 | } 78 | 79 | 80 | /*=======MAIN=====*/ 81 | int main(void) 82 | { 83 | UnityBegin("testdata/mocksample.c"); 84 | RUN_TEST(test_TheFirstThingToTest, 21); 85 | RUN_TEST(test_TheSecondThingToTest, 43); 86 | 87 | CMock_Guts_MemFreeFinal(); 88 | return (UnityEnd()); 89 | } 90 | -------------------------------------------------------------------------------- /tests/unity/test/expectdata/testsample_mock_new2.c: -------------------------------------------------------------------------------- 1 | /* AUTOGENERATED FILE. DO NOT EDIT. */ 2 | 3 | /*=======Test Runner Used To Run Each Test Below=====*/ 4 | #define RUN_TEST(TestFunc, TestLineNum) \ 5 | { \ 6 | Unity.CurrentTestName = #TestFunc; \ 7 | Unity.CurrentTestLineNumber = TestLineNum; \ 8 | Unity.NumberOfTests++; \ 9 | CMock_Init(); \ 10 | UNITY_CLR_DETAILS(); \ 11 | if (TEST_PROTECT()) \ 12 | { \ 13 | setUp(); \ 14 | TestFunc(); \ 15 | } \ 16 | if (TEST_PROTECT() && !TEST_IS_IGNORED) \ 17 | { \ 18 | tearDown(); \ 19 | CMock_Verify(); \ 20 | } \ 21 | CMock_Destroy(); \ 22 | UnityConcludeTest(); \ 23 | } 24 | 25 | /*=======Automagically Detected Files To Include=====*/ 26 | #include "unity.h" 27 | #include "cmock.h" 28 | #include 29 | #include 30 | #include "funky.h" 31 | #include 32 | #include "Mockstanky.h" 33 | 34 | /*=======External Functions This Runner Calls=====*/ 35 | extern void setUp(void); 36 | extern void tearDown(void); 37 | extern void test_TheFirstThingToTest(void); 38 | extern void test_TheSecondThingToTest(void); 39 | 40 | 41 | /*=======Mock Management=====*/ 42 | static void CMock_Init(void) 43 | { 44 | Mockstanky_Init(); 45 | } 46 | static void CMock_Verify(void) 47 | { 48 | Mockstanky_Verify(); 49 | } 50 | static void CMock_Destroy(void) 51 | { 52 | Mockstanky_Destroy(); 53 | } 54 | 55 | /*=======Suite Setup=====*/ 56 | static int suite_setup(void) 57 | { 58 | a_custom_setup(); 59 | } 60 | 61 | /*=======Suite Teardown=====*/ 62 | static int suite_teardown(int num_failures) 63 | { 64 | a_custom_teardown(); 65 | } 66 | 67 | /*=======Test Reset Option=====*/ 68 | void resetTest(void); 69 | void resetTest(void) 70 | { 71 | CMock_Verify(); 72 | CMock_Destroy(); 73 | tearDown(); 74 | CMock_Init(); 75 | setUp(); 76 | } 77 | 78 | 79 | /*=======MAIN=====*/ 80 | int main(void) 81 | { 82 | suite_setup(); 83 | UnityBegin("testdata/mocksample.c"); 84 | RUN_TEST(test_TheFirstThingToTest, 21); 85 | RUN_TEST(test_TheSecondThingToTest, 43); 86 | 87 | CMock_Guts_MemFreeFinal(); 88 | return suite_teardown(UnityEnd()); 89 | } 90 | -------------------------------------------------------------------------------- /tests/unity/test/expectdata/testsample_mock_param.c: -------------------------------------------------------------------------------- 1 | /* AUTOGENERATED FILE. DO NOT EDIT. */ 2 | 3 | /*=======Test Runner Used To Run Each Test Below=====*/ 4 | #define RUN_TEST_NO_ARGS 5 | #define RUN_TEST(TestFunc, TestLineNum, ...) \ 6 | { \ 7 | Unity.CurrentTestName = #TestFunc "(" #__VA_ARGS__ ")"; \ 8 | Unity.CurrentTestLineNumber = TestLineNum; \ 9 | Unity.NumberOfTests++; \ 10 | CMock_Init(); \ 11 | UNITY_CLR_DETAILS(); \ 12 | if (TEST_PROTECT()) \ 13 | { \ 14 | setUp(); \ 15 | TestFunc(__VA_ARGS__); \ 16 | } \ 17 | if (TEST_PROTECT() && !TEST_IS_IGNORED) \ 18 | { \ 19 | tearDown(); \ 20 | CMock_Verify(); \ 21 | } \ 22 | CMock_Destroy(); \ 23 | UnityConcludeTest(); \ 24 | } 25 | 26 | /*=======Automagically Detected Files To Include=====*/ 27 | #include "unity.h" 28 | #include "cmock.h" 29 | #include 30 | #include 31 | #include "funky.h" 32 | #include 33 | #include "Mockstanky.h" 34 | 35 | /*=======External Functions This Runner Calls=====*/ 36 | extern void setUp(void); 37 | extern void tearDown(void); 38 | extern void test_TheFirstThingToTest(void); 39 | extern void test_TheSecondThingToTest(void); 40 | 41 | 42 | /*=======Mock Management=====*/ 43 | static void CMock_Init(void) 44 | { 45 | Mockstanky_Init(); 46 | } 47 | static void CMock_Verify(void) 48 | { 49 | Mockstanky_Verify(); 50 | } 51 | static void CMock_Destroy(void) 52 | { 53 | Mockstanky_Destroy(); 54 | } 55 | 56 | /*=======Test Reset Option=====*/ 57 | void resetTest(void); 58 | void resetTest(void) 59 | { 60 | CMock_Verify(); 61 | CMock_Destroy(); 62 | tearDown(); 63 | CMock_Init(); 64 | setUp(); 65 | } 66 | 67 | 68 | /*=======MAIN=====*/ 69 | int main(void) 70 | { 71 | UnityBegin("testdata/mocksample.c"); 72 | RUN_TEST(test_TheFirstThingToTest, 21, RUN_TEST_NO_ARGS); 73 | RUN_TEST(test_TheSecondThingToTest, 43, RUN_TEST_NO_ARGS); 74 | 75 | CMock_Guts_MemFreeFinal(); 76 | return (UnityEnd()); 77 | } 78 | -------------------------------------------------------------------------------- /tests/unity/test/expectdata/testsample_mock_run1.c: -------------------------------------------------------------------------------- 1 | /* AUTOGENERATED FILE. DO NOT EDIT. */ 2 | 3 | /*=======Test Runner Used To Run Each Test Below=====*/ 4 | #define RUN_TEST(TestFunc, TestLineNum) \ 5 | { \ 6 | Unity.CurrentTestName = #TestFunc; \ 7 | Unity.CurrentTestLineNumber = TestLineNum; \ 8 | Unity.NumberOfTests++; \ 9 | CMock_Init(); \ 10 | UNITY_CLR_DETAILS(); \ 11 | if (TEST_PROTECT()) \ 12 | { \ 13 | CEXCEPTION_T e; \ 14 | Try { \ 15 | setUp(); \ 16 | TestFunc(); \ 17 | } Catch(e) { TEST_ASSERT_EQUAL_HEX32_MESSAGE(CEXCEPTION_NONE, e, "Unhandled Exception!"); } \ 18 | } \ 19 | if (TEST_PROTECT() && !TEST_IS_IGNORED) \ 20 | { \ 21 | tearDown(); \ 22 | CMock_Verify(); \ 23 | } \ 24 | CMock_Destroy(); \ 25 | UnityConcludeTest(); \ 26 | } 27 | 28 | /*=======Automagically Detected Files To Include=====*/ 29 | #include "unity.h" 30 | #include "cmock.h" 31 | #include 32 | #include 33 | #include "CException.h" 34 | #include "one.h" 35 | #include "two.h" 36 | #include "funky.h" 37 | #include 38 | #include "Mockstanky.h" 39 | 40 | int GlobalExpectCount; 41 | int GlobalVerifyOrder; 42 | char* GlobalOrderError; 43 | 44 | /*=======External Functions This Runner Calls=====*/ 45 | extern void setUp(void); 46 | extern void tearDown(void); 47 | extern void test_TheFirstThingToTest(void); 48 | extern void test_TheSecondThingToTest(void); 49 | 50 | 51 | /*=======Mock Management=====*/ 52 | static void CMock_Init(void) 53 | { 54 | GlobalExpectCount = 0; 55 | GlobalVerifyOrder = 0; 56 | GlobalOrderError = NULL; 57 | Mockstanky_Init(); 58 | } 59 | static void CMock_Verify(void) 60 | { 61 | Mockstanky_Verify(); 62 | } 63 | static void CMock_Destroy(void) 64 | { 65 | Mockstanky_Destroy(); 66 | } 67 | 68 | /*=======Test Reset Option=====*/ 69 | void resetTest(void); 70 | void resetTest(void) 71 | { 72 | CMock_Verify(); 73 | CMock_Destroy(); 74 | tearDown(); 75 | CMock_Init(); 76 | setUp(); 77 | } 78 | 79 | 80 | /*=======MAIN=====*/ 81 | int main(void) 82 | { 83 | UnityBegin("testdata/mocksample.c"); 84 | RUN_TEST(test_TheFirstThingToTest, 21); 85 | RUN_TEST(test_TheSecondThingToTest, 43); 86 | 87 | CMock_Guts_MemFreeFinal(); 88 | return (UnityEnd()); 89 | } 90 | -------------------------------------------------------------------------------- /tests/unity/test/expectdata/testsample_mock_run2.c: -------------------------------------------------------------------------------- 1 | /* AUTOGENERATED FILE. DO NOT EDIT. */ 2 | 3 | /*=======Test Runner Used To Run Each Test Below=====*/ 4 | #define RUN_TEST(TestFunc, TestLineNum) \ 5 | { \ 6 | Unity.CurrentTestName = #TestFunc; \ 7 | Unity.CurrentTestLineNumber = TestLineNum; \ 8 | Unity.NumberOfTests++; \ 9 | CMock_Init(); \ 10 | UNITY_CLR_DETAILS(); \ 11 | if (TEST_PROTECT()) \ 12 | { \ 13 | setUp(); \ 14 | TestFunc(); \ 15 | } \ 16 | if (TEST_PROTECT() && !TEST_IS_IGNORED) \ 17 | { \ 18 | tearDown(); \ 19 | CMock_Verify(); \ 20 | } \ 21 | CMock_Destroy(); \ 22 | UnityConcludeTest(); \ 23 | } 24 | 25 | /*=======Automagically Detected Files To Include=====*/ 26 | #include "unity.h" 27 | #include "cmock.h" 28 | #include 29 | #include 30 | #include "funky.h" 31 | #include 32 | #include "Mockstanky.h" 33 | 34 | /*=======External Functions This Runner Calls=====*/ 35 | extern void setUp(void); 36 | extern void tearDown(void); 37 | extern void test_TheFirstThingToTest(void); 38 | extern void test_TheSecondThingToTest(void); 39 | 40 | 41 | /*=======Mock Management=====*/ 42 | static void CMock_Init(void) 43 | { 44 | Mockstanky_Init(); 45 | } 46 | static void CMock_Verify(void) 47 | { 48 | Mockstanky_Verify(); 49 | } 50 | static void CMock_Destroy(void) 51 | { 52 | Mockstanky_Destroy(); 53 | } 54 | 55 | /*=======Suite Setup=====*/ 56 | static int suite_setup(void) 57 | { 58 | a_custom_setup(); 59 | } 60 | 61 | /*=======Suite Teardown=====*/ 62 | static int suite_teardown(int num_failures) 63 | { 64 | a_custom_teardown(); 65 | } 66 | 67 | /*=======Test Reset Option=====*/ 68 | void resetTest(void); 69 | void resetTest(void) 70 | { 71 | CMock_Verify(); 72 | CMock_Destroy(); 73 | tearDown(); 74 | CMock_Init(); 75 | setUp(); 76 | } 77 | 78 | 79 | /*=======MAIN=====*/ 80 | int main(void) 81 | { 82 | suite_setup(); 83 | UnityBegin("testdata/mocksample.c"); 84 | RUN_TEST(test_TheFirstThingToTest, 21); 85 | RUN_TEST(test_TheSecondThingToTest, 43); 86 | 87 | CMock_Guts_MemFreeFinal(); 88 | return suite_teardown(UnityEnd()); 89 | } 90 | -------------------------------------------------------------------------------- /tests/unity/test/expectdata/testsample_mock_yaml.c: -------------------------------------------------------------------------------- 1 | /* AUTOGENERATED FILE. DO NOT EDIT. */ 2 | 3 | /*=======Test Runner Used To Run Each Test Below=====*/ 4 | #define RUN_TEST(TestFunc, TestLineNum) \ 5 | { \ 6 | Unity.CurrentTestName = #TestFunc; \ 7 | Unity.CurrentTestLineNumber = TestLineNum; \ 8 | Unity.NumberOfTests++; \ 9 | CMock_Init(); \ 10 | UNITY_CLR_DETAILS(); \ 11 | if (TEST_PROTECT()) \ 12 | { \ 13 | CEXCEPTION_T e; \ 14 | Try { \ 15 | setUp(); \ 16 | TestFunc(); \ 17 | } Catch(e) { TEST_ASSERT_EQUAL_HEX32_MESSAGE(CEXCEPTION_NONE, e, "Unhandled Exception!"); } \ 18 | } \ 19 | if (TEST_PROTECT() && !TEST_IS_IGNORED) \ 20 | { \ 21 | tearDown(); \ 22 | CMock_Verify(); \ 23 | } \ 24 | CMock_Destroy(); \ 25 | UnityConcludeTest(); \ 26 | } 27 | 28 | /*=======Automagically Detected Files To Include=====*/ 29 | #include "unity.h" 30 | #include "cmock.h" 31 | #include 32 | #include 33 | #include "CException.h" 34 | #include "two.h" 35 | #include "three.h" 36 | #include 37 | #include "funky.h" 38 | #include 39 | #include "Mockstanky.h" 40 | 41 | /*=======External Functions This Runner Calls=====*/ 42 | extern void setUp(void); 43 | extern void tearDown(void); 44 | extern void test_TheFirstThingToTest(void); 45 | extern void test_TheSecondThingToTest(void); 46 | 47 | 48 | /*=======Mock Management=====*/ 49 | static void CMock_Init(void) 50 | { 51 | Mockstanky_Init(); 52 | } 53 | static void CMock_Verify(void) 54 | { 55 | Mockstanky_Verify(); 56 | } 57 | static void CMock_Destroy(void) 58 | { 59 | Mockstanky_Destroy(); 60 | } 61 | 62 | /*=======Suite Setup=====*/ 63 | static int suite_setup(void) 64 | { 65 | a_yaml_setup(); 66 | } 67 | 68 | /*=======Test Reset Option=====*/ 69 | void resetTest(void); 70 | void resetTest(void) 71 | { 72 | CMock_Verify(); 73 | CMock_Destroy(); 74 | tearDown(); 75 | CMock_Init(); 76 | setUp(); 77 | } 78 | 79 | 80 | /*=======MAIN=====*/ 81 | int main(void) 82 | { 83 | suite_setup(); 84 | UnityBegin("testdata/mocksample.c"); 85 | RUN_TEST(test_TheFirstThingToTest, 21); 86 | RUN_TEST(test_TheSecondThingToTest, 43); 87 | 88 | CMock_Guts_MemFreeFinal(); 89 | return (UnityEnd()); 90 | } 91 | -------------------------------------------------------------------------------- /tests/unity/test/expectdata/testsample_new1.c: -------------------------------------------------------------------------------- 1 | /* AUTOGENERATED FILE. DO NOT EDIT. */ 2 | 3 | /*=======Test Runner Used To Run Each Test Below=====*/ 4 | #define RUN_TEST(TestFunc, TestLineNum) \ 5 | { \ 6 | Unity.CurrentTestName = #TestFunc; \ 7 | Unity.CurrentTestLineNumber = TestLineNum; \ 8 | Unity.NumberOfTests++; \ 9 | if (TEST_PROTECT()) \ 10 | { \ 11 | CEXCEPTION_T e; \ 12 | Try { \ 13 | setUp(); \ 14 | TestFunc(); \ 15 | } Catch(e) { TEST_ASSERT_EQUAL_HEX32_MESSAGE(CEXCEPTION_NONE, e, "Unhandled Exception!"); } \ 16 | } \ 17 | if (TEST_PROTECT() && !TEST_IS_IGNORED) \ 18 | { \ 19 | tearDown(); \ 20 | } \ 21 | UnityConcludeTest(); \ 22 | } 23 | 24 | /*=======Automagically Detected Files To Include=====*/ 25 | #include "unity.h" 26 | #include 27 | #include 28 | #include "CException.h" 29 | #include "one.h" 30 | #include "two.h" 31 | #include "funky.h" 32 | #include "stanky.h" 33 | #include 34 | 35 | int GlobalExpectCount; 36 | int GlobalVerifyOrder; 37 | char* GlobalOrderError; 38 | 39 | /*=======External Functions This Runner Calls=====*/ 40 | extern void setUp(void); 41 | extern void tearDown(void); 42 | extern void test_TheFirstThingToTest(void); 43 | extern void test_TheSecondThingToTest(void); 44 | extern void test_TheThirdThingToTest(void); 45 | extern void test_TheFourthThingToTest(void); 46 | 47 | 48 | /*=======Test Reset Option=====*/ 49 | void resetTest(void); 50 | void resetTest(void) 51 | { 52 | tearDown(); 53 | setUp(); 54 | } 55 | 56 | 57 | /*=======MAIN=====*/ 58 | int main(void) 59 | { 60 | UnityBegin("testdata/testsample.c"); 61 | RUN_TEST(test_TheFirstThingToTest, 21); 62 | RUN_TEST(test_TheSecondThingToTest, 43); 63 | RUN_TEST(test_TheThirdThingToTest, 53); 64 | RUN_TEST(test_TheFourthThingToTest, 58); 65 | 66 | return (UnityEnd()); 67 | } 68 | -------------------------------------------------------------------------------- /tests/unity/test/expectdata/testsample_new2.c: -------------------------------------------------------------------------------- 1 | /* AUTOGENERATED FILE. DO NOT EDIT. */ 2 | 3 | /*=======Test Runner Used To Run Each Test Below=====*/ 4 | #define RUN_TEST(TestFunc, TestLineNum) \ 5 | { \ 6 | Unity.CurrentTestName = #TestFunc; \ 7 | Unity.CurrentTestLineNumber = TestLineNum; \ 8 | Unity.NumberOfTests++; \ 9 | if (TEST_PROTECT()) \ 10 | { \ 11 | setUp(); \ 12 | TestFunc(); \ 13 | } \ 14 | if (TEST_PROTECT() && !TEST_IS_IGNORED) \ 15 | { \ 16 | tearDown(); \ 17 | } \ 18 | UnityConcludeTest(); \ 19 | } 20 | 21 | /*=======Automagically Detected Files To Include=====*/ 22 | #include "unity.h" 23 | #include 24 | #include 25 | #include "funky.h" 26 | #include "stanky.h" 27 | #include 28 | 29 | /*=======External Functions This Runner Calls=====*/ 30 | extern void setUp(void); 31 | extern void tearDown(void); 32 | extern void test_TheFirstThingToTest(void); 33 | extern void test_TheSecondThingToTest(void); 34 | extern void test_TheThirdThingToTest(void); 35 | extern void test_TheFourthThingToTest(void); 36 | 37 | 38 | /*=======Suite Setup=====*/ 39 | static int suite_setup(void) 40 | { 41 | a_custom_setup(); 42 | } 43 | 44 | /*=======Suite Teardown=====*/ 45 | static int suite_teardown(int num_failures) 46 | { 47 | a_custom_teardown(); 48 | } 49 | 50 | /*=======Test Reset Option=====*/ 51 | void resetTest(void); 52 | void resetTest(void) 53 | { 54 | tearDown(); 55 | setUp(); 56 | } 57 | 58 | 59 | /*=======MAIN=====*/ 60 | int main(void) 61 | { 62 | suite_setup(); 63 | UnityBegin("testdata/testsample.c"); 64 | RUN_TEST(test_TheFirstThingToTest, 21); 65 | RUN_TEST(test_TheSecondThingToTest, 43); 66 | RUN_TEST(test_TheThirdThingToTest, 53); 67 | RUN_TEST(test_TheFourthThingToTest, 58); 68 | 69 | return suite_teardown(UnityEnd()); 70 | } 71 | -------------------------------------------------------------------------------- /tests/unity/test/expectdata/testsample_param.c: -------------------------------------------------------------------------------- 1 | /* AUTOGENERATED FILE. DO NOT EDIT. */ 2 | 3 | /*=======Test Runner Used To Run Each Test Below=====*/ 4 | #define RUN_TEST_NO_ARGS 5 | #define RUN_TEST(TestFunc, TestLineNum, ...) \ 6 | { \ 7 | Unity.CurrentTestName = #TestFunc "(" #__VA_ARGS__ ")"; \ 8 | Unity.CurrentTestLineNumber = TestLineNum; \ 9 | Unity.NumberOfTests++; \ 10 | if (TEST_PROTECT()) \ 11 | { \ 12 | setUp(); \ 13 | TestFunc(__VA_ARGS__); \ 14 | } \ 15 | if (TEST_PROTECT() && !TEST_IS_IGNORED) \ 16 | { \ 17 | tearDown(); \ 18 | } \ 19 | UnityConcludeTest(); \ 20 | } 21 | 22 | /*=======Automagically Detected Files To Include=====*/ 23 | #include "unity.h" 24 | #include 25 | #include 26 | #include "funky.h" 27 | #include "stanky.h" 28 | #include 29 | 30 | /*=======External Functions This Runner Calls=====*/ 31 | extern void setUp(void); 32 | extern void tearDown(void); 33 | extern void test_TheFirstThingToTest(void); 34 | extern void test_TheSecondThingToTest(void); 35 | extern void test_TheThirdThingToTest(void); 36 | extern void test_TheFourthThingToTest(void); 37 | 38 | 39 | /*=======Test Reset Option=====*/ 40 | void resetTest(void); 41 | void resetTest(void) 42 | { 43 | tearDown(); 44 | setUp(); 45 | } 46 | 47 | 48 | /*=======MAIN=====*/ 49 | int main(void) 50 | { 51 | UnityBegin("testdata/testsample.c"); 52 | RUN_TEST(test_TheFirstThingToTest, 21, RUN_TEST_NO_ARGS); 53 | RUN_TEST(test_TheSecondThingToTest, 43, RUN_TEST_NO_ARGS); 54 | RUN_TEST(test_TheThirdThingToTest, 53, RUN_TEST_NO_ARGS); 55 | RUN_TEST(test_TheFourthThingToTest, 58, RUN_TEST_NO_ARGS); 56 | 57 | return (UnityEnd()); 58 | } 59 | -------------------------------------------------------------------------------- /tests/unity/test/expectdata/testsample_run1.c: -------------------------------------------------------------------------------- 1 | /* AUTOGENERATED FILE. DO NOT EDIT. */ 2 | 3 | /*=======Test Runner Used To Run Each Test Below=====*/ 4 | #define RUN_TEST(TestFunc, TestLineNum) \ 5 | { \ 6 | Unity.CurrentTestName = #TestFunc; \ 7 | Unity.CurrentTestLineNumber = TestLineNum; \ 8 | Unity.NumberOfTests++; \ 9 | if (TEST_PROTECT()) \ 10 | { \ 11 | CEXCEPTION_T e; \ 12 | Try { \ 13 | setUp(); \ 14 | TestFunc(); \ 15 | } Catch(e) { TEST_ASSERT_EQUAL_HEX32_MESSAGE(CEXCEPTION_NONE, e, "Unhandled Exception!"); } \ 16 | } \ 17 | if (TEST_PROTECT() && !TEST_IS_IGNORED) \ 18 | { \ 19 | tearDown(); \ 20 | } \ 21 | UnityConcludeTest(); \ 22 | } 23 | 24 | /*=======Automagically Detected Files To Include=====*/ 25 | #include "unity.h" 26 | #include 27 | #include 28 | #include "CException.h" 29 | #include "one.h" 30 | #include "two.h" 31 | #include "funky.h" 32 | #include "stanky.h" 33 | #include 34 | 35 | int GlobalExpectCount; 36 | int GlobalVerifyOrder; 37 | char* GlobalOrderError; 38 | 39 | /*=======External Functions This Runner Calls=====*/ 40 | extern void setUp(void); 41 | extern void tearDown(void); 42 | extern void test_TheFirstThingToTest(void); 43 | extern void test_TheSecondThingToTest(void); 44 | extern void test_TheThirdThingToTest(void); 45 | extern void test_TheFourthThingToTest(void); 46 | 47 | 48 | /*=======Test Reset Option=====*/ 49 | void resetTest(void); 50 | void resetTest(void) 51 | { 52 | tearDown(); 53 | setUp(); 54 | } 55 | 56 | 57 | /*=======MAIN=====*/ 58 | int main(void) 59 | { 60 | UnityBegin("testdata/testsample.c"); 61 | RUN_TEST(test_TheFirstThingToTest, 21); 62 | RUN_TEST(test_TheSecondThingToTest, 43); 63 | RUN_TEST(test_TheThirdThingToTest, 53); 64 | RUN_TEST(test_TheFourthThingToTest, 58); 65 | 66 | return (UnityEnd()); 67 | } 68 | -------------------------------------------------------------------------------- /tests/unity/test/expectdata/testsample_run2.c: -------------------------------------------------------------------------------- 1 | /* AUTOGENERATED FILE. DO NOT EDIT. */ 2 | 3 | /*=======Test Runner Used To Run Each Test Below=====*/ 4 | #define RUN_TEST(TestFunc, TestLineNum) \ 5 | { \ 6 | Unity.CurrentTestName = #TestFunc; \ 7 | Unity.CurrentTestLineNumber = TestLineNum; \ 8 | Unity.NumberOfTests++; \ 9 | if (TEST_PROTECT()) \ 10 | { \ 11 | setUp(); \ 12 | TestFunc(); \ 13 | } \ 14 | if (TEST_PROTECT() && !TEST_IS_IGNORED) \ 15 | { \ 16 | tearDown(); \ 17 | } \ 18 | UnityConcludeTest(); \ 19 | } 20 | 21 | /*=======Automagically Detected Files To Include=====*/ 22 | #include "unity.h" 23 | #include 24 | #include 25 | #include "funky.h" 26 | #include "stanky.h" 27 | #include 28 | 29 | /*=======External Functions This Runner Calls=====*/ 30 | extern void setUp(void); 31 | extern void tearDown(void); 32 | extern void test_TheFirstThingToTest(void); 33 | extern void test_TheSecondThingToTest(void); 34 | extern void test_TheThirdThingToTest(void); 35 | extern void test_TheFourthThingToTest(void); 36 | 37 | 38 | /*=======Suite Setup=====*/ 39 | static int suite_setup(void) 40 | { 41 | a_custom_setup(); 42 | } 43 | 44 | /*=======Suite Teardown=====*/ 45 | static int suite_teardown(int num_failures) 46 | { 47 | a_custom_teardown(); 48 | } 49 | 50 | /*=======Test Reset Option=====*/ 51 | void resetTest(void); 52 | void resetTest(void) 53 | { 54 | tearDown(); 55 | setUp(); 56 | } 57 | 58 | 59 | /*=======MAIN=====*/ 60 | int main(void) 61 | { 62 | suite_setup(); 63 | UnityBegin("testdata/testsample.c"); 64 | RUN_TEST(test_TheFirstThingToTest, 21); 65 | RUN_TEST(test_TheSecondThingToTest, 43); 66 | RUN_TEST(test_TheThirdThingToTest, 53); 67 | RUN_TEST(test_TheFourthThingToTest, 58); 68 | 69 | return suite_teardown(UnityEnd()); 70 | } 71 | -------------------------------------------------------------------------------- /tests/unity/test/expectdata/testsample_yaml.c: -------------------------------------------------------------------------------- 1 | /* AUTOGENERATED FILE. DO NOT EDIT. */ 2 | 3 | /*=======Test Runner Used To Run Each Test Below=====*/ 4 | #define RUN_TEST(TestFunc, TestLineNum) \ 5 | { \ 6 | Unity.CurrentTestName = #TestFunc; \ 7 | Unity.CurrentTestLineNumber = TestLineNum; \ 8 | Unity.NumberOfTests++; \ 9 | if (TEST_PROTECT()) \ 10 | { \ 11 | CEXCEPTION_T e; \ 12 | Try { \ 13 | setUp(); \ 14 | TestFunc(); \ 15 | } Catch(e) { TEST_ASSERT_EQUAL_HEX32_MESSAGE(CEXCEPTION_NONE, e, "Unhandled Exception!"); } \ 16 | } \ 17 | if (TEST_PROTECT() && !TEST_IS_IGNORED) \ 18 | { \ 19 | tearDown(); \ 20 | } \ 21 | UnityConcludeTest(); \ 22 | } 23 | 24 | /*=======Automagically Detected Files To Include=====*/ 25 | #include "unity.h" 26 | #include 27 | #include 28 | #include "CException.h" 29 | #include "two.h" 30 | #include "three.h" 31 | #include 32 | #include "funky.h" 33 | #include "stanky.h" 34 | #include 35 | 36 | /*=======External Functions This Runner Calls=====*/ 37 | extern void setUp(void); 38 | extern void tearDown(void); 39 | extern void test_TheFirstThingToTest(void); 40 | extern void test_TheSecondThingToTest(void); 41 | extern void test_TheThirdThingToTest(void); 42 | extern void test_TheFourthThingToTest(void); 43 | 44 | 45 | /*=======Suite Setup=====*/ 46 | static int suite_setup(void) 47 | { 48 | a_yaml_setup(); 49 | } 50 | 51 | /*=======Test Reset Option=====*/ 52 | void resetTest(void); 53 | void resetTest(void) 54 | { 55 | tearDown(); 56 | setUp(); 57 | } 58 | 59 | 60 | /*=======MAIN=====*/ 61 | int main(void) 62 | { 63 | suite_setup(); 64 | UnityBegin("testdata/testsample.c"); 65 | RUN_TEST(test_TheFirstThingToTest, 21); 66 | RUN_TEST(test_TheSecondThingToTest, 43); 67 | RUN_TEST(test_TheThirdThingToTest, 53); 68 | RUN_TEST(test_TheFourthThingToTest, 58); 69 | 70 | return (UnityEnd()); 71 | } 72 | -------------------------------------------------------------------------------- /tests/unity/test/rakefile: -------------------------------------------------------------------------------- 1 | # ========================================== 2 | # Unity Project - A Test Framework for C 3 | # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 4 | # [Released under MIT License. Please refer to license.txt for details] 5 | # ========================================== 6 | 7 | UNITY_ROOT = File.expand_path(File.dirname(__FILE__)) + '/' 8 | $verbose = false 9 | 10 | require 'rake' 11 | require 'rake/clean' 12 | require UNITY_ROOT + 'rakefile_helper' 13 | require 'rspec/core/rake_task' 14 | 15 | TEMP_DIRS = [ 16 | File.join(UNITY_ROOT, 'build'), 17 | File.join(UNITY_ROOT, 'sandbox') 18 | ] 19 | 20 | TEMP_DIRS.each do |dir| 21 | directory(dir) 22 | CLOBBER.include(dir) 23 | end 24 | 25 | task :prepare_for_tests => TEMP_DIRS 26 | 27 | include RakefileHelpers 28 | 29 | # Load proper GCC as defult configuration 30 | DEFAULT_CONFIG_FILE = 'gcc_auto_stdint.yml' 31 | configure_toolchain(DEFAULT_CONFIG_FILE) 32 | 33 | desc "Test unity with its own unit tests" 34 | task :unit => [:prepare_for_tests] do 35 | run_tests get_unit_test_files 36 | end 37 | 38 | desc "Test unity's helper scripts" 39 | task :scripts => [:prepare_for_tests] do 40 | Dir['tests/test_*.rb'].each do |scriptfile| 41 | require "./"+scriptfile 42 | end 43 | end 44 | 45 | desc "Run all rspecs" 46 | RSpec::Core::RakeTask.new(:spec) do |t| 47 | t.pattern = 'spec/**/*_spec.rb' 48 | end 49 | 50 | desc "Generate test summary" 51 | task :summary do 52 | report_summary 53 | end 54 | 55 | desc "Build and test Unity" 56 | task :all => [:clean, :prepare_for_tests, :scripts, :unit, :summary] 57 | task :default => [:clobber, :all] 58 | task :ci => [:no_color, :default] 59 | task :cruise => [:no_color, :default] 60 | 61 | desc "Load configuration" 62 | task :config, :config_file do |t, args| 63 | configure_toolchain(args[:config_file]) 64 | end 65 | 66 | task :no_color do 67 | $colour_output = false 68 | end 69 | 70 | task :verbose do 71 | $verbose = true 72 | end 73 | -------------------------------------------------------------------------------- /tests/unity/test/spec/generate_module_existing_file_spec.rb: -------------------------------------------------------------------------------- 1 | 2 | require '../auto/generate_module.rb' 3 | require 'fileutils' 4 | 5 | def touch_src(file) 6 | FileUtils.touch "sandbox/src/#{file}" 7 | end 8 | 9 | def touch_test(file) 10 | FileUtils.touch "sandbox/test/#{file}" 11 | end 12 | 13 | def create_src_with_known_content(file) 14 | File.open("sandbox/src/#{file}", "w") {|f| f.write("the original #{file}")} 15 | end 16 | 17 | def create_test_with_known_content(file) 18 | File.open("sandbox/test/#{file}", "w") {|f| f.write("the original #{file}")} 19 | end 20 | 21 | def expect_src_content_didnt_change(file) 22 | expect(File.read("sandbox/src/#{file}")).to eq("the original #{file}") 23 | end 24 | 25 | def expect_test_content_didnt_change(file) 26 | expect(File.read("sandbox/test/#{file}")).to eq("the original #{file}") 27 | end 28 | 29 | def expect_src_file_to_exist(file) 30 | expect(File.exist?("sandbox/src/#{file}")).to be true 31 | end 32 | 33 | def expect_test_file_to_exist(file) 34 | expect(File.exist?("sandbox/test/#{file}")).to be true 35 | end 36 | 37 | describe "UnityModuleGenerator" do 38 | 39 | before do 40 | # clean sandbox and setup our "project" folders 41 | FileUtils.rm_rf "sandbox" 42 | FileUtils.mkdir_p "sandbox" 43 | FileUtils.mkdir_p "sandbox/src" 44 | FileUtils.mkdir_p "sandbox/test" 45 | 46 | @options = { 47 | :path_src => "sandbox/src", 48 | :path_tst => "sandbox/test", 49 | } 50 | end 51 | 52 | context "with src pattern" do 53 | before do 54 | @options[:pattern] = "src" 55 | end 56 | 57 | it "fails when all files already exist" do 58 | # create an existing triad of files 59 | touch_src "meh.c" 60 | touch_src "meh.h" 61 | touch_test "Testmeh.c" 62 | expect { 63 | UnityModuleGenerator.new(@options).generate("meh") 64 | }.to raise_error("ERROR: File meh already exists. Exiting.") 65 | end 66 | 67 | it "creates the test file if the source and header files exist" do 68 | # Create the existing files. 69 | touch_src "meh.c" 70 | touch_src "meh.h" 71 | 72 | UnityModuleGenerator.new(@options).generate("meh") 73 | 74 | expect_test_file_to_exist "Testmeh.c" 75 | end 76 | 77 | it "does not alter existing files" do 78 | # Create some files with known content. 79 | create_src_with_known_content "meh.c" 80 | create_src_with_known_content "meh.h" 81 | 82 | UnityModuleGenerator.new(@options).generate("meh") 83 | 84 | expect_src_content_didnt_change "meh.c" 85 | expect_src_content_didnt_change "meh.c" 86 | end 87 | 88 | it "does not alter existing test files" do 89 | # Create some files with known content. 90 | create_test_with_known_content "Testmeh.c" 91 | 92 | UnityModuleGenerator.new(@options).generate("meh") 93 | 94 | expect_test_content_didnt_change "Testmeh.c" 95 | end 96 | 97 | end 98 | 99 | context "with mch pattern" do 100 | before do 101 | @options[:pattern] = "mch" 102 | end 103 | 104 | it "fails when all files exist" do 105 | touch_src "meh_model.c" 106 | touch_src "meh_conductor.c" 107 | touch_src "meh_hardware.c" 108 | touch_src "meh_model.h" 109 | touch_src "meh_conductor.h" 110 | touch_src "meh_hardware.h" 111 | touch_test "Testmeh_model.c" 112 | touch_test "Testmeh_conductor.c" 113 | touch_test "Testmeh_hardware.c" 114 | expect { 115 | UnityModuleGenerator.new(@options).generate("meh") 116 | }.to raise_error("ERROR: File meh_model already exists. Exiting.") 117 | end 118 | 119 | it "creates files that don't exist" do 120 | touch_src "meh_model.c" 121 | touch_src "meh_conductor.c" 122 | touch_src "meh_hardware.c" 123 | touch_src "meh_model.h" 124 | touch_src "meh_conductor.h" 125 | 126 | UnityModuleGenerator.new(@options).generate("meh") 127 | 128 | expect_src_file_to_exist "meh_hardware.h" 129 | expect_test_file_to_exist "Testmeh_model.c" 130 | expect_test_file_to_exist "Testmeh_conductor.c" 131 | expect_test_file_to_exist "Testmeh_hardware.c" 132 | end 133 | 134 | it "does not alter existing source files" do 135 | create_src_with_known_content "meh_model.c" 136 | create_src_with_known_content "meh_model.c" 137 | create_src_with_known_content "meh_model.c" 138 | create_src_with_known_content "meh_model.h" 139 | create_src_with_known_content "meh_model.c" 140 | 141 | UnityModuleGenerator.new(@options).generate("meh") 142 | 143 | expect_src_content_didnt_change "meh_model.c" 144 | expect_src_content_didnt_change "meh_model.c" 145 | expect_src_content_didnt_change "meh_model.c" 146 | expect_src_content_didnt_change "meh_model.c" 147 | end 148 | 149 | it "does not alter existing test files" do 150 | create_test_with_known_content "Testmeh_model.c" 151 | 152 | UnityModuleGenerator.new(@options).generate("meh") 153 | 154 | expect_test_content_didnt_change "Testmeh_model.c" 155 | end 156 | 157 | end 158 | end 159 | -------------------------------------------------------------------------------- /tests/unity/test/targets/clang_file.yml: -------------------------------------------------------------------------------- 1 | --- 2 | compiler: 3 | path: clang 4 | source_path: '../src/' 5 | unit_tests_path: &unit_tests_path 'tests/' 6 | build_path: &build_path 'build/' 7 | options: 8 | - '-c' 9 | - '-Wall' 10 | - '-Wextra' 11 | - '-Werror' 12 | - '-Wcast-qual' 13 | - '-Wconversion' 14 | - '-Wdisabled-optimization' 15 | - '-Wformat=2' 16 | - '-Winit-self' 17 | - '-Winline' 18 | - '-Winvalid-pch' 19 | - '-Wmissing-include-dirs' 20 | - '-Wnonnull' 21 | - '-Wpacked' 22 | - '-Wpointer-arith' 23 | - '-Wswitch-default' 24 | - '-Wstrict-aliasing' 25 | - '-Wstrict-overflow=5' 26 | - '-Wuninitialized' 27 | - '-Wunused' 28 | # - '-Wunreachable-code' 29 | - '-Wreturn-type' 30 | - '-Wshadow' 31 | - '-Wundef' 32 | - '-Wwrite-strings' 33 | - '-Wno-nested-externs' 34 | - '-Wno-unused-parameter' 35 | - '-Wno-variadic-macros' 36 | - '-Wbad-function-cast' 37 | - '-fms-extensions' 38 | - '-fno-omit-frame-pointer' 39 | - '-ffloat-store' 40 | - '-fno-common' 41 | - '-fstrict-aliasing' 42 | - '-std=gnu99' 43 | - '-pedantic' 44 | - '-O0' 45 | includes: 46 | prefix: '-I' 47 | items: 48 | - 'src/' 49 | - '../src/' 50 | - 'testdata/' 51 | - *unit_tests_path 52 | defines: 53 | prefix: '-D' 54 | items: 55 | - UNITY_INCLUDE_DOUBLE 56 | - UNITY_SUPPORT_64 57 | - UNITY_OUTPUT_RESULTS_FILE 58 | object_files: 59 | prefix: '-o' 60 | extension: '.o' 61 | destination: *build_path 62 | linker: 63 | path: clang 64 | options: 65 | - -lm 66 | - '-m64' 67 | includes: 68 | prefix: '-I' 69 | object_files: 70 | path: *build_path 71 | extension: '.o' 72 | bin_files: 73 | prefix: '-o' 74 | extension: '.exe' 75 | destination: *build_path 76 | colour: true 77 | :unity: 78 | :plugins: [] 79 | -------------------------------------------------------------------------------- /tests/unity/test/targets/clang_strict.yml: -------------------------------------------------------------------------------- 1 | --- 2 | compiler: 3 | path: clang 4 | source_path: '../src/' 5 | unit_tests_path: &unit_tests_path 'tests/' 6 | build_path: &build_path 'build/' 7 | options: 8 | - '-c' 9 | - '-Wall' 10 | - '-Wextra' 11 | - '-Werror' 12 | - '-Wcast-qual' 13 | - '-Wconversion' 14 | - '-Wdisabled-optimization' 15 | - '-Wformat=2' 16 | - '-Winit-self' 17 | - '-Winline' 18 | - '-Winvalid-pch' 19 | - '-Wmissing-include-dirs' 20 | - '-Wnonnull' 21 | - '-Wpacked' 22 | - '-Wpointer-arith' 23 | - '-Wswitch-default' 24 | - '-Wstrict-aliasing' 25 | - '-Wstrict-overflow=5' 26 | - '-Wuninitialized' 27 | - '-Wunused' 28 | # - '-Wunreachable-code' 29 | - '-Wreturn-type' 30 | - '-Wshadow' 31 | - '-Wundef' 32 | - '-Wwrite-strings' 33 | - '-Wno-nested-externs' 34 | - '-Wno-unused-parameter' 35 | - '-Wno-variadic-macros' 36 | - '-Wbad-function-cast' 37 | - '-fms-extensions' 38 | - '-fno-omit-frame-pointer' 39 | - '-ffloat-store' 40 | - '-fno-common' 41 | - '-fstrict-aliasing' 42 | - '-std=gnu99' 43 | - '-pedantic' 44 | - '-O0' 45 | includes: 46 | prefix: '-I' 47 | items: 48 | - 'src/' 49 | - '../src/' 50 | - 'testdata/' 51 | - *unit_tests_path 52 | defines: 53 | prefix: '-D' 54 | items: 55 | - UNITY_INCLUDE_DOUBLE 56 | - UNITY_SUPPORT_TEST_CASES 57 | - UNITY_SUPPORT_64 58 | - UNITY_OUTPUT_FLUSH 59 | - UNITY_OMIT_OUTPUT_FLUSH_HEADER_DECLARATION 60 | object_files: 61 | prefix: '-o' 62 | extension: '.o' 63 | destination: *build_path 64 | linker: 65 | path: clang 66 | options: 67 | - -lm 68 | - '-m64' 69 | includes: 70 | prefix: '-I' 71 | object_files: 72 | path: *build_path 73 | extension: '.o' 74 | bin_files: 75 | prefix: '-o' 76 | extension: '.exe' 77 | destination: *build_path 78 | colour: true 79 | :unity: 80 | :plugins: [] 81 | -------------------------------------------------------------------------------- /tests/unity/test/targets/gcc_32.yml: -------------------------------------------------------------------------------- 1 | compiler: 2 | path: gcc 3 | source_path: '../src/' 4 | unit_tests_path: &unit_tests_path 'tests/' 5 | build_path: &build_path 'build/' 6 | options: 7 | - '-c' 8 | - '-m32' 9 | - '-Wall' 10 | - '-Wno-address' 11 | - '-std=c99' 12 | - '-pedantic' 13 | includes: 14 | prefix: '-I' 15 | items: 16 | - 'src/' 17 | - '../src/' 18 | - 'testdata/' 19 | - *unit_tests_path 20 | defines: 21 | prefix: '-D' 22 | items: 23 | - UNITY_EXCLUDE_STDINT_H 24 | - UNITY_EXCLUDE_LIMITS_H 25 | - UNITY_INCLUDE_DOUBLE 26 | - UNITY_SUPPORT_TEST_CASES 27 | - UNITY_INT_WIDTH=32 28 | - UNITY_LONG_WIDTH=32 29 | object_files: 30 | prefix: '-o' 31 | extension: '.o' 32 | destination: *build_path 33 | linker: 34 | path: gcc 35 | options: 36 | - -lm 37 | - '-m32' 38 | includes: 39 | prefix: '-I' 40 | object_files: 41 | path: *build_path 42 | extension: '.o' 43 | bin_files: 44 | prefix: '-o' 45 | extension: '.exe' 46 | destination: *build_path 47 | colour: true 48 | :unity: 49 | :plugins: [] 50 | -------------------------------------------------------------------------------- /tests/unity/test/targets/gcc_64.yml: -------------------------------------------------------------------------------- 1 | compiler: 2 | path: gcc 3 | source_path: '../src/' 4 | unit_tests_path: &unit_tests_path 'tests/' 5 | build_path: &build_path 'build/' 6 | options: 7 | - '-c' 8 | - '-m64' 9 | - '-Wall' 10 | - '-Wno-address' 11 | - '-std=c99' 12 | - '-pedantic' 13 | includes: 14 | prefix: '-I' 15 | items: 16 | - 'src/' 17 | - '../src/' 18 | - 'testdata/' 19 | - *unit_tests_path 20 | defines: 21 | prefix: '-D' 22 | items: 23 | - UNITY_EXCLUDE_STDINT_H 24 | - UNITY_EXCLUDE_LIMITS_H 25 | - UNITY_INCLUDE_DOUBLE 26 | - UNITY_SUPPORT_TEST_CASES 27 | - UNITY_SUPPORT_64 28 | - UNITY_INT_WIDTH=32 29 | - UNITY_LONG_WIDTH=64 30 | object_files: 31 | prefix: '-o' 32 | extension: '.o' 33 | destination: *build_path 34 | linker: 35 | path: gcc 36 | options: 37 | - -lm 38 | - '-m64' 39 | includes: 40 | prefix: '-I' 41 | object_files: 42 | path: *build_path 43 | extension: '.o' 44 | bin_files: 45 | prefix: '-o' 46 | extension: '.exe' 47 | destination: *build_path 48 | colour: true 49 | :unity: 50 | :plugins: [] 51 | -------------------------------------------------------------------------------- /tests/unity/test/targets/gcc_auto_limits.yml: -------------------------------------------------------------------------------- 1 | compiler: 2 | path: gcc 3 | source_path: '../src/' 4 | unit_tests_path: &unit_tests_path 'tests/' 5 | build_path: &build_path 'build/' 6 | options: 7 | - '-c' 8 | - '-m64' 9 | - '-Wall' 10 | - '-Wno-address' 11 | - '-std=c99' 12 | - '-pedantic' 13 | includes: 14 | prefix: '-I' 15 | items: 16 | - 'src/' 17 | - '../src/' 18 | - 'testdata/' 19 | - *unit_tests_path 20 | defines: 21 | prefix: '-D' 22 | items: 23 | - UNITY_EXCLUDE_STDINT_H 24 | - UNITY_INCLUDE_DOUBLE 25 | - UNITY_SUPPORT_TEST_CASES 26 | - UNITY_SUPPORT_64 27 | object_files: 28 | prefix: '-o' 29 | extension: '.o' 30 | destination: *build_path 31 | linker: 32 | path: gcc 33 | options: 34 | - -lm 35 | - '-m64' 36 | includes: 37 | prefix: '-I' 38 | object_files: 39 | path: *build_path 40 | extension: '.o' 41 | bin_files: 42 | prefix: '-o' 43 | extension: '.exe' 44 | destination: *build_path 45 | colour: true 46 | :unity: 47 | :plugins: [] 48 | -------------------------------------------------------------------------------- /tests/unity/test/targets/gcc_auto_stdint.yml: -------------------------------------------------------------------------------- 1 | compiler: 2 | path: gcc 3 | source_path: '../src/' 4 | unit_tests_path: &unit_tests_path 'tests/' 5 | build_path: &build_path 'build/' 6 | options: 7 | - '-c' 8 | - '-m64' 9 | - '-Wall' 10 | - '-Wno-address' 11 | - '-std=c99' 12 | - '-pedantic' 13 | - '-Wextra' 14 | - '-Werror' 15 | - '-Wpointer-arith' 16 | - '-Wcast-align' 17 | - '-Wwrite-strings' 18 | - '-Wswitch-default' 19 | - '-Wunreachable-code' 20 | - '-Winit-self' 21 | - '-Wmissing-field-initializers' 22 | - '-Wno-unknown-pragmas' 23 | - '-Wstrict-prototypes' 24 | - '-Wundef' 25 | - '-Wold-style-definition' 26 | includes: 27 | prefix: '-I' 28 | items: 29 | - 'src/' 30 | - '../src/' 31 | - 'testdata/' 32 | - *unit_tests_path 33 | defines: 34 | prefix: '-D' 35 | items: 36 | - UNITY_INCLUDE_DOUBLE 37 | - UNITY_SUPPORT_TEST_CASES 38 | - UNITY_SUPPORT_64 39 | object_files: 40 | prefix: '-o' 41 | extension: '.o' 42 | destination: *build_path 43 | linker: 44 | path: gcc 45 | options: 46 | - -lm 47 | - '-m64' 48 | includes: 49 | prefix: '-I' 50 | object_files: 51 | path: *build_path 52 | extension: '.o' 53 | bin_files: 54 | prefix: '-o' 55 | extension: '.exe' 56 | destination: *build_path 57 | colour: true 58 | :unity: 59 | :plugins: [] 60 | -------------------------------------------------------------------------------- /tests/unity/test/targets/gcc_manual_math.yml: -------------------------------------------------------------------------------- 1 | compiler: 2 | path: gcc 3 | source_path: '../src/' 4 | unit_tests_path: &unit_tests_path 'tests/' 5 | build_path: &build_path 'build/' 6 | options: 7 | - '-c' 8 | - '-m64' 9 | - '-Wall' 10 | - '-Wno-address' 11 | - '-std=c99' 12 | - '-pedantic' 13 | includes: 14 | prefix: '-I' 15 | items: 16 | - 'src/' 17 | - '../src/' 18 | - 'testdata/' 19 | - *unit_tests_path 20 | defines: 21 | prefix: '-D' 22 | items: 23 | - UNITY_EXCLUDE_MATH_H 24 | - UNITY_INCLUDE_DOUBLE 25 | - UNITY_SUPPORT_TEST_CASES 26 | - UNITY_SUPPORT_64 27 | object_files: 28 | prefix: '-o' 29 | extension: '.o' 30 | destination: *build_path 31 | linker: 32 | path: gcc 33 | options: 34 | - -lm 35 | - '-m64' 36 | includes: 37 | prefix: '-I' 38 | object_files: 39 | path: *build_path 40 | extension: '.o' 41 | bin_files: 42 | prefix: '-o' 43 | extension: '.exe' 44 | destination: *build_path 45 | colour: true 46 | :unity: 47 | :plugins: [] 48 | -------------------------------------------------------------------------------- /tests/unity/test/targets/hitech_picc18.yml: -------------------------------------------------------------------------------- 1 | # rumor has it that this yaml file works for the standard edition of the 2 | # hitech PICC18 compiler, but not the pro version. 3 | # 4 | compiler: 5 | path: cd build && picc18 6 | source_path: '..\src\' 7 | unit_tests_path: &unit_tests_path 'tests\' 8 | build_path: &build_path 'build\' 9 | options: 10 | - --chip=18F87J10 11 | - --ide=hitide 12 | - --q #quiet please 13 | - --asmlist 14 | - --codeoffset=0 15 | - --emi=wordwrite # External memory interface protocol 16 | - --warn=0 # allow all normal warning messages 17 | - --errors=10 # Number of errors before aborting compile 18 | - --char=unsigned 19 | - -Bl # Large memory model 20 | - -G # generate symbol file 21 | - --cp=16 # 16-bit pointers 22 | - --double=24 23 | - -N255 # 255-char symbol names 24 | - --opt=none # Do not use any compiler optimziations 25 | - -c # compile only 26 | - -M 27 | includes: 28 | prefix: '-I' 29 | items: 30 | - 'c:/Projects/NexGen/Prototypes/CMockTest/src/' 31 | - 'c:/Projects/NexGen/Prototypes/CMockTest/mocks/' 32 | - 'c:/CMock/src/' 33 | - 'c:/CMock/examples/src/' 34 | - 'c:/CMock/vendor/unity/src/' 35 | - 'c:/CMock/vendor/unity/examples/helper/' 36 | - *unit_tests_path 37 | defines: 38 | prefix: '-D' 39 | items: 40 | - UNITY_INT_WIDTH=16 41 | - UNITY_POINTER_WIDTH=16 42 | - CMOCK_MEM_STATIC 43 | - CMOCK_MEM_SIZE=3000 44 | - UNITY_SUPPORT_TEST_CASES 45 | - _PICC18 46 | object_files: 47 | # prefix: '-O' # Hi-Tech doesn't want a prefix. They key off of filename .extensions, instead 48 | extension: '.obj' 49 | destination: *build_path 50 | 51 | linker: 52 | path: cd build && picc18 53 | options: 54 | - --chip=18F87J10 55 | - --ide=hitide 56 | - --cp=24 # 24-bit pointers. Is this needed for linker?? 57 | - --double=24 # Is this needed for linker?? 58 | - -Lw # Scan the pic87*w.lib in the lib/ of the compiler installation directory 59 | - --summary=mem,file # info listing 60 | - --summary=+psect 61 | - --summary=+hex 62 | - --output=+intel 63 | - --output=+mcof 64 | - --runtime=+init # Directs startup code to copy idata, ibigdata and ifardata psects from ROM to RAM. 65 | - --runtime=+clear # Directs startup code to clear bss, bigbss, rbss and farbss psects 66 | - --runtime=+clib # link in the c-runtime 67 | - --runtime=+keep # Keep the generated startup src after its obj is linked 68 | - -G # Generate src-level symbol file 69 | - -MIWasTheLastToBuild.map 70 | - --warn=0 # allow all normal warning messages 71 | - -Bl # Large memory model (probably not needed for linking) 72 | includes: 73 | prefix: '-I' 74 | object_files: 75 | path: *build_path 76 | extension: '.obj' 77 | bin_files: 78 | prefix: '-O' 79 | extension: '.hex' 80 | destination: *build_path 81 | 82 | simulator: 83 | path: 84 | pre_support: 85 | - 'java -client -jar ' # note space 86 | - ['C:\Program Files\HI-TECH Software\HI-TIDE\3.15\lib\', 'simpic18.jar'] 87 | - 18F87J10 88 | post_support: 89 | 90 | :cmock: 91 | :plugins: [] 92 | :includes: 93 | - Types.h 94 | :suite_teardown: | 95 | if (num_failures) 96 | _FAILED_TEST(); 97 | else 98 | _PASSED_TESTS(); 99 | return 0; 100 | 101 | colour: true 102 | -------------------------------------------------------------------------------- /tests/unity/test/targets/iar_arm_v4.yml: -------------------------------------------------------------------------------- 1 | tools_root: &tools_root 'C:\Program Files\IAR Systems\Embedded Workbench 4.0 Kickstart\' 2 | compiler: 3 | path: [*tools_root, 'arm\bin\iccarm.exe'] 4 | source_path: '..\src\' 5 | unit_tests_path: &unit_tests_path 'tests\' 6 | build_path: &build_path 'build\' 7 | options: 8 | - --dlib_config 9 | - [*tools_root, 'arm\lib\dl4tptinl8n.h'] 10 | - -z3 11 | - --no_cse 12 | - --no_unroll 13 | - --no_inline 14 | - --no_code_motion 15 | - --no_tbaa 16 | - --no_clustering 17 | - --no_scheduling 18 | - --debug 19 | - --cpu_mode thumb 20 | - --endian little 21 | - --cpu ARM7TDMI 22 | - --stack_align 4 23 | - --interwork 24 | - -e 25 | - --silent 26 | - --warnings_are_errors 27 | - --fpu None 28 | - --diag_suppress Pa050 29 | includes: 30 | prefix: '-I' 31 | items: 32 | - [*tools_root, 'arm\inc\'] 33 | - 'src\' 34 | - '..\src\' 35 | - 'testdata/' 36 | - *unit_tests_path 37 | - 'vendor\unity\src\' 38 | defines: 39 | prefix: '-D' 40 | items: 41 | - UNITY_SUPPORT_64 42 | - 'UNITY_SUPPORT_TEST_CASES' 43 | object_files: 44 | prefix: '-o' 45 | extension: '.r79' 46 | destination: *build_path 47 | linker: 48 | path: [*tools_root, 'common\bin\xlink.exe'] 49 | options: 50 | - -rt 51 | - [*tools_root, 'arm\lib\dl4tptinl8n.r79'] 52 | - -D_L_EXTMEM_START=0 53 | - -D_L_EXTMEM_SIZE=0 54 | - -D_L_HEAP_SIZE=120 55 | - -D_L_STACK_SIZE=32 56 | - -e_small_write=_formatted_write 57 | - -s 58 | - __program_start 59 | - -f 60 | - [*tools_root, '\arm\config\lnkarm.xcl'] 61 | includes: 62 | prefix: '-I' 63 | items: 64 | - [*tools_root, 'arm\config\'] 65 | - [*tools_root, 'arm\lib\'] 66 | object_files: 67 | path: *build_path 68 | extension: '.r79' 69 | bin_files: 70 | prefix: '-o' 71 | extension: '.d79' 72 | destination: *build_path 73 | simulator: 74 | path: [*tools_root, 'common\bin\CSpyBat.exe'] 75 | pre_support: 76 | - --silent 77 | - [*tools_root, 'arm\bin\armproc.dll'] 78 | - [*tools_root, 'arm\bin\armsim.dll'] 79 | post_support: 80 | - --plugin 81 | - [*tools_root, 'arm\bin\armbat.dll'] 82 | - --backend 83 | - -B 84 | - -p 85 | - [*tools_root, 'arm\config\ioat91sam7X256.ddf'] 86 | - -d 87 | - sim 88 | colour: true 89 | :unity: 90 | :plugins: [] 91 | -------------------------------------------------------------------------------- /tests/unity/test/targets/iar_arm_v5.yml: -------------------------------------------------------------------------------- 1 | tools_root: &tools_root 'C:\Program Files\IAR Systems\Embedded Workbench 5.3\' 2 | compiler: 3 | path: [*tools_root, 'arm\bin\iccarm.exe'] 4 | source_path: '..\src\' 5 | unit_tests_path: &unit_tests_path 'tests\' 6 | build_path: &build_path 'build\' 7 | options: 8 | - --dlib_config 9 | - [*tools_root, 'arm\inc\DLib_Config_Normal.h'] 10 | - --no_cse 11 | - --no_unroll 12 | - --no_inline 13 | - --no_code_motion 14 | - --no_tbaa 15 | - --no_clustering 16 | - --no_scheduling 17 | - --debug 18 | - --cpu_mode thumb 19 | - --endian=little 20 | - --cpu=ARM7TDMI 21 | - --interwork 22 | - --warnings_are_errors 23 | - --fpu=None 24 | - --diag_suppress=Pa050 25 | - --diag_suppress=Pe111 26 | - -e 27 | - -On 28 | includes: 29 | prefix: '-I' 30 | items: 31 | - [*tools_root, 'arm\inc\'] 32 | - 'src\' 33 | - '..\src\' 34 | - 'testdata/' 35 | - *unit_tests_path 36 | - 'vendor\unity\src\' 37 | - 'iar\iar_v5\incIAR\' 38 | defines: 39 | prefix: '-D' 40 | items: 41 | - UNITY_SUPPORT_64 42 | - 'UNITY_SUPPORT_TEST_CASES' 43 | object_files: 44 | prefix: '-o' 45 | extension: '.r79' 46 | destination: *build_path 47 | linker: 48 | path: [*tools_root, 'arm\bin\ilinkarm.exe'] 49 | options: 50 | - --redirect _Printf=_PrintfLarge 51 | - --redirect _Scanf=_ScanfSmall 52 | - --semihosting 53 | - --entry __iar_program_start 54 | - --config 55 | - [*tools_root, 'arm\config\generic.icf'] 56 | object_files: 57 | path: *build_path 58 | extension: '.o' 59 | bin_files: 60 | prefix: '-o' 61 | extension: '.out' 62 | destination: *build_path 63 | simulator: 64 | path: [*tools_root, 'common\bin\CSpyBat.exe'] 65 | pre_support: 66 | - --silent 67 | - [*tools_root, 'arm\bin\armproc.dll'] 68 | - [*tools_root, 'arm\bin\armsim.dll'] 69 | post_support: 70 | - --plugin 71 | - [*tools_root, 'arm\bin\armbat.dll'] 72 | - --backend 73 | - -B 74 | - -p 75 | - [*tools_root, 'arm\config\debugger\atmel\ioat91sam7X256.ddf'] 76 | - -d 77 | - sim 78 | colour: true 79 | :unity: 80 | :plugins: [] 81 | -------------------------------------------------------------------------------- /tests/unity/test/targets/iar_arm_v5_3.yml: -------------------------------------------------------------------------------- 1 | tools_root: &tools_root 'C:\Program Files\IAR Systems\Embedded Workbench 5.3\' 2 | compiler: 3 | path: [*tools_root, 'arm\bin\iccarm.exe'] 4 | source_path: '..\src\' 5 | unit_tests_path: &unit_tests_path 'tests\' 6 | build_path: &build_path 'build\' 7 | options: 8 | - --dlib_config 9 | - [*tools_root, 'arm\inc\DLib_Config_Normal.h'] 10 | - --no_cse 11 | - --no_unroll 12 | - --no_inline 13 | - --no_code_motion 14 | - --no_tbaa 15 | - --no_clustering 16 | - --no_scheduling 17 | - --debug 18 | - --cpu_mode thumb 19 | - --endian=little 20 | - --cpu=ARM7TDMI 21 | - --interwork 22 | - --warnings_are_errors 23 | - --fpu=None 24 | - --diag_suppress=Pa050 25 | - --diag_suppress=Pe111 26 | - -e 27 | - -On 28 | includes: 29 | prefix: '-I' 30 | items: 31 | - [*tools_root, 'arm\inc\'] 32 | - 'src\' 33 | - '..\src\' 34 | - 'testdata/' 35 | - *unit_tests_path 36 | - 'vendor\unity\src\' 37 | - 'iar\iar_v5\incIAR\' 38 | defines: 39 | prefix: '-D' 40 | items: 41 | - UNITY_SUPPORT_64 42 | - 'UNITY_SUPPORT_TEST_CASES' 43 | object_files: 44 | prefix: '-o' 45 | extension: '.r79' 46 | destination: *build_path 47 | linker: 48 | path: [*tools_root, 'arm\bin\ilinkarm.exe'] 49 | options: 50 | - --redirect _Printf=_PrintfLarge 51 | - --redirect _Scanf=_ScanfSmall 52 | - --semihosting 53 | - --entry __iar_program_start 54 | - --config 55 | - [*tools_root, 'arm\config\generic.icf'] 56 | object_files: 57 | path: *build_path 58 | extension: '.o' 59 | bin_files: 60 | prefix: '-o' 61 | extension: '.out' 62 | destination: *build_path 63 | simulator: 64 | path: [*tools_root, 'common\bin\CSpyBat.exe'] 65 | pre_support: 66 | - --silent 67 | - [*tools_root, 'arm\bin\armproc.dll'] 68 | - [*tools_root, 'arm\bin\armsim.dll'] 69 | post_support: 70 | - --plugin 71 | - [*tools_root, 'arm\bin\armbat.dll'] 72 | - --backend 73 | - -B 74 | - -p 75 | - [*tools_root, 'arm\config\debugger\atmel\ioat91sam7X256.ddf'] 76 | - -d 77 | - sim 78 | colour: true 79 | :unity: 80 | :plugins: [] 81 | -------------------------------------------------------------------------------- /tests/unity/test/targets/iar_armcortex_LM3S9B92_v5_4.yml: -------------------------------------------------------------------------------- 1 | #Default tool path for IAR 5.4 on Windows XP 64bit 2 | tools_root: &tools_root 'C:\Program Files (x86)\IAR Systems\Embedded Workbench 5.4 Kickstart\' 3 | compiler: 4 | path: [*tools_root, 'arm\bin\iccarm.exe'] 5 | source_path: '..\src\' 6 | unit_tests_path: &unit_tests_path 'tests\' 7 | build_path: &build_path 'build\' 8 | options: 9 | - --diag_suppress=Pa050 10 | #- --diag_suppress=Pe111 11 | - --debug 12 | - --endian=little 13 | - --cpu=Cortex-M3 14 | - --no_path_in_file_macros 15 | - -e 16 | - --fpu=None 17 | - --dlib_config 18 | - [*tools_root, 'arm\inc\DLib_Config_Normal.h'] 19 | #- --preinclude --preinclude C:\Vss\T2 Working\common\system.h 20 | - --interwork 21 | - --warnings_are_errors 22 | # - Ohz 23 | - -Oh 24 | # - --no_cse 25 | # - --no_unroll 26 | # - --no_inline 27 | # - --no_code_motion 28 | # - --no_tbaa 29 | # - --no_clustering 30 | # - --no_scheduling 31 | 32 | includes: 33 | prefix: '-I' 34 | items: 35 | - [*tools_root, 'arm\inc\'] 36 | - 'src\' 37 | - '..\src\' 38 | - 'testdata/' 39 | - *unit_tests_path 40 | - 'vendor\unity\src\' 41 | - 'iar\iar_v5\incIAR\' 42 | defines: 43 | prefix: '-D' 44 | items: 45 | - ewarm 46 | - PART_LM3S9B92 47 | - TARGET_IS_TEMPEST_RB1 48 | - USE_ROM_DRIVERS 49 | - UART_BUFFERED 50 | - UNITY_SUPPORT_64 51 | object_files: 52 | prefix: '-o' 53 | extension: '.r79' 54 | destination: *build_path 55 | linker: 56 | path: [*tools_root, 'arm\bin\ilinkarm.exe'] 57 | options: 58 | - --redirect _Printf=_PrintfLarge 59 | - --redirect _Scanf=_ScanfSmall 60 | - --semihosting 61 | - --entry __iar_program_start 62 | - --config 63 | - [*tools_root, 'arm\config\generic.icf'] 64 | # - ['C:\Temp\lm3s9b92.icf'] 65 | object_files: 66 | path: *build_path 67 | extension: '.o' 68 | bin_files: 69 | prefix: '-o' 70 | extension: '.out' 71 | destination: *build_path 72 | simulator: 73 | path: [*tools_root, 'common\bin\CSpyBat.exe'] 74 | pre_support: 75 | #- --silent 76 | - [*tools_root, 'arm\bin\armproc.dll'] 77 | - [*tools_root, 'arm\bin\armsim2.dll'] 78 | post_support: 79 | - --plugin 80 | - [*tools_root, 'arm\bin\armbat.dll'] 81 | - --backend 82 | - -B 83 | - --endian=little 84 | - --cpu=Cortex-M3 85 | - --fpu=None 86 | - -p 87 | - [*tools_root, 'arm\config\debugger\TexasInstruments\iolm3sxxxx.ddf'] 88 | - --semihosting 89 | - --device=LM3SxBxx 90 | #- -d 91 | #- sim 92 | colour: true 93 | :unity: 94 | :plugins: [] 95 | -------------------------------------------------------------------------------- /tests/unity/test/targets/iar_cortexm3_v5.yml: -------------------------------------------------------------------------------- 1 | # unit testing under iar compiler / simulator for STM32 Cortex-M3 2 | 3 | tools_root: &tools_root 'C:\Program Files\IAR Systems\Embedded Workbench 5.4\' 4 | compiler: 5 | path: [*tools_root, 'arm\bin\iccarm.exe'] 6 | source_path: '..\src\' 7 | unit_tests_path: &unit_tests_path 'tests\' 8 | build_path: &build_path 'build\' 9 | options: 10 | - --dlib_config 11 | - [*tools_root, 'arm\inc\DLib_Config_Normal.h'] 12 | - --no_cse 13 | - --no_unroll 14 | - --no_inline 15 | - --no_code_motion 16 | - --no_tbaa 17 | - --no_clustering 18 | - --no_scheduling 19 | - --debug 20 | - --cpu_mode thumb 21 | - --endian=little 22 | - --cpu=Cortex-M3 23 | - --interwork 24 | - --warnings_are_errors 25 | - --fpu=None 26 | - --diag_suppress=Pa050 27 | - --diag_suppress=Pe111 28 | - -e 29 | - -On 30 | includes: 31 | prefix: '-I' 32 | items: 33 | - [*tools_root, 'arm\inc\'] 34 | - 'src\' 35 | - '..\src\' 36 | - 'testdata/' 37 | - *unit_tests_path 38 | - 'vendor\unity\src\' 39 | - 'iar\iar_v5\incIAR\' 40 | defines: 41 | prefix: '-D' 42 | items: 43 | - 'IAR' 44 | - 'UNITY_SUPPORT_64' 45 | - 'UNITY_SUPPORT_TEST_CASES' 46 | object_files: 47 | prefix: '-o' 48 | extension: '.r79' 49 | destination: *build_path 50 | linker: 51 | path: [*tools_root, 'arm\bin\ilinkarm.exe'] 52 | options: 53 | - --redirect _Printf=_PrintfLarge 54 | - --redirect _Scanf=_ScanfSmall 55 | - --semihosting 56 | - --entry __iar_program_start 57 | - --config 58 | - [*tools_root, 'arm\config\generic_cortex.icf'] 59 | object_files: 60 | path: *build_path 61 | extension: '.o' 62 | bin_files: 63 | prefix: '-o' 64 | extension: '.out' 65 | destination: *build_path 66 | simulator: 67 | path: [*tools_root, 'common\bin\CSpyBat.exe'] 68 | pre_support: 69 | - --silent 70 | - [*tools_root, 'arm\bin\armproc.dll'] 71 | - [*tools_root, 'arm\bin\armsim.dll'] 72 | post_support: 73 | - --plugin 74 | - [*tools_root, 'arm\bin\armbat.dll'] 75 | - --backend 76 | - -B 77 | - -p 78 | - [*tools_root, 'arm\config\debugger\ST\iostm32f107xx.ddf'] 79 | - --cpu=Cortex-M3 80 | - -d 81 | - sim 82 | colour: true 83 | :unity: 84 | :plugins: [] 85 | -------------------------------------------------------------------------------- /tests/unity/test/targets/iar_msp430.yml: -------------------------------------------------------------------------------- 1 | tools_root: &tools_root 'C:\Program Files\IAR Systems\Embedded Workbench 5.3 MSP430\' 2 | core_root: &core_root [*tools_root, '430\'] 3 | core_bin: &core_bin [*core_root, 'bin\'] 4 | core_config: &core_config [*core_root, 'config\'] 5 | core_lib: &core_lib [*core_root, 'lib\'] 6 | core_inc: &core_inc [*core_root, 'inc\'] 7 | core_config: &core_config [*core_root, 'config\'] 8 | 9 | compiler: 10 | path: [*core_bin, 'icc430.exe'] 11 | source_path: '..\src\' 12 | unit_tests_path: &unit_tests_path 'tests\' 13 | build_path: &build_path 'build\' 14 | options: 15 | - --dlib_config 16 | - [*core_lib, 'dlib\dl430fn.h'] 17 | - --no_cse 18 | - --no_unroll 19 | - --no_inline 20 | - --no_code_motion 21 | - --no_tbaa 22 | - --debug 23 | - -e 24 | - -Ol 25 | - --multiplier=16 26 | - --double=32 27 | - --diag_suppress Pa050 28 | - --diag_suppress Pe111 29 | includes: 30 | prefix: '-I' 31 | items: 32 | - *core_inc 33 | - [*core_inc, 'dlib'] 34 | - [*core_lib, 'dlib'] 35 | - 'src\' 36 | - '../src/' 37 | - 'testdata/' 38 | - *unit_tests_path 39 | - 'vendor\unity\src' 40 | defines: 41 | prefix: '-D' 42 | items: 43 | - '__MSP430F149__' 44 | - 'INT_WIDTH=16' 45 | - 'UNITY_EXCLUDE_FLOAT' 46 | - 'UNITY_SUPPORT_TEST_CASES' 47 | object_files: 48 | prefix: '-o' 49 | extension: '.r43' 50 | destination: *build_path 51 | linker: 52 | path: [*core_bin, 'xlink.exe'] 53 | options: 54 | - -rt 55 | - [*core_lib, 'dlib\dl430fn.r43'] 56 | - -e_PrintfTiny=_Printf 57 | - -e_ScanfSmall=_Scanf 58 | - -s __program_start 59 | - -D_STACK_SIZE=50 60 | - -D_DATA16_HEAP_SIZE=50 61 | - -D_DATA20_HEAP_SIZE=50 62 | - -f 63 | - [*core_config, 'lnk430f5438.xcl'] 64 | - -f 65 | - [*core_config, 'multiplier.xcl'] 66 | includes: 67 | prefix: '-I' 68 | items: 69 | - *core_config 70 | - *core_lib 71 | - [*core_lib, 'dlib'] 72 | object_files: 73 | path: *build_path 74 | extension: '.r79' 75 | bin_files: 76 | prefix: '-o' 77 | extension: '.d79' 78 | destination: *build_path 79 | simulator: 80 | path: [*tools_root, 'common\bin\CSpyBat.exe'] 81 | pre_support: 82 | - --silent 83 | - [*core_bin, '430proc.dll'] 84 | - [*core_bin, '430sim.dll'] 85 | post_support: 86 | - --plugin 87 | - [*core_bin, '430bat.dll'] 88 | - --backend -B 89 | - --cpu MSP430F5438 90 | - -p 91 | - [*core_config, 'MSP430F5438.ddf'] 92 | - -d sim 93 | colour: true 94 | :unity: 95 | :plugins: [] 96 | -------------------------------------------------------------------------------- /tests/unity/test/targets/iar_sh2a_v6.yml: -------------------------------------------------------------------------------- 1 | tools_root: &tools_root 'C:\Program Files\IAR Systems\Embedded Workbench 6.0\' 2 | compiler: 3 | path: [*tools_root, 'sh\bin\iccsh.exe'] 4 | source_path: '..\src\' 5 | unit_tests_path: &unit_tests_path 'tests\' 6 | build_path: &build_path 'build\' 7 | options: 8 | - -e 9 | - --char_is_signed 10 | - -Ol 11 | - --no_cse 12 | - --no_unroll 13 | - --no_inline 14 | - --no_code_motion 15 | - --no_tbaa 16 | - --no_scheduling 17 | - --no_clustering 18 | - --debug 19 | - --dlib_config 20 | - [*tools_root, 'sh\inc\DLib_Product.h'] 21 | - --double=32 22 | - --code_model=huge 23 | - --data_model=huge 24 | - --core=sh2afpu 25 | - --warnings_affect_exit_code 26 | - --warnings_are_errors 27 | - --mfc 28 | - --use_unix_directory_separators 29 | - --diag_suppress=Pe161 30 | includes: 31 | prefix: '-I' 32 | items: 33 | - [*tools_root, 'sh\inc\'] 34 | - [*tools_root, 'sh\inc\c'] 35 | - 'src\' 36 | - '..\src\' 37 | - 'testdata/' 38 | - *unit_tests_path 39 | - 'vendor\unity\src\' 40 | defines: 41 | prefix: '-D' 42 | items: 43 | - UNITY_SUPPORT_64 44 | - 'UNITY_SUPPORT_TEST_CASES' 45 | object_files: 46 | prefix: '-o' 47 | extension: '.o' 48 | destination: *build_path 49 | linker: 50 | path: [*tools_root, 'sh\bin\ilinksh.exe'] 51 | options: 52 | - --redirect __Printf=__PrintfSmall 53 | - --redirect __Scanf=__ScanfSmall 54 | - --config 55 | - [*tools_root, 'sh\config\generic.icf'] 56 | - --config_def _CSTACK_SIZE=0x800 57 | - --config_def _HEAP_SIZE=0x800 58 | - --config_def _INT_TABLE=0x10 59 | - --entry __iar_program_start 60 | - --debug_lib 61 | object_files: 62 | path: *build_path 63 | extension: '.o' 64 | bin_files: 65 | prefix: '-o' 66 | extension: '.out' 67 | destination: *build_path 68 | simulator: 69 | path: [*tools_root, 'common\bin\CSpyBat.exe'] 70 | pre_support: 71 | - --silent 72 | - [*tools_root, 'sh\bin\shproc.dll'] 73 | - [*tools_root, 'sh\bin\shsim.dll'] 74 | post_support: 75 | - --plugin 76 | - [*tools_root, 'sh\bin\shbat.dll'] 77 | - --backend 78 | - -B 79 | - --core sh2afpu 80 | - -p 81 | - [*tools_root, 'sh\config\debugger\io7264.ddf'] 82 | - -d 83 | - sim 84 | colour: true 85 | :unity: 86 | :plugins: [] 87 | -------------------------------------------------------------------------------- /tests/unity/test/testdata/CException.h: -------------------------------------------------------------------------------- 1 | #ifndef CEXCEPTION_H 2 | #define CEXCEPTION_H 3 | 4 | #define CEXCEPTION_BEING_USED 1 5 | 6 | #define CEXCEPTION_NONE 0 7 | #define CEXCEPTION_T int e = 1; (void) 8 | #define Try if (e) 9 | #define Catch(a) if (!a) 10 | 11 | #endif //CEXCEPTION_H 12 | -------------------------------------------------------------------------------- /tests/unity/test/testdata/Defs.h: -------------------------------------------------------------------------------- 1 | #ifndef DEF_H 2 | #define DEF_H 3 | 4 | #define EXTERN_DECL 5 | 6 | extern int CounterSuiteSetup; 7 | 8 | #endif //DEF_H 9 | -------------------------------------------------------------------------------- /tests/unity/test/testdata/cmock.h: -------------------------------------------------------------------------------- 1 | #ifndef CMOCK_H 2 | #define CMOCK_H 3 | 4 | int CMockMemFreeFinalCounter = 0; 5 | int mockMock_Init_Counter = 0; 6 | int mockMock_Verify_Counter = 0; 7 | int mockMock_Destroy_Counter = 0; 8 | 9 | void CMock_Guts_MemFreeFinal(void) { CMockMemFreeFinalCounter++; } 10 | void mockMock_Init(void) { mockMock_Init_Counter++; } 11 | void mockMock_Verify(void) { mockMock_Verify_Counter++; } 12 | void mockMock_Destroy(void) { mockMock_Destroy_Counter++; } 13 | 14 | #endif //CMOCK_H 15 | -------------------------------------------------------------------------------- /tests/unity/test/testdata/mockMock.h: -------------------------------------------------------------------------------- 1 | #ifndef MOCK_MOCK_H 2 | #define MOCK_MOCK_H 3 | 4 | extern int mockMock_Init_Counter; 5 | extern int mockMock_Verify_Counter; 6 | extern int mockMock_Destroy_Counter; 7 | extern int CMockMemFreeFinalCounter; 8 | 9 | void mockMock_Init(void); 10 | void mockMock_Verify(void); 11 | void mockMock_Destroy(void); 12 | 13 | #endif //MOCK_MOCK_H 14 | -------------------------------------------------------------------------------- /tests/unity/test/testdata/testRunnerGeneratorSmall.c: -------------------------------------------------------------------------------- 1 | /* This Test File Is Used To Verify Many Combinations Of Using the Generate Test Runner Script */ 2 | 3 | #include 4 | #include "unity.h" 5 | #include "Defs.h" 6 | 7 | /* Notes about prefixes: 8 | test - normal default prefix. these are "always run" tests for this procedure 9 | spec - normal default prefix. required to run default setup/teardown calls. 10 | */ 11 | 12 | /* Support for Meta Test Rig */ 13 | #define TEST_CASE(a) 14 | void putcharSpy(int c) { (void)putchar(c);} // include passthrough for linking tests 15 | 16 | /* Global Variables Used During These Tests */ 17 | int CounterSetup = 0; 18 | int CounterTeardown = 0; 19 | int CounterSuiteSetup = 0; 20 | 21 | void setUp(void) 22 | { 23 | CounterSetup = 1; 24 | } 25 | 26 | void tearDown(void) 27 | { 28 | CounterTeardown = 1; 29 | } 30 | 31 | void custom_setup(void) 32 | { 33 | CounterSetup = 2; 34 | } 35 | 36 | void custom_teardown(void) 37 | { 38 | CounterTeardown = 2; 39 | } 40 | 41 | void test_ThisTestAlwaysPasses(void) 42 | { 43 | TEST_PASS(); 44 | } 45 | 46 | void test_ThisTestAlwaysFails(void) 47 | { 48 | TEST_FAIL_MESSAGE("This Test Should Fail"); 49 | } 50 | 51 | void test_ThisTestAlwaysIgnored(void) 52 | { 53 | TEST_IGNORE_MESSAGE("This Test Should Be Ignored"); 54 | } 55 | 56 | void spec_ThisTestPassesWhenNormalSetupRan(void) 57 | { 58 | TEST_ASSERT_EQUAL_MESSAGE(1, CounterSetup, "Normal Setup Wasn't Run"); 59 | } 60 | 61 | void spec_ThisTestPassesWhenNormalTeardownRan(void) 62 | { 63 | TEST_ASSERT_EQUAL_MESSAGE(1, CounterTeardown, "Normal Teardown Wasn't Run"); 64 | } 65 | 66 | -------------------------------------------------------------------------------- /tests/unity/test/tests/testparameterized.c: -------------------------------------------------------------------------------- 1 | /* ========================================== 2 | Unity Project - A Test Framework for C 3 | Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 4 | [Released under MIT License. Please refer to license.txt for details] 5 | ========================================== */ 6 | 7 | #include 8 | #include 9 | #include "unity.h" 10 | 11 | void putcharSpy(int c) { (void)putchar(c);} // include passthrough for linking tests 12 | 13 | #define TEST_CASE(...) 14 | 15 | #define EXPECT_ABORT_BEGIN \ 16 | if (TEST_PROTECT()) \ 17 | { 18 | 19 | #define VERIFY_FAILS_END \ 20 | } \ 21 | Unity.CurrentTestFailed = (Unity.CurrentTestFailed != 0) ? 0 : 1; \ 22 | if (Unity.CurrentTestFailed == 1) { \ 23 | SetToOneMeanWeAlreadyCheckedThisGuy = 1; \ 24 | UnityPrintNumberUnsigned(Unity.CurrentTestLineNumber); \ 25 | UNITY_OUTPUT_CHAR(':'); \ 26 | UnityPrint(Unity.CurrentTestName); \ 27 | UnityPrint(":FAIL: [[[[ Test Should Have Failed But Did Not ]]]]"); \ 28 | UNITY_OUTPUT_CHAR('\n'); \ 29 | } 30 | 31 | #define VERIFY_IGNORES_END \ 32 | } \ 33 | Unity.CurrentTestFailed = (Unity.CurrentTestIgnored != 0) ? 0 : 1; \ 34 | Unity.CurrentTestIgnored = 0; \ 35 | if (Unity.CurrentTestFailed == 1) { \ 36 | SetToOneMeanWeAlreadyCheckedThisGuy = 1; \ 37 | UnityPrintNumberUnsigned(Unity.CurrentTestLineNumber); \ 38 | UNITY_OUTPUT_CHAR(':'); \ 39 | UnityPrint(Unity.CurrentTestName); \ 40 | UnityPrint(":FAIL: [[[[ Test Should Have Ignored But Did Not ]]]]"); \ 41 | UNITY_OUTPUT_CHAR('\n'); \ 42 | } 43 | 44 | int SetToOneToFailInTearDown; 45 | int SetToOneMeanWeAlreadyCheckedThisGuy; 46 | 47 | void setUp(void) 48 | { 49 | SetToOneToFailInTearDown = 0; 50 | SetToOneMeanWeAlreadyCheckedThisGuy = 0; 51 | } 52 | 53 | void tearDown(void) 54 | { 55 | if (SetToOneToFailInTearDown == 1) 56 | TEST_FAIL_MESSAGE("<= Failed in tearDown"); 57 | if ((SetToOneMeanWeAlreadyCheckedThisGuy == 0) && (Unity.CurrentTestFailed > 0)) 58 | { 59 | UnityPrint(": [[[[ Test Should Have Passed But Did Not ]]]]"); 60 | UNITY_OUTPUT_CHAR('\n'); 61 | } 62 | } 63 | 64 | TEST_CASE(0) 65 | TEST_CASE(44) 66 | TEST_CASE((90)+9) 67 | void test_TheseShouldAllPass(int Num) 68 | { 69 | TEST_ASSERT_TRUE(Num < 100); 70 | } 71 | 72 | TEST_CASE(3) 73 | TEST_CASE(77) 74 | TEST_CASE( (99) + 1 - (1)) 75 | void test_TheseShouldAllFail(int Num) 76 | { 77 | EXPECT_ABORT_BEGIN 78 | TEST_ASSERT_TRUE(Num > 100); 79 | VERIFY_FAILS_END 80 | } 81 | 82 | TEST_CASE(1) 83 | TEST_CASE(44) 84 | TEST_CASE(99) 85 | TEST_CASE(98) 86 | void test_TheseAreEveryOther(int Num) 87 | { 88 | if (Num & 1) 89 | { 90 | EXPECT_ABORT_BEGIN 91 | TEST_ASSERT_TRUE(Num > 100); 92 | VERIFY_FAILS_END 93 | } 94 | else 95 | { 96 | TEST_ASSERT_TRUE(Num < 100); 97 | } 98 | } 99 | 100 | void test_NormalPassesStillWork(void) 101 | { 102 | TEST_ASSERT_TRUE(1); 103 | } 104 | 105 | void test_NormalFailsStillWork(void) 106 | { 107 | EXPECT_ABORT_BEGIN 108 | TEST_ASSERT_TRUE(0); 109 | VERIFY_FAILS_END 110 | } 111 | --------------------------------------------------------------------------------