diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 000000000..0e447d44b --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,18 @@ +version: 2.1 + +jobs: + latest-clang-autotools: + docker: + - image: silkeh/clang:latest + environment: + BUILD: autotools + CXX: clang + CPPUTEST_BUILD_DIR: ./cpputest_build + steps: + - checkout +# - run: mkdir -p $CPPUTEST_BUILD_DIR && cd $CPPUTEST_BUILD_DIR && ../scripts/travis_ci_build.sh + +workflows: + basic-build-and-test: + jobs: + - latest-clang-autotools diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..a586a94d3 --- /dev/null +++ b/.clang-format @@ -0,0 +1,41 @@ +--- +Language: Cpp +Standard: Cpp03 +AccessModifierOffset: -4 +AlignAfterOpenBracket: BlockIndent +AllowShortBlocksOnASingleLine: Empty +AllowShortEnumsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Empty +AlwaysBreakBeforeMultilineStrings: true +BinPackParameters: false +BreakBeforeBraces: Custom +BraceWrapping: + AfterClass: true + AfterControlStatement: Never + AfterEnum: true + AfterFunction: true + AfterNamespace: true + AfterStruct: true + AfterUnion: true + AfterExternBlock: false + BeforeCatch: true + BeforeElse: false + BeforeWhile: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakConstructorInitializers: AfterColon +ColumnLimit: 120 +NamespaceIndentation: All +NamespaceMacros: + - TEST_GROUP +FixNamespaceComments: false +IndentPPDirectives: BeforeHash +IndentWidth: 4 +IndentExternBlock: NoIndent +PackConstructorInitializers: CurrentLine +PointerAlignment: Left +SortIncludes: Never +SpaceBeforeParens: Custom +SpaceBeforeParensOptions: + AfterForeachMacros: false diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 000000000..6a48af4f9 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,11 @@ +--- +Checks: + - clang-diagnostic-* + - clang-analyzer-* + - bugprone-* + - -bugprone-easily-swappable-parameters + - -bugprone-casting-through-void # No C++ casts allowed +WarningsAsErrors: "*" +FormatStyle: file +UseColor: true +HeaderFilterRegex: .* diff --git a/.cproject b/.cproject deleted file mode 100644 index 1249a9da3..000000000 --- a/.cproject +++ /dev/null @@ -1,141 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - make - extensions - true - true - true - - - make - - examples - true - true - true - - - make - - cleanExamples - true - true - true - - - - - diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 000000000..30c51b94f --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1,7 @@ +# Enable via `git config blame.ignoreRevsFile .git-blame-ignore-revs` + +# Fix line endings +e674cfe759b20c6b78becbc50d8f9f644d32ea8a + +# clang-format +2a4942eb93b823c9723d4797222d6d3315f3bef2 diff --git a/.github/workflows/basic.yml b/.github/workflows/basic.yml new file mode 100644 index 000000000..47c3161ab --- /dev/null +++ b/.github/workflows/basic.yml @@ -0,0 +1,445 @@ +--- +name: Basic builds + +"on": + push: + pull_request: + +jobs: + clang-format: + name: Clang Format + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@main + - uses: DoozyX/clang-format-lint-action@v0.14 + with: + clangFormatVersion: 14 + source: examples + + codeql: + runs-on: ubuntu-latest + name: "CodeQL" + steps: + - name: Checkout + uses: actions/checkout@main + - name: CodeQL Initialization + uses: github/codeql-action/init@v2 + with: + languages: cpp + queries: +security-and-quality + - name: Build + run: | + mkdir _build && cd _build + cmake -DCMAKE_CXX_STANDARD=17 .. + make -j2 + - name: CodeQL Analysis + uses: github/codeql-action/analyze@v2 + + autotools: + strategy: + matrix: + include: + - name: Mac GNU + os: macos-latest + cc: gcc + cxx: g++ + make_args: tdd + - name: Mac Clang + os: macos-latest + cc: clang + cxx: clang++ + make_args: tdd + - name: Linux GNU + os: ubuntu-latest + cc: gcc + cxx: g++ + make_args: tdd + - name: Linux Clang + os: ubuntu-latest + cc: clang + cxx: clang++ + make_args: tdd + - name: Disable long long + os: ubuntu-latest + configure_args: --disable-longlong + make_args: tdd + - name: Distribution + os: ubuntu-latest + make_args: dist dist-zip VERSION=latest + - name: Install + os: ubuntu-latest + make_args: DESTDIR=install_autotools install + runs-on: ${{ matrix.os }} + name: Autotools ${{ matrix.name }} + steps: + - name: Checkout + uses: actions/checkout@main + - run: brew install automake libtool + if: ${{ startswith(matrix.os, 'macos') }} + - if: ${{ matrix.cxx }} + run: echo "CXX=${{ matrix.cxx }}" >> $GITHUB_ENV + - if: ${{ matrix.cc }} + run: echo "CC=${{ matrix.cc }}" >> $GITHUB_ENV + - name: Configure + run: | + autoreconf -i . + ./configure ${{ matrix.configure_args }} + - name: Build and test + run: make ${{ matrix.make_args }} + + cmake: + strategy: + matrix: + include: + - name: MSVC install + os: windows-latest + preset: MSVC + install: true + ctest_args: -C Debug + - name: MSVC 20 + os: windows-latest + cmake_args: -DCMAKE_CXX_STANDARD=20 + preset: MSVC + ctest_args: -C Debug + - name: ClangCL + os: windows-latest + cmake_args: -DCMAKE_CXX_STANDARD=17 + preset: ClangCL + ctest_args: -C Debug + - name: Clang-Tidy + os: ubuntu-latest + preset: clang-tidy + - name: Linux Clang 98 + os: ubuntu-latest + cmake_args: -DCMAKE_CXX_STANDARD=98 + preset: Clang + - name: Linux Clang 11 + os: ubuntu-latest + cmake_args: -DCMAKE_CXX_STANDARD=11 + preset: Clang + - name: Linux Clang 14 + os: ubuntu-latest + cmake_args: -DCMAKE_CXX_STANDARD=14 + preset: Clang + - name: Linux Clang 17 + os: ubuntu-latest + cmake_args: -DCMAKE_CXX_STANDARD=17 + preset: Clang + - name: Linux Clang 20 + os: ubuntu-latest + cmake_args: -DCMAKE_CXX_STANDARD=20 + preset: Clang + - name: Linux GNU 98 + os: ubuntu-latest + cmake_args: -DCMAKE_CXX_STANDARD=98 + preset: GNU + - name: No long long + os: ubuntu-latest + preset: no-long-long + - name: Detailed + os: ubuntu-latest + preset: detailed + - name: Linux GNU Install + os: ubuntu-latest + cmake_args: -DCMAKE_CXX_STANDARD=11 + preset: GNU + install: true + - name: Linux GNU 14 + os: ubuntu-latest + cmake_args: -DCMAKE_CXX_STANDARD=14 + preset: GNU + - name: Linux GNU 17 + os: ubuntu-latest + cmake_args: -DCMAKE_CXX_STANDARD=17 + preset: GNU + - name: Linux GNU 20 + os: ubuntu-latest + cmake_args: -DCMAKE_CXX_STANDARD=20 + preset: GNU + - name: MinGW + os: ubuntu-latest + preset: MinGW + apt_packages: mingw-w64 wine64 + - name: No C++ Standard Library + os: ubuntu-latest + preset: no-std-cpp + - name: No RTTI + os: ubuntu-latest + preset: no-rtti + - name: No Exceptions + os: ubuntu-latest + preset: no-exceptions + - name: No C Standard Library + os: ubuntu-latest + preset: no-std-c + - name: Coverage + os: ubuntu-latest + preset: coverage + apt_packages: lcov + - name: Address Sanitizer + os: ubuntu-latest + preset: asan + - name: GCC ARM embedded + os: ubuntu-latest + preset: arm-embedded + - name: Mac install + os: macos-latest + preset: defaults + install: true + - name: Apple Clang 14 + os: macos-latest + cmake_args: -DCMAKE_CXX_STANDARD=14 + preset: Clang + - name: Apple Clang 17 + os: macos-latest + cmake_args: -DCMAKE_CXX_STANDARD=17 + preset: Clang + - name: Apple Clang 20 + os: macos-latest + cmake_args: -DCMAKE_CXX_STANDARD=20 + preset: Clang + - name: Mac GNU 14 + os: macos-latest + cmake_args: -DCMAKE_CXX_STANDARD=14 + preset: GNU + - name: OpenWatcom DOS + os: ubuntu-latest + preset: DOS + apt_packages: dosbox + - name: Cygwin + os: windows-latest + preset: GNU + name: CMake ${{ matrix.name }} + runs-on: ${{ matrix.os }} + steps: + ### SETUP + + - name: Install packages + run: | + sudo apt-get update + sudo apt-get install -y ${{ matrix.apt_packages }} + if: ${{ matrix.apt_packages }} + + - uses: carlosperate/arm-none-eabi-gcc-action@v1 + if: ${{ matrix.name == 'GCC ARM embedded' }} + + - name: Install OpenWatcom + uses: open-watcom/setup-watcom@v0 + with: + version: "2.0" + if: ${{ matrix.name == 'OpenWatcom DOS' }} + + - run: git config --global core.autocrlf input + if: ${{ matrix.name == 'Cygwin' }} + - name: Checkout + uses: actions/checkout@main + + - name: Install Cygwin + uses: cygwin/cygwin-install-action@master + with: + platform: x86 + packages: > + cmake + gcc-core + gcc-g++ + make + if: ${{ matrix.name == 'Cygwin' }} + + ## BUILD AND TEST + + - name: Configure + run: cmake --preset ${{ matrix.preset }} ${{ matrix.cmake_args }} + - name: Build + run: cmake --build cpputest_build --verbose -j + - name: Save map files + uses: actions/upload-artifact@v4 + with: + name: "${{ matrix.name }} map files" + path: cpputest_build/**/*.map + - name: Test + run: > + ctest + --test-dir cpputest_build + ${{ matrix.ctest_args }} + --output-on-failure + + # POST PROCESSING + + - name: Install (*nix) + run: | + sudo cmake --install cpputest_build/ + pkg-config --print-provides cpputest + if: ${{ matrix.install && !startswith(matrix.os, 'windows')}} + - name: Install (Windows) + run: cmake --install cpputest_build/ --config=Debug + if: ${{ matrix.install && startswith(matrix.os, 'windows')}} + - name: Use install + run: | + cmake -B build -S examples + cmake --build build -j + ctest --test-dir build + if: ${{ matrix.install }} + + - name: Coverage + run: | + lcov --ignore-errors mismatch --capture --directory . --no-external --output-file lcov.info + lcov --remove lcov.info --output-file lcov.info '*/tests/*' + if: ${{ matrix.name == 'Coverage' }} + - name: Coveralls + uses: coverallsapp/github-action@master + with: + path-to-lcov: lcov.info + github-token: ${{ secrets.GITHUB_TOKEN }} + if: ${{ matrix.name == 'Coverage' }} + + test_report: + name: JUnit Test Report + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@main + - run: cmake --preset=defaults -DCPPUTEST_JUNIT_REPORT=TRUE + - run: cmake --build cpputest_build -j + - run: ctest --test-dir cpputest_build + - uses: actions/upload-artifact@v4 + if: success() || failure() + with: + name: test-results + path: "cpputest_build/**/cpputest_*.xml" + + make: + strategy: + matrix: + include: + - name: Defaults + make_target: test_defaults + - name: STDC++ disabled + make_target: test_disable_std_cpp + - name: Memory Leak Detection disabled + make_target: test_disable_memory_leak_detection + - name: Disable Leak Detection and STD C++ + make_target: test_disable_std_cpp_and_leak_detection + - name: debug disabled + make_target: test_disable_debug + - name: overridden CXXFLAGS and CFLAGS and CPPFLAGS + make_target: test_override_flags + - name: without Standard C library includes + make_target: test_disable_std_c + - name: different TARGET_PLATFORM + make_target: test_target_platform + - name: override flags and disable memory leak and STDC++ + make_target: test_override_and_disable + - name: Examples + make_target: test_examples + - name: JUnit Output + make_target: test_junit_output + # - name: gcov + # make_target: test_gcov + - name: VPATH usage + make_target: test_vpath + - name: VPATH Install + make_target: test_vpath_install + name: Make ${{ matrix.name }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@main + - name: Build + run: make -f Makefile_using_MakefileWorker ${{ matrix.make_target }} + + make_dos: + name: Make OpenWatcom DOS + runs-on: ubuntu-latest + env: + WATCOM: "./watcom" + TERM: linux + steps: + - name: Checkout + uses: actions/checkout@main + - name: Install tools + run: | + sudo apt-get update + sudo apt-get install -y dosbox + git clone https://github.com/cpputest/watcom-compiler.git $WATCOM + echo "$WATCOM/binl" >> $GITHUB_PATH + - name: Build + run: make -f platforms/Dos/Makefile + - name: Test + run: make -f platforms/Dos/Makefile test + + cmake_msys: + name: CMake MSYS + runs-on: windows-latest + defaults: + run: + shell: msys2 {0} + env: + LDFLAGS: -static + steps: + - name: Checkout + uses: actions/checkout@main + - uses: msys2/setup-msys2@v2 + with: + msystem: MINGW64 + update: true + install: > + git + mingw-w64-x86_64-cc + mingw-w64-x86_64-cmake + mingw-w64-x86_64-make + - name: Configure + run: cmake --preset=GNU + - name: Build + run: cmake --build cpputest_build -j + - name: Test + run: ctest --test-dir cpputest_build --output-on-failure + + autotools_msys: + name: Autotools MSYS + runs-on: windows-latest + defaults: + run: + shell: msys2 {0} + env: + LDFLAGS: -static + steps: + - uses: actions/checkout@v3 + - uses: msys2/setup-msys2@v2 + with: + msystem: MINGW64 + update: true + install: > + git + mingw-w64-x86_64-autotools + mingw-w64-x86_64-cc + mingw-w64-x86_64-make + - name: Configure + run: | + autoreconf -i . + ./configure + - name: Build and test + run: make tdd + + Docker: + strategy: + matrix: + image: ["ubuntu", "dos"] + runs-on: ubuntu-latest + name: Docker ${{ matrix.image }} + steps: + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + env: + TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} + if: ${{ env.TOKEN != '' }} + - name: Build + uses: docker/build-push-action@v3 + with: + file: docker/Dockerfile.${{ matrix.image }} + tags: cpputest/${{ matrix.image }} diff --git a/.github/workflows/test-report.yml b/.github/workflows/test-report.yml new file mode 100644 index 000000000..d44746601 --- /dev/null +++ b/.github/workflows/test-report.yml @@ -0,0 +1,17 @@ +--- +name: 'Test Report' +"on": + workflow_run: + workflows: ['Basic builds'] + types: + - completed +jobs: + report: + runs-on: ubuntu-latest + steps: + - uses: dorny/test-reporter@v1 + with: + artifact: test-results + name: JUnit Tests + path: "**/cpputest_*.xml" + reporter: java-junit diff --git a/.gitignore b/.gitignore index eda2a9d57..fa41116a8 100644 --- a/.gitignore +++ b/.gitignore @@ -88,7 +88,19 @@ generated/ *.deps/ *.dirstamp *.trs +lcov.info #IAR automatically generated files *.dep *.ewt + +# Watcom +*.LIB +*.LST +*.EXE +*.LOG +/console_output +/exit + +# Builds +/cpputest_build/ diff --git a/.project b/.project deleted file mode 100644 index 978d661d1..000000000 --- a/.project +++ /dev/null @@ -1,78 +0,0 @@ - - - CppUTest - - - - - - org.eclipse.cdt.managedbuilder.core.genmakebuilder - - - ?name? - - - - org.eclipse.cdt.make.core.append_environment - true - - - org.eclipse.cdt.make.core.autoBuildTarget - all - - - org.eclipse.cdt.make.core.buildArguments - - - - org.eclipse.cdt.make.core.buildCommand - make - - - org.eclipse.cdt.make.core.cleanBuildTarget - clean - - - org.eclipse.cdt.make.core.contents - org.eclipse.cdt.make.core.activeConfigSettings - - - org.eclipse.cdt.make.core.enableAutoBuild - true - - - org.eclipse.cdt.make.core.enableCleanBuild - true - - - org.eclipse.cdt.make.core.enableFullBuild - true - - - org.eclipse.cdt.make.core.fullBuildTarget - all - - - org.eclipse.cdt.make.core.stopOnError - true - - - org.eclipse.cdt.make.core.useDefaultBuildCmd - true - - - - - org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder - full,incremental, - - - - - - org.eclipse.cdt.core.cnature - org.eclipse.cdt.core.ccnature - org.eclipse.cdt.managedbuilder.core.managedBuildNature - org.eclipse.cdt.managedbuilder.core.ScannerConfigNature - - diff --git a/.settings/org.eclipse.cdt.core.prefs b/.settings/org.eclipse.cdt.core.prefs deleted file mode 100644 index 7bc75596d..000000000 --- a/.settings/org.eclipse.cdt.core.prefs +++ /dev/null @@ -1,152 +0,0 @@ -#Mon Jun 07 17:30:05 SGT 2010 -eclipse.preferences.version=1 -org.eclipse.cdt.core.formatter.alignment_for_arguments_in_method_invocation=16 -org.eclipse.cdt.core.formatter.alignment_for_base_clause_in_type_declaration=80 -org.eclipse.cdt.core.formatter.alignment_for_compact_if=0 -org.eclipse.cdt.core.formatter.alignment_for_conditional_expression=80 -org.eclipse.cdt.core.formatter.alignment_for_declarator_list=16 -org.eclipse.cdt.core.formatter.alignment_for_enumerator_list=48 -org.eclipse.cdt.core.formatter.alignment_for_expression_list=0 -org.eclipse.cdt.core.formatter.alignment_for_expressions_in_array_initializer=16 -org.eclipse.cdt.core.formatter.alignment_for_parameters_in_method_declaration=16 -org.eclipse.cdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16 -org.eclipse.cdt.core.formatter.brace_position_for_array_initializer=end_of_line -org.eclipse.cdt.core.formatter.brace_position_for_block=end_of_line -org.eclipse.cdt.core.formatter.brace_position_for_block_in_case=end_of_line -org.eclipse.cdt.core.formatter.brace_position_for_method_declaration=next_line -org.eclipse.cdt.core.formatter.brace_position_for_namespace_declaration=next_line -org.eclipse.cdt.core.formatter.brace_position_for_switch=end_of_line -org.eclipse.cdt.core.formatter.brace_position_for_type_declaration=next_line -org.eclipse.cdt.core.formatter.compact_else_if=true -org.eclipse.cdt.core.formatter.continuation_indentation=2 -org.eclipse.cdt.core.formatter.continuation_indentation_for_array_initializer=2 -org.eclipse.cdt.core.formatter.format_guardian_clause_on_one_line=false -org.eclipse.cdt.core.formatter.indent_access_specifier_compare_to_type_header=false -org.eclipse.cdt.core.formatter.indent_body_declarations_compare_to_access_specifier=true -org.eclipse.cdt.core.formatter.indent_body_declarations_compare_to_namespace_header=false -org.eclipse.cdt.core.formatter.indent_breaks_compare_to_cases=true -org.eclipse.cdt.core.formatter.indent_declaration_compare_to_template_header=false -org.eclipse.cdt.core.formatter.indent_empty_lines=false -org.eclipse.cdt.core.formatter.indent_statements_compare_to_block=true -org.eclipse.cdt.core.formatter.indent_statements_compare_to_body=true -org.eclipse.cdt.core.formatter.indent_switchstatements_compare_to_cases=true -org.eclipse.cdt.core.formatter.indent_switchstatements_compare_to_switch=false -org.eclipse.cdt.core.formatter.indentation.size=4 -org.eclipse.cdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert -org.eclipse.cdt.core.formatter.insert_new_line_after_template_declaration=do not insert -org.eclipse.cdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert -org.eclipse.cdt.core.formatter.insert_new_line_before_catch_in_try_statement=insert -org.eclipse.cdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert -org.eclipse.cdt.core.formatter.insert_new_line_before_else_in_if_statement=insert -org.eclipse.cdt.core.formatter.insert_new_line_before_identifier_in_function_declaration=do not insert -org.eclipse.cdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert -org.eclipse.cdt.core.formatter.insert_new_line_in_empty_block=insert -org.eclipse.cdt.core.formatter.insert_space_after_assignment_operator=insert -org.eclipse.cdt.core.formatter.insert_space_after_binary_operator=insert -org.eclipse.cdt.core.formatter.insert_space_after_closing_angle_bracket_in_template_arguments=insert -org.eclipse.cdt.core.formatter.insert_space_after_closing_angle_bracket_in_template_parameters=insert -org.eclipse.cdt.core.formatter.insert_space_after_closing_brace_in_block=insert -org.eclipse.cdt.core.formatter.insert_space_after_closing_paren_in_cast=insert -org.eclipse.cdt.core.formatter.insert_space_after_colon_in_base_clause=insert -org.eclipse.cdt.core.formatter.insert_space_after_colon_in_case=insert -org.eclipse.cdt.core.formatter.insert_space_after_colon_in_conditional=insert -org.eclipse.cdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert -org.eclipse.cdt.core.formatter.insert_space_after_comma_in_array_initializer=insert -org.eclipse.cdt.core.formatter.insert_space_after_comma_in_base_types=insert -org.eclipse.cdt.core.formatter.insert_space_after_comma_in_declarator_list=insert -org.eclipse.cdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert -org.eclipse.cdt.core.formatter.insert_space_after_comma_in_expression_list=insert -org.eclipse.cdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert -org.eclipse.cdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert -org.eclipse.cdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert -org.eclipse.cdt.core.formatter.insert_space_after_comma_in_template_arguments=insert -org.eclipse.cdt.core.formatter.insert_space_after_comma_in_template_parameters=insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_angle_bracket_in_template_arguments=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_angle_bracket_in_template_parameters=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_bracket=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_exception_specification=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_postfix_operator=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_prefix_operator=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_question_in_conditional=insert -org.eclipse.cdt.core.formatter.insert_space_after_semicolon_in_for=insert -org.eclipse.cdt.core.formatter.insert_space_after_unary_operator=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_assignment_operator=insert -org.eclipse.cdt.core.formatter.insert_space_before_binary_operator=insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_angle_bracket_in_template_arguments=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_angle_bracket_in_template_parameters=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_bracket=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_exception_specification=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_colon_in_base_clause=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_colon_in_case=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_colon_in_conditional=insert -org.eclipse.cdt.core.formatter.insert_space_before_colon_in_default=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_comma_in_base_types=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_comma_in_declarator_list=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_comma_in_expression_list=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_comma_in_template_arguments=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_comma_in_template_parameters=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_angle_bracket_in_template_arguments=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_angle_bracket_in_template_parameters=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_block=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_namespace_declaration=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_switch=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_bracket=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_catch=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_exception_specification=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_for=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_if=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_switch=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_while=insert -org.eclipse.cdt.core.formatter.insert_space_before_postfix_operator=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_prefix_operator=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_question_in_conditional=insert -org.eclipse.cdt.core.formatter.insert_space_before_semicolon=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_semicolon_in_for=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_unary_operator=do not insert -org.eclipse.cdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert -org.eclipse.cdt.core.formatter.insert_space_between_empty_brackets=do not insert -org.eclipse.cdt.core.formatter.insert_space_between_empty_parens_in_exception_specification=do not insert -org.eclipse.cdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert -org.eclipse.cdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert -org.eclipse.cdt.core.formatter.keep_else_statement_on_same_line=true -org.eclipse.cdt.core.formatter.keep_empty_array_initializer_on_one_line=false -org.eclipse.cdt.core.formatter.keep_imple_if_on_one_line=false -org.eclipse.cdt.core.formatter.keep_then_statement_on_same_line=true -org.eclipse.cdt.core.formatter.lineSplit=200 -org.eclipse.cdt.core.formatter.number_of_empty_lines_to_preserve=1 -org.eclipse.cdt.core.formatter.put_empty_statement_on_new_line=true -org.eclipse.cdt.core.formatter.tabulation.char=tab -org.eclipse.cdt.core.formatter.tabulation.size=4 -org.eclipse.cdt.core.formatter.use_tabs_only_for_leading_indentations=false diff --git a/.settings/org.eclipse.cdt.ui.prefs b/.settings/org.eclipse.cdt.ui.prefs deleted file mode 100644 index b684b38df..000000000 --- a/.settings/org.eclipse.cdt.ui.prefs +++ /dev/null @@ -1,4 +0,0 @@ -#Tue Dec 29 09:23:19 SGT 2009 -eclipse.preferences.version=1 -formatter_profile=_CppUTest Coding Style -formatter_settings_version=1 diff --git a/.travis.yml b/.travis.yml index e7b1e3145..1ce211e3e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -93,14 +93,14 @@ jobs: - sourceline: 'ppa:ubuntu-toolchain-r/test' - compiler: clang env: BUILD=cmake CPP_STD=17 - - CC=clang-10 - - CXX=clang++-10 + - CC=clang-11 + - CXX=clang++-11 addons: apt: sources: - - sourceline: 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-10 main' + - sourceline: 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-11 main' key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key' - packages: ['clang-10', 'libc++-10-dev', 'libc++abi-10-dev'] + packages: ['clang-11', 'libc++-11-dev', 'libc++abi-11-dev'] # Specific other tests - compiler: gcc diff --git a/CMakeLists.txt b/CMakeLists.txt index 88e0cfb5f..0b6a4eeaf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,19 @@ -project(CppUTest) - -set(CppUTest_version_major 4) -set(CppUTest_version_minor 0) - # 2.6.3 is needed for ctest support # 3.1 is needed for target_sources -cmake_minimum_required(VERSION 3.1) +# 3.8 is needed for try_compile improvements (CMP0067) +cmake_minimum_required(VERSION 3.8...3.31) + +project(CppUTest + VERSION 4.0 +) + +if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.21") + # PROJECT_IS_TOP_LEVEL is defined automatically +elseif (CMAKE_CURRENT_BINARY_DIR STREQUAL CMAKE_BINARY_DIR) + set(PROJECT_IS_TOP_LEVEL TRUE) +else() + set(PROJECT_IS_TOP_LEVEL FALSE) +endif() ############### # Conan support @@ -16,206 +24,131 @@ if (EXISTS "${CMAKE_BINARY_DIR}/conanbuildinfo.cmake") conan_basic_setup() endif() -# Check for functions before setting a lot of stuff -include(CheckFunctionExists) -set (CMAKE_REQUIRED_INCLUDES "unistd.h") -check_function_exists(fork HAVE_FORK) -if(HAVE_FORK) - add_definitions(-DCPPUTEST_HAVE_FORK) -endif(HAVE_FORK) - -check_function_exists(gettimeofday HAVE_GETTIMEOFDAY) -if(HAVE_GETTIMEOFDAY) - add_definitions(-DCPPUTEST_HAVE_GETTIMEOFDAY=1) -endif(HAVE_GETTIMEOFDAY) - -check_function_exists(pthread_mutex_lock HAVE_PTHREAD_MUTEX_LOCK) -if(HAVE_PTHREAD_MUTEX_LOCK) - add_definitions(-DCPPUTEST_HAVE_PTHREAD_MUTEX_LOCK=1) -endif(HAVE_PTHREAD_MUTEX_LOCK) - -check_function_exists(strdup HAVE_STRDUP) -if(HAVE_STRDUP) - add_definitions(-DCPPUTEST_HAVE_STRDUP=1) -endif(HAVE_STRDUP) - -if (MINGW) - # Apply workaround for MinGW timespec redefinition (pthread.h / time.h) - include(CheckStructHasMember) - check_struct_has_member("struct timespec" tv_sec time.h HAVE_STRUCT_TIMESPEC) - if (HAVE_STRUCT_TIMESPEC) - add_definitions(-D_TIMESPEC_DEFINED=1) - endif() +include(CTest) - if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - # Apply workaround for static/shared libraries on MinGW C/C++ compiler - # Issue occurs with CMake >= 3.9.0, it doesn't filter out gcc,gcc_s,gcc_eh from - # the implicit library list anymore, so the C++ linker is getting passed the static - # gcc_eh library since that's what the C linker uses by default. Only solution appears - # to be to force static linkage. - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static") +include(CMakeDependentOption) +option(CPPUTEST_STD_C_LIB_DISABLED "Disable the standard C library") + +cmake_dependent_option(CPPUTEST_STD_CPP_LIB_DISABLED "Use the standard C++ library" + OFF "NOT CPPUTEST_STD_C_LIB_DISABLED" ON) +cmake_dependent_option(CPPUTEST_MEM_LEAK_DETECTION_DISABLED "Enable memory leak detection" + OFF "NOT BORLAND;NOT CPPUTEST_STD_C_LIB_DISABLED" ON) +option(CPPUTEST_EXTENSIONS "Use the CppUTest extension library" ON) +include(CheckTypeSize) +check_type_size("long long" SIZEOF_LONGLONG) +cmake_dependent_option(CPPUTEST_USE_LONG_LONG "Support long long" + YES "HAVE_SIZEOF_LONGLONG" OFF) + +cmake_dependent_option(CPPUTEST_BUILD_TESTING "Compile and make tests for CppUTest" + ${PROJECT_IS_TOP_LEVEL} "BUILD_TESTING" OFF) +cmake_dependent_option(CPPUTEST_SPLIT_TESTS "Split tests into small executables" + OFF "CPPUTEST_BUILD_TESTING" OFF) +cmake_dependent_option(CPPUTEST_TEST_GTEST "Test GoogleTest integration" + OFF "CPPUTEST_BUILD_TESTING" OFF) +cmake_dependent_option(CPPUTEST_EXAMPLES "Compile and make examples?" + ${PROJECT_IS_TOP_LEVEL} "CPPUTEST_EXTENSIONS;NOT CPPUTEST_STD_CPP_LIB_DISABLED" OFF) + +if(NOT DEFINED CPPUTEST_PLATFORM) + if(DEFINED CPP_PLATFORM) + message(DEPRECATION + "The CPP_PLATFORM variable has been deprecated. " + "Use CPPUTEST_PLATFORM instead." + ) + set(CPPUTEST_PLATFORM ${CPP_PLATFORM}) + else() + if(CPPUTEST_STD_C_LIB_DISABLED) + set(CPPUTEST_PLATFORM OFF) + elseif(MSVC) + set(CPPUTEST_PLATFORM VisualCpp) + elseif(CMAKE_CXX_COMPILER_ID STREQUAL "IAR") + set(CPPUTEST_PLATFORM Iar) + elseif(CMAKE_CXX_COMPILER_ID STREQUAL "ARMCC") + set(CPPUTEST_PLATFORM armcc) + elseif(DOS) + set(CPPUTEST_PLATFORM Dos) + elseif(BORLAND) + set(CPPUTEST_PLATFORM Borland) + else() + set(CPPUTEST_PLATFORM Gcc) endif() + endif() + message(STATUS "Setting CPPUTEST_PLATFORM: ${CPPUTEST_PLATFORM}") +endif() +set(CPPUTEST_PLATFORM "${CPPUTEST_PLATFORM}" CACHE STRING "Platform implementation") +set_property( + CACHE CPPUTEST_PLATFORM + PROPERTY STRINGS + armcc Borland C2000 Dos Gcc Iar Keil Symbian VisualCpp OFF +) + +include(CheckCXXSymbolExists) +check_cxx_symbol_exists(fopen_s "stdio.h" CPPUTEST_HAVE_SECURE_STDLIB) +cmake_dependent_option(CPPUTEST_USE_SECURE_STDLIB "Use MSVC safe functions" + ON "WIN32;CPPUTEST_HAVE_SECURE_STDLIB" OFF) + +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules") +if(NOT PROJECT_IS_TOP_LEVEL) + set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" PARENT_SCOPE) endif() -option(STD_C "Use the standard C library" ON) -option(STD_CPP "Use the standard C++ library" ON) -option(CPPUTEST_FLAGS "Use the CFLAGS/CXXFLAGS/LDFLAGS set by CppUTest" ON) -option(MEMORY_LEAK_DETECTION "Enable memory leak detection" ON) -option(EXTENSIONS "Use the CppUTest extension library" ON) -option(LONGLONG "Support long long" OFF) -option(MAP_FILE "Enable the creation of a map file" OFF) -option(COVERAGE "Enable running with coverage" OFF) -option(C++11 "Compile with C++11 support" OFF) -option(WERROR "Compile with warnings as errors" OFF) - -option(TESTS "Compile and make tests for the code?" ON) -option(TESTS_DETAILED "Run each test separately instead of grouped?" OFF) -option(TESTS_BUILD_DISCOVER "Build time test discover" ON) - -option(EXAMPLES "Compile and make exaples?" OFF) - -option(VERBOSE_CONFIG "Print configuration to stdout during generation" ON) - -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "What kind of build this is" FORCE) -endif(NOT CMAKE_BUILD_TYPE) - -# Pkg-config file -include(FindPkgConfig) -set(CppUTest_PKGCONFIG_FILE cpputest.pc) - -set(CppUTestRootDirectory ${PROJECT_SOURCE_DIR}) -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CppUTestRootDirectory}/cmake/Modules) +if( + (NOT CPPUTEST_MEM_LEAK_DETECTION_DISABLED) + AND (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "15.1") +) + # Leak detection macros are not sane. + message(NOTICE "Disabling -fassume-sane-operators-new-delete which breaks leak detection") + add_compile_options($<$:-fno-assume-sane-operators-new-delete>) +endif() -include("${CppUTestRootDirectory}/cmake/Modules/CppUTestConfigurationOptions.cmake") -include(CTest) -#include("${CppUTestRootDirectory}/cmake/Modules/CheckFunctionExists.cmake") -include("${CppUTestRootDirectory}/cmake/Modules/CppUTestBuildTimeDiscoverTests.cmake") -include("${CppUTestRootDirectory}/cmake/Modules/CppUTestNormalizeTestOutputLocation.cmake") +if(PROJECT_IS_TOP_LEVEL) + include(cmake/warnings.cmake) +endif() include(GNUInstallDirs) -enable_testing() +# Check for symbols before setting a lot of stuff +include(CheckTypeSize) +include(CheckStructHasMember) +set(CMAKE_REQUIRED_FLAGS ${CMAKE_CXX_FLAGS}) +check_cxx_symbol_exists(kill "signal.h" CPPUTEST_HAVE_KILL) +check_cxx_symbol_exists(fork "unistd.h" CPPUTEST_HAVE_FORK) +check_cxx_symbol_exists(waitpid "sys/wait.h" CPPUTEST_HAVE_WAITPID) +check_cxx_symbol_exists(gettimeofday "sys/time.h" CPPUTEST_HAVE_GETTIMEOFDAY) +check_cxx_symbol_exists(pthread_mutex_lock "pthread.h" CPPUTEST_HAVE_PTHREAD_MUTEX_LOCK) + +if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "IAR") + check_cxx_symbol_exists(strdup "string.h" CPPUTEST_HAVE_STRDUP) +endif() +check_type_size("long long" SIZEOF_LONGLONG LANGUAGE CXX) +if(HAVE_SIZEOF_LONGLONG) + set(CPPUTEST_HAVE_LONG_LONG_INT ON) +endif() configure_file ( "${PROJECT_SOURCE_DIR}/config.h.cmake" "${PROJECT_BINARY_DIR}/generated/CppUTestGeneratedConfig.h" - ) -include_directories(${PROJECT_BINARY_DIR}) -add_definitions(-DHAVE_CONFIG_H) +) -include_directories(${CppUTestRootDirectory}/include) -add_subdirectory(src/CppUTest) +add_subdirectory(src) -if (EXTENSIONS) - add_subdirectory(src/CppUTestExt) -endif (EXTENSIONS) +target_include_directories(CppUTest + PUBLIC + $ +) +target_compile_definitions(CppUTest + PUBLIC + HAVE_CONFIG_H +) -if (TESTS) - add_subdirectory(tests/CppUTest) - if (EXTENSIONS) - add_subdirectory(tests/CppUTestExt) - endif (EXTENSIONS) -endif (TESTS) +if (CPPUTEST_BUILD_TESTING) + add_subdirectory(tests) +endif () -if (EXAMPLES) +if (CPPUTEST_EXAMPLES) add_subdirectory(examples) -endif(EXAMPLES) - -set (INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}") -set (LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}") -set (INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include") - -# Pkg-config file. -set (prefix "${CMAKE_INSTALL_PREFIX}") -set (exec_prefix "\${prefix}") -set (libdir "\${exec_prefix}/${LIB_INSTALL_DIR}") -set (includedir "\${prefix}/${INCLUDE_INSTALL_DIR}") -set (PACKAGE_VERSION "${CppUTest_version_major}.${CppUTest_version_minor}") - -configure_file (cpputest.pc.in - ${CMAKE_CURRENT_BINARY_DIR}/${CppUTest_PKGCONFIG_FILE} @ONLY) - -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${CppUTest_PKGCONFIG_FILE} - DESTINATION ${LIB_INSTALL_DIR}/pkgconfig - ) - -install(FILES "${CMAKE_CURRENT_BINARY_DIR}/generated/CppUTestGeneratedConfig.h" - DESTINATION "${INCLUDE_INSTALL_DIR}/CppUTest" - ) - -# Try to include helper module -include(CMakePackageConfigHelpers OPTIONAL - RESULT_VARIABLE PkgHelpers_AVAILABLE) -# guard against older versions of cmake which do not provide it -if(PkgHelpers_AVAILABLE) - configure_package_config_file(CppUTestConfig.cmake.install.in - ${CMAKE_CURRENT_BINARY_DIR}/install/CppUTestConfig.cmake - INSTALL_DESTINATION ${LIB_INSTALL_DIR}/CppUTest/cmake - PATH_VARS INCLUDE_INSTALL_DIR LIB_INSTALL_DIR) - write_basic_package_version_file( - ${CMAKE_CURRENT_BINARY_DIR}/install/CppUTestConfigVersion.cmake - VERSION ${CppUTest_version_major}.${CppUTest_version_minor} - COMPATIBILITY SameMajorVersion ) - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/install/CppUTestConfig.cmake - ${CMAKE_CURRENT_BINARY_DIR}/install/CppUTestConfigVersion.cmake - DESTINATION ${LIB_INSTALL_DIR}/CppUTest/cmake ) - install(EXPORT CppUTestTargets - DESTINATION ${LIB_INSTALL_DIR}/CppUTest/cmake) - install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Scripts/CppUTestBuildTimeDiscoverTests.cmake - DESTINATION ${LIB_INSTALL_DIR}/CppUTest/cmake/Scripts) - install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/CppUTestBuildTimeDiscoverTests.cmake - DESTINATION ${LIB_INSTALL_DIR}/CppUTest/cmake/Modules) - configure_package_config_file(CppUTestConfig.cmake.build.in - ${CMAKE_CURRENT_BINARY_DIR}/CppUTestConfig.cmake - INSTALL_DESTINATION ${CMAKE_CURRENT_BINARY_DIR} - PATH_VARS INCLUDE_DIR CMAKE_CURRENT_BINARY_DIR) - if (EXTENSIONS) - export(TARGETS CppUTest CppUTestExt - FILE "${CMAKE_CURRENT_BINARY_DIR}/CppUTestTargets.cmake") - else() - export(TARGETS CppUTest - FILE "${CMAKE_CURRENT_BINARY_DIR}/CppUTestTargets.cmake") - endif() - write_basic_package_version_file( - ${CMAKE_CURRENT_BINARY_DIR}/CppUTestConfigVersion.cmake - VERSION ${CppUTest_version_major}.${CppUTest_version_minor} - COMPATIBILITY SameMajorVersion ) - set(CppUTest_DIR "${CMAKE_CURRENT_BINARY_DIR}" CACHE PATH "The directory containing a CMake configuration file for CppUTest.") -else() - message("If you wish to use find_package(CppUTest) in your own project to find CppUTest library" - " please update cmake to version which provides CMakePackageConfighelpers module" - " or write generators for CppUTestConfig.cmake by yourself.") endif() -if(VERBOSE_CONFIG) - message(" -------------------------------------------------------- -CppUTest Version ${CppUTest_version_major}.${CppUTest_version_minor} - -Current compiler options: - CC: ${CMAKE_C_COMPILER} - CXX: ${CMAKE_CXX_COMPILER} - CppUTest CFLAGS: ${CPPUTEST_C_FLAGS} - CppUTest CXXFLAGS: ${CPPUTEST_CXX_FLAGS} - CppUTest LDFLAGS: ${CPPUTEST_LD_FLAGS} - -Features configured in CppUTest: - Memory Leak Detection: ${MEMORY_LEAK_DETECTION} - Compiling Extensions: ${EXTENSIONS} - Support Long Long: ${LONGLONG} - Use CppUTest flags: ${CPPUTEST_FLAGS} - - Using Standard C library: ${STD_C} - Using Standard C++ library: ${STD_CPP} - Using C++11 library: ${C++11} - - Generating map file: ${MAP_FILE} - Compiling with coverage: ${COVERAGE} - - Compile and run self-tests ${TESTS} - Run self-tests separately ${TESTS_DETAILED} - -------------------------------------------------------- -") +if(PROJECT_IS_TOP_LEVEL) + include(cmake/install.cmake) endif() diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 000000000..a4a3f8327 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,183 @@ +{ + "version": 3, + "configurePresets": [ + { + "name": "defaults", + "binaryDir": "cpputest_build", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "RelWithDebInfo", + "CMAKE_CXX_EXTENSIONS": false + } + }, + { + "name": "GNU", + "inherits": ["defaults"], + "environment": { + "CFLAGS": "-Werror", + "CXXFLAGS": "-Werror" + }, + "cacheVariables": { + "CMAKE_C_COMPILER": "gcc", + "CMAKE_CXX_COMPILER": "g++" + } + }, + { + "name": "Clang", + "inherits": ["GNU"], + "cacheVariables": { + "CMAKE_C_COMPILER": "clang", + "CMAKE_CXX_COMPILER": "clang++" + } + }, + { + "name": "clang-tidy", + "inherits": ["Clang"], + "cacheVariables": { + "CMAKE_CXX_CLANG_TIDY": "clang-tidy;-header-filter=.*", + "CMAKE_C_CLANG_TIDY": "clang-tidy;-header-filter=.*" + } + }, + { + "name": "MSVC", + "inherits": ["defaults"], + "environment": { + "CFLAGS": "/WX", + "CXXFLAGS": "/WX" + } + }, + { + "name": "ClangCL", + "inherits": ["MSVC"], + "generator": "Visual Studio 17 2022", + "toolset": "ClangCL" + }, + { + "name": "MinGW", + "inherits": ["GNU"], + "environment": { + "LDFLAGS": "-static" + }, + "cacheVariables": { + "CMAKE_C_COMPILER": "x86_64-w64-mingw32-gcc", + "CMAKE_CXX_COMPILER": "x86_64-w64-mingw32-g++", + "CMAKE_SYSTEM_NAME": "Windows", + "CMAKE_CROSSCOMPILING_EMULATOR": "wine" + } + }, + { + "name": "arm-embedded", + "inherits": ["defaults"], + "toolchainFile": "${sourceDir}/cmake/Toolchains/arm-none-eabi-gcc.toolchain.cmake", + "cacheVariables": { + "CMAKE_CROSSCOMPILING_EMULATOR": "docker;run;--rm;-v=${sourceDir}:${sourceDir};multiarch/qemu-user-static:arm-7.1.0-2;qemu-arm-static;-cpu;cortex-m4" + } + }, + { + "name": "coverage", + "inherits": ["GNU"], + "environment": { + "CFLAGS": "--coverage", + "CXXFLAGS": "--coverage" + }, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug", + "CMAKE_CXX_STANDARD": "11", + "CPPUTEST_EXAMPLES": false + } + }, + { + "name": "no-std-cpp", + "inherits": ["GNU"], + "environment": { + "CXXFLAGS": "-Werror -nostdinc++" + }, + "cacheVariables": { + "CPPUTEST_STD_CPP_LIB_DISABLED": true + } + }, + { + "name": "no-rtti", + "inherits": ["GNU"], + "environment": { + "CXXFLAGS": "-Werror -fno-rtti" + } + }, + { + "name": "no-exceptions", + "inherits": ["GNU"], + "environment": { + "CXXFLAGS": "-Werror -fno-exceptions" + } + }, + { + "name": "no-std-c", + "inherits": ["GNU"], + "environment": { + "CXXFLAGS": "-DCPPUTEST_CHAR_BIT=8 -Werror -nostdinc", + "CFLAGS": "-DCPPUTEST_CHAR_BIT=8 -Werror -nostdinc" + }, + "cacheVariables": { + "CPPUTEST_STD_C_LIB_DISABLED": true + } + }, + { + "name": "no-long-long", + "inherits": ["GNU"], + "cacheVariables": { + "CPPUTEST_USE_LONG_LONG": false + } + }, + { + "name": "asan", + "inherits": ["Clang"], + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + }, + "environment": { + "CFLAGS": "-fsanitize=address -fno-omit-frame-pointer", + "CXXFLAGS": "-fsanitize=address -fno-omit-frame-pointer", + "LDFLAGS": "-fsanitize=address" + } + }, + { + "name": "detailed", + "inherits": ["defaults"], + "cacheVariables": { + "CPPUTEST_TESTS_DETAILED": true + } + }, + { + "name": "gtest", + "inherits": ["defaults"], + "generator": "Ninja Multi-Config", + "cacheVariables": { + "CPPUTEST_TEST_GTEST": true, + "gtest_build_tests": true + } + }, + { + "name": "IAR", + "inherits": ["defaults"], + "cacheVariables": { + "CMAKE_SYSTEM_NAME": "Generic", + "CMAKE_C_COMPILER": "iccarm", + "CMAKE_C_FLAGS_INIT": "--cpu Cortex-M4F --dlib_config normal", + "CMAKE_CXX_COMPILER": "iccarm", + "CMAKE_CXX_FLAGS_INIT": "--cpu Cortex-M4F --dlib_config normal", + "CMAKE_EXE_LINKER_FLAGS": "--semihosting --config ${sourceDir}/platforms/iar/CppUTestTest.icf" + } + }, + { + "name": "DOS", + "inherits": ["defaults"], + "generator": "Watcom WMake", + "cacheVariables": { + "CMAKE_SYSTEM_NAME": "DOS", + "CMAKE_BUILD_TYPE": "MinRelSize", + "CMAKE_CXX_STANDARD": "98", + "CPPUTEST_MEM_LEAK_DETECTION_DISABLED": true, + "CPPUTEST_STD_CPP_LIB_DISABLED": true + } + } + ] +} diff --git a/CppUTest.vcproj b/CppUTest.vcproj index 99a32833e..9a8bfdcc2 100644 --- a/CppUTest.vcproj +++ b/CppUTest.vcproj @@ -41,7 +41,7 @@ + + diff --git a/CppUTest.vcxproj b/CppUTest.vcxproj index e39220c90..4a2f18e61 100644 --- a/CppUTest.vcxproj +++ b/CppUTest.vcxproj @@ -60,21 +60,21 @@ <_ProjectFileVersion>10.0.30319.1 - lib\ - lib\ - cpputest_build\Debug\$(ProjectName)\ - cpputest_build\Debug\$(ProjectName)\ - lib\ - lib\ - cpputest_build\Release\$(ProjectName)\ - cpputest_build\Release\$(ProjectName)\ + lib\x86\ + lib\x64\ + cpputest_build\Debug\x86\$(ProjectName)\ + cpputest_build\Debug\x64\$(ProjectName)\ + lib\x86\ + lib\x64\ + cpputest_build\Release\x86\$(ProjectName)\ + cpputest_build\Release\x64\$(ProjectName)\ $(ProjectName)d $(ProjectName)d Disabled - .\include;.\include\Platforms\VisualCpp;%(AdditionalIncludeDirectories) + .\include;%(AdditionalIncludeDirectories) _LIB;WIN32;_DEBUG;STDC_WANT_SECURE_LIB;CPPUTEST_USE_LONG_LONG;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebugDLL @@ -106,7 +106,7 @@ Disabled - .\include;.\include\Platforms\VisualCpp;%(AdditionalIncludeDirectories) + .\include;%(AdditionalIncludeDirectories) _LIB;WIN32;_DEBUG;STDC_WANT_SECURE_LIB;CPPUTEST_USE_LONG_LONG;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebugDLL @@ -138,7 +138,7 @@ Disabled - .\include;.\include\Platforms\VisualCpp;%(AdditionalIncludeDirectories) + .\include;%(AdditionalIncludeDirectories) OnlyExplicitInline WIN32;NDEBUG;_LIB;STDC_WANT_SECURE_LIB;CPPUTEST_USE_LONG_LONG;%(PreprocessorDefinitions) true @@ -173,7 +173,7 @@ Disabled - .\include;.\include\Platforms\VisualCpp;%(AdditionalIncludeDirectories) + .\include;%(AdditionalIncludeDirectories) OnlyExplicitInline WIN32;NDEBUG;_LIB;STDC_WANT_SECURE_LIB;CPPUTEST_USE_LONG_LONG;%(PreprocessorDefinitions) true @@ -271,6 +271,7 @@ + @@ -295,4 +296,4 @@ - + \ No newline at end of file diff --git a/CppUTestConfig.cmake.install.in b/CppUTestConfig.cmake.install.in index 3e6b91e00..3c79ea3aa 100644 --- a/CppUTestConfig.cmake.install.in +++ b/CppUTestConfig.cmake.install.in @@ -1,6 +1,7 @@ @PACKAGE_INIT@ set_and_check(CppUTest_INCLUDE_DIRS "@PACKAGE_INCLUDE_INSTALL_DIR@") +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/Modules") include("${CMAKE_CURRENT_LIST_DIR}/CppUTestTargets.cmake") set(CppUTest_LIBRARIES CppUTest CppUTestExt) include("${CMAKE_CURRENT_LIST_DIR}/Modules/CppUTestBuildTimeDiscoverTests.cmake") diff --git a/Makefile.am b/Makefile.am index a770a68b8..3406079c7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -77,6 +77,7 @@ include_cpputest_HEADERS = \ include/CppUTest/CppUTestConfig.h \ include/CppUTest/JUnitTestOutput.h \ include/CppUTest/MemoryLeakDetector.h \ + include/CppUTest/MemoryLeakDetectorForceInclude.h \ include/CppUTest/MemoryLeakDetectorMallocMacros.h \ include/CppUTest/MemoryLeakDetectorNewMacros.h \ include/CppUTest/MemoryLeakWarningPlugin.h \ @@ -260,6 +261,25 @@ if INCLUDE_CPPUTEST_EXT ./$(CPPUTESTEXT_TESTS) endif + +cpputest_build_gtest112: + mkdir -p cpputest_build_gtest112 + cd cpputest_build_gtest112; \ + wget https://github.com/google/googletest/archive/refs/tags/release-1.12.1.zip -O gtest-1.12.1.zip && unzip gtest-1.12.1.zip; \ + cd googletest-release-1.12.1; cmake .; make + +cpputest_build_gtest111: + mkdir -p cpputest_build_gtest111 + cd cpputest_build_gtest111; \ + wget https://github.com/google/googletest/archive/refs/tags/release-1.11.0.zip -O gtest-1.11.0.zip && unzip gtest-1.11.0.zip; \ + cd googletest-release-1.11.0; cmake .; make + +cpputest_build_gtest110: + mkdir -p cpputest_build_gtest110 + cd cpputest_build_gtest110; \ + wget https://github.com/google/googletest/archive/refs/tags/release-1.10.0.zip -O gtest-1.10.0.zip && unzip gtest-1.10.0.zip; \ + cd googletest-release-1.10.0; cmake .; make + cpputest_build_gtest18: mkdir -p cpputest_build_gtest18 cd cpputest_build_gtest18; \ @@ -311,13 +331,34 @@ check_gtest18: cpputest_build_gtest18 export GTEST_HOME=`pwd`/cpputest_build_gtest18/googletest-release-1.8.0/googletest; \ make distclean; $(srcdir)/configure --enable-std-cpp98; make check +check_gtest110: cpputest_build_gtest110 + @echo "Build using gmock 1.10" + export GMOCK_MOCK=`pwd`/cpputest_build_gtest110/googletest-release-1.10.0; \ + export GTEST_HOME=`pwd`/cpputest_build_gtest110/googletest-release-1.10.0; \ + make distclean; $(srcdir)/configure --enable-std-cpp11; make check + +check_gtest111: cpputest_build_gtest111 + @echo "Build using gmock 1.11" + export GMOCK_MOCK=`pwd`/cpputest_build_gtest111/googletest-release-1.11.0; \ + export GTEST_HOME=`pwd`/cpputest_build_gtest111/googletest-release-1.11.0; \ + make distclean; $(srcdir)/configure --enable-std-cpp11; make check + +check_gtest112: cpputest_build_gtest112 + @echo "Build using gmock 1.12" + export GMOCK_MOCK=`pwd`/cpputest_build_gtest121/googletest-release-1.12.1; \ + export GTEST_HOME=`pwd`/cpputest_build_gtest121/googletest-release-1.12.1; \ + make distclean; $(srcdir)/configure --enable-std-cpp11; make check + remove_gtest_directories: rm -rf cpputest_build_gtest15 rm -rf cpputest_build_gtest16 rm -rf cpputest_build_gtest17 rm -rf cpputest_build_gtest18 + rm -rf cpputest_build_gtest110 + rm -rf cpputest_build_gtest111 + rm -rf cpputest_build_gtest112 -check_gtest: remove_gtest_directories check_gtest15 check_gtest16 check_gtest17 check_gtest18 +check_gtest: remove_gtest_directories check_gtest15 check_gtest16 check_gtest17 check_gtest18 check_gtest110 check_gtest111 check_gtest112 check_basic: @echo "If dash is available, run the configure with dash to find bash-isms and increase portability" diff --git a/Makefile_using_MakefileWorker b/Makefile_using_MakefileWorker index 0aa7395b8..66ec53932 100644 --- a/Makefile_using_MakefileWorker +++ b/Makefile_using_MakefileWorker @@ -29,38 +29,85 @@ include $(CPPUTEST_HOME)/build/MakefileWorker.mk #these are a sample of the other alternative flag settings .PHONY: test_all test_all: start + $(MAKE_CMD) test_defaults + $(MAKE_CMD) test_disable_std_cpp + $(MAKE_CMD) test_disable_memory_leak_detection + $(MAKE_CMD) test_disable_std_cpp_and_leak_detection + $(MAKE_CMD) test_disable_debug + $(MAKE_CMD) test_override_flags + $(MAKE_CMD) test_disable_std_c + $(MAKE_CMD) test_target_platform + $(MAKE_CMD) test_override_and_disable + $(MAKE_CMD) test_examples + $(MAKE_CMD) test_junit_output + $(MAKE_CMD) test_gcov + $(MAKE_CMD) test_vpath + $(MAKE_CMD) test_vpath_install + +.PHONY: test_defaults +test_defaults: start @echo Building with the default flags. $(MAKE_CMD) clean $(TIME) $(MAKE_CMD) ./$(TEST_TARGET) -r $(MAKE_CMD) clean + +.PHONY: test_disable_std_cpp +test_disable_std_cpp: start @echo Building with the STDC++ new disabled. - $(TIME) $(MAKE_CMD) CPPUTEST_USE_STD_CPP_LIB=Y extensions - $(MAKE_CMD) CPPUTEST_USE_STD_CPP_LIB=Y cleanExtensions + $(TIME) $(MAKE_CMD) CPPUTEST_USE_STD_CPP_LIB=N extensions + $(MAKE_CMD) CPPUTEST_USE_STD_CPP_LIB=N cleanExtensions + +.PHONY: test_disable_memory_leak_detection +test_disable_memory_leak_detection: start @echo Building with Memory Leak Detection disabled $(TIME) $(MAKE_CMD) CPPUTEST_USE_MEM_LEAK_DETECTION=N extensions $(MAKE_CMD) CPPUTEST_USE_MEM_LEAK_DETECTION=N cleanExtensions + +.PHONY: test_disable_std_cpp_and_leak_detection +test_disable_std_cpp_and_leak_detection: start @echo Building with Memory Leak Detection disabled and STD C++ disabled $(TIME) $(MAKE_CMD) CPPUTEST_USE_MEM_LEAK_DETECTION=N CPPUTEST_USE_STD_CPP_LIB=Y extensions $(MAKE_CMD) CPPUTEST_USE_MEM_LEAK_DETECTION=N CPPUTEST_USE_STD_CPP_LIB=Y cleanExtensions + +.PHONY: test_disable_debug +test_disable_debug: start @echo Building with debug disabled $(TIME) $(MAKE_CMD) CPPUTEST_ENABLE_DEBUG=N extensions $(MAKE_CMD) CPPUTEST_ENABLE_DEBUG=N cleanExtensions + +.PHONY: test_override_flags +test_override_flags: start @echo Building with overridden CXXFLAGS and CFLAGS and CPPFLAGS - $(TIME) $(MAKE_CMD) CLFAGS="" CXXFLAGS="" CPPFLAGS="-Iinclude" + $(TIME) $(MAKE_CMD) CFLAGS="" CXXFLAGS="" CPPFLAGS="-Iinclude" $(MAKE_CMD) CFLAGS="" CXXFLAGS="" clean + +.PHONY: test_disable_std_c +test_disable_std_c: start @echo Building without Standard C library includes - $(TIME) $(MAKE_CMD) CPPUTEST_USE_STD_C_LIB=N all_no_tests + $(TIME) $(MAKE_CMD) CPPUTEST_USE_STD_C_LIB=N CPPUTEST_ADDITIONAL_CPPFLAGS="-DCPPUTEST_CHAR_BIT=8" all_no_tests $(MAKE_CMD) CPPUTEST_USE_STD_C_LIB=N clean + +.PHONY: test_target_platform +test_target_platform: start @echo Building with a different TARGET_PLATFORM $(MAKE_CMD) TARGET_PLATFORM=real_platform + +.PHONY: test_override_and_disable +test_override_and_disable: start @echo Building with overridden CXXFLAGS and CFLAGS and memory leak and STDC++ disabled - $(TIME) $(MAKE_CMD) CLFAGS="" CXXFLAGS="" CPPFLAGS="-Iinclude -DCPPUTEST_STD_CPP_LIB_DISABLED -DCPPUTEST_MEM_LEAK_DETECTION_DISABLED" + $(TIME) $(MAKE_CMD) CFLAGS="" CXXFLAGS="" CPPFLAGS="-Iinclude -DCPPUTEST_STD_CPP_LIB_DISABLED -DCPPUTEST_MEM_LEAK_DETECTION_DISABLED" $(MAKE_CMD) CFLAGS="" CXXFLAGS="" CPPFLAGS="-DCPPUTEST_STD_CPP_LIB_DISABLED -DCPPUTEST_MEM_LEAK_DETECTION_DISABLED" clean + +.PHONY: test_examples +test_examples: start @echo Building examples $(MAKE_CMD) cleanExamples $(TIME) $(MAKE_CMD) examples $(MAKE_CMD) cleanExamples + +.PHONY: test_junit_output +test_junit_output: start @echo Testing JUnit output $(TIME) $(MAKE_CMD) $(SILENCE)./$(TEST_TARGET) -ojunit > junit_run_output @@ -68,18 +115,27 @@ test_all: start $(MAKE_CMD) clean $(MAKE_CMD) CPPUTEST_MAP_FILE=map.txt $(MAKE_CMD) clean + +.PHONY: test_gcov +test_gcov: start @echo Testing GCOV usage $(TIME) $(MAKE_CMD) CPPUTEST_USE_GCOV=Y everythingInstall $(MAKE_CMD) gcov $(MAKE) -f Makefile_CppUTestExt gcov $(MAKE) -C examples gcov $(MAKE_CMD) cleanEverythingInstall + +.PHONY: test_vpath +test_vpath: start @echo Testing VPATH usage $(TIME) $(MAKE_CMD) CPPUTEST_USE_GCOV=Y CPPUTEST_USE_VPATH=Y everythingInstall $(MAKE_CMD) CPPUTEST_USE_VPATH=Y gcov $(MAKE) CPPUTEST_USE_VPATH=Y -f Makefile_CppUTestExt gcov $(MAKE) CPPUTEST_USE_VPATH=Y -C examples gcov $(MAKE_CMD) clean cleanExamples + +.PHONY: test_vpath_install +test_vpath_install: start @echo Testing VPATH usage $(TIME) $(MAKE_CMD) CPPUTEST_USE_VPATH=Y everythingInstall $(MAKE_CMD) CPPUTEST_USE_VPATH=Y cleanEverythingInstall diff --git a/README.md b/README.md index c3c6af2be..8d6ae3727 100644 --- a/README.md +++ b/README.md @@ -1,54 +1,58 @@ -CppUTest -======== - -CppUTest unit testing and mocking framework for C/C++ - -[More information on the project page](http://cpputest.github.com) +# CppUTest -Travis Linux build status: -[![Build Status](https://travis-ci.org/cpputest/cpputest.png?branch=master)](https://travis-ci.org/cpputest/cpputest) +[![GitHub Actions](https://github.com/cpputest/cpputest/actions/workflows/basic.yml/badge.svg)](https://github.com/cpputest/cpputest/actions/workflows/basic.yml) +[![AppveyorBuild status](https://ci.appveyor.com/api/projects/status/irh38i4wblsb5tew?svg=true)](https://ci.appveyor.com/project/basvodde/cpputest) +[![Coverage Status](https://coveralls.io/repos/cpputest/cpputest/badge.svg?branch=master&service=github)](https://coveralls.io/github/cpputest/cpputest?branch=master) +[![ConanCenter package](https://repology.org/badge/version-for-repo/conancenter/cpputest.svg)](https://conan.io/center/cpputest) -AppVeyor Windows build status: -[![Build status](https://ci.appveyor.com/api/projects/status/irh38i4wblsb5tew?svg=true)](https://ci.appveyor.com/project/basvodde/cpputest) +CppUTest unit testing and mocking framework for C/C++ -Coverage: -[![Coverage Status](https://coveralls.io/repos/cpputest/cpputest/badge.svg?branch=master&service=github)](https://coveralls.io/github/cpputest/cpputest?branch=master) +[More information on the project page](https://cpputest.github.io) Slack channel: -[Join if link not expired](https://join.slack.com/t/cpputest/shared_invite/zt-dvhne8z8-i_sOcxMF3oYvjoN~qpwiDw) +[Join if link not expired](https://join.slack.com/t/cpputest/shared_invite/zt-epq97u9h-6yBQHHl2cvUADjEENtdASw) ## Getting Started You'll need to do the following to get started: -Building from source (unix-based, cygwin, MacOSX): +Building from source (Unix-based, Cygwin, MacOS): -* git clone git://github.com/cpputest/cpputest.git -* cd cpputest_build -* autoreconf .. -i -* ../configure -* make +```bash +git clone https://github.com/cpputest/cpputest.git +cd cpputest +mkdir cpputest_build +cd cpputest_build +autoreconf .. -i +../configure +make +``` -You can use `make install` if you want to install CppUTest system-wide +You can use `make install` if you want to install CppUTest system-wide. You can also use CMake, which also works for Windows Visual Studio. -* Download latest version -* cmake CMakeList.txt -* make +```bash +git clone https://github.com/cpputest/cpputest.git +cd cpputest +mkdir cpputest_build +cmake -B cpputest_build +cmake --build cpputest_build +``` Then to get started, you'll need to do the following: + * Add the include path to the Makefile. Something like: - * CPPFLAGS += -I$(CPPUTEST_HOME)/include + * `CPPFLAGS += -I$(CPPUTEST_HOME)/include` * Add the memory leak macros to your Makefile (needed for additional debug info!). Something like: - * CXXFLAGS += -include $(CPPUTEST_HOME)/include/CppUTest/MemoryLeakDetectorNewMacros.h - * CFLAGS += -include $(CPPUTEST_HOME)/include/CppUTest/MemoryLeakDetectorMallocMacros.h + * `CXXFLAGS += -include $(CPPUTEST_HOME)/include/CppUTest/MemoryLeakDetectorNewMacros.h` + * `CFLAGS += -include $(CPPUTEST_HOME)/include/CppUTest/MemoryLeakDetectorMallocMacros.h` * Add the library linking to your Makefile. Something like: - * LD_LIBRARIES = -L$(CPPUTEST_HOME)/lib -lCppUTest -lCppUTestExt + * `LD_LIBRARIES = -L$(CPPUTEST_HOME)/lib -lCppUTest -lCppUTestExt` After this, you can write your first test: -```C++ +```cpp TEST_GROUP(FirstTestGroup) { }; @@ -59,52 +63,58 @@ TEST(FirstTestGroup, FirstTest) } ``` +You can build and install cpputest using [vcpkg](https://github.com/Microsoft/vcpkg/) dependency manager: + +```console +$ vcpkg install cpputest (More information: https://github.com/microsoft/vcpkg) +``` + ## Command line switches -* -h help, shows the latest help, including the parameters we've implemented after updating this README page. -* -v verbose, print each test name as it runs -* -r# repeat the tests some number of times, default is one, default if # is not specified is 2. This is handy if you are experiencing memory leaks related to statics and caches. -* -s# random shuffle the test execution order. # is an integer used for seeding the random number generator. # is optional, and if omitted, the seed value is chosen automatically, which results in a different order every time. The seed value is printed to console to make it possible to reproduce a previously generated execution order. Handy for detecting problems related to dependencies between tests. -* -g group only run test whose group contains the substring group -* -n name only run test whose name contains the substring name +* `-h` help, shows the latest help, including the parameters we've implemented after updating this README page. +* `-v` verbose, print each test name as it runs +* `-r#` repeat the tests some number of times, default is one, default if # is not specified is 2. This is handy if you are experiencing memory leaks related to statics and caches. +* `-s#` random shuffle the test execution order. # is an integer used for seeding the random number generator. # is optional, and if omitted, the seed value is chosen automatically, which results in a different order every time. The seed value is printed to console to make it possible to reproduce a previously generated execution order. Handy for detecting problems related to dependencies between tests. +* `-g` group only run test whose group contains the substring group +* `-n` name only run test whose name contains the substring name +* `-f` crash on fail, run the tests as normal but, when a test fails, crash rather than report the failure in the normal way ## Test Macros -* TEST(group, name) - define a test -* IGNORE_TEST(group, name) - turn off the execution of a test -* TEST_GROUP(group) - Declare a test group to which certain tests belong. This will also create the link needed from another library. -* TEST_GROUP_BASE(group, base) - Same as TEST_GROUP, just use a different base class than Utest -* TEST_SETUP() - Declare a void setup method in a TEST_GROUP - this is the same as declaring void setup() -* TEST_TEARDOWN() - Declare a void setup method in a TEST_GROUP -* IMPORT_TEST_GROUP(group) - Export the name of a test group so it can be linked in from a library. Needs to be done in main. +* `TEST(group, name)` - define a test +* `IGNORE_TEST(group, name)` - turn off the execution of a test +* `TEST_GROUP(group)` - Declare a test group to which certain tests belong. This will also create the link needed from another library. +* `TEST_GROUP_BASE(group, base)` - Same as `TEST_GROUP`, just use a different base class than Utest +* `TEST_SETUP()` - Declare a void setup method in a `TEST_GROUP` - this is the same as declaring void `setup()` +* `TEST_TEARDOWN()` - Declare a void setup method in a `TEST_GROUP` +* `IMPORT_TEST_GROUP(group)` - Export the name of a test group so it can be linked in from a library. Needs to be done in `main`. ## Set up and tear down support -* Each TEST_GROUP may contain a setup and/or a teardown method. -* setup() is called prior to each TEST body and teardown() is called after the test body. +* Each `TEST_GROUP` may contain a `setup` and/or a `teardown` method. +* `setup()` is called prior to each `TEST` body and `teardown()` is called after the test body. ## Assertion Macros The failure of one of these macros causes the current test to immediately exit -* CHECK(boolean condition) - checks any boolean result -* CHECK_TRUE(boolean condition) - checks for true -* CHECK_FALSE(boolean condition) - checks for false -* CHECK_EQUAL(expected, actual) - checks for equality between entities using ==. So if you have a class that supports operator==() you can use this macro to compare two instances. -* STRCMP_EQUAL(expected, actual) - check const char* strings for equality using strcmp -* LONGS_EQUAL(expected, actual) - Compares two numbers -* BYTES_EQUAL(expected, actual) - Compares two numbers, eight bits wide -* POINTERS_EQUAL(expected, actual) - Compares two const void * -* DOUBLES_EQUAL(expected, actual, tolerance) - Compares two doubles within some tolerance -* ENUMS_EQUAL_INT(excepted, actual) - Compares two enums which their underlying type is int -* ENUMS_EQUAL_TYPE(underlying_type, excepted, actual) - Compares two enums which they have the same underlying type -* FAIL(text) - always fails -* TEST_EXIT - Exit the test without failure - useful for contract testing (implementing an assert fake) - +* `CHECK(boolean condition)` - checks any boolean result +* `CHECK_TRUE(boolean condition)` - checks for true +* `CHECK_FALSE(boolean condition)` - checks for false +* `CHECK_EQUAL(expected, actual)` - checks for equality between entities using `==`. So if you have a class that supports `operator==()` you can use this macro to compare two instances. +* `STRCMP_EQUAL(expected, actual)` - check const `char*` strings for equality using `strcmp` +* `LONGS_EQUAL(expected, actual)` - Compares two numbers +* `BYTES_EQUAL(expected, actual)` - Compares two numbers, eight bits wide +* `POINTERS_EQUAL(expected, actual)` - Compares two `const void *` +* `DOUBLES_EQUAL(expected, actual, tolerance)` - Compares two doubles within some tolerance +* `ENUMS_EQUAL_INT(excepted, actual)` - Compares two enums which their underlying type is `int` +* `ENUMS_EQUAL_TYPE(underlying_type, excepted, actual)` - Compares two enums which they have the same underlying type +* `FAIL(text)` - always fails +* `TEST_EXIT` - Exit the test without failure - useful for contract testing (implementing an assert fake) -Customize CHECK_EQUAL to work with your types that support operator==() +Customize `CHECK_EQUAL` to work with your types that support `operator==()` -* Create the function: `SimpleString StringFrom(const yourType&)` +- Create the function: `SimpleString StringFrom(const yourType&)` The Extensions directory has a few of these. @@ -117,7 +127,7 @@ The Extensions directory has a few of these. Example of a main with a TestPlugin: -```C++ +```cpp int main(int ac, char** av) { LogPlugin logPlugin; @@ -133,19 +143,19 @@ Memory leak detection * A platform specific memory leak detection mechanism is provided. * If a test fails and has allocated memory prior to the fail and that memory is not cleaned up by TearDown, a memory leak is reported. It is best to only chase memory leaks when other errors have been eliminated. -* Some code uses lazy initialization and appears to leak when it really does not (for example: gcc stringstream used to in an earlier release). One cause is that some standard library calls allocate something and do not free it until after main (or never). - To find out if a memory leak is due to lazy initialization set the -r switch to run tests twice. The signature of this situation is that the first run shows leaks and the second run shows no leaks. When both runs show leaks, you have a leak to find. +* Some code uses lazy initialization and appears to leak when it really does not (for example: gcc stringstream used to in an earlier release). One cause is that some standard library calls allocate something and do not free it until after `main` (or never). + To find out if a memory leak is due to lazy initialization set the `-r` switch to run tests twice. The signature of this situation is that the first run shows leaks and the second run shows no leaks. When both runs show leaks, you have a leak to find. ## How is memory leak detection implemented? -* Before setup() a memory usage checkpoint is recorded -* After teardown() another checkpoint is taken and compared to the original checkpoint +* Before `setup()` a memory usage checkpoint is recorded +* After `teardown()` another checkpoint is taken and compared to the original checkpoint * In Visual Studio the MS debug heap capabilities are used -* For GCC a simple new/delete count is used in overridden operators new, new[], delete and delete[] +* For GCC a simple new/delete count is used in overridden operators `new`, `new[]`, `delete` and `delete[]` If you use some leaky code that you can't or won't fix you can tell a TEST to ignore a certain number of leaks as in this example: -```C++ +```cpp TEST(MemoryLeakWarningTest, Ignore1) { EXPECT_N_LEAKS(1); @@ -155,7 +165,7 @@ TEST(MemoryLeakWarningTest, Ignore1) ## Example Main -```C++ +```cpp #include "CppUTest/CommandLineTestRunner.h" int main(int ac, char** av) @@ -166,7 +176,7 @@ int main(int ac, char** av) ## Example Test -```C++ +```cpp #include "CppUTest/TestHarness.h" #include "ClassName.h" @@ -197,12 +207,38 @@ TEST(ClassName, Create) ``` There are some scripts that are helpful in creating your initial h, cpp, and -Test files. See scripts/README.TXT +Test files. See scripts/README.TXT +## Conan + +CppUTest is available through [conan-center][conan-center]. + +##### conanfile.txt + +```ini +[requires] +cpputest/4.0 + +[generators] +cmake_find_package +cmake_paths +``` + +##### CMake + +```cmake +find_package(CppUTest REQUIRED) + +add_executable(example_test ExampleTest.cpp) + +target_link_libraries(example_test PRIVATE + CppUTest::CppUTest + CppUTest::CppUTestExt) +``` ## Integration as external CMake project -Sometimes you want to use CppUTest in your project without installing it to your system or for having control over the version you are using. This little snippet get the wanted version from Github and builds it as a library. +Sometimes you want to use CppUTest in your project without installing it to your system or for having control over the version you are using. This little snippet get the wanted version from GitHub and builds it as a library. ```cmake # CppUTest @@ -210,10 +246,8 @@ include(FetchContent) FetchContent_Declare( CppUTest GIT_REPOSITORY https://github.com/cpputest/cpputest.git - GIT_TAG latest-passing-build # or use release tag, eg. v3.8 + GIT_TAG master # or use release tag, eg. v4.0 ) -# Set this to ON if you want to have the CppUTests in your project as well. -set(TESTS OFF CACHE BOOL "Switch off CppUTest Test build") FetchContent_MakeAvailable(CppUTest) ``` @@ -221,5 +255,10 @@ It can be used then like so: ```cmake add_executable(run_tests UnitTest1.cpp UnitTest2.cpp) -target_link_libraries(run_tests PRIVATE CppUTest CppUTestExt) + +target_link_libraries(example_test PRIVATE + CppUTest::CppUTest + CppUTest::CppUTestExt) ``` + +[conan-center]: https://conan.io/center/cpputest diff --git a/README_CppUTest_for_C.txt b/README_CppUTest_for_C.txt index 578c348e8..8674364ce 100644 --- a/README_CppUTest_for_C.txt +++ b/README_CppUTest_for_C.txt @@ -7,10 +7,9 @@ common problems to solve. ---++ Using extern "C" When including C-header files or when declaring C-variables and routines -in a .cpp file, you'll have to surround them with an extern "C". This is -because the C++ linker works different than the C linker and you need to -instruct the compiler about this. If you do NOT do this, you will probably -get a linker error, like unresolved symbols, for a routine that you did +in a .cpp file, you'll need to enclose them within an extern "C". This is +because the C++ linker works differently than the C linker and you need to +instruct the compiler about this else you may encounter a linker error. Like unresolved symbols for a routine that you did implement. An example: @@ -25,10 +24,10 @@ extern "C" { CppUTest comes with a file called TestHarness_c.h which contains a couple of routines that can be used in C code, like C-versions of the CHECK-macro's. -The file also contains malloc and free routines that can be used for using +The file also contains malloc and free routines that can be used for accessing the CppUTest memory leak detector. These routines should be used instead of the normal malloc/free. This can be achieved by #defining them somewhere, for -examples as a compiler option: -Dmalloc=cpputest_malloc. +example as a compiler option: -Dmalloc=cpputest_malloc. It's important to remember that TestHarness_c.h is a C-header file. It can be used in C code, but when using in C++ code, you need to use extern "C" before diff --git a/build/MakefileWorker.mk b/build/MakefileWorker.mk index 6c7c90ab6..46852df8d 100644 --- a/build/MakefileWorker.mk +++ b/build/MakefileWorker.mk @@ -24,6 +24,8 @@ # These do not go in a library. They are explicitly included in the test runner # MOCKS_SRC_DIRS - Directories containing mock source files to build into the test runner # These do not go in a library. They are explicitly included in the test runner +# MOCKS_SRC_FILES - Specific mock source files to build into the unit test runner +# These do not go in a library. They are explicitly included in the test runner #---------- # You can adjust these variables to influence how to build the test target # and where to put and name outputs @@ -46,6 +48,7 @@ # of the test harness # CPPUTEST_USE_GCOV - Turn on coverage analysis # Clean then build with this flag set to Y, then 'make gcov' +# CPPUTEST_USE_GCOV_NO_GCNO_FILES - Disable gcov's .gcno files from being generated # CPPUTEST_MAPFILE - generate a map file # CPPUTEST_WARNINGFLAGS - overly picky by default # OTHER_MAKEFILE_TO_INCLUDE - a hook to use this makefile to make @@ -62,6 +65,8 @@ # CPPUTEST_CPPFLAGS - flags for the C++ AND C preprocessor # CPPUTEST_CFLAGS - flags for the C complier # CPPUTEST_LDFLAGS - Linker flags +# CPPUTEST_CXX_PREFIX - prefix for the C++ compiler +# CPPUTEST_CC_PREFIX - prefix for the C compiler #---------- # Some behavior is weird on some platforms. Need to discover the platform. @@ -73,14 +78,14 @@ MINGW_STR = MINGW CYGWIN_STR = CYGWIN LINUX_STR = Linux SUNOS_STR = SunOS -UNKNWOWN_OS_STR = Unknown +UNKNOWN_OS_STR = Unknown # Compilers CC_VERSION_OUTPUT ="$(shell $(CXX) -v 2>&1)" CLANG_STR = clang SUNSTUDIO_CXX_STR = SunStudio -UNAME_OS = $(UNKNWOWN_OS_STR) +UNAME_OS = $(UNKNOWN_OS_STR) ifeq ($(findstring $(MINGW_STR),$(UNAME_OUTPUT)),$(MINGW_STR)) UNAME_OS = $(MINGW_STR) @@ -170,6 +175,11 @@ ifndef CPPUTEST_USE_GCOV CPPUTEST_USE_GCOV = N endif +# Skip generating gcov's .gcno files, off by default +ifndef CPPUTEST_USE_GCOV_NO_GCNO_FILES + CPPUTEST_USE_GCOV_NO_GCNO_FILES = N +endif + ifndef CPPUTEST_PEDANTIC_ERRORS CPPUTEST_PEDANTIC_ERRORS = Y endif @@ -192,25 +202,38 @@ ifeq ($(COMPILER_NAME),$(CLANG_STR)) # -Wno-disabled-macro-expansion -> Have to disable the macro expansion warning as the operator new overload warns on that. # -Wno-padded -> I sort-of like this warning but if there is a bool at the end of the class, it seems impossible to remove it! (except by making padding explicit) # -Wno-global-constructors Wno-exit-time-destructors -> Great warnings, but in CppUTest it is impossible to avoid as the automatic test registration depends on the global ctor and dtor -# -Wno-weak-vtables -> The TEST_GROUP macro declares a class and will automatically inline its methods. Thats ok as they are only in one translation unit. Unfortunately, the warning can't detect that, so it must be disabled. +# -Wno-weak-vtables -> The TEST_GROUP macro declares a class and will automatically inline its methods. That's ok as they are only in one translation unit. Unfortunately, the warning can't detect that, so it must be disabled. # -Wno-old-style-casts -> We only use old style casts by decision # -Wno-c++11-long-long -> When it detects long long, then we can use it and no need for a warning about that # -Wno-c++98-compat-pedantic -> Incompatibilities with C++98, these are happening through #define. -# -Wno-reserved-id-macro -> Macro uses __ in MINGW... can't change that. -# -Wno-keyword-macro -> new overload - CPPUTEST_CXX_WARNINGFLAGS += -Weverything -Wno-disabled-macro-expansion -Wno-padded -Wno-global-constructors -Wno-exit-time-destructors -Wno-weak-vtables -Wno-old-style-cast -Wno-c++11-long-long -Wno-c++98-compat-pedantic -Wno-reserved-id-macro -Wno-keyword-macro - CPPUTEST_C_WARNINGFLAGS += -Weverything -Wno-padded + CPPUTEST_CXX_WARNINGFLAGS += -Wno-disabled-macro-expansion -Wno-padded -Wno-global-constructors -Wno-exit-time-destructors -Wno-weak-vtables -Wno-old-style-cast -Wno-c++11-long-long -Wno-c++98-compat-pedantic -Wreserved-id-macro + CPPUTEST_C_WARNINGFLAGS += -Wno-padded -Wreserved-id-macro -# Clang "7" or newer (Xcode 7 or newer command-line tools) introduced new warnings by default that don't exist on previous versions of clang and cause errors when present. -CLANG_VERSION := $(shell echo $(CC_VERSION_OUTPUT) | grep -o 'clang-[0-9][0-9][0-9]*.') -CLANG_VERSION_NUM := $(subst .,,$(subst clang-,,$(CLANG_VERSION))) -CLANG_VERSION_NUM_GT_700 := $(shell [[ $(CLANG_VERSION_NUM) -ge 700 ]] && echo Y) +# Clang 7 and 12 introduced new warnings by default that don't exist on previous versions of clang and cause errors when present. +CLANG_VERSION := $(shell echo $(CC_VERSION_OUTPUT) | sed -n 's/.* \([0-9]*\.[0-9]*\.[0-9]*\).*/\1/p') +CLANG_VERSION_NUM := $(subst .,,$(CLANG_VERSION)) +CLANG_VERSION_NUM_GT_700 := $(shell [ "$(CLANG_VERSION_NUM)" -ge 700 ] && echo Y || echo N) +CLANG_VERSION_NUM_GT_1200 := $(shell [ "$(CLANG_VERSION_NUM)" -ge 1200 ] && echo Y || echo N) +CLANG_VERSION_NUM_GT_1205 := $(shell [ "$(CLANG_VERSION_NUM)" -ge 1205 ] && echo Y || echo N) ifeq ($(CLANG_VERSION_NUM_GT_700), Y) -# -Wno-reserved-id-macro -> Many CppUTest macros start with __, which is a reserved namespace -# -Wno-keyword-macro -> CppUTest redefines the 'new' keyword for memory leak tracking - CPPUTEST_CXX_WARNINGFLAGS += -Wno-reserved-id-macro -Wno-keyword-macro - CPPUTEST_C_WARNINGFLAGS += -Wno-reserved-id-macro -Wno-keyword-macro + CPPUTEST_CXX_WARNINGFLAGS += -Wkeyword-macro + CPPUTEST_C_WARNINGFLAGS += -Wkeyword-macro +endif + +ifeq ($(UNAME_OS),$(MACOSX_STR)) +#apple clang has some special behavior +ifeq ($(CLANG_VERSION_NUM_GT_1200), Y) +# -Wno-poison-system-directories -> Apparently apple clang thinks everything is a cross compile, making this useless + CPPUTEST_CXX_WARNINGFLAGS += -Wno-poison-system-directories + CPPUTEST_C_WARNINGFLAGS += -Wno-poison-system-directories +endif # clang 1200 + +ifeq ($(CLANG_VERSION_NUM_GT_1205), Y) +# Not sure why apple clang throws these warnings on cpputest code when clang doesn't + CPPUTEST_CXX_WARNINGFLAGS += -Wno-suggest-override -Wno-suggest-destructor-override + CPPUTEST_C_WARNINGFLAGS += -Wno-suggest-override -Wno-suggest-destructor-override +endif endif endif @@ -229,7 +252,7 @@ else endif endif -# Default dir for the outout library +# Default dir for the output library ifndef CPPUTEST_LIB_DIR ifndef TARGET_PLATFORM CPPUTEST_LIB_DIR = lib @@ -243,7 +266,7 @@ ifndef CPPUTEST_MAP_FILE CPPUTEST_MAP_FILE = N endif -# No extentions is default +# No extensions is default ifndef CPPUTEST_USE_EXTENSIONS CPPUTEST_USE_EXTENSIONS = N endif @@ -317,8 +340,12 @@ endif ifeq ($(CPPUTEST_USE_GCOV), Y) - CPPUTEST_CXXFLAGS += -fprofile-arcs -ftest-coverage - CPPUTEST_CFLAGS += -fprofile-arcs -ftest-coverage + CPPUTEST_CXXFLAGS += -fprofile-arcs + CPPUTEST_CFLAGS += -fprofile-arcs + ifneq ($(CPPUTEST_USE_GCOV_NO_GCNO_FILES), Y) + CPPUTEST_CXXFLAGS += -ftest-coverage + CPPUTEST_CFLAGS += -ftest-coverage + endif endif CPPUTEST_CXXFLAGS += $(CPPUTEST_WARNINGFLAGS) $(CPPUTEST_CXX_WARNINGFLAGS) @@ -381,7 +408,7 @@ TEST_OBJS = $(call src_to_o,$(TEST_SRC)) STUFF_TO_CLEAN += $(TEST_OBJS) -MOCKS_SRC += $(call get_src_from_dir_list, $(MOCKS_SRC_DIRS)) +MOCKS_SRC += $(call get_src_from_dir_list, $(MOCKS_SRC_DIRS)) $(MOCKS_SRC_FILES) MOCKS_OBJS = $(call src_to_o,$(MOCKS_SRC)) STUFF_TO_CLEAN += $(MOCKS_OBJS) @@ -485,35 +512,53 @@ TEST_DEPS = $(TEST_OBJS) $(MOCKS_OBJS) $(PRODUCTION_CODE_START) $(TARGET_LIB) $( test-deps: $(TEST_DEPS) $(TEST_TARGET): $(TEST_DEPS) +ifndef MORE_SILENCE @echo Linking $@ +endif $(SILENCE)$(CXX) -o $@ $^ $(LD_LIBRARIES) $(LDFLAGS) $(TARGET_LIB): $(OBJ) +ifndef MORE_SILENCE @echo Building archive $@ +endif $(SILENCE)mkdir -p $(dir $@) +ifndef MORE_SILENCE $(SILENCE)$(AR) $(ARFLAGS) $@ $^ +else + $(SILENCE)$(AR) $(ARFLAGS) $@ $^ >/dev/null +endif $(SILENCE)$(RANLIB) $@ test: $(TEST_TARGET) - $(RUN_TEST_TARGET) | tee $(TEST_OUTPUT) + @$(eval TEST_RUN_RETURN_CODE_FILE=$(shell mktemp /tmp/cpputestResult.XXX)) + @($(RUN_TEST_TARGET); echo $$? > $(TEST_RUN_RETURN_CODE_FILE)) | tee $(TEST_OUTPUT) + @ret=$$(cat $(TEST_RUN_RETURN_CODE_FILE)); rm $(TEST_RUN_RETURN_CODE_FILE); if [ "$$ret" -ne 0 ]; then echo "$$(tput setaf 1)$(TEST_TARGET) returned $${ret}$$(tput sgr0)"; fi; exit $$ret vtest: $(TEST_TARGET) - $(RUN_TEST_TARGET) -v | tee $(TEST_OUTPUT) + @$(eval TEST_RUN_RETURN_CODE_FILE=$(shell mktemp /tmp/cpputestResult.XXX)) + @($(RUN_TEST_TARGET) -v; echo $$? > $(TEST_RUN_RETURN_CODE_FILE)) | tee $(TEST_OUTPUT) + @ret=$$(cat $(TEST_RUN_RETURN_CODE_FILE)); rm $(TEST_RUN_RETURN_CODE_FILE); if [ "$$ret" -ne 0 ]; then echo "$$(tput setaf 1)$(TEST_TARGET) returned $${ret}$$(tput sgr0)"; fi; exit $$ret $(CPPUTEST_OBJS_DIR)/%.o: %.cc +ifndef MORE_SILENCE @echo compiling $(notdir $<) +endif $(SILENCE)mkdir -p $(dir $@) - $(SILENCE)$(COMPILE.cpp) $(DEP_FLAGS) $(OUTPUT_OPTION) $< + $(SILENCE)$(CPPUTEST_CXX_PREFIX)$(COMPILE.cpp) $(DEP_FLAGS) $(OUTPUT_OPTION) $< $(CPPUTEST_OBJS_DIR)/%.o: %.cpp +ifndef MORE_SILENCE @echo compiling $(notdir $<) +endif $(SILENCE)mkdir -p $(dir $@) - $(SILENCE)$(COMPILE.cpp) $(DEP_FLAGS) $(OUTPUT_OPTION) $< + $(SILENCE)$(CPPUTEST_CXX_PREFIX)$(COMPILE.cpp) $(DEP_FLAGS) $(OUTPUT_OPTION) $< $(CPPUTEST_OBJS_DIR)/%.o: %.c +ifndef MORE_SILENCE @echo compiling $(notdir $<) +endif $(SILENCE)mkdir -p $(dir $@) - $(SILENCE)$(COMPILE.c) $(DEP_FLAGS) $(OUTPUT_OPTION) $< + $(SILENCE)$(CPPUTEST_CC_PREFIX)$(COMPILE.c) $(DEP_FLAGS) $(OUTPUT_OPTION) $< ifneq "$(MAKECMDGOALS)" "clean" -include $(DEP_FILES) @@ -521,7 +566,9 @@ endif .PHONY: clean clean: +ifndef MORE_SILENCE @echo Making clean +endif $(SILENCE)$(RM) $(STUFF_TO_CLEAN) $(SILENCE)rm -rf gcov $(CPPUTEST_OBJS_DIR) $(CPPUTEST_LIB_DIR) $(SILENCE)find . -name "*.gcno" | xargs rm -f diff --git a/build/alltests.mmp b/build/alltests.mmp index 8eaaf5b13..40c1dc86a 100644 --- a/build/alltests.mmp +++ b/build/alltests.mmp @@ -29,7 +29,7 @@ TARGET cpputest.exe TARGETTYPE exe UID 0x00000000 0x03A6305A -USERINCLUDE ..\include ..\include\CppUTest ..\include\Platforms\Symbian ..\tests +USERINCLUDE ..\include ..\include\CppUTest ..\tests SYSTEMINCLUDE \epoc32\include \epoc32\include\stdapis STATICLIBRARY libcrt0.lib diff --git a/build/cpputest.mmp b/build/cpputest.mmp index 8093f8c59..103063507 100644 --- a/build/cpputest.mmp +++ b/build/cpputest.mmp @@ -29,7 +29,7 @@ TARGET cpputest.lib TARGETTYPE LIB UID 0x00000000 0x03A6305A -USERINCLUDE ..\include ..\include\CppUTest ..\include\Platforms\Symbian +USERINCLUDE ..\include ..\include\CppUTest SYSTEMINCLUDE \epoc32\include \epoc32\include\stdapis SOURCEPATH ..\src\CppUTest diff --git a/cmake/Modules/CppUTest.cmake b/cmake/Modules/CppUTest.cmake new file mode 100644 index 000000000..160959a5e --- /dev/null +++ b/cmake/Modules/CppUTest.cmake @@ -0,0 +1,117 @@ +set(_CPPUTEST_DISCOVERY_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/_CppUTestDiscovery.cmake + CACHE INTERNAL "CppUTest discovery scripts" +) + +option(CPPUTEST_TESTS_DETAILED "Run discovered tests individually") +option(CPPUTEST_JUNIT_REPORT "Output JUnit test reports") + +function(cpputest_discover_tests target) + set(options JUNIT) + set(oneValueArgs DETAILED) + set(multiValueArgs EXTRA_ARGS) + cmake_parse_arguments( + "" + "${options}" + "${oneValueArgs}" + "${multiValueArgs}" + ${ARGN} + ) + + # Validate arguments. + if(NOT TARGET ${target}) + message(FATAL_ERROR + "Cannot discover tests for target \"${target}\" " + "which is not built by this project." + ) + endif() + + get_property(target_type + TARGET ${target} + PROPERTY TYPE + ) + if(NOT target_type STREQUAL "EXECUTABLE") + message(FATAL_ERROR + "Cannot discover tests for target \"${target}\" " + "which is not an executable." + ) + endif() + + get_property(emulator + TARGET ${target} + PROPERTY CROSSCOMPILING_EMULATOR + ) + if(CMAKE_CROSSCOMPILING) + if(NOT emulator) + message(WARNING "Cannot discover cross compiled tests without an emulator") + return() + endif() + endif() + + if(NOT DEFINED _EXTRA_ARGS) + set(_EXTRA_ARGS -v) + endif() + + if(NOT DEFINED _DETAILED) + set(_DETAILED ${CPPUTEST_TESTS_DETAILED}) + endif() + + if(_JUNIT OR CPPUTEST_JUNIT_REPORT) + list(APPEND _EXTRA_ARGS -ojunit) + endif() + + set(CTEST_INCLUDE_FILE "${CMAKE_CURRENT_BINARY_DIR}/${target}_include.cmake") + if(CMAKE_CONFIGURATION_TYPES) + set(CTEST_GENERATED_FILE "${CMAKE_CURRENT_BINARY_DIR}/${target}.$.cmake") + file(WRITE "${CTEST_INCLUDE_FILE}" + "if(EXISTS \"${CMAKE_CURRENT_BINARY_DIR}/${target}.\${CTEST_CONFIGURATION_TYPE}.cmake\")\n" + " include(\"${CMAKE_CURRENT_BINARY_DIR}/${target}.\${CTEST_CONFIGURATION_TYPE}.cmake\")\n" + "endif()\n" + ) + else() + set(CTEST_GENERATED_FILE "${CMAKE_CURRENT_BINARY_DIR}/${target}.cmake") + file(WRITE "${CTEST_INCLUDE_FILE}" + "if(EXISTS \"${CTEST_GENERATED_FILE}\")\n" + " include(\"${CTEST_GENERATED_FILE}\")\n" + "endif()\n" + ) + endif() + + add_custom_command( + TARGET ${target} POST_BUILD + BYPRODUCTS "${CTEST_GENERATED_FILE}" + COMMAND + "${CMAKE_COMMAND}" + -D "TESTS_DETAILED:BOOL=${_DETAILED}" + -D "EXECUTABLE=$" + -D "EMULATOR=${emulator}" + -D "ARGS=${_EXTRA_ARGS}" + -D "CTEST_FILE=${CTEST_GENERATED_FILE}" + -P "${_CPPUTEST_DISCOVERY_SCRIPT}" + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" + VERBATIM + ) + + if(${CMAKE_VERSION} VERSION_LESS "3.10") + # We can only set one. + get_property(already_set + DIRECTORY + PROPERTY TEST_INCLUDE_FILE + SET + ) + if(${already_set}) + message(FATAL_ERROR + "Cannot discovery multiple tests from the same file" + ) + endif() + set_property( + DIRECTORY + PROPERTY TEST_INCLUDE_FILE "${CTEST_INCLUDE_FILE}" + ) + else() + set_property( + DIRECTORY APPEND + PROPERTY TEST_INCLUDE_FILES "${CTEST_INCLUDE_FILE}" + ) + endif() + +endfunction() diff --git a/cmake/Modules/CppUTestBuildTimeDiscoverTests.cmake b/cmake/Modules/CppUTestBuildTimeDiscoverTests.cmake index 49b297319..cfffad56c 100644 --- a/cmake/Modules/CppUTestBuildTimeDiscoverTests.cmake +++ b/cmake/Modules/CppUTestBuildTimeDiscoverTests.cmake @@ -1,19 +1,55 @@ +option(CPPUTEST_TESTS_DETAILED "Run discovered tests individually") + +set(_DISCOVER_SCRIPT "${CMAKE_CURRENT_LIST_DIR}/../Scripts/CppUTestBuildTimeDiscoverTests.cmake") + # Create target to discover tests -function (cpputest_buildtime_discover_tests EXECUTABLE) - # The path to the discover script depends on execution mode: - # - internal (building CppUTest it self). - # - imported (installed, imported, and executed by a client of the CppUTest lib) - if (PROJECT_NAME STREQUAL "CppUTest") # internal - (path is relative to source dir) - SET(DISCOVER_SCRIPT ${PROJECT_SOURCE_DIR}/cmake/Scripts/CppUTestBuildTimeDiscoverTests.cmake) - else (PROJECT_NAME STREQUAL "CppUTest") # Installed (path is relative to install directory) - SET(DISCOVER_SCRIPT ${CppUTest_DIR}/Scripts/CppUTestBuildTimeDiscoverTests.cmake) - endif (PROJECT_NAME STREQUAL "CppUTest") +function (cpputest_buildtime_discover_tests tgt) + message(DEPRECATION + "Use cpputest_discover_tests from the CppUTest module instead" + ) - add_custom_command (TARGET ${EXECUTABLE} - POST_BUILD - COMMAND ${CMAKE_COMMAND} -DTESTS_DETAILED:BOOL=${TESTS_DETAILED} -DEXECUTABLE=$ -P ${DISCOVER_SCRIPT} - VERBATIM + set(options) + set(oneValueArgs DETAILED) + set(multiValueArgs) + cmake_parse_arguments( + "" + "${options}" + "${oneValueArgs}" + "${multiValueArgs}" + ${ARGN} + ) + if(NOT DEFINED _DETAILED) + set(_DETAILED ${CPPUTEST_TESTS_DETAILED}) + endif() + + if(NOT TARGET ${tgt}) + message(FATAL_ERROR + "Cannot discover tests for target \"${tgt}\" " + "which is not built by this project." + ) + endif() + + get_property(target_type + TARGET ${tgt} + PROPERTY TYPE + ) + if(NOT target_type STREQUAL "EXECUTABLE") + message(FATAL_ERROR + "Cannot discover tests for target \"${tgt}\" " + "which is not an executable." + ) + endif() + + add_custom_command( + TARGET ${tgt} POST_BUILD + COMMAND + ${CMAKE_COMMAND} + -D "TESTS_DETAILED:BOOL=${_DETAILED}" + -D "EXECUTABLE=$" + -D "EMULATOR=$" + -P "${_DISCOVER_SCRIPT}" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMENT "Discovering Tests in ${EXECUTABLE}" - VERBATIM) + COMMENT "Discovering Tests in ${tgt}" + VERBATIM + ) endfunction () diff --git a/cmake/Modules/CppUTestConfigurationOptions.cmake b/cmake/Modules/CppUTestConfigurationOptions.cmake deleted file mode 100644 index 43147cb5d..000000000 --- a/cmake/Modules/CppUTestConfigurationOptions.cmake +++ /dev/null @@ -1,98 +0,0 @@ -if (MSVC) - set(CPP_PLATFORM VisualCpp) - include_directories(${CppUTestRootDirectory}/include/Platforms/${CPP_PLATFORM}) - option(STDC_WANT_SECURE_LIB "Use MSVC safe functions" ON) - if(STDC_WANT_SECURE_LIB) - ADD_DEFINITIONS(-DSTDC_WANT_SECURE_LIB) - endif(STDC_WANT_SECURE_LIB) -elseif (STD_C) - if(NOT CPP_PLATFORM) - set(CPP_PLATFORM Gcc) - endif(NOT CPP_PLATFORM) -else (MSVC) - set(STD_CPP False) - set(MEMORY_LEAK_DETECTION False) - set(CPPUTEST_CXX_FLAGS "${CPPUTEST_CXX_FLAGS} -nostdinc") - set(CPPUTEST_LD_FLAGS "${CPPUTEST_LD_FLAGS} -nostdinc") - set(CPPUTEST_STD_C_LIB_DISABLED 1) - set(CPP_PLATFORM GccNoStdC) -endif (MSVC) - -include("${CppUTestRootDirectory}/cmake/Modules/CppUTestWarningFlags.cmake") - -if (NOT STD_CPP) - set(CPPUTEST_STD_CPP_LIB_DISABLED 1) - if (STD_C AND NOT MSVC) - set(CPPUTEST_CXX_FLAGS "${CPPUTEST_CXX_FLAGS} -nostdinc++") - endif (STD_C AND NOT MSVC) -endif (NOT STD_CPP) - -if (MEMORY_LEAK_DETECTION) - if (MSVC) - set(CPPUTEST_C_FLAGS "${CPPUTEST_C_FLAGS} /FI \"${CppUTestRootDirectory}/include/CppUTest/MemoryLeakDetectorMallocMacros.h\"") - set(CPPUTEST_CXX_FLAGS "${CPPUTEST_CXX_FLAGS} /FI \"${CppUTestRootDirectory}/include/CppUTest/MemoryLeakDetectorMallocMacros.h\"") - else (MSVC) - set(CPPUTEST_C_FLAGS "${CPPUTEST_C_FLAGS} -include \"${CppUTestRootDirectory}/include/CppUTest/MemoryLeakDetectorMallocMacros.h\"") - set(CPPUTEST_CXX_FLAGS "${CPPUTEST_CXX_FLAGS} -include \"${CppUTestRootDirectory}/include/CppUTest/MemoryLeakDetectorNewMacros.h\"") - set(CPPUTEST_CXX_FLAGS "${CPPUTEST_CXX_FLAGS} -include \"${CppUTestRootDirectory}/include/CppUTest/MemoryLeakDetectorMallocMacros.h\"") - endif (MSVC) -else (MEMORY_LEAK_DETECTION) - set(CPPUTEST_MEM_LEAK_DETECTION_DISABLED 1) -endif (MEMORY_LEAK_DETECTION) - -if (LONGLONG) - set(CPPUTEST_USE_LONG_LONG 1) -endif (LONGLONG) - -if (MAP_FILE AND NOT MSVC) - set(CPPUTEST_LD_FLAGS "${CPPUTEST_LD_FLAGS} -Wl,-Map,$<.map.txt") -endif (MAP_FILE AND NOT MSVC) - -if (COVERAGE AND NOT MSVC) - set(CPPUTEST_C_FLAGS "${CPPUTEST_C_FLAGS} --coverage") - set(CPPUTEST_CXX_FLAGS "${CPPUTEST_CXX_FLAGS} --coverage") - set(CMAKE_BUILD_TYPE "Debug") - find_program(GCOVR gcovr DOC "gcovr executable") - - if (NOT GCOVR) - message(SEND_ERROR "gcovr not found") - endif() - - add_custom_target(coverage ${GCOVR} - --root ${PROJECT_SOURCE_DIR} - --output "${CMAKE_BINARY_DIR}/coverage/coverage.html" - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} - COMMENT "Generate coverage data" - VERBATIM - ) -endif() - -if (CMAKE_CXX_STANDARD) - set(CMAKE_CXX_EXTENSIONS OFF) -elseif (C++11) - find_package(CXX11 REQUIRED) - set(CPPUTEST_CXX_FLAGS "${CPPUTEST_CXX_FLAGS} ${CXX11_FLAGS}") -else() - # No standard specified -endif () - -set(GMOCK_HOME $ENV{GMOCK_HOME}) -if (DEFINED ENV{GMOCK_HOME}) - # GMock pulls in gtest. - set(CPPUTEST_INCLUDE_GTEST_TESTS 1) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGTEST_USE_OWN_TR1_TUPLE=1") - include_directories(${GMOCK_HOME}/include ${GMOCK_HOME}/gtest ${GMOCK_HOME}/gtest/include) - add_subdirectory(${GMOCK_HOME} "${CMAKE_CURRENT_BINARY_DIR}/gmock") - - set(CPPUTEST_C_WARNING_FLAGS "") - set(CPPUTEST_CXX_WARNING_FLAGS "") -endif (DEFINED ENV{GMOCK_HOME}) - -set(CPPUTEST_C_FLAGS "${CPPUTEST_C_FLAGS} ${CPPUTEST_C_WARNING_FLAGS}") -set(CPPUTEST_CXX_FLAGS "${CPPUTEST_CXX_FLAGS} ${CPPUTEST_CXX_WARNING_FLAGS}") - -if (CPPUTEST_FLAGS) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CPPUTEST_C_FLAGS}") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CPPUTEST_CXX_FLAGS}") - set(CMAKE_LD_FLAGS "${CMAKE_LD_FLAGS} ${CPPUTEST_LD_FLAGS}") -endif (CPPUTEST_FLAGS) diff --git a/cmake/Modules/CppUTestNormalizeTestOutputLocation.cmake b/cmake/Modules/CppUTestNormalizeTestOutputLocation.cmake deleted file mode 100644 index acb5efb34..000000000 --- a/cmake/Modules/CppUTestNormalizeTestOutputLocation.cmake +++ /dev/null @@ -1,10 +0,0 @@ -# Override output properties to put test executable at specificied location -function (cpputest_normalize_test_output_location TEST_TARGET) - set_target_properties(${TEST_TARGET} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - foreach(OUTPUT_CONFIG ${CMAKE_CONFIGURATION_TYPES}) - string(TOUPPER ${OUTPUT_CONFIG} OUTPUT_CONFIG) - set_target_properties(${TEST_TARGET} PROPERTIES - RUNTIME_OUTPUT_DIRECTORY_${OUTPUT_CONFIG} ${CMAKE_CURRENT_BINARY_DIR}) - endforeach(OUTPUT_CONFIG) -endfunction () - diff --git a/cmake/Modules/CppUTestWarningFlags.cmake b/cmake/Modules/CppUTestWarningFlags.cmake deleted file mode 100644 index 3b8f2d7f2..000000000 --- a/cmake/Modules/CppUTestWarningFlags.cmake +++ /dev/null @@ -1,80 +0,0 @@ -if (MSVC) - set(CPPUTEST_C_WARNING_FLAGS "/WX") - set(CPPUTEST_CXX_WARNING_FLAGS "/WX /wd4290") -else (MSVC) - include(CheckCCompilerFlag) - include(CheckCXXCompilerFlag) - - macro(check_and_append_c_warning_flags) - foreach (flag ${ARGN}) - check_c_compiler_flag("-${flag}" WARNING_C_FLAG_${flag}) - if (WARNING_C_FLAG_${flag}) - set(CPPUTEST_C_WARNING_FLAGS "${CPPUTEST_C_WARNING_FLAGS} -${flag}") - endif (WARNING_C_FLAG_${flag}) - endforeach (flag) - endmacro(check_and_append_c_warning_flags) - - macro(check_and_append_cxx_warning_flags) - foreach (flag ${ARGN}) - string(REPLACE "++" "xx" WARNING_CXX_FLAG_VAR "WARNING_CXX_FLAG_${flag}") - check_cxx_compiler_flag("-${flag}" ${WARNING_CXX_FLAG_VAR}) - if (${WARNING_CXX_FLAG_VAR}) - set(CPPUTEST_CXX_WARNING_FLAGS "${CPPUTEST_CXX_WARNING_FLAGS} -${flag}") - endif (${WARNING_CXX_FLAG_VAR}) - endforeach (flag) - endmacro(check_and_append_cxx_warning_flags) - - if (NOT GMOCK AND NOT REAL_GTEST) - list(APPEND WARNING_C_FLAGS Werror pedantic-errors) - endif (NOT GMOCK AND NOT REAL_GTEST) - - set(WARNING_C_FLAGS - Weverything - Wall - Wextra - pedantic - Wshadow - Wswitch-default - Wswitch-enum - Wconversion - Wsign-conversion - Wno-padded - Wno-disabled-macro-expansion - Wno-reserved-id-macro - Wno-keyword-macro - Wno-long-long - ) - - if (WERROR) - list(APPEND WARNING_C_FLAGS Werror) - endif (WERROR) - - - set(WARNING_C_ONLY_FLAGS - Wstrict-prototypes - ) - - set(WARNING_CXX_FLAGS - ${WARNING_C_FLAGS} - Woverloaded-virtual - Wno-global-constructors - Wno-exit-time-destructors - Wno-weak-vtables - Wno-old-style-cast - ) - - if (C++11 OR (DEFINED CMAKE_CXX_STANDARD AND NOT CMAKE_CXX_STANDARD EQUAL 98)) - set(WARNING_CXX_FLAGS - ${WARNING_CXX_FLAGS} - Wno-c++98-compat - Wno-c++98-compat-pedantic - Wno-c++14-compat - Wno-inconsistent-missing-destructor-override - ) - endif () - - check_and_append_c_warning_flags(${WARNING_C_FLAGS}) - check_and_append_c_warning_flags(${WARNING_C_ONLY_FLAGS}) - check_and_append_cxx_warning_flags(${WARNING_CXX_FLAGS}) - -endif (MSVC) diff --git a/cmake/Modules/FindCXX11.cmake b/cmake/Modules/FindCXX11.cmake deleted file mode 100644 index 8718ec107..000000000 --- a/cmake/Modules/FindCXX11.cmake +++ /dev/null @@ -1,54 +0,0 @@ -# - Finds if the compiler has C++11 support -# This module can be used to detect compiler flags for using C++11, and checks -# a small subset of the language. -# -# The following variables are set: -# CXX11_FLAGS - flags to add to the CXX compiler for C++11 support -# CXX11_FOUND - true if the compiler supports C++11 -# -# TODO: When compilers starts implementing the whole C++11, check the full set - -include(CheckCXXSourceCompiles) -include(FindPackageHandleStandardArgs) - -set(CXX11_FLAG_CANDIDATES - # Eveerything that automatically accepts C++11 - " " - # gcc, clang and Intel Linux - "-std=c++11" - # Intel windows - "/Qstd=c++0x" - "/Qstd=c++11" - ) - -set(CXX11_TEST_SOURCE -" -#if defined(_MSC_VER) - #if _MSC_VER < 1800 - #error \"Can not compile with C++11\" - #endif -#elif __cplusplus < 201103L - #error \"Can not compile with C++11\" -#endif - -int main() -{} -") - -foreach(FLAG ${CXX11_FLAG_CANDIDATES}) - set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") - set(CMAKE_REQUIRED_FLAGS "${FLAG}") - unset(CXX11_FLAG_DETECTED CACHE) - message(STATUS "Try C++11 flag = [${FLAG}]") - check_cxx_source_compiles("${CXX11_TEST_SOURCE}" CXX11_FLAG_DETECTED) - set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}") - if(CXX11_FLAG_DETECTED) - set(CXX11_FLAGS_INTERNAL "${FLAG}") - break() - endif(CXX11_FLAG_DETECTED) -endforeach(FLAG ${CXX11_FLAG_CANDIDATES}) - -set(CXX11_FLAGS "${CXX11_FLAGS_INTERNAL}") - -find_package_handle_standard_args(CXX11 DEFAULT_MSG CXX11_FLAGS) -mark_as_advanced(CXX11_FLAGS) diff --git a/cmake/Modules/_CppUTestDiscovery.cmake b/cmake/Modules/_CppUTestDiscovery.cmake new file mode 100644 index 000000000..a970fbc37 --- /dev/null +++ b/cmake/Modules/_CppUTestDiscovery.cmake @@ -0,0 +1,98 @@ +set(script) + +function(add_command NAME) + set(_args "") + # use ARGV* instead of ARGN, because ARGN splits arrays into multiple arguments + math(EXPR _last_arg ${ARGC}-1) + foreach(_n RANGE 1 ${_last_arg}) + set(_arg "${ARGV${_n}}") + if(_arg MATCHES "[^-./:a-zA-Z0-9_]") + set(_args "${_args} [==[${_arg}]==]") # form a bracket_argument + else() + set(_args "${_args} ${_arg}") + endif() + endforeach() + set(script "${script}${NAME}(${_args})\n" PARENT_SCOPE) +endfunction() + +if(NOT EXISTS "${EXECUTABLE}") + message(FATAL_ERROR + "Executable \"${EXECUTABLE}\" does not exist" + ) +endif() + +macro(add_test_to_script TEST_NAME TEST_LOCATION SELECT_ARG) + add_command( + add_test + "${TEST_NAME}" + ${EMULATOR} + "${EXECUTABLE}" + ${ARGS} + ${SELECT_ARG} + ${TEST_NAME} + ) + add_command( + set_tests_properties + "${TEST_NAME}" + PROPERTIES + DEF_SOURCE_LINE + "${TEST_LOCATION}" + ) +endmacro() + +execute_process( + COMMAND ${EMULATOR} "${EXECUTABLE}" -ll + OUTPUT_VARIABLE discovered_tests + RESULT_VARIABLE result + ERROR_VARIABLE error +) +if(NOT ${result} EQUAL 0) + message(FATAL_ERROR + "Error executing ${EXECUTABLE}:\n" + "${error}" + ) +endif() + +string(CONCAT LL_LINE_REGEX + "^([^.]*)" # test group + "\\." + "([^.]*)" # test name + "\\." + "(.*)" # file name (only this field is allowed to contain dots) + "\\." + "([^.]*)" # line number + "\n" +) +string(REGEX MATCHALL "[^\n]+\n" discovered_test_lines "${discovered_tests}") +if(TESTS_DETAILED) + foreach(line IN LISTS discovered_test_lines) + string(REGEX MATCH "${LL_LINE_REGEX}" __unused "${line}") + set(test_name "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}") + file(TO_CMAKE_PATH "${CMAKE_MATCH_3}" test_file) + set(test_location "${test_file}:${CMAKE_MATCH_4}") + add_test_to_script("${test_name}" "${test_location}" -st) + endforeach() +else() + foreach(line IN LISTS discovered_test_lines) + string(REGEX MATCH "${LL_LINE_REGEX}" __unused "${line}") + set(test_name "${CMAKE_MATCH_1}") + file(TO_CMAKE_PATH "${CMAKE_MATCH_3}" test_file) + set(test_line "${CMAKE_MATCH_4}") + if (NOT _${test_name}_file) + # if the group spans two files, arbitrarily choose the first one encountered + set(_${test_name}_file "${test_file}") + set(_${test_name}_line "${test_line}") + elseif(test_file STREQUAL _${test_name}_file AND test_line LESS _${test_name}_line) + # line number will eventually be the first line of the first test in the group's file + set(_${test_name}_line ${test_line}) + endif() + list(APPEND groups_seen ${test_name}) + endforeach() + list(REMOVE_DUPLICATES groups_seen) + foreach(test_name IN LISTS groups_seen) + set(test_location "${_${test_name}_file}:${_${test_name}_line}") + add_test_to_script("${test_name}" "${test_location}" -sg) + endforeach() +endif() + +file(WRITE "${CTEST_FILE}" "${script}") diff --git a/cmake/Scripts/CppUTestBuildTimeDiscoverTests.cmake b/cmake/Scripts/CppUTestBuildTimeDiscoverTests.cmake index 01eb45b3c..c5d96c031 100644 --- a/cmake/Scripts/CppUTestBuildTimeDiscoverTests.cmake +++ b/cmake/Scripts/CppUTestBuildTimeDiscoverTests.cmake @@ -41,7 +41,7 @@ function (JOIN VALUES GLUE OUTPUT) endfunction() function (buildtime_discover_tests EXECUTABLE DISCOVER_ARG OUTPUT) - execute_process(COMMAND ${EXECUTABLE} ${DISCOVER_ARG} + execute_process(COMMAND ${EMULATOR} ${EXECUTABLE} ${DISCOVER_ARG} OUTPUT_VARIABLE _TMP_OUTPUT ERROR_VARIABLE DISCOVER_ERR RESULT_VARIABLE DISCOVER_ERR) @@ -75,14 +75,14 @@ if (TESTS_DETAILED) set(lastgroup "${groupname}") endif (NOT ("${groupname}" STREQUAL "${lastgroup}")) message("... ${testname}") - buildtime_add_test(${EXECUTABLE_SHORT_NAME}.${testfullname} ${EXECUTABLE} -sg ${groupname} -sn ${testname}) + buildtime_add_test(${EXECUTABLE_SHORT_NAME}.${testfullname} ${EMULATOR} ${EXECUTABLE} -sg ${groupname} -sn ${testname}) endforeach() else (TESTS_DETAILED) set(DISCOVER_ARG "-lg") buildtime_discover_tests("${EXECUTABLE}" "${DISCOVER_ARG}" TestList_Groups) foreach(group ${TestList_Groups}) message("TestGroup: ${group}") - buildtime_add_test(${EXECUTABLE_SHORT_NAME}.${group} "${EXECUTABLE}" -sg ${group}) + buildtime_add_test(${EXECUTABLE_SHORT_NAME}.${group} ${EMULATOR} "${EXECUTABLE}" -sg ${group}) endforeach() endif (TESTS_DETAILED) diff --git a/cmake/Toolchains/arm-none-eabi-gcc.toolchain.cmake b/cmake/Toolchains/arm-none-eabi-gcc.toolchain.cmake new file mode 100644 index 000000000..b9ab5030e --- /dev/null +++ b/cmake/Toolchains/arm-none-eabi-gcc.toolchain.cmake @@ -0,0 +1,8 @@ +set(CMAKE_SYSTEM_NAME Generic) +set(CMAKE_SYSTEM_PROCESSOR cortex-m4) + +set(CMAKE_C_COMPILER arm-none-eabi-gcc) + +set(CMAKE_C_FLAGS_INIT "-mcpu=cortex-m4") +set(CMAKE_CXX_FLAGS_INIT "-mcpu=cortex-m4") +set(CMAKE_EXE_LINKER_FLAGS_INIT "-specs=rdimon.specs") diff --git a/cmake/clang+mingw-win32.toolchain.cmake b/cmake/Toolchains/clang+mingw-win32.toolchain.cmake similarity index 100% rename from cmake/clang+mingw-win32.toolchain.cmake rename to cmake/Toolchains/clang+mingw-win32.toolchain.cmake diff --git a/cmake/clang+mingw-win64.toolchain.cmake b/cmake/Toolchains/clang+mingw-win64.toolchain.cmake similarity index 100% rename from cmake/clang+mingw-win64.toolchain.cmake rename to cmake/Toolchains/clang+mingw-win64.toolchain.cmake diff --git a/cmake/Toolchains/ewarm-linux.toolchain.cmake b/cmake/Toolchains/ewarm-linux.toolchain.cmake new file mode 100644 index 000000000..e0053a7bf --- /dev/null +++ b/cmake/Toolchains/ewarm-linux.toolchain.cmake @@ -0,0 +1,21 @@ +### BEGIN CMAKE_TOOLCHAIN_FILE +# "Generic" is used when compiling for bare-metal +set(CMAKE_SYSTEM_NAME Generic) + +# Set the EW installation root directory +#(Avoid spaces in the path or you need to escape them) +set(EW_ROOT_DIR "/opt/iarsystems/bxarm/arm/") + +# Compiler flags needed to compile for this CPU +set(CPU_FLAGS "--cpu Cortex-M4F") + +# Set up the CMake variables for compiler and assembler +# (The reason for both C and CXX variables is that CMake +# treats C and C++ tools individually) +set(CMAKE_C_COMPILER "${EW_ROOT_DIR}/bin/iccarm" "${CPU_FLAGS} --dlib_config normal") +set(CMAKE_CXX_COMPILER "${EW_ROOT_DIR}/bin/iccarm" "${CPU_FLAGS} --dlib_config normal") +set(CMAKE_ASM_COMPILER "${EW_ROOT_DIR}/bin/iasmarm" "${CPU_FLAGS}") + +# Build with cmake -S. -Bbuild -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=cmake/Toolchains/ewarm-linux.toolchain.cmake + +### END CMAKE_TOOLCHAIN_FILE diff --git a/cmake/Toolchains/ewarm-win.toolchain.cmake b/cmake/Toolchains/ewarm-win.toolchain.cmake new file mode 100644 index 000000000..ab28b445f --- /dev/null +++ b/cmake/Toolchains/ewarm-win.toolchain.cmake @@ -0,0 +1,21 @@ +### BEGIN CMAKE_TOOLCHAIN_FILE +# "Generic" is used when compiling for bare-metal +set(CMAKE_SYSTEM_NAME Generic) + +# Set the EW installation root directory +#(Avoid spaces in the path or you need to escape them) +set(EW_ROOT_DIR "E:/Program Files\ (x86)/IAR\ Systems/Embedded\ Workbench\ Arm 8.50.6/arm") + +# Compiler flags needed to compile for this CPU +set(CPU_FLAGS "--cpu Cortex-M4F") + +# Set up the CMake variables for compiler and assembler +# (The reason for both C and CXX variables is that CMake +# treats C and C++ tools individually) +set(CMAKE_C_COMPILER "${EW_ROOT_DIR}/bin/iccarm.exe" "${CPU_FLAGS} --dlib_config normal") +set(CMAKE_CXX_COMPILER "${EW_ROOT_DIR}/bin/iccarm.exe" "${CPU_FLAGS} --dlib_config normal") +set(CMAKE_ASM_COMPILER "${EW_ROOT_DIR}/bin/iasmarm.exe" "${CPU_FLAGS}") + +# Build with cmake -S. -Bbuild -G "NMake Makefiles" -DCMAKE_TOOLCHAIN_FILE=cmake/Toolchains/ewarm-win.toolchain.cmake + +### END CMAKE_TOOLCHAIN_FILE diff --git a/cmake/install.cmake b/cmake/install.cmake new file mode 100644 index 000000000..f58ba31b9 --- /dev/null +++ b/cmake/install.cmake @@ -0,0 +1,65 @@ +set(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}") +set(LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}") +set(INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include") + +# Pkg-config file. +set(prefix "${CMAKE_INSTALL_PREFIX}") +set(exec_prefix "\${prefix}") +set(libdir "\${exec_prefix}/${LIB_INSTALL_DIR}") +set(includedir "\${prefix}/${INCLUDE_INSTALL_DIR}") +set(PACKAGE_VERSION "${PROJECT_VERSION}") + +configure_file(cpputest.pc.in cpputest.pc @ONLY) +install( + FILES "${CMAKE_CURRENT_BINARY_DIR}/cpputest.pc" + DESTINATION ${LIB_INSTALL_DIR}/pkgconfig +) + +install( + FILES "${CMAKE_CURRENT_BINARY_DIR}/generated/CppUTestGeneratedConfig.h" + DESTINATION "${INCLUDE_INSTALL_DIR}/generated" +) + +include(CMakePackageConfigHelpers) + +set(CPPUTEST_CONFIG_DEST "${LIB_INSTALL_DIR}/CppUTest/cmake") + +configure_package_config_file(CppUTestConfig.cmake.install.in + ${CMAKE_CURRENT_BINARY_DIR}/install/CppUTestConfig.cmake + INSTALL_DESTINATION "${CPPUTEST_CONFIG_DEST}" + PATH_VARS INCLUDE_INSTALL_DIR LIB_INSTALL_DIR) +write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/install/CppUTestConfigVersion.cmake + COMPATIBILITY SameMajorVersion +) +install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/install/CppUTestConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/install/CppUTestConfigVersion.cmake + DESTINATION "${CPPUTEST_CONFIG_DEST}" +) +install( + EXPORT CppUTestTargets + NAMESPACE CppUTest:: + DESTINATION "${CPPUTEST_CONFIG_DEST}" +) +install( + FILES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Scripts/CppUTestBuildTimeDiscoverTests.cmake + DESTINATION "${CPPUTEST_CONFIG_DEST}/Scripts" +) +install( + FILES + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/CppUTestBuildTimeDiscoverTests.cmake + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/CppUTest.cmake + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/_CppUTestDiscovery.cmake + DESTINATION "${CPPUTEST_CONFIG_DEST}/Modules" +) +configure_package_config_file(CppUTestConfig.cmake.build.in + ${CMAKE_CURRENT_BINARY_DIR}/CppUTestConfig.cmake + INSTALL_DESTINATION ${CMAKE_CURRENT_BINARY_DIR} + PATH_VARS INCLUDE_DIR CMAKE_CURRENT_BINARY_DIR +) +write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/CppUTestConfigVersion.cmake + COMPATIBILITY SameMajorVersion +) diff --git a/cmake/warnings.cmake b/cmake/warnings.cmake new file mode 100644 index 000000000..4b763f684 --- /dev/null +++ b/cmake/warnings.cmake @@ -0,0 +1,68 @@ +unset(WARNING_COMMON_FLAGS) +unset(WARNING_C_FLAGS) +unset(WARNING_CXX_FLAGS) + +if( + (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR + (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") OR + (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") +) + set(WARNING_COMMON_FLAGS + -Wall + -Wextra + -pedantic + -Wshadow + -Wswitch-default + -Wswitch-enum + -Wconversion + -Wsign-conversion + -Wmissing-include-dirs + -Wno-padded + -Wno-disabled-macro-expansion + -Wreserved-id-macro + -Wreserved-identifier + -Wno-long-long + -Wno-unsafe-buffer-usage + ) + + set(WARNING_C_FLAGS + -Wstrict-prototypes + ) + + set(WARNING_CXX_FLAGS + -Woverloaded-virtual + -Wno-global-constructors + -Wno-exit-time-destructors + -Wno-weak-vtables + -Wno-old-style-cast + ) + + if(DEFINED CMAKE_CXX_STANDARD AND NOT CMAKE_CXX_STANDARD EQUAL 98) + list(APPEND WARNING_CXX_FLAGS + -Wno-c++98-compat + -Wno-c++98-compat-pedantic + -Wno-c++14-compat + -Wno-inconsistent-missing-destructor-override + -Wsuggest-override + ) + endif() + + set(CMAKE_REQUIRED_FLAGS "-Wno-error") +endif() + +include(CheckCCompilerFlag) +foreach(flag IN LISTS WARNING_COMMON_FLAGS WARNING_C_FLAGS) + check_c_compiler_flag("${flag}" WARNING_C_FLAG_${flag}) + if(WARNING_C_FLAG_${flag}) + add_compile_options("$<$:${flag}>") + endif() +endforeach() + +include(CheckCXXCompilerFlag) +foreach(flag IN LISTS WARNING_COMMON_FLAGS WARNING_CXX_FLAGS) + string(REPLACE "++" "xx" WARNING_CXX_FLAG_VAR "WARNING_CXX_FLAG_${flag}") + check_cxx_compiler_flag("${flag}" ${WARNING_CXX_FLAG_VAR}) + if(${WARNING_CXX_FLAG_VAR}) + add_compile_options("$<$:${flag}>") + endif() +endforeach() diff --git a/config.h.cmake b/config.h.cmake index e8a4b9fd4..037a695fb 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -2,11 +2,17 @@ #define CONFIG_H_ #cmakedefine CPPUTEST_MEM_LEAK_DETECTION_DISABLED -#cmakedefine CPPUTEST_USE_LONG_LONG +#cmakedefine01 CPPUTEST_USE_LONG_LONG +#cmakedefine CPPUTEST_HAVE_STRDUP + +#cmakedefine CPPUTEST_HAVE_FORK +#cmakedefine CPPUTEST_HAVE_WAITPID +#cmakedefine CPPUTEST_HAVE_KILL +#cmakedefine CPPUTEST_HAVE_PTHREAD_MUTEX_LOCK + +#cmakedefine CPPUTEST_HAVE_GETTIMEOFDAY #cmakedefine CPPUTEST_STD_C_LIB_DISABLED #cmakedefine CPPUTEST_STD_CPP_LIB_DISABLED -#cmakedefine INCLUDE_GTEST_TESTS - #endif diff --git a/configure.ac b/configure.ac index a6cd8328e..3120f9571 100644 --- a/configure.ac +++ b/configure.ac @@ -62,7 +62,7 @@ AC_TYPE_LONG_LONG_INT # Checks for library functions. AC_FUNC_FORK -AC_CHECK_FUNCS([gettimeofday memset strstr strdup pthread_mutex_lock]) +AC_CHECK_FUNCS([waitpid gettimeofday memset strstr strdup pthread_mutex_lock kill]) AC_CHECK_PROG([CPPUTEST_HAS_GCC], [gcc], [yes], [no]) AC_CHECK_PROG([CPPUTEST_HAS_CLANG], [clang], [yes], [no]) @@ -76,7 +76,7 @@ saved_cxxflags="$CXXFLAGS" saved_ldflags="$LDFLAGS" if test "x$USE_MAINTAINER_MODE" = "xyes"; then -# FLag -Werror. +# Flag -Werror. CFLAGS=-Werror AC_MSG_CHECKING([whether CC and CXX supports -Werror]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CWARNINGFLAGS_STRICT="${CPPUTEST_CWARNINGFLAGS} -Werror"; CPPUTEST_CXXWARNINGFLAGS_STRICT="${CPPUTEST_CXXWARNINGFLAGS} -Werror" ], [AC_MSG_RESULT([no])]) @@ -87,31 +87,31 @@ AC_LANG_PUSH([C++]) ##################################################################################### ##### C++ checks -# FLag -std=c++1y +# Flag -std=c++1y CXXFLAGS="-Werror -std=c++1y" AC_MSG_CHECKING([whether CXX supports -std=c++1y]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CPP14FLAG="-std=c++1y" ], [AC_MSG_RESULT([no])]) CXXFLAGS="$saved_cxxflags" -# FLag std=c++14 +# Flag std=c++14 CXXFLAGS="-Werror -std=c++14" AC_MSG_CHECKING([whether CXX supports -std=c++14]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CPP14FLAG="-std=c++14" ], [AC_MSG_RESULT([no])]) CXXFLAGS="$saved_cxxflags" -# FLag std=c++17 +# Flag std=c++17 CXXFLAGS="-Werror -std=c++17" AC_MSG_CHECKING([whether CXX supports -std=c++17]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CPP17FLAG="-std=c++17" ], [AC_MSG_RESULT([no])]) CXXFLAGS="$saved_cxxflags" -# FLag std=c++20 +# Flag std=c++20 CXXFLAGS="-Werror -std=c++2a" AC_MSG_CHECKING([whether CXX supports -std=c++2a]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CPP20FLAG="-std=c++2a" ], [AC_MSG_RESULT([no])]) CXXFLAGS="$saved_cxxflags" -# FLag std=c++20 +# Flag std=c++20 CXXFLAGS="-Werror -std=c++20" AC_MSG_CHECKING([whether CXX supports -std=c++20]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CPP20FLAG="-std=c++20" ], [AC_MSG_RESULT([no])]) @@ -122,13 +122,13 @@ CXXFLAGS="$saved_cxxflags" ### Checking for C++ version compiler flags -# FLag -std=c++98 +# Flag -std=c++98 CXXFLAGS="-Werror -std=c++98" AC_MSG_CHECKING([whether CXX supports -std=c++98]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CPP98FLAG="-std=c++98" ], [AC_MSG_RESULT([no])]) CXXFLAGS="$saved_cxxflags" -# FLag -std=c++0x +# Flag -std=c++0x CXXFLAGS="-Werror -std=c++0x" AC_MSG_CHECKING([whether CXX supports -std=c++0x]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CPP11FLAG="-std=c++0x" ], [AC_MSG_RESULT([no])]) @@ -164,13 +164,13 @@ CXXFLAGS="$saved_cxxflags" AC_LANG_POP -# FLag -Wno-c++11-long-long. This must be on if it is available as otherwise long long is supported but causes a warning. +# Flag -Wno-c++11-long-long. This must be on if it is available as otherwise long long is supported but causes a warning. CFLAGS="-Werror -Wno-c++11-long-long" AC_MSG_CHECKING([whether CC and CXX supports -Wno-c++11-long-long]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CWARNINGFLAGS="${CPPUTEST_CWARNINGFLAGS} -Wno-c++11-long-long" CPPUTEST_CXXWARNINGFLAGS="${CPPUTEST_CXXWARNINGFLAGS} -Wno-c++11-long-long" ], [AC_MSG_RESULT([no])]) CFLAGS="$saved_cflags" -# FLag -Wno-long-long must be on for C. +# Flag -Wno-long-long must be on for C. CFLAGS="-Werror -Wno-long-long" AC_MSG_CHECKING([whether CC and CXX supports -Wno-long-long]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CWARNINGFLAGS="${CPPUTEST_CWARNINGFLAGS} -Wno-long-long" CPPUTEST_CXXWARNINGFLAGS="${CPPUTEST_CXXWARNINGFLAGS} -Wno-long-long"], [AC_MSG_RESULT([no])]) @@ -178,63 +178,68 @@ CFLAGS="$saved_cflags" ##################################################################################### -##### More of these warnings -# FLag -Weverything. -CFLAGS="-Werror -Weverything -Wno-unused-macros" -AC_MSG_CHECKING([whether CC and CXX supports -Weverything]) -AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CWARNINGFLAGS="${CPPUTEST_CWARNINGFLAGS} -Weverything"; CPPUTEST_CXXWARNINGFLAGS="${CPPUTEST_CXXWARNINGFLAGS} -Weverything" ], [AC_MSG_RESULT([no])]) -CFLAGS="$saved_cflags" - -# FLag -Wall. +# Flag -Wall. CFLAGS="-Werror -Wall" AC_MSG_CHECKING([whether CC and CXX supports -Wall]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CWARNINGFLAGS="${CPPUTEST_CWARNINGFLAGS} -Wall"; CPPUTEST_CXXWARNINGFLAGS="${CPPUTEST_CXXWARNINGFLAGS} -Wall" ], [AC_MSG_RESULT([no])]) CFLAGS="$saved_cflags" -# FLag -Wextra. +# Flag -Wextra. CFLAGS="-Werror -Wextra" AC_MSG_CHECKING([whether CC and CXX supports -Wextra]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CWARNINGFLAGS="${CPPUTEST_CWARNINGFLAGS} -Wextra"; CPPUTEST_CXXWARNINGFLAGS="${CPPUTEST_CXXWARNINGFLAGS} -Wextra" ], [AC_MSG_RESULT([no])]) CFLAGS="$saved_cflags" -# FLag -Wshadow. +# Flag -Wshadow. CFLAGS="-Werror -Wshadow" AC_MSG_CHECKING([whether CC and CXX supports -Wshadow]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CWARNINGFLAGS="${CPPUTEST_CWARNINGFLAGS} -Wshadow"; CPPUTEST_CXXWARNINGFLAGS="${CPPUTEST_CXXWARNINGFLAGS} -Wshadow" ], [AC_MSG_RESULT([no])]) CFLAGS="$saved_cflags" -# FLag -Wswitch-default +# Flag -Wswitch-default CFLAGS="-Werror -Wswitch-default" AC_MSG_CHECKING([whether CC and CXX supports -Wswitch-default]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CWARNINGFLAGS="${CPPUTEST_CWARNINGFLAGS} -Wswitch-default"; CPPUTEST_CXXWARNINGFLAGS="${CPPUTEST_CXXWARNINGFLAGS} -Wswitch-default" ], [AC_MSG_RESULT([no])]) CFLAGS="$saved_cflags" -# FLag -Wswitch-enum +# Flag -Wswitch-enum CFLAGS="-Werror -Wswitch-enum" AC_MSG_CHECKING([whether CC and CXX supports -Wswitch-enum]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CWARNINGFLAGS="${CPPUTEST_CWARNINGFLAGS} -Wswitch-enum"; CPPUTEST_CXXWARNINGFLAGS="${CPPUTEST_CXXWARNINGFLAGS} -Wswitch-enum" ], [AC_MSG_RESULT([no])]) CFLAGS="$saved_cflags" -# FLag -Wconversion +# Flag -Wconversion CFLAGS="-Werror -Wconversion" AC_MSG_CHECKING([whether CC and CXX supports -Wconversion]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CWARNINGFLAGS="${CPPUTEST_CWARNINGFLAGS} -Wconversion"; CPPUTEST_CXXWARNINGFLAGS="${CPPUTEST_CXXWARNINGFLAGS} -Wconversion" ], [AC_MSG_RESULT([no])]) CFLAGS="$saved_cflags" -# FLag -pedantic +# Flag -pedantic CFLAGS="-Werror -pedantic" AC_MSG_CHECKING([whether CC and CXX supports -pedantic]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CWARNINGFLAGS="${CPPUTEST_CWARNINGFLAGS} -pedantic"; CPPUTEST_CXXWARNINGFLAGS="${CPPUTEST_CXXWARNINGFLAGS} -pedantic" ], [AC_MSG_RESULT([no])]) CFLAGS="$saved_cflags" -# FLag -Wsign-conversion +# Flag -Wsign-conversion CFLAGS="-Werror -Wsign-conversion" AC_MSG_CHECKING([whether CC supports -Wsign-conversion]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CWARNINGFLAGS="${CPPUTEST_CWARNINGFLAGS} -Wsign-conversion"], [AC_MSG_RESULT([no])]) CFLAGS="$saved_cflags" +# Flag -Wreserved-id-macro +CFLAGS="-Werror -Wreserved-id-macro" +AC_MSG_CHECKING([whether CC support -Wreserved-id-macro]) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CWARNINGFLAGS="${CPPUTEST_CWARNINGFLAGS} -Wreserved-id-macro"], [AC_MSG_RESULT([no])]) +CFLAGS="$saved_cflags" + +# Flag -Wreserved-identifier +CFLAGS="-Werror -Wreserved-identifier" +AC_MSG_CHECKING([whether CC supports -Wreserved-identifier]) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CWARNINGFLAGS="${CPPUTEST_CWARNINGFLAGS} -Wreserved-identifier"; CPPUTEST_CXXWARNINGFLAGS="${CPPUTEST_CXXWARNINGFLAGS} -Wreserved-identifier" ], [AC_MSG_RESULT([no])]) +CFLAGS="$saved_cflags" + ##### C++ Warnings -# FLag -Wsign-conversion (for CXX) +# Flag -Wsign-conversion (for CXX) AC_LANG_PUSH([C++]) CXXFLAGS="-Werror -Wsign-conversion" @@ -242,7 +247,7 @@ AC_MSG_CHECKING([whether CXX supports -Wsign-conversion]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CXXWARNINGFLAGS="${CPPUTEST_CXXWARNINGFLAGS} -Wsign-conversion"], [AC_MSG_RESULT([no])]) CXXFLAGS="$saved_cxxflags" -# FLag -Woverloaded-virtual +# Flag -Woverloaded-virtual CXXFLAGS="-Werror -Woverloaded-virtual" AC_MSG_CHECKING([whether CXX supports -Woverloaded-virtual]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CXXWARNINGFLAGS="${CPPUTEST_CXXWARNINGFLAGS} -Woverloaded-virtual" ], [AC_MSG_RESULT([no])]) @@ -250,7 +255,7 @@ CXXFLAGS="$saved_cxxflags" AC_LANG_POP -# FLag -Wstrict-prototypes +# Flag -Wstrict-prototypes CFLAGS="-Werror -Wstrict-prototypes" AC_MSG_CHECKING([whether CC supports -Wstrict-prototypes]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CWARNINGFLAGS="${CPPUTEST_CWARNINGFLAGS} -Wstrict-prototypes" ], [AC_MSG_RESULT([no])]) @@ -261,61 +266,58 @@ CFLAGS="$saved_cflags" ##### Less of these warnings # # Disable some warnings as CppUTest has this and can't be prevented at the moment. -# FLag -Wno-disabled-macro-expansion. +# Flag -Wno-disabled-macro-expansion. CFLAGS="-Werror -Wno-disabled-macro-expansion" AC_MSG_CHECKING([whether CC and CXX supports -Wno-disabled-macro-expansion]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CWARNINGFLAGS="${CPPUTEST_CWARNINGFLAGS} -Wno-disabled-macro-expansion"; CPPUTEST_CXXWARNINGFLAGS="${CPPUTEST_CXXWARNINGFLAGS} -Wno-disabled-macro-expansion" ], [AC_MSG_RESULT([no])]) CFLAGS="$saved_cflags" -# FLag -Wno-padded. +# Flag -Wno-padded. CFLAGS="-Werror -Wno-padded" AC_MSG_CHECKING([whether CC and CXX supports -Wno-padded]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CWARNINGFLAGS="${CPPUTEST_CWARNINGFLAGS} -Wno-padded"; CPPUTEST_CXXWARNINGFLAGS="${CPPUTEST_CXXWARNINGFLAGS} -Wno-padded" ], [AC_MSG_RESULT([no])]) CFLAGS="$saved_cflags" -# FLag -Wno-reserved-id-macro. -CFLAGS="-Werror -Wno-reserved-id-macro" -AC_MSG_CHECKING([whether CC and CXX supports -Wno-reserved-id-macro]) -AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CWARNINGFLAGS="${CPPUTEST_CWARNINGFLAGS} -Wno-reserved-id-macro"; CPPUTEST_CXXWARNINGFLAGS="${CPPUTEST_CXXWARNINGFLAGS} -Wno-reserved-id-macro" ], [AC_MSG_RESULT([no])]) -CFLAGS="$saved_cflags" - -# FLag -Wno-keyword-macro. -CFLAGS="-Werror -Wno-keyword-macro" -AC_MSG_CHECKING([whether CC and CXX supports -Wno-keyword-macro]) -AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CWARNINGFLAGS="${CPPUTEST_CWARNINGFLAGS} -Wno-keyword-macro"; CPPUTEST_CXXWARNINGFLAGS="${CPPUTEST_CXXWARNINGFLAGS} -Wno-keyword-macro" ], [AC_MSG_RESULT([no])]) -CFLAGS="$saved_cflags" - AC_LANG_PUSH([C++]) -# FLag -Wno-global-constructors. +# Flag -Wno-global-constructors. CXXFLAGS="-Werror -Wno-global-constructors" AC_MSG_CHECKING([whether CXX supports -Wno-global-constructors]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CXXWARNINGFLAGS="${CPPUTEST_CXXWARNINGFLAGS} -Wno-global-constructors" ], [AC_MSG_RESULT([no])]) CXXFLAGS="$saved_cxxflags" -# FLag -Wno-exit-time-destructors. +# Flag -Wno-exit-time-destructors. CXXFLAGS="-Werror -Wno-exit-time-destructors" AC_MSG_CHECKING([whether CXX supports -Wno-exit-time-destructors]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CXXWARNINGFLAGS="${CPPUTEST_CXXWARNINGFLAGS} -Wno-exit-time-destructors" ], [AC_MSG_RESULT([no])]) CXXFLAGS="$saved_cxxflags" -# FLag -Wno-weak-vtables. +# Flag -Wno-weak-vtables. CXXFLAGS="-Werror -Wno-weak-vtables" AC_MSG_CHECKING([whether CXX supports -Wno-weak-vtables]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CXXWARNINGFLAGS="${CPPUTEST_CXXWARNINGFLAGS} -Wno-weak-vtables" ], [AC_MSG_RESULT([no])]) CXXFLAGS="$saved_cxxflags" -# FLag -Wno-old-style-cast. +# Flag -Wno-old-style-cast. CXXFLAGS="-Werror -Wno-old-style-cast" AC_MSG_CHECKING([whether CXX supports -Wno-old-style-cast]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CXXWARNINGFLAGS="${CPPUTEST_CXXWARNINGFLAGS} -Wno-old-style-cast" ], [AC_MSG_RESULT([no])]) CXXFLAGS="$saved_cxxflags" +if test "x${memory_leak_detection}" = xyes; then + # GCC's default optimization breaks leak detection: + # https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Dialect-Options.html#index-fassume-sane-operators-new-delete + CXXFLAGS="-Werror -fno-assume-sane-operators-new-delete" + AC_MSG_CHECKING([whether CXX supports -fno-assume-sane-operators-new-delete]) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CXXWARNINGFLAGS="${CPPUTEST_CXXWARNINGFLAGS} -fno-assume-sane-operators-new-delete" ], [AC_MSG_RESULT([no])]) + CXXFLAGS="$saved_cxxflags" +fi + AC_LANG_POP ##################################################### ######## End warning section -# FLag --coverage +# Flag --coverage AC_LANG_PUSH([C++]) CXXFLAGS="-Werror --coverage" AC_MSG_CHECKING([whether CXX and the linker supports --coverage (broken in clang 3.3)]) @@ -341,7 +343,7 @@ AC_MSG_CHECKING([whether CXX supports operator new with exception handling speci AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include \nvoid* operator new(size_t size) throw(std::bad_alloc);;])], [AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no]); UT_NEW_CANT_HAVE_EXCEPTION_SPECIFIER="yes"]) CXXFLAGS="$saved_cxxflags" -# FLag -Wno-missing-exception-spec +# Flag -Wno-missing-exception-spec CXXFLAGS="-Werror -Wno-missing-exception-spec" AC_MSG_CHECKING([whether CXX supports -Wno-missing-exception-spec]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CXX_NO_INC_WARNINGFLAGS="${CPPUTEST_CXX_NO_INC_WARNINGFLAGS} -Wno-missing-exception-spec" ], [AC_MSG_RESULT([no])]) diff --git a/cpputest_build/.gitignore b/cpputest_build/.gitignore deleted file mode 100644 index d6b7ef32c..000000000 --- a/cpputest_build/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore diff --git a/examples/AllTests/AllTests.cpp b/examples/AllTests/AllTests.cpp index 5ff9de3b1..7d17d6f3d 100644 --- a/examples/AllTests/AllTests.cpp +++ b/examples/AllTests/AllTests.cpp @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -34,12 +34,12 @@ class MyDummyComparator : public MockNamedValueComparator { public: - virtual bool isEqual(const void* object1, const void* object2) + virtual bool isEqual(const void* object1, const void* object2) CPPUTEST_OVERRIDE { return object1 == object2; } - virtual SimpleString valueToString(const void* object) + virtual SimpleString valueToString(const void* object) CPPUTEST_OVERRIDE { return StringFrom(object); } diff --git a/examples/AllTests/AllTests.h b/examples/AllTests/AllTests.h index aebcc310d..9902c6f17 100644 --- a/examples/AllTests/AllTests.h +++ b/examples/AllTests/AllTests.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -25,8 +25,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -IMPORT_TEST_GROUP( Printer); -IMPORT_TEST_GROUP( CircularBuffer); -IMPORT_TEST_GROUP( HelloWorld); -IMPORT_TEST_GROUP( EventDispatcher); -IMPORT_TEST_GROUP( MockDocumentation); +IMPORT_TEST_GROUP(Printer); +IMPORT_TEST_GROUP(CircularBuffer); +IMPORT_TEST_GROUP(HelloWorld); +IMPORT_TEST_GROUP(EventDispatcher); +IMPORT_TEST_GROUP(MockDocumentation); diff --git a/examples/AllTests/AllTests.vcproj b/examples/AllTests/AllTests.vcproj index 4d1be1530..ad9ab2b72 100644 --- a/examples/AllTests/AllTests.vcproj +++ b/examples/AllTests/AllTests.vcproj @@ -45,7 +45,7 @@ :/wd4723> +) + +target_link_libraries(ExampleTests + PRIVATE + ApplicationLib + CppUTest::CppUTestExt +) + +include(CppUTest) +cpputest_discover_tests(ExampleTests) diff --git a/examples/AllTests/CircularBufferTest.cpp b/examples/AllTests/CircularBufferTest.cpp index 7554385ce..4602e5ab9 100644 --- a/examples/AllTests/CircularBufferTest.cpp +++ b/examples/AllTests/CircularBufferTest.cpp @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -30,27 +30,28 @@ #include "CircularBuffer.h" TEST_GROUP(CircularBuffer) -{ CircularBuffer* buffer; - -void setup() -{ - buffer = new CircularBuffer(); -} -void teardown() -{ - delete buffer; -} - -void fillTheQueue(int seed, int howMany) { - for (int i = 0; i < howMany; i++) - buffer->Put(seed + i); -} -void removeFromQueue(int howMany) -{ - for (int i = 0; i < howMany; i++) - buffer->Get(); -} + CircularBuffer* buffer; + + void setup() CPPUTEST_OVERRIDE + { + buffer = new CircularBuffer(); + } + void teardown() CPPUTEST_OVERRIDE + { + delete buffer; + } + + void fillTheQueue(int seed, int howMany) + { + for (int i = 0; i < howMany; i++) + buffer->Put(seed + i); + } + void removeFromQueue(int howMany) + { + for (int i = 0; i < howMany; i++) + buffer->Get(); + } }; TEST(CircularBuffer, EmptyAfterCreation) @@ -134,15 +135,14 @@ TEST(CircularBuffer, PutToFull) buffer->Put(9999); for (int i = 0; i < buffer->Capacity() - 1; i++) - LONGS_EQUAL(i+900+1, buffer->Get()); + LONGS_EQUAL(i + 900 + 1, buffer->Get()); LONGS_EQUAL(9999, buffer->Get()); CHECK(buffer->IsEmpty()); } -//Sometime people ask what tests the tests. -//Do you know the answer - +// Sometime people ask what tests the tests. +// Do you know the answer TEST(CircularBuffer, GetFromEmpty) { @@ -162,8 +162,7 @@ TEST(CircularBuffer, PrintEmpty) Printer* p = &mock; buffer->Print(p); - STRCMP_EQUAL("Circular buffer content:\n<>\n", - mock.getOutput().c_str()); + STRCMP_EQUAL("Circular buffer content:\n<>\n", mock.getOutput().c_str()); } TEST(CircularBuffer, PrintAfterOnePut) @@ -172,8 +171,7 @@ TEST(CircularBuffer, PrintAfterOnePut) buffer->Put(1); buffer->Print(&mock); - STRCMP_EQUAL("Circular buffer content:\n<1>\n", - mock.getOutput().c_str()); + STRCMP_EQUAL("Circular buffer content:\n<1>\n", mock.getOutput().c_str()); } TEST(CircularBuffer, PrintNotYetWrappedOrFull) @@ -184,8 +182,7 @@ TEST(CircularBuffer, PrintNotYetWrappedOrFull) buffer->Put(2); buffer->Put(3); buffer->Print(&mock); - STRCMP_EQUAL("Circular buffer content:\n<1, 2, 3>\n", - mock.getOutput().c_str()); + STRCMP_EQUAL("Circular buffer content:\n<1, 2, 3>\n", mock.getOutput().c_str()); } TEST(CircularBuffer, PrintNotYetWrappedAndIsFull) @@ -195,7 +192,8 @@ TEST(CircularBuffer, PrintNotYetWrappedAndIsFull) fillTheQueue(200, buffer->Capacity()); buffer->Print(&mock); - const char* expected = "Circular buffer content:\n" + const char* expected = + "Circular buffer content:\n" "<200, 201, 202, 203, 204>\n"; STRCMP_EQUAL(expected, mock.getOutput().c_str()); @@ -210,7 +208,8 @@ TEST(CircularBuffer, PrintWrappedAndIsFullOldestToNewest) buffer->Put(999); buffer->Print(&mock); - const char* expected = "Circular buffer content:\n" + const char* expected = + "Circular buffer content:\n" "<201, 202, 203, 204, 999>\n"; STRCMP_EQUAL(expected, mock.getOutput().c_str()); @@ -224,7 +223,8 @@ TEST(CircularBuffer, PrintWrappedAndFullOverwriteOldest) buffer->Put(9999); buffer->Print(&mock); - const char* expected = "Circular buffer content:\n" + const char* expected = + "Circular buffer content:\n" "<201, 202, 203, 204, 9999>\n"; STRCMP_EQUAL(expected, mock.getOutput().c_str()); @@ -240,7 +240,8 @@ TEST(CircularBuffer, PrintBoundary) fillTheQueue(300, buffer->Capacity() - 1); buffer->Print(&mock); - const char* expected = "Circular buffer content:\n" + const char* expected = + "Circular buffer content:\n" "<888, 300, 301, 302, 303>\n"; STRCMP_EQUAL(expected, mock.getOutput().c_str()); @@ -253,7 +254,8 @@ TEST(CircularBuffer, FillEmptyThenPrint) fillTheQueue(200, buffer->Capacity()); removeFromQueue(buffer->Capacity()); buffer->Print(&mock); - const char* expected = "Circular buffer content:\n" + const char* expected = + "Circular buffer content:\n" "<>\n"; STRCMP_EQUAL(expected, mock.getOutput().c_str()); diff --git a/examples/AllTests/EventDispatcherTest.cpp b/examples/AllTests/EventDispatcherTest.cpp index 4515ff559..7ea4b52a4 100644 --- a/examples/AllTests/EventDispatcherTest.cpp +++ b/examples/AllTests/EventDispatcherTest.cpp @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -25,18 +25,32 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#if CPPUTEST_USE_NEW_MACROS + #undef realloc + #undef new +#endif + +#include "EventDispatcher.h" + +#if CPPUTEST_USE_NEW_MACROS + #include "CppUTest/MemoryLeakDetectorNewMacros.h" +#endif + #include "CppUTest/TestHarness.h" #include "CppUTestExt/MockSupport.h" -#include "EventDispatcher.h" class ObserverMock : public EventObserver { public: - virtual void notify(const Event& event, int timeOutInSeconds) + virtual void notify(const Event& event, int timeOutInSeconds) CPPUTEST_OVERRIDE { - mock().actualCall("notify").onObject(this).withParameterOfType("Event", "event", (void*) &event).withParameter("timeOutInSeconds", timeOutInSeconds); + mock() + .actualCall("notify") + .onObject(this) + .withParameterOfType("Event", "event", (void*)&event) + .withParameter("timeOutInSeconds", timeOutInSeconds); } - virtual void notifyRegistration(EventObserver* newObserver) + virtual void notifyRegistration(EventObserver* newObserver) CPPUTEST_OVERRIDE { mock().actualCall("notifyRegistration").onObject(this).withParameter("newObserver", newObserver); } @@ -45,17 +59,16 @@ class ObserverMock : public EventObserver class EventComparator : public MockNamedValueComparator { public: - virtual bool isEqual(const void* object1, const void* object2) + virtual bool isEqual(const void* object1, const void* object2) CPPUTEST_OVERRIDE { return ((const Event*)object1)->type == ((const Event*)object2)->type; } - virtual SimpleString valueToString(const void* object) + virtual SimpleString valueToString(const void* object) CPPUTEST_OVERRIDE { return StringFrom(((const Event*)object)->type); } }; - TEST_GROUP(EventDispatcher) { Event event; @@ -64,19 +77,18 @@ TEST_GROUP(EventDispatcher) ObserverMock observer2; EventComparator eventComparator; - void setup() + void setup() CPPUTEST_OVERRIDE { dispatcher = new EventDispatcher; mock().installComparator("Event", eventComparator); } - void teardown() + void teardown() CPPUTEST_OVERRIDE { delete dispatcher; mock().removeAllComparatorsAndCopiers(); } }; - TEST(EventDispatcher, EventWithoutRegistrationsResultsIntoNoCalls) { dispatcher->dispatchEvent(event, 10); @@ -84,7 +96,11 @@ TEST(EventDispatcher, EventWithoutRegistrationsResultsIntoNoCalls) TEST(EventDispatcher, EventWithRegistrationForEventResultsIntoCallback) { - mock().expectOneCall("notify").onObject(&observer).withParameterOfType("Event", "event", &event).withParameter("timeOutInSeconds", 10); + mock() + .expectOneCall("notify") + .onObject(&observer) + .withParameterOfType("Event", "event", &event) + .withParameter("timeOutInSeconds", 10); event.type = IMPORTANT_EVENT; dispatcher->registerObserver(IMPORTANT_EVENT, &observer); @@ -100,8 +116,16 @@ TEST(EventDispatcher, DifferentEventWithRegistrationDoesNotResultIntoCallback) TEST(EventDispatcher, RegisterTwoObserversResultIntoTwoCallsAndARegistrationNotification) { - mock().expectOneCall("notify").onObject(&observer).withParameterOfType("Event", "event", &event).withParameter("timeOutInSeconds", 10); - mock().expectOneCall("notify").onObject(&observer2).withParameterOfType("Event", "event", &event).withParameter("timeOutInSeconds", 10); + mock() + .expectOneCall("notify") + .onObject(&observer) + .withParameterOfType("Event", "event", &event) + .withParameter("timeOutInSeconds", 10); + mock() + .expectOneCall("notify") + .onObject(&observer2) + .withParameterOfType("Event", "event", &event) + .withParameter("timeOutInSeconds", 10); mock().expectOneCall("notifyRegistration").onObject(&observer).withParameter("newObserver", &observer2); event.type = IMPORTANT_EVENT; diff --git a/examples/AllTests/FEDemoTest.cpp b/examples/AllTests/FEDemoTest.cpp index 8737ca9a4..c2f6c17f2 100644 --- a/examples/AllTests/FEDemoTest.cpp +++ b/examples/AllTests/FEDemoTest.cpp @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -29,8 +29,8 @@ #include "CppUTest/TestHarness.h" #include "CppUTest/TestRegistry.h" -#ifdef CPPUTEST_HAVE_FENV -#include "CppUTestExt/IEEE754ExceptionsPlugin.h" +#if CPPUTEST_HAVE_FENV + #include "CppUTestExt/IEEE754ExceptionsPlugin.h" /* * To see a demonstration of tests failing as a result of IEEE754ExceptionsPlugin @@ -42,43 +42,43 @@ extern "C" { #include } -#include - -static volatile float f; + #include TEST_GROUP(FE_Demo) { - void setup() + void setup() CPPUTEST_OVERRIDE { IEEE754ExceptionsPlugin::disableInexact(); } }; -IGNORE_TEST(FE_Demo, should_fail_when__FE_DIVBYZERO__is_set) +IGNORE_TEST(FE_Demo, should_fail_when_FE_DIVBYZERO_is_set) { - f = 1.0f; + float f = 1.0f; CHECK((f /= 0.0f) >= std::numeric_limits::infinity()); } -IGNORE_TEST(FE_Demo, should_fail_when__FE_UNDERFLOW__is_set) +IGNORE_TEST(FE_Demo, should_fail_when_FE_UNDERFLOW_is_set) { - f = 0.01f; - while (f > 0.0f) f *= f; + volatile float f = 0.01f; + while (f > 0.0f) + f = f * f; CHECK(f == 0.0f); } -IGNORE_TEST(FE_Demo, should_fail_when__FE_OVERFLOW__is_set) +IGNORE_TEST(FE_Demo, should_fail_when_FE_OVERFLOW_is_set) { - f = 1000.0f; - while (f < std::numeric_limits::infinity()) f *= f; + volatile float f = 1000.0f; + while (f < std::numeric_limits::infinity()) + f = f * f; CHECK(f >= std::numeric_limits::infinity()); } -IGNORE_TEST(FE_Demo, should_fail_when__FE_INEXACT____is_set) +IGNORE_TEST(FE_Demo, should_fail_when_FE_INEXACT_is_set) { IEEE754ExceptionsPlugin::enableInexact(); - f = 10.0f; - DOUBLES_EQUAL((double) (f / 3.0f), (double) 3.333f, (double) 0.001f); + float f = 10.0f; + DOUBLES_EQUAL((double)(f / 3.0f), (double)3.333f, (double)0.001f); } TEST(FE_Demo, should_succeed_when_no_flags_are_set) diff --git a/examples/AllTests/HelloTest.cpp b/examples/AllTests/HelloTest.cpp index 84407906d..7bc644e0e 100644 --- a/examples/AllTests/HelloTest.cpp +++ b/examples/AllTests/HelloTest.cpp @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -34,23 +34,24 @@ static SimpleString* buffer; TEST_GROUP(HelloWorld) -{ static int output_method(const char* output, ...) { - va_list arguments; - va_start(arguments, output); - *buffer = VStringFromFormat(output, arguments); - va_end(arguments); - return 1; -} -void setup() -{ - buffer = new SimpleString(); - UT_PTR_SET(PrintFormated, &output_method); -} -void teardown() -{ - delete buffer; -} + static int output_method(const char* output, ...) + { + va_list arguments; + va_start(arguments, output); + *buffer = VStringFromFormat(output, arguments); + va_end(arguments); + return 1; + } + void setup() CPPUTEST_OVERRIDE + { + buffer = new SimpleString(); + UT_PTR_SET(PrintFormated, &output_method); + } + void teardown() CPPUTEST_OVERRIDE + { + delete buffer; + } }; TEST(HelloWorld, PrintOk) diff --git a/examples/AllTests/MockDocumentationTest.cpp b/examples/AllTests/MockDocumentationTest.cpp index e2b79d726..0bd578ea8 100644 --- a/examples/AllTests/MockDocumentationTest.cpp +++ b/examples/AllTests/MockDocumentationTest.cpp @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -25,7 +25,6 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include "CppUTest/TestHarness.h" #include "CppUTestExt/MockSupport.h" #include "CppUTestExt/MockSupport_c.h" @@ -36,15 +35,14 @@ TEST_GROUP(FirstTestGroup) TEST(FirstTestGroup, FirsTest) { -// FAIL("Fail me!"); + // FAIL("Fail me!"); } TEST(FirstTestGroup, SecondTest) { -// STRCMP_EQUAL("hello", "world"); + // STRCMP_EQUAL("hello", "world"); } - TEST_GROUP(MockDocumentation) { }; @@ -64,14 +62,14 @@ TEST(MockDocumentation, SimpleScenario) class ClassFromProductionCode { public: - virtual void importantFunction(){} + virtual void importantFunction() {} virtual ~ClassFromProductionCode() {} }; class ClassFromProductionCodeMock : public ClassFromProductionCode { public: - virtual void importantFunction() + virtual void importantFunction() CPPUTEST_OVERRIDE { mock().actualCall("importantFunction").onObject(this); } @@ -90,13 +88,13 @@ TEST(MockDocumentation, SimpleScenarioObject) static void parameters_function(int p1, const char* p2) { - void* object = (void*) 1; + void* object = (void*)1; mock().actualCall("function").onObject(object).withParameter("p1", p1).withParameter("p2", p2); } TEST(MockDocumentation, parameters) { - void* object = (void*) 1; + void* object = (void*)1; mock().expectOneCall("function").onObject(object).withParameter("p1", 2).withParameter("p2", "hah"); parameters_function(2, "hah"); } @@ -104,11 +102,11 @@ TEST(MockDocumentation, parameters) class MyTypeComparator : public MockNamedValueComparator { public: - virtual bool isEqual(const void* object1, const void* object2) + virtual bool isEqual(const void* object1, const void* object2) CPPUTEST_OVERRIDE { return object1 == object2; } - virtual SimpleString valueToString(const void* object) + virtual SimpleString valueToString(const void* object) CPPUTEST_OVERRIDE { return StringFrom(object); } @@ -116,7 +114,7 @@ class MyTypeComparator : public MockNamedValueComparator TEST(MockDocumentation, ObjectParameters) { - void* object = (void*) 1; + void* object = (void*)1; MyTypeComparator comparator; mock().installComparator("myType", comparator); mock().expectOneCall("function").withParameterOfType("myType", "parameterName", object); @@ -127,8 +125,8 @@ TEST(MockDocumentation, ObjectParameters) TEST(MockDocumentation, returnValue) { mock().expectOneCall("function").andReturnValue(10); - int value = mock().actualCall("function").returnValue().getIntValue(); - value = mock().returnValue().getIntValue(); + mock().actualCall("function").returnValue().getIntValue(); + int value = mock().returnValue().getIntValue(); LONGS_EQUAL(10, value); } @@ -138,22 +136,20 @@ TEST(MockDocumentation, setData) mock().setData("importantValue", 10); mock().setDataObject("importantObject", "ClassFromProductionCode", &object); - ClassFromProductionCode * pobject; + ClassFromProductionCode* pobject; int value = mock().getData("importantValue").getIntValue(); - pobject = (ClassFromProductionCode*) mock().getData("importantObject").getObjectPointer(); + pobject = (ClassFromProductionCode*)mock().getData("importantObject").getObjectPointer(); LONGS_EQUAL(10, value); POINTERS_EQUAL(pobject, &object); } -static void doSomethingThatWouldOtherwiseBlowUpTheMockingFramework() -{ -} +static void doSomethingThatWouldOtherwiseBlowUpTheMockingFramework() {} TEST(MockDocumentation, otherMockSupport) { mock().crashOnFailure(); -// mock().actualCall("unex"); + // mock().actualCall("unex"); mock().expectOneCall("foo"); mock().ignoreOtherCalls(); @@ -163,7 +159,6 @@ TEST(MockDocumentation, otherMockSupport) mock().enable(); mock().clear(); - } TEST(MockDocumentation, scope) @@ -174,7 +169,7 @@ TEST(MockDocumentation, scope) mock("xmlparser").actualCall("open"); } -static int equalMethod(const void* object1, const void* object2) +static int equalMethod(const void* object1, const void* object2) { return object1 == object2; } @@ -186,13 +181,12 @@ static const char* toStringMethod(const void*) TEST(MockDocumentation, CInterface) { - void* object = (void*) 0x1; + void* object = (void*)0x1; mock_c()->expectOneCall("foo")->withIntParameters("integer", 10)->andReturnDoubleValue(1.11); double d = mock_c()->actualCall("foo")->withIntParameters("integer", 10)->returnValue().value.doubleValue; DOUBLES_EQUAL(1.11, d, 0.00001); - mock_c()->installComparator("type", equalMethod, toStringMethod); mock_scope_c("scope")->expectOneCall("bar")->withParameterOfType("type", "name", object); mock_scope_c("scope")->actualCall("bar")->withParameterOfType("type", "name", object); @@ -205,12 +199,12 @@ TEST(MockDocumentation, CInterface) TEST_GROUP(FooTestGroup) { - void setup() + void setup() CPPUTEST_OVERRIDE { // Init stuff } - void teardown() + void teardown() CPPUTEST_OVERRIDE { // Uninit stuff } @@ -228,7 +222,7 @@ TEST(FooTestGroup, MoreFoo) TEST_GROUP(BarTestGroup) { - void setup() + void setup() CPPUTEST_OVERRIDE { // Init Bar } diff --git a/examples/AllTests/MockPrinter.h b/examples/AllTests/MockPrinter.h index 90dd435d5..1df48962f 100644 --- a/examples/AllTests/MockPrinter.h +++ b/examples/AllTests/MockPrinter.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -40,22 +40,18 @@ #include #include -class MockPrinter: public Printer +class MockPrinter : public Printer { public: - explicit MockPrinter() - { - } - virtual ~MockPrinter() - { - } + explicit MockPrinter() {} + virtual ~MockPrinter() CPPUTEST_DESTRUCTOR_OVERRIDE {} - virtual void Print(const char* s) + virtual void Print(const char* s) CPPUTEST_OVERRIDE { savedOutput.append(s); } - virtual void Print(long int value) + virtual void Print(long int value) CPPUTEST_OVERRIDE { SimpleString buffer; buffer = StringFromFormat("%ld", value); @@ -68,12 +64,10 @@ class MockPrinter: public Printer } private: - std::string savedOutput; MockPrinter(const MockPrinter&); MockPrinter& operator=(const MockPrinter&); - }; -#endif // D_MockPrinter_H +#endif // D_MockPrinter_H diff --git a/examples/AllTests/PrinterTest.cpp b/examples/AllTests/PrinterTest.cpp index 1f872597a..88a5d1ca3 100644 --- a/examples/AllTests/PrinterTest.cpp +++ b/examples/AllTests/PrinterTest.cpp @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -30,18 +30,19 @@ #include "MockPrinter.h" TEST_GROUP(Printer) -{ Printer* printer; -MockPrinter* mockPrinter; - -void setup() -{ - mockPrinter = new MockPrinter(); - printer = mockPrinter; -} -void teardown() { - delete printer; -} + Printer* printer; + MockPrinter* mockPrinter; + + void setup() CPPUTEST_OVERRIDE + { + mockPrinter = new MockPrinter(); + printer = mockPrinter; + } + void teardown() CPPUTEST_OVERRIDE + { + delete printer; + } }; TEST(Printer, PrintConstCharStar) @@ -65,4 +66,3 @@ TEST(Printer, StreamOperators) const char* expected = "n=1234"; CHECK_EQUAL(expected, mockPrinter->getOutput()); } - diff --git a/examples/ApplicationLib/ApplicationLib.vcproj b/examples/ApplicationLib/ApplicationLib.vcproj index bf83e4718..f7b054bbe 100644 --- a/examples/ApplicationLib/ApplicationLib.vcproj +++ b/examples/ApplicationLib/ApplicationLib.vcproj @@ -42,7 +42,7 @@ BE LIABLE FOR ANY @@ -29,10 +29,9 @@ #include "Printer.h" #include -CircularBuffer::CircularBuffer(int _capacity) : - index(0), outdex(0), capacity(_capacity), empty(true), full(false) +CircularBuffer::CircularBuffer(int _capacity) : index(0), outdex(0), capacity(_capacity), empty(true), full(false) { - buffer = new int[(size_t) this->capacity]; + buffer = new int[(size_t)this->capacity]; } CircularBuffer::~CircularBuffer() @@ -55,8 +54,10 @@ void CircularBuffer::Put(int i) empty = false; buffer[index] = i; index = Next(index); - if (full) outdex = Next(outdex); - else if (index == outdex) full = true; + if (full) + outdex = Next(outdex); + else if (index == outdex) + full = true; } int CircularBuffer::Get() @@ -67,7 +68,8 @@ int CircularBuffer::Get() if (!empty) { result = buffer[outdex]; outdex = Next(outdex); - if (outdex == index) empty = true; + if (outdex == index) + empty = true; } return result; } @@ -79,7 +81,8 @@ int CircularBuffer::Capacity() int CircularBuffer::Next(int i) { - if (++i >= capacity) i = 0; + if (++i >= capacity) + i = 0; return i; } @@ -90,12 +93,14 @@ void CircularBuffer::Print(Printer* p) int printIndex = outdex; int count = index - outdex; - if (!empty && (index <= outdex)) count = capacity - (outdex - index); + if (!empty && (index <= outdex)) + count = capacity - (outdex - index); for (int i = 0; i < count; i++) { p->Print(buffer[printIndex]); printIndex = Next(printIndex); - if (i + 1 != count) p->Print(", "); + if (i + 1 != count) + p->Print(", "); } p->Print(">\n"); } diff --git a/examples/ApplicationLib/CircularBuffer.h b/examples/ApplicationLib/CircularBuffer.h index e804c29ba..e9634f10a 100644 --- a/examples/ApplicationLib/CircularBuffer.h +++ b/examples/ApplicationLib/CircularBuffer.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -52,7 +52,6 @@ class CircularBuffer void Print(Printer*); private: - int index; int outdex; int* buffer; @@ -66,7 +65,6 @@ class CircularBuffer CircularBuffer(const CircularBuffer&); CircularBuffer& operator=(const CircularBuffer&); - }; -#endif // D_CircularBuffer_H +#endif // D_CircularBuffer_H diff --git a/examples/ApplicationLib/EventDispatcher.cpp b/examples/ApplicationLib/EventDispatcher.cpp index ef5ebbcba..140be3547 100644 --- a/examples/ApplicationLib/EventDispatcher.cpp +++ b/examples/ApplicationLib/EventDispatcher.cpp @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -28,9 +28,7 @@ #include "EventDispatcher.h" using namespace std; -EventDispatcher::EventDispatcher() -{ -} +EventDispatcher::EventDispatcher() {} void EventDispatcher::registerObserver(EventType type, EventObserver* observer) { @@ -42,8 +40,7 @@ void EventDispatcher::registerObserver(EventType type, EventObserver* observer) void EventDispatcher::dispatchEvent(const Event& event, int timeoutSeconds) { - for (list >::iterator i = observerList_.begin(); i != observerList_.end(); i++) - { + for (list >::iterator i = observerList_.begin(); i != observerList_.end(); i++) { if (i->first == event.type) i->second->notify(event, timeoutSeconds); } diff --git a/examples/ApplicationLib/EventDispatcher.h b/examples/ApplicationLib/EventDispatcher.h index 06e2c687c..a27eb056f 100644 --- a/examples/ApplicationLib/EventDispatcher.h +++ b/examples/ApplicationLib/EventDispatcher.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -25,8 +25,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EVENTDISPATCHER__H -#define EVENTDISPATCHER__H +#ifndef EVENTDISPATCHER_H +#define EVENTDISPATCHER_H #include @@ -45,14 +45,15 @@ class Event class EventObserver { public: - virtual void notify(const Event& event, int timeOutInSeconds)=0; - virtual void notifyRegistration(EventObserver* newObserver)=0; + virtual void notify(const Event& event, int timeOutInSeconds) = 0; + virtual void notifyRegistration(EventObserver* newObserver) = 0; virtual ~EventObserver() {} }; class EventDispatcher { std::list > observerList_; + public: EventDispatcher(); diff --git a/examples/ApplicationLib/ExamplesNewOverrides.h b/examples/ApplicationLib/ExamplesNewOverrides.h index ad108fc7a..86cb0219b 100644 --- a/examples/ApplicationLib/ExamplesNewOverrides.h +++ b/examples/ApplicationLib/ExamplesNewOverrides.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY diff --git a/examples/ApplicationLib/Printer.cpp b/examples/ApplicationLib/Printer.cpp index af9c9266d..893ae1a40 100644 --- a/examples/ApplicationLib/Printer.cpp +++ b/examples/ApplicationLib/Printer.cpp @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -28,13 +28,9 @@ #include "Printer.h" #include -Printer::Printer() -{ -} +Printer::Printer() {} -Printer::~Printer() -{ -} +Printer::~Printer() {} void Printer::Print(const char* s) { @@ -44,7 +40,7 @@ void Printer::Print(const char* s) void Printer::Print(long int n) { - printf("%ld", n); + printf("%ld", n); } Printer& operator<<(Printer& p, const char* s) diff --git a/examples/ApplicationLib/Printer.h b/examples/ApplicationLib/Printer.h index dcfc59ccd..51aa63313 100644 --- a/examples/ApplicationLib/Printer.h +++ b/examples/ApplicationLib/Printer.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -44,13 +44,11 @@ class Printer virtual void Print(long int); private: - Printer(const Printer&); Printer& operator=(const Printer&); - }; Printer& operator<<(Printer&, const char*); Printer& operator<<(Printer&, long int); -#endif // D_Printer_H +#endif // D_Printer_H diff --git a/examples/ApplicationLib/hello.c b/examples/ApplicationLib/hello.c index 6cbe03f44..2ab67a69c 100644 --- a/examples/ApplicationLib/hello.c +++ b/examples/ApplicationLib/hello.c @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -28,7 +28,7 @@ #include #include "hello.h" -void printHelloWorld() +void printHelloWorld(void) { PrintFormated("Hello World!\n"); } diff --git a/examples/ApplicationLib/hello.h b/examples/ApplicationLib/hello.h index 5154b3cf1..83524a5c0 100644 --- a/examples/ApplicationLib/hello.h +++ b/examples/ApplicationLib/hello.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index d4b547439..98244cee6 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,2 +1,20 @@ +cmake_minimum_required(VERSION 3.8...3.31) + +project(CppUTestExample) + +if (CMAKE_VERSION GREATER_EQUAL "3.21") + # PROJECT_IS_TOP_LEVEL is defined automatically +elseif(CMAKE_CURRENT_BINARY_DIR STREQUAL CMAKE_BINARY_DIR) + set(PROJECT_IS_TOP_LEVEL TRUE) +else() + set(PROJECT_IS_TOP_LEVEL FALSE) +endif() + +if(PROJECT_IS_TOP_LEVEL) + find_package(CppUTest 4.0 REQUIRED) +endif() + +include(CTest) + add_subdirectory(AllTests) add_subdirectory(ApplicationLib) diff --git a/include/CppUTest/CommandLineArguments.h b/include/CppUTest/CommandLineArguments.h index afd134047..d162a5e2f 100644 --- a/include/CppUTest/CommandLineArguments.h +++ b/include/CppUTest/CommandLineArguments.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -47,10 +47,13 @@ class CommandLineArguments bool isColor() const; bool isListingTestGroupNames() const; bool isListingTestGroupAndCaseNames() const; + bool isListingTestLocations() const; bool isRunIgnored() const; size_t getRepeatCount() const; bool isShuffling() const; bool isReversing() const; + bool isCrashingOnFail() const; + bool isRethrowingExceptions() const; size_t getShuffleSeed() const; const TestFilter* getGroupFilters() const; const TestFilter* getNameFilters() const; @@ -79,8 +82,11 @@ class CommandLineArguments bool runTestsAsSeperateProcess_; bool listTestGroupNames_; bool listTestGroupAndCaseNames_; + bool listTestLocations_; bool runIgnored_; bool reversing_; + bool crashOnFail_; + bool rethrowExceptions_; bool shuffling_; bool shufflingPreSeeded_; size_t repeat_; @@ -94,7 +100,7 @@ class CommandLineArguments void setRepeatCount(int ac, const char *const *av, int& index); bool setShuffle(int ac, const char *const *av, int& index); void addGroupFilter(int ac, const char *const *av, int& index); - bool addGroupDotNameFilter(int ac, const char *const *av, int& index); + bool addGroupDotNameFilter(int ac, const char *const *av, int& index, const SimpleString& parameterName, bool strict, bool exclude); void addStrictGroupFilter(int ac, const char *const *av, int& index); void addExcludeGroupFilter(int ac, const char *const *av, int& index); void addExcludeStrictGroupFilter(int ac, const char *const *av, int& index); diff --git a/include/CppUTest/CommandLineTestRunner.h b/include/CppUTest/CommandLineTestRunner.h index 194cd4cb2..91c52d177 100644 --- a/include/CppUTest/CommandLineTestRunner.h +++ b/include/CppUTest/CommandLineTestRunner.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY diff --git a/include/CppUTest/CppUTestConfig.h b/include/CppUTest/CppUTestConfig.h index 7c7371fe3..435ea74d2 100644 --- a/include/CppUTest/CppUTestConfig.h +++ b/include/CppUTest/CppUTestConfig.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -29,7 +29,17 @@ #define CPPUTESTCONFIG_H_ #ifndef CPPUTEST_USE_OWN_CONFIGURATION -#include "CppUTestGeneratedConfig.h" + // The autotools generated header uses reserved names in macros + #ifdef __clang__ + #pragma clang diagnostic push + #if __clang_major__ >= 13 + #pragma clang diagnostic ignored "-Wreserved-identifier" + #endif + #endif + #include "CppUTestGeneratedConfig.h" + #ifdef __clang__ + #pragma clang diagnostic pop + #endif #endif /* @@ -40,13 +50,6 @@ * */ -#ifdef __clang__ - #pragma clang diagnostic push - #if (__clang_major__ == 3 && __clang_minor__ >= 6) || __clang_major__ >= 4 - #pragma clang diagnostic ignored "-Wreserved-id-macro" - #endif -#endif - /* * Lib C dependencies that are currently still left: * @@ -94,56 +97,35 @@ /* Should be the only #include here. Standard C library wrappers */ #include "StandardCLibrary.h" -/* Create a _no_return_ macro, which is used to flag a function as not returning. +/* Create a CPPUTEST_NORETURN macro, which is used to flag a function as not returning. * Used for functions that always throws for instance. * * This is needed for compiling with clang, without breaking other compilers. */ #ifndef __has_attribute - #define __has_attribute(x) 0 -#endif - -#if __has_attribute(noreturn) - #define _no_return_ __attribute__((noreturn)) + #define CPPUTEST_HAS_ATTRIBUTE(x) 0 #else - #define _no_return_ + #define CPPUTEST_HAS_ATTRIBUTE(x) __has_attribute(x) #endif -#if __has_attribute(format) - #define _check_format_(type, format_parameter, other_parameters) __attribute__ ((format (type, format_parameter, other_parameters))) +#if defined (__cplusplus) && __cplusplus >= 201103L + #define CPPUTEST_NORETURN [[noreturn]] +#elif CPPUTEST_HAS_ATTRIBUTE(noreturn) + #define CPPUTEST_NORETURN __attribute__((noreturn)) #else - #define _check_format_(type, format_parameter, other_parameters) /* type, format_parameter, other_parameters */ + #define CPPUTEST_NORETURN #endif -/* - * When we don't link Standard C++, then we won't throw exceptions as we assume the compiler might not support that! - */ - -#if CPPUTEST_USE_STD_CPP_LIB - #if defined(__cplusplus) && __cplusplus >= 201103L - #define UT_THROW(exception) - #define UT_NOTHROW noexcept - #else - #define UT_THROW(exception) throw (exception) - #define UT_NOTHROW throw() - #endif +#if defined(__MINGW32__) +#define CPPUTEST_CHECK_FORMAT_TYPE __MINGW_PRINTF_FORMAT #else - #define UT_THROW(exception) - #ifdef __clang__ - #define UT_NOTHROW throw() - #else - #define UT_NOTHROW - #endif +#define CPPUTEST_CHECK_FORMAT_TYPE printf #endif -/* - * Visual C++ doesn't define __cplusplus as C++11 yet (201103), however it doesn't want the throw(exception) either, but - * it does want throw(). - */ - -#ifdef _MSC_VER - #undef UT_THROW - #define UT_THROW(exception) +#if CPPUTEST_HAS_ATTRIBUTE(format) + #define CPPUTEST_CHECK_FORMAT(type, format_parameter, other_parameters) __attribute__ ((format (type, format_parameter, other_parameters))) +#else + #define CPPUTEST_CHECK_FORMAT(type, format_parameter, other_parameters) /* type, format_parameter, other_parameters */ #endif #if defined(__cplusplus) && __cplusplus >= 201103L @@ -152,69 +134,124 @@ #define DEFAULT_COPY_CONSTRUCTOR(classname) #endif -/* - * g++-4.7 with stdc++11 enabled On MacOSX! will have a different exception specifier for operator new (and thank you!) - * I assume they'll fix this in the future, but for now, we'll change that here. - * (This should perhaps also be done in the configure.ac) - */ - -#ifdef __GXX_EXPERIMENTAL_CXX0X__ -#ifdef __APPLE__ -#ifdef _GLIBCXX_THROW -#undef UT_THROW -#define UT_THROW(exception) _GLIBCXX_THROW(exception) -#endif -#endif -#endif - /* * Address sanitizer is a good thing... and it causes some conflicts with the CppUTest tests * To check whether it is on or off, we create a CppUTest define here. */ #if defined(__has_feature) -#if __has_feature(address_sanitizer) -#define CPPUTEST_SANITIZE_ADDRESS 1 -#endif -#endif - -#ifdef __SANITIZE_ADDRESS__ -#define CPPUTEST_SANITIZE_ADDRESS 1 + #if __has_feature(address_sanitizer) + #define CPPUTEST_SANITIZE_ADDRESS 1 + #endif +#elif defined(__SANITIZE_ADDRESS__) + #define CPPUTEST_SANITIZE_ADDRESS 1 #endif #ifndef CPPUTEST_SANITIZE_ADDRESS -#define CPPUTEST_SANITIZE_ADDRESS 0 + #define CPPUTEST_SANITIZE_ADDRESS 0 #endif #if CPPUTEST_SANITIZE_ADDRESS -#define CPPUTEST_SANITIZE_ADDRESS 1 -#define CPPUTEST_DO_NOT_SANITIZE_ADDRESS __attribute__((no_sanitize_address)) - #if defined(__linux__) && defined(__clang__) - #if CPPUTEST_USE_MEM_LEAK_DETECTION - #warning Compiling with Address Sanitizer with clang on linux will cause duplicate symbols for operator new. Turning off memory leak detection. Compile with -DCPPUTEST_MEM_LEAK_DETECTION_DISABLED to get rid of this warning. - #undef CPPUTEST_USE_MEM_LEAK_DETECTION - #define CPPUTEST_USE_MEM_LEAK_DETECTION 0 - #endif + #if defined(__linux__) && defined(__clang__) && CPPUTEST_USE_STD_CPP_LIB && CPPUTEST_USE_MEM_LEAK_DETECTION + #warning Compiling with Address Sanitizer with clang on linux may cause duplicate symbols for operator new. Turning off memory leak detection. Compile with -DCPPUTEST_MEM_LEAK_DETECTION_DISABLED to get rid of this warning. #endif + #define CPPUTEST_DO_NOT_SANITIZE_ADDRESS __attribute__((no_sanitize_address)) #else -#define CPPUTEST_SANITIZER_ADDRESS 0 -#define CPPUTEST_DO_NOT_SANITIZE_ADDRESS + #define CPPUTEST_DO_NOT_SANITIZE_ADDRESS #endif /* - * Handling of IEEE754 floating point exceptions via fenv.h + * Handling of IEEE754 (IEC559) floating point exceptions via fenv.h * Predominantly works on non-Visual C++ compilers and Visual C++ 2008 and newer */ - -#if CPPUTEST_USE_STD_C_LIB && \ - (!defined(_MSC_VER) || (_MSC_VER >= 1800)) && \ - (!defined(__APPLE__)) && \ - (!defined(__ghs__) || !defined(__ColdFire__)) -#define CPPUTEST_HAVE_FENV -#if defined(__WATCOMC__) || defined(__ARMEL__) || defined(__m68k__) -#define CPPUTEST_FENV_IS_WORKING_PROPERLY 0 -#else -#define CPPUTEST_FENV_IS_WORKING_PROPERLY 1 +#ifndef CPPUTEST_HAVE_FENV + #if (defined(__STDC_IEC_559__) && __STDC_IEC_559__) && CPPUTEST_USE_STD_C_LIB + #define CPPUTEST_HAVE_FENV 1 + #else + #define CPPUTEST_HAVE_FENV 0 + #endif #endif + +#ifdef __cplusplus + /* + * Detection of run-time type information (RTTI) presence. Since it's a + * standard language feature, assume it is enabled unless we see otherwise. + */ + #ifndef CPPUTEST_HAVE_RTTI + #if ((__cplusplus >= 202002L) && !__cpp_rtti) || \ + (defined(_MSC_VER) && !_CPPRTTI) || \ + (defined(__GNUC__) && !__GXX_RTTI) || \ + (defined(__ghs__) && !__RTTI) || \ + (defined(__WATCOMC__) && !_CPPRTTI) + #define CPPUTEST_HAVE_RTTI 0 + #else + #define CPPUTEST_HAVE_RTTI 1 + #endif + #endif + + /* + * Detection of exception support. Since it's a standard language feature, + * assume it is enabled unless we see otherwise. + */ + #ifndef CPPUTEST_HAVE_EXCEPTIONS + #if ((__cplusplus >= 202002L) && !__cpp_exceptions) || \ + (defined(_MSC_VER) && !_CPPUNWIND) || \ + (defined(__GNUC__) && !__EXCEPTIONS) || \ + (defined(__ghs__) && !__EXCEPTION_HANDLING) || \ + (defined(__WATCOMC__) && !_CPPUNWIND) + #define CPPUTEST_HAVE_EXCEPTIONS 0 + #else + #define CPPUTEST_HAVE_EXCEPTIONS 1 + #endif + #endif + + #if CPPUTEST_HAVE_EXCEPTIONS + #if defined(__cplusplus) && __cplusplus >= 201103L + #define UT_THROW(exception) + #define UT_NOTHROW noexcept + #else + #define UT_THROW(exception) throw (exception) + #define UT_NOTHROW throw() + #endif + #else + #define UT_THROW(exception) + #if defined(__clang__) || defined(__GNUC__) + #if defined(__cplusplus) && __cplusplus >= 201103L + #define UT_NOTHROW noexcept + #else + #define UT_NOTHROW throw() + #endif + #else + #define UT_NOTHROW + #endif + #endif + + /* + * Visual C++ doesn't define __cplusplus as C++11 yet (201103), however it doesn't want the throw(exception) either, but + * it does want throw(). + */ + #ifdef _MSC_VER + #undef UT_THROW + #define UT_THROW(exception) + #endif + + /* + * g++-4.7 with stdc++11 enabled On MacOSX! will have a different exception specifier for operator new (and thank you!) + * I assume they'll fix this in the future, but for now, we'll change that here. + * (This should perhaps also be done in the configure.ac) + */ + #if defined(__GXX_EXPERIMENTAL_CXX0X__) && \ + defined(__APPLE__) && \ + defined(_GLIBCXX_THROW) + #undef UT_THROW + #define UT_THROW(exception) _GLIBCXX_THROW(exception) + #endif + + #if CPPUTEST_USE_STD_CPP_LIB + #define CPPUTEST_BAD_ALLOC std::bad_alloc + #else + class CppUTestBadAlloc {}; + #define CPPUTEST_BAD_ALLOC CppUTestBadAlloc + #endif #endif /* @@ -228,13 +265,16 @@ #endif #endif -/* Handling of systems with a different byte-width (e.g. 16 bit). - * Since CHAR_BIT is defined in limits.h (ANSI C), use default of 8 when building without Std C library. +/* Handling of systems with a different byte-width (e.g. 16 bit). Since + * CHAR_BIT is defined in limits.h (ANSI C), the user must provide a definition + * when building without Std C library. */ -#if CPPUTEST_USE_STD_C_LIB -#define CPPUTEST_CHAR_BIT CHAR_BIT -#else -#define CPPUTEST_CHAR_BIT 8 +#ifndef CPPUTEST_CHAR_BIT + #if defined(CHAR_BIT) + #define CPPUTEST_CHAR_BIT CHAR_BIT + #else + #error "Provide a definition for CPPUTEST_CHAR_BIT" + #endif #endif /* Handling of systems with a different int-width (e.g. 16 bit). @@ -249,18 +289,19 @@ * Not supported when CPPUTEST_LONG_LONG_DISABLED is set. * Can be overridden by using CPPUTEST_USE_LONG_LONG * - * CPPUTEST_HAVE_LONG_LONG_INT is set by configure + * CPPUTEST_HAVE_LONG_LONG_INT is set by configure or CMake. * LLONG_MAX is set in limits.h. This is a crude attempt to detect long long support when no configure is used * */ - -#if !defined(CPPUTEST_LONG_LONG_DISABLED) && !defined(CPPUTEST_USE_LONG_LONG) -#if defined(CPPUTEST_HAVE_LONG_LONG_INT) || defined(LLONG_MAX) +#ifndef CPPUTEST_USE_LONG_LONG +#if !defined(CPPUTEST_LONG_LONG_DISABLED) && (defined(CPPUTEST_HAVE_LONG_LONG_INT) || defined(LLONG_MAX)) #define CPPUTEST_USE_LONG_LONG 1 +#else +#define CPPUTEST_USE_LONG_LONG 0 #endif #endif -#ifdef CPPUTEST_USE_LONG_LONG +#if CPPUTEST_USE_LONG_LONG typedef long long cpputest_longlong; typedef unsigned long long cpputest_ulonglong; #else @@ -274,59 +315,44 @@ typedef unsigned long long cpputest_ulonglong; #define CPPUTEST_SIZE_OF_FAKE_LONG_LONG_TYPE 8 #endif -struct cpputest_longlong -{ #if defined(__cplusplus) - cpputest_longlong() {} - cpputest_longlong(int) {} +extern "C" { #endif + +typedef struct +{ char dummy[CPPUTEST_SIZE_OF_FAKE_LONG_LONG_TYPE]; -}; +} cpputest_longlong; -struct cpputest_ulonglong +typedef struct { -#if defined(__cplusplus) - cpputest_ulonglong() {} - cpputest_ulonglong(int) {} -#endif char dummy[CPPUTEST_SIZE_OF_FAKE_LONG_LONG_TYPE]; -}; +} cpputest_ulonglong; -#if !defined(__cplusplus) -typedef struct cpputest_longlong cpputest_longlong; -typedef struct cpputest_ulonglong cpputest_ulonglong; +#if defined(__cplusplus) +} /* extern "C" */ #endif #endif -/* Visual C++ 10.0+ (2010+) supports the override keyword, but doesn't define the C++ version as C++11 */ -#if defined(__cplusplus) && ((__cplusplus >= 201103L) || (defined(_MSC_VER) && (_MSC_VER >= 1600))) -#if !defined(__ghs__) -#define CPPUTEST_COMPILER_FULLY_SUPPORTS_CXX11 -#define _override override -#else -/* GreenHills is not compatible with other compilers with regards to where - * it expects the override specifier to be on methods that return function - * pointers. Given this, it is easiest to not use the override specifier. - */ -#define _override -#endif -#define NULLPTR nullptr -#else -#define _override -#define NULLPTR NULL -#endif - -/* Visual C++ 11.0+ (2012+) supports the override keyword on destructors */ -#if defined(__cplusplus) && ((__cplusplus >= 201103L) || (defined(_MSC_VER) && (_MSC_VER >= 1700))) -#define _destructor_override override -#else -#define _destructor_override +#ifdef __cplusplus + /* Visual C++ 10.0+ (2010+) supports the override keyword, but doesn't define the C++ version as C++11 */ + #if (__cplusplus >= 201103L) || (defined(_MSC_VER) && (_MSC_VER >= 1600)) + #define CPPUTEST_OVERRIDE override + #define NULLPTR nullptr + #else + #define CPPUTEST_OVERRIDE + #define NULLPTR NULL + #endif #endif -#ifdef __clang__ - #pragma clang diagnostic pop +#ifdef __cplusplus + /* Visual C++ 11.0+ (2012+) supports the override keyword on destructors */ + #if (__cplusplus >= 201103L) || (defined(_MSC_VER) && (_MSC_VER >= 1700)) + #define CPPUTEST_DESTRUCTOR_OVERRIDE override + #else + #define CPPUTEST_DESTRUCTOR_OVERRIDE + #endif #endif - #endif diff --git a/include/CppUTest/CppUTestGeneratedConfig.h b/include/CppUTest/CppUTestGeneratedConfig.h index 94e293f9c..5bcd53768 100644 --- a/include/CppUTest/CppUTestGeneratedConfig.h +++ b/include/CppUTest/CppUTestGeneratedConfig.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY diff --git a/include/CppUTest/JUnitTestOutput.h b/include/CppUTest/JUnitTestOutput.h index 1c4a0b0eb..5e5746f56 100644 --- a/include/CppUTest/JUnitTestOutput.h +++ b/include/CppUTest/JUnitTestOutput.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -38,22 +38,22 @@ class JUnitTestOutput: public TestOutput { public: JUnitTestOutput(); - virtual ~JUnitTestOutput() _destructor_override; + virtual ~JUnitTestOutput() CPPUTEST_DESTRUCTOR_OVERRIDE; - virtual void printTestsStarted() _override; - virtual void printTestsEnded(const TestResult& result) _override; - virtual void printCurrentTestStarted(const UtestShell& test) _override; - virtual void printCurrentTestEnded(const TestResult& res) _override; - virtual void printCurrentGroupStarted(const UtestShell& test) _override; - virtual void printCurrentGroupEnded(const TestResult& res) _override; + virtual void printTestsStarted() CPPUTEST_OVERRIDE; + virtual void printTestsEnded(const TestResult& result) CPPUTEST_OVERRIDE; + virtual void printCurrentTestStarted(const UtestShell& test) CPPUTEST_OVERRIDE; + virtual void printCurrentTestEnded(const TestResult& res) CPPUTEST_OVERRIDE; + virtual void printCurrentGroupStarted(const UtestShell& test) CPPUTEST_OVERRIDE; + virtual void printCurrentGroupEnded(const TestResult& res) CPPUTEST_OVERRIDE; - virtual void printBuffer(const char*) _override; - virtual void print(const char*) _override; - virtual void print(long) _override; - virtual void print(size_t) _override; - virtual void printFailure(const TestFailure& failure) _override; + virtual void printBuffer(const char*) CPPUTEST_OVERRIDE; + virtual void print(const char*) CPPUTEST_OVERRIDE; + virtual void print(long) CPPUTEST_OVERRIDE; + virtual void print(size_t) CPPUTEST_OVERRIDE; + virtual void printFailure(const TestFailure& failure) CPPUTEST_OVERRIDE; - virtual void flush() _override; + virtual void flush() CPPUTEST_OVERRIDE; virtual SimpleString createFileName(const SimpleString& group); void setPackageName(const SimpleString &package); diff --git a/include/CppUTest/MemoryLeakDetector.h b/include/CppUTest/MemoryLeakDetector.h index 4057ca806..195a3384a 100644 --- a/include/CppUTest/MemoryLeakDetector.h +++ b/include/CppUTest/MemoryLeakDetector.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -58,7 +58,7 @@ struct SimpleStringBuffer SimpleStringBuffer(); void clear(); - void add(const char* format, ...) _check_format_(printf, 2, 3); + void add(const char* format, ...) CPPUTEST_CHECK_FORMAT(CPPUTEST_CHECK_FORMAT_TYPE, 2, 3); void addMemoryDump(const void* memory, size_t memorySize); char* toString(); diff --git a/include/CppUTest/MemoryLeakDetectorForceInclude.h b/include/CppUTest/MemoryLeakDetectorForceInclude.h new file mode 100644 index 000000000..6de90e177 --- /dev/null +++ b/include/CppUTest/MemoryLeakDetectorForceInclude.h @@ -0,0 +1,4 @@ +// Not all toolchains support multiple force includes (namely IAR), +// so we wrap the two in a single header. +#include "MemoryLeakDetectorMallocMacros.h" +#include "MemoryLeakDetectorNewMacros.h" diff --git a/include/CppUTest/MemoryLeakDetectorNewMacros.h b/include/CppUTest/MemoryLeakDetectorNewMacros.h index 4f4699cbe..880b89560 100644 --- a/include/CppUTest/MemoryLeakDetectorNewMacros.h +++ b/include/CppUTest/MemoryLeakDetectorNewMacros.h @@ -34,29 +34,38 @@ * Some platforms (OSx, i.e.) will get or included when using header, * in order to avoid conflicts with strdup and strndup macros defined by MemoryLeakDetectorMallocMacros.h * we will undefined those macros, include the C++ headers and then reinclude MemoryLeakDetectorMallocMacros.h. - * The check `#if CPPUTEST_USE_STRDUP_MACROS` will ensure we only include MemoryLeakDetectorMallocMacros.h if + * The check '#if CPPUTEST_USE_STRDUP_MACROS' will ensure we only include MemoryLeakDetectorMallocMacros.h if * it has already been includeded earlier. */ #undef strdup #undef strndup #undef CPPUTEST_USE_STRDUP_MACROS - #define __CPPUTEST_REINCLUDE_MALLOC_MEMORY_LEAK_DETECTOR + #define CPPUTEST_REINCLUDE_MALLOC_MEMORY_LEAK_DETECTOR #endif #endif #include #include #include - #ifdef __CPPUTEST_REINCLUDE_MALLOC_MEMORY_LEAK_DETECTOR + #ifdef CPPUTEST_REINCLUDE_MALLOC_MEMORY_LEAK_DETECTOR #include "MemoryLeakDetectorMallocMacros.h" #endif #endif - void* operator new(size_t size, const char* file, size_t line) UT_THROW (std::bad_alloc); - void* operator new[](size_t size, const char* file, size_t line) UT_THROW (std::bad_alloc); - void* operator new(size_t size) UT_THROW(std::bad_alloc); - void* operator new[](size_t size) UT_THROW(std::bad_alloc); + /* Some toolkits, e.g. MFC, provide their own new overloads with signature (size_t, const char *, int). + * If we don't provide them, in addition to the (size_t, const char *, size_t) version, we don't get to + * know about all allocations and report freeing of unallocated blocks. Hence, provide both overloads. + */ + void* operator new(size_t size, const char* file, int line) UT_THROW (CPPUTEST_BAD_ALLOC); + void* operator new(size_t size, const char* file, size_t line) UT_THROW (CPPUTEST_BAD_ALLOC); + void* operator new[](size_t size, const char* file, int line) UT_THROW (CPPUTEST_BAD_ALLOC); + void* operator new[](size_t size, const char* file, size_t line) UT_THROW (CPPUTEST_BAD_ALLOC); + void* operator new(size_t size) UT_THROW(CPPUTEST_BAD_ALLOC); + void* operator new[](size_t size) UT_THROW(CPPUTEST_BAD_ALLOC); + + void operator delete(void* mem, const char* file, int line) UT_NOTHROW; void operator delete(void* mem, const char* file, size_t line) UT_NOTHROW; + void operator delete[](void* mem, const char* file, int line) UT_NOTHROW; void operator delete[](void* mem, const char* file, size_t line) UT_NOTHROW; void operator delete(void* mem) UT_NOTHROW; void operator delete[](void* mem) UT_NOTHROW; diff --git a/include/CppUTest/MemoryLeakWarningPlugin.h b/include/CppUTest/MemoryLeakWarningPlugin.h index ec3c824d9..01ae95be7 100644 --- a/include/CppUTest/MemoryLeakWarningPlugin.h +++ b/include/CppUTest/MemoryLeakWarningPlugin.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -43,10 +43,10 @@ class MemoryLeakWarningPlugin: public TestPlugin { public: MemoryLeakWarningPlugin(const SimpleString& name, MemoryLeakDetector* localDetector = NULLPTR); - virtual ~MemoryLeakWarningPlugin() _destructor_override; + virtual ~MemoryLeakWarningPlugin() CPPUTEST_DESTRUCTOR_OVERRIDE; - virtual void preTestAction(UtestShell& test, TestResult& result) _override; - virtual void postTestAction(UtestShell& test, TestResult& result) _override; + virtual void preTestAction(UtestShell& test, TestResult& result) CPPUTEST_OVERRIDE; + virtual void postTestAction(UtestShell& test, TestResult& result) CPPUTEST_OVERRIDE; virtual const char* FinalReport(size_t toBeDeletedLeaks = 0); diff --git a/include/CppUTest/PlatformSpecificFunctions.h b/include/CppUTest/PlatformSpecificFunctions.h index 6737f582a..3b2f983cc 100644 --- a/include/CppUTest/PlatformSpecificFunctions.h +++ b/include/CppUTest/PlatformSpecificFunctions.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY diff --git a/include/CppUTest/PlatformSpecificFunctions_c.h b/include/CppUTest/PlatformSpecificFunctions_c.h index b39d88fd3..36700818b 100644 --- a/include/CppUTest/PlatformSpecificFunctions_c.h +++ b/include/CppUTest/PlatformSpecificFunctions_c.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -47,7 +47,7 @@ extern void (*PlatformSpecificLongJmp)(void); extern void (*PlatformSpecificRestoreJumpBuffer)(void); /* Time operations */ -extern long (*GetPlatformSpecificTimeInMillis)(void); +extern unsigned long (*GetPlatformSpecificTimeInMillis)(void); extern const char* (*GetPlatformSpecificTimeString)(void); /* String operations */ @@ -62,11 +62,12 @@ extern int (*PlatformSpecificAtExit)(void(*func)(void)); /* IO operations */ typedef void* PlatformSpecificFile; +extern PlatformSpecificFile PlatformSpecificStdOut; + extern PlatformSpecificFile (*PlatformSpecificFOpen)(const char* filename, const char* flag); extern void (*PlatformSpecificFPuts)(const char* str, PlatformSpecificFile file); extern void (*PlatformSpecificFClose)(PlatformSpecificFile file); -extern int (*PlatformSpecificPutchar)(int c); extern void (*PlatformSpecificFlush)(void); /* Random operations */ @@ -82,9 +83,12 @@ extern void* (*PlatformSpecificMemset)(void* mem, int c, size_t size); typedef void* PlatformSpecificMutex; extern PlatformSpecificMutex (*PlatformSpecificMutexCreate)(void); +extern void (*PlatformSpecificSrand)(unsigned int); +extern int (*PlatformSpecificRand)(void); extern void (*PlatformSpecificMutexLock)(PlatformSpecificMutex mtx); extern void (*PlatformSpecificMutexUnlock)(PlatformSpecificMutex mtx); extern void (*PlatformSpecificMutexDestroy)(PlatformSpecificMutex mtx); +extern void (*PlatformSpecificAbort)(void); #ifdef __cplusplus } diff --git a/include/CppUTest/SimpleMutex.h b/include/CppUTest/SimpleMutex.h index eb4990054..8bb59fb69 100644 --- a/include/CppUTest/SimpleMutex.h +++ b/include/CppUTest/SimpleMutex.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY diff --git a/include/CppUTest/SimpleString.h b/include/CppUTest/SimpleString.h index e56e6947c..63e7684d0 100644 --- a/include/CppUTest/SimpleString.h +++ b/include/CppUTest/SimpleString.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -83,6 +83,8 @@ class SimpleString SimpleString subStringFromTill(char startChar, char lastExcludedChar) const; void copyToBuffer(char* buffer, size_t bufferSize) const; + SimpleString printable() const; + const char *asCharString() const; size_t size() const; bool isEmpty() const; @@ -125,6 +127,10 @@ class SimpleString static bool isDigit(char ch); static bool isSpace(char ch); static bool isUpper(char ch); + static bool isControl(char ch); + static bool isControlWithShortEscapeSequence(char ch); + + size_t getPrintableSize() const; }; class SimpleStringCollection @@ -203,7 +209,7 @@ SimpleString HexStringFrom(const void* value); SimpleString HexStringFrom(void (*value)()); SimpleString StringFrom(double value, int precision = 6); SimpleString StringFrom(const SimpleString& other); -SimpleString StringFromFormat(const char* format, ...) _check_format_(printf, 1, 2); +SimpleString StringFromFormat(const char* format, ...) CPPUTEST_CHECK_FORMAT(CPPUTEST_CHECK_FORMAT_TYPE, 1, 2); SimpleString VStringFromFormat(const char* format, va_list args); SimpleString StringFromBinary(const unsigned char* value, size_t size); SimpleString StringFromBinaryOrNull(const unsigned char* value, size_t size); @@ -219,6 +225,7 @@ SimpleString BracketsFormattedHexStringFrom(cpputest_longlong value); SimpleString BracketsFormattedHexStringFrom(cpputest_ulonglong value); SimpleString BracketsFormattedHexStringFrom(signed char value); SimpleString BracketsFormattedHexString(SimpleString hexString); +SimpleString PrintableStringFromOrNull(const char * expected); /* * ARM compiler has only partial support for C++11. @@ -230,8 +237,6 @@ SimpleString StringFrom(const std::nullptr_t value); #if CPPUTEST_USE_STD_CPP_LIB -#include - SimpleString StringFrom(const std::string& other); #endif diff --git a/include/CppUTest/SimpleStringInternalCache.h b/include/CppUTest/SimpleStringInternalCache.h index 94bfdd808..ebbd30f6b 100644 --- a/include/CppUTest/SimpleStringInternalCache.h +++ b/include/CppUTest/SimpleStringInternalCache.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -79,16 +79,16 @@ class SimpleStringCacheAllocator : public TestMemoryAllocator { public: SimpleStringCacheAllocator(SimpleStringInternalCache& cache, TestMemoryAllocator* previousAllocator); - virtual ~SimpleStringCacheAllocator() _destructor_override; + virtual ~SimpleStringCacheAllocator() CPPUTEST_DESTRUCTOR_OVERRIDE; - virtual char* alloc_memory(size_t size, const char* file, size_t line) _override; - virtual void free_memory(char* memory, size_t size, const char* file, size_t line) _override; + virtual char* alloc_memory(size_t size, const char* file, size_t line) CPPUTEST_OVERRIDE; + virtual void free_memory(char* memory, size_t size, const char* file, size_t line) CPPUTEST_OVERRIDE; - virtual const char* name() const _override; - virtual const char* alloc_name() const _override; - virtual const char* free_name() const _override; + virtual const char* name() const CPPUTEST_OVERRIDE; + virtual const char* alloc_name() const CPPUTEST_OVERRIDE; + virtual const char* free_name() const CPPUTEST_OVERRIDE; - virtual TestMemoryAllocator* actualAllocator() _override; + virtual TestMemoryAllocator* actualAllocator() CPPUTEST_OVERRIDE; TestMemoryAllocator* originalAllocator(); private: SimpleStringInternalCache& cache_; diff --git a/include/CppUTest/StandardCLibrary.h b/include/CppUTest/StandardCLibrary.h index a2171eafe..d518236ca 100644 --- a/include/CppUTest/StandardCLibrary.h +++ b/include/CppUTest/StandardCLibrary.h @@ -14,6 +14,8 @@ #ifdef __cplusplus #if CPPUTEST_USE_STD_CPP_LIB #include + #include + #include #endif #endif @@ -43,7 +45,7 @@ #include /* Needed to ensure that string.h is included prior to strdup redefinition */ -#ifdef CPPUTEST_HAVE_STRING_H +#ifdef CPPUTEST_HAVE_STRDUP #include #endif @@ -78,8 +80,15 @@ typedef long unsigned int size_t; #endif #define NULL (0) +#ifdef __cplusplus +extern "C" { +#endif extern void* malloc(size_t); extern void free(void *); +#ifdef __cplusplus +} +#endif + #define _bnd(X, bnd) (((sizeof (X)) + (bnd)) & (~(bnd))) diff --git a/include/CppUTest/TeamCityTestOutput.h b/include/CppUTest/TeamCityTestOutput.h index 186d21867..caf67d586 100644 --- a/include/CppUTest/TeamCityTestOutput.h +++ b/include/CppUTest/TeamCityTestOutput.h @@ -8,14 +8,14 @@ class TeamCityTestOutput: public ConsoleTestOutput { public: TeamCityTestOutput(void); - virtual ~TeamCityTestOutput(void) _destructor_override; + virtual ~TeamCityTestOutput(void) CPPUTEST_DESTRUCTOR_OVERRIDE; - virtual void printCurrentTestStarted(const UtestShell& test) _override; - virtual void printCurrentTestEnded(const TestResult& res) _override; - virtual void printCurrentGroupStarted(const UtestShell& test) _override; - virtual void printCurrentGroupEnded(const TestResult& res) _override; + virtual void printCurrentTestStarted(const UtestShell& test) CPPUTEST_OVERRIDE; + virtual void printCurrentTestEnded(const TestResult& res) CPPUTEST_OVERRIDE; + virtual void printCurrentGroupStarted(const UtestShell& test) CPPUTEST_OVERRIDE; + virtual void printCurrentGroupEnded(const TestResult& res) CPPUTEST_OVERRIDE; - virtual void printFailure(const TestFailure& failure) _override; + virtual void printFailure(const TestFailure& failure) CPPUTEST_OVERRIDE; protected: diff --git a/include/CppUTest/TestFailure.h b/include/CppUTest/TestFailure.h index 8b93fe332..7dc816f2c 100644 --- a/include/CppUTest/TestFailure.h +++ b/include/CppUTest/TestFailure.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -38,6 +38,10 @@ #include "SimpleString.h" +#if CPPUTEST_USE_STD_CPP_LIB +#include +#endif + class UtestShell; class TestOutput; @@ -63,13 +67,8 @@ class TestFailure protected: - enum DifferenceFormat - { - DIFFERENCE_STRING, DIFFERENCE_BINARY - }; - SimpleString createButWasString(const SimpleString& expected, const SimpleString& actual); - SimpleString createDifferenceAtPosString(const SimpleString& actual, size_t position, DifferenceFormat format = DIFFERENCE_STRING); + SimpleString createDifferenceAtPosString(const SimpleString& actual, size_t offset, size_t reportedPosition); SimpleString createUserText(const SimpleString& text); SimpleString testName_; @@ -187,4 +186,15 @@ class FeatureUnsupportedFailure : public TestFailure FeatureUnsupportedFailure(UtestShell* test, const char* fileName, size_t lineNumber, const SimpleString& featureName, const SimpleString& text); }; +#if CPPUTEST_HAVE_EXCEPTIONS +class UnexpectedExceptionFailure : public TestFailure +{ +public: + UnexpectedExceptionFailure(UtestShell* test); +#if CPPUTEST_USE_STD_CPP_LIB + UnexpectedExceptionFailure(UtestShell* test, const std::exception &e); +#endif +}; +#endif + #endif diff --git a/include/CppUTest/TestFilter.h b/include/CppUTest/TestFilter.h index 6f92a00bd..730f52e14 100644 --- a/include/CppUTest/TestFilter.h +++ b/include/CppUTest/TestFilter.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY diff --git a/include/CppUTest/TestHarness.h b/include/CppUTest/TestHarness.h index 8eb5b29bf..a4f1a8f71 100644 --- a/include/CppUTest/TestHarness.h +++ b/include/CppUTest/TestHarness.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY diff --git a/include/CppUTest/TestHarness_c.h b/include/CppUTest/TestHarness_c.h index d859c4ff6..f3a64cf83 100644 --- a/include/CppUTest/TestHarness_c.h +++ b/include/CppUTest/TestHarness_c.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -37,85 +37,91 @@ #include "CppUTestConfig.h" #define CHECK_EQUAL_C_BOOL(expected,actual) \ - CHECK_EQUAL_C_BOOL_LOCATION(expected,actual,NULLPTR,__FILE__,__LINE__) + CHECK_EQUAL_C_BOOL_LOCATION(expected,actual,NULL,__FILE__,__LINE__) #define CHECK_EQUAL_C_BOOL_TEXT(expected,actual,text) \ CHECK_EQUAL_C_BOOL_LOCATION(expected,actual,text,__FILE__,__LINE__) #define CHECK_EQUAL_C_INT(expected,actual) \ - CHECK_EQUAL_C_INT_LOCATION(expected,actual,NULLPTR,__FILE__,__LINE__) + CHECK_EQUAL_C_INT_LOCATION(expected,actual,NULL,__FILE__,__LINE__) #define CHECK_EQUAL_C_INT_TEXT(expected,actual,text) \ CHECK_EQUAL_C_INT_LOCATION(expected,actual,text,__FILE__,__LINE__) #define CHECK_EQUAL_C_UINT(expected,actual) \ - CHECK_EQUAL_C_UINT_LOCATION(expected,actual,NULLPTR,__FILE__,__LINE__) + CHECK_EQUAL_C_UINT_LOCATION(expected,actual,NULL,__FILE__,__LINE__) #define CHECK_EQUAL_C_UINT_TEXT(expected,actual,text) \ CHECK_EQUAL_C_UINT_LOCATION(expected,actual,text,__FILE__,__LINE__) #define CHECK_EQUAL_C_LONG(expected,actual) \ - CHECK_EQUAL_C_LONG_LOCATION(expected,actual,NULLPTR,__FILE__,__LINE__) + CHECK_EQUAL_C_LONG_LOCATION(expected,actual,NULL,__FILE__,__LINE__) #define CHECK_EQUAL_C_LONG_TEXT(expected,actual,text) \ CHECK_EQUAL_C_LONG_LOCATION(expected,actual,text,__FILE__,__LINE__) #define CHECK_EQUAL_C_ULONG(expected,actual) \ - CHECK_EQUAL_C_ULONG_LOCATION(expected,actual,NULLPTR,__FILE__,__LINE__) + CHECK_EQUAL_C_ULONG_LOCATION(expected,actual,NULL,__FILE__,__LINE__) #define CHECK_EQUAL_C_ULONG_TEXT(expected,actual,text) \ CHECK_EQUAL_C_ULONG_LOCATION(expected,actual,text,__FILE__,__LINE__) #define CHECK_EQUAL_C_LONGLONG(expected,actual) \ - CHECK_EQUAL_C_LONGLONG_LOCATION(expected,actual,NULLPTR,__FILE__,__LINE__) + CHECK_EQUAL_C_LONGLONG_LOCATION(expected,actual,NULL,__FILE__,__LINE__) #define CHECK_EQUAL_C_LONGLONG_TEXT(expected,actual,text) \ CHECK_EQUAL_C_LONGLONG_LOCATION(expected,actual,text,__FILE__,__LINE__) #define CHECK_EQUAL_C_ULONGLONG(expected,actual) \ - CHECK_EQUAL_C_ULONGLONG_LOCATION(expected,actual,NULLPTR,__FILE__,__LINE__) + CHECK_EQUAL_C_ULONGLONG_LOCATION(expected,actual,NULL,__FILE__,__LINE__) #define CHECK_EQUAL_C_ULONGLONG_TEXT(expected,actual,text) \ CHECK_EQUAL_C_ULONGLONG_LOCATION(expected,actual,text,__FILE__,__LINE__) #define CHECK_EQUAL_C_REAL(expected,actual,threshold) \ - CHECK_EQUAL_C_REAL_LOCATION(expected,actual,threshold,NULLPTR,__FILE__,__LINE__) + CHECK_EQUAL_C_REAL_LOCATION(expected,actual,threshold,NULL,__FILE__,__LINE__) #define CHECK_EQUAL_C_REAL_TEXT(expected,actual,threshold,text) \ CHECK_EQUAL_C_REAL_LOCATION(expected,actual,threshold,text,__FILE__,__LINE__) #define CHECK_EQUAL_C_CHAR(expected,actual) \ - CHECK_EQUAL_C_CHAR_LOCATION(expected,actual,NULLPTR,__FILE__,__LINE__) + CHECK_EQUAL_C_CHAR_LOCATION(expected,actual,NULL,__FILE__,__LINE__) #define CHECK_EQUAL_C_CHAR_TEXT(expected,actual,text) \ CHECK_EQUAL_C_CHAR_LOCATION(expected,actual,text,__FILE__,__LINE__) #define CHECK_EQUAL_C_UBYTE(expected,actual) \ - CHECK_EQUAL_C_UBYTE_LOCATION(expected,actual,NULLPTR,__FILE__,__LINE__) + CHECK_EQUAL_C_UBYTE_LOCATION(expected,actual,NULL,__FILE__,__LINE__) #define CHECK_EQUAL_C_UBYTE_TEXT(expected,actual,text) \ CHECK_EQUAL_C_UBYTE_LOCATION(expected,actual,text,__FILE__,__LINE__) #define CHECK_EQUAL_C_SBYTE(expected,actual) \ - CHECK_EQUAL_C_SBYTE_LOCATION(expected,actual,NULLPTR,__FILE__,__LINE__) + CHECK_EQUAL_C_SBYTE_LOCATION(expected,actual,NULL,__FILE__,__LINE__) #define CHECK_EQUAL_C_SBYTE_TEXT(expected,actual,text) \ CHECK_EQUAL_C_SBYTE_LOCATION(expected,actual,text,__FILE__,__LINE__) #define CHECK_EQUAL_C_STRING(expected,actual) \ - CHECK_EQUAL_C_STRING_LOCATION(expected,actual,NULLPTR,__FILE__,__LINE__) + CHECK_EQUAL_C_STRING_LOCATION(expected,actual,NULL,__FILE__,__LINE__) #define CHECK_EQUAL_C_STRING_TEXT(expected,actual,text) \ CHECK_EQUAL_C_STRING_LOCATION(expected,actual,text,__FILE__,__LINE__) #define CHECK_EQUAL_C_POINTER(expected,actual) \ - CHECK_EQUAL_C_POINTER_LOCATION(expected,actual,NULLPTR,__FILE__,__LINE__) + CHECK_EQUAL_C_POINTER_LOCATION(expected,actual,NULL,__FILE__,__LINE__) #define CHECK_EQUAL_C_POINTER_TEXT(expected,actual,text) \ CHECK_EQUAL_C_POINTER_LOCATION(expected,actual,text,__FILE__,__LINE__) +#define CHECK_EQUAL_C_MEMCMP(expected, actual, size) \ + CHECK_EQUAL_C_MEMCMP_LOCATION(expected, actual, size, NULL, __FILE__, __LINE__) + +#define CHECK_EQUAL_C_MEMCMP_TEXT(expected, actual, size, text) \ + CHECK_EQUAL_C_MEMCMP_LOCATION(expected, actual, size, text, __FILE__, __LINE__) + #define CHECK_EQUAL_C_BITS(expected, actual, mask) \ - CHECK_EQUAL_C_BITS_LOCATION(expected, actual, mask, sizeof(actual), NULLPTR, __FILE__, __LINE__) + CHECK_EQUAL_C_BITS_LOCATION(expected, actual, mask, sizeof(actual), NULL, __FILE__, __LINE__) #define CHECK_EQUAL_C_BITS_TEXT(expected, actual, mask, text) \ CHECK_EQUAL_C_BITS_LOCATION(expected, actual, mask, sizeof(actual), text, __FILE__, __LINE__) @@ -127,7 +133,7 @@ FAIL_C_LOCATION(__FILE__,__LINE__) #define CHECK_C(condition) \ - CHECK_C_LOCATION(condition, #condition, NULLPTR, __FILE__,__LINE__) + CHECK_C_LOCATION(condition, #condition, NULL, __FILE__,__LINE__) #define CHECK_C_TEXT(condition, text) \ CHECK_C_LOCATION(condition, #condition, text, __FILE__, __LINE__) @@ -141,19 +147,19 @@ /* For use in C file */ #define TEST_GROUP_C_SETUP(group_name) \ extern void group_##group_name##_setup_wrapper_c(void); \ - void group_##group_name##_setup_wrapper_c() + void group_##group_name##_setup_wrapper_c(void) #define TEST_GROUP_C_TEARDOWN(group_name) \ extern void group_##group_name##_teardown_wrapper_c(void); \ - void group_##group_name##_teardown_wrapper_c() + void group_##group_name##_teardown_wrapper_c(void) #define TEST_C(group_name, test_name) \ extern void test_##group_name##_##test_name##_wrapper_c(void);\ - void test_##group_name##_##test_name##_wrapper_c() + void test_##group_name##_##test_name##_wrapper_c(void) #define IGNORE_TEST_C(group_name, test_name) \ extern void ignore_##group_name##_##test_name##_wrapper_c(void);\ - void ignore_##group_name##_##test_name##_wrapper_c() + void ignore_##group_name##_##test_name##_wrapper_c(void) /* For use in C++ file */ @@ -164,12 +170,12 @@ TEST_GROUP(group_name) #define TEST_GROUP_C_SETUP_WRAPPER(group_name) \ - void setup() { \ + void setup() CPPUTEST_OVERRIDE { \ group_##group_name##_setup_wrapper_c(); \ } #define TEST_GROUP_C_TEARDOWN_WRAPPER(group_name) \ - void teardown() { \ + void teardown() CPPUTEST_OVERRIDE { \ group_##group_name##_teardown_wrapper_c(); \ } @@ -205,6 +211,7 @@ extern void CHECK_EQUAL_C_UBYTE_LOCATION(unsigned char expected, unsigned char a extern void CHECK_EQUAL_C_SBYTE_LOCATION(signed char expected, signed char actual, const char* text, const char* fileName, size_t lineNumber); extern void CHECK_EQUAL_C_STRING_LOCATION(const char* expected, const char* actual, const char* text, const char* fileName, size_t lineNumber); extern void CHECK_EQUAL_C_POINTER_LOCATION(const void* expected, const void* actual, const char* text, const char* fileName, size_t lineNumber); +extern void CHECK_EQUAL_C_MEMCMP_LOCATION(const void* expected, const void* actual, size_t size, const char* text, const char* fileName, size_t lineNumber); extern void CHECK_EQUAL_C_BITS_LOCATION(unsigned int expected, unsigned int actual, unsigned int mask, size_t size, const char* text, const char* fileName, size_t lineNumber); extern void FAIL_TEXT_C_LOCATION(const char* text, const char* fileName, size_t lineNumber); extern void FAIL_C_LOCATION(const char* fileName, size_t lineNumber); diff --git a/include/CppUTest/TestMemoryAllocator.h b/include/CppUTest/TestMemoryAllocator.h index 17e5b11f8..8f65bf508 100644 --- a/include/CppUTest/TestMemoryAllocator.h +++ b/include/CppUTest/TestMemoryAllocator.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -93,16 +93,16 @@ class MemoryLeakAllocator : public TestMemoryAllocator { public: MemoryLeakAllocator(TestMemoryAllocator* originalAllocator); - virtual ~MemoryLeakAllocator() _destructor_override; + virtual ~MemoryLeakAllocator() CPPUTEST_DESTRUCTOR_OVERRIDE; - virtual char* alloc_memory(size_t size, const char* file, size_t line) _override; - virtual void free_memory(char* memory, size_t size, const char* file, size_t line) _override; + virtual char* alloc_memory(size_t size, const char* file, size_t line) CPPUTEST_OVERRIDE; + virtual void free_memory(char* memory, size_t size, const char* file, size_t line) CPPUTEST_OVERRIDE; - virtual const char* name() const _override; - virtual const char* alloc_name() const _override; - virtual const char* free_name() const _override; + virtual const char* name() const CPPUTEST_OVERRIDE; + virtual const char* alloc_name() const CPPUTEST_OVERRIDE; + virtual const char* free_name() const CPPUTEST_OVERRIDE; - virtual TestMemoryAllocator* actualAllocator() _override; + virtual TestMemoryAllocator* actualAllocator() CPPUTEST_OVERRIDE; private: TestMemoryAllocator* originalAllocator_; }; @@ -112,11 +112,11 @@ class CrashOnAllocationAllocator : public TestMemoryAllocator unsigned allocationToCrashOn_; public: CrashOnAllocationAllocator(); - virtual ~CrashOnAllocationAllocator() _destructor_override; + virtual ~CrashOnAllocationAllocator() CPPUTEST_DESTRUCTOR_OVERRIDE; virtual void setNumberToCrashOn(unsigned allocationToCrashOn); - virtual char* alloc_memory(size_t size, const char* file, size_t line) _override; + virtual char* alloc_memory(size_t size, const char* file, size_t line) CPPUTEST_OVERRIDE; }; @@ -124,10 +124,10 @@ class NullUnknownAllocator: public TestMemoryAllocator { public: NullUnknownAllocator(); - virtual ~NullUnknownAllocator() _destructor_override; + virtual ~NullUnknownAllocator() CPPUTEST_DESTRUCTOR_OVERRIDE; - virtual char* alloc_memory(size_t size, const char* file, size_t line) _override; - virtual void free_memory(char* memory, size_t size, const char* file, size_t line) _override; + virtual char* alloc_memory(size_t size, const char* file, size_t line) CPPUTEST_OVERRIDE; + virtual void free_memory(char* memory, size_t size, const char* file, size_t line) CPPUTEST_OVERRIDE; static TestMemoryAllocator* defaultAllocator(); }; @@ -138,10 +138,10 @@ class FailableMemoryAllocator: public TestMemoryAllocator { public: FailableMemoryAllocator(const char* name_str = "failable alloc", const char* alloc_name_str = "alloc", const char* free_name_str = "free"); - virtual ~FailableMemoryAllocator() _destructor_override; + virtual ~FailableMemoryAllocator() CPPUTEST_DESTRUCTOR_OVERRIDE; - virtual char* alloc_memory(size_t size, const char* file, size_t line) _override; - virtual char* allocMemoryLeakNode(size_t size) _override; + virtual char* alloc_memory(size_t size, const char* file, size_t line) CPPUTEST_OVERRIDE; + virtual char* allocMemoryLeakNode(size_t size) CPPUTEST_OVERRIDE; virtual void failAllocNumber(int number); virtual void failNthAllocAt(int allocationNumber, const char* file, size_t line); @@ -207,16 +207,16 @@ class AccountingTestMemoryAllocator : public TestMemoryAllocator { public: AccountingTestMemoryAllocator(MemoryAccountant& accountant, TestMemoryAllocator* originalAllocator); - virtual ~AccountingTestMemoryAllocator() _destructor_override; + virtual ~AccountingTestMemoryAllocator() CPPUTEST_DESTRUCTOR_OVERRIDE; - virtual char* alloc_memory(size_t size, const char* file, size_t line) _override; - virtual void free_memory(char* memory, size_t size, const char* file, size_t line) _override; + virtual char* alloc_memory(size_t size, const char* file, size_t line) CPPUTEST_OVERRIDE; + virtual void free_memory(char* memory, size_t size, const char* file, size_t line) CPPUTEST_OVERRIDE; - virtual TestMemoryAllocator* actualAllocator() _override; + virtual TestMemoryAllocator* actualAllocator() CPPUTEST_OVERRIDE; TestMemoryAllocator* originalAllocator(); - virtual const char* alloc_name() const _override; - virtual const char* free_name() const _override; + virtual const char* alloc_name() const CPPUTEST_OVERRIDE; + virtual const char* free_name() const CPPUTEST_OVERRIDE; private: void addMemoryToMemoryTrackingToKeepTrackOfSize(char* memory, size_t size); diff --git a/include/CppUTest/TestOutput.h b/include/CppUTest/TestOutput.h index dff6e0af9..47fbe02ea 100644 --- a/include/CppUTest/TestOutput.h +++ b/include/CppUTest/TestOutput.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -117,12 +117,12 @@ class ConsoleTestOutput: public TestOutput explicit ConsoleTestOutput() { } - virtual ~ConsoleTestOutput() _destructor_override + virtual ~ConsoleTestOutput() CPPUTEST_DESTRUCTOR_OVERRIDE { } - virtual void printBuffer(const char* s) _override; - virtual void flush() _override; + virtual void printBuffer(const char* s) CPPUTEST_OVERRIDE; + virtual void flush() CPPUTEST_OVERRIDE; private: ConsoleTestOutput(const ConsoleTestOutput&); @@ -145,14 +145,14 @@ class StringBufferTestOutput: public TestOutput { } - virtual ~StringBufferTestOutput() _destructor_override; + virtual ~StringBufferTestOutput() CPPUTEST_DESTRUCTOR_OVERRIDE; - void printBuffer(const char* s) _override + void printBuffer(const char* s) CPPUTEST_OVERRIDE { output += s; } - void flush() _override + void flush() CPPUTEST_OVERRIDE { output = ""; } @@ -178,27 +178,29 @@ class CompositeTestOutput : public TestOutput virtual void setOutputTwo(TestOutput* output); CompositeTestOutput(); - virtual ~CompositeTestOutput() _destructor_override; - - virtual void printTestsStarted() _override; - virtual void printTestsEnded(const TestResult& result) _override; - - virtual void printCurrentTestStarted(const UtestShell& test) _override; - virtual void printCurrentTestEnded(const TestResult& res) _override; - virtual void printCurrentGroupStarted(const UtestShell& test) _override; - virtual void printCurrentGroupEnded(const TestResult& res) _override; - - virtual void verbose(VerbosityLevel level) _override; - virtual void color() _override; - virtual void printBuffer(const char*) _override; - virtual void print(const char*) _override; - virtual void print(long) _override; - virtual void print(size_t) _override; - virtual void printDouble(double) _override; - virtual void printFailure(const TestFailure& failure) _override; - virtual void setProgressIndicator(const char*) _override; - - virtual void flush() _override; + virtual ~CompositeTestOutput() CPPUTEST_DESTRUCTOR_OVERRIDE; + + virtual void printTestsStarted() CPPUTEST_OVERRIDE; + virtual void printTestsEnded(const TestResult& result) CPPUTEST_OVERRIDE; + + virtual void printCurrentTestStarted(const UtestShell& test) CPPUTEST_OVERRIDE; + virtual void printCurrentTestEnded(const TestResult& res) CPPUTEST_OVERRIDE; + virtual void printCurrentGroupStarted(const UtestShell& test) CPPUTEST_OVERRIDE; + virtual void printCurrentGroupEnded(const TestResult& res) CPPUTEST_OVERRIDE; + + virtual void verbose(VerbosityLevel level) CPPUTEST_OVERRIDE; + virtual void color() CPPUTEST_OVERRIDE; + virtual void printBuffer(const char*) CPPUTEST_OVERRIDE; + virtual void print(const char*) CPPUTEST_OVERRIDE; + virtual void print(long) CPPUTEST_OVERRIDE; + virtual void print(size_t) CPPUTEST_OVERRIDE; + virtual void printDouble(double) CPPUTEST_OVERRIDE; + virtual void printFailure(const TestFailure& failure) CPPUTEST_OVERRIDE; + virtual void setProgressIndicator(const char*) CPPUTEST_OVERRIDE; + + virtual void printVeryVerbose(const char*) CPPUTEST_OVERRIDE; + + virtual void flush() CPPUTEST_OVERRIDE; protected: CompositeTestOutput(const TestOutput&); diff --git a/include/CppUTest/TestPlugin.h b/include/CppUTest/TestPlugin.h index 2b2ed932b..d0b3c41b3 100644 --- a/include/CppUTest/TestPlugin.h +++ b/include/CppUTest/TestPlugin.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -28,6 +28,8 @@ #ifndef D_TestPlugin_h #define D_TestPlugin_h +#include "SimpleString.h" + class UtestShell; class TestResult; @@ -90,7 +92,7 @@ class SetPointerPlugin: public TestPlugin { public: SetPointerPlugin(const SimpleString& name); - virtual void postTestAction(UtestShell&, TestResult&) _override; + virtual void postTestAction(UtestShell&, TestResult&) CPPUTEST_OVERRIDE; enum { @@ -98,7 +100,11 @@ class SetPointerPlugin: public TestPlugin }; }; -#define UT_PTR_SET(a, b) do { CppUTestStore( (void**)&a ); a = b; } while(0) +#define UT_PTR_SET(a, b) \ + do { \ + CppUTestStore((void**)&(a)); \ + (a) = b; \ + } while (0) ///////////// Null Plugin @@ -108,8 +114,8 @@ class NullTestPlugin: public TestPlugin NullTestPlugin(); - virtual void runAllPreTestAction(UtestShell& test, TestResult& result) _override; - virtual void runAllPostTestAction(UtestShell& test, TestResult& result) _override; + virtual void runAllPreTestAction(UtestShell& test, TestResult& result) CPPUTEST_OVERRIDE; + virtual void runAllPostTestAction(UtestShell& test, TestResult& result) CPPUTEST_OVERRIDE; static NullTestPlugin* instance(); }; diff --git a/include/CppUTest/TestRegistry.h b/include/CppUTest/TestRegistry.h index 36617a2c7..20575dd5a 100644 --- a/include/CppUTest/TestRegistry.h +++ b/include/CppUTest/TestRegistry.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -55,6 +55,7 @@ class TestRegistry virtual void reverseTests(); virtual void listTestGroupNames(TestResult& result); virtual void listTestGroupAndCaseNames(TestResult& result); + virtual void listTestLocations(TestResult& result); virtual void setNameFilters(const TestFilter* filters); virtual void setGroupFilters(const TestFilter* filters); virtual void installPlugin(TestPlugin* plugin); diff --git a/include/CppUTest/TestResult.h b/include/CppUTest/TestResult.h index 62c4f77fe..fc6e63fd6 100644 --- a/include/CppUTest/TestResult.h +++ b/include/CppUTest/TestResult.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY diff --git a/include/CppUTest/TestTestingFixture.h b/include/CppUTest/TestTestingFixture.h index 17d12d0cb..2c7cdd5ba 100644 --- a/include/CppUTest/TestTestingFixture.h +++ b/include/CppUTest/TestTestingFixture.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY diff --git a/include/CppUTest/Utest.h b/include/CppUTest/Utest.h index 5d7a7f9a3..02e865b76 100644 --- a/include/CppUTest/Utest.h +++ b/include/CppUTest/Utest.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -69,15 +69,29 @@ class TestTerminator class NormalTestTerminator : public TestTerminator { public: - virtual void exitCurrentTest() const _override; - virtual ~NormalTestTerminator() _destructor_override; + virtual void exitCurrentTest() const CPPUTEST_OVERRIDE; + virtual ~NormalTestTerminator() CPPUTEST_DESTRUCTOR_OVERRIDE; }; class TestTerminatorWithoutExceptions : public TestTerminator { public: - virtual void exitCurrentTest() const _override; - virtual ~TestTerminatorWithoutExceptions() _destructor_override; + virtual void exitCurrentTest() const CPPUTEST_OVERRIDE; + virtual ~TestTerminatorWithoutExceptions() CPPUTEST_DESTRUCTOR_OVERRIDE; +}; + +class CrashingTestTerminator : public NormalTestTerminator +{ +public: + virtual void exitCurrentTest() const CPPUTEST_OVERRIDE; + virtual ~CrashingTestTerminator() CPPUTEST_DESTRUCTOR_OVERRIDE; +}; + +class CrashingTestTerminatorWithoutExceptions : public TestTerminatorWithoutExceptions +{ +public: + virtual void exitCurrentTest() const CPPUTEST_OVERRIDE; + virtual ~CrashingTestTerminatorWithoutExceptions() CPPUTEST_DESTRUCTOR_OVERRIDE; }; //////////////////// UtestShell @@ -87,6 +101,15 @@ class UtestShell public: static UtestShell *getCurrent(); + static const TestTerminator &getCurrentTestTerminator(); + static const TestTerminator &getCurrentTestTerminatorWithoutExceptions(); + + static void setCrashOnFail(); + static void restoreDefaultTestTerminator(); + + static void setRethrowExceptions(bool rethrowExceptions); + static bool isRethrowingExceptions(); + public: UtestShell(const char* groupName, const char* testName, const char* fileName, size_t lineNumber); virtual ~UtestShell(); @@ -105,26 +128,26 @@ class UtestShell virtual bool hasFailed() const; void countCheck(); - virtual void assertTrue(bool condition, const char *checkString, const char *conditionString, const char* text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = NormalTestTerminator()); - virtual void assertCstrEqual(const char *expected, const char *actual, const char* text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = NormalTestTerminator()); - virtual void assertCstrNEqual(const char *expected, const char *actual, size_t length, const char* text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = NormalTestTerminator()); + virtual void assertTrue(bool condition, const char *checkString, const char *conditionString, const char* text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = getCurrentTestTerminator()); + virtual void assertCstrEqual(const char *expected, const char *actual, const char* text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = getCurrentTestTerminator()); + virtual void assertCstrNEqual(const char *expected, const char *actual, size_t length, const char* text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = getCurrentTestTerminator()); virtual void assertCstrNoCaseEqual(const char *expected, const char *actual, const char* text, const char *fileName, size_t lineNumber); virtual void assertCstrContains(const char *expected, const char *actual, const char* text, const char *fileName, size_t lineNumber); virtual void assertCstrNoCaseContains(const char *expected, const char *actual, const char* text, const char *fileName, size_t lineNumber); - virtual void assertLongsEqual(long expected, long actual, const char* text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = NormalTestTerminator()); - virtual void assertUnsignedLongsEqual(unsigned long expected, unsigned long actual, const char* text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = NormalTestTerminator()); - virtual void assertLongLongsEqual(cpputest_longlong expected, cpputest_longlong actual, const char* text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = NormalTestTerminator()); - virtual void assertUnsignedLongLongsEqual(cpputest_ulonglong expected, cpputest_ulonglong actual, const char* text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = NormalTestTerminator()); - virtual void assertSignedBytesEqual(signed char expected, signed char actual, const char* text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = NormalTestTerminator()); - virtual void assertPointersEqual(const void *expected, const void *actual, const char* text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = NormalTestTerminator()); - virtual void assertFunctionPointersEqual(void (*expected)(), void (*actual)(), const char* text, const char* fileName, size_t lineNumber, const TestTerminator& testTerminator = NormalTestTerminator()); - virtual void assertDoublesEqual(double expected, double actual, double threshold, const char* text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = NormalTestTerminator()); - virtual void assertEquals(bool failed, const char* expected, const char* actual, const char* text, const char* file, size_t lineNumber, const TestTerminator& testTerminator = NormalTestTerminator()); - virtual void assertBinaryEqual(const void *expected, const void *actual, size_t length, const char* text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = NormalTestTerminator()); - virtual void assertBitsEqual(unsigned long expected, unsigned long actual, unsigned long mask, size_t byteCount, const char* text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = NormalTestTerminator()); - virtual void assertCompare(bool comparison, const char *checkString, const char *comparisonString, const char *text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = NormalTestTerminator()); - virtual void fail(const char *text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = NormalTestTerminator()); - virtual void exitTest(const TestTerminator& testTerminator = NormalTestTerminator()); + virtual void assertLongsEqual(long expected, long actual, const char* text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = getCurrentTestTerminator()); + virtual void assertUnsignedLongsEqual(unsigned long expected, unsigned long actual, const char* text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = getCurrentTestTerminator()); + virtual void assertLongLongsEqual(cpputest_longlong expected, cpputest_longlong actual, const char* text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = getCurrentTestTerminator()); + virtual void assertUnsignedLongLongsEqual(cpputest_ulonglong expected, cpputest_ulonglong actual, const char* text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = getCurrentTestTerminator()); + virtual void assertSignedBytesEqual(signed char expected, signed char actual, const char* text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = getCurrentTestTerminator()); + virtual void assertPointersEqual(const void *expected, const void *actual, const char* text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = getCurrentTestTerminator()); + virtual void assertFunctionPointersEqual(void (*expected)(), void (*actual)(), const char* text, const char* fileName, size_t lineNumber, const TestTerminator& testTerminator = getCurrentTestTerminator()); + virtual void assertDoublesEqual(double expected, double actual, double threshold, const char* text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = getCurrentTestTerminator()); + virtual void assertEquals(bool failed, const char* expected, const char* actual, const char* text, const char* file, size_t lineNumber, const TestTerminator& testTerminator = getCurrentTestTerminator()); + virtual void assertBinaryEqual(const void *expected, const void *actual, size_t length, const char* text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = getCurrentTestTerminator()); + virtual void assertBitsEqual(unsigned long expected, unsigned long actual, unsigned long mask, size_t byteCount, const char* text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = getCurrentTestTerminator()); + virtual void assertCompare(bool comparison, const char *checkString, const char *comparisonString, const char *text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = getCurrentTestTerminator()); + virtual void fail(const char *text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = getCurrentTestTerminator()); + virtual void exitTest(const TestTerminator& testTerminator = getCurrentTestTerminator()); virtual void print(const char *text, const char *fileName, size_t lineNumber); virtual void print(const SimpleString & text, const char *fileName, size_t lineNumber); @@ -153,6 +176,8 @@ class UtestShell virtual void failWith(const TestFailure& failure); virtual void failWith(const TestFailure& failure, const TestTerminator& terminator); + virtual void addFailure(const TestFailure& failure); + protected: UtestShell(); UtestShell(const char *groupName, const char *testName, const char *fileName, size_t lineNumber, UtestShell *nextTest); @@ -175,6 +200,9 @@ class UtestShell static UtestShell* currentTest_; static TestResult* testResult_; + static const TestTerminator *currentTestTerminator_; + static const TestTerminator *currentTestTerminatorWithoutExceptions_; + static bool rethrowExceptions_; }; @@ -187,9 +215,9 @@ class ExecFunctionTest : public Utest { public: ExecFunctionTest(ExecFunctionTestShell* shell); - void testBody() _override; - virtual void setup() _override; - virtual void teardown() _override; + void testBody() CPPUTEST_OVERRIDE; + virtual void setup() CPPUTEST_OVERRIDE; + virtual void teardown() CPPUTEST_OVERRIDE; private: ExecFunctionTestShell* shell_; }; @@ -211,9 +239,9 @@ class ExecFunctionWithoutParameters : public ExecFunction void (*testFunction_)(); ExecFunctionWithoutParameters(void(*testFunction)()); - virtual ~ExecFunctionWithoutParameters() _destructor_override; + virtual ~ExecFunctionWithoutParameters() CPPUTEST_DESTRUCTOR_OVERRIDE; - virtual void exec() _override; + virtual void exec() CPPUTEST_OVERRIDE; }; //////////////////// ExecFunctionTestShell @@ -230,8 +258,8 @@ class ExecFunctionTestShell : public UtestShell { } - Utest* createTest() _override { return new ExecFunctionTest(this); } - virtual ~ExecFunctionTestShell() _destructor_override; + Utest* createTest() CPPUTEST_OVERRIDE { return new ExecFunctionTest(this); } + virtual ~ExecFunctionTestShell() CPPUTEST_DESTRUCTOR_OVERRIDE; }; //////////////////// CppUTestFailedException @@ -248,14 +276,14 @@ class IgnoredUtestShell : public UtestShell { public: IgnoredUtestShell(); - virtual ~IgnoredUtestShell() _destructor_override; + virtual ~IgnoredUtestShell() CPPUTEST_DESTRUCTOR_OVERRIDE; explicit IgnoredUtestShell(const char* groupName, const char* testName, const char* fileName, size_t lineNumber); - virtual bool willRun() const _override; - virtual void setRunIgnored() _override; + virtual bool willRun() const CPPUTEST_OVERRIDE; + virtual void setRunIgnored() CPPUTEST_OVERRIDE; protected: - virtual SimpleString getMacroName() const _override; - virtual void runOneTest(TestPlugin* plugin, TestResult& result) _override; + virtual SimpleString getMacroName() const CPPUTEST_OVERRIDE; + virtual void runOneTest(TestPlugin* plugin, TestResult& result) CPPUTEST_OVERRIDE; private: IgnoredUtestShell(const IgnoredUtestShell&); diff --git a/include/CppUTest/UtestMacros.h b/include/CppUTest/UtestMacros.h index 8e144996b..743bf069e 100644 --- a/include/CppUTest/UtestMacros.h +++ b/include/CppUTest/UtestMacros.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -50,10 +50,10 @@ TEST_GROUP_BASE(testGroup, Utest) #define TEST_SETUP() \ - virtual void setup() + virtual void setup() CPPUTEST_OVERRIDE #define TEST_TEARDOWN() \ - virtual void teardown() + virtual void teardown() CPPUTEST_OVERRIDE #define TEST(testGroup, testName) \ /* External declarations for strict compilers */ \ @@ -62,9 +62,9 @@ \ class TEST_##testGroup##_##testName##_Test : public TEST_GROUP_##CppUTestGroup##testGroup \ { public: TEST_##testGroup##_##testName##_Test () : TEST_GROUP_##CppUTestGroup##testGroup () {} \ - void testBody() _override; }; \ + void testBody() CPPUTEST_OVERRIDE; }; \ class TEST_##testGroup##_##testName##_TestShell : public UtestShell { \ - virtual Utest* createTest() _override { return new TEST_##testGroup##_##testName##_Test; } \ + virtual Utest* createTest() CPPUTEST_OVERRIDE { return new TEST_##testGroup##_##testName##_Test; } \ } TEST_##testGroup##_##testName##_TestShell_instance; \ static TestInstaller TEST_##testGroup##_##testName##_Installer(TEST_##testGroup##_##testName##_TestShell_instance, #testGroup, #testName, __FILE__,__LINE__); \ void TEST_##testGroup##_##testName##_Test::testBody() @@ -76,9 +76,9 @@ \ class IGNORE##testGroup##_##testName##_Test : public TEST_GROUP_##CppUTestGroup##testGroup \ { public: IGNORE##testGroup##_##testName##_Test () : TEST_GROUP_##CppUTestGroup##testGroup () {} \ - public: void testBody() _override; }; \ + public: void testBody() CPPUTEST_OVERRIDE; }; \ class IGNORE##testGroup##_##testName##_TestShell : public IgnoredUtestShell { \ - virtual Utest* createTest() _override { return new IGNORE##testGroup##_##testName##_Test; } \ + virtual Utest* createTest() CPPUTEST_OVERRIDE { return new IGNORE##testGroup##_##testName##_Test; } \ } IGNORE##testGroup##_##testName##_TestShell_instance; \ static TestInstaller TEST_##testGroup##testName##_Installer(IGNORE##testGroup##_##testName##_TestShell_instance, #testGroup, #testName, __FILE__,__LINE__); \ void IGNORE##testGroup##_##testName##_Test::testBody () @@ -142,6 +142,10 @@ UtestShell::getCurrent()->assertLongsEqual((long)0, (long)0, NULLPTR, file, line); \ } } while(0) +#define CHECK_EQUAL_ZERO(actual) CHECK_EQUAL(0, (actual)) + +#define CHECK_EQUAL_ZERO_TEXT(actual, text) CHECK_EQUAL_TEXT(0, (actual), (text)) + #define CHECK_COMPARE(first, relop, second)\ CHECK_COMPARE_TEXT(first, relop, second, NULLPTR) @@ -149,11 +153,15 @@ CHECK_COMPARE_LOCATION(first, relop, second, text, __FILE__, __LINE__) #define CHECK_COMPARE_LOCATION(first, relop, second, text, file, line)\ - do { SimpleString conditionString;\ - conditionString += StringFrom(first); conditionString += " ";\ - conditionString += #relop; conditionString += " ";\ - conditionString += StringFrom(second);\ - UtestShell::getCurrent()->assertCompare((first) relop (second), "CHECK_COMPARE", conditionString.asCharString(), text, __FILE__, __LINE__);\ + do {\ + bool success = (first) relop (second);\ + if (!success) {\ + SimpleString conditionString;\ + conditionString += StringFrom(first); conditionString += " ";\ + conditionString += #relop; conditionString += " ";\ + conditionString += StringFrom(second);\ + UtestShell::getCurrent()->assertCompare(false, "CHECK_COMPARE", conditionString.asCharString(), text, __FILE__, __LINE__);\ + }\ } while(0) //This check checks for char* string equality using strcmp. @@ -217,11 +225,12 @@ UNSIGNED_LONGS_EQUAL_LOCATION((expected), (actual), text, __FILE__, __LINE__) #define LONGS_EQUAL_LOCATION(expected, actual, text, file, line)\ - do { UtestShell::getCurrent()->assertLongsEqual((long)expected, (long)actual, text, file, line); } while(0) + do { UtestShell::getCurrent()->assertLongsEqual((long)(expected), (long)(actual), text, file, line); } while(0) #define UNSIGNED_LONGS_EQUAL_LOCATION(expected, actual, text, file, line)\ - do { UtestShell::getCurrent()->assertUnsignedLongsEqual((unsigned long)expected, (unsigned long)actual, text, file, line); } while(0) + do { UtestShell::getCurrent()->assertUnsignedLongsEqual((unsigned long)(expected), (unsigned long)(actual), text, file, line); } while(0) +#if CPPUTEST_USE_LONG_LONG #define LONGLONGS_EQUAL(expected, actual)\ LONGLONGS_EQUAL_LOCATION(expected, actual, NULLPTR, __FILE__, __LINE__) @@ -235,10 +244,11 @@ UNSIGNED_LONGLONGS_EQUAL_LOCATION(expected, actual, text, __FILE__, __LINE__) #define LONGLONGS_EQUAL_LOCATION(expected, actual, text, file, line)\ - do { UtestShell::getCurrent()->assertLongLongsEqual((long long)expected, (long long)actual, text, file, line); } while(0) + do { UtestShell::getCurrent()->assertLongLongsEqual((cpputest_longlong)(expected), (cpputest_longlong)(actual), text, file, line); } while(0) #define UNSIGNED_LONGLONGS_EQUAL_LOCATION(expected, actual, text, file, line)\ - do { UtestShell::getCurrent()->assertUnsignedLongLongsEqual((unsigned long long)expected, (unsigned long long)actual, text, file, line); } while(0) + do { UtestShell::getCurrent()->assertUnsignedLongLongsEqual((cpputest_ulonglong)(expected), (cpputest_ulonglong)(actual), text, file, line); } while(0) +#endif // CPPUTEST_USE_LONG_LONG #define BYTES_EQUAL(expected, actual)\ LONGS_EQUAL((expected) & 0xff,(actual) & 0xff) @@ -265,7 +275,7 @@ POINTERS_EQUAL_LOCATION((expected), (actual), text, __FILE__, __LINE__) #define POINTERS_EQUAL_LOCATION(expected, actual, text, file, line)\ - do { UtestShell::getCurrent()->assertPointersEqual((const void *)expected, (const void *)actual, text, file, line); } while(0) + do { UtestShell::getCurrent()->assertPointersEqual((const void *)(expected), (const void *)(actual), text, file, line); } while(0) #define FUNCTIONPOINTERS_EQUAL(expected, actual)\ FUNCTIONPOINTERS_EQUAL_LOCATION((expected), (actual), NULLPTR, __FILE__, __LINE__) @@ -274,7 +284,7 @@ FUNCTIONPOINTERS_EQUAL_LOCATION((expected), (actual), text, __FILE__, __LINE__) #define FUNCTIONPOINTERS_EQUAL_LOCATION(expected, actual, text, file, line)\ - do { UtestShell::getCurrent()->assertFunctionPointersEqual((void (*)())expected, (void (*)())actual, text, file, line); } while(0) + do { UtestShell::getCurrent()->assertFunctionPointersEqual((void (*)())(expected), (void (*)())(actual), text, file, line); } while(0) //Check two doubles for equality within a tolerance threshold #define DOUBLES_EQUAL(expected, actual, threshold)\ @@ -302,7 +312,7 @@ BITS_LOCATION(expected, actual, mask, text, __FILE__, __LINE__) #define BITS_LOCATION(expected, actual, mask, text, file, line)\ - do { UtestShell::getCurrent()->assertBitsEqual(expected, actual, mask, sizeof(actual), text, file, line); } while(0) + do { UtestShell::getCurrent()->assertBitsEqual(expected, actual, mask, sizeof(actual), text, file, line); } while(0) // NOLINT(bugprone-sizeof-expression) #define ENUMS_EQUAL_INT(expected, actual)\ ENUMS_EQUAL_TYPE(int, expected, actual) @@ -353,7 +363,7 @@ #define UT_PRINT(text) \ UT_PRINT_LOCATION(text, __FILE__, __LINE__) -#if CPPUTEST_USE_STD_CPP_LIB +#if CPPUTEST_HAVE_EXCEPTIONS #define CHECK_THROWS(expected, expression) \ do { \ SimpleString failure_msg("expected to throw "#expected "\nbut threw nothing"); \ @@ -372,7 +382,7 @@ UtestShell::getCurrent()->countCheck(); \ } \ } while(0) -#endif /* CPPUTEST_USE_STD_CPP_LIB */ +#endif /* CPPUTEST_HAVE_EXCEPTIONS */ #define UT_CRASH() do { UtestShell::crash(); } while(0) #define RUN_ALL_TESTS(ac, av) CommandLineTestRunner::RunAllTests(ac, av) diff --git a/include/CppUTestExt/CodeMemoryReportFormatter.h b/include/CppUTestExt/CodeMemoryReportFormatter.h index 466784123..6e87fe302 100644 --- a/include/CppUTestExt/CodeMemoryReportFormatter.h +++ b/include/CppUTestExt/CodeMemoryReportFormatter.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -39,16 +39,16 @@ class CodeMemoryReportFormatter : public MemoryReportFormatter public: CodeMemoryReportFormatter(TestMemoryAllocator* internalAllocator); - virtual ~CodeMemoryReportFormatter() _destructor_override; + virtual ~CodeMemoryReportFormatter() CPPUTEST_DESTRUCTOR_OVERRIDE; - virtual void report_testgroup_start(TestResult* result, UtestShell& test) _override; - virtual void report_testgroup_end(TestResult* /*result*/, UtestShell& /*test*/) _override {} // LCOV_EXCL_LINE + virtual void report_testgroup_start(TestResult* result, UtestShell& test) CPPUTEST_OVERRIDE; + virtual void report_testgroup_end(TestResult* /*result*/, UtestShell& /*test*/) CPPUTEST_OVERRIDE {} // LCOV_EXCL_LINE - virtual void report_test_start(TestResult* result, UtestShell& test) _override; - virtual void report_test_end(TestResult* result, UtestShell& test) _override; + virtual void report_test_start(TestResult* result, UtestShell& test) CPPUTEST_OVERRIDE; + virtual void report_test_end(TestResult* result, UtestShell& test) CPPUTEST_OVERRIDE; - virtual void report_alloc_memory(TestResult* result, TestMemoryAllocator* allocator, size_t size, char* memory, const char* file, size_t line) _override; - virtual void report_free_memory(TestResult* result, TestMemoryAllocator* allocator, char* memory, const char* file, size_t line) _override; + virtual void report_alloc_memory(TestResult* result, TestMemoryAllocator* allocator, size_t size, char* memory, const char* file, size_t line) CPPUTEST_OVERRIDE; + virtual void report_free_memory(TestResult* result, TestMemoryAllocator* allocator, char* memory, const char* file, size_t line) CPPUTEST_OVERRIDE; private: diff --git a/include/CppUTestExt/GMock.h b/include/CppUTestExt/GMock.h index 71e4c7052..131597371 100644 --- a/include/CppUTestExt/GMock.h +++ b/include/CppUTestExt/GMock.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY diff --git a/include/CppUTestExt/GTest.h b/include/CppUTestExt/GTest.h index 1d3a7d124..a2472d3c7 100644 --- a/include/CppUTestExt/GTest.h +++ b/include/CppUTestExt/GTest.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -25,8 +25,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef GTEST__H_ -#define GTEST__H_ +#ifndef GTEST_H_ +#define GTEST_H_ #undef new #undef strdup diff --git a/include/CppUTestExt/GTestConvertor.h b/include/CppUTestExt/GTestConvertor.h index d7853ff1a..c606d6c18 100644 --- a/include/CppUTestExt/GTestConvertor.h +++ b/include/CppUTestExt/GTestConvertor.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -30,8 +30,8 @@ #include "CppUTest/Utest.h" -#ifdef GTEST__H_ -#error "Please include this file before you include any other GTest files" +#ifdef GTEST_H_ + #error "Please include this file before you include any other GTest files" #endif /* @@ -63,10 +63,11 @@ class GTestShell : public UtestShell ::testing::TestInfo* testinfo_; GTestShell* next_; GTestFlagsThatAllocateMemory* flags_; + public: GTestShell(::testing::TestInfo* testinfo, GTestShell* next, GTestFlagsThatAllocateMemory* flags); - virtual Utest* createTest() _override; + virtual Utest* createTest() CPPUTEST_OVERRIDE; GTestShell* nextGTest() { @@ -101,7 +102,7 @@ class GTestShell : public UtestShell * */ #define GTEST_IMPLEMENTATION_ 1 -#include "src/gtest-internal-inl.h" +#include "../src/gtest-internal-inl.h" #include "CppUTest/TestRegistry.h" #include "CppUTest/TestFailure.h" @@ -121,7 +122,7 @@ class GTestShell : public UtestShell class GTestFlagsThatAllocateMemory { public: - void storeValuesOfGTestFLags() + void storeValuesOfGTestFlags() { GTestFlagcolor = ::testing::GTEST_FLAG(color); GTestFlagfilter = ::testing::GTEST_FLAG(filter); @@ -145,7 +146,7 @@ class GTestFlagsThatAllocateMemory #endif } - void setGTestFLagValuesToNULLToAvoidMemoryLeaks() + void setGTestFlagValuesToNULLToAvoidMemoryLeaks() { #ifndef GTEST_VERSION_GTEST_1_7 ::testing::GTEST_FLAG(color) = GTEST_NO_STRING_VALUE; @@ -207,7 +208,7 @@ class GMockTestTerminator : public TestTerminator virtual void exitCurrentTest() const { /* - * When using GMock, it throws an exception fromt he destructor leaving + * When using GMock, it throws an exception from the destructor leaving * the system in an unstable state. * Therefore, when the test fails because of failed gmock expectation * then don't throw the exception, but let it return. Usually this should @@ -300,7 +301,7 @@ class GTestUTest: public Utest { ::testing::UnitTest::GetInstance()->impl()->set_current_test_info(NULL); delete test_; - flags_->setGTestFLagValuesToNULLToAvoidMemoryLeaks(); + flags_->setGTestFlagValuesToNULLToAvoidMemoryLeaks(); ::testing::internal::DeathTest::set_last_death_test_message(GTEST_NO_STRING_VALUE); } @@ -366,7 +367,7 @@ inline void GTestConvertor::createDummyInSequenceToAndFailureReporterAvoidMemory inline void GTestConvertor::addAllGTestToTestRegistry() { createDummyInSequenceToAndFailureReporterAvoidMemoryLeakInGMock(); - flags_.storeValuesOfGTestFLags(); + flags_.storeValuesOfGTestFlags(); int argc = 2; const char * argv[] = {"NameOfTheProgram", "--gmock_catch_leaked_mocks=0"}; diff --git a/include/CppUTestExt/GTestSupport.h b/include/CppUTestExt/GTestSupport.h index 9cbb27bb5..80892a0fa 100644 --- a/include/CppUTestExt/GTestSupport.h +++ b/include/CppUTestExt/GTestSupport.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -25,8 +25,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef GTESTSUPPORT__H_ -#define GTESTSUPPORT__H_ +#ifndef GTESTSUPPORT_H_ +#define GTESTSUPPORT_H_ extern void CppuTestGTestIgnoreLeaksInTest(); diff --git a/include/CppUTestExt/IEEE754ExceptionsPlugin.h b/include/CppUTestExt/IEEE754ExceptionsPlugin.h index 9d3f0cdc1..35a18181f 100644 --- a/include/CppUTestExt/IEEE754ExceptionsPlugin.h +++ b/include/CppUTestExt/IEEE754ExceptionsPlugin.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -35,8 +35,8 @@ class IEEE754ExceptionsPlugin: public TestPlugin public: IEEE754ExceptionsPlugin(const SimpleString& name = "IEEE754ExceptionsPlugin"); - virtual void preTestAction(UtestShell& test, TestResult& result) _override; - virtual void postTestAction(UtestShell& test, TestResult& result) _override; + virtual void preTestAction(UtestShell& test, TestResult& result) CPPUTEST_OVERRIDE; + virtual void postTestAction(UtestShell& test, TestResult& result) CPPUTEST_OVERRIDE; static void disableInexact(void); static void enableInexact(void); diff --git a/include/CppUTestExt/MemoryReportAllocator.h b/include/CppUTestExt/MemoryReportAllocator.h index becdb4ac4..2cca67e25 100644 --- a/include/CppUTestExt/MemoryReportAllocator.h +++ b/include/CppUTestExt/MemoryReportAllocator.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -40,7 +40,7 @@ class MemoryReportAllocator : public TestMemoryAllocator MemoryReportFormatter* formatter_; public: MemoryReportAllocator(); - virtual ~MemoryReportAllocator() _destructor_override; + virtual ~MemoryReportAllocator() CPPUTEST_DESTRUCTOR_OVERRIDE; virtual void setFormatter(MemoryReportFormatter* formatter); virtual void setTestResult(TestResult* result); @@ -48,14 +48,14 @@ class MemoryReportAllocator : public TestMemoryAllocator virtual TestMemoryAllocator* getRealAllocator(); - virtual char* alloc_memory(size_t size, const char* file, size_t line) _override; - virtual void free_memory(char* memory, size_t size, const char* file, size_t line) _override; + virtual char* alloc_memory(size_t size, const char* file, size_t line) CPPUTEST_OVERRIDE; + virtual void free_memory(char* memory, size_t size, const char* file, size_t line) CPPUTEST_OVERRIDE; - virtual const char* name() const _override; - virtual const char* alloc_name() const _override; - virtual const char* free_name() const _override; + virtual const char* name() const CPPUTEST_OVERRIDE; + virtual const char* alloc_name() const CPPUTEST_OVERRIDE; + virtual const char* free_name() const CPPUTEST_OVERRIDE; - virtual TestMemoryAllocator* actualAllocator() _override; + virtual TestMemoryAllocator* actualAllocator() CPPUTEST_OVERRIDE; }; #endif diff --git a/include/CppUTestExt/MemoryReportFormatter.h b/include/CppUTestExt/MemoryReportFormatter.h index d0034b686..2c7af57aa 100644 --- a/include/CppUTestExt/MemoryReportFormatter.h +++ b/include/CppUTestExt/MemoryReportFormatter.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -50,16 +50,16 @@ class NormalMemoryReportFormatter : public MemoryReportFormatter { public: NormalMemoryReportFormatter(); - virtual ~NormalMemoryReportFormatter() _destructor_override; + virtual ~NormalMemoryReportFormatter() CPPUTEST_DESTRUCTOR_OVERRIDE; - virtual void report_testgroup_start(TestResult* /*result*/, UtestShell& /*test*/) _override; - virtual void report_testgroup_end(TestResult* /*result*/, UtestShell& /*test*/) _override {} // LCOV_EXCL_LINE + virtual void report_testgroup_start(TestResult* /*result*/, UtestShell& /*test*/) CPPUTEST_OVERRIDE; + virtual void report_testgroup_end(TestResult* /*result*/, UtestShell& /*test*/) CPPUTEST_OVERRIDE {} // LCOV_EXCL_LINE - virtual void report_test_start(TestResult* result, UtestShell& test) _override; - virtual void report_test_end(TestResult* result, UtestShell& test) _override; + virtual void report_test_start(TestResult* result, UtestShell& test) CPPUTEST_OVERRIDE; + virtual void report_test_end(TestResult* result, UtestShell& test) CPPUTEST_OVERRIDE; - virtual void report_alloc_memory(TestResult* result, TestMemoryAllocator* allocator, size_t size, char* memory, const char* file, size_t line) _override; - virtual void report_free_memory(TestResult* result, TestMemoryAllocator* allocator, char* memory, const char* file, size_t line) _override; + virtual void report_alloc_memory(TestResult* result, TestMemoryAllocator* allocator, size_t size, char* memory, const char* file, size_t line) CPPUTEST_OVERRIDE; + virtual void report_free_memory(TestResult* result, TestMemoryAllocator* allocator, char* memory, const char* file, size_t line) CPPUTEST_OVERRIDE; }; #endif diff --git a/include/CppUTestExt/MemoryReporterPlugin.h b/include/CppUTestExt/MemoryReporterPlugin.h index 9874cade6..5b1816f9b 100644 --- a/include/CppUTestExt/MemoryReporterPlugin.h +++ b/include/CppUTestExt/MemoryReporterPlugin.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -44,11 +44,11 @@ class MemoryReporterPlugin : public TestPlugin SimpleString currentTestGroup_; public: MemoryReporterPlugin(); - virtual ~MemoryReporterPlugin() _destructor_override; + virtual ~MemoryReporterPlugin() CPPUTEST_DESTRUCTOR_OVERRIDE; - virtual void preTestAction(UtestShell & test, TestResult & result) _override; - virtual void postTestAction(UtestShell & test, TestResult & result) _override; - virtual bool parseArguments(int, const char *const *, int) _override; + virtual void preTestAction(UtestShell & test, TestResult & result) CPPUTEST_OVERRIDE; + virtual void postTestAction(UtestShell & test, TestResult & result) CPPUTEST_OVERRIDE; + virtual bool parseArguments(int, const char *const *, int) CPPUTEST_OVERRIDE; MemoryReportAllocator* getMallocAllocator(); MemoryReportAllocator* getNewAllocator(); diff --git a/include/CppUTestExt/MockActualCall.h b/include/CppUTestExt/MockActualCall.h index b41c3fdd5..51f2fa7e5 100644 --- a/include/CppUTestExt/MockActualCall.h +++ b/include/CppUTestExt/MockActualCall.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY diff --git a/include/CppUTestExt/MockCheckedActualCall.h b/include/CppUTestExt/MockCheckedActualCall.h index fd6ebd0ff..51b12e405 100644 --- a/include/CppUTestExt/MockCheckedActualCall.h +++ b/include/CppUTestExt/MockCheckedActualCall.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -35,67 +35,68 @@ class MockCheckedActualCall : public MockActualCall { public: MockCheckedActualCall(unsigned int callOrder, MockFailureReporter* reporter, const MockExpectedCallsList& expectations); - virtual ~MockCheckedActualCall() _destructor_override; + virtual ~MockCheckedActualCall() CPPUTEST_DESTRUCTOR_OVERRIDE; - virtual MockActualCall& withName(const SimpleString& name) _override; - virtual MockActualCall& withCallOrder(unsigned int) _override; - virtual MockActualCall& withBoolParameter(const SimpleString& name, bool value) _override; - virtual MockActualCall& withIntParameter(const SimpleString& name, int value) _override; - virtual MockActualCall& withUnsignedIntParameter(const SimpleString& name, unsigned int value) _override; - virtual MockActualCall& withLongIntParameter(const SimpleString& name, long int value) _override; - virtual MockActualCall& withUnsignedLongIntParameter(const SimpleString& name, unsigned long int value) _override; - virtual MockActualCall& withLongLongIntParameter(const SimpleString& name, cpputest_longlong value) _override; - virtual MockActualCall& withUnsignedLongLongIntParameter(const SimpleString& name, cpputest_ulonglong value) _override; - virtual MockActualCall& withDoubleParameter(const SimpleString& name, double value) _override; - virtual MockActualCall& withStringParameter(const SimpleString& name, const char* value) _override; - virtual MockActualCall& withPointerParameter(const SimpleString& name, void* value) _override; - virtual MockActualCall& withConstPointerParameter(const SimpleString& name, const void* value) _override; - virtual MockActualCall& withFunctionPointerParameter(const SimpleString& name, void (*value)()) _override; - virtual MockActualCall& withMemoryBufferParameter(const SimpleString& name, const unsigned char* value, size_t size) _override; - virtual MockActualCall& withParameterOfType(const SimpleString& type, const SimpleString& name, const void* value) _override; - virtual MockActualCall& withOutputParameter(const SimpleString& name, void* output) _override; - virtual MockActualCall& withOutputParameterOfType(const SimpleString& type, const SimpleString& name, void* output) _override; + virtual MockActualCall& withName(const SimpleString& name) CPPUTEST_OVERRIDE; + virtual MockActualCall& withCallOrder(unsigned int) CPPUTEST_OVERRIDE; + virtual MockActualCall& withBoolParameter(const SimpleString& name, bool value) CPPUTEST_OVERRIDE; + virtual MockActualCall& withIntParameter(const SimpleString& name, int value) CPPUTEST_OVERRIDE; + virtual MockActualCall& withUnsignedIntParameter(const SimpleString& name, unsigned int value) CPPUTEST_OVERRIDE; + virtual MockActualCall& withLongIntParameter(const SimpleString& name, long int value) CPPUTEST_OVERRIDE; + virtual MockActualCall& withUnsignedLongIntParameter(const SimpleString& name, unsigned long int value) CPPUTEST_OVERRIDE; + virtual MockActualCall& withLongLongIntParameter(const SimpleString& name, cpputest_longlong value) CPPUTEST_OVERRIDE; + virtual MockActualCall& withUnsignedLongLongIntParameter(const SimpleString& name, cpputest_ulonglong value) CPPUTEST_OVERRIDE; + virtual MockActualCall& withDoubleParameter(const SimpleString& name, double value) CPPUTEST_OVERRIDE; + virtual MockActualCall& withStringParameter(const SimpleString& name, const char* value) CPPUTEST_OVERRIDE; + virtual MockActualCall& withPointerParameter(const SimpleString& name, void* value) CPPUTEST_OVERRIDE; + virtual MockActualCall& withConstPointerParameter(const SimpleString& name, const void* value) CPPUTEST_OVERRIDE; + virtual MockActualCall& withFunctionPointerParameter(const SimpleString& name, void (*value)()) CPPUTEST_OVERRIDE; + virtual MockActualCall& withMemoryBufferParameter(const SimpleString& name, const unsigned char* value, size_t size) CPPUTEST_OVERRIDE; + virtual MockActualCall& withParameterOfType(const SimpleString& type, const SimpleString& name, const void* value) CPPUTEST_OVERRIDE; + virtual MockActualCall& withOutputParameter(const SimpleString& name, void* output) CPPUTEST_OVERRIDE; + virtual MockActualCall& withOutputParameterOfType(const SimpleString& type, const SimpleString& name, void* output) CPPUTEST_OVERRIDE; - virtual bool hasReturnValue() _override; - virtual MockNamedValue returnValue() _override; + virtual bool hasReturnValue() CPPUTEST_OVERRIDE; + virtual MockNamedValue returnValue() CPPUTEST_OVERRIDE; - virtual bool returnBoolValueOrDefault(bool default_value) _override; - virtual bool returnBoolValue() _override; + virtual bool returnBoolValueOrDefault(bool default_value) CPPUTEST_OVERRIDE; + virtual bool returnBoolValue() CPPUTEST_OVERRIDE; - virtual int returnIntValueOrDefault(int default_value) _override; - virtual int returnIntValue() _override; + virtual int returnIntValueOrDefault(int default_value) CPPUTEST_OVERRIDE; + virtual int returnIntValue() CPPUTEST_OVERRIDE; - virtual unsigned long int returnUnsignedLongIntValue() _override; - virtual unsigned long int returnUnsignedLongIntValueOrDefault(unsigned long int) _override; + virtual unsigned long int returnUnsignedLongIntValue() CPPUTEST_OVERRIDE; + virtual unsigned long int returnUnsignedLongIntValueOrDefault(unsigned long int) CPPUTEST_OVERRIDE; - virtual long int returnLongIntValue() _override; - virtual long int returnLongIntValueOrDefault(long int default_value) _override; + virtual long int returnLongIntValue() CPPUTEST_OVERRIDE; + virtual long int returnLongIntValueOrDefault(long int default_value) CPPUTEST_OVERRIDE; - virtual cpputest_ulonglong returnUnsignedLongLongIntValue() _override; - virtual cpputest_ulonglong returnUnsignedLongLongIntValueOrDefault(cpputest_ulonglong default_value) _override; + virtual cpputest_ulonglong returnUnsignedLongLongIntValue() CPPUTEST_OVERRIDE; + virtual cpputest_ulonglong returnUnsignedLongLongIntValueOrDefault(cpputest_ulonglong default_value) CPPUTEST_OVERRIDE; - virtual cpputest_longlong returnLongLongIntValue() _override; - virtual cpputest_longlong returnLongLongIntValueOrDefault(cpputest_longlong default_value) _override; + virtual cpputest_longlong returnLongLongIntValue() CPPUTEST_OVERRIDE; + virtual cpputest_longlong returnLongLongIntValueOrDefault(cpputest_longlong default_value) CPPUTEST_OVERRIDE; - virtual unsigned int returnUnsignedIntValue() _override; - virtual unsigned int returnUnsignedIntValueOrDefault(unsigned int default_value) _override; + virtual unsigned int returnUnsignedIntValue() CPPUTEST_OVERRIDE; + virtual unsigned int returnUnsignedIntValueOrDefault(unsigned int default_value) CPPUTEST_OVERRIDE; - virtual const char * returnStringValueOrDefault(const char * default_value) _override; - virtual const char * returnStringValue() _override; + virtual const char * returnStringValueOrDefault(const char * default_value) CPPUTEST_OVERRIDE; + virtual const char * returnStringValue() CPPUTEST_OVERRIDE; - virtual double returnDoubleValue() _override; - virtual double returnDoubleValueOrDefault(double default_value) _override; + virtual double returnDoubleValue() CPPUTEST_OVERRIDE; + virtual double returnDoubleValueOrDefault(double default_value) CPPUTEST_OVERRIDE; - virtual const void * returnConstPointerValue() _override; - virtual const void * returnConstPointerValueOrDefault(const void * default_value) _override; + virtual const void * returnConstPointerValue() CPPUTEST_OVERRIDE; + virtual const void * returnConstPointerValueOrDefault(const void * default_value) CPPUTEST_OVERRIDE; - virtual void * returnPointerValue() _override; - virtual void * returnPointerValueOrDefault(void *) _override; + virtual void * returnPointerValue() CPPUTEST_OVERRIDE; + virtual void * returnPointerValueOrDefault(void *) CPPUTEST_OVERRIDE; - virtual void (*returnFunctionPointerValue())() _override; - virtual void (*returnFunctionPointerValueOrDefault(void (*)()))() _override; + typedef void (*FunctionPointerReturnValue)(); + virtual FunctionPointerReturnValue returnFunctionPointerValue() CPPUTEST_OVERRIDE; + virtual FunctionPointerReturnValue returnFunctionPointerValueOrDefault(void (*)()) CPPUTEST_OVERRIDE; - virtual MockActualCall& onObject(const void* objectPtr) _override; + virtual MockActualCall& onObject(const void* objectPtr) CPPUTEST_OVERRIDE; virtual bool isFulfilled() const; virtual bool hasFailed() const; @@ -149,74 +150,74 @@ class MockCheckedActualCall : public MockActualCall MockOutputParametersListNode* outputParameterExpectations_; virtual void addOutputParameter(const SimpleString& name, const SimpleString& type, void* ptr); - virtual void cleanUpOutputParameterList(); + void cleanUpOutputParameterList(); }; class MockActualCallTrace : public MockActualCall { public: MockActualCallTrace(); - virtual ~MockActualCallTrace() _destructor_override; + virtual ~MockActualCallTrace() CPPUTEST_DESTRUCTOR_OVERRIDE; - virtual MockActualCall& withName(const SimpleString& name) _override; - virtual MockActualCall& withCallOrder(unsigned int) _override; - virtual MockActualCall& withBoolParameter(const SimpleString& name, bool value) _override; - virtual MockActualCall& withIntParameter(const SimpleString& name, int value) _override; - virtual MockActualCall& withUnsignedIntParameter(const SimpleString& name, unsigned int value) _override; - virtual MockActualCall& withLongIntParameter(const SimpleString& name, long int value) _override; - virtual MockActualCall& withUnsignedLongIntParameter(const SimpleString& name, unsigned long int value) _override; - virtual MockActualCall& withLongLongIntParameter(const SimpleString& name, cpputest_longlong value) _override; - virtual MockActualCall& withUnsignedLongLongIntParameter(const SimpleString& name, cpputest_ulonglong value) _override; - virtual MockActualCall& withDoubleParameter(const SimpleString& name, double value) _override; - virtual MockActualCall& withStringParameter(const SimpleString& name, const char* value) _override; - virtual MockActualCall& withPointerParameter(const SimpleString& name, void* value) _override; - virtual MockActualCall& withConstPointerParameter(const SimpleString& name, const void* value) _override; - virtual MockActualCall& withFunctionPointerParameter(const SimpleString& name, void (*value)()) _override; - virtual MockActualCall& withMemoryBufferParameter(const SimpleString& name, const unsigned char* value, size_t size) _override; - virtual MockActualCall& withParameterOfType(const SimpleString& typeName, const SimpleString& name, const void* value) _override; - virtual MockActualCall& withOutputParameter(const SimpleString& name, void* output) _override; - virtual MockActualCall& withOutputParameterOfType(const SimpleString& typeName, const SimpleString& name, void* output) _override; + virtual MockActualCall& withName(const SimpleString& name) CPPUTEST_OVERRIDE; + virtual MockActualCall& withCallOrder(unsigned int) CPPUTEST_OVERRIDE; + virtual MockActualCall& withBoolParameter(const SimpleString& name, bool value) CPPUTEST_OVERRIDE; + virtual MockActualCall& withIntParameter(const SimpleString& name, int value) CPPUTEST_OVERRIDE; + virtual MockActualCall& withUnsignedIntParameter(const SimpleString& name, unsigned int value) CPPUTEST_OVERRIDE; + virtual MockActualCall& withLongIntParameter(const SimpleString& name, long int value) CPPUTEST_OVERRIDE; + virtual MockActualCall& withUnsignedLongIntParameter(const SimpleString& name, unsigned long int value) CPPUTEST_OVERRIDE; + virtual MockActualCall& withLongLongIntParameter(const SimpleString& name, cpputest_longlong value) CPPUTEST_OVERRIDE; + virtual MockActualCall& withUnsignedLongLongIntParameter(const SimpleString& name, cpputest_ulonglong value) CPPUTEST_OVERRIDE; + virtual MockActualCall& withDoubleParameter(const SimpleString& name, double value) CPPUTEST_OVERRIDE; + virtual MockActualCall& withStringParameter(const SimpleString& name, const char* value) CPPUTEST_OVERRIDE; + virtual MockActualCall& withPointerParameter(const SimpleString& name, void* value) CPPUTEST_OVERRIDE; + virtual MockActualCall& withConstPointerParameter(const SimpleString& name, const void* value) CPPUTEST_OVERRIDE; + virtual MockActualCall& withFunctionPointerParameter(const SimpleString& name, void (*value)()) CPPUTEST_OVERRIDE; + virtual MockActualCall& withMemoryBufferParameter(const SimpleString& name, const unsigned char* value, size_t size) CPPUTEST_OVERRIDE; + virtual MockActualCall& withParameterOfType(const SimpleString& typeName, const SimpleString& name, const void* value) CPPUTEST_OVERRIDE; + virtual MockActualCall& withOutputParameter(const SimpleString& name, void* output) CPPUTEST_OVERRIDE; + virtual MockActualCall& withOutputParameterOfType(const SimpleString& typeName, const SimpleString& name, void* output) CPPUTEST_OVERRIDE; - virtual bool hasReturnValue() _override; - virtual MockNamedValue returnValue() _override; + virtual bool hasReturnValue() CPPUTEST_OVERRIDE; + virtual MockNamedValue returnValue() CPPUTEST_OVERRIDE; - virtual bool returnBoolValueOrDefault(bool default_value) _override; - virtual bool returnBoolValue() _override; + virtual bool returnBoolValueOrDefault(bool default_value) CPPUTEST_OVERRIDE; + virtual bool returnBoolValue() CPPUTEST_OVERRIDE; - virtual int returnIntValueOrDefault(int default_value) _override; - virtual int returnIntValue() _override; + virtual int returnIntValueOrDefault(int default_value) CPPUTEST_OVERRIDE; + virtual int returnIntValue() CPPUTEST_OVERRIDE; - virtual unsigned long int returnUnsignedLongIntValue() _override; - virtual unsigned long int returnUnsignedLongIntValueOrDefault(unsigned long int) _override; + virtual unsigned long int returnUnsignedLongIntValue() CPPUTEST_OVERRIDE; + virtual unsigned long int returnUnsignedLongIntValueOrDefault(unsigned long int) CPPUTEST_OVERRIDE; - virtual long int returnLongIntValue() _override; - virtual long int returnLongIntValueOrDefault(long int default_value) _override; + virtual long int returnLongIntValue() CPPUTEST_OVERRIDE; + virtual long int returnLongIntValueOrDefault(long int default_value) CPPUTEST_OVERRIDE; - virtual cpputest_ulonglong returnUnsignedLongLongIntValue() _override; - virtual cpputest_ulonglong returnUnsignedLongLongIntValueOrDefault(cpputest_ulonglong default_value) _override; + virtual cpputest_ulonglong returnUnsignedLongLongIntValue() CPPUTEST_OVERRIDE; + virtual cpputest_ulonglong returnUnsignedLongLongIntValueOrDefault(cpputest_ulonglong default_value) CPPUTEST_OVERRIDE; - virtual cpputest_longlong returnLongLongIntValue() _override; - virtual cpputest_longlong returnLongLongIntValueOrDefault(cpputest_longlong default_value) _override; + virtual cpputest_longlong returnLongLongIntValue() CPPUTEST_OVERRIDE; + virtual cpputest_longlong returnLongLongIntValueOrDefault(cpputest_longlong default_value) CPPUTEST_OVERRIDE; - virtual unsigned int returnUnsignedIntValue() _override; - virtual unsigned int returnUnsignedIntValueOrDefault(unsigned int default_value) _override; + virtual unsigned int returnUnsignedIntValue() CPPUTEST_OVERRIDE; + virtual unsigned int returnUnsignedIntValueOrDefault(unsigned int default_value) CPPUTEST_OVERRIDE; - virtual const char * returnStringValueOrDefault(const char * default_value) _override; - virtual const char * returnStringValue() _override; + virtual const char * returnStringValueOrDefault(const char * default_value) CPPUTEST_OVERRIDE; + virtual const char * returnStringValue() CPPUTEST_OVERRIDE; - virtual double returnDoubleValue() _override; - virtual double returnDoubleValueOrDefault(double default_value) _override; + virtual double returnDoubleValue() CPPUTEST_OVERRIDE; + virtual double returnDoubleValueOrDefault(double default_value) CPPUTEST_OVERRIDE; - virtual void * returnPointerValue() _override; - virtual void * returnPointerValueOrDefault(void *) _override; + virtual void * returnPointerValue() CPPUTEST_OVERRIDE; + virtual void * returnPointerValueOrDefault(void *) CPPUTEST_OVERRIDE; - virtual const void * returnConstPointerValue() _override; - virtual const void * returnConstPointerValueOrDefault(const void * default_value) _override; + virtual const void * returnConstPointerValue() CPPUTEST_OVERRIDE; + virtual const void * returnConstPointerValueOrDefault(const void * default_value) CPPUTEST_OVERRIDE; - virtual void (*returnFunctionPointerValue())() _override; - virtual void (*returnFunctionPointerValueOrDefault(void (*)()))() _override; + virtual MockCheckedActualCall::FunctionPointerReturnValue returnFunctionPointerValue() CPPUTEST_OVERRIDE; + virtual MockCheckedActualCall::FunctionPointerReturnValue returnFunctionPointerValueOrDefault(void (*)()) CPPUTEST_OVERRIDE; - virtual MockActualCall& onObject(const void* objectPtr) _override; + virtual MockActualCall& onObject(const void* objectPtr) CPPUTEST_OVERRIDE; const char* getTraceOutput(); void clear(); @@ -234,65 +235,83 @@ class MockActualCallTrace : public MockActualCall class MockIgnoredActualCall: public MockActualCall { public: - virtual MockActualCall& withName(const SimpleString&) _override { return *this;} - virtual MockActualCall& withCallOrder(unsigned int) _override { return *this; } - virtual MockActualCall& withBoolParameter(const SimpleString&, bool) _override { return *this; } - virtual MockActualCall& withIntParameter(const SimpleString&, int) _override { return *this; } - virtual MockActualCall& withUnsignedIntParameter(const SimpleString&, unsigned int) _override { return *this; } - virtual MockActualCall& withLongIntParameter(const SimpleString&, long int) _override { return *this; } - virtual MockActualCall& withUnsignedLongIntParameter(const SimpleString&, unsigned long int) _override { return *this; } - virtual MockActualCall& withLongLongIntParameter(const SimpleString&, cpputest_longlong) _override { return *this; } - virtual MockActualCall& withUnsignedLongLongIntParameter(const SimpleString&, cpputest_ulonglong) _override { return *this; } - virtual MockActualCall& withDoubleParameter(const SimpleString&, double) _override { return *this; } - virtual MockActualCall& withStringParameter(const SimpleString&, const char*) _override { return *this; } - virtual MockActualCall& withPointerParameter(const SimpleString& , void*) _override { return *this; } - virtual MockActualCall& withConstPointerParameter(const SimpleString& , const void*) _override { return *this; } - virtual MockActualCall& withFunctionPointerParameter(const SimpleString& , void (*)()) _override { return *this; } - virtual MockActualCall& withMemoryBufferParameter(const SimpleString&, const unsigned char*, size_t) _override { return *this; } - virtual MockActualCall& withParameterOfType(const SimpleString&, const SimpleString&, const void*) _override { return *this; } - virtual MockActualCall& withOutputParameter(const SimpleString&, void*) _override { return *this; } - virtual MockActualCall& withOutputParameterOfType(const SimpleString&, const SimpleString&, void*) _override { return *this; } - - virtual bool hasReturnValue() _override { return false; } - virtual MockNamedValue returnValue() _override { return MockNamedValue(""); } - - virtual bool returnBoolValueOrDefault(bool value) _override { return value; } - virtual bool returnBoolValue() _override { return false; } - - virtual int returnIntValue() _override { return 0; } - virtual int returnIntValueOrDefault(int value) _override { return value; } - - virtual unsigned long int returnUnsignedLongIntValue() _override { return 0; } - virtual unsigned long int returnUnsignedLongIntValueOrDefault(unsigned long int value) _override { return value; } + virtual MockActualCall& withName(const SimpleString&) CPPUTEST_OVERRIDE { return *this;} + virtual MockActualCall& withCallOrder(unsigned int) CPPUTEST_OVERRIDE { return *this; } + virtual MockActualCall& withBoolParameter(const SimpleString&, bool) CPPUTEST_OVERRIDE { return *this; } + virtual MockActualCall& withIntParameter(const SimpleString&, int) CPPUTEST_OVERRIDE { return *this; } + virtual MockActualCall& withUnsignedIntParameter(const SimpleString&, unsigned int) CPPUTEST_OVERRIDE { return *this; } + virtual MockActualCall& withLongIntParameter(const SimpleString&, long int) CPPUTEST_OVERRIDE { return *this; } + virtual MockActualCall& withUnsignedLongIntParameter(const SimpleString&, unsigned long int) CPPUTEST_OVERRIDE { return *this; } + virtual MockActualCall& withLongLongIntParameter(const SimpleString&, cpputest_longlong) CPPUTEST_OVERRIDE { return *this; } + virtual MockActualCall& withUnsignedLongLongIntParameter(const SimpleString&, cpputest_ulonglong) CPPUTEST_OVERRIDE { return *this; } + virtual MockActualCall& withDoubleParameter(const SimpleString&, double) CPPUTEST_OVERRIDE { return *this; } + virtual MockActualCall& withStringParameter(const SimpleString&, const char*) CPPUTEST_OVERRIDE { return *this; } + virtual MockActualCall& withPointerParameter(const SimpleString& , void*) CPPUTEST_OVERRIDE { return *this; } + virtual MockActualCall& withConstPointerParameter(const SimpleString& , const void*) CPPUTEST_OVERRIDE { return *this; } + virtual MockActualCall& withFunctionPointerParameter(const SimpleString& , void (*)()) CPPUTEST_OVERRIDE { return *this; } + virtual MockActualCall& withMemoryBufferParameter(const SimpleString&, const unsigned char*, size_t) CPPUTEST_OVERRIDE { return *this; } + virtual MockActualCall& withParameterOfType(const SimpleString&, const SimpleString&, const void*) CPPUTEST_OVERRIDE { return *this; } + virtual MockActualCall& withOutputParameter(const SimpleString&, void*) CPPUTEST_OVERRIDE { return *this; } + virtual MockActualCall& withOutputParameterOfType(const SimpleString&, const SimpleString&, void*) CPPUTEST_OVERRIDE { return *this; } + + virtual bool hasReturnValue() CPPUTEST_OVERRIDE { return false; } + virtual MockNamedValue returnValue() CPPUTEST_OVERRIDE { return MockNamedValue(""); } + + virtual bool returnBoolValueOrDefault(bool value) CPPUTEST_OVERRIDE { return value; } + virtual bool returnBoolValue() CPPUTEST_OVERRIDE { return false; } + + virtual int returnIntValue() CPPUTEST_OVERRIDE { return 0; } + virtual int returnIntValueOrDefault(int value) CPPUTEST_OVERRIDE { return value; } + + virtual unsigned long int returnUnsignedLongIntValue() CPPUTEST_OVERRIDE { return 0; } + virtual unsigned long int returnUnsignedLongIntValueOrDefault(unsigned long int value) CPPUTEST_OVERRIDE { return value; } + + virtual long int returnLongIntValue() CPPUTEST_OVERRIDE { return 0; } + virtual long int returnLongIntValueOrDefault(long int value) CPPUTEST_OVERRIDE { return value; } + + virtual cpputest_ulonglong returnUnsignedLongLongIntValue() CPPUTEST_OVERRIDE + { +#if CPPUTEST_USE_LONG_LONG + return 0; +#else + cpputest_ulonglong ret = {}; + return ret; +#endif + } - virtual long int returnLongIntValue() _override { return 0; } - virtual long int returnLongIntValueOrDefault(long int value) _override { return value; } + virtual cpputest_ulonglong returnUnsignedLongLongIntValueOrDefault(cpputest_ulonglong value) CPPUTEST_OVERRIDE { return value; } - virtual cpputest_ulonglong returnUnsignedLongLongIntValue() _override { return 0; } - virtual cpputest_ulonglong returnUnsignedLongLongIntValueOrDefault(cpputest_ulonglong value) _override { return value; } + virtual cpputest_longlong returnLongLongIntValue() CPPUTEST_OVERRIDE + { +#if CPPUTEST_USE_LONG_LONG + return 0; +#else + cpputest_longlong ret = {}; + return ret; +#endif + } - virtual cpputest_longlong returnLongLongIntValue() _override { return 0; } - virtual cpputest_longlong returnLongLongIntValueOrDefault(cpputest_longlong value) _override { return value; } + virtual cpputest_longlong returnLongLongIntValueOrDefault(cpputest_longlong value) CPPUTEST_OVERRIDE { return value; } - virtual unsigned int returnUnsignedIntValue() _override { return 0; } - virtual unsigned int returnUnsignedIntValueOrDefault(unsigned int value) _override { return value; } + virtual unsigned int returnUnsignedIntValue() CPPUTEST_OVERRIDE { return 0; } + virtual unsigned int returnUnsignedIntValueOrDefault(unsigned int value) CPPUTEST_OVERRIDE { return value; } - virtual double returnDoubleValue() _override { return 0.0; } - virtual double returnDoubleValueOrDefault(double value) _override { return value; } + virtual double returnDoubleValue() CPPUTEST_OVERRIDE { return 0.0; } + virtual double returnDoubleValueOrDefault(double value) CPPUTEST_OVERRIDE { return value; } - virtual const char * returnStringValue() _override { return ""; } - virtual const char * returnStringValueOrDefault(const char * value) _override { return value; } + virtual const char * returnStringValue() CPPUTEST_OVERRIDE { return ""; } + virtual const char * returnStringValueOrDefault(const char * value) CPPUTEST_OVERRIDE { return value; } - virtual void * returnPointerValue() _override { return NULLPTR; } - virtual void * returnPointerValueOrDefault(void * value) _override { return value; } + virtual void * returnPointerValue() CPPUTEST_OVERRIDE { return NULLPTR; } + virtual void * returnPointerValueOrDefault(void * value) CPPUTEST_OVERRIDE { return value; } - virtual const void * returnConstPointerValue() _override { return NULLPTR; } - virtual const void * returnConstPointerValueOrDefault(const void * value) _override { return value; } + virtual const void * returnConstPointerValue() CPPUTEST_OVERRIDE { return NULLPTR; } + virtual const void * returnConstPointerValueOrDefault(const void * value) CPPUTEST_OVERRIDE { return value; } - virtual void (*returnFunctionPointerValue())() _override { return NULLPTR; } - virtual void (*returnFunctionPointerValueOrDefault(void (*value)()))() _override { return value; } + virtual MockCheckedActualCall::FunctionPointerReturnValue returnFunctionPointerValue() CPPUTEST_OVERRIDE { return NULLPTR; } + virtual MockCheckedActualCall::FunctionPointerReturnValue returnFunctionPointerValueOrDefault(void (*value)()) CPPUTEST_OVERRIDE { return value; } - virtual MockActualCall& onObject(const void* ) _override { return *this; } + virtual MockActualCall& onObject(const void* ) CPPUTEST_OVERRIDE { return *this; } static MockIgnoredActualCall& instance(); }; diff --git a/include/CppUTestExt/MockCheckedExpectedCall.h b/include/CppUTestExt/MockCheckedExpectedCall.h index 2079577f0..a1a87fd6e 100644 --- a/include/CppUTestExt/MockCheckedExpectedCall.h +++ b/include/CppUTestExt/MockCheckedExpectedCall.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -37,47 +37,47 @@ class MockCheckedExpectedCall : public MockExpectedCall public: MockCheckedExpectedCall(); MockCheckedExpectedCall(unsigned int numCalls); - virtual ~MockCheckedExpectedCall() _destructor_override; - - virtual MockExpectedCall& withName(const SimpleString& name) _override; - virtual MockExpectedCall& withCallOrder(unsigned int callOrder) _override { return withCallOrder(callOrder, callOrder); } - virtual MockExpectedCall& withCallOrder(unsigned int initialCallOrder, unsigned int finalCallOrder) _override; - virtual MockExpectedCall& withBoolParameter(const SimpleString& name, bool value) _override; - virtual MockExpectedCall& withIntParameter(const SimpleString& name, int value) _override; - virtual MockExpectedCall& withUnsignedIntParameter(const SimpleString& name, unsigned int value) _override; - virtual MockExpectedCall& withLongIntParameter(const SimpleString& name, long int value) _override; - virtual MockExpectedCall& withUnsignedLongIntParameter(const SimpleString& name, unsigned long int value) _override; - virtual MockExpectedCall& withLongLongIntParameter(const SimpleString& name, cpputest_longlong value) _override; - virtual MockExpectedCall& withUnsignedLongLongIntParameter(const SimpleString& name, cpputest_ulonglong value) _override; - virtual MockExpectedCall& withDoubleParameter(const SimpleString& name, double value) _override; - virtual MockExpectedCall& withDoubleParameter(const SimpleString& name, double value, double tolerance) _override; - virtual MockExpectedCall& withStringParameter(const SimpleString& name, const char* value) _override; - virtual MockExpectedCall& withPointerParameter(const SimpleString& name, void* value) _override; - virtual MockExpectedCall& withConstPointerParameter(const SimpleString& name, const void* value) _override; - virtual MockExpectedCall& withFunctionPointerParameter(const SimpleString& name, void (*value)()) _override; - virtual MockExpectedCall& withMemoryBufferParameter(const SimpleString& name, const unsigned char* value, size_t size) _override; - virtual MockExpectedCall& withParameterOfType(const SimpleString& typeName, const SimpleString& name, const void* value) _override; - virtual MockExpectedCall& withOutputParameterReturning(const SimpleString& name, const void* value, size_t size) _override; - virtual MockExpectedCall& withOutputParameterOfTypeReturning(const SimpleString& typeName, const SimpleString& name, const void* value) _override; - virtual MockExpectedCall& withUnmodifiedOutputParameter(const SimpleString& name) _override; - virtual MockExpectedCall& ignoreOtherParameters() _override; - - virtual MockExpectedCall& andReturnValue(bool value) _override; - virtual MockExpectedCall& andReturnValue(int value) _override; - virtual MockExpectedCall& andReturnValue(unsigned int value) _override; - virtual MockExpectedCall& andReturnValue(long int value) _override; - virtual MockExpectedCall& andReturnValue(unsigned long int value) _override; - virtual MockExpectedCall& andReturnValue(cpputest_longlong value) _override; - virtual MockExpectedCall& andReturnValue(cpputest_ulonglong value) _override; - virtual MockExpectedCall& andReturnValue(double value) _override; - virtual MockExpectedCall& andReturnValue(const char* value) _override; - virtual MockExpectedCall& andReturnValue(void* value) _override; - virtual MockExpectedCall& andReturnValue(const void* value) _override; - virtual MockExpectedCall& andReturnValue(void (*value)()) _override; + virtual ~MockCheckedExpectedCall() CPPUTEST_DESTRUCTOR_OVERRIDE; + + virtual MockExpectedCall& withName(const SimpleString& name) CPPUTEST_OVERRIDE; + virtual MockExpectedCall& withCallOrder(unsigned int callOrder) CPPUTEST_OVERRIDE { return withCallOrder(callOrder, callOrder); } + virtual MockExpectedCall& withCallOrder(unsigned int initialCallOrder, unsigned int finalCallOrder) CPPUTEST_OVERRIDE; + virtual MockExpectedCall& withBoolParameter(const SimpleString& name, bool value) CPPUTEST_OVERRIDE; + virtual MockExpectedCall& withIntParameter(const SimpleString& name, int value) CPPUTEST_OVERRIDE; + virtual MockExpectedCall& withUnsignedIntParameter(const SimpleString& name, unsigned int value) CPPUTEST_OVERRIDE; + virtual MockExpectedCall& withLongIntParameter(const SimpleString& name, long int value) CPPUTEST_OVERRIDE; + virtual MockExpectedCall& withUnsignedLongIntParameter(const SimpleString& name, unsigned long int value) CPPUTEST_OVERRIDE; + virtual MockExpectedCall& withLongLongIntParameter(const SimpleString& name, cpputest_longlong value) CPPUTEST_OVERRIDE; + virtual MockExpectedCall& withUnsignedLongLongIntParameter(const SimpleString& name, cpputest_ulonglong value) CPPUTEST_OVERRIDE; + virtual MockExpectedCall& withDoubleParameter(const SimpleString& name, double value) CPPUTEST_OVERRIDE; + virtual MockExpectedCall& withDoubleParameter(const SimpleString& name, double value, double tolerance) CPPUTEST_OVERRIDE; + virtual MockExpectedCall& withStringParameter(const SimpleString& name, const char* value) CPPUTEST_OVERRIDE; + virtual MockExpectedCall& withPointerParameter(const SimpleString& name, void* value) CPPUTEST_OVERRIDE; + virtual MockExpectedCall& withConstPointerParameter(const SimpleString& name, const void* value) CPPUTEST_OVERRIDE; + virtual MockExpectedCall& withFunctionPointerParameter(const SimpleString& name, void (*value)()) CPPUTEST_OVERRIDE; + virtual MockExpectedCall& withMemoryBufferParameter(const SimpleString& name, const unsigned char* value, size_t size) CPPUTEST_OVERRIDE; + virtual MockExpectedCall& withParameterOfType(const SimpleString& typeName, const SimpleString& name, const void* value) CPPUTEST_OVERRIDE; + virtual MockExpectedCall& withOutputParameterReturning(const SimpleString& name, const void* value, size_t size) CPPUTEST_OVERRIDE; + virtual MockExpectedCall& withOutputParameterOfTypeReturning(const SimpleString& typeName, const SimpleString& name, const void* value) CPPUTEST_OVERRIDE; + virtual MockExpectedCall& withUnmodifiedOutputParameter(const SimpleString& name) CPPUTEST_OVERRIDE; + virtual MockExpectedCall& ignoreOtherParameters() CPPUTEST_OVERRIDE; + + virtual MockExpectedCall& andReturnValue(bool value) CPPUTEST_OVERRIDE; + virtual MockExpectedCall& andReturnValue(int value) CPPUTEST_OVERRIDE; + virtual MockExpectedCall& andReturnValue(unsigned int value) CPPUTEST_OVERRIDE; + virtual MockExpectedCall& andReturnValue(long int value) CPPUTEST_OVERRIDE; + virtual MockExpectedCall& andReturnValue(unsigned long int value) CPPUTEST_OVERRIDE; + virtual MockExpectedCall& andReturnValue(cpputest_longlong value) CPPUTEST_OVERRIDE; + virtual MockExpectedCall& andReturnValue(cpputest_ulonglong value) CPPUTEST_OVERRIDE; + virtual MockExpectedCall& andReturnValue(double value) CPPUTEST_OVERRIDE; + virtual MockExpectedCall& andReturnValue(const char* value) CPPUTEST_OVERRIDE; + virtual MockExpectedCall& andReturnValue(void* value) CPPUTEST_OVERRIDE; + virtual MockExpectedCall& andReturnValue(const void* value) CPPUTEST_OVERRIDE; + virtual MockExpectedCall& andReturnValue(void (*value)()) CPPUTEST_OVERRIDE; virtual MockNamedValue returnValue(); - virtual MockExpectedCall& onObject(void* objectPtr) _override; + virtual MockExpectedCall& onObject(void* objectPtr) CPPUTEST_OVERRIDE; virtual MockNamedValue getInputParameter(const SimpleString& name); virtual MockNamedValue getOutputParameter(const SimpleString& name); @@ -151,43 +151,43 @@ class MockIgnoredExpectedCall: public MockExpectedCall { public: - virtual MockExpectedCall& withName(const SimpleString&) _override { return *this;} - virtual MockExpectedCall& withCallOrder(unsigned int) _override { return *this; } - virtual MockExpectedCall& withCallOrder(unsigned int, unsigned int) _override { return *this; } - virtual MockExpectedCall& withBoolParameter(const SimpleString&, bool) _override { return *this; } - virtual MockExpectedCall& withIntParameter(const SimpleString&, int) _override { return *this; } - virtual MockExpectedCall& withUnsignedIntParameter(const SimpleString&, unsigned int) _override{ return *this; } - virtual MockExpectedCall& withLongIntParameter(const SimpleString&, long int) _override { return *this; } - virtual MockExpectedCall& withUnsignedLongIntParameter(const SimpleString&, unsigned long int) _override { return *this; } - virtual MockExpectedCall& withLongLongIntParameter(const SimpleString&, cpputest_longlong) _override { return *this; } - virtual MockExpectedCall& withUnsignedLongLongIntParameter(const SimpleString&, cpputest_ulonglong) _override { return *this; } - virtual MockExpectedCall& withDoubleParameter(const SimpleString&, double) _override { return *this; } - virtual MockExpectedCall& withDoubleParameter(const SimpleString&, double, double) _override { return *this; } - virtual MockExpectedCall& withStringParameter(const SimpleString&, const char*) _override { return *this; } - virtual MockExpectedCall& withPointerParameter(const SimpleString& , void*) _override { return *this; } - virtual MockExpectedCall& withConstPointerParameter(const SimpleString& , const void*) _override { return *this; } - virtual MockExpectedCall& withFunctionPointerParameter(const SimpleString& , void(*)()) _override { return *this; } - virtual MockExpectedCall& withMemoryBufferParameter(const SimpleString&, const unsigned char*, size_t) _override { return *this; } - virtual MockExpectedCall& withParameterOfType(const SimpleString&, const SimpleString&, const void*) _override { return *this; } - virtual MockExpectedCall& withOutputParameterReturning(const SimpleString&, const void*, size_t) _override { return *this; } - virtual MockExpectedCall& withOutputParameterOfTypeReturning(const SimpleString&, const SimpleString&, const void*) _override { return *this; } - virtual MockExpectedCall& withUnmodifiedOutputParameter(const SimpleString&) _override { return *this; } - virtual MockExpectedCall& ignoreOtherParameters() _override { return *this;} - - virtual MockExpectedCall& andReturnValue(bool) _override { return *this; } - virtual MockExpectedCall& andReturnValue(int) _override { return *this; } - virtual MockExpectedCall& andReturnValue(unsigned int) _override { return *this; } - virtual MockExpectedCall& andReturnValue(long int) _override { return *this; } - virtual MockExpectedCall& andReturnValue(unsigned long int) _override { return *this; } - virtual MockExpectedCall& andReturnValue(cpputest_longlong) _override { return *this; } - virtual MockExpectedCall& andReturnValue(cpputest_ulonglong) _override { return *this; } - virtual MockExpectedCall& andReturnValue(double) _override { return *this;} - virtual MockExpectedCall& andReturnValue(const char*) _override { return *this; } - virtual MockExpectedCall& andReturnValue(void*) _override { return *this; } - virtual MockExpectedCall& andReturnValue(const void*) _override { return *this; } - virtual MockExpectedCall& andReturnValue(void (*)()) _override { return *this; } - - virtual MockExpectedCall& onObject(void*) _override { return *this; } + virtual MockExpectedCall& withName(const SimpleString&) CPPUTEST_OVERRIDE { return *this;} + virtual MockExpectedCall& withCallOrder(unsigned int) CPPUTEST_OVERRIDE { return *this; } + virtual MockExpectedCall& withCallOrder(unsigned int, unsigned int) CPPUTEST_OVERRIDE { return *this; } + virtual MockExpectedCall& withBoolParameter(const SimpleString&, bool) CPPUTEST_OVERRIDE { return *this; } + virtual MockExpectedCall& withIntParameter(const SimpleString&, int) CPPUTEST_OVERRIDE { return *this; } + virtual MockExpectedCall& withUnsignedIntParameter(const SimpleString&, unsigned int) CPPUTEST_OVERRIDE{ return *this; } + virtual MockExpectedCall& withLongIntParameter(const SimpleString&, long int) CPPUTEST_OVERRIDE { return *this; } + virtual MockExpectedCall& withUnsignedLongIntParameter(const SimpleString&, unsigned long int) CPPUTEST_OVERRIDE { return *this; } + virtual MockExpectedCall& withLongLongIntParameter(const SimpleString&, cpputest_longlong) CPPUTEST_OVERRIDE { return *this; } + virtual MockExpectedCall& withUnsignedLongLongIntParameter(const SimpleString&, cpputest_ulonglong) CPPUTEST_OVERRIDE { return *this; } + virtual MockExpectedCall& withDoubleParameter(const SimpleString&, double) CPPUTEST_OVERRIDE { return *this; } + virtual MockExpectedCall& withDoubleParameter(const SimpleString&, double, double) CPPUTEST_OVERRIDE { return *this; } + virtual MockExpectedCall& withStringParameter(const SimpleString&, const char*) CPPUTEST_OVERRIDE { return *this; } + virtual MockExpectedCall& withPointerParameter(const SimpleString& , void*) CPPUTEST_OVERRIDE { return *this; } + virtual MockExpectedCall& withConstPointerParameter(const SimpleString& , const void*) CPPUTEST_OVERRIDE { return *this; } + virtual MockExpectedCall& withFunctionPointerParameter(const SimpleString& , void(*)()) CPPUTEST_OVERRIDE { return *this; } + virtual MockExpectedCall& withMemoryBufferParameter(const SimpleString&, const unsigned char*, size_t) CPPUTEST_OVERRIDE { return *this; } + virtual MockExpectedCall& withParameterOfType(const SimpleString&, const SimpleString&, const void*) CPPUTEST_OVERRIDE { return *this; } + virtual MockExpectedCall& withOutputParameterReturning(const SimpleString&, const void*, size_t) CPPUTEST_OVERRIDE { return *this; } + virtual MockExpectedCall& withOutputParameterOfTypeReturning(const SimpleString&, const SimpleString&, const void*) CPPUTEST_OVERRIDE { return *this; } + virtual MockExpectedCall& withUnmodifiedOutputParameter(const SimpleString&) CPPUTEST_OVERRIDE { return *this; } + virtual MockExpectedCall& ignoreOtherParameters() CPPUTEST_OVERRIDE { return *this;} + + virtual MockExpectedCall& andReturnValue(bool) CPPUTEST_OVERRIDE { return *this; } + virtual MockExpectedCall& andReturnValue(int) CPPUTEST_OVERRIDE { return *this; } + virtual MockExpectedCall& andReturnValue(unsigned int) CPPUTEST_OVERRIDE { return *this; } + virtual MockExpectedCall& andReturnValue(long int) CPPUTEST_OVERRIDE { return *this; } + virtual MockExpectedCall& andReturnValue(unsigned long int) CPPUTEST_OVERRIDE { return *this; } + virtual MockExpectedCall& andReturnValue(cpputest_longlong) CPPUTEST_OVERRIDE { return *this; } + virtual MockExpectedCall& andReturnValue(cpputest_ulonglong) CPPUTEST_OVERRIDE { return *this; } + virtual MockExpectedCall& andReturnValue(double) CPPUTEST_OVERRIDE { return *this;} + virtual MockExpectedCall& andReturnValue(const char*) CPPUTEST_OVERRIDE { return *this; } + virtual MockExpectedCall& andReturnValue(void*) CPPUTEST_OVERRIDE { return *this; } + virtual MockExpectedCall& andReturnValue(const void*) CPPUTEST_OVERRIDE { return *this; } + virtual MockExpectedCall& andReturnValue(void (*)()) CPPUTEST_OVERRIDE { return *this; } + + virtual MockExpectedCall& onObject(void*) CPPUTEST_OVERRIDE { return *this; } static MockExpectedCall& instance(); }; diff --git a/include/CppUTestExt/MockExpectedCall.h b/include/CppUTestExt/MockExpectedCall.h index 51630dc3d..e043de886 100644 --- a/include/CppUTestExt/MockExpectedCall.h +++ b/include/CppUTestExt/MockExpectedCall.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY diff --git a/include/CppUTestExt/MockExpectedCallsList.h b/include/CppUTestExt/MockExpectedCallsList.h index 74c920dee..3cb2e651d 100644 --- a/include/CppUTestExt/MockExpectedCallsList.h +++ b/include/CppUTestExt/MockExpectedCallsList.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -75,7 +75,8 @@ class MockExpectedCallsList virtual SimpleString unfulfilledCallsToString(const SimpleString& linePrefix = "") const; virtual SimpleString fulfilledCallsToString(const SimpleString& linePrefix = "") const; - virtual SimpleString missingParametersToString() const; + virtual SimpleString callsWithMissingParametersToString(const SimpleString& linePrefix, + const SimpleString& missingParametersPrefix) const; protected: virtual void pruneEmptyNodeFromList(); diff --git a/include/CppUTestExt/MockFailure.h b/include/CppUTestExt/MockFailure.h index af2578575..3ee4f73d3 100644 --- a/include/CppUTestExt/MockFailure.h +++ b/include/CppUTestExt/MockFailure.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -54,7 +54,7 @@ class MockFailure : public TestFailure { public: MockFailure(UtestShell* test); - virtual ~MockFailure() _destructor_override {} + virtual ~MockFailure() CPPUTEST_DESTRUCTOR_OVERRIDE {} protected: void addExpectationsAndCallHistory(const MockExpectedCallsList& expectations); void addExpectationsAndCallHistoryRelatedTo(const SimpleString& function, const MockExpectedCallsList& expectations); @@ -93,7 +93,8 @@ class MockUnexpectedOutputParameterFailure : public MockFailure class MockExpectedParameterDidntHappenFailure : public MockFailure { public: - MockExpectedParameterDidntHappenFailure(UtestShell* test, const SimpleString& functionName, const MockExpectedCallsList& expectations); + MockExpectedParameterDidntHappenFailure(UtestShell* test, const SimpleString& functionName, const MockExpectedCallsList& allExpectations, + const MockExpectedCallsList& matchingExpectations); }; class MockNoWayToCompareCustomTypeFailure : public MockFailure diff --git a/include/CppUTestExt/MockNamedValue.h b/include/CppUTestExt/MockNamedValue.h index 426b70c9d..b6e5be2cc 100644 --- a/include/CppUTestExt/MockNamedValue.h +++ b/include/CppUTestExt/MockNamedValue.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -69,8 +69,8 @@ class MockFunctionComparator : public MockNamedValueComparator MockFunctionComparator(isEqualFunction equal, valueToStringFunction valToString) : equal_(equal), valueToString_(valToString) {} - virtual bool isEqual(const void* object1, const void* object2) _override { return equal_(object1, object2); } - virtual SimpleString valueToString(const void* object) _override { return valueToString_(object); } + virtual bool isEqual(const void* object1, const void* object2) CPPUTEST_OVERRIDE { return equal_(object1, object2); } + virtual SimpleString valueToString(const void* object) CPPUTEST_OVERRIDE { return valueToString_(object); } private: isEqualFunction equal_; valueToStringFunction valueToString_; @@ -83,7 +83,7 @@ class MockFunctionCopier : public MockNamedValueCopier MockFunctionCopier(copyFunction copier) : copier_(copier) {} - virtual void copy(void* dst, const void* src) _override { copier_(dst, src); } + virtual void copy(void* dst, const void* src) CPPUTEST_OVERRIDE { copier_(dst, src); } private: copyFunction copier_; @@ -167,7 +167,7 @@ class MockNamedValue unsigned int unsignedIntValue_; long int longIntValue_; unsigned long int unsignedLongIntValue_; -#ifdef CPPUTEST_USE_LONG_LONG +#if CPPUTEST_USE_LONG_LONG cpputest_longlong longLongIntValue_; cpputest_ulonglong unsignedLongLongIntValue_; #else diff --git a/include/CppUTestExt/MockSupport.h b/include/CppUTestExt/MockSupport.h index 60a5131f1..ea770ab3a 100644 --- a/include/CppUTestExt/MockSupport.h +++ b/include/CppUTestExt/MockSupport.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY diff --git a/include/CppUTestExt/MockSupportPlugin.h b/include/CppUTestExt/MockSupportPlugin.h index cc0be2099..b77041c38 100644 --- a/include/CppUTestExt/MockSupportPlugin.h +++ b/include/CppUTestExt/MockSupportPlugin.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -35,10 +35,10 @@ class MockSupportPlugin : public TestPlugin { public: MockSupportPlugin(const SimpleString& name = "MockSupportPLugin"); - virtual ~MockSupportPlugin() _destructor_override; + virtual ~MockSupportPlugin() CPPUTEST_DESTRUCTOR_OVERRIDE; - virtual void preTestAction(UtestShell&, TestResult&) _override; - virtual void postTestAction(UtestShell&, TestResult&) _override; + virtual void preTestAction(UtestShell&, TestResult&) CPPUTEST_OVERRIDE; + virtual void postTestAction(UtestShell&, TestResult&) CPPUTEST_OVERRIDE; virtual void installComparator(const SimpleString& name, MockNamedValueComparator& comparator); virtual void installCopier(const SimpleString& name, MockNamedValueCopier& copier); diff --git a/include/CppUTestExt/MockSupport_c.h b/include/CppUTestExt/MockSupport_c.h index 32f2b7d40..b133e3682 100644 --- a/include/CppUTestExt/MockSupport_c.h +++ b/include/CppUTestExt/MockSupport_c.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -61,7 +61,7 @@ typedef struct SMockValue_c unsigned int unsignedIntValue; long int longIntValue; unsigned long int unsignedLongIntValue; -#ifdef CPPUTEST_USE_LONG_LONG +#if CPPUTEST_USE_LONG_LONG cpputest_longlong longLongIntValue; cpputest_ulonglong unsignedLongLongIntValue; #else diff --git a/include/CppUTestExt/OrderedTest.h b/include/CppUTestExt/OrderedTest.h index a3687fa99..3db756b2a 100644 --- a/include/CppUTestExt/OrderedTest.h +++ b/include/CppUTestExt/OrderedTest.h @@ -13,7 +13,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY @@ -32,7 +32,7 @@ class OrderedTestShell : public UtestShell { public: OrderedTestShell(); - virtual ~OrderedTestShell() _destructor_override; + virtual ~OrderedTestShell() CPPUTEST_DESTRUCTOR_OVERRIDE; virtual OrderedTestShell* addOrderedTest(OrderedTestShell* test); virtual OrderedTestShell* getNextOrderedTest(); @@ -71,9 +71,9 @@ class OrderedTestInstaller extern TEST_##testGroup##_##testName##_TestShell TEST_##testGroup##_##testName##_Instance; \ class TEST_##testGroup##_##testName##_Test : public TEST_GROUP_##CppUTestGroup##testGroup \ { public: TEST_##testGroup##_##testName##_Test () : TEST_GROUP_##CppUTestGroup##testGroup () {} \ - void testBody(); }; \ + void testBody() CPPUTEST_OVERRIDE; }; \ class TEST_##testGroup##_##testName##_TestShell : public OrderedTestShell { \ - virtual Utest* createTest() _override { return new TEST_##testGroup##_##testName##_Test; } \ + virtual Utest* createTest() CPPUTEST_OVERRIDE { return new TEST_##testGroup##_##testName##_Test; } \ } TEST_##testGroup##_##testName##_Instance; \ static OrderedTestInstaller TEST_##testGroup##_##testName##_Installer(TEST_##testGroup##_##testName##_Instance, #testGroup, #testName, __FILE__,__LINE__, testLevel); \ void TEST_##testGroup##_##testName##_Test::testBody() @@ -85,4 +85,3 @@ class OrderedTestInstaller } #endif - diff --git a/include/Platforms/c2000/stdint.h b/include/Platforms/c2000/stdint.h index e2831fdc0..3e076a500 100644 --- a/include/Platforms/c2000/stdint.h +++ b/include/Platforms/c2000/stdint.h @@ -14,7 +14,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY diff --git a/platforms/CCStudio/tests/CppUTest/AllTestsForTarget.cpp b/platforms/CCStudio/tests/CppUTest/AllTestsForTarget.cpp index 47cda0edc..1c977dbde 100644 --- a/platforms/CCStudio/tests/CppUTest/AllTestsForTarget.cpp +++ b/platforms/CCStudio/tests/CppUTest/AllTestsForTarget.cpp @@ -14,7 +14,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY diff --git a/platforms/CCStudio/tests/CppUTestExt/AllTestsForTarget.cpp b/platforms/CCStudio/tests/CppUTestExt/AllTestsForTarget.cpp index 4d7ec09df..d55800a2d 100644 --- a/platforms/CCStudio/tests/CppUTestExt/AllTestsForTarget.cpp +++ b/platforms/CCStudio/tests/CppUTestExt/AllTestsForTarget.cpp @@ -14,7 +14,7 @@ * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY diff --git a/platforms/Dos/Makefile b/platforms/Dos/Makefile index 9273c1a2b..7b19cafa4 100644 --- a/platforms/Dos/Makefile +++ b/platforms/Dos/Makefile @@ -9,23 +9,33 @@ comma := , path_separator := / drive = $(subst $(CYGDRIVE),$(lastword $(subst /, ,$(CYGDRIVE))):/,$(1)) convert_paths = $(if $(CYGDRIVE),$(subst /,$(path_separator),$(call drive,$(1))),$(1)) +export CPPUTEST_HOME ?= . -include $(CPPUTEST_HOME)/platforms/Dos/platform.mk include $(CPPUTEST_HOME)/platforms/Dos/sources.mk -# Disable W013 unreachable code - it overreacts to CHECK_EQUAL macros -# Disable W367 conditional expression in if statement is always true - same -# Disable W368 conditional expression in if statement is always false - same -# Disable W391 assignment found in boolean expression - we don't care - -CFLAGS := \ - -q -c -os -oc -d0 -we -w=3 -wcd=13 -wcd=367 -wcd=368 -wcd391 -wcd=472 -ml -zm \ +COMMONFLAGS := \ + -q -c -os -oc -d0 -we -w=3 -ml -zm \ -dCPPUTEST_MEM_LEAK_DETECTION_DISABLED=1 -dCPPUTEST_STD_CPP_LIB_DISABLED=1 \ -i$(call convert_paths,$(CPPUTEST_HOME)/include) \ - -i$(call convert_paths,$(CPPUTEST_HOME)/include/Platforms/Dos) \ -i$(call convert_paths,$(WATCOM)/h) -i$(call convert_paths,$(WATCOM)/h/nt) \ -CXXFLAGS := $(CFLAGS) -xds +# Disable W303 unreferenced parameter - PUNUSED is GNU-specific +CFLAGS := \ + $(COMMONFLAGS) \ + -wcd=303 + +# Disable W013 unreachable code - it overreacts to CHECK_EQUAL macros +# Disable W367 conditional expression in if statement is always true - same +# Disable W368 conditional expression in if statement is always false - same +# Disable W391 assignment found in boolean expression - we don't care +CXXFLAGS := \ + $(COMMONFLAGS) \ + -wcd=13 \ + -wcd=367 \ + -wcd=368 \ + -wcd=391 \ + -xds .PHONY: all clean @@ -36,7 +46,7 @@ all: CPPU.LIB CPPUX.LIB \ clean: rm -rf ../src/CppUTest/*.o ../src/CppUTestExt/*.o \ ../src/Platforms/dos/*.o ../tests/*.o ../tests/CppUTestExt/*.o \ - *.o *.map *.txt *.LOG *.EXE *.err *.LIB *.LST + *.o *.map *.LOG *.EXE *.err *.LIB *.LST %.o: %.cpp $(CXX) $(CXXFLAGS) -fo=$(call convert_paths,$@) $(call convert_paths,$<) @@ -52,3 +62,7 @@ clean: %.EXE: $$($$*_OBJECTS) | CPPU.LIB CPPUX.LIB $(LINK) opt q,map,st=50k sys dos lib CPPU.LIB,CPPUX.LIB \ file $(subst $(space),$(comma),$(call convert_paths,$?)) name $@ + +.PHONY: +test: + $(CPPUTEST_HOME)/platforms/Dos/alltests.sh diff --git a/platforms/Dos/alltests.sh b/platforms/Dos/alltests.sh index 2acebbcb9..9c54b3e0b 100755 --- a/platforms/Dos/alltests.sh +++ b/platforms/Dos/alltests.sh @@ -1,5 +1,7 @@ #!/bin/bash +: "${CPPUTEST_HOME:=.}" + checkForCppUTestToolsEnvVariable() { if [ -z "$CPPUTEST_HOME" ] ; then echo "CPPUTEST_HOME not set. You must set CPPUTEST_HOME to the top level CppUTest directory" diff --git a/platforms/IAR-STR912.zip b/platforms/IAR-STR912.zip deleted file mode 100644 index f5e69943e..000000000 Binary files a/platforms/IAR-STR912.zip and /dev/null differ diff --git a/platforms/armcc/Makefile b/platforms/armcc/Makefile index 83e64c57a..0bb7c5db9 100644 --- a/platforms/armcc/Makefile +++ b/platforms/armcc/Makefile @@ -29,7 +29,6 @@ COMPONENT_NAME := CppUTest INCLUDE_DIRS :=\ $(CPPUTEST_HOME)/include \ - $(CPPUTEST_HOME)/include/Platforms/armcc \ # armcc system include path SYS_INCLUDE_DIRS:=$(KEIL_DIR)/include diff --git a/platforms/iar/CppUTest.ewp b/platforms/iar/CppUTest.ewp index cef9176ad..f2f1fbe16 100644 --- a/platforms/iar/CppUTest.ewp +++ b/platforms/iar/CppUTest.ewp @@ -77,7 +77,7 @@ @@ -1603,7 +1607,7 @@ ILINK 0 - 17 + 18 1 0 + diff --git a/platforms/iar/CppUTestExt.ewp b/platforms/iar/CppUTestExt.ewp index baafa6ab2..429c3f5cf 100644 --- a/platforms/iar/CppUTestExt.ewp +++ b/platforms/iar/CppUTestExt.ewp @@ -77,7 +77,7 @@ @@ -951,7 +955,7 @@ @@ -1603,7 +1607,7 @@ ILINK 0 - 17 + 18 1 0 + diff --git a/platforms/iar/CppUTestExtTest.ewp b/platforms/iar/CppUTestExtTest.ewp index 5693a97d1..6ad4084c7 100644 --- a/platforms/iar/CppUTestExtTest.ewp +++ b/platforms/iar/CppUTestExtTest.ewp @@ -77,7 +77,7 @@ @@ -1604,7 +1608,7 @@ ILINK 0 - 17 + 18 1 0 + @@ -2019,17 +2027,20 @@ $PROJ_DIR$\..\..\tests\CppUTestExt\OrderedTestTest.cpp - $PROJ_DIR$\..\..\tests\CppUTestExt\OrderedTestTest_c.c + $PROJ_DIR$\..\..\tests\CppUTestExt\OrderedTestTest.h - $PROJ_DIR$\..\..\tests\CppUTestExt\OrderedTestTest.h + $PROJ_DIR$\..\..\tests\CppUTestExt\OrderedTestTest_c.c warnings - $PROJ_DIR$\tests\CppUTestExt\AllTests.cpp + $PROJ_DIR$\..\..\tests\CppUTestExt\AllTests.cpp + + + $PROJ_DIR$\tests\iar_argc_argv.c diff --git a/platforms/iar/CppUTestExtTest.icf b/platforms/iar/CppUTestExtTest.icf index 2d0a73bfd..23bfb64c3 100644 --- a/platforms/iar/CppUTestExtTest.icf +++ b/platforms/iar/CppUTestExtTest.icf @@ -5,7 +5,7 @@ define symbol __ICFEDIT_intvec_start__ = 0x00000000; /*-Memory Regions-*/ define symbol __ICFEDIT_region_IROM1_start__ = 0x00000080; -define symbol __ICFEDIT_region_IROM1_end__ = 0x0009FFFF; +define symbol __ICFEDIT_region_IROM1_end__ = 0x000FFFFF; define symbol __ICFEDIT_region_IROM2_start__ = 0x0; define symbol __ICFEDIT_region_IROM2_end__ = 0x0; define symbol __ICFEDIT_region_EROM1_start__ = 0x0; @@ -25,13 +25,13 @@ define symbol __ICFEDIT_region_ERAM2_end__ = 0x0; define symbol __ICFEDIT_region_ERAM3_start__ = 0x0; define symbol __ICFEDIT_region_ERAM3_end__ = 0x0; /*-Sizes-*/ -define symbol __ICFEDIT_size_cstack__ = 0x600; +define symbol __ICFEDIT_size_cstack__ = 0x2000; define symbol __ICFEDIT_size_svcstack__ = 0x100; define symbol __ICFEDIT_size_irqstack__ = 0x100; define symbol __ICFEDIT_size_fiqstack__ = 0x100; define symbol __ICFEDIT_size_undstack__ = 0x100; define symbol __ICFEDIT_size_abtstack__ = 0x100; -define symbol __ICFEDIT_size_heap__ = 0x8000; +define symbol __ICFEDIT_size_heap__ = 0x10000; /**** End of ICF editor section. ###ICF###*/ define memory mem with size = 4G; diff --git a/platforms/iar/CppUTestTest.ewp b/platforms/iar/CppUTestTest.ewp index d9200406c..c1283fe9e 100644 --- a/platforms/iar/CppUTestTest.ewp +++ b/platforms/iar/CppUTestTest.ewp @@ -77,7 +77,7 @@