mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Changed layout to match boost
This commit is contained in:
parent
7a8ba352c6
commit
c950c24f52
122 changed files with 15469 additions and 15550 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
bin
|
||||
out
|
||||
|
|
@ -1,3 +1,8 @@
|
|||
# Copyright Rene Rivera 2007.
|
||||
#
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
import modules ;
|
||||
|
||||
|
|
@ -1,5 +1 @@
|
|||
extensions = svn,headers,check
|
||||
src.dir = ${root.dir}
|
||||
tests.dir = ${root.dir}
|
||||
libraries.dir = ${root.dir}
|
||||
boost.dir = ${out.dir}/../boost
|
||||
extensions = headers,check
|
||||
|
|
|
|||
245
build/build.xml
245
build/build.xml
|
|
@ -1,135 +1,26 @@
|
|||
<!--
|
||||
Copyright Mathieu Champlon 2008.
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt)
|
||||
-->
|
||||
<project name="turtle" default="all">
|
||||
|
||||
<property environment="env"/>
|
||||
<import file="${env.PONEY_HOME}/poney.xml"/>
|
||||
|
||||
<property name="boost.root" value="${env.BOOST_ROOT}"/>
|
||||
<property name="boost.dir" value="${out.dir}/../boost"/>
|
||||
<fail unless="env.BOOST_ROOT" message="missing BOOST_ROOT environment variable"/>
|
||||
<property name="boost.dir" value="${env.BOOST_ROOT}"/>
|
||||
<property name="include.dir" value="${env.BOOST_ROOT}"/>
|
||||
<property name="src.dir" value="${root.dir}"/>
|
||||
<property name="doc.dir" value="${src.dir}/doc"/>
|
||||
<property name="tests.dir" value="${src.dir}/test"/>
|
||||
<property name="libraries.dir" value="${src.dir}/include"/>
|
||||
<property name="boostbook.dir" value="${out.dir}/boostbook"/>
|
||||
<property name="boost-mock.dir" value="${boost.dir}/libs/mock"/>
|
||||
|
||||
<target name="clean" description="clean intermediate build artifacts">
|
||||
<delete dir="${out.dir}"/>
|
||||
</target>
|
||||
|
||||
<target name="configure" description="update external libraries">
|
||||
<update name="boost"/>
|
||||
</target>
|
||||
|
||||
<presetdef name="build-turtle-test">
|
||||
<build-test input="test" depends="boost" mode="all" excludes="bench_*,fail_*">
|
||||
<compilerarg value="-Wno-uninitialized" location="mid" if="is-cygwin"/>
|
||||
<compilerarg value="-Wno-strict-aliasing" location="mid" if="is-gcc"/>
|
||||
<compilerarg value="/wd4505" if="is-msvc"/>
|
||||
</build-test>
|
||||
</presetdef>
|
||||
|
||||
<target name="test" description="run unit tests">
|
||||
<delete dir="${tests.dir}/test/bin"/>
|
||||
<build-turtle-test name="turtle"/>
|
||||
<build-turtle-test name="turtle_max_args">
|
||||
<defineset>
|
||||
<define name="MOCK_MAX_ARGS" value="21"/>
|
||||
</defineset>
|
||||
</build-turtle-test>
|
||||
<build-turtle-test name="turtle_use_conversions">
|
||||
<defineset define="MOCK_USE_CONVERSIONS"/>
|
||||
</build-turtle-test>
|
||||
<build-turtle-test name="turtle_no_decltype">
|
||||
<defineset define="MOCK_NO_DECLTYPE"/>
|
||||
</build-turtle-test>
|
||||
<build-turtle-test name="turtle_no_variadic_macros">
|
||||
<defineset define="MOCK_NO_VARIADIC_MACROS"/>
|
||||
</build-turtle-test>
|
||||
<build-turtle-test name="turtle_thread_safe">
|
||||
<defineset define="MOCK_THREAD_SAFE"/>
|
||||
</build-turtle-test>
|
||||
</target>
|
||||
|
||||
<target name="analyse" description="run errors analyser">
|
||||
<quiet>
|
||||
<mkdir dir="${reports.dir}"/>
|
||||
<delete file="${reports.dir}/errors-${platform}.log"/>
|
||||
<touch file="${reports.dir}/errors-${platform}.log"/>
|
||||
</quiet>
|
||||
<for param="file">
|
||||
<fileset dir="${tests.dir}/test" includes="fail*.cpp"/>
|
||||
<sequential>
|
||||
<record name="${reports.dir}/errors-${platform}.log" action="start" append="true"/>
|
||||
<ant target="-analyse">
|
||||
<property name="file" value="@{file}"/>
|
||||
</ant>
|
||||
<record name="${reports.dir}/errors-${platform}.log" action="stop"/>
|
||||
</sequential>
|
||||
</for>
|
||||
</target>
|
||||
|
||||
<target name="-analyse">
|
||||
<trycatch>
|
||||
<try>
|
||||
<echo>${file}</echo>
|
||||
<compile name="errors" input="${tests.dir}/errors_test" outdir="${out.dir}/errors_test" excludes="**">
|
||||
<includepath path="${libraries.dir}"/>
|
||||
<fileset file="${file}"/>
|
||||
</compile>
|
||||
</try>
|
||||
</trycatch>
|
||||
</target>
|
||||
|
||||
<target name="bench" description="run compilation benchmark">
|
||||
<mkdir dir="${reports.dir}"/>
|
||||
<quiet>
|
||||
<delete file="${reports.dir}/benchmark-${platform}.log"/>
|
||||
<touch file="${reports.dir}/benchmark-${platform}.log"/>
|
||||
<delete dir="${out.dir}/bench_test"/>
|
||||
<delete dir="${tests.dir}/test/bin"/>
|
||||
</quiet>
|
||||
<for param="file">
|
||||
<fileset dir="${tests.dir}/test" includes="bench_*.cpp"/>
|
||||
<sequential>
|
||||
<record name="${reports.dir}/benchmark-${platform}.log" action="start" append="true"/>
|
||||
<ant target="-bench">
|
||||
<property name="file" value="@{file}"/>
|
||||
</ant>
|
||||
<record name="${reports.dir}/benchmark-${platform}.log" action="stop"/>
|
||||
</sequential>
|
||||
</for>
|
||||
</target>
|
||||
|
||||
<target name="-bench">
|
||||
<echo>${file}</echo>
|
||||
<stopwatch name="bench"/>
|
||||
<quiet>
|
||||
<compile name="bench" input="${tests.dir}/test" outdir="${out.dir}/bench_test" excludes="**">
|
||||
<includepath path="${libraries.dir}"/>
|
||||
<fileset file="${file}"/>
|
||||
</compile>
|
||||
</quiet>
|
||||
<stopwatch name="bench" action="total"/>
|
||||
</target>
|
||||
|
||||
<target name="reports" description="generate code analysis reports">
|
||||
<headers name="turtle" excludes="**/*_iterate.hpp,**/*_template.hpp"/>
|
||||
<check name="turtle"/>
|
||||
</target>
|
||||
|
||||
<target name="export" description="export distribution">
|
||||
<sync todir="${dist.dir}/include">
|
||||
<fileset dir="${libraries.dir}" includes="turtle/**"/>
|
||||
</sync>
|
||||
<info version="svn rev ${svn.revision}" todir="${dist.dir}"/>
|
||||
</target>
|
||||
|
||||
<target name="package" depends="export" description="package distribution">
|
||||
<mkdir dir="${dist.dir}"/>
|
||||
<zip destfile="${dist.dir}/${ant.project.name}.zip">
|
||||
<fileset dir="${dist.dir}" includes="include/**"/>
|
||||
</zip>
|
||||
<tar destfile="${dist.dir}/${ant.project.name}.tar.bz2" compression="bzip2">
|
||||
<fileset dir="${dist.dir}" includes="include/**"/>
|
||||
</tar>
|
||||
</target>
|
||||
<property name="boost-mock.dir" value="${out.dir}/boost-mock"/>
|
||||
<property name="version" value="unreleased"/>
|
||||
|
||||
<import file="${env.PONEY_HOME}/poney.xml"/>
|
||||
|
||||
<condition property="b2.toolset" value="--toolset=${boost.toolset}" else="">
|
||||
<isset property="boost.toolset"/>
|
||||
</condition>
|
||||
|
|
@ -137,37 +28,65 @@
|
|||
<os family="windows"/>
|
||||
</condition>
|
||||
<presetdef name="b2">
|
||||
<exec taskname="b2" failonerror="true" executable="${boost.root}/${b2}">
|
||||
<exec taskname="b2" failonerror="true" executable="${boost.dir}/${b2}">
|
||||
<arg value="-q"/>
|
||||
<arg value="${b2.toolset}"/>
|
||||
</exec>
|
||||
</presetdef>
|
||||
|
||||
<target name="boost.generate" description="generate boost.mock into ${boost.dir}">
|
||||
<target name="reports" description="generate code analysis reports">
|
||||
<headers name="turtle" excludes="**/*_iterate.hpp,**/*_template.hpp"/>
|
||||
<check name="turtle"/>
|
||||
</target>
|
||||
|
||||
<target name="test" description="run tests">
|
||||
<b2 dir="${tests.dir}"/>
|
||||
</target>
|
||||
|
||||
<target name="documentation" depends="boost.generate" description="generate documentation">
|
||||
<b2 dir="${boost-mock.dir}/doc">
|
||||
<env key="BOOSTBOOK_DIR" value="${boostbook.dir}"/>
|
||||
</b2>
|
||||
</target>
|
||||
|
||||
<target name="release" depends="documentation" description="produce release packages">
|
||||
<fail unless="version" message="missing version property"/>
|
||||
<copy file="version.hpp" tofile="${out.dir}/version.hpp">
|
||||
<filterset>
|
||||
<filter token="MOCK_VERSION" value="${version}"/>
|
||||
</filterset>
|
||||
</copy>
|
||||
<zip destfile="${dist.dir}/${ant.project.name}-${version}.zip">
|
||||
<fileset dir="${dist.dir}" includes="include/**"/>
|
||||
<zipfileset dir="${doc.dir}/html" prefix="doc"/>
|
||||
<zipfileset dir="${out.dir}" includes="version.hpp" prefix="include/turtle"/>
|
||||
</zip>
|
||||
<tar destfile="${dist.dir}/${ant.project.name}-${version}.tar.bz2" compression="bzip2">
|
||||
<fileset dir="${dist.dir}" includes="include/**"/>
|
||||
<zipfileset dir="${doc.dir}/html" prefix="doc"/>
|
||||
<zipfileset dir="${out.dir}" includes="version.hpp" prefix="include/turtle"/>
|
||||
</tar>
|
||||
</target>
|
||||
|
||||
<target name="all" depends="test,reports,release" description="build and run tests then package distribution"/>
|
||||
|
||||
<target name="boost.generate" description="generate Boost.Mock">
|
||||
<delete dir="${boost-mock.dir}"/>
|
||||
<copy todir="${boost-mock.dir}/include/turtle">
|
||||
<fileset dir="${libraries.dir}/turtle"/>
|
||||
<copy todir="${boost-mock.dir}" overwrite="true" preservelastmodified="true">
|
||||
<fileset dir="${src.dir}" includes="LICENSE_1_0.txt,index.html,include/**,doc/**,test/**" excludes="**/bin/**"/>
|
||||
</copy>
|
||||
<copy todir="${boostbook.dir}">
|
||||
<fileset dir="${boost.root}/tools/boostbook" includes="xsl/**,dtd/**"/>
|
||||
<fileset dir="${boost.dir}/tools/boostbook" includes="xsl/**,dtd/**"/>
|
||||
</copy>
|
||||
<copy todir="${boostbook.dir}" overwrite="true">
|
||||
<fileset dir="boostbook"/>
|
||||
</copy>
|
||||
<copy todir="${boost-mock.dir}/doc/html">
|
||||
<fileset dir="${boost.root}/doc/src" includes="**/boostbook.css,**/**.png"/>
|
||||
<fileset dir="boost/doc" includes="images/*.png"/>
|
||||
</copy>
|
||||
<copy todir="${boost-mock.dir}" overwrite="true">
|
||||
<fileset dir="${tests.dir}" includes="test/**"/>
|
||||
<fileset dir="boost" includes="test/**,doc/**,index.html"/>
|
||||
</copy>
|
||||
<copy todir="${boost.dir}">
|
||||
<fileset dir="boost" includes="LICENSE_1_0.txt,Jamroot.jam,Jamfile.v2"/>
|
||||
<fileset dir="${boost.dir}/doc/src" includes="**/boostbook.css,**/**.png"/>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<target name="boost.convert" description="convert boost.mock in ${boost.dir}">
|
||||
<target name="boost.convert" depends="boost.generate" description="convert Boost.Mock">
|
||||
<move file="${boost-mock.dir}/include/turtle" tofile="${boost-mock.dir}/include/boost/mock"/>
|
||||
<replaceregexp match="MOCK" replace="BOOST_MOCK" flags="g">
|
||||
<fileset dir="${boost-mock.dir}" includes="**/*.cpp,**/*.hpp,**/*.qbk"/>
|
||||
|
|
@ -214,55 +133,29 @@
|
|||
<replaceregexp match="\[include changelog.qbk\]" replace="" flags="g">
|
||||
<fileset dir="${boost-mock.dir}" includes="**/mock.qbk"/>
|
||||
</replaceregexp>
|
||||
<copy todir="${boostbook.dir}" overwrite="true">
|
||||
<fileset dir="${boost.root}/tools/boostbook" includes="xsl/**,dtd/**"/>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<target name="boost.test" description="run boost.mock tests in ${boost.dir}">
|
||||
<target name="boost.test" description="run Boost.Mock tests">
|
||||
<b2 dir="${boost-mock.dir}/test"/>
|
||||
</target>
|
||||
|
||||
<target name="boost.doc" description="generate boost.mock documentation in ${boost.dir}">
|
||||
<target name="boost.documentation" depends="boost.generate" description="generate Boost.Mock documentation">
|
||||
<b2 dir="${boost-mock.dir}/doc">
|
||||
<env key="BOOSTBOOK_DIR" value="${boostbook.dir}"/>
|
||||
</b2>
|
||||
</target>
|
||||
|
||||
<target name="boost.package" description="package boost.mock">
|
||||
<target name="boost.package" description="package Boost.Mock">
|
||||
<zip destfile="${out.dir}/boost-mock.zip">
|
||||
<fileset dir="${boost.dir}" includes="libs/mock/**" excludes="**/bin/**"/>
|
||||
<fileset dir="${boost.dir}" includes="LICENSE_1_0.txt"/>
|
||||
<fileset dir="${boost-mock.dir}" includes="libs/mock/**" excludes="**/bin/**"/>
|
||||
<fileset dir="${boost-mock.dir}" includes="LICENSE_1_0.txt"/>
|
||||
</zip>
|
||||
<tar destfile="${out.dir}/boost-mock.tar.bz2" compression="bzip2">
|
||||
<fileset dir="${boost.dir}" includes="libs/mock/**" excludes="**/bin/**"/>
|
||||
<fileset dir="${boost.dir}" includes="LICENSE_1_0.txt"/>
|
||||
<fileset dir="${boost-mock.dir}" includes="libs/mock/**" excludes="**/bin/**"/>
|
||||
<fileset dir="${boost-mock.dir}" includes="LICENSE_1_0.txt"/>
|
||||
</tar>
|
||||
</target>
|
||||
|
||||
<target name="documentation" depends="boost.generate,boost.doc" description="generate documentation"/>
|
||||
|
||||
<target name="boost" depends="boost.generate,boost.convert,boost.doc,boost.test,boost.package" description="convert to boost with documentation and tests"/>
|
||||
|
||||
<target name="release" depends="documentation,package" description="produce release packages">
|
||||
<fail unless="version" message="missing version property"/>
|
||||
<copy file="version.hpp" tofile="${out.dir}/version.hpp">
|
||||
<filterset>
|
||||
<filter token="MOCK_VERSION" value="${version}"/>
|
||||
</filterset>
|
||||
</copy>
|
||||
<zip destfile="${dist.dir}/${ant.project.name}-${version}.zip">
|
||||
<fileset dir="${dist.dir}" includes="include/**"/>
|
||||
<zipfileset dir="${boost-mock.dir}/doc/html" prefix="doc"/>
|
||||
<zipfileset dir="${out.dir}" includes="version.hpp" prefix="include/turtle"/>
|
||||
</zip>
|
||||
<tar destfile="${dist.dir}/${ant.project.name}-${version}.tar.bz2" compression="bzip2">
|
||||
<fileset dir="${dist.dir}" includes="include/**"/>
|
||||
<zipfileset dir="${boost-mock.dir}/doc/html" prefix="doc"/>
|
||||
<zipfileset dir="${out.dir}" includes="version.hpp" prefix="include/turtle"/>
|
||||
</tar>
|
||||
</target>
|
||||
|
||||
<target name="all" depends="configure,test,bench,reports,export,package" description="configure, build and run tests and benchmark, export and package distribution"/>
|
||||
<target name="boost" depends="boost.convert,boost.test,boost.documentation,boost.package" description="convert to boost with documentation and tests"/>
|
||||
|
||||
</project>
|
||||
|
|
|
|||
3
build/vc100/.gitignore
vendored
Normal file
3
build/vc100/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
/*.opensdf
|
||||
/*.sdf
|
||||
/*.suo
|
||||
|
|
@ -19,45 +19,45 @@
|
|||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\turtle\config.hpp" />
|
||||
<ClInclude Include="..\..\turtle\constraint.hpp" />
|
||||
<ClInclude Include="..\..\turtle\constraints.hpp" />
|
||||
<ClInclude Include="..\..\turtle\detail\action.hpp" />
|
||||
<ClInclude Include="..\..\turtle\detail\addressof.hpp" />
|
||||
<ClInclude Include="..\..\turtle\detail\child.hpp" />
|
||||
<ClInclude Include="..\..\turtle\detail\cleanup.hpp" />
|
||||
<ClInclude Include="..\..\turtle\detail\context.hpp" />
|
||||
<ClInclude Include="..\..\turtle\detail\expectation_template.hpp" />
|
||||
<ClInclude Include="..\..\turtle\detail\formatter.hpp" />
|
||||
<ClInclude Include="..\..\turtle\detail\function.hpp" />
|
||||
<ClInclude Include="..\..\turtle\detail\function_impl_template.hpp" />
|
||||
<ClInclude Include="..\..\turtle\detail\function_iterate.hpp" />
|
||||
<ClInclude Include="..\..\turtle\detail\function_template.hpp" />
|
||||
<ClInclude Include="..\..\turtle\detail\functor.hpp" />
|
||||
<ClInclude Include="..\..\turtle\detail\group.hpp" />
|
||||
<ClInclude Include="..\..\turtle\detail\invocation.hpp" />
|
||||
<ClInclude Include="..\..\turtle\detail\is_functor.hpp" />
|
||||
<ClInclude Include="..\..\turtle\detail\matcher_base_template.hpp" />
|
||||
<ClInclude Include="..\..\turtle\detail\mutex.hpp" />
|
||||
<ClInclude Include="..\..\turtle\detail\object_impl.hpp" />
|
||||
<ClInclude Include="..\..\turtle\detail\parameter.hpp" />
|
||||
<ClInclude Include="..\..\turtle\detail\parent.hpp" />
|
||||
<ClInclude Include="..\..\turtle\detail\root.hpp" />
|
||||
<ClInclude Include="..\..\turtle\detail\sequence_impl.hpp" />
|
||||
<ClInclude Include="..\..\turtle\detail\signature.hpp" />
|
||||
<ClInclude Include="..\..\turtle\detail\type_name.hpp" />
|
||||
<ClInclude Include="..\..\turtle\detail\verifiable.hpp" />
|
||||
<ClInclude Include="..\..\turtle\error.hpp" />
|
||||
<ClInclude Include="..\..\turtle\exception.hpp" />
|
||||
<ClInclude Include="..\..\turtle\format.hpp" />
|
||||
<ClInclude Include="..\..\turtle\log.hpp" />
|
||||
<ClInclude Include="..\..\turtle\matcher.hpp" />
|
||||
<ClInclude Include="..\..\turtle\mock.hpp" />
|
||||
<ClInclude Include="..\..\turtle\object.hpp" />
|
||||
<ClInclude Include="..\..\turtle\reset.hpp" />
|
||||
<ClInclude Include="..\..\turtle\sequence.hpp" />
|
||||
<ClInclude Include="..\..\turtle\stream.hpp" />
|
||||
<ClInclude Include="..\..\turtle\verify.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\config.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\constraint.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\constraints.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\detail\action.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\detail\addressof.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\detail\child.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\detail\cleanup.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\detail\context.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\detail\expectation_template.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\detail\formatter.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\detail\function.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\detail\function_impl_template.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\detail\function_iterate.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\detail\function_template.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\detail\functor.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\detail\group.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\detail\invocation.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\detail\is_functor.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\detail\matcher_base_template.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\detail\mutex.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\detail\object_impl.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\detail\parameter.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\detail\parent.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\detail\root.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\detail\sequence_impl.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\detail\signature.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\detail\type_name.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\detail\verifiable.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\error.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\exception.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\format.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\log.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\matcher.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\mock.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\object.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\reset.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\sequence.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\stream.hpp" />
|
||||
<ClInclude Include="..\..\include\turtle\verify.hpp" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{831F2DEE-1E35-4533-A3B2-12C01BA8DA1D}</ProjectGuid>
|
||||
|
|
|
|||
|
|
@ -10,121 +10,121 @@
|
|||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\turtle\config.hpp">
|
||||
<ClInclude Include="..\..\include\turtle\config.hpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\constraint.hpp">
|
||||
<ClInclude Include="..\..\include\turtle\constraint.hpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\constraints.hpp">
|
||||
<ClInclude Include="..\..\include\turtle\constraints.hpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\error.hpp">
|
||||
<ClInclude Include="..\..\include\turtle\error.hpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\log.hpp">
|
||||
<ClInclude Include="..\..\include\turtle\exception.hpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\mock.hpp">
|
||||
<ClInclude Include="..\..\include\turtle\format.hpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\object.hpp">
|
||||
<ClInclude Include="..\..\include\turtle\log.hpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\sequence.hpp">
|
||||
<ClInclude Include="..\..\include\turtle\matcher.hpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\detail\signature.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\detail\child.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\detail\group.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\detail\context.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\detail\parent.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\detail\root.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\detail\type_name.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\detail\verifiable.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\detail\action.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\detail\expectation_template.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\detail\function.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\detail\function_iterate.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\detail\function_template.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\detail\invocation.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\detail\object_impl.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\detail\function_impl_template.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\detail\is_functor.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\stream.hpp">
|
||||
<ClInclude Include="..\..\include\turtle\mock.hpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\format.hpp">
|
||||
<ClInclude Include="..\..\include\turtle\object.hpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\verify.hpp">
|
||||
<ClInclude Include="..\..\include\turtle\reset.hpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\reset.hpp">
|
||||
<ClInclude Include="..\..\include\turtle\sequence.hpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\detail\functor.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\detail\parameter.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\detail\sequence_impl.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\detail\formatter.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\detail\cleanup.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\matcher.hpp">
|
||||
<ClInclude Include="..\..\include\turtle\stream.hpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\exception.hpp">
|
||||
<ClInclude Include="..\..\include\turtle\verify.hpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\detail\addressof.hpp">
|
||||
<ClInclude Include="..\..\include\turtle\detail\function.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\detail\mutex.hpp">
|
||||
<ClInclude Include="..\..\include\turtle\detail\function_impl_template.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\turtle\detail\matcher_base_template.hpp">
|
||||
<ClInclude Include="..\..\include\turtle\detail\function_iterate.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\turtle\detail\function_template.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\turtle\detail\functor.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\turtle\detail\group.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\turtle\detail\invocation.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\turtle\detail\is_functor.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\turtle\detail\matcher_base_template.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\turtle\detail\mutex.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\turtle\detail\object_impl.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\turtle\detail\parameter.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\turtle\detail\parent.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\turtle\detail\root.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\turtle\detail\sequence_impl.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\turtle\detail\signature.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\turtle\detail\type_name.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\turtle\detail\verifiable.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\turtle\detail\action.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\turtle\detail\addressof.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\turtle\detail\child.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\turtle\detail\cleanup.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\turtle\detail\context.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\turtle\detail\expectation_template.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\turtle\detail\formatter.hpp">
|
||||
<Filter>Source Files\detail</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
[section Changelog]
|
||||
|
||||
[section trunk]
|
||||
[section unreleased]
|
||||
Not yet released
|
||||
|
||||
* Dropped support for obsolete Boost.Phoenix V2
|
||||
|
|
@ -1,48 +1,48 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
//[ limitations_comma_in_macro_problem
|
||||
template< typename T1, typename T2 >
|
||||
struct my_base_class
|
||||
{};
|
||||
//]
|
||||
}
|
||||
|
||||
namespace limitations_comma_in_macro_solution_1
|
||||
{
|
||||
//[ limitations_comma_in_macro_solution_1
|
||||
typedef my_base_class< int, int > my_base_type;
|
||||
|
||||
MOCK_BASE_CLASS( my_mock, my_base_type )
|
||||
{};
|
||||
//]
|
||||
}
|
||||
|
||||
namespace limitations_comma_in_macro_solution_2
|
||||
{
|
||||
//[ limitations_comma_in_macro_solution_2
|
||||
template< typename T1, typename T2 >
|
||||
MOCK_BASE_CLASS( my_mock, my_base_class< T1 BOOST_PP_COMMA() T2 > )
|
||||
{};
|
||||
//]
|
||||
}
|
||||
|
||||
namespace limitations_comma_in_macro_solution_3
|
||||
{
|
||||
//[ limitations_comma_in_macro_solution_3
|
||||
template< typename T1, typename T2 >
|
||||
struct my_mock : my_base_class< T1, T2 >, mock::object
|
||||
{};
|
||||
//]
|
||||
}
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
//[ limitations_comma_in_macro_problem
|
||||
template< typename T1, typename T2 >
|
||||
struct my_base_class
|
||||
{};
|
||||
//]
|
||||
}
|
||||
|
||||
namespace limitations_comma_in_macro_solution_1
|
||||
{
|
||||
//[ limitations_comma_in_macro_solution_1
|
||||
typedef my_base_class< int, int > my_base_type;
|
||||
|
||||
MOCK_BASE_CLASS( my_mock, my_base_type )
|
||||
{};
|
||||
//]
|
||||
}
|
||||
|
||||
namespace limitations_comma_in_macro_solution_2
|
||||
{
|
||||
//[ limitations_comma_in_macro_solution_2
|
||||
template< typename T1, typename T2 >
|
||||
MOCK_BASE_CLASS( my_mock, my_base_class< T1 BOOST_PP_COMMA() T2 > )
|
||||
{};
|
||||
//]
|
||||
}
|
||||
|
||||
namespace limitations_comma_in_macro_solution_3
|
||||
{
|
||||
//[ limitations_comma_in_macro_solution_3
|
||||
template< typename T1, typename T2 >
|
||||
struct my_mock : my_base_class< T1, T2 >, mock::object
|
||||
{};
|
||||
//]
|
||||
}
|
||||
|
|
@ -1,50 +1,50 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
//[ limitations_const_parameter_warning_problem
|
||||
class base
|
||||
{
|
||||
public:
|
||||
virtual void method( const int ) = 0;
|
||||
};
|
||||
//]
|
||||
}
|
||||
|
||||
namespace limitations_const_parameter_warning_explanation
|
||||
{
|
||||
//[ limitations_const_parameter_warning_explanation
|
||||
class derived : public base
|
||||
{
|
||||
public:
|
||||
virtual void method( const int );
|
||||
};
|
||||
|
||||
void derived::method( int )
|
||||
{}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace limitations_const_parameter_warning_solution
|
||||
{
|
||||
//[ limitations_const_parameter_warning_solution
|
||||
MOCK_BASE_CLASS( mock_base, base )
|
||||
{
|
||||
void method( const int i )
|
||||
{
|
||||
method_stub( i );
|
||||
}
|
||||
MOCK_METHOD( method_stub, 1, void( int ), method )
|
||||
};
|
||||
//]
|
||||
}
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
//[ limitations_const_parameter_warning_problem
|
||||
class base
|
||||
{
|
||||
public:
|
||||
virtual void method( const int ) = 0;
|
||||
};
|
||||
//]
|
||||
}
|
||||
|
||||
namespace limitations_const_parameter_warning_explanation
|
||||
{
|
||||
//[ limitations_const_parameter_warning_explanation
|
||||
class derived : public base
|
||||
{
|
||||
public:
|
||||
virtual void method( const int );
|
||||
};
|
||||
|
||||
void derived::method( int )
|
||||
{}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace limitations_const_parameter_warning_solution
|
||||
{
|
||||
//[ limitations_const_parameter_warning_solution
|
||||
MOCK_BASE_CLASS( mock_base, base )
|
||||
{
|
||||
void method( const int i )
|
||||
{
|
||||
method_stub( i );
|
||||
}
|
||||
MOCK_METHOD( method_stub, 1, void( int ), method )
|
||||
};
|
||||
//]
|
||||
}
|
||||
|
|
@ -1,43 +1,43 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
//[ limitations_literal_zero_problem
|
||||
class base
|
||||
{
|
||||
public:
|
||||
virtual void method( int* i ) = 0;
|
||||
};
|
||||
|
||||
MOCK_BASE_CLASS( mock_base, base )
|
||||
{
|
||||
MOCK_METHOD( method, 1 )
|
||||
};
|
||||
//]
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( literal_zero )
|
||||
{
|
||||
mock_base m;
|
||||
//[ limitations_literal_zero_solution_1
|
||||
MOCK_EXPECT( m.method ).with( mock::equal< int* >( 0 ) ); // this compiles
|
||||
//]
|
||||
//[ limitations_literal_zero_solution_2
|
||||
MOCK_EXPECT( m.method ).with( mock::negate );
|
||||
//]
|
||||
#ifdef MOCK_NULLPTR
|
||||
//[ limitations_literal_zero_solution_3
|
||||
MOCK_EXPECT( m.method ).with( nullptr );
|
||||
//]
|
||||
#endif
|
||||
}
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
//[ limitations_literal_zero_problem
|
||||
class base
|
||||
{
|
||||
public:
|
||||
virtual void method( int* i ) = 0;
|
||||
};
|
||||
|
||||
MOCK_BASE_CLASS( mock_base, base )
|
||||
{
|
||||
MOCK_METHOD( method, 1 )
|
||||
};
|
||||
//]
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( literal_zero )
|
||||
{
|
||||
mock_base m;
|
||||
//[ limitations_literal_zero_solution_1
|
||||
MOCK_EXPECT( m.method ).with( mock::equal< int* >( 0 ) ); // this compiles
|
||||
//]
|
||||
//[ limitations_literal_zero_solution_2
|
||||
MOCK_EXPECT( m.method ).with( mock::negate );
|
||||
//]
|
||||
#ifdef MOCK_NULLPTR
|
||||
//[ limitations_literal_zero_solution_3
|
||||
MOCK_EXPECT( m.method ).with( nullptr );
|
||||
//]
|
||||
#endif
|
||||
}
|
||||
|
|
@ -1,27 +1,27 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
//[ limitations_non_virtual_method_problem
|
||||
class base
|
||||
{
|
||||
public:
|
||||
void method() // the method is not virtual
|
||||
{}
|
||||
};
|
||||
//]
|
||||
|
||||
//[ limitations_non_virtual_method_problem_2
|
||||
MOCK_BASE_CLASS( mock_base, base )
|
||||
{
|
||||
MOCK_METHOD( method, 0 )
|
||||
};
|
||||
//]
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
//[ limitations_non_virtual_method_problem
|
||||
class base
|
||||
{
|
||||
public:
|
||||
void method() // the method is not virtual
|
||||
{}
|
||||
};
|
||||
//]
|
||||
|
||||
//[ limitations_non_virtual_method_problem_2
|
||||
MOCK_BASE_CLASS( mock_base, base )
|
||||
{
|
||||
MOCK_METHOD( method, 0 )
|
||||
};
|
||||
//]
|
||||
|
|
@ -1,29 +1,29 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
//[ limitations_private_method_problem
|
||||
class base
|
||||
{
|
||||
private:
|
||||
virtual void method() = 0;
|
||||
};
|
||||
//]
|
||||
|
||||
//[ limitations_private_method_solution
|
||||
MOCK_BASE_CLASS( mock_base, base )
|
||||
{
|
||||
MOCK_METHOD( method, 0, void() )
|
||||
};
|
||||
//]
|
||||
}
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
//[ limitations_private_method_problem
|
||||
class base
|
||||
{
|
||||
private:
|
||||
virtual void method() = 0;
|
||||
};
|
||||
//]
|
||||
|
||||
//[ limitations_private_method_solution
|
||||
MOCK_BASE_CLASS( mock_base, base )
|
||||
{
|
||||
MOCK_METHOD( method, 0, void() )
|
||||
};
|
||||
//]
|
||||
}
|
||||
|
|
@ -1,83 +1,83 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace limitations_template_method_problem
|
||||
{
|
||||
//[ limitations_template_method_problem
|
||||
class concept
|
||||
{
|
||||
public:
|
||||
template< typename T >
|
||||
void method( T t )
|
||||
{}
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
void function_under_test( T t ) // T is supposed to model the previous concept
|
||||
{
|
||||
t.method( 42 );
|
||||
t.method( "string" );
|
||||
}
|
||||
//]
|
||||
|
||||
//[ limitations_template_method_solution
|
||||
MOCK_CLASS( mock_concept )
|
||||
{
|
||||
MOCK_METHOD( method, 1, void( int ), method_int )
|
||||
MOCK_METHOD( method, 1, void( const char* ), method_string )
|
||||
};
|
||||
//]
|
||||
}
|
||||
|
||||
namespace limitations_template_method_problem_2
|
||||
{
|
||||
//[ limitations_template_method_problem_2
|
||||
class concept
|
||||
{
|
||||
public:
|
||||
template< typename T >
|
||||
T create()
|
||||
{
|
||||
return T();
|
||||
}
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
void function_under_test( T t ) // T is supposed to model the previous concept
|
||||
{
|
||||
t.create< int >();
|
||||
t.create< std::string >();
|
||||
}
|
||||
//]
|
||||
|
||||
//[ limitations_template_method_solution_2
|
||||
MOCK_CLASS( mock_concept )
|
||||
{
|
||||
template< typename T >
|
||||
T create();
|
||||
|
||||
template<>
|
||||
int create< int >()
|
||||
{
|
||||
return create_int();
|
||||
}
|
||||
template<>
|
||||
std::string create< std::string >()
|
||||
{
|
||||
return create_string();
|
||||
}
|
||||
|
||||
MOCK_METHOD( create_int, 0, int(), create_int )
|
||||
MOCK_METHOD( create_string, 0, std::string(), create_string )
|
||||
};
|
||||
//]
|
||||
}
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace limitations_template_method_problem
|
||||
{
|
||||
//[ limitations_template_method_problem
|
||||
class concept
|
||||
{
|
||||
public:
|
||||
template< typename T >
|
||||
void method( T t )
|
||||
{}
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
void function_under_test( T t ) // T is supposed to model the previous concept
|
||||
{
|
||||
t.method( 42 );
|
||||
t.method( "string" );
|
||||
}
|
||||
//]
|
||||
|
||||
//[ limitations_template_method_solution
|
||||
MOCK_CLASS( mock_concept )
|
||||
{
|
||||
MOCK_METHOD( method, 1, void( int ), method_int )
|
||||
MOCK_METHOD( method, 1, void( const char* ), method_string )
|
||||
};
|
||||
//]
|
||||
}
|
||||
|
||||
namespace limitations_template_method_problem_2
|
||||
{
|
||||
//[ limitations_template_method_problem_2
|
||||
class concept
|
||||
{
|
||||
public:
|
||||
template< typename T >
|
||||
T create()
|
||||
{
|
||||
return T();
|
||||
}
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
void function_under_test( T t ) // T is supposed to model the previous concept
|
||||
{
|
||||
t.create< int >();
|
||||
t.create< std::string >();
|
||||
}
|
||||
//]
|
||||
|
||||
//[ limitations_template_method_solution_2
|
||||
MOCK_CLASS( mock_concept )
|
||||
{
|
||||
template< typename T >
|
||||
T create();
|
||||
|
||||
template<>
|
||||
int create< int >()
|
||||
{
|
||||
return create_int();
|
||||
}
|
||||
template<>
|
||||
std::string create< std::string >()
|
||||
{
|
||||
return create_string();
|
||||
}
|
||||
|
||||
MOCK_METHOD( create_int, 0, int(), create_int )
|
||||
MOCK_METHOD( create_string, 0, std::string(), create_string )
|
||||
};
|
||||
//]
|
||||
}
|
||||
|
|
@ -1,35 +1,35 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
//[ limitations_throw_specifier_problem
|
||||
struct base_class
|
||||
{
|
||||
virtual ~base_class()
|
||||
{}
|
||||
|
||||
virtual void method() throw ();
|
||||
};
|
||||
//]
|
||||
|
||||
//[ limitations_throw_specifier_solution
|
||||
MOCK_BASE_CLASS( mock_class, base_class )
|
||||
{
|
||||
void method() throw ()
|
||||
{
|
||||
method_proxy();
|
||||
}
|
||||
MOCK_METHOD( method_proxy, 0, void(), method )
|
||||
};
|
||||
//]
|
||||
}
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
//[ limitations_throw_specifier_problem
|
||||
struct base_class
|
||||
{
|
||||
virtual ~base_class()
|
||||
{}
|
||||
|
||||
virtual void method() throw ();
|
||||
};
|
||||
//]
|
||||
|
||||
//[ limitations_throw_specifier_solution
|
||||
MOCK_BASE_CLASS( mock_class, base_class )
|
||||
{
|
||||
void method() throw ()
|
||||
{
|
||||
method_proxy();
|
||||
}
|
||||
MOCK_METHOD( method_proxy, 0, void(), method )
|
||||
};
|
||||
//]
|
||||
}
|
||||
|
|
@ -1,76 +1,76 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <boost/mock/mock.hpp>
|
||||
#include "calculator.hpp"
|
||||
#include "mock_view.hpp"
|
||||
|
||||
namespace simple
|
||||
{
|
||||
//[ simple_calculator
|
||||
class calculator
|
||||
{
|
||||
public:
|
||||
int add( int a, int b );
|
||||
};
|
||||
//]
|
||||
|
||||
//[ simple_zero_plus_zero_is_zero
|
||||
BOOST_AUTO_TEST_CASE( zero_plus_zero_is_zero )
|
||||
{
|
||||
calculator c;
|
||||
BOOST_CHECK_EQUAL( 0, c.add( 0, 0 ) );
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace without_mock_object
|
||||
{
|
||||
//[ my_view
|
||||
class my_view : public view
|
||||
{
|
||||
public:
|
||||
my_view()
|
||||
: called( false )
|
||||
{}
|
||||
virtual void display( int result )
|
||||
{
|
||||
called = true;
|
||||
value = result;
|
||||
}
|
||||
bool called;
|
||||
int value;
|
||||
};
|
||||
//]
|
||||
|
||||
//[ zero_plus_zero_is_zero_without_mock_object
|
||||
BOOST_AUTO_TEST_CASE( zero_plus_zero_is_zero )
|
||||
{
|
||||
my_view v;
|
||||
calculator c( v );
|
||||
c.add( 0, 0 );
|
||||
BOOST_REQUIRE( v.called );
|
||||
BOOST_CHECK_EQUAL( 0, v.value );
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace with_mock_object
|
||||
{
|
||||
//[ zero_plus_zero_is_zero_with_mock_object
|
||||
BOOST_AUTO_TEST_CASE( zero_plus_zero_is_zero )
|
||||
{
|
||||
mock_view v;
|
||||
calculator c( v );
|
||||
MOCK_EXPECT( v.display ).once().with( 0 ); // expect the 'display' method to be called once (and only once) with a parameter value equal to 0
|
||||
c.add( 0, 0 );
|
||||
}
|
||||
//]
|
||||
}
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <boost/mock/mock.hpp>
|
||||
#include "calculator.hpp"
|
||||
#include "mock_view.hpp"
|
||||
|
||||
namespace simple
|
||||
{
|
||||
//[ simple_calculator
|
||||
class calculator
|
||||
{
|
||||
public:
|
||||
int add( int a, int b );
|
||||
};
|
||||
//]
|
||||
|
||||
//[ simple_zero_plus_zero_is_zero
|
||||
BOOST_AUTO_TEST_CASE( zero_plus_zero_is_zero )
|
||||
{
|
||||
calculator c;
|
||||
BOOST_CHECK_EQUAL( 0, c.add( 0, 0 ) );
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace without_mock_object
|
||||
{
|
||||
//[ my_view
|
||||
class my_view : public view
|
||||
{
|
||||
public:
|
||||
my_view()
|
||||
: called( false )
|
||||
{}
|
||||
virtual void display( int result )
|
||||
{
|
||||
called = true;
|
||||
value = result;
|
||||
}
|
||||
bool called;
|
||||
int value;
|
||||
};
|
||||
//]
|
||||
|
||||
//[ zero_plus_zero_is_zero_without_mock_object
|
||||
BOOST_AUTO_TEST_CASE( zero_plus_zero_is_zero )
|
||||
{
|
||||
my_view v;
|
||||
calculator c( v );
|
||||
c.add( 0, 0 );
|
||||
BOOST_REQUIRE( v.called );
|
||||
BOOST_CHECK_EQUAL( 0, v.value );
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace with_mock_object
|
||||
{
|
||||
//[ zero_plus_zero_is_zero_with_mock_object
|
||||
BOOST_AUTO_TEST_CASE( zero_plus_zero_is_zero )
|
||||
{
|
||||
mock_view v;
|
||||
calculator c( v );
|
||||
MOCK_EXPECT( v.display ).once().with( 0 ); // expect the 'display' method to be called once (and only once) with a parameter value equal to 0
|
||||
c.add( 0, 0 );
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
|
@ -1,61 +1,61 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
//[ async_call_problem
|
||||
namespace
|
||||
{
|
||||
class base_class
|
||||
{
|
||||
public:
|
||||
virtual void method() = 0;
|
||||
};
|
||||
|
||||
class my_class
|
||||
{
|
||||
public:
|
||||
explicit my_class( base_class& );
|
||||
|
||||
void flush(); // repetitively calling this method will in turn call base_class::method at some point
|
||||
};
|
||||
}
|
||||
//]
|
||||
|
||||
//[ async_call_solution
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <boost/lambda/lambda.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
template< typename F >
|
||||
void wait( bool& condition, F flush, int timeout = 100, int sleep = 100 )
|
||||
{
|
||||
while( !condition && timeout > 0 )
|
||||
{
|
||||
--timeout;
|
||||
boost::this_thread::sleep( boost::posix_time::milliseconds( sleep ) );
|
||||
flush();
|
||||
}
|
||||
}
|
||||
MOCK_BASE_CLASS( mock_base_class, base_class )
|
||||
{
|
||||
MOCK_METHOD( method, 0 )
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( method_is_called )
|
||||
{
|
||||
mock_base_class mock;
|
||||
my_class c( mock );
|
||||
bool done = false;
|
||||
MOCK_EXPECT( mock.method ).once().calls( boost::lambda::var( done ) = true ); // when method is called it will set done to true
|
||||
wait( done, boost::bind( &my_class::flush, &c ) ); // just wait on done, flushing from time to time
|
||||
}
|
||||
//]
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
//[ async_call_problem
|
||||
namespace
|
||||
{
|
||||
class base_class
|
||||
{
|
||||
public:
|
||||
virtual void method() = 0;
|
||||
};
|
||||
|
||||
class my_class
|
||||
{
|
||||
public:
|
||||
explicit my_class( base_class& );
|
||||
|
||||
void flush(); // repetitively calling this method will in turn call base_class::method at some point
|
||||
};
|
||||
}
|
||||
//]
|
||||
|
||||
//[ async_call_solution
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <boost/lambda/lambda.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
template< typename F >
|
||||
void wait( bool& condition, F flush, int timeout = 100, int sleep = 100 )
|
||||
{
|
||||
while( !condition && timeout > 0 )
|
||||
{
|
||||
--timeout;
|
||||
boost::this_thread::sleep( boost::posix_time::milliseconds( sleep ) );
|
||||
flush();
|
||||
}
|
||||
}
|
||||
MOCK_BASE_CLASS( mock_base_class, base_class )
|
||||
{
|
||||
MOCK_METHOD( method, 0 )
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( method_is_called )
|
||||
{
|
||||
mock_base_class mock;
|
||||
my_class c( mock );
|
||||
bool done = false;
|
||||
MOCK_EXPECT( mock.method ).once().calls( boost::lambda::var( done ) = true ); // when method is called it will set done to true
|
||||
wait( done, boost::bind( &my_class::flush, &c ) ); // just wait on done, flushing from time to time
|
||||
}
|
||||
//]
|
||||
|
|
@ -1,44 +1,44 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
//[ invoke_functor_problem
|
||||
#include <boost/function.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
class base_class
|
||||
{
|
||||
public:
|
||||
virtual void method( boost::function< void( int ) > functor ) = 0;
|
||||
};
|
||||
|
||||
void function( base_class& ); // the function will call 'method' with a functor to be applied
|
||||
}
|
||||
//]
|
||||
|
||||
//[ invoke_functor_solution
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <boost/bind/apply.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
MOCK_BASE_CLASS( mock_class, base_class )
|
||||
{
|
||||
MOCK_METHOD( method, 1 )
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( how_to_invoke_a_functor_passed_as_parameter_of_a_mock_method )
|
||||
{
|
||||
mock_class mock;
|
||||
MOCK_EXPECT( mock.method ).calls( boost::bind( boost::apply< void >(), _1, 42 ) ); // whenever 'method' is called, invoke the functor with 42
|
||||
function( mock );
|
||||
}
|
||||
//]
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
//[ invoke_functor_problem
|
||||
#include <boost/function.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
class base_class
|
||||
{
|
||||
public:
|
||||
virtual void method( boost::function< void( int ) > functor ) = 0;
|
||||
};
|
||||
|
||||
void function( base_class& ); // the function will call 'method' with a functor to be applied
|
||||
}
|
||||
//]
|
||||
|
||||
//[ invoke_functor_solution
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <boost/bind/apply.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
MOCK_BASE_CLASS( mock_class, base_class )
|
||||
{
|
||||
MOCK_METHOD( method, 1 )
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( how_to_invoke_a_functor_passed_as_parameter_of_a_mock_method )
|
||||
{
|
||||
mock_class mock;
|
||||
MOCK_EXPECT( mock.method ).calls( boost::bind( boost::apply< void >(), _1, 42 ) ); // whenever 'method' is called, invoke the functor with 42
|
||||
function( mock );
|
||||
}
|
||||
//]
|
||||
|
|
@ -1,54 +1,54 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
//[ quick_constraint_problem
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
#include <iostream>
|
||||
|
||||
namespace
|
||||
{
|
||||
class my_class
|
||||
{
|
||||
public:
|
||||
explicit my_class( int data )
|
||||
: data_( data )
|
||||
{}
|
||||
int data_;
|
||||
};
|
||||
std::ostream& operator<<( std::ostream& os, const my_class& c ) // my_class is serializable to an std::ostream
|
||||
{
|
||||
return os << "my_class( " << c.data_ << " )";
|
||||
}
|
||||
|
||||
MOCK_CLASS( my_mock )
|
||||
{
|
||||
MOCK_METHOD( method, 1, void( const my_class& ) ) // how to simply write a custom constraint ?
|
||||
};
|
||||
}
|
||||
//]
|
||||
|
||||
//[ quick_constraint_solution
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
namespace mock // it could also be in the namespace of 'my_class'
|
||||
{
|
||||
bool operator==( const my_class& actual, const std::string& expected ) // the first part of the trick is to compare to a string
|
||||
{
|
||||
return boost::lexical_cast< std::string >( actual ) == expected;
|
||||
}
|
||||
} // mock
|
||||
|
||||
BOOST_AUTO_TEST_CASE( method_is_called )
|
||||
{
|
||||
my_mock mock;
|
||||
MOCK_EXPECT( mock.method ).once().with( "my_class( 42 )" ); // the second part of the trick is to express the constraint as a string
|
||||
mock.method( my_class( 42 ) );
|
||||
}
|
||||
//]
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
//[ quick_constraint_problem
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
#include <iostream>
|
||||
|
||||
namespace
|
||||
{
|
||||
class my_class
|
||||
{
|
||||
public:
|
||||
explicit my_class( int data )
|
||||
: data_( data )
|
||||
{}
|
||||
int data_;
|
||||
};
|
||||
std::ostream& operator<<( std::ostream& os, const my_class& c ) // my_class is serializable to an std::ostream
|
||||
{
|
||||
return os << "my_class( " << c.data_ << " )";
|
||||
}
|
||||
|
||||
MOCK_CLASS( my_mock )
|
||||
{
|
||||
MOCK_METHOD( method, 1, void( const my_class& ) ) // how to simply write a custom constraint ?
|
||||
};
|
||||
}
|
||||
//]
|
||||
|
||||
//[ quick_constraint_solution
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
namespace mock // it could also be in the namespace of 'my_class'
|
||||
{
|
||||
bool operator==( const my_class& actual, const std::string& expected ) // the first part of the trick is to compare to a string
|
||||
{
|
||||
return boost::lexical_cast< std::string >( actual ) == expected;
|
||||
}
|
||||
} // mock
|
||||
|
||||
BOOST_AUTO_TEST_CASE( method_is_called )
|
||||
{
|
||||
my_mock mock;
|
||||
MOCK_EXPECT( mock.method ).once().with( "my_class( 42 )" ); // the second part of the trick is to express the constraint as a string
|
||||
mock.method( my_class( 42 ) );
|
||||
}
|
||||
//]
|
||||
|
|
@ -1,50 +1,50 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
//[ retrieve_cref_problem
|
||||
namespace
|
||||
{
|
||||
class base_class
|
||||
{
|
||||
public:
|
||||
virtual void method( int value ) = 0;
|
||||
};
|
||||
|
||||
class my_class
|
||||
{
|
||||
public:
|
||||
explicit my_class( base_class& );
|
||||
|
||||
void process(); // the processing will call 'method' two times with the same value, but we don't know what value beforehand
|
||||
};
|
||||
}
|
||||
//]
|
||||
|
||||
//[ retrieve_cref_solution
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
MOCK_BASE_CLASS( mock_base_class, base_class )
|
||||
{
|
||||
MOCK_METHOD( method, 1 )
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( method_is_called_two_times_with_the_same_value )
|
||||
{
|
||||
mock_base_class mock;
|
||||
my_class c( mock );
|
||||
int value;
|
||||
MOCK_EXPECT( mock.method ).once().with( mock::retrieve( value ) ); // on first call retrieve the value, this expectation takes precedence because it can never fail
|
||||
MOCK_EXPECT( mock.method ).once().with( boost::cref( value ) ); // on second call compare the previously retrieved value with the newly received one
|
||||
c.process();
|
||||
}
|
||||
//]
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
//[ retrieve_cref_problem
|
||||
namespace
|
||||
{
|
||||
class base_class
|
||||
{
|
||||
public:
|
||||
virtual void method( int value ) = 0;
|
||||
};
|
||||
|
||||
class my_class
|
||||
{
|
||||
public:
|
||||
explicit my_class( base_class& );
|
||||
|
||||
void process(); // the processing will call 'method' two times with the same value, but we don't know what value beforehand
|
||||
};
|
||||
}
|
||||
//]
|
||||
|
||||
//[ retrieve_cref_solution
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
MOCK_BASE_CLASS( mock_base_class, base_class )
|
||||
{
|
||||
MOCK_METHOD( method, 1 )
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( method_is_called_two_times_with_the_same_value )
|
||||
{
|
||||
mock_base_class mock;
|
||||
my_class c( mock );
|
||||
int value;
|
||||
MOCK_EXPECT( mock.method ).once().with( mock::retrieve( value ) ); // on first call retrieve the value, this expectation takes precedence because it can never fail
|
||||
MOCK_EXPECT( mock.method ).once().with( boost::cref( value ) ); // on second call compare the previously retrieved value with the newly received one
|
||||
c.process();
|
||||
}
|
||||
//]
|
||||
File diff suppressed because it is too large
Load diff
2
doc/html/.gitignore
vendored
Normal file
2
doc/html/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
*.html
|
||||
standalone_HTML.manifest
|
||||
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
|
|
@ -1,85 +1,85 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2009
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// boost-no-inspect
|
||||
|
||||
#ifndef MOCK_CONFIG_HPP_INCLUDED
|
||||
#define MOCK_CONFIG_HPP_INCLUDED
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/preprocessor/arithmetic/inc.hpp>
|
||||
#include <boost/preprocessor/comparison/less.hpp>
|
||||
|
||||
#ifndef MOCK_ERROR_POLICY
|
||||
# define MOCK_ERROR_POLICY mock::error
|
||||
# define MOCK_USE_BOOST_TEST
|
||||
#endif
|
||||
|
||||
#ifndef MOCK_MAX_ARGS
|
||||
# define MOCK_MAX_ARGS 9
|
||||
#endif
|
||||
|
||||
#ifndef MOCK_MAX_SEQUENCES
|
||||
# define MOCK_MAX_SEQUENCES 10
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_FUNCTION_MAX_ARGS
|
||||
# define BOOST_FUNCTION_MAX_ARGS MOCK_MAX_ARGS
|
||||
#elif BOOST_PP_LESS(BOOST_FUNCTION_MAX_ARGS, MOCK_MAX_ARGS)
|
||||
# error BOOST_FUNCTION_MAX_ARGS must be set to MOCK_MAX_ARGS or higher
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_FT_MAX_ARITY
|
||||
# define BOOST_FT_MAX_ARITY BOOST_PP_INC(MOCK_MAX_ARGS)
|
||||
#elif BOOST_PP_LESS_EQUAL(BOOST_FT_MAX_ARITY, MOCK_MAX_ARGS)
|
||||
# error BOOST_FT_MAX_ARITY must be set to MOCK_MAX_ARGS + 1 or higher
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_NULLPTR) && !defined(BOOST_NO_NULLPTR)
|
||||
# ifndef MOCK_NO_NULLPTR
|
||||
# define MOCK_NULLPTR
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_DECLTYPE)
|
||||
# ifndef MOCK_NO_DECLTYPE
|
||||
# define MOCK_DECLTYPE
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_VARIADIC_MACROS) && !defined(BOOST_NO_VARIADIC_MACROS)
|
||||
# ifndef MOCK_NO_VARIADIC_MACROS
|
||||
# define MOCK_VARIADIC_MACROS
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_SMART_PTR) && !defined(BOOST_NO_SMART_PTR)
|
||||
# ifndef MOCK_NO_SMART_PTR
|
||||
# define MOCK_SMART_PTR
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_RVALUE_REFERENCES)
|
||||
# ifndef MOCK_NO_RVALUE_REFERENCES
|
||||
# define MOCK_RVALUE_REFERENCES
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_MUTEX) && !defined(BOOST_NO_0X_HDR_MUTEX)
|
||||
# ifndef MOCK_NO_HDR_MUTEX
|
||||
# define MOCK_HDR_MUTEX
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_LAMBDAS) && !defined(BOOST_NO_LAMBDAS)
|
||||
# ifndef MOCK_NO_LAMBDAS
|
||||
# define MOCK_LAMBDAS
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif // MOCK_CONFIG_HPP_INCLUDED
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2009
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// boost-no-inspect
|
||||
|
||||
#ifndef MOCK_CONFIG_HPP_INCLUDED
|
||||
#define MOCK_CONFIG_HPP_INCLUDED
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/preprocessor/arithmetic/inc.hpp>
|
||||
#include <boost/preprocessor/comparison/less.hpp>
|
||||
|
||||
#ifndef MOCK_ERROR_POLICY
|
||||
# define MOCK_ERROR_POLICY mock::error
|
||||
# define MOCK_USE_BOOST_TEST
|
||||
#endif
|
||||
|
||||
#ifndef MOCK_MAX_ARGS
|
||||
# define MOCK_MAX_ARGS 9
|
||||
#endif
|
||||
|
||||
#ifndef MOCK_MAX_SEQUENCES
|
||||
# define MOCK_MAX_SEQUENCES 10
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_FUNCTION_MAX_ARGS
|
||||
# define BOOST_FUNCTION_MAX_ARGS MOCK_MAX_ARGS
|
||||
#elif BOOST_PP_LESS(BOOST_FUNCTION_MAX_ARGS, MOCK_MAX_ARGS)
|
||||
# error BOOST_FUNCTION_MAX_ARGS must be set to MOCK_MAX_ARGS or higher
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_FT_MAX_ARITY
|
||||
# define BOOST_FT_MAX_ARITY BOOST_PP_INC(MOCK_MAX_ARGS)
|
||||
#elif BOOST_PP_LESS_EQUAL(BOOST_FT_MAX_ARITY, MOCK_MAX_ARGS)
|
||||
# error BOOST_FT_MAX_ARITY must be set to MOCK_MAX_ARGS + 1 or higher
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_NULLPTR) && !defined(BOOST_NO_NULLPTR)
|
||||
# ifndef MOCK_NO_NULLPTR
|
||||
# define MOCK_NULLPTR
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_DECLTYPE)
|
||||
# ifndef MOCK_NO_DECLTYPE
|
||||
# define MOCK_DECLTYPE
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_VARIADIC_MACROS) && !defined(BOOST_NO_VARIADIC_MACROS)
|
||||
# ifndef MOCK_NO_VARIADIC_MACROS
|
||||
# define MOCK_VARIADIC_MACROS
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_SMART_PTR) && !defined(BOOST_NO_SMART_PTR)
|
||||
# ifndef MOCK_NO_SMART_PTR
|
||||
# define MOCK_SMART_PTR
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_RVALUE_REFERENCES)
|
||||
# ifndef MOCK_NO_RVALUE_REFERENCES
|
||||
# define MOCK_RVALUE_REFERENCES
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_MUTEX) && !defined(BOOST_NO_0X_HDR_MUTEX)
|
||||
# ifndef MOCK_NO_HDR_MUTEX
|
||||
# define MOCK_HDR_MUTEX
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_LAMBDAS) && !defined(BOOST_NO_LAMBDAS)
|
||||
# ifndef MOCK_NO_LAMBDAS
|
||||
# define MOCK_LAMBDAS
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif // MOCK_CONFIG_HPP_INCLUDED
|
||||
|
|
@ -1,247 +1,247 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_CONSTRAINT_HPP_INCLUDED
|
||||
#define MOCK_CONSTRAINT_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include "log.hpp"
|
||||
#include <boost/ref.hpp>
|
||||
#include <boost/preprocessor/stringize.hpp>
|
||||
#include <boost/preprocessor/control/if.hpp>
|
||||
#include <boost/preprocessor/variadic/to_array.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_params.hpp>
|
||||
#include <boost/preprocessor/repetition/enum.hpp>
|
||||
#include <boost/preprocessor/array.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
template< typename Constraint >
|
||||
struct constraint
|
||||
{
|
||||
constraint()
|
||||
{}
|
||||
constraint( const Constraint& c )
|
||||
: c_( c )
|
||||
{}
|
||||
Constraint c_;
|
||||
};
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template< typename Lhs, typename Rhs >
|
||||
class and_
|
||||
{
|
||||
public:
|
||||
and_( const Lhs& lhs, const Rhs& rhs )
|
||||
: lhs_( lhs )
|
||||
, rhs_( rhs )
|
||||
{}
|
||||
template< typename Actual >
|
||||
bool operator()( const Actual& actual ) const
|
||||
{
|
||||
return lhs_( actual ) && rhs_( actual );
|
||||
}
|
||||
friend std::ostream& operator<<( std::ostream& s, const and_& a )
|
||||
{
|
||||
return s << "( " << mock::format( a.lhs_ )
|
||||
<< " && " << mock::format( a.rhs_ ) << " )";
|
||||
}
|
||||
private:
|
||||
Lhs lhs_;
|
||||
Rhs rhs_;
|
||||
};
|
||||
|
||||
template< typename Lhs, typename Rhs >
|
||||
class or_
|
||||
{
|
||||
public:
|
||||
or_( const Lhs& lhs, const Rhs& rhs )
|
||||
: lhs_( lhs )
|
||||
, rhs_( rhs )
|
||||
{}
|
||||
template< typename Actual >
|
||||
bool operator()( const Actual& actual ) const
|
||||
{
|
||||
return lhs_( actual ) || rhs_( actual );
|
||||
}
|
||||
friend std::ostream& operator<<( std::ostream& s, const or_& o )
|
||||
{
|
||||
return s << "( " << mock::format( o.lhs_ )
|
||||
<< " || " << mock::format( o.rhs_ )<< " )";
|
||||
}
|
||||
private:
|
||||
Lhs lhs_;
|
||||
Rhs rhs_;
|
||||
};
|
||||
|
||||
template< typename Constraint >
|
||||
class not_
|
||||
{
|
||||
public:
|
||||
explicit not_( const Constraint& c )
|
||||
: c_( c )
|
||||
{}
|
||||
template< typename Actual >
|
||||
bool operator()( const Actual& actual ) const
|
||||
{
|
||||
return ! c_( actual );
|
||||
}
|
||||
friend std::ostream& operator<<( std::ostream& s, const not_& n )
|
||||
{
|
||||
return s << "! " << mock::format( n.c_ );
|
||||
}
|
||||
private:
|
||||
Constraint c_;
|
||||
};
|
||||
}
|
||||
|
||||
template< typename Lhs, typename Rhs >
|
||||
const constraint< detail::or_< Lhs, Rhs > >
|
||||
operator||( const constraint< Lhs >& lhs,
|
||||
const constraint< Rhs >& rhs )
|
||||
{
|
||||
return detail::or_< Lhs, Rhs >( lhs.c_, rhs.c_ );
|
||||
}
|
||||
|
||||
template< typename Lhs, typename Rhs >
|
||||
const constraint< detail::and_< Lhs, Rhs > >
|
||||
operator&&( const constraint< Lhs >& lhs,
|
||||
const constraint< Rhs >& rhs )
|
||||
{
|
||||
return detail::and_< Lhs, Rhs >( lhs.c_, rhs.c_ );
|
||||
}
|
||||
|
||||
template< typename Constraint >
|
||||
const constraint< detail::not_< Constraint > >
|
||||
operator!( const constraint< Constraint >& c )
|
||||
{
|
||||
return detail::not_< Constraint >( c.c_ );
|
||||
}
|
||||
} // mock
|
||||
|
||||
#define MOCK_UNARY_CONSTRAINT(Name, n, Args, Expr) \
|
||||
namespace detail \
|
||||
{ \
|
||||
struct Name \
|
||||
{ \
|
||||
template< typename Actual > \
|
||||
bool operator()( const Actual& actual ) const \
|
||||
{ \
|
||||
return Expr; \
|
||||
} \
|
||||
friend std::ostream& operator<<( std::ostream& s, const Name& ) \
|
||||
{ \
|
||||
return s << BOOST_STRINGIZE(Name); \
|
||||
} \
|
||||
}; \
|
||||
} \
|
||||
const mock::constraint< detail::Name > Name;
|
||||
|
||||
#define MOCK_CONSTRAINT_ASSIGN(z, n, d) \
|
||||
expected##n( e##n )
|
||||
|
||||
#define MOCK_CONSTRAINT_UNWRAP_REF(z, n, d) \
|
||||
boost::unwrap_ref( expected##n )
|
||||
|
||||
#define MOCK_CONSTRAINT_FORMAT(z, n, d) \
|
||||
BOOST_PP_IF(n, << ", " <<,) mock::format( c.expected##n )
|
||||
|
||||
#define MOCK_CONSTRAINT_MEMBER(z, n, d) \
|
||||
Expected_##n expected##n;
|
||||
|
||||
#define MOCK_CONSTRAINT_CREF_PARAM(z, n, Args) \
|
||||
typename \
|
||||
boost::unwrap_reference< Expected_##n >::type \
|
||||
BOOST_PP_ARRAY_ELEM(n, Args)
|
||||
|
||||
#define MOCK_CONSTRAINT_PARAM(z, n, Args) \
|
||||
T##n BOOST_PP_ARRAY_ELEM(n, Args)
|
||||
|
||||
#define MOCK_NARY_CONSTRAINT(Name, n, Args, Expr) \
|
||||
namespace detail \
|
||||
{ \
|
||||
template< BOOST_PP_ENUM_PARAMS(n, typename Expected_) > \
|
||||
struct Name \
|
||||
{ \
|
||||
explicit Name( \
|
||||
BOOST_PP_ENUM_BINARY_PARAMS(n, const Expected_, & e) ) \
|
||||
: BOOST_PP_ENUM(n, MOCK_CONSTRAINT_ASSIGN, _) \
|
||||
{} \
|
||||
template< typename Actual > \
|
||||
bool operator()( const Actual& actual ) const \
|
||||
{ \
|
||||
return test( actual, \
|
||||
BOOST_PP_ENUM(n, MOCK_CONSTRAINT_UNWRAP_REF, _) ); \
|
||||
} \
|
||||
template< typename Actual > \
|
||||
bool test( const Actual& actual, \
|
||||
BOOST_PP_ENUM(n, \
|
||||
MOCK_CONSTRAINT_CREF_PARAM, (n, Args)) ) const \
|
||||
{ \
|
||||
return Expr; \
|
||||
} \
|
||||
friend std::ostream& operator<<( std::ostream& s, const Name& c ) \
|
||||
{ \
|
||||
return s << BOOST_STRINGIZE(Name) << "( " \
|
||||
<< BOOST_PP_REPEAT(n, MOCK_CONSTRAINT_FORMAT, _) \
|
||||
<< " )"; \
|
||||
} \
|
||||
BOOST_PP_REPEAT(n, MOCK_CONSTRAINT_MEMBER, _) \
|
||||
}; \
|
||||
} \
|
||||
template< BOOST_PP_ENUM_PARAMS(n, typename T) > \
|
||||
mock::constraint< \
|
||||
detail::Name< BOOST_PP_ENUM_PARAMS(n, T) > \
|
||||
> Name( BOOST_PP_ENUM(n, MOCK_CONSTRAINT_PARAM, (n, Args)) ) \
|
||||
{ \
|
||||
return detail::Name< BOOST_PP_ENUM_PARAMS(n, T) > Args; \
|
||||
}
|
||||
|
||||
#define MOCK_CONSTRAINT_EXT(Name, n, Args, Expr) \
|
||||
BOOST_PP_IF(n, \
|
||||
MOCK_NARY_CONSTRAINT, \
|
||||
MOCK_UNARY_CONSTRAINT)(Name, n, Args, Expr)
|
||||
|
||||
#ifdef MOCK_VARIADIC_MACROS
|
||||
|
||||
#if BOOST_MSVC
|
||||
# define MOCK_VARIADIC_SIZE(...) \
|
||||
BOOST_PP_CAT(MOCK_VARIADIC_SIZE_I(__VA_ARGS__, \
|
||||
32, 31, 30, 29, 28, 27, 26, 25, 24, 23, \
|
||||
22, 21, 20, 19, 18, 17, 16, 15, 14, 13, \
|
||||
12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1,),)
|
||||
#else // BOOST_MSVC
|
||||
# define MOCK_VARIADIC_SIZE(...) \
|
||||
MOCK_VARIADIC_SIZE_I(__VA_ARGS__, \
|
||||
32, 31, 30, 29, 28, 27, 26, 25, 24, 23, \
|
||||
22, 21, 20, 19, 18, 17, 16, 15, 14, 13, \
|
||||
12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1,)
|
||||
#endif // BOOST_MSVC
|
||||
#define MOCK_VARIADIC_SIZE_I( \
|
||||
e0, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, \
|
||||
e13, e14, e15, e16, e17, e18, e19, e20, e21, e22, e23, e24, \
|
||||
e25, e26, e27, e28, e29, e30, e31, size, ...) size
|
||||
|
||||
#define MOCK_CONSTRAINT_AUX_AUX(Name, n, Array) \
|
||||
MOCK_CONSTRAINT_EXT( \
|
||||
Name, n, \
|
||||
BOOST_PP_ARRAY_TO_TUPLE(BOOST_PP_ARRAY_POP_BACK(Array)), \
|
||||
BOOST_PP_ARRAY_ELEM(n, Array))
|
||||
|
||||
#define MOCK_CONSTRAINT_AUX(Name, Size, Tuple) \
|
||||
MOCK_CONSTRAINT_AUX_AUX(Name, BOOST_PP_DEC(Size), (Size,Tuple))
|
||||
|
||||
#define MOCK_CONSTRAINT(Name, ...) \
|
||||
MOCK_CONSTRAINT_AUX( \
|
||||
Name, MOCK_VARIADIC_SIZE(__VA_ARGS__), (__VA_ARGS__))
|
||||
|
||||
#endif // MOCK_VARIADIC_MACROS
|
||||
|
||||
#endif // MOCK_CONSTRAINT_HPP_INCLUDED
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_CONSTRAINT_HPP_INCLUDED
|
||||
#define MOCK_CONSTRAINT_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include "log.hpp"
|
||||
#include <boost/ref.hpp>
|
||||
#include <boost/preprocessor/stringize.hpp>
|
||||
#include <boost/preprocessor/control/if.hpp>
|
||||
#include <boost/preprocessor/variadic/to_array.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_params.hpp>
|
||||
#include <boost/preprocessor/repetition/enum.hpp>
|
||||
#include <boost/preprocessor/array.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
template< typename Constraint >
|
||||
struct constraint
|
||||
{
|
||||
constraint()
|
||||
{}
|
||||
constraint( const Constraint& c )
|
||||
: c_( c )
|
||||
{}
|
||||
Constraint c_;
|
||||
};
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template< typename Lhs, typename Rhs >
|
||||
class and_
|
||||
{
|
||||
public:
|
||||
and_( const Lhs& lhs, const Rhs& rhs )
|
||||
: lhs_( lhs )
|
||||
, rhs_( rhs )
|
||||
{}
|
||||
template< typename Actual >
|
||||
bool operator()( const Actual& actual ) const
|
||||
{
|
||||
return lhs_( actual ) && rhs_( actual );
|
||||
}
|
||||
friend std::ostream& operator<<( std::ostream& s, const and_& a )
|
||||
{
|
||||
return s << "( " << mock::format( a.lhs_ )
|
||||
<< " && " << mock::format( a.rhs_ ) << " )";
|
||||
}
|
||||
private:
|
||||
Lhs lhs_;
|
||||
Rhs rhs_;
|
||||
};
|
||||
|
||||
template< typename Lhs, typename Rhs >
|
||||
class or_
|
||||
{
|
||||
public:
|
||||
or_( const Lhs& lhs, const Rhs& rhs )
|
||||
: lhs_( lhs )
|
||||
, rhs_( rhs )
|
||||
{}
|
||||
template< typename Actual >
|
||||
bool operator()( const Actual& actual ) const
|
||||
{
|
||||
return lhs_( actual ) || rhs_( actual );
|
||||
}
|
||||
friend std::ostream& operator<<( std::ostream& s, const or_& o )
|
||||
{
|
||||
return s << "( " << mock::format( o.lhs_ )
|
||||
<< " || " << mock::format( o.rhs_ )<< " )";
|
||||
}
|
||||
private:
|
||||
Lhs lhs_;
|
||||
Rhs rhs_;
|
||||
};
|
||||
|
||||
template< typename Constraint >
|
||||
class not_
|
||||
{
|
||||
public:
|
||||
explicit not_( const Constraint& c )
|
||||
: c_( c )
|
||||
{}
|
||||
template< typename Actual >
|
||||
bool operator()( const Actual& actual ) const
|
||||
{
|
||||
return ! c_( actual );
|
||||
}
|
||||
friend std::ostream& operator<<( std::ostream& s, const not_& n )
|
||||
{
|
||||
return s << "! " << mock::format( n.c_ );
|
||||
}
|
||||
private:
|
||||
Constraint c_;
|
||||
};
|
||||
}
|
||||
|
||||
template< typename Lhs, typename Rhs >
|
||||
const constraint< detail::or_< Lhs, Rhs > >
|
||||
operator||( const constraint< Lhs >& lhs,
|
||||
const constraint< Rhs >& rhs )
|
||||
{
|
||||
return detail::or_< Lhs, Rhs >( lhs.c_, rhs.c_ );
|
||||
}
|
||||
|
||||
template< typename Lhs, typename Rhs >
|
||||
const constraint< detail::and_< Lhs, Rhs > >
|
||||
operator&&( const constraint< Lhs >& lhs,
|
||||
const constraint< Rhs >& rhs )
|
||||
{
|
||||
return detail::and_< Lhs, Rhs >( lhs.c_, rhs.c_ );
|
||||
}
|
||||
|
||||
template< typename Constraint >
|
||||
const constraint< detail::not_< Constraint > >
|
||||
operator!( const constraint< Constraint >& c )
|
||||
{
|
||||
return detail::not_< Constraint >( c.c_ );
|
||||
}
|
||||
} // mock
|
||||
|
||||
#define MOCK_UNARY_CONSTRAINT(Name, n, Args, Expr) \
|
||||
namespace detail \
|
||||
{ \
|
||||
struct Name \
|
||||
{ \
|
||||
template< typename Actual > \
|
||||
bool operator()( const Actual& actual ) const \
|
||||
{ \
|
||||
return Expr; \
|
||||
} \
|
||||
friend std::ostream& operator<<( std::ostream& s, const Name& ) \
|
||||
{ \
|
||||
return s << BOOST_STRINGIZE(Name); \
|
||||
} \
|
||||
}; \
|
||||
} \
|
||||
const mock::constraint< detail::Name > Name;
|
||||
|
||||
#define MOCK_CONSTRAINT_ASSIGN(z, n, d) \
|
||||
expected##n( e##n )
|
||||
|
||||
#define MOCK_CONSTRAINT_UNWRAP_REF(z, n, d) \
|
||||
boost::unwrap_ref( expected##n )
|
||||
|
||||
#define MOCK_CONSTRAINT_FORMAT(z, n, d) \
|
||||
BOOST_PP_IF(n, << ", " <<,) mock::format( c.expected##n )
|
||||
|
||||
#define MOCK_CONSTRAINT_MEMBER(z, n, d) \
|
||||
Expected_##n expected##n;
|
||||
|
||||
#define MOCK_CONSTRAINT_CREF_PARAM(z, n, Args) \
|
||||
typename \
|
||||
boost::unwrap_reference< Expected_##n >::type \
|
||||
BOOST_PP_ARRAY_ELEM(n, Args)
|
||||
|
||||
#define MOCK_CONSTRAINT_PARAM(z, n, Args) \
|
||||
T##n BOOST_PP_ARRAY_ELEM(n, Args)
|
||||
|
||||
#define MOCK_NARY_CONSTRAINT(Name, n, Args, Expr) \
|
||||
namespace detail \
|
||||
{ \
|
||||
template< BOOST_PP_ENUM_PARAMS(n, typename Expected_) > \
|
||||
struct Name \
|
||||
{ \
|
||||
explicit Name( \
|
||||
BOOST_PP_ENUM_BINARY_PARAMS(n, const Expected_, & e) ) \
|
||||
: BOOST_PP_ENUM(n, MOCK_CONSTRAINT_ASSIGN, _) \
|
||||
{} \
|
||||
template< typename Actual > \
|
||||
bool operator()( const Actual& actual ) const \
|
||||
{ \
|
||||
return test( actual, \
|
||||
BOOST_PP_ENUM(n, MOCK_CONSTRAINT_UNWRAP_REF, _) ); \
|
||||
} \
|
||||
template< typename Actual > \
|
||||
bool test( const Actual& actual, \
|
||||
BOOST_PP_ENUM(n, \
|
||||
MOCK_CONSTRAINT_CREF_PARAM, (n, Args)) ) const \
|
||||
{ \
|
||||
return Expr; \
|
||||
} \
|
||||
friend std::ostream& operator<<( std::ostream& s, const Name& c ) \
|
||||
{ \
|
||||
return s << BOOST_STRINGIZE(Name) << "( " \
|
||||
<< BOOST_PP_REPEAT(n, MOCK_CONSTRAINT_FORMAT, _) \
|
||||
<< " )"; \
|
||||
} \
|
||||
BOOST_PP_REPEAT(n, MOCK_CONSTRAINT_MEMBER, _) \
|
||||
}; \
|
||||
} \
|
||||
template< BOOST_PP_ENUM_PARAMS(n, typename T) > \
|
||||
mock::constraint< \
|
||||
detail::Name< BOOST_PP_ENUM_PARAMS(n, T) > \
|
||||
> Name( BOOST_PP_ENUM(n, MOCK_CONSTRAINT_PARAM, (n, Args)) ) \
|
||||
{ \
|
||||
return detail::Name< BOOST_PP_ENUM_PARAMS(n, T) > Args; \
|
||||
}
|
||||
|
||||
#define MOCK_CONSTRAINT_EXT(Name, n, Args, Expr) \
|
||||
BOOST_PP_IF(n, \
|
||||
MOCK_NARY_CONSTRAINT, \
|
||||
MOCK_UNARY_CONSTRAINT)(Name, n, Args, Expr)
|
||||
|
||||
#ifdef MOCK_VARIADIC_MACROS
|
||||
|
||||
#if BOOST_MSVC
|
||||
# define MOCK_VARIADIC_SIZE(...) \
|
||||
BOOST_PP_CAT(MOCK_VARIADIC_SIZE_I(__VA_ARGS__, \
|
||||
32, 31, 30, 29, 28, 27, 26, 25, 24, 23, \
|
||||
22, 21, 20, 19, 18, 17, 16, 15, 14, 13, \
|
||||
12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1,),)
|
||||
#else // BOOST_MSVC
|
||||
# define MOCK_VARIADIC_SIZE(...) \
|
||||
MOCK_VARIADIC_SIZE_I(__VA_ARGS__, \
|
||||
32, 31, 30, 29, 28, 27, 26, 25, 24, 23, \
|
||||
22, 21, 20, 19, 18, 17, 16, 15, 14, 13, \
|
||||
12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1,)
|
||||
#endif // BOOST_MSVC
|
||||
#define MOCK_VARIADIC_SIZE_I( \
|
||||
e0, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, \
|
||||
e13, e14, e15, e16, e17, e18, e19, e20, e21, e22, e23, e24, \
|
||||
e25, e26, e27, e28, e29, e30, e31, size, ...) size
|
||||
|
||||
#define MOCK_CONSTRAINT_AUX_AUX(Name, n, Array) \
|
||||
MOCK_CONSTRAINT_EXT( \
|
||||
Name, n, \
|
||||
BOOST_PP_ARRAY_TO_TUPLE(BOOST_PP_ARRAY_POP_BACK(Array)), \
|
||||
BOOST_PP_ARRAY_ELEM(n, Array))
|
||||
|
||||
#define MOCK_CONSTRAINT_AUX(Name, Size, Tuple) \
|
||||
MOCK_CONSTRAINT_AUX_AUX(Name, BOOST_PP_DEC(Size), (Size,Tuple))
|
||||
|
||||
#define MOCK_CONSTRAINT(Name, ...) \
|
||||
MOCK_CONSTRAINT_AUX( \
|
||||
Name, MOCK_VARIADIC_SIZE(__VA_ARGS__), (__VA_ARGS__))
|
||||
|
||||
#endif // MOCK_VARIADIC_MACROS
|
||||
|
||||
#endif // MOCK_CONSTRAINT_HPP_INCLUDED
|
||||
|
|
@ -1,201 +1,201 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_CONSTRAINTS_HPP_INCLUDED
|
||||
#define MOCK_CONSTRAINTS_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include "constraint.hpp"
|
||||
#include "detail/addressof.hpp"
|
||||
#include <boost/ref.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/type_traits/is_convertible.hpp>
|
||||
#include <boost/test/floating_point_comparison.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
MOCK_UNARY_CONSTRAINT( any, 0,, true && &actual )
|
||||
MOCK_UNARY_CONSTRAINT( affirm, 0,, !! actual )
|
||||
MOCK_UNARY_CONSTRAINT( negate, 0,, ! actual )
|
||||
MOCK_UNARY_CONSTRAINT( evaluate, 0,, actual() )
|
||||
|
||||
MOCK_NARY_CONSTRAINT( equal, 1, ( expected ), actual == expected )
|
||||
MOCK_NARY_CONSTRAINT( less, 1, ( expected ), actual < expected )
|
||||
MOCK_NARY_CONSTRAINT( greater, 1, ( expected ), actual > expected )
|
||||
MOCK_NARY_CONSTRAINT( less_equal, 1, ( expected ), actual <= expected )
|
||||
MOCK_NARY_CONSTRAINT( greater_equal, 1, ( expected ), actual >= expected )
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
# pragma push_macro( "small" )
|
||||
# undef small
|
||||
#endif
|
||||
MOCK_NARY_CONSTRAINT( small, 1, ( expected ), \
|
||||
( boost::test_tools::check_is_small( actual, expected ) ) )
|
||||
#ifdef BOOST_MSVC
|
||||
# pragma pop_macro( "small" )
|
||||
#endif
|
||||
|
||||
MOCK_NARY_CONSTRAINT( close, 2, ( expected, tolerance ), \
|
||||
( boost::test_tools::check_is_close( \
|
||||
actual, expected, \
|
||||
boost::test_tools::percent_tolerance( tolerance ) ) ) )
|
||||
MOCK_NARY_CONSTRAINT( close_fraction, 2, ( expected, tolerance ), \
|
||||
( boost::test_tools::check_is_close( \
|
||||
actual, expected, \
|
||||
boost::test_tools::fraction_tolerance( tolerance ) ) ) )
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
# pragma push_macro( "near" )
|
||||
# undef near
|
||||
#endif
|
||||
MOCK_NARY_CONSTRAINT( near, 2, ( expected, tolerance ), \
|
||||
std::abs( actual - expected ) < tolerance )
|
||||
#ifdef BOOST_MSVC
|
||||
# pragma pop_macro( "near" )
|
||||
#endif
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template< typename Expected >
|
||||
struct same
|
||||
{
|
||||
explicit same( const Expected& expected )
|
||||
: expected_( detail::addressof( boost::unwrap_ref( expected ) ) )
|
||||
{}
|
||||
template< typename Actual >
|
||||
bool operator()( const Actual& actual ) const
|
||||
{
|
||||
return detail::addressof( actual ) == expected_;
|
||||
}
|
||||
friend std::ostream& operator<<( std::ostream& os, const same& s )
|
||||
{
|
||||
return os << "same( " << mock::format( *s.expected_ ) << " )";
|
||||
}
|
||||
const typename
|
||||
boost::unwrap_reference< Expected >::type* expected_;
|
||||
};
|
||||
|
||||
template< typename Expected >
|
||||
struct retrieve
|
||||
{
|
||||
explicit retrieve( Expected& expected )
|
||||
: expected_( detail::addressof( boost::unwrap_ref( expected ) ) )
|
||||
{}
|
||||
template< typename Actual >
|
||||
bool operator()( const Actual& actual,
|
||||
typename boost::disable_if<
|
||||
boost::is_convertible<
|
||||
const Actual*,
|
||||
typename
|
||||
boost::unwrap_reference< Expected >::type
|
||||
>
|
||||
>::type* = 0 ) const
|
||||
{
|
||||
*expected_ = actual;
|
||||
return true;
|
||||
}
|
||||
template< typename Actual >
|
||||
bool operator()( Actual& actual,
|
||||
typename boost::enable_if<
|
||||
boost::is_convertible< Actual*,
|
||||
typename
|
||||
boost::unwrap_reference< Expected >::type
|
||||
>
|
||||
>::type* = 0 ) const
|
||||
{
|
||||
*expected_ = detail::addressof( actual );
|
||||
return true;
|
||||
}
|
||||
friend std::ostream& operator<<( std::ostream& s, const retrieve& r )
|
||||
{
|
||||
return s << "retrieve( " << mock::format( *r.expected_ ) << " )";
|
||||
}
|
||||
typename
|
||||
boost::unwrap_reference< Expected >::type* expected_;
|
||||
};
|
||||
|
||||
template< typename Expected >
|
||||
struct assign
|
||||
{
|
||||
explicit assign( const Expected& expected )
|
||||
: expected_( expected )
|
||||
{}
|
||||
template< typename Actual >
|
||||
bool operator()( Actual& actual ) const
|
||||
{
|
||||
actual = boost::unwrap_ref( expected_ );
|
||||
return true;
|
||||
}
|
||||
template< typename Actual >
|
||||
bool operator()( Actual* actual,
|
||||
typename boost::enable_if<
|
||||
boost::is_convertible<
|
||||
typename
|
||||
boost::unwrap_reference< Expected >::type,
|
||||
Actual
|
||||
>
|
||||
>::type* = 0 ) const
|
||||
{
|
||||
*actual = boost::unwrap_ref( expected_ );
|
||||
return true;
|
||||
}
|
||||
friend std::ostream& operator<<( std::ostream& s, const assign& a )
|
||||
{
|
||||
return s << "assign( " << mock::format( a.expected_ ) << " )";
|
||||
}
|
||||
Expected expected_;
|
||||
};
|
||||
|
||||
template< typename Expected >
|
||||
struct contain
|
||||
{
|
||||
explicit contain( const Expected& expected )
|
||||
: expected_( expected )
|
||||
{}
|
||||
bool operator()( const std::string& actual ) const
|
||||
{
|
||||
return actual.find( boost::unwrap_ref( expected_ ) )
|
||||
!= std::string::npos;
|
||||
}
|
||||
friend std::ostream& operator<<( std::ostream& s, const contain& n )
|
||||
{
|
||||
return s << "contain( " << mock::format( n.expected_ ) << " )";
|
||||
}
|
||||
Expected expected_;
|
||||
};
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
constraint< detail::same< T > > same( T& t )
|
||||
{
|
||||
return detail::same< T >( t );
|
||||
}
|
||||
template< typename T >
|
||||
constraint< detail::retrieve< T > > retrieve( T& t )
|
||||
{
|
||||
return detail::retrieve< T >( t );
|
||||
}
|
||||
template< typename T >
|
||||
constraint< detail::assign< T > > assign( T t )
|
||||
{
|
||||
return detail::assign< T >( t );
|
||||
}
|
||||
template< typename T >
|
||||
constraint< detail::contain< T > > contain( T t )
|
||||
{
|
||||
return detail::contain< T >( t );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
constraint< T > call( T t )
|
||||
{
|
||||
return constraint< T >( t );
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_CONSTRAINTS_HPP_INCLUDED
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_CONSTRAINTS_HPP_INCLUDED
|
||||
#define MOCK_CONSTRAINTS_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include "constraint.hpp"
|
||||
#include "detail/addressof.hpp"
|
||||
#include <boost/ref.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/type_traits/is_convertible.hpp>
|
||||
#include <boost/test/floating_point_comparison.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
MOCK_UNARY_CONSTRAINT( any, 0,, true && &actual )
|
||||
MOCK_UNARY_CONSTRAINT( affirm, 0,, !! actual )
|
||||
MOCK_UNARY_CONSTRAINT( negate, 0,, ! actual )
|
||||
MOCK_UNARY_CONSTRAINT( evaluate, 0,, actual() )
|
||||
|
||||
MOCK_NARY_CONSTRAINT( equal, 1, ( expected ), actual == expected )
|
||||
MOCK_NARY_CONSTRAINT( less, 1, ( expected ), actual < expected )
|
||||
MOCK_NARY_CONSTRAINT( greater, 1, ( expected ), actual > expected )
|
||||
MOCK_NARY_CONSTRAINT( less_equal, 1, ( expected ), actual <= expected )
|
||||
MOCK_NARY_CONSTRAINT( greater_equal, 1, ( expected ), actual >= expected )
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
# pragma push_macro( "small" )
|
||||
# undef small
|
||||
#endif
|
||||
MOCK_NARY_CONSTRAINT( small, 1, ( expected ), \
|
||||
( boost::test_tools::check_is_small( actual, expected ) ) )
|
||||
#ifdef BOOST_MSVC
|
||||
# pragma pop_macro( "small" )
|
||||
#endif
|
||||
|
||||
MOCK_NARY_CONSTRAINT( close, 2, ( expected, tolerance ), \
|
||||
( boost::test_tools::check_is_close( \
|
||||
actual, expected, \
|
||||
boost::test_tools::percent_tolerance( tolerance ) ) ) )
|
||||
MOCK_NARY_CONSTRAINT( close_fraction, 2, ( expected, tolerance ), \
|
||||
( boost::test_tools::check_is_close( \
|
||||
actual, expected, \
|
||||
boost::test_tools::fraction_tolerance( tolerance ) ) ) )
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
# pragma push_macro( "near" )
|
||||
# undef near
|
||||
#endif
|
||||
MOCK_NARY_CONSTRAINT( near, 2, ( expected, tolerance ), \
|
||||
std::abs( actual - expected ) < tolerance )
|
||||
#ifdef BOOST_MSVC
|
||||
# pragma pop_macro( "near" )
|
||||
#endif
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template< typename Expected >
|
||||
struct same
|
||||
{
|
||||
explicit same( const Expected& expected )
|
||||
: expected_( detail::addressof( boost::unwrap_ref( expected ) ) )
|
||||
{}
|
||||
template< typename Actual >
|
||||
bool operator()( const Actual& actual ) const
|
||||
{
|
||||
return detail::addressof( actual ) == expected_;
|
||||
}
|
||||
friend std::ostream& operator<<( std::ostream& os, const same& s )
|
||||
{
|
||||
return os << "same( " << mock::format( *s.expected_ ) << " )";
|
||||
}
|
||||
const typename
|
||||
boost::unwrap_reference< Expected >::type* expected_;
|
||||
};
|
||||
|
||||
template< typename Expected >
|
||||
struct retrieve
|
||||
{
|
||||
explicit retrieve( Expected& expected )
|
||||
: expected_( detail::addressof( boost::unwrap_ref( expected ) ) )
|
||||
{}
|
||||
template< typename Actual >
|
||||
bool operator()( const Actual& actual,
|
||||
typename boost::disable_if<
|
||||
boost::is_convertible<
|
||||
const Actual*,
|
||||
typename
|
||||
boost::unwrap_reference< Expected >::type
|
||||
>
|
||||
>::type* = 0 ) const
|
||||
{
|
||||
*expected_ = actual;
|
||||
return true;
|
||||
}
|
||||
template< typename Actual >
|
||||
bool operator()( Actual& actual,
|
||||
typename boost::enable_if<
|
||||
boost::is_convertible< Actual*,
|
||||
typename
|
||||
boost::unwrap_reference< Expected >::type
|
||||
>
|
||||
>::type* = 0 ) const
|
||||
{
|
||||
*expected_ = detail::addressof( actual );
|
||||
return true;
|
||||
}
|
||||
friend std::ostream& operator<<( std::ostream& s, const retrieve& r )
|
||||
{
|
||||
return s << "retrieve( " << mock::format( *r.expected_ ) << " )";
|
||||
}
|
||||
typename
|
||||
boost::unwrap_reference< Expected >::type* expected_;
|
||||
};
|
||||
|
||||
template< typename Expected >
|
||||
struct assign
|
||||
{
|
||||
explicit assign( const Expected& expected )
|
||||
: expected_( expected )
|
||||
{}
|
||||
template< typename Actual >
|
||||
bool operator()( Actual& actual ) const
|
||||
{
|
||||
actual = boost::unwrap_ref( expected_ );
|
||||
return true;
|
||||
}
|
||||
template< typename Actual >
|
||||
bool operator()( Actual* actual,
|
||||
typename boost::enable_if<
|
||||
boost::is_convertible<
|
||||
typename
|
||||
boost::unwrap_reference< Expected >::type,
|
||||
Actual
|
||||
>
|
||||
>::type* = 0 ) const
|
||||
{
|
||||
*actual = boost::unwrap_ref( expected_ );
|
||||
return true;
|
||||
}
|
||||
friend std::ostream& operator<<( std::ostream& s, const assign& a )
|
||||
{
|
||||
return s << "assign( " << mock::format( a.expected_ ) << " )";
|
||||
}
|
||||
Expected expected_;
|
||||
};
|
||||
|
||||
template< typename Expected >
|
||||
struct contain
|
||||
{
|
||||
explicit contain( const Expected& expected )
|
||||
: expected_( expected )
|
||||
{}
|
||||
bool operator()( const std::string& actual ) const
|
||||
{
|
||||
return actual.find( boost::unwrap_ref( expected_ ) )
|
||||
!= std::string::npos;
|
||||
}
|
||||
friend std::ostream& operator<<( std::ostream& s, const contain& n )
|
||||
{
|
||||
return s << "contain( " << mock::format( n.expected_ ) << " )";
|
||||
}
|
||||
Expected expected_;
|
||||
};
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
constraint< detail::same< T > > same( T& t )
|
||||
{
|
||||
return detail::same< T >( t );
|
||||
}
|
||||
template< typename T >
|
||||
constraint< detail::retrieve< T > > retrieve( T& t )
|
||||
{
|
||||
return detail::retrieve< T >( t );
|
||||
}
|
||||
template< typename T >
|
||||
constraint< detail::assign< T > > assign( T t )
|
||||
{
|
||||
return detail::assign< T >( t );
|
||||
}
|
||||
template< typename T >
|
||||
constraint< detail::contain< T > > contain( T t )
|
||||
{
|
||||
return detail::contain< T >( t );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
constraint< T > call( T t )
|
||||
{
|
||||
return constraint< T >( t );
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_CONSTRAINTS_HPP_INCLUDED
|
||||
|
|
@ -1,214 +1,214 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_ACTION_HPP_INCLUDED
|
||||
#define MOCK_ACTION_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include <boost/type_traits/remove_reference.hpp>
|
||||
#include <boost/type_traits/remove_const.hpp>
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/move/move.hpp>
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/ref.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template< typename Result, typename Signature >
|
||||
class action_base
|
||||
{
|
||||
private:
|
||||
typedef boost::function< Signature > functor_type;
|
||||
typedef boost::function< Result() > action_type;
|
||||
|
||||
public:
|
||||
const functor_type& functor() const
|
||||
{
|
||||
return f_;
|
||||
}
|
||||
bool valid() const
|
||||
{
|
||||
return f_ || a_;
|
||||
}
|
||||
Result trigger() const
|
||||
{
|
||||
return a_();
|
||||
}
|
||||
|
||||
void calls( const functor_type& f )
|
||||
{
|
||||
if( ! f )
|
||||
throw std::invalid_argument( "null functor" );
|
||||
f_ = f;
|
||||
}
|
||||
|
||||
template< typename Exception >
|
||||
void throws( Exception e )
|
||||
{
|
||||
a_ = boost::bind( &do_throw< Exception >, e );
|
||||
}
|
||||
|
||||
protected:
|
||||
void set( const action_type& a )
|
||||
{
|
||||
a_ = a;
|
||||
}
|
||||
template< typename Y >
|
||||
void set( const boost::reference_wrapper< Y >& r )
|
||||
{
|
||||
a_ = boost::bind( &do_ref< Y >, r.get_pointer() );
|
||||
}
|
||||
|
||||
private:
|
||||
template< typename T >
|
||||
static T& do_ref( T* t )
|
||||
{
|
||||
return *t;
|
||||
}
|
||||
template< typename T >
|
||||
static Result do_throw( T t )
|
||||
{
|
||||
throw t;
|
||||
}
|
||||
|
||||
functor_type f_;
|
||||
action_type a_;
|
||||
};
|
||||
|
||||
template< typename Result, typename Signature >
|
||||
class action : public action_base< Result, Signature >
|
||||
{
|
||||
public:
|
||||
template< typename Value >
|
||||
void returns( const Value& v )
|
||||
{
|
||||
this->set( boost::ref( store( v ) ) );
|
||||
}
|
||||
template< typename Y >
|
||||
void returns( const boost::reference_wrapper< Y >& r )
|
||||
{
|
||||
this->set( r );
|
||||
}
|
||||
|
||||
template< typename Value >
|
||||
void moves( BOOST_RV_REF( Value ) v )
|
||||
{
|
||||
this->set(
|
||||
boost::bind(
|
||||
&boost::move< BOOST_RV_REF( Value ) >,
|
||||
boost::ref( store( boost::move( v ) ) ) ) );
|
||||
}
|
||||
|
||||
private:
|
||||
struct value : boost::noncopyable
|
||||
{
|
||||
virtual ~value()
|
||||
{}
|
||||
};
|
||||
template< typename T >
|
||||
struct value_imp : value
|
||||
{
|
||||
typedef
|
||||
typename boost::remove_const<
|
||||
typename boost::remove_reference<
|
||||
T
|
||||
>::type
|
||||
>::type value_type;
|
||||
|
||||
value_imp( BOOST_RV_REF( value_type ) t )
|
||||
: t_( boost::move( t ) )
|
||||
{}
|
||||
value_imp( const T& t )
|
||||
: t_( t )
|
||||
{}
|
||||
template< typename Y >
|
||||
value_imp( Y* y )
|
||||
: t_( y )
|
||||
{}
|
||||
value_type t_;
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
T& store( BOOST_RV_REF( T ) t )
|
||||
{
|
||||
v_.reset( new value_imp< T >( boost::move( t ) ) );
|
||||
return static_cast< value_imp< T >& >( *v_ ).t_;
|
||||
}
|
||||
template< typename T >
|
||||
T& store( const T& t )
|
||||
{
|
||||
v_.reset( new value_imp< T >( t ) );
|
||||
return static_cast< value_imp< T >& >( *v_ ).t_;
|
||||
}
|
||||
template< typename T >
|
||||
Result& store( T* t )
|
||||
{
|
||||
v_.reset( new value_imp< Result >( t ) );
|
||||
return static_cast< value_imp< Result >& >( *v_ ).t_;
|
||||
}
|
||||
|
||||
boost::shared_ptr< value > v_;
|
||||
};
|
||||
|
||||
template< typename Signature >
|
||||
class action< void, Signature > : public action_base< void, Signature >
|
||||
{
|
||||
public:
|
||||
action()
|
||||
{
|
||||
this->set( boost::bind( &do_nothing ) );
|
||||
}
|
||||
|
||||
private:
|
||||
static void do_nothing()
|
||||
{}
|
||||
};
|
||||
|
||||
template< typename Result, typename Signature >
|
||||
class action< std::auto_ptr< Result >, Signature >
|
||||
: public action_base< std::auto_ptr< Result >, Signature >
|
||||
{
|
||||
public:
|
||||
action()
|
||||
{}
|
||||
action( const action& rhs )
|
||||
: v_( rhs.v_.release() )
|
||||
{
|
||||
if( v_.get() )
|
||||
returns( boost::ref( v_ ) );
|
||||
}
|
||||
|
||||
template< typename Y >
|
||||
void returns( Y* r )
|
||||
{
|
||||
v_.reset( r );
|
||||
this->set( boost::ref( v_ ) );
|
||||
}
|
||||
template< typename Y >
|
||||
void returns( std::auto_ptr< Y > r )
|
||||
{
|
||||
v_ = r;
|
||||
this->set( boost::ref( v_ ) );
|
||||
}
|
||||
template< typename Y >
|
||||
void returns( const boost::reference_wrapper< Y >& r )
|
||||
{
|
||||
this->set( r );
|
||||
}
|
||||
|
||||
private:
|
||||
mutable std::auto_ptr< Result > v_;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_ACTION_HPP_INCLUDED
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_ACTION_HPP_INCLUDED
|
||||
#define MOCK_ACTION_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include <boost/type_traits/remove_reference.hpp>
|
||||
#include <boost/type_traits/remove_const.hpp>
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/move/move.hpp>
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/ref.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template< typename Result, typename Signature >
|
||||
class action_base
|
||||
{
|
||||
private:
|
||||
typedef boost::function< Signature > functor_type;
|
||||
typedef boost::function< Result() > action_type;
|
||||
|
||||
public:
|
||||
const functor_type& functor() const
|
||||
{
|
||||
return f_;
|
||||
}
|
||||
bool valid() const
|
||||
{
|
||||
return f_ || a_;
|
||||
}
|
||||
Result trigger() const
|
||||
{
|
||||
return a_();
|
||||
}
|
||||
|
||||
void calls( const functor_type& f )
|
||||
{
|
||||
if( ! f )
|
||||
throw std::invalid_argument( "null functor" );
|
||||
f_ = f;
|
||||
}
|
||||
|
||||
template< typename Exception >
|
||||
void throws( Exception e )
|
||||
{
|
||||
a_ = boost::bind( &do_throw< Exception >, e );
|
||||
}
|
||||
|
||||
protected:
|
||||
void set( const action_type& a )
|
||||
{
|
||||
a_ = a;
|
||||
}
|
||||
template< typename Y >
|
||||
void set( const boost::reference_wrapper< Y >& r )
|
||||
{
|
||||
a_ = boost::bind( &do_ref< Y >, r.get_pointer() );
|
||||
}
|
||||
|
||||
private:
|
||||
template< typename T >
|
||||
static T& do_ref( T* t )
|
||||
{
|
||||
return *t;
|
||||
}
|
||||
template< typename T >
|
||||
static Result do_throw( T t )
|
||||
{
|
||||
throw t;
|
||||
}
|
||||
|
||||
functor_type f_;
|
||||
action_type a_;
|
||||
};
|
||||
|
||||
template< typename Result, typename Signature >
|
||||
class action : public action_base< Result, Signature >
|
||||
{
|
||||
public:
|
||||
template< typename Value >
|
||||
void returns( const Value& v )
|
||||
{
|
||||
this->set( boost::ref( store( v ) ) );
|
||||
}
|
||||
template< typename Y >
|
||||
void returns( const boost::reference_wrapper< Y >& r )
|
||||
{
|
||||
this->set( r );
|
||||
}
|
||||
|
||||
template< typename Value >
|
||||
void moves( BOOST_RV_REF( Value ) v )
|
||||
{
|
||||
this->set(
|
||||
boost::bind(
|
||||
&boost::move< BOOST_RV_REF( Value ) >,
|
||||
boost::ref( store( boost::move( v ) ) ) ) );
|
||||
}
|
||||
|
||||
private:
|
||||
struct value : boost::noncopyable
|
||||
{
|
||||
virtual ~value()
|
||||
{}
|
||||
};
|
||||
template< typename T >
|
||||
struct value_imp : value
|
||||
{
|
||||
typedef
|
||||
typename boost::remove_const<
|
||||
typename boost::remove_reference<
|
||||
T
|
||||
>::type
|
||||
>::type value_type;
|
||||
|
||||
value_imp( BOOST_RV_REF( value_type ) t )
|
||||
: t_( boost::move( t ) )
|
||||
{}
|
||||
value_imp( const T& t )
|
||||
: t_( t )
|
||||
{}
|
||||
template< typename Y >
|
||||
value_imp( Y* y )
|
||||
: t_( y )
|
||||
{}
|
||||
value_type t_;
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
T& store( BOOST_RV_REF( T ) t )
|
||||
{
|
||||
v_.reset( new value_imp< T >( boost::move( t ) ) );
|
||||
return static_cast< value_imp< T >& >( *v_ ).t_;
|
||||
}
|
||||
template< typename T >
|
||||
T& store( const T& t )
|
||||
{
|
||||
v_.reset( new value_imp< T >( t ) );
|
||||
return static_cast< value_imp< T >& >( *v_ ).t_;
|
||||
}
|
||||
template< typename T >
|
||||
Result& store( T* t )
|
||||
{
|
||||
v_.reset( new value_imp< Result >( t ) );
|
||||
return static_cast< value_imp< Result >& >( *v_ ).t_;
|
||||
}
|
||||
|
||||
boost::shared_ptr< value > v_;
|
||||
};
|
||||
|
||||
template< typename Signature >
|
||||
class action< void, Signature > : public action_base< void, Signature >
|
||||
{
|
||||
public:
|
||||
action()
|
||||
{
|
||||
this->set( boost::bind( &do_nothing ) );
|
||||
}
|
||||
|
||||
private:
|
||||
static void do_nothing()
|
||||
{}
|
||||
};
|
||||
|
||||
template< typename Result, typename Signature >
|
||||
class action< std::auto_ptr< Result >, Signature >
|
||||
: public action_base< std::auto_ptr< Result >, Signature >
|
||||
{
|
||||
public:
|
||||
action()
|
||||
{}
|
||||
action( const action& rhs )
|
||||
: v_( rhs.v_.release() )
|
||||
{
|
||||
if( v_.get() )
|
||||
returns( boost::ref( v_ ) );
|
||||
}
|
||||
|
||||
template< typename Y >
|
||||
void returns( Y* r )
|
||||
{
|
||||
v_.reset( r );
|
||||
this->set( boost::ref( v_ ) );
|
||||
}
|
||||
template< typename Y >
|
||||
void returns( std::auto_ptr< Y > r )
|
||||
{
|
||||
v_ = r;
|
||||
this->set( boost::ref( v_ ) );
|
||||
}
|
||||
template< typename Y >
|
||||
void returns( const boost::reference_wrapper< Y >& r )
|
||||
{
|
||||
this->set( r );
|
||||
}
|
||||
|
||||
private:
|
||||
mutable std::auto_ptr< Result > v_;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_ACTION_HPP_INCLUDED
|
||||
|
|
@ -1,36 +1,36 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2013
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_ADDRESSOF_HPP_INCLUDED
|
||||
#define MOCK_ADDRESSOF_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include <boost/utility/addressof.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
using boost::addressof;
|
||||
|
||||
#ifdef MOCK_NULLPTR
|
||||
|
||||
inline const std::nullptr_t* addressof( const std::nullptr_t& p )
|
||||
{
|
||||
return &p;
|
||||
}
|
||||
inline std::nullptr_t* addressof( std::nullptr_t& p )
|
||||
{
|
||||
return &p;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_ADDRESSOF_HPP_INCLUDED
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2013
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_ADDRESSOF_HPP_INCLUDED
|
||||
#define MOCK_ADDRESSOF_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include <boost/utility/addressof.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
using boost::addressof;
|
||||
|
||||
#ifdef MOCK_NULLPTR
|
||||
|
||||
inline const std::nullptr_t* addressof( const std::nullptr_t& p )
|
||||
{
|
||||
return &p;
|
||||
}
|
||||
inline std::nullptr_t* addressof( std::nullptr_t& p )
|
||||
{
|
||||
return &p;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_ADDRESSOF_HPP_INCLUDED
|
||||
|
|
@ -1,52 +1,52 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2011
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_CHILD_HPP_INCLUDED
|
||||
#define MOCK_CHILD_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include "type_name.hpp"
|
||||
#include "parent.hpp"
|
||||
#include <boost/test/utils/basic_cstring/basic_cstring.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <ostream>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
class child
|
||||
{
|
||||
public:
|
||||
child()
|
||||
: parent_( 0 )
|
||||
{}
|
||||
void update( parent& p,
|
||||
boost::unit_test::const_string instance,
|
||||
boost::optional< type_name > type,
|
||||
boost::unit_test::const_string name )
|
||||
{
|
||||
if( instance != "?." || name_.empty() )
|
||||
p = parent( instance, type );
|
||||
parent_ = &p;
|
||||
name_ = name;
|
||||
}
|
||||
friend std::ostream& operator<<( std::ostream& s, const child& c )
|
||||
{
|
||||
if( c.parent_ )
|
||||
s << *c.parent_;
|
||||
return s << c.name_;
|
||||
}
|
||||
private:
|
||||
const parent* parent_;
|
||||
boost::unit_test::const_string name_;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_CHILD_HPP_INCLUDED
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2011
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_CHILD_HPP_INCLUDED
|
||||
#define MOCK_CHILD_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include "type_name.hpp"
|
||||
#include "parent.hpp"
|
||||
#include <boost/test/utils/basic_cstring/basic_cstring.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <ostream>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
class child
|
||||
{
|
||||
public:
|
||||
child()
|
||||
: parent_( 0 )
|
||||
{}
|
||||
void update( parent& p,
|
||||
boost::unit_test::const_string instance,
|
||||
boost::optional< type_name > type,
|
||||
boost::unit_test::const_string name )
|
||||
{
|
||||
if( instance != "?." || name_.empty() )
|
||||
p = parent( instance, type );
|
||||
parent_ = &p;
|
||||
name_ = name;
|
||||
}
|
||||
friend std::ostream& operator<<( std::ostream& s, const child& c )
|
||||
{
|
||||
if( c.parent_ )
|
||||
s << *c.parent_;
|
||||
return s << c.name_;
|
||||
}
|
||||
private:
|
||||
const parent* parent_;
|
||||
boost::unit_test::const_string name_;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_CHILD_HPP_INCLUDED
|
||||
|
|
@ -1,37 +1,37 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2011
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_CLEANUP_HPP_INCLUDED
|
||||
#define MOCK_CLEANUP_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#ifdef MOCK_USE_BOOST_TEST
|
||||
#include "../verify.hpp"
|
||||
#include "../reset.hpp"
|
||||
#include <boost/test/unit_test_suite.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
struct cleanup
|
||||
{
|
||||
~cleanup()
|
||||
{
|
||||
// see https://svn.boost.org/trac/boost/ticket/5563
|
||||
//mock::verify();
|
||||
mock::reset();
|
||||
}
|
||||
};
|
||||
BOOST_GLOBAL_FIXTURE( cleanup )
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_USE_BOOST_TEST
|
||||
|
||||
#endif // MOCK_CLEANUP_HPP_INCLUDED
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2011
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_CLEANUP_HPP_INCLUDED
|
||||
#define MOCK_CLEANUP_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#ifdef MOCK_USE_BOOST_TEST
|
||||
#include "../verify.hpp"
|
||||
#include "../reset.hpp"
|
||||
#include <boost/test/unit_test_suite.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
struct cleanup
|
||||
{
|
||||
~cleanup()
|
||||
{
|
||||
// see https://svn.boost.org/trac/boost/ticket/5563
|
||||
//mock::verify();
|
||||
mock::reset();
|
||||
}
|
||||
};
|
||||
BOOST_GLOBAL_FIXTURE( cleanup )
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_USE_BOOST_TEST
|
||||
|
||||
#endif // MOCK_CLEANUP_HPP_INCLUDED
|
||||
|
|
@ -1,44 +1,44 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2011
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_CONTEXT_HPP_INCLUDED
|
||||
#define MOCK_CONTEXT_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include "type_name.hpp"
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/test/utils/basic_cstring/basic_cstring.hpp>
|
||||
#include <ostream>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
class verifiable;
|
||||
|
||||
class context : boost::noncopyable
|
||||
{
|
||||
public:
|
||||
context() {}
|
||||
virtual ~context() {}
|
||||
|
||||
virtual void add( const void* p, verifiable& v,
|
||||
boost::unit_test::const_string instance,
|
||||
boost::optional< type_name > type,
|
||||
boost::unit_test::const_string name ) = 0;
|
||||
virtual void add( verifiable& v ) = 0;
|
||||
virtual void remove( verifiable& v ) = 0;
|
||||
|
||||
virtual void serialize( std::ostream& s,
|
||||
const verifiable& v ) const = 0;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_CONTEXT_HPP_INCLUDED
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2011
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_CONTEXT_HPP_INCLUDED
|
||||
#define MOCK_CONTEXT_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include "type_name.hpp"
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/test/utils/basic_cstring/basic_cstring.hpp>
|
||||
#include <ostream>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
class verifiable;
|
||||
|
||||
class context : boost::noncopyable
|
||||
{
|
||||
public:
|
||||
context() {}
|
||||
virtual ~context() {}
|
||||
|
||||
virtual void add( const void* p, verifiable& v,
|
||||
boost::unit_test::const_string instance,
|
||||
boost::optional< type_name > type,
|
||||
boost::unit_test::const_string name ) = 0;
|
||||
virtual void add( verifiable& v ) = 0;
|
||||
virtual void remove( verifiable& v ) = 0;
|
||||
|
||||
virtual void serialize( std::ostream& s,
|
||||
const verifiable& v ) const = 0;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_CONTEXT_HPP_INCLUDED
|
||||
|
|
@ -1,263 +1,263 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2012
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include "matcher_base_template.hpp"
|
||||
|
||||
#define MOCK_EXPECTATION_INITIALIZE(z, n, d) \
|
||||
BOOST_PP_COMMA_IF(n) c##n##_( c##n )
|
||||
|
||||
#define MOCK_EXPECTATION_MEMBER(z, n, d) \
|
||||
matcher< T##n, Constraint_##n > c##n##_;
|
||||
|
||||
#define MOCK_EXPECTATION_IS_VALID(z, n, d) \
|
||||
BOOST_PP_IF(n, &&,) c##n##_( a##n )
|
||||
|
||||
#define MOCK_EXPECTATION_SERIALIZE(z, n, d) \
|
||||
BOOST_PP_IF(n, << ", " <<,) c##n##_
|
||||
|
||||
#define MOCK_EXPECTATION_SERIALIZE_ANY(z, n, d) \
|
||||
BOOST_PP_IF(n, << ", " <<,) "any"
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template< typename Signature > class default_matcher;
|
||||
|
||||
template<
|
||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename T) >
|
||||
class default_matcher< void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) ) >
|
||||
: public matcher_base< void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) ) >
|
||||
{
|
||||
private:
|
||||
virtual bool operator()(
|
||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
virtual void serialize( std::ostream& s ) const
|
||||
{
|
||||
s << "" BOOST_PP_REPEAT(MOCK_NUM_ARGS,
|
||||
MOCK_EXPECTATION_SERIALIZE_ANY, _ );
|
||||
}
|
||||
};
|
||||
|
||||
#ifndef MOCK_NUM_ARGS_0
|
||||
|
||||
template< typename Constraint, typename Signature > class single_matcher;
|
||||
|
||||
template<
|
||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename Constraint_),
|
||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename T)
|
||||
>
|
||||
class single_matcher<
|
||||
void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, Constraint_) ),
|
||||
void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )
|
||||
>
|
||||
: public matcher_base< void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) ) >
|
||||
{
|
||||
public:
|
||||
single_matcher(
|
||||
BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, Constraint_, c) )
|
||||
: BOOST_PP_REPEAT(MOCK_NUM_ARGS,
|
||||
MOCK_EXPECTATION_INITIALIZE, _)
|
||||
{}
|
||||
|
||||
private:
|
||||
virtual bool operator()(
|
||||
BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, T, a) )
|
||||
{
|
||||
return BOOST_PP_REPEAT(MOCK_NUM_ARGS,
|
||||
MOCK_EXPECTATION_IS_VALID, _);
|
||||
}
|
||||
virtual void serialize( std::ostream& s ) const
|
||||
{
|
||||
s << BOOST_PP_REPEAT(MOCK_NUM_ARGS,
|
||||
MOCK_EXPECTATION_SERIALIZE, _ );
|
||||
}
|
||||
|
||||
private:
|
||||
BOOST_PP_REPEAT(
|
||||
MOCK_NUM_ARGS, MOCK_EXPECTATION_MEMBER, _ )
|
||||
};
|
||||
|
||||
template< typename F, typename Signature > class multi_matcher;
|
||||
|
||||
template< typename F,
|
||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename T) >
|
||||
class multi_matcher< F, void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) ) >
|
||||
: public matcher_base< void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS,T) ) >
|
||||
{
|
||||
public:
|
||||
multi_matcher( const F& f )
|
||||
: f_( f )
|
||||
{}
|
||||
|
||||
private:
|
||||
virtual bool operator()(
|
||||
BOOST_PP_ENUM_BINARY_PARAMS( MOCK_NUM_ARGS, T, a ) )
|
||||
{
|
||||
return f_( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, a ) );
|
||||
}
|
||||
virtual void serialize( std::ostream& s ) const
|
||||
{
|
||||
s << mock::format( f_ );
|
||||
}
|
||||
|
||||
private:
|
||||
F f_;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
template< typename Signature > class expectation;
|
||||
|
||||
template< typename R
|
||||
BOOST_PP_ENUM_TRAILING_PARAMS(MOCK_NUM_ARGS, typename T) >
|
||||
class expectation< R (BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS,T)) >
|
||||
: public action< R, R (BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS,T)) >
|
||||
{
|
||||
public:
|
||||
expectation()
|
||||
: invocation_( boost::make_shared< unlimited >() )
|
||||
, matcher_(
|
||||
boost::make_shared<
|
||||
default_matcher<
|
||||
void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )
|
||||
>
|
||||
> () )
|
||||
, file_( "unknown location" )
|
||||
, line_( 0 )
|
||||
{}
|
||||
expectation( const char* file, int line )
|
||||
: invocation_( boost::make_shared< unlimited >() )
|
||||
, matcher_(
|
||||
boost::make_shared<
|
||||
default_matcher<
|
||||
void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )
|
||||
>
|
||||
> () )
|
||||
, file_( file )
|
||||
, line_( line )
|
||||
{}
|
||||
|
||||
~expectation()
|
||||
{
|
||||
for( sequences_cit it = sequences_.begin();
|
||||
it != sequences_.end(); ++it )
|
||||
(*it)->remove( this );
|
||||
}
|
||||
|
||||
void invoke( const boost::shared_ptr< invocation >& i )
|
||||
{
|
||||
invocation_ = i;
|
||||
}
|
||||
|
||||
#ifndef MOCK_NUM_ARGS_0
|
||||
template<
|
||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename Constraint_)
|
||||
>
|
||||
expectation& with(
|
||||
BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, Constraint_, c) )
|
||||
{
|
||||
matcher_ =
|
||||
boost::make_shared< single_matcher<
|
||||
void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, Constraint_) ),
|
||||
void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )
|
||||
> >(
|
||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, c) );
|
||||
return *this;
|
||||
}
|
||||
#if MOCK_NUM_ARGS > 1
|
||||
template< typename Constraint >
|
||||
expectation& with( const Constraint& c )
|
||||
{
|
||||
matcher_ =
|
||||
boost::make_shared< multi_matcher<
|
||||
Constraint,
|
||||
void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) ) > >( c );
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void add( sequence& s )
|
||||
{
|
||||
s.impl_->add( this );
|
||||
sequences_.push_back( s.impl_ );
|
||||
}
|
||||
|
||||
bool verify() const
|
||||
{
|
||||
return invocation_->verify();
|
||||
}
|
||||
|
||||
bool is_valid(
|
||||
BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, T, a) ) const
|
||||
{
|
||||
return !invocation_->exhausted()
|
||||
&& (*matcher_)( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, a) );
|
||||
}
|
||||
|
||||
bool invoke() const
|
||||
{
|
||||
for( sequences_cit it = sequences_.begin();
|
||||
it != sequences_.end(); ++it )
|
||||
if( ! (*it)->is_valid( this ) )
|
||||
return false;
|
||||
bool result = invocation_->invoke();
|
||||
for( sequences_cit it = sequences_.begin();
|
||||
it != sequences_.end(); ++it )
|
||||
(*it)->invalidate( this );
|
||||
return result;
|
||||
}
|
||||
|
||||
const char* file() const
|
||||
{
|
||||
return file_;
|
||||
}
|
||||
int line() const
|
||||
{
|
||||
return line_;
|
||||
}
|
||||
|
||||
friend std::ostream& operator<<(
|
||||
std::ostream& s, const expectation& e )
|
||||
{
|
||||
return s << ( e.invocation_->exhausted() ? 'v' : '.' )
|
||||
<< ' ' << *e.invocation_
|
||||
#ifndef MOCK_NUM_ARGS_0
|
||||
<< ".with( " << *e.matcher_ << " )"
|
||||
#endif
|
||||
;
|
||||
}
|
||||
|
||||
private:
|
||||
typedef std::vector<
|
||||
boost::shared_ptr< sequence_impl >
|
||||
> sequences_type;
|
||||
typedef sequences_type::const_iterator sequences_cit;
|
||||
|
||||
boost::shared_ptr< invocation > invocation_;
|
||||
boost::shared_ptr<
|
||||
matcher_base<
|
||||
void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )
|
||||
>
|
||||
> matcher_;
|
||||
sequences_type sequences_;
|
||||
const char* file_;
|
||||
int line_;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#undef MOCK_EXPECTATION_INITIALIZE
|
||||
#undef MOCK_EXPECTATION_MEMBER
|
||||
#undef MOCK_EXPECTATION_IS_VALID
|
||||
#undef MOCK_EXPECTATION_SERIALIZE
|
||||
#undef MOCK_EXPECTATION_SERIALIZE_ANY
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2012
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include "matcher_base_template.hpp"
|
||||
|
||||
#define MOCK_EXPECTATION_INITIALIZE(z, n, d) \
|
||||
BOOST_PP_COMMA_IF(n) c##n##_( c##n )
|
||||
|
||||
#define MOCK_EXPECTATION_MEMBER(z, n, d) \
|
||||
matcher< T##n, Constraint_##n > c##n##_;
|
||||
|
||||
#define MOCK_EXPECTATION_IS_VALID(z, n, d) \
|
||||
BOOST_PP_IF(n, &&,) c##n##_( a##n )
|
||||
|
||||
#define MOCK_EXPECTATION_SERIALIZE(z, n, d) \
|
||||
BOOST_PP_IF(n, << ", " <<,) c##n##_
|
||||
|
||||
#define MOCK_EXPECTATION_SERIALIZE_ANY(z, n, d) \
|
||||
BOOST_PP_IF(n, << ", " <<,) "any"
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template< typename Signature > class default_matcher;
|
||||
|
||||
template<
|
||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename T) >
|
||||
class default_matcher< void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) ) >
|
||||
: public matcher_base< void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) ) >
|
||||
{
|
||||
private:
|
||||
virtual bool operator()(
|
||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
virtual void serialize( std::ostream& s ) const
|
||||
{
|
||||
s << "" BOOST_PP_REPEAT(MOCK_NUM_ARGS,
|
||||
MOCK_EXPECTATION_SERIALIZE_ANY, _ );
|
||||
}
|
||||
};
|
||||
|
||||
#ifndef MOCK_NUM_ARGS_0
|
||||
|
||||
template< typename Constraint, typename Signature > class single_matcher;
|
||||
|
||||
template<
|
||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename Constraint_),
|
||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename T)
|
||||
>
|
||||
class single_matcher<
|
||||
void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, Constraint_) ),
|
||||
void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )
|
||||
>
|
||||
: public matcher_base< void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) ) >
|
||||
{
|
||||
public:
|
||||
single_matcher(
|
||||
BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, Constraint_, c) )
|
||||
: BOOST_PP_REPEAT(MOCK_NUM_ARGS,
|
||||
MOCK_EXPECTATION_INITIALIZE, _)
|
||||
{}
|
||||
|
||||
private:
|
||||
virtual bool operator()(
|
||||
BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, T, a) )
|
||||
{
|
||||
return BOOST_PP_REPEAT(MOCK_NUM_ARGS,
|
||||
MOCK_EXPECTATION_IS_VALID, _);
|
||||
}
|
||||
virtual void serialize( std::ostream& s ) const
|
||||
{
|
||||
s << BOOST_PP_REPEAT(MOCK_NUM_ARGS,
|
||||
MOCK_EXPECTATION_SERIALIZE, _ );
|
||||
}
|
||||
|
||||
private:
|
||||
BOOST_PP_REPEAT(
|
||||
MOCK_NUM_ARGS, MOCK_EXPECTATION_MEMBER, _ )
|
||||
};
|
||||
|
||||
template< typename F, typename Signature > class multi_matcher;
|
||||
|
||||
template< typename F,
|
||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename T) >
|
||||
class multi_matcher< F, void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) ) >
|
||||
: public matcher_base< void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS,T) ) >
|
||||
{
|
||||
public:
|
||||
multi_matcher( const F& f )
|
||||
: f_( f )
|
||||
{}
|
||||
|
||||
private:
|
||||
virtual bool operator()(
|
||||
BOOST_PP_ENUM_BINARY_PARAMS( MOCK_NUM_ARGS, T, a ) )
|
||||
{
|
||||
return f_( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, a ) );
|
||||
}
|
||||
virtual void serialize( std::ostream& s ) const
|
||||
{
|
||||
s << mock::format( f_ );
|
||||
}
|
||||
|
||||
private:
|
||||
F f_;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
template< typename Signature > class expectation;
|
||||
|
||||
template< typename R
|
||||
BOOST_PP_ENUM_TRAILING_PARAMS(MOCK_NUM_ARGS, typename T) >
|
||||
class expectation< R (BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS,T)) >
|
||||
: public action< R, R (BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS,T)) >
|
||||
{
|
||||
public:
|
||||
expectation()
|
||||
: invocation_( boost::make_shared< unlimited >() )
|
||||
, matcher_(
|
||||
boost::make_shared<
|
||||
default_matcher<
|
||||
void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )
|
||||
>
|
||||
> () )
|
||||
, file_( "unknown location" )
|
||||
, line_( 0 )
|
||||
{}
|
||||
expectation( const char* file, int line )
|
||||
: invocation_( boost::make_shared< unlimited >() )
|
||||
, matcher_(
|
||||
boost::make_shared<
|
||||
default_matcher<
|
||||
void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )
|
||||
>
|
||||
> () )
|
||||
, file_( file )
|
||||
, line_( line )
|
||||
{}
|
||||
|
||||
~expectation()
|
||||
{
|
||||
for( sequences_cit it = sequences_.begin();
|
||||
it != sequences_.end(); ++it )
|
||||
(*it)->remove( this );
|
||||
}
|
||||
|
||||
void invoke( const boost::shared_ptr< invocation >& i )
|
||||
{
|
||||
invocation_ = i;
|
||||
}
|
||||
|
||||
#ifndef MOCK_NUM_ARGS_0
|
||||
template<
|
||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename Constraint_)
|
||||
>
|
||||
expectation& with(
|
||||
BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, Constraint_, c) )
|
||||
{
|
||||
matcher_ =
|
||||
boost::make_shared< single_matcher<
|
||||
void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, Constraint_) ),
|
||||
void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )
|
||||
> >(
|
||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, c) );
|
||||
return *this;
|
||||
}
|
||||
#if MOCK_NUM_ARGS > 1
|
||||
template< typename Constraint >
|
||||
expectation& with( const Constraint& c )
|
||||
{
|
||||
matcher_ =
|
||||
boost::make_shared< multi_matcher<
|
||||
Constraint,
|
||||
void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) ) > >( c );
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void add( sequence& s )
|
||||
{
|
||||
s.impl_->add( this );
|
||||
sequences_.push_back( s.impl_ );
|
||||
}
|
||||
|
||||
bool verify() const
|
||||
{
|
||||
return invocation_->verify();
|
||||
}
|
||||
|
||||
bool is_valid(
|
||||
BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, T, a) ) const
|
||||
{
|
||||
return !invocation_->exhausted()
|
||||
&& (*matcher_)( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, a) );
|
||||
}
|
||||
|
||||
bool invoke() const
|
||||
{
|
||||
for( sequences_cit it = sequences_.begin();
|
||||
it != sequences_.end(); ++it )
|
||||
if( ! (*it)->is_valid( this ) )
|
||||
return false;
|
||||
bool result = invocation_->invoke();
|
||||
for( sequences_cit it = sequences_.begin();
|
||||
it != sequences_.end(); ++it )
|
||||
(*it)->invalidate( this );
|
||||
return result;
|
||||
}
|
||||
|
||||
const char* file() const
|
||||
{
|
||||
return file_;
|
||||
}
|
||||
int line() const
|
||||
{
|
||||
return line_;
|
||||
}
|
||||
|
||||
friend std::ostream& operator<<(
|
||||
std::ostream& s, const expectation& e )
|
||||
{
|
||||
return s << ( e.invocation_->exhausted() ? 'v' : '.' )
|
||||
<< ' ' << *e.invocation_
|
||||
#ifndef MOCK_NUM_ARGS_0
|
||||
<< ".with( " << *e.matcher_ << " )"
|
||||
#endif
|
||||
;
|
||||
}
|
||||
|
||||
private:
|
||||
typedef std::vector<
|
||||
boost::shared_ptr< sequence_impl >
|
||||
> sequences_type;
|
||||
typedef sequences_type::const_iterator sequences_cit;
|
||||
|
||||
boost::shared_ptr< invocation > invocation_;
|
||||
boost::shared_ptr<
|
||||
matcher_base<
|
||||
void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )
|
||||
>
|
||||
> matcher_;
|
||||
sequences_type sequences_;
|
||||
const char* file_;
|
||||
int line_;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#undef MOCK_EXPECTATION_INITIALIZE
|
||||
#undef MOCK_EXPECTATION_MEMBER
|
||||
#undef MOCK_EXPECTATION_IS_VALID
|
||||
#undef MOCK_EXPECTATION_SERIALIZE
|
||||
#undef MOCK_EXPECTATION_SERIALIZE_ANY
|
||||
|
|
@ -1,50 +1,50 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2012
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_FORMATTER_HPP_INCLUDED
|
||||
#define MOCK_FORMATTER_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include "../stream.hpp"
|
||||
#include "addressof.hpp"
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template< typename T >
|
||||
struct formatter
|
||||
{
|
||||
explicit formatter( const T& t )
|
||||
: t_( detail::addressof( t ) )
|
||||
{}
|
||||
void serialize( stream& s ) const
|
||||
{
|
||||
detail::serialize( s, *t_ );
|
||||
}
|
||||
const T* t_;
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
stream& operator<<( stream& s, const formatter< T >& f )
|
||||
{
|
||||
f.serialize( s );
|
||||
return s;
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
std::ostream& operator<<( std::ostream& s, const formatter< T >& f )
|
||||
{
|
||||
stream ss( s );
|
||||
f.serialize( ss );
|
||||
return s;
|
||||
}
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_FORMATTER_HPP_INCLUDED
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2012
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_FORMATTER_HPP_INCLUDED
|
||||
#define MOCK_FORMATTER_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include "../stream.hpp"
|
||||
#include "addressof.hpp"
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template< typename T >
|
||||
struct formatter
|
||||
{
|
||||
explicit formatter( const T& t )
|
||||
: t_( detail::addressof( t ) )
|
||||
{}
|
||||
void serialize( stream& s ) const
|
||||
{
|
||||
detail::serialize( s, *t_ );
|
||||
}
|
||||
const T* t_;
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
stream& operator<<( stream& s, const formatter< T >& f )
|
||||
{
|
||||
f.serialize( s );
|
||||
return s;
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
std::ostream& operator<<( std::ostream& s, const formatter< T >& f )
|
||||
{
|
||||
stream ss( s );
|
||||
f.serialize( ss );
|
||||
return s;
|
||||
}
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_FORMATTER_HPP_INCLUDED
|
||||
|
|
@ -1,103 +1,103 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_FUNCTION_HPP_INCLUDED
|
||||
#define MOCK_FUNCTION_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include "../error.hpp"
|
||||
#include "../log.hpp"
|
||||
#include "../constraints.hpp"
|
||||
#include "../sequence.hpp"
|
||||
#include "../matcher.hpp"
|
||||
#include "action.hpp"
|
||||
#include "verifiable.hpp"
|
||||
#include "invocation.hpp"
|
||||
#include "type_name.hpp"
|
||||
#include "context.hpp"
|
||||
#include "mutex.hpp"
|
||||
#include <boost/preprocessor/iteration/iterate.hpp>
|
||||
#include <boost/preprocessor/repetition/repeat_from_to.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_params.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
||||
#include <boost/preprocessor/comparison/equal.hpp>
|
||||
#include <boost/preprocessor/comparison/greater.hpp>
|
||||
#include <boost/test/utils/basic_cstring/basic_cstring.hpp>
|
||||
#include <boost/test/utils/lazy_ostream.hpp>
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
#include <boost/call_traits.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <ostream>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template< typename R, typename E >
|
||||
struct wrapper_base
|
||||
{
|
||||
wrapper_base( E& e )
|
||||
: e_( &e )
|
||||
{}
|
||||
|
||||
template< typename T >
|
||||
void returns( T t )
|
||||
{
|
||||
e_->returns( t );
|
||||
}
|
||||
|
||||
E* e_;
|
||||
};
|
||||
template< typename E >
|
||||
struct wrapper_base< void, E >
|
||||
{
|
||||
wrapper_base( E& e )
|
||||
: e_( &e )
|
||||
{}
|
||||
|
||||
E* e_;
|
||||
};
|
||||
template< typename R, typename E >
|
||||
struct wrapper_base< R*, E >
|
||||
{
|
||||
wrapper_base( E& e )
|
||||
: e_( &e )
|
||||
{}
|
||||
|
||||
void returns( R* r )
|
||||
{
|
||||
e_->returns( r );
|
||||
}
|
||||
template< typename Y >
|
||||
void returns( const boost::reference_wrapper< Y >& r )
|
||||
{
|
||||
e_->returns( r );
|
||||
}
|
||||
|
||||
E* e_;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#define MOCK_NUM_ARGS 0
|
||||
#define MOCK_NUM_ARGS_0
|
||||
#include "function_template.hpp"
|
||||
#undef MOCK_NUM_ARGS_0
|
||||
#undef MOCK_NUM_ARGS
|
||||
|
||||
#define BOOST_PP_FILENAME_1 <turtle/detail/function_iterate.hpp>
|
||||
#define BOOST_PP_ITERATION_LIMITS (1, MOCK_MAX_ARGS)
|
||||
#include BOOST_PP_ITERATE()
|
||||
#undef BOOST_PP_FILENAME_1
|
||||
#undef BOOST_PP_ITERATION_LIMITS
|
||||
|
||||
#endif // MOCK_FUNCTION_HPP_INCLUDED
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_FUNCTION_HPP_INCLUDED
|
||||
#define MOCK_FUNCTION_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include "../error.hpp"
|
||||
#include "../log.hpp"
|
||||
#include "../constraints.hpp"
|
||||
#include "../sequence.hpp"
|
||||
#include "../matcher.hpp"
|
||||
#include "action.hpp"
|
||||
#include "verifiable.hpp"
|
||||
#include "invocation.hpp"
|
||||
#include "type_name.hpp"
|
||||
#include "context.hpp"
|
||||
#include "mutex.hpp"
|
||||
#include <boost/preprocessor/iteration/iterate.hpp>
|
||||
#include <boost/preprocessor/repetition/repeat_from_to.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_params.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
||||
#include <boost/preprocessor/comparison/equal.hpp>
|
||||
#include <boost/preprocessor/comparison/greater.hpp>
|
||||
#include <boost/test/utils/basic_cstring/basic_cstring.hpp>
|
||||
#include <boost/test/utils/lazy_ostream.hpp>
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
#include <boost/call_traits.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <ostream>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template< typename R, typename E >
|
||||
struct wrapper_base
|
||||
{
|
||||
wrapper_base( E& e )
|
||||
: e_( &e )
|
||||
{}
|
||||
|
||||
template< typename T >
|
||||
void returns( T t )
|
||||
{
|
||||
e_->returns( t );
|
||||
}
|
||||
|
||||
E* e_;
|
||||
};
|
||||
template< typename E >
|
||||
struct wrapper_base< void, E >
|
||||
{
|
||||
wrapper_base( E& e )
|
||||
: e_( &e )
|
||||
{}
|
||||
|
||||
E* e_;
|
||||
};
|
||||
template< typename R, typename E >
|
||||
struct wrapper_base< R*, E >
|
||||
{
|
||||
wrapper_base( E& e )
|
||||
: e_( &e )
|
||||
{}
|
||||
|
||||
void returns( R* r )
|
||||
{
|
||||
e_->returns( r );
|
||||
}
|
||||
template< typename Y >
|
||||
void returns( const boost::reference_wrapper< Y >& r )
|
||||
{
|
||||
e_->returns( r );
|
||||
}
|
||||
|
||||
E* e_;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#define MOCK_NUM_ARGS 0
|
||||
#define MOCK_NUM_ARGS_0
|
||||
#include "function_template.hpp"
|
||||
#undef MOCK_NUM_ARGS_0
|
||||
#undef MOCK_NUM_ARGS
|
||||
|
||||
#define BOOST_PP_FILENAME_1 <turtle/detail/function_iterate.hpp>
|
||||
#define BOOST_PP_ITERATION_LIMITS (1, MOCK_MAX_ARGS)
|
||||
#include BOOST_PP_ITERATE()
|
||||
#undef BOOST_PP_FILENAME_1
|
||||
#undef BOOST_PP_ITERATION_LIMITS
|
||||
|
||||
#endif // MOCK_FUNCTION_HPP_INCLUDED
|
||||
|
|
@ -1,304 +1,308 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2012
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include "expectation_template.hpp"
|
||||
|
||||
#ifndef MOCK_ERROR_POLICY
|
||||
# error no error policy has been set
|
||||
#endif
|
||||
|
||||
#define MOCK_FUNCTION_FORMAT(z, n, N) \
|
||||
<< ' ' << mock::format( t##n ) \
|
||||
<< BOOST_PP_IF(BOOST_PP_EQUAL(N,n), ' ', ',')
|
||||
|
||||
#define MOCK_FUNCTION_CONTEXT \
|
||||
boost::unit_test::lazy_ostream::instance() \
|
||||
<< lazy_context( this ) \
|
||||
<< '(' BOOST_PP_REPEAT(MOCK_NUM_ARGS, MOCK_FUNCTION_FORMAT, \
|
||||
BOOST_PP_DEC(MOCK_NUM_ARGS)) \
|
||||
<< ')' \
|
||||
<< lazy_expectations( this )
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template< typename Signature > class function_impl;
|
||||
|
||||
template< typename R
|
||||
BOOST_PP_ENUM_TRAILING_PARAMS(MOCK_NUM_ARGS, typename T) >
|
||||
class function_impl< R ( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) ) >
|
||||
: public verifiable, public boost::enable_shared_from_this<
|
||||
function_impl< R ( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )> >
|
||||
{
|
||||
public:
|
||||
typedef safe_error< R, MOCK_ERROR_POLICY< R > > error_type;
|
||||
|
||||
public:
|
||||
function_impl()
|
||||
: context_( 0 )
|
||||
, valid_( true )
|
||||
, mutex_( boost::make_shared< mutex >() )
|
||||
{}
|
||||
virtual ~function_impl()
|
||||
{
|
||||
if( valid_ && ! std::uncaught_exception() )
|
||||
for( expectations_cit it = expectations_.begin();
|
||||
it != expectations_.end(); ++it )
|
||||
if( ! it->verify() )
|
||||
error_type::fail( "untriggered expectation",
|
||||
boost::unit_test::lazy_ostream::instance()
|
||||
<< lazy_context( this )
|
||||
<< lazy_expectations( this ),
|
||||
it->file(), it->line() );
|
||||
if( context_ )
|
||||
context_->remove( *this );
|
||||
}
|
||||
|
||||
virtual bool verify() const
|
||||
{
|
||||
lock _( mutex_ );
|
||||
for( expectations_cit it = expectations_.begin();
|
||||
it != expectations_.end(); ++it )
|
||||
if( ! it->verify() )
|
||||
{
|
||||
valid_ = false;
|
||||
error_type::fail( "verification failed",
|
||||
boost::unit_test::lazy_ostream::instance()
|
||||
<< lazy_context( this )
|
||||
<< lazy_expectations( this ),
|
||||
it->file(), it->line() );
|
||||
}
|
||||
return valid_;
|
||||
}
|
||||
|
||||
virtual void reset()
|
||||
{
|
||||
lock _( mutex_ );
|
||||
valid_ = true;
|
||||
boost::shared_ptr< function_impl > guard =
|
||||
this->shared_from_this();
|
||||
expectations_.clear();
|
||||
}
|
||||
|
||||
private:
|
||||
typedef expectation<
|
||||
R( BOOST_PP_ENUM_PARAMS( MOCK_NUM_ARGS, T ) )
|
||||
> expectation_type;
|
||||
|
||||
struct wrapper : wrapper_base< R, expectation_type >
|
||||
{
|
||||
wrapper( const boost::shared_ptr< mutex >& m, expectation_type& e )
|
||||
: wrapper_base< R, expectation_type >( e )
|
||||
, lock_( m )
|
||||
{}
|
||||
|
||||
wrapper once()
|
||||
{
|
||||
this->e_->invoke( boost::make_shared< detail::once >() );
|
||||
return *this;
|
||||
}
|
||||
wrapper never()
|
||||
{
|
||||
this->e_->invoke( boost::make_shared< detail::never >() );
|
||||
return *this;
|
||||
}
|
||||
wrapper exactly( std::size_t count )
|
||||
{
|
||||
this->e_->invoke( boost::make_shared< detail::exactly >( count ) );
|
||||
return *this;
|
||||
}
|
||||
wrapper at_least( std::size_t min )
|
||||
{
|
||||
this->e_->invoke( boost::make_shared< detail::at_least >( min ) );
|
||||
return *this;
|
||||
}
|
||||
wrapper at_most( std::size_t max )
|
||||
{
|
||||
this->e_->invoke( boost::make_shared< detail::at_most >( max ) );
|
||||
return *this;
|
||||
}
|
||||
wrapper between( std::size_t min, std::size_t max )
|
||||
{
|
||||
this->e_->invoke( boost::make_shared< detail::between >( min, max ) );
|
||||
return *this;
|
||||
}
|
||||
|
||||
#ifndef MOCK_NUM_ARGS_0
|
||||
template<
|
||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename Constraint_)
|
||||
>
|
||||
wrapper with(
|
||||
BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, Constraint_, c) )
|
||||
{
|
||||
this->e_->with(
|
||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, c) );
|
||||
return *this;
|
||||
}
|
||||
#if MOCK_NUM_ARGS > 1
|
||||
template< typename Constraint >
|
||||
wrapper with( const Constraint& c )
|
||||
{
|
||||
this->e_->with( c );
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define MOCK_FUNCTION_IN_ADD(z, n, d) \
|
||||
this->e_->add( s##n );
|
||||
|
||||
#define MOCK_FUNCTION_IN(z, n, d) \
|
||||
wrapper in( BOOST_PP_ENUM_PARAMS(n, sequence& s) ) \
|
||||
{ \
|
||||
BOOST_PP_REPEAT(n, MOCK_FUNCTION_IN_ADD, _) \
|
||||
return *this; \
|
||||
}
|
||||
|
||||
BOOST_PP_REPEAT(MOCK_MAX_SEQUENCES,
|
||||
MOCK_FUNCTION_IN, _)
|
||||
|
||||
#undef MOCK_FUNCTION_IN
|
||||
#undef MOCK_FUNCTION_IN_ADD
|
||||
|
||||
template< typename TT >
|
||||
void calls( TT t )
|
||||
{
|
||||
this->e_->calls( t );
|
||||
}
|
||||
template< typename TT >
|
||||
void throws( TT t )
|
||||
{
|
||||
this->e_->throws( t );
|
||||
}
|
||||
template< typename TT >
|
||||
void moves( TT t )
|
||||
{
|
||||
this->e_->moves( t );
|
||||
}
|
||||
|
||||
lock lock_;
|
||||
};
|
||||
|
||||
public:
|
||||
typedef wrapper wrapper_type;
|
||||
|
||||
wrapper expect( const char* file, int line )
|
||||
{
|
||||
lock _( mutex_ );
|
||||
expectations_.push_back( expectation_type( file, line ) );
|
||||
valid_ = true;
|
||||
return wrapper( mutex_, expectations_.back() );
|
||||
}
|
||||
wrapper expect()
|
||||
{
|
||||
lock _( mutex_ );
|
||||
expectations_.push_back( expectation_type() );
|
||||
valid_ = true;
|
||||
return wrapper( mutex_, expectations_.back() );
|
||||
}
|
||||
|
||||
R operator()(
|
||||
BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, T, t) ) const
|
||||
{
|
||||
lock _( mutex_ );
|
||||
valid_ = false;
|
||||
for( expectations_cit it = expectations_.begin();
|
||||
it != expectations_.end(); ++it )
|
||||
if( it->is_valid(
|
||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, t) ) )
|
||||
{
|
||||
if( ! it->invoke() )
|
||||
{
|
||||
error_type::fail( "sequence failed",
|
||||
MOCK_FUNCTION_CONTEXT, it->file(), it->line() );
|
||||
return error_type::abort();
|
||||
}
|
||||
if( ! it->valid() )
|
||||
{
|
||||
error_type::fail( "missing action",
|
||||
MOCK_FUNCTION_CONTEXT, it->file(), it->line() );
|
||||
return error_type::abort();
|
||||
}
|
||||
valid_ = true;
|
||||
error_type::call(
|
||||
MOCK_FUNCTION_CONTEXT, it->file(), it->line() );
|
||||
if( it->functor() )
|
||||
return it->functor()(
|
||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, t) );
|
||||
return it->trigger();
|
||||
}
|
||||
error_type::fail( "unexpected call", MOCK_FUNCTION_CONTEXT );
|
||||
return error_type::abort();
|
||||
}
|
||||
|
||||
void add( context& c, const void* p,
|
||||
boost::unit_test::const_string instance,
|
||||
boost::optional< type_name > type,
|
||||
boost::unit_test::const_string name )
|
||||
{
|
||||
lock _( mutex_ );
|
||||
if( ! context_ )
|
||||
c.add( *this );
|
||||
c.add( p, *this, instance, type, name );
|
||||
context_ = &c;
|
||||
}
|
||||
|
||||
friend std::ostream& operator<<(
|
||||
std::ostream& s, const function_impl& impl )
|
||||
{
|
||||
lock _( impl.mutex_ );
|
||||
return s << lazy_context( &impl ) << lazy_expectations( &impl );
|
||||
}
|
||||
|
||||
struct lazy_context
|
||||
{
|
||||
lazy_context( const function_impl* impl )
|
||||
: impl_( impl )
|
||||
{}
|
||||
friend std::ostream& operator<<(
|
||||
std::ostream& s, const lazy_context& c )
|
||||
{
|
||||
if( c.impl_->context_ )
|
||||
c.impl_->context_->serialize( s, *c.impl_ );
|
||||
else
|
||||
s << '?';
|
||||
return s;
|
||||
}
|
||||
const function_impl* impl_;
|
||||
};
|
||||
|
||||
struct lazy_expectations
|
||||
{
|
||||
lazy_expectations( const function_impl* impl )
|
||||
: impl_( impl )
|
||||
{}
|
||||
friend std::ostream& operator<<(
|
||||
std::ostream& s, const lazy_expectations& e )
|
||||
{
|
||||
for( expectations_cit it = e.impl_->expectations_.begin();
|
||||
it != e.impl_->expectations_.end(); ++it )
|
||||
s << std::endl << *it;
|
||||
return s;
|
||||
}
|
||||
const function_impl* impl_;
|
||||
};
|
||||
|
||||
typedef std::list< expectation_type > expectations_type;
|
||||
typedef typename expectations_type::const_iterator expectations_cit;
|
||||
|
||||
expectations_type expectations_;
|
||||
context* context_;
|
||||
mutable bool valid_;
|
||||
const boost::shared_ptr< mutex > mutex_;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#undef MOCK_FUNCTION_FORMAT
|
||||
#undef MOCK_FUNCTION_CONTEXT
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2012
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include "expectation_template.hpp"
|
||||
|
||||
#ifndef MOCK_ERROR_POLICY
|
||||
# error no error policy has been set
|
||||
#endif
|
||||
|
||||
#define MOCK_FUNCTION_FORMAT(z, n, N) \
|
||||
<< ' ' << mock::format( t##n ) \
|
||||
<< BOOST_PP_IF(BOOST_PP_EQUAL(N,n), ' ', ',')
|
||||
|
||||
#define MOCK_FUNCTION_CONTEXT \
|
||||
boost::unit_test::lazy_ostream::instance() \
|
||||
<< lazy_context( this ) \
|
||||
<< '(' BOOST_PP_REPEAT(MOCK_NUM_ARGS, MOCK_FUNCTION_FORMAT, \
|
||||
BOOST_PP_DEC(MOCK_NUM_ARGS)) \
|
||||
<< ')' \
|
||||
<< lazy_expectations( this )
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template< typename Signature > class function_impl;
|
||||
|
||||
template< typename R
|
||||
BOOST_PP_ENUM_TRAILING_PARAMS(MOCK_NUM_ARGS, typename T) >
|
||||
class function_impl< R ( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) ) >
|
||||
: public verifiable, public boost::enable_shared_from_this<
|
||||
function_impl< R ( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )> >
|
||||
{
|
||||
public:
|
||||
typedef safe_error< R, MOCK_ERROR_POLICY< R > > error_type;
|
||||
|
||||
public:
|
||||
function_impl()
|
||||
: context_( 0 )
|
||||
, valid_( true )
|
||||
, mutex_( boost::make_shared< mutex >() )
|
||||
{}
|
||||
virtual ~function_impl()
|
||||
{
|
||||
if( valid_ && ! std::uncaught_exception() )
|
||||
for( expectations_cit it = expectations_.begin();
|
||||
it != expectations_.end(); ++it )
|
||||
if( ! it->verify() )
|
||||
error_type::fail( "untriggered expectation",
|
||||
boost::unit_test::lazy_ostream::instance()
|
||||
<< lazy_context( this )
|
||||
<< lazy_expectations( this ),
|
||||
it->file(), it->line() );
|
||||
if( context_ )
|
||||
context_->remove( *this );
|
||||
}
|
||||
|
||||
virtual bool verify() const
|
||||
{
|
||||
lock _( mutex_ );
|
||||
for( expectations_cit it = expectations_.begin();
|
||||
it != expectations_.end(); ++it )
|
||||
if( ! it->verify() )
|
||||
{
|
||||
valid_ = false;
|
||||
error_type::fail( "verification failed",
|
||||
boost::unit_test::lazy_ostream::instance()
|
||||
<< lazy_context( this )
|
||||
<< lazy_expectations( this ),
|
||||
it->file(), it->line() );
|
||||
}
|
||||
return valid_;
|
||||
}
|
||||
|
||||
virtual void reset()
|
||||
{
|
||||
lock _( mutex_ );
|
||||
valid_ = true;
|
||||
boost::shared_ptr< function_impl > guard =
|
||||
this->shared_from_this();
|
||||
expectations_.clear();
|
||||
}
|
||||
|
||||
private:
|
||||
typedef expectation<
|
||||
R( BOOST_PP_ENUM_PARAMS( MOCK_NUM_ARGS, T ) )
|
||||
> expectation_type;
|
||||
|
||||
struct wrapper : wrapper_base< R, expectation_type >
|
||||
{
|
||||
wrapper( const boost::shared_ptr< mutex >& m, expectation_type& e )
|
||||
: wrapper_base< R, expectation_type >( e )
|
||||
, lock_( m )
|
||||
{}
|
||||
|
||||
wrapper once()
|
||||
{
|
||||
this->e_->invoke( boost::make_shared< detail::once >() );
|
||||
return *this;
|
||||
}
|
||||
wrapper never()
|
||||
{
|
||||
this->e_->invoke( boost::make_shared< detail::never >() );
|
||||
return *this;
|
||||
}
|
||||
wrapper exactly( std::size_t count )
|
||||
{
|
||||
this->e_->invoke(
|
||||
boost::make_shared< detail::exactly >( count ) );
|
||||
return *this;
|
||||
}
|
||||
wrapper at_least( std::size_t min )
|
||||
{
|
||||
this->e_->invoke(
|
||||
boost::make_shared< detail::at_least >( min ) );
|
||||
return *this;
|
||||
}
|
||||
wrapper at_most( std::size_t max )
|
||||
{
|
||||
this->e_->invoke(
|
||||
boost::make_shared< detail::at_most >( max ) );
|
||||
return *this;
|
||||
}
|
||||
wrapper between( std::size_t min, std::size_t max )
|
||||
{
|
||||
this->e_->invoke(
|
||||
boost::make_shared< detail::between >( min, max ) );
|
||||
return *this;
|
||||
}
|
||||
|
||||
#ifndef MOCK_NUM_ARGS_0
|
||||
template<
|
||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename Constraint_)
|
||||
>
|
||||
wrapper with(
|
||||
BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, Constraint_, c) )
|
||||
{
|
||||
this->e_->with(
|
||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, c) );
|
||||
return *this;
|
||||
}
|
||||
#if MOCK_NUM_ARGS > 1
|
||||
template< typename Constraint >
|
||||
wrapper with( const Constraint& c )
|
||||
{
|
||||
this->e_->with( c );
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define MOCK_FUNCTION_IN_ADD(z, n, d) \
|
||||
this->e_->add( s##n );
|
||||
|
||||
#define MOCK_FUNCTION_IN(z, n, d) \
|
||||
wrapper in( BOOST_PP_ENUM_PARAMS(n, sequence& s) ) \
|
||||
{ \
|
||||
BOOST_PP_REPEAT(n, MOCK_FUNCTION_IN_ADD, _) \
|
||||
return *this; \
|
||||
}
|
||||
|
||||
BOOST_PP_REPEAT(MOCK_MAX_SEQUENCES,
|
||||
MOCK_FUNCTION_IN, _)
|
||||
|
||||
#undef MOCK_FUNCTION_IN
|
||||
#undef MOCK_FUNCTION_IN_ADD
|
||||
|
||||
template< typename TT >
|
||||
void calls( TT t )
|
||||
{
|
||||
this->e_->calls( t );
|
||||
}
|
||||
template< typename TT >
|
||||
void throws( TT t )
|
||||
{
|
||||
this->e_->throws( t );
|
||||
}
|
||||
template< typename TT >
|
||||
void moves( TT t )
|
||||
{
|
||||
this->e_->moves( t );
|
||||
}
|
||||
|
||||
lock lock_;
|
||||
};
|
||||
|
||||
public:
|
||||
typedef wrapper wrapper_type;
|
||||
|
||||
wrapper expect( const char* file, int line )
|
||||
{
|
||||
lock _( mutex_ );
|
||||
expectations_.push_back( expectation_type( file, line ) );
|
||||
valid_ = true;
|
||||
return wrapper( mutex_, expectations_.back() );
|
||||
}
|
||||
wrapper expect()
|
||||
{
|
||||
lock _( mutex_ );
|
||||
expectations_.push_back( expectation_type() );
|
||||
valid_ = true;
|
||||
return wrapper( mutex_, expectations_.back() );
|
||||
}
|
||||
|
||||
R operator()(
|
||||
BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, T, t) ) const
|
||||
{
|
||||
lock _( mutex_ );
|
||||
valid_ = false;
|
||||
for( expectations_cit it = expectations_.begin();
|
||||
it != expectations_.end(); ++it )
|
||||
if( it->is_valid(
|
||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, t) ) )
|
||||
{
|
||||
if( ! it->invoke() )
|
||||
{
|
||||
error_type::fail( "sequence failed",
|
||||
MOCK_FUNCTION_CONTEXT, it->file(), it->line() );
|
||||
return error_type::abort();
|
||||
}
|
||||
if( ! it->valid() )
|
||||
{
|
||||
error_type::fail( "missing action",
|
||||
MOCK_FUNCTION_CONTEXT, it->file(), it->line() );
|
||||
return error_type::abort();
|
||||
}
|
||||
valid_ = true;
|
||||
error_type::call(
|
||||
MOCK_FUNCTION_CONTEXT, it->file(), it->line() );
|
||||
if( it->functor() )
|
||||
return it->functor()(
|
||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, t) );
|
||||
return it->trigger();
|
||||
}
|
||||
error_type::fail( "unexpected call", MOCK_FUNCTION_CONTEXT );
|
||||
return error_type::abort();
|
||||
}
|
||||
|
||||
void add( context& c, const void* p,
|
||||
boost::unit_test::const_string instance,
|
||||
boost::optional< type_name > type,
|
||||
boost::unit_test::const_string name )
|
||||
{
|
||||
lock _( mutex_ );
|
||||
if( ! context_ )
|
||||
c.add( *this );
|
||||
c.add( p, *this, instance, type, name );
|
||||
context_ = &c;
|
||||
}
|
||||
|
||||
friend std::ostream& operator<<(
|
||||
std::ostream& s, const function_impl& impl )
|
||||
{
|
||||
lock _( impl.mutex_ );
|
||||
return s << lazy_context( &impl ) << lazy_expectations( &impl );
|
||||
}
|
||||
|
||||
struct lazy_context
|
||||
{
|
||||
lazy_context( const function_impl* impl )
|
||||
: impl_( impl )
|
||||
{}
|
||||
friend std::ostream& operator<<(
|
||||
std::ostream& s, const lazy_context& c )
|
||||
{
|
||||
if( c.impl_->context_ )
|
||||
c.impl_->context_->serialize( s, *c.impl_ );
|
||||
else
|
||||
s << '?';
|
||||
return s;
|
||||
}
|
||||
const function_impl* impl_;
|
||||
};
|
||||
|
||||
struct lazy_expectations
|
||||
{
|
||||
lazy_expectations( const function_impl* impl )
|
||||
: impl_( impl )
|
||||
{}
|
||||
friend std::ostream& operator<<(
|
||||
std::ostream& s, const lazy_expectations& e )
|
||||
{
|
||||
for( expectations_cit it = e.impl_->expectations_.begin();
|
||||
it != e.impl_->expectations_.end(); ++it )
|
||||
s << std::endl << *it;
|
||||
return s;
|
||||
}
|
||||
const function_impl* impl_;
|
||||
};
|
||||
|
||||
typedef std::list< expectation_type > expectations_type;
|
||||
typedef typename expectations_type::const_iterator expectations_cit;
|
||||
|
||||
expectations_type expectations_;
|
||||
context* context_;
|
||||
mutable bool valid_;
|
||||
const boost::shared_ptr< mutex > mutex_;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#undef MOCK_FUNCTION_FORMAT
|
||||
#undef MOCK_FUNCTION_CONTEXT
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2012
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define MOCK_NUM_ARGS BOOST_PP_ITERATION()
|
||||
#include "function_template.hpp"
|
||||
#undef MOCK_NUM_ARGS
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2012
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define MOCK_NUM_ARGS BOOST_PP_ITERATION()
|
||||
#include "function_template.hpp"
|
||||
#undef MOCK_NUM_ARGS
|
||||
|
|
@ -1,111 +1,111 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include "function_impl_template.hpp"
|
||||
|
||||
#define MOCK_FUNCTION_CALL(z, n, d ) \
|
||||
BOOST_PP_COMMA_IF(n) typename \
|
||||
boost::call_traits< T##n >::param_type
|
||||
|
||||
#define MOCK_FUNCTION_PARAM(z, n, d) \
|
||||
MOCK_FUNCTION_CALL(z, n, d) t##n
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template< typename Signature > class function;
|
||||
|
||||
template< typename R
|
||||
BOOST_PP_ENUM_TRAILING_PARAMS(MOCK_NUM_ARGS, typename T) >
|
||||
class function< R ( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) ) >
|
||||
{
|
||||
public:
|
||||
typedef R result_type;
|
||||
|
||||
template< typename Args >
|
||||
struct sig
|
||||
{
|
||||
typedef R type;
|
||||
};
|
||||
|
||||
private:
|
||||
typedef function_impl<
|
||||
R ( BOOST_PP_REPEAT(MOCK_NUM_ARGS, MOCK_FUNCTION_CALL, _) )
|
||||
> impl_type;
|
||||
typedef typename impl_type::wrapper_type expectation_type;
|
||||
typedef typename impl_type::error_type error_type;
|
||||
|
||||
public:
|
||||
function()
|
||||
: impl_( boost::make_shared< impl_type >() )
|
||||
{}
|
||||
|
||||
bool verify() const
|
||||
{
|
||||
return impl_->verify();
|
||||
}
|
||||
bool verify( const char* file, int line ) const
|
||||
{
|
||||
error_type::pass( file, line );
|
||||
return impl_->verify();
|
||||
}
|
||||
void reset()
|
||||
{
|
||||
impl_->reset();
|
||||
}
|
||||
void reset( const char* file, int line )
|
||||
{
|
||||
error_type::pass( file, line );
|
||||
impl_->reset();
|
||||
}
|
||||
|
||||
expectation_type expect( const char* file, int line )
|
||||
{
|
||||
error_type::pass( file, line );
|
||||
return impl_->expect( file, line );
|
||||
}
|
||||
expectation_type expect()
|
||||
{
|
||||
return impl_->expect();
|
||||
}
|
||||
|
||||
R operator()(
|
||||
BOOST_PP_REPEAT(MOCK_NUM_ARGS, MOCK_FUNCTION_PARAM, _) ) const
|
||||
{
|
||||
return (*impl_)( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, t) );
|
||||
}
|
||||
|
||||
friend std::ostream& operator<<( std::ostream& s, const function& f )
|
||||
{
|
||||
return s << *f.impl_;
|
||||
}
|
||||
|
||||
function& operator()( context& c,
|
||||
boost::unit_test::const_string instance )
|
||||
{
|
||||
impl_->add( c, impl_.get(), instance, boost::none, "" );
|
||||
return *this;
|
||||
}
|
||||
|
||||
void configure( context& c, const void* p,
|
||||
boost::unit_test::const_string instance,
|
||||
boost::optional< type_name > type,
|
||||
boost::unit_test::const_string name ) const
|
||||
{
|
||||
impl_->add( c, p, instance, type, name );
|
||||
}
|
||||
|
||||
private:
|
||||
boost::shared_ptr< impl_type > impl_;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#undef MOCK_FUNCTION_CALL
|
||||
#undef MOCK_FUNCTION_PARAM
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include "function_impl_template.hpp"
|
||||
|
||||
#define MOCK_FUNCTION_CALL(z, n, d ) \
|
||||
BOOST_PP_COMMA_IF(n) typename \
|
||||
boost::call_traits< T##n >::param_type
|
||||
|
||||
#define MOCK_FUNCTION_PARAM(z, n, d) \
|
||||
MOCK_FUNCTION_CALL(z, n, d) t##n
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template< typename Signature > class function;
|
||||
|
||||
template< typename R
|
||||
BOOST_PP_ENUM_TRAILING_PARAMS(MOCK_NUM_ARGS, typename T) >
|
||||
class function< R ( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) ) >
|
||||
{
|
||||
public:
|
||||
typedef R result_type;
|
||||
|
||||
template< typename Args >
|
||||
struct sig
|
||||
{
|
||||
typedef R type;
|
||||
};
|
||||
|
||||
private:
|
||||
typedef function_impl<
|
||||
R ( BOOST_PP_REPEAT(MOCK_NUM_ARGS, MOCK_FUNCTION_CALL, _) )
|
||||
> impl_type;
|
||||
typedef typename impl_type::wrapper_type expectation_type;
|
||||
typedef typename impl_type::error_type error_type;
|
||||
|
||||
public:
|
||||
function()
|
||||
: impl_( boost::make_shared< impl_type >() )
|
||||
{}
|
||||
|
||||
bool verify() const
|
||||
{
|
||||
return impl_->verify();
|
||||
}
|
||||
bool verify( const char* file, int line ) const
|
||||
{
|
||||
error_type::pass( file, line );
|
||||
return impl_->verify();
|
||||
}
|
||||
void reset()
|
||||
{
|
||||
impl_->reset();
|
||||
}
|
||||
void reset( const char* file, int line )
|
||||
{
|
||||
error_type::pass( file, line );
|
||||
impl_->reset();
|
||||
}
|
||||
|
||||
expectation_type expect( const char* file, int line )
|
||||
{
|
||||
error_type::pass( file, line );
|
||||
return impl_->expect( file, line );
|
||||
}
|
||||
expectation_type expect()
|
||||
{
|
||||
return impl_->expect();
|
||||
}
|
||||
|
||||
R operator()(
|
||||
BOOST_PP_REPEAT(MOCK_NUM_ARGS, MOCK_FUNCTION_PARAM, _) ) const
|
||||
{
|
||||
return (*impl_)( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, t) );
|
||||
}
|
||||
|
||||
friend std::ostream& operator<<( std::ostream& s, const function& f )
|
||||
{
|
||||
return s << *f.impl_;
|
||||
}
|
||||
|
||||
function& operator()( context& c,
|
||||
boost::unit_test::const_string instance )
|
||||
{
|
||||
impl_->add( c, impl_.get(), instance, boost::none, "" );
|
||||
return *this;
|
||||
}
|
||||
|
||||
void configure( context& c, const void* p,
|
||||
boost::unit_test::const_string instance,
|
||||
boost::optional< type_name > type,
|
||||
boost::unit_test::const_string name ) const
|
||||
{
|
||||
impl_->add( c, p, instance, type, name );
|
||||
}
|
||||
|
||||
private:
|
||||
boost::shared_ptr< impl_type > impl_;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#undef MOCK_FUNCTION_CALL
|
||||
#undef MOCK_FUNCTION_PARAM
|
||||
|
|
@ -1,52 +1,52 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2012
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_FUNCTOR_HPP_INCLUDED
|
||||
#define MOCK_FUNCTOR_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include "function.hpp"
|
||||
#include "mutex.hpp"
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
class functor_mutex_t :
|
||||
public boost::unit_test::singleton< functor_mutex_t >,
|
||||
public mutex
|
||||
{
|
||||
private:
|
||||
BOOST_TEST_SINGLETON_CONS( functor_mutex_t );
|
||||
};
|
||||
BOOST_TEST_SINGLETON_INST( functor_mutex )
|
||||
|
||||
template< typename Signature >
|
||||
struct functor : function< Signature >
|
||||
{
|
||||
functor()
|
||||
{
|
||||
scoped_lock _( functor_mutex );
|
||||
static functor* f = 0;
|
||||
if( f )
|
||||
{
|
||||
*this = *f;
|
||||
f = 0;
|
||||
functor_mutex.unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
functor_mutex.lock();
|
||||
f = this;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_FUNCTOR_HPP_INCLUDED
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2012
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_FUNCTOR_HPP_INCLUDED
|
||||
#define MOCK_FUNCTOR_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include "function.hpp"
|
||||
#include "mutex.hpp"
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
class functor_mutex_t :
|
||||
public boost::unit_test::singleton< functor_mutex_t >,
|
||||
public mutex
|
||||
{
|
||||
private:
|
||||
BOOST_TEST_SINGLETON_CONS( functor_mutex_t );
|
||||
};
|
||||
BOOST_TEST_SINGLETON_INST( functor_mutex )
|
||||
|
||||
template< typename Signature >
|
||||
struct functor : function< Signature >
|
||||
{
|
||||
functor()
|
||||
{
|
||||
scoped_lock _( functor_mutex );
|
||||
static functor* f = 0;
|
||||
if( f )
|
||||
{
|
||||
*this = *f;
|
||||
f = 0;
|
||||
functor_mutex.unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
functor_mutex.lock();
|
||||
f = this;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_FUNCTOR_HPP_INCLUDED
|
||||
|
|
@ -1,64 +1,64 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2011
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_GROUP_HPP_INCLUDED
|
||||
#define MOCK_GROUP_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include "verifiable.hpp"
|
||||
#include <functional>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
class group
|
||||
{
|
||||
public:
|
||||
void add( verifiable& v )
|
||||
{
|
||||
verifiables_.push_back( &v );
|
||||
}
|
||||
void remove( verifiable& v )
|
||||
{
|
||||
verifiables_.erase(
|
||||
std::remove( verifiables_.begin(), verifiables_.end(), &v ),
|
||||
verifiables_.end() );
|
||||
}
|
||||
|
||||
bool verify() const
|
||||
{
|
||||
bool valid = true;
|
||||
for( verifiables_cit it = verifiables_.begin();
|
||||
it != verifiables_.end(); ++it )
|
||||
if( ! (*it)->verify() )
|
||||
valid = false;
|
||||
return valid;
|
||||
}
|
||||
void reset()
|
||||
{
|
||||
const verifiables_t verifiables = verifiables_;
|
||||
for( verifiables_cit it = verifiables.begin();
|
||||
it != verifiables.end(); ++it )
|
||||
if( std::find( verifiables_.begin(), verifiables_.end(), *it )
|
||||
!= verifiables_.end() )
|
||||
(*it)->reset();
|
||||
}
|
||||
|
||||
private:
|
||||
typedef std::vector< verifiable* > verifiables_t;
|
||||
typedef verifiables_t::const_iterator verifiables_cit;
|
||||
|
||||
verifiables_t verifiables_;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_GROUP_HPP_INCLUDED
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2011
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_GROUP_HPP_INCLUDED
|
||||
#define MOCK_GROUP_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include "verifiable.hpp"
|
||||
#include <functional>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
class group
|
||||
{
|
||||
public:
|
||||
void add( verifiable& v )
|
||||
{
|
||||
verifiables_.push_back( &v );
|
||||
}
|
||||
void remove( verifiable& v )
|
||||
{
|
||||
verifiables_.erase(
|
||||
std::remove( verifiables_.begin(), verifiables_.end(), &v ),
|
||||
verifiables_.end() );
|
||||
}
|
||||
|
||||
bool verify() const
|
||||
{
|
||||
bool valid = true;
|
||||
for( verifiables_cit it = verifiables_.begin();
|
||||
it != verifiables_.end(); ++it )
|
||||
if( ! (*it)->verify() )
|
||||
valid = false;
|
||||
return valid;
|
||||
}
|
||||
void reset()
|
||||
{
|
||||
const verifiables_t verifiables = verifiables_;
|
||||
for( verifiables_cit it = verifiables.begin();
|
||||
it != verifiables.end(); ++it )
|
||||
if( std::find( verifiables_.begin(), verifiables_.end(), *it )
|
||||
!= verifiables_.end() )
|
||||
(*it)->reset();
|
||||
}
|
||||
|
||||
private:
|
||||
typedef std::vector< verifiable* > verifiables_t;
|
||||
typedef verifiables_t::const_iterator verifiables_cit;
|
||||
|
||||
verifiables_t verifiables_;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_GROUP_HPP_INCLUDED
|
||||
|
|
@ -1,170 +1,170 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_INVOCATION_HPP_INCLUDED
|
||||
#define MOCK_INVOCATION_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <stdexcept>
|
||||
#include <ostream>
|
||||
#include <limits>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
class invocation : private boost::noncopyable
|
||||
{
|
||||
public:
|
||||
invocation() {}
|
||||
virtual ~invocation() {}
|
||||
|
||||
virtual bool invoke() = 0;
|
||||
virtual bool verify() const = 0;
|
||||
|
||||
virtual bool exhausted() const = 0;
|
||||
|
||||
friend std::ostream& operator<<( std::ostream& s, const invocation& i )
|
||||
{
|
||||
return i.serialize( s );
|
||||
}
|
||||
|
||||
private:
|
||||
virtual std::ostream& serialize( std::ostream& s ) const = 0;
|
||||
};
|
||||
|
||||
class between : public invocation
|
||||
{
|
||||
public:
|
||||
between( std::size_t min, std::size_t max )
|
||||
: min_( min )
|
||||
, max_( max )
|
||||
, count_( 0 )
|
||||
{
|
||||
if( min > max )
|
||||
throw std::invalid_argument( "'min' > 'max'" );
|
||||
}
|
||||
|
||||
virtual bool invoke()
|
||||
{
|
||||
if( count_ == max_ )
|
||||
return false;
|
||||
++count_;
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool exhausted() const
|
||||
{
|
||||
return count_ >= max_;
|
||||
}
|
||||
|
||||
virtual bool verify() const
|
||||
{
|
||||
return min_ <= count_ && count_ <= max_;
|
||||
}
|
||||
|
||||
protected:
|
||||
const std::size_t min_, max_;
|
||||
std::size_t count_;
|
||||
|
||||
private:
|
||||
virtual std::ostream& serialize( std::ostream& s ) const
|
||||
{
|
||||
return s << "between( " << count_
|
||||
<< "/[" << min_ << ',' << max_ << "] )";
|
||||
}
|
||||
};
|
||||
|
||||
class exactly : public between
|
||||
{
|
||||
public:
|
||||
explicit exactly( std::size_t count )
|
||||
: between( count, count )
|
||||
{}
|
||||
|
||||
private:
|
||||
virtual std::ostream& serialize( std::ostream& s ) const
|
||||
{
|
||||
return s << "exactly( " << count_ << '/' << max_ << " )";
|
||||
}
|
||||
};
|
||||
|
||||
class never : public exactly
|
||||
{
|
||||
public:
|
||||
never()
|
||||
: exactly( 0 )
|
||||
{}
|
||||
|
||||
private:
|
||||
virtual std::ostream& serialize( std::ostream& s ) const
|
||||
{
|
||||
return s << "never()";
|
||||
}
|
||||
};
|
||||
|
||||
class once : public exactly
|
||||
{
|
||||
public:
|
||||
once()
|
||||
: exactly( 1 )
|
||||
{}
|
||||
|
||||
private:
|
||||
virtual std::ostream& serialize( std::ostream& s ) const
|
||||
{
|
||||
return s << "once()";
|
||||
}
|
||||
};
|
||||
|
||||
class at_least : public between
|
||||
{
|
||||
public:
|
||||
explicit at_least( std::size_t min )
|
||||
: between( min, (std::numeric_limits< std::size_t >::max)() )
|
||||
{}
|
||||
|
||||
private:
|
||||
virtual std::ostream& serialize( std::ostream& s ) const
|
||||
{
|
||||
return s << "at_least( " << count_ << '/' << min_ << " )";
|
||||
}
|
||||
};
|
||||
|
||||
class at_most : public between
|
||||
{
|
||||
public:
|
||||
explicit at_most( std::size_t max )
|
||||
: between( 0, max )
|
||||
{}
|
||||
|
||||
private:
|
||||
virtual std::ostream& serialize( std::ostream& s ) const
|
||||
{
|
||||
return s << "at_most( " << count_ << '/' << max_ << " )";
|
||||
}
|
||||
};
|
||||
|
||||
class unlimited : public at_least
|
||||
{
|
||||
public:
|
||||
unlimited()
|
||||
: at_least( 0 )
|
||||
{}
|
||||
|
||||
private:
|
||||
virtual std::ostream& serialize( std::ostream& s ) const
|
||||
{
|
||||
return s << "unlimited()";
|
||||
}
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_INVOCATION_HPP_INCLUDED
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_INVOCATION_HPP_INCLUDED
|
||||
#define MOCK_INVOCATION_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <stdexcept>
|
||||
#include <ostream>
|
||||
#include <limits>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
class invocation : private boost::noncopyable
|
||||
{
|
||||
public:
|
||||
invocation() {}
|
||||
virtual ~invocation() {}
|
||||
|
||||
virtual bool invoke() = 0;
|
||||
virtual bool verify() const = 0;
|
||||
|
||||
virtual bool exhausted() const = 0;
|
||||
|
||||
friend std::ostream& operator<<( std::ostream& s, const invocation& i )
|
||||
{
|
||||
return i.serialize( s );
|
||||
}
|
||||
|
||||
private:
|
||||
virtual std::ostream& serialize( std::ostream& s ) const = 0;
|
||||
};
|
||||
|
||||
class between : public invocation
|
||||
{
|
||||
public:
|
||||
between( std::size_t min, std::size_t max )
|
||||
: min_( min )
|
||||
, max_( max )
|
||||
, count_( 0 )
|
||||
{
|
||||
if( min > max )
|
||||
throw std::invalid_argument( "'min' > 'max'" );
|
||||
}
|
||||
|
||||
virtual bool invoke()
|
||||
{
|
||||
if( count_ == max_ )
|
||||
return false;
|
||||
++count_;
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool exhausted() const
|
||||
{
|
||||
return count_ >= max_;
|
||||
}
|
||||
|
||||
virtual bool verify() const
|
||||
{
|
||||
return min_ <= count_ && count_ <= max_;
|
||||
}
|
||||
|
||||
protected:
|
||||
const std::size_t min_, max_;
|
||||
std::size_t count_;
|
||||
|
||||
private:
|
||||
virtual std::ostream& serialize( std::ostream& s ) const
|
||||
{
|
||||
return s << "between( " << count_
|
||||
<< "/[" << min_ << ',' << max_ << "] )";
|
||||
}
|
||||
};
|
||||
|
||||
class exactly : public between
|
||||
{
|
||||
public:
|
||||
explicit exactly( std::size_t count )
|
||||
: between( count, count )
|
||||
{}
|
||||
|
||||
private:
|
||||
virtual std::ostream& serialize( std::ostream& s ) const
|
||||
{
|
||||
return s << "exactly( " << count_ << '/' << max_ << " )";
|
||||
}
|
||||
};
|
||||
|
||||
class never : public exactly
|
||||
{
|
||||
public:
|
||||
never()
|
||||
: exactly( 0 )
|
||||
{}
|
||||
|
||||
private:
|
||||
virtual std::ostream& serialize( std::ostream& s ) const
|
||||
{
|
||||
return s << "never()";
|
||||
}
|
||||
};
|
||||
|
||||
class once : public exactly
|
||||
{
|
||||
public:
|
||||
once()
|
||||
: exactly( 1 )
|
||||
{}
|
||||
|
||||
private:
|
||||
virtual std::ostream& serialize( std::ostream& s ) const
|
||||
{
|
||||
return s << "once()";
|
||||
}
|
||||
};
|
||||
|
||||
class at_least : public between
|
||||
{
|
||||
public:
|
||||
explicit at_least( std::size_t min )
|
||||
: between( min, (std::numeric_limits< std::size_t >::max)() )
|
||||
{}
|
||||
|
||||
private:
|
||||
virtual std::ostream& serialize( std::ostream& s ) const
|
||||
{
|
||||
return s << "at_least( " << count_ << '/' << min_ << " )";
|
||||
}
|
||||
};
|
||||
|
||||
class at_most : public between
|
||||
{
|
||||
public:
|
||||
explicit at_most( std::size_t max )
|
||||
: between( 0, max )
|
||||
{}
|
||||
|
||||
private:
|
||||
virtual std::ostream& serialize( std::ostream& s ) const
|
||||
{
|
||||
return s << "at_most( " << count_ << '/' << max_ << " )";
|
||||
}
|
||||
};
|
||||
|
||||
class unlimited : public at_least
|
||||
{
|
||||
public:
|
||||
unlimited()
|
||||
: at_least( 0 )
|
||||
{}
|
||||
|
||||
private:
|
||||
virtual std::ostream& serialize( std::ostream& s ) const
|
||||
{
|
||||
return s << "unlimited()";
|
||||
}
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_INVOCATION_HPP_INCLUDED
|
||||
|
|
@ -1,62 +1,62 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2009
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_IS_FUNCTOR_HPP_INCLUDED
|
||||
#define MOCK_IS_FUNCTOR_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include <boost/function_types/is_callable_builtin.hpp>
|
||||
#include <boost/type_traits/detail/yes_no_type.hpp>
|
||||
#include <boost/utility/declval.hpp>
|
||||
#include <boost/mpl/has_xxx.hpp>
|
||||
#include <boost/mpl/or.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
BOOST_MPL_HAS_XXX_TRAIT_DEF( result_type )
|
||||
BOOST_MPL_HAS_XXX_TEMPLATE_DEF( sig )
|
||||
BOOST_MPL_HAS_XXX_TEMPLATE_DEF( result )
|
||||
|
||||
#ifdef MOCK_DECLTYPE
|
||||
|
||||
template< typename F, typename P >
|
||||
struct is_callable
|
||||
{
|
||||
typedef boost::type_traits::yes_type yes_type;
|
||||
typedef boost::type_traits::no_type no_type;
|
||||
|
||||
template< typename T >
|
||||
static yes_type check(
|
||||
decltype( boost::declval< T >()( boost::declval< P >() ) )* );
|
||||
template< typename T >
|
||||
static no_type check( ... );
|
||||
|
||||
typedef boost::mpl::bool_<
|
||||
sizeof( check< F >( 0 ) ) == sizeof( yes_type ) > type;
|
||||
};
|
||||
|
||||
#endif // MOCK_DECLTYPE
|
||||
|
||||
template< typename T, typename P >
|
||||
struct is_functor
|
||||
: boost::mpl::or_<
|
||||
boost::function_types::is_callable_builtin< T >,
|
||||
#ifdef MOCK_DECLTYPE
|
||||
is_callable< T, P >,
|
||||
#endif
|
||||
has_result_type< T >,
|
||||
has_result< T >,
|
||||
has_sig< T >
|
||||
>
|
||||
{};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_IS_FUNCTOR_HPP_INCLUDED
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2009
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_IS_FUNCTOR_HPP_INCLUDED
|
||||
#define MOCK_IS_FUNCTOR_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include <boost/function_types/is_callable_builtin.hpp>
|
||||
#include <boost/type_traits/detail/yes_no_type.hpp>
|
||||
#include <boost/utility/declval.hpp>
|
||||
#include <boost/mpl/has_xxx.hpp>
|
||||
#include <boost/mpl/or.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
BOOST_MPL_HAS_XXX_TRAIT_DEF( result_type )
|
||||
BOOST_MPL_HAS_XXX_TEMPLATE_DEF( sig )
|
||||
BOOST_MPL_HAS_XXX_TEMPLATE_DEF( result )
|
||||
|
||||
#ifdef MOCK_DECLTYPE
|
||||
|
||||
template< typename F, typename P >
|
||||
struct is_callable
|
||||
{
|
||||
typedef boost::type_traits::yes_type yes_type;
|
||||
typedef boost::type_traits::no_type no_type;
|
||||
|
||||
template< typename T >
|
||||
static yes_type check(
|
||||
decltype( boost::declval< T >()( boost::declval< P >() ) )* );
|
||||
template< typename T >
|
||||
static no_type check( ... );
|
||||
|
||||
typedef boost::mpl::bool_<
|
||||
sizeof( check< F >( 0 ) ) == sizeof( yes_type ) > type;
|
||||
};
|
||||
|
||||
#endif // MOCK_DECLTYPE
|
||||
|
||||
template< typename T, typename P >
|
||||
struct is_functor
|
||||
: boost::mpl::or_<
|
||||
boost::function_types::is_callable_builtin< T >,
|
||||
#ifdef MOCK_DECLTYPE
|
||||
is_callable< T, P >,
|
||||
#endif
|
||||
has_result_type< T >,
|
||||
has_result< T >,
|
||||
has_sig< T >
|
||||
>
|
||||
{};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_IS_FUNCTOR_HPP_INCLUDED
|
||||
|
|
@ -1,37 +1,37 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2012
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template< typename Signature > class matcher_base;
|
||||
|
||||
template<
|
||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename Actual_) >
|
||||
class matcher_base< void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, Actual_) ) >
|
||||
: boost::noncopyable
|
||||
{
|
||||
public:
|
||||
virtual ~matcher_base() {}
|
||||
|
||||
virtual bool operator()(
|
||||
BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, Actual_, actual_) ) = 0;
|
||||
|
||||
friend std::ostream& operator<<(
|
||||
std::ostream& s, const matcher_base& m )
|
||||
{
|
||||
m.serialize( s );
|
||||
return s;
|
||||
}
|
||||
|
||||
private:
|
||||
virtual void serialize( std::ostream& ) const = 0;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2012
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template< typename Signature > class matcher_base;
|
||||
|
||||
template<
|
||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename Actual_) >
|
||||
class matcher_base< void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, Actual_) ) >
|
||||
: boost::noncopyable
|
||||
{
|
||||
public:
|
||||
virtual ~matcher_base() {}
|
||||
|
||||
virtual bool operator()(
|
||||
BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, Actual_, actual_) ) = 0;
|
||||
|
||||
friend std::ostream& operator<<(
|
||||
std::ostream& s, const matcher_base& m )
|
||||
{
|
||||
m.serialize( s );
|
||||
return s;
|
||||
}
|
||||
|
||||
private:
|
||||
virtual void serialize( std::ostream& ) const = 0;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
|
@ -1,141 +1,141 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_MUTEX_HPP_INCLUDED
|
||||
#define MOCK_MUTEX_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include <boost/test/utils/trivial_singleton.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#ifdef MOCK_THREAD_SAFE
|
||||
|
||||
#ifdef MOCK_HDR_MUTEX
|
||||
#include <mutex>
|
||||
#else
|
||||
#include <boost/thread/recursive_mutex.hpp>
|
||||
#include <boost/thread/lock_guard.hpp>
|
||||
#endif
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
#ifdef MOCK_HDR_MUTEX
|
||||
typedef std::recursive_mutex mutex;
|
||||
typedef std::lock_guard< mutex > scoped_lock;
|
||||
#else
|
||||
typedef boost::recursive_mutex mutex;
|
||||
typedef boost::lock_guard< mutex > scoped_lock;
|
||||
#endif
|
||||
|
||||
struct lock
|
||||
{
|
||||
lock( const boost::shared_ptr< mutex >& m )
|
||||
: m_( m )
|
||||
{
|
||||
m_->lock();
|
||||
}
|
||||
lock( const lock& rhs )
|
||||
{
|
||||
m_.swap( rhs.m_ );
|
||||
}
|
||||
~lock()
|
||||
{
|
||||
if( m_ )
|
||||
m_->unlock();
|
||||
}
|
||||
|
||||
private:
|
||||
lock& operator=( const lock& rhs );
|
||||
|
||||
mutable boost::shared_ptr< mutex > m_;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#else // MOCK_THREAD_SAFE
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
struct mutex
|
||||
{
|
||||
mutex()
|
||||
{}
|
||||
void lock()
|
||||
{}
|
||||
void unlock()
|
||||
{}
|
||||
};
|
||||
struct scoped_lock
|
||||
{
|
||||
scoped_lock( mutex& )
|
||||
{}
|
||||
};
|
||||
struct lock
|
||||
{
|
||||
lock( const boost::shared_ptr< mutex >& )
|
||||
{}
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_THREAD_SAFE
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
class error_mutex_t : public boost::unit_test::singleton< error_mutex_t >,
|
||||
public mutex
|
||||
{
|
||||
private:
|
||||
BOOST_TEST_SINGLETON_CONS( error_mutex_t );
|
||||
};
|
||||
BOOST_TEST_SINGLETON_INST( error_mutex )
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
# pragma warning( push )
|
||||
# pragma warning( disable: 4702 )
|
||||
#endif
|
||||
template< typename Result, typename Error >
|
||||
struct safe_error
|
||||
{
|
||||
static Result abort()
|
||||
{
|
||||
scoped_lock _( error_mutex );
|
||||
return Error::abort();
|
||||
}
|
||||
template< typename Context >
|
||||
static void fail( const char* message, const Context& context,
|
||||
const char* file = "unknown location", int line = 0 )
|
||||
{
|
||||
scoped_lock _( error_mutex );
|
||||
Error::fail( message, context, file, line );
|
||||
}
|
||||
template< typename Context >
|
||||
static void call( const Context& context, const char* file, int line )
|
||||
{
|
||||
scoped_lock _( error_mutex );
|
||||
Error::call( context, file, line );
|
||||
}
|
||||
static void pass( const char* file, int line )
|
||||
{
|
||||
scoped_lock _( error_mutex );
|
||||
Error::pass( file, line );
|
||||
}
|
||||
};
|
||||
#ifdef BOOST_MSVC
|
||||
# pragma warning( pop )
|
||||
#endif
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_MUTEX_HPP_INCLUDED
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_MUTEX_HPP_INCLUDED
|
||||
#define MOCK_MUTEX_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include <boost/test/utils/trivial_singleton.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#ifdef MOCK_THREAD_SAFE
|
||||
|
||||
#ifdef MOCK_HDR_MUTEX
|
||||
#include <mutex>
|
||||
#else
|
||||
#include <boost/thread/recursive_mutex.hpp>
|
||||
#include <boost/thread/lock_guard.hpp>
|
||||
#endif
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
#ifdef MOCK_HDR_MUTEX
|
||||
typedef std::recursive_mutex mutex;
|
||||
typedef std::lock_guard< mutex > scoped_lock;
|
||||
#else
|
||||
typedef boost::recursive_mutex mutex;
|
||||
typedef boost::lock_guard< mutex > scoped_lock;
|
||||
#endif
|
||||
|
||||
struct lock
|
||||
{
|
||||
lock( const boost::shared_ptr< mutex >& m )
|
||||
: m_( m )
|
||||
{
|
||||
m_->lock();
|
||||
}
|
||||
lock( const lock& rhs )
|
||||
{
|
||||
m_.swap( rhs.m_ );
|
||||
}
|
||||
~lock()
|
||||
{
|
||||
if( m_ )
|
||||
m_->unlock();
|
||||
}
|
||||
|
||||
private:
|
||||
lock& operator=( const lock& rhs );
|
||||
|
||||
mutable boost::shared_ptr< mutex > m_;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#else // MOCK_THREAD_SAFE
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
struct mutex
|
||||
{
|
||||
mutex()
|
||||
{}
|
||||
void lock()
|
||||
{}
|
||||
void unlock()
|
||||
{}
|
||||
};
|
||||
struct scoped_lock
|
||||
{
|
||||
scoped_lock( mutex& )
|
||||
{}
|
||||
};
|
||||
struct lock
|
||||
{
|
||||
lock( const boost::shared_ptr< mutex >& )
|
||||
{}
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_THREAD_SAFE
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
class error_mutex_t : public boost::unit_test::singleton< error_mutex_t >,
|
||||
public mutex
|
||||
{
|
||||
private:
|
||||
BOOST_TEST_SINGLETON_CONS( error_mutex_t );
|
||||
};
|
||||
BOOST_TEST_SINGLETON_INST( error_mutex )
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
# pragma warning( push )
|
||||
# pragma warning( disable: 4702 )
|
||||
#endif
|
||||
template< typename Result, typename Error >
|
||||
struct safe_error
|
||||
{
|
||||
static Result abort()
|
||||
{
|
||||
scoped_lock _( error_mutex );
|
||||
return Error::abort();
|
||||
}
|
||||
template< typename Context >
|
||||
static void fail( const char* message, const Context& context,
|
||||
const char* file = "unknown location", int line = 0 )
|
||||
{
|
||||
scoped_lock _( error_mutex );
|
||||
Error::fail( message, context, file, line );
|
||||
}
|
||||
template< typename Context >
|
||||
static void call( const Context& context, const char* file, int line )
|
||||
{
|
||||
scoped_lock _( error_mutex );
|
||||
Error::call( context, file, line );
|
||||
}
|
||||
static void pass( const char* file, int line )
|
||||
{
|
||||
scoped_lock _( error_mutex );
|
||||
Error::pass( file, line );
|
||||
}
|
||||
};
|
||||
#ifdef BOOST_MSVC
|
||||
# pragma warning( pop )
|
||||
#endif
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_MUTEX_HPP_INCLUDED
|
||||
|
|
@ -1,94 +1,94 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2012
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_OBJECT_IMPL_HPP_INCLUDED
|
||||
#define MOCK_OBJECT_IMPL_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include "root.hpp"
|
||||
#include "parent.hpp"
|
||||
#include "type_name.hpp"
|
||||
#include "context.hpp"
|
||||
#include "child.hpp"
|
||||
#include "mutex.hpp"
|
||||
#include <boost/test/utils/basic_cstring/basic_cstring.hpp>
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
class object_impl : public context, public verifiable,
|
||||
public boost::enable_shared_from_this< object_impl >
|
||||
{
|
||||
public:
|
||||
object_impl()
|
||||
: mutex_( boost::make_shared< mutex >() )
|
||||
{}
|
||||
|
||||
virtual void add( const void* /*p*/, verifiable& v,
|
||||
boost::unit_test::const_string instance,
|
||||
boost::optional< type_name > type,
|
||||
boost::unit_test::const_string name )
|
||||
{
|
||||
lock _( mutex_ );
|
||||
if( children_.empty() )
|
||||
detail::root.add( *this );
|
||||
children_[ &v ].update( parent_, instance, type, name );
|
||||
}
|
||||
virtual void add( verifiable& v )
|
||||
{
|
||||
lock _( mutex_ );
|
||||
group_.add( v );
|
||||
}
|
||||
virtual void remove( verifiable& v )
|
||||
{
|
||||
lock _( mutex_ );
|
||||
group_.remove( v );
|
||||
children_.erase( &v );
|
||||
if( children_.empty() )
|
||||
detail::root.remove( *this );
|
||||
}
|
||||
|
||||
virtual void serialize( std::ostream& s, const verifiable& v ) const
|
||||
{
|
||||
lock _( mutex_ );
|
||||
children_cit it = children_.find( &v );
|
||||
if( it != children_.end() )
|
||||
s << it->second;
|
||||
else
|
||||
s << "?";
|
||||
}
|
||||
|
||||
virtual bool verify() const
|
||||
{
|
||||
lock _( mutex_ );
|
||||
return group_.verify();
|
||||
}
|
||||
virtual void reset()
|
||||
{
|
||||
lock _( mutex_ );
|
||||
boost::shared_ptr< object_impl > guard = shared_from_this();
|
||||
group_.reset();
|
||||
}
|
||||
|
||||
private:
|
||||
typedef std::map< const verifiable*, child > children_t;
|
||||
typedef children_t::const_iterator children_cit;
|
||||
|
||||
group group_;
|
||||
parent parent_;
|
||||
children_t children_;
|
||||
const boost::shared_ptr< mutex > mutex_;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_OBJECT_IMPL_HPP_INCLUDED
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2012
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_OBJECT_IMPL_HPP_INCLUDED
|
||||
#define MOCK_OBJECT_IMPL_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include "root.hpp"
|
||||
#include "parent.hpp"
|
||||
#include "type_name.hpp"
|
||||
#include "context.hpp"
|
||||
#include "child.hpp"
|
||||
#include "mutex.hpp"
|
||||
#include <boost/test/utils/basic_cstring/basic_cstring.hpp>
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
class object_impl : public context, public verifiable,
|
||||
public boost::enable_shared_from_this< object_impl >
|
||||
{
|
||||
public:
|
||||
object_impl()
|
||||
: mutex_( boost::make_shared< mutex >() )
|
||||
{}
|
||||
|
||||
virtual void add( const void* /*p*/, verifiable& v,
|
||||
boost::unit_test::const_string instance,
|
||||
boost::optional< type_name > type,
|
||||
boost::unit_test::const_string name )
|
||||
{
|
||||
lock _( mutex_ );
|
||||
if( children_.empty() )
|
||||
detail::root.add( *this );
|
||||
children_[ &v ].update( parent_, instance, type, name );
|
||||
}
|
||||
virtual void add( verifiable& v )
|
||||
{
|
||||
lock _( mutex_ );
|
||||
group_.add( v );
|
||||
}
|
||||
virtual void remove( verifiable& v )
|
||||
{
|
||||
lock _( mutex_ );
|
||||
group_.remove( v );
|
||||
children_.erase( &v );
|
||||
if( children_.empty() )
|
||||
detail::root.remove( *this );
|
||||
}
|
||||
|
||||
virtual void serialize( std::ostream& s, const verifiable& v ) const
|
||||
{
|
||||
lock _( mutex_ );
|
||||
children_cit it = children_.find( &v );
|
||||
if( it != children_.end() )
|
||||
s << it->second;
|
||||
else
|
||||
s << "?";
|
||||
}
|
||||
|
||||
virtual bool verify() const
|
||||
{
|
||||
lock _( mutex_ );
|
||||
return group_.verify();
|
||||
}
|
||||
virtual void reset()
|
||||
{
|
||||
lock _( mutex_ );
|
||||
boost::shared_ptr< object_impl > guard = shared_from_this();
|
||||
group_.reset();
|
||||
}
|
||||
|
||||
private:
|
||||
typedef std::map< const verifiable*, child > children_t;
|
||||
typedef children_t::const_iterator children_cit;
|
||||
|
||||
group group_;
|
||||
parent parent_;
|
||||
children_t children_;
|
||||
const boost::shared_ptr< mutex > mutex_;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_OBJECT_IMPL_HPP_INCLUDED
|
||||
|
|
@ -1,34 +1,34 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2012
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_PARAMETER_HPP_INCLUDED
|
||||
#define MOCK_PARAMETER_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include <boost/function_types/parameter_types.hpp>
|
||||
#include <boost/function_types/function_arity.hpp>
|
||||
#include <boost/mpl/at.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template< typename Signature, int n >
|
||||
struct parameter
|
||||
{
|
||||
typedef typename
|
||||
boost::mpl::at_c<
|
||||
typename
|
||||
boost::function_types::parameter_types< Signature >,
|
||||
n
|
||||
>::type type;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_PARAMETER_HPP_INCLUDED
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2012
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_PARAMETER_HPP_INCLUDED
|
||||
#define MOCK_PARAMETER_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include <boost/function_types/parameter_types.hpp>
|
||||
#include <boost/function_types/function_arity.hpp>
|
||||
#include <boost/mpl/at.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template< typename Signature, int n >
|
||||
struct parameter
|
||||
{
|
||||
typedef typename
|
||||
boost::mpl::at_c<
|
||||
typename
|
||||
boost::function_types::parameter_types< Signature >,
|
||||
n
|
||||
>::type type;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_PARAMETER_HPP_INCLUDED
|
||||
|
|
@ -1,46 +1,46 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2011
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_PARENT_HPP_INCLUDED
|
||||
#define MOCK_PARENT_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include "type_name.hpp"
|
||||
#include <boost/test/utils/basic_cstring/io.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <ostream>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
class parent
|
||||
{
|
||||
public:
|
||||
parent()
|
||||
{}
|
||||
parent( boost::unit_test::const_string instance,
|
||||
boost::optional< type_name > type )
|
||||
: instance_( instance )
|
||||
, type_( type )
|
||||
{}
|
||||
friend std::ostream& operator<<( std::ostream& s, const parent& p )
|
||||
{
|
||||
s << p.instance_;
|
||||
if( p.type_ )
|
||||
s << *p.type_ << "::";
|
||||
return s;
|
||||
}
|
||||
private:
|
||||
boost::unit_test::const_string instance_;
|
||||
boost::optional< type_name > type_;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_PARENT_HPP_INCLUDED
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2011
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_PARENT_HPP_INCLUDED
|
||||
#define MOCK_PARENT_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include "type_name.hpp"
|
||||
#include <boost/test/utils/basic_cstring/io.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <ostream>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
class parent
|
||||
{
|
||||
public:
|
||||
parent()
|
||||
{}
|
||||
parent( boost::unit_test::const_string instance,
|
||||
boost::optional< type_name > type )
|
||||
: instance_( instance )
|
||||
, type_( type )
|
||||
{}
|
||||
friend std::ostream& operator<<( std::ostream& s, const parent& p )
|
||||
{
|
||||
s << p.instance_;
|
||||
if( p.type_ )
|
||||
s << *p.type_ << "::";
|
||||
return s;
|
||||
}
|
||||
private:
|
||||
boost::unit_test::const_string instance_;
|
||||
boost::optional< type_name > type_;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_PARENT_HPP_INCLUDED
|
||||
|
|
@ -1,138 +1,138 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_ROOT_HPP_INCLUDED
|
||||
#define MOCK_ROOT_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include "parent.hpp"
|
||||
#include "group.hpp"
|
||||
#include "context.hpp"
|
||||
#include "child.hpp"
|
||||
#include "mutex.hpp"
|
||||
#include <boost/test/utils/trivial_singleton.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <ostream>
|
||||
#include <map>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
class root_t : public boost::unit_test::singleton< root_t >, public context
|
||||
{
|
||||
public:
|
||||
virtual void add( const void* p, verifiable& v,
|
||||
boost::unit_test::const_string instance,
|
||||
boost::optional< type_name > type,
|
||||
boost::unit_test::const_string name )
|
||||
{
|
||||
scoped_lock _( mutex_ );
|
||||
children_t::iterator it = children_.lower_bound( &v );
|
||||
if( it == children_.end() ||
|
||||
children_.key_comp()( &v, it->first ) )
|
||||
it = children_.insert( it,
|
||||
std::make_pair( &v, counter_child( parents_, p ) ) );
|
||||
it->second.update( instance, type, name );
|
||||
}
|
||||
virtual void add( verifiable& v )
|
||||
{
|
||||
scoped_lock _( mutex_ );
|
||||
group_.add( v );
|
||||
}
|
||||
|
||||
virtual void remove( verifiable& v )
|
||||
{
|
||||
scoped_lock _( mutex_ );
|
||||
group_.remove( v );
|
||||
children_.erase( &v );
|
||||
}
|
||||
|
||||
bool verify() const
|
||||
{
|
||||
scoped_lock _( mutex_ );
|
||||
return group_.verify();
|
||||
}
|
||||
void reset()
|
||||
{
|
||||
scoped_lock _( mutex_ );
|
||||
group_.reset();
|
||||
}
|
||||
|
||||
virtual void serialize( std::ostream& s, const verifiable& v ) const
|
||||
{
|
||||
scoped_lock _( mutex_ );
|
||||
children_cit it = children_.find( &v );
|
||||
if( it != children_.end() )
|
||||
s << it->second;
|
||||
else
|
||||
s << "?";
|
||||
}
|
||||
|
||||
private:
|
||||
typedef std::map< const void*,
|
||||
std::pair< parent, std::size_t > > parents_t;
|
||||
|
||||
class counter_child
|
||||
{
|
||||
public:
|
||||
counter_child( parents_t& parents, const void* p )
|
||||
: parents_( &parents )
|
||||
, it_( parents.insert(
|
||||
std::make_pair( p, parents_t::mapped_type() ) ).first )
|
||||
{
|
||||
++it_->second.second;
|
||||
}
|
||||
counter_child( const counter_child& rhs )
|
||||
: parents_( rhs.parents_ )
|
||||
, it_( rhs.it_ )
|
||||
, child_( rhs.child_ )
|
||||
{
|
||||
++it_->second.second;
|
||||
}
|
||||
~counter_child()
|
||||
{
|
||||
if( --it_->second.second == 0 )
|
||||
parents_->erase( it_ );
|
||||
}
|
||||
void update( boost::unit_test::const_string instance,
|
||||
boost::optional< type_name > type,
|
||||
boost::unit_test::const_string name )
|
||||
{
|
||||
child_.update( it_->second.first, instance, type, name );
|
||||
}
|
||||
friend std::ostream& operator<<( std::ostream& s,
|
||||
const counter_child& c )
|
||||
{
|
||||
return s << c.child_;
|
||||
}
|
||||
|
||||
private:
|
||||
counter_child& operator=( const counter_child& );
|
||||
|
||||
parents_t* parents_;
|
||||
parents_t::iterator it_;
|
||||
child child_;
|
||||
};
|
||||
|
||||
typedef std::map< const verifiable*, counter_child > children_t;
|
||||
typedef children_t::const_iterator children_cit;
|
||||
|
||||
parents_t parents_;
|
||||
children_t children_;
|
||||
group group_;
|
||||
mutable mutex mutex_;
|
||||
|
||||
private:
|
||||
BOOST_TEST_SINGLETON_CONS( root_t );
|
||||
};
|
||||
BOOST_TEST_SINGLETON_INST( root )
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_ROOT_HPP_INCLUDED
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_ROOT_HPP_INCLUDED
|
||||
#define MOCK_ROOT_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include "parent.hpp"
|
||||
#include "group.hpp"
|
||||
#include "context.hpp"
|
||||
#include "child.hpp"
|
||||
#include "mutex.hpp"
|
||||
#include <boost/test/utils/trivial_singleton.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <ostream>
|
||||
#include <map>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
class root_t : public boost::unit_test::singleton< root_t >, public context
|
||||
{
|
||||
public:
|
||||
virtual void add( const void* p, verifiable& v,
|
||||
boost::unit_test::const_string instance,
|
||||
boost::optional< type_name > type,
|
||||
boost::unit_test::const_string name )
|
||||
{
|
||||
scoped_lock _( mutex_ );
|
||||
children_t::iterator it = children_.lower_bound( &v );
|
||||
if( it == children_.end() ||
|
||||
children_.key_comp()( &v, it->first ) )
|
||||
it = children_.insert( it,
|
||||
std::make_pair( &v, counter_child( parents_, p ) ) );
|
||||
it->second.update( instance, type, name );
|
||||
}
|
||||
virtual void add( verifiable& v )
|
||||
{
|
||||
scoped_lock _( mutex_ );
|
||||
group_.add( v );
|
||||
}
|
||||
|
||||
virtual void remove( verifiable& v )
|
||||
{
|
||||
scoped_lock _( mutex_ );
|
||||
group_.remove( v );
|
||||
children_.erase( &v );
|
||||
}
|
||||
|
||||
bool verify() const
|
||||
{
|
||||
scoped_lock _( mutex_ );
|
||||
return group_.verify();
|
||||
}
|
||||
void reset()
|
||||
{
|
||||
scoped_lock _( mutex_ );
|
||||
group_.reset();
|
||||
}
|
||||
|
||||
virtual void serialize( std::ostream& s, const verifiable& v ) const
|
||||
{
|
||||
scoped_lock _( mutex_ );
|
||||
children_cit it = children_.find( &v );
|
||||
if( it != children_.end() )
|
||||
s << it->second;
|
||||
else
|
||||
s << "?";
|
||||
}
|
||||
|
||||
private:
|
||||
typedef std::map< const void*,
|
||||
std::pair< parent, std::size_t > > parents_t;
|
||||
|
||||
class counter_child
|
||||
{
|
||||
public:
|
||||
counter_child( parents_t& parents, const void* p )
|
||||
: parents_( &parents )
|
||||
, it_( parents.insert(
|
||||
std::make_pair( p, parents_t::mapped_type() ) ).first )
|
||||
{
|
||||
++it_->second.second;
|
||||
}
|
||||
counter_child( const counter_child& rhs )
|
||||
: parents_( rhs.parents_ )
|
||||
, it_( rhs.it_ )
|
||||
, child_( rhs.child_ )
|
||||
{
|
||||
++it_->second.second;
|
||||
}
|
||||
~counter_child()
|
||||
{
|
||||
if( --it_->second.second == 0 )
|
||||
parents_->erase( it_ );
|
||||
}
|
||||
void update( boost::unit_test::const_string instance,
|
||||
boost::optional< type_name > type,
|
||||
boost::unit_test::const_string name )
|
||||
{
|
||||
child_.update( it_->second.first, instance, type, name );
|
||||
}
|
||||
friend std::ostream& operator<<( std::ostream& s,
|
||||
const counter_child& c )
|
||||
{
|
||||
return s << c.child_;
|
||||
}
|
||||
|
||||
private:
|
||||
counter_child& operator=( const counter_child& );
|
||||
|
||||
parents_t* parents_;
|
||||
parents_t::iterator it_;
|
||||
child child_;
|
||||
};
|
||||
|
||||
typedef std::map< const verifiable*, counter_child > children_t;
|
||||
typedef children_t::const_iterator children_cit;
|
||||
|
||||
parents_t parents_;
|
||||
children_t children_;
|
||||
group group_;
|
||||
mutable mutex mutex_;
|
||||
|
||||
private:
|
||||
BOOST_TEST_SINGLETON_CONS( root_t );
|
||||
};
|
||||
BOOST_TEST_SINGLETON_INST( root )
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_ROOT_HPP_INCLUDED
|
||||
|
|
@ -1,57 +1,57 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2012
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_SEQUENCE_IMPL_HPP_INCLUDED
|
||||
#define MOCK_SEQUENCE_IMPL_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
class sequence_impl : private boost::noncopyable
|
||||
{
|
||||
public:
|
||||
void add( void* e )
|
||||
{
|
||||
elements_.push_back( e );
|
||||
}
|
||||
void remove( void* e )
|
||||
{
|
||||
elements_.erase( std::remove( elements_.begin(),
|
||||
elements_.end(), e ), elements_.end() );
|
||||
}
|
||||
|
||||
bool is_valid( const void* e ) const
|
||||
{
|
||||
return std::find( elements_.begin(), elements_.end(), e )
|
||||
!= elements_.end();
|
||||
}
|
||||
|
||||
void invalidate( const void* e )
|
||||
{
|
||||
elements_type::iterator it =
|
||||
std::find( elements_.begin(), elements_.end(), e );
|
||||
if( it != elements_.end() )
|
||||
elements_.erase( elements_.begin(), it );
|
||||
}
|
||||
|
||||
private:
|
||||
typedef std::vector< void* > elements_type;
|
||||
|
||||
elements_type elements_;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_SEQUENCE_IMPL_HPP_INCLUDED
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2012
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_SEQUENCE_IMPL_HPP_INCLUDED
|
||||
#define MOCK_SEQUENCE_IMPL_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
class sequence_impl : private boost::noncopyable
|
||||
{
|
||||
public:
|
||||
void add( void* e )
|
||||
{
|
||||
elements_.push_back( e );
|
||||
}
|
||||
void remove( void* e )
|
||||
{
|
||||
elements_.erase( std::remove( elements_.begin(),
|
||||
elements_.end(), e ), elements_.end() );
|
||||
}
|
||||
|
||||
bool is_valid( const void* e ) const
|
||||
{
|
||||
return std::find( elements_.begin(), elements_.end(), e )
|
||||
!= elements_.end();
|
||||
}
|
||||
|
||||
void invalidate( const void* e )
|
||||
{
|
||||
elements_type::iterator it =
|
||||
std::find( elements_.begin(), elements_.end(), e );
|
||||
if( it != elements_.end() )
|
||||
elements_.erase( elements_.begin(), it );
|
||||
}
|
||||
|
||||
private:
|
||||
typedef std::vector< void* > elements_type;
|
||||
|
||||
elements_type elements_;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_SEQUENCE_IMPL_HPP_INCLUDED
|
||||
|
|
@ -1,63 +1,63 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2012
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_SIGNATURE_HPP_INCLUDED
|
||||
#define MOCK_SIGNATURE_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include <boost/function_types/parameter_types.hpp>
|
||||
#include <boost/function_types/function_type.hpp>
|
||||
#include <boost/function_types/result_type.hpp>
|
||||
#include <boost/mpl/single_view.hpp>
|
||||
#include <boost/mpl/joint_view.hpp>
|
||||
#include <boost/mpl/pop_front.hpp>
|
||||
#define BOOST_TYPEOF_SILENT
|
||||
#include <boost/typeof/typeof.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template< typename M >
|
||||
struct signature :
|
||||
boost::function_types::function_type<
|
||||
boost::mpl::joint_view<
|
||||
boost::mpl::single_view<
|
||||
typename
|
||||
boost::function_types::result_type< M >::type
|
||||
>,
|
||||
typename boost::mpl::pop_front<
|
||||
typename
|
||||
boost::function_types::parameter_types< M >
|
||||
>::type
|
||||
>
|
||||
>
|
||||
{};
|
||||
|
||||
template< typename T >
|
||||
struct base
|
||||
{
|
||||
typedef T base_type;
|
||||
};
|
||||
|
||||
// if an error is generated by the line below it means
|
||||
// the method is ambiguous : specify its signature to
|
||||
// disambiguate
|
||||
template< typename T >
|
||||
T& ambiguous_method_requires_to_specify_signature( const T& );
|
||||
}
|
||||
} // mock
|
||||
|
||||
#define MOCK_SIGNATURE(M) \
|
||||
mock::detail::signature< \
|
||||
BOOST_TYPEOF( \
|
||||
mock::detail::ambiguous_method_requires_to_specify_signature( \
|
||||
&base_type::M ) ) \
|
||||
>::type
|
||||
|
||||
#endif // MOCK_SIGNATURE_HPP_INCLUDED
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2012
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_SIGNATURE_HPP_INCLUDED
|
||||
#define MOCK_SIGNATURE_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include <boost/function_types/parameter_types.hpp>
|
||||
#include <boost/function_types/function_type.hpp>
|
||||
#include <boost/function_types/result_type.hpp>
|
||||
#include <boost/mpl/single_view.hpp>
|
||||
#include <boost/mpl/joint_view.hpp>
|
||||
#include <boost/mpl/pop_front.hpp>
|
||||
#define BOOST_TYPEOF_SILENT
|
||||
#include <boost/typeof/typeof.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template< typename M >
|
||||
struct signature :
|
||||
boost::function_types::function_type<
|
||||
boost::mpl::joint_view<
|
||||
boost::mpl::single_view<
|
||||
typename
|
||||
boost::function_types::result_type< M >::type
|
||||
>,
|
||||
typename boost::mpl::pop_front<
|
||||
typename
|
||||
boost::function_types::parameter_types< M >
|
||||
>::type
|
||||
>
|
||||
>
|
||||
{};
|
||||
|
||||
template< typename T >
|
||||
struct base
|
||||
{
|
||||
typedef T base_type;
|
||||
};
|
||||
|
||||
// if an error is generated by the line below it means
|
||||
// the method is ambiguous : specify its signature to
|
||||
// disambiguate
|
||||
template< typename T >
|
||||
T& ambiguous_method_requires_to_specify_signature( const T& );
|
||||
}
|
||||
} // mock
|
||||
|
||||
#define MOCK_SIGNATURE(M) \
|
||||
mock::detail::signature< \
|
||||
BOOST_TYPEOF( \
|
||||
mock::detail::ambiguous_method_requires_to_specify_signature( \
|
||||
&base_type::M ) ) \
|
||||
>::type
|
||||
|
||||
#endif // MOCK_SIGNATURE_HPP_INCLUDED
|
||||
|
|
@ -1,116 +1,116 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2009
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_TYPE_NAME_HPP_INCLUDED
|
||||
#define MOCK_TYPE_NAME_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include <boost/test/utils/basic_cstring/io.hpp>
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include <boost/algorithm/string/erase.hpp>
|
||||
#include <boost/algorithm/string/trim.hpp>
|
||||
#include <boost/detail/sp_typeinfo.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <stdexcept>
|
||||
#include <typeinfo>
|
||||
#include <ostream>
|
||||
#ifdef __GNUC__
|
||||
#include <cxxabi.h>
|
||||
#include <cstdlib>
|
||||
#endif
|
||||
|
||||
#define MOCK_TYPE_NAME( T ) mock::detail::type_name( BOOST_SP_TYPEID(T) )
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
class type_name
|
||||
{
|
||||
public:
|
||||
explicit type_name( const boost::detail::sp_typeinfo& info )
|
||||
: info_( &info )
|
||||
{}
|
||||
friend std::ostream& operator<<( std::ostream& s, const type_name& t )
|
||||
{
|
||||
t.serialize( s, *t.info_ );
|
||||
return s;
|
||||
}
|
||||
private:
|
||||
void serialize( std::ostream& s,
|
||||
const boost::detail::sp_typeinfo& info ) const
|
||||
{
|
||||
const char* name = info.name();
|
||||
#ifdef __GNUC__
|
||||
int status = 0;
|
||||
boost::shared_ptr< char > demangled(
|
||||
abi::__cxa_demangle( name, 0, 0, &status ),
|
||||
&std::free );
|
||||
if( ! status && demangled )
|
||||
serialize( s, demangled.get() );
|
||||
else
|
||||
#endif
|
||||
serialize( s, name );
|
||||
}
|
||||
|
||||
typedef std::string::size_type size_type;
|
||||
|
||||
void serialize( std::ostream& s, std::string name ) const
|
||||
{
|
||||
const size_type nm = rfind( name, ':' ) + 1;
|
||||
const size_type tpl = name.find( '<', nm );
|
||||
s << clean( name.substr( nm, tpl - nm ) );
|
||||
if( tpl == std::string::npos )
|
||||
return;
|
||||
s << '<';
|
||||
list( s, name.substr( tpl + 1, name.rfind( '>' ) - tpl - 1 ) );
|
||||
s << '>';
|
||||
}
|
||||
void list( std::ostream& s, const std::string& name ) const
|
||||
{
|
||||
const size_type comma = rfind( name, ',' );
|
||||
if( comma != std::string::npos )
|
||||
{
|
||||
list( s, name.substr( 0, comma ) );
|
||||
s << ", ";
|
||||
}
|
||||
serialize( s, name.substr( comma + 1 ) );
|
||||
}
|
||||
std::string clean( std::string name ) const
|
||||
{
|
||||
boost::algorithm::trim( name );
|
||||
boost::algorithm::erase_all( name, "class " );
|
||||
boost::algorithm::erase_all( name, "struct " );
|
||||
boost::algorithm::erase_all( name, "__ptr64" );
|
||||
boost::algorithm::replace_all( name, " &", "&" );
|
||||
boost::algorithm::replace_all( name, "& ", "&" );
|
||||
boost::algorithm::replace_all( name, " *", "*" );
|
||||
boost::algorithm::replace_all( name, "* ", "*" );
|
||||
return name;
|
||||
}
|
||||
size_type rfind( const std::string& name, char c ) const
|
||||
{
|
||||
size_type count = 0;
|
||||
for( size_type i = name.size() - 1; i > 0; --i )
|
||||
{
|
||||
if( name[ i ] == '>' )
|
||||
++count;
|
||||
else if( name[ i ] == '<' )
|
||||
--count;
|
||||
if( name[ i ] == c && count == 0 )
|
||||
return i;
|
||||
}
|
||||
return std::string::npos;
|
||||
}
|
||||
|
||||
const boost::detail::sp_typeinfo* info_;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_TYPE_NAME_HPP_INCLUDED
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2009
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_TYPE_NAME_HPP_INCLUDED
|
||||
#define MOCK_TYPE_NAME_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include <boost/test/utils/basic_cstring/io.hpp>
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include <boost/algorithm/string/erase.hpp>
|
||||
#include <boost/algorithm/string/trim.hpp>
|
||||
#include <boost/detail/sp_typeinfo.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <stdexcept>
|
||||
#include <typeinfo>
|
||||
#include <ostream>
|
||||
#ifdef __GNUC__
|
||||
#include <cxxabi.h>
|
||||
#include <cstdlib>
|
||||
#endif
|
||||
|
||||
#define MOCK_TYPE_NAME( T ) mock::detail::type_name( BOOST_SP_TYPEID(T) )
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
class type_name
|
||||
{
|
||||
public:
|
||||
explicit type_name( const boost::detail::sp_typeinfo& info )
|
||||
: info_( &info )
|
||||
{}
|
||||
friend std::ostream& operator<<( std::ostream& s, const type_name& t )
|
||||
{
|
||||
t.serialize( s, *t.info_ );
|
||||
return s;
|
||||
}
|
||||
private:
|
||||
void serialize( std::ostream& s,
|
||||
const boost::detail::sp_typeinfo& info ) const
|
||||
{
|
||||
const char* name = info.name();
|
||||
#ifdef __GNUC__
|
||||
int status = 0;
|
||||
boost::shared_ptr< char > demangled(
|
||||
abi::__cxa_demangle( name, 0, 0, &status ),
|
||||
&std::free );
|
||||
if( ! status && demangled )
|
||||
serialize( s, demangled.get() );
|
||||
else
|
||||
#endif
|
||||
serialize( s, name );
|
||||
}
|
||||
|
||||
typedef std::string::size_type size_type;
|
||||
|
||||
void serialize( std::ostream& s, std::string name ) const
|
||||
{
|
||||
const size_type nm = rfind( name, ':' ) + 1;
|
||||
const size_type tpl = name.find( '<', nm );
|
||||
s << clean( name.substr( nm, tpl - nm ) );
|
||||
if( tpl == std::string::npos )
|
||||
return;
|
||||
s << '<';
|
||||
list( s, name.substr( tpl + 1, name.rfind( '>' ) - tpl - 1 ) );
|
||||
s << '>';
|
||||
}
|
||||
void list( std::ostream& s, const std::string& name ) const
|
||||
{
|
||||
const size_type comma = rfind( name, ',' );
|
||||
if( comma != std::string::npos )
|
||||
{
|
||||
list( s, name.substr( 0, comma ) );
|
||||
s << ", ";
|
||||
}
|
||||
serialize( s, name.substr( comma + 1 ) );
|
||||
}
|
||||
std::string clean( std::string name ) const
|
||||
{
|
||||
boost::algorithm::trim( name );
|
||||
boost::algorithm::erase_all( name, "class " );
|
||||
boost::algorithm::erase_all( name, "struct " );
|
||||
boost::algorithm::erase_all( name, "__ptr64" );
|
||||
boost::algorithm::replace_all( name, " &", "&" );
|
||||
boost::algorithm::replace_all( name, "& ", "&" );
|
||||
boost::algorithm::replace_all( name, " *", "*" );
|
||||
boost::algorithm::replace_all( name, "* ", "*" );
|
||||
return name;
|
||||
}
|
||||
size_type rfind( const std::string& name, char c ) const
|
||||
{
|
||||
size_type count = 0;
|
||||
for( size_type i = name.size() - 1; i > 0; --i )
|
||||
{
|
||||
if( name[ i ] == '>' )
|
||||
++count;
|
||||
else if( name[ i ] == '<' )
|
||||
--count;
|
||||
if( name[ i ] == c && count == 0 )
|
||||
return i;
|
||||
}
|
||||
return std::string::npos;
|
||||
}
|
||||
|
||||
const boost::detail::sp_typeinfo* info_;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_TYPE_NAME_HPP_INCLUDED
|
||||
|
|
@ -1,32 +1,32 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_VERIFIABLE_HPP_INCLUDED
|
||||
#define MOCK_VERIFIABLE_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include <boost/noncopyable.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
class verifiable : private boost::noncopyable
|
||||
{
|
||||
public:
|
||||
verifiable() {}
|
||||
virtual ~verifiable() {}
|
||||
|
||||
virtual bool verify() const = 0;
|
||||
|
||||
virtual void reset() = 0;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_VERIFIABLE_HPP_INCLUDED
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_VERIFIABLE_HPP_INCLUDED
|
||||
#define MOCK_VERIFIABLE_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include <boost/noncopyable.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
class verifiable : private boost::noncopyable
|
||||
{
|
||||
public:
|
||||
verifiable() {}
|
||||
virtual ~verifiable() {}
|
||||
|
||||
virtual bool verify() const = 0;
|
||||
|
||||
virtual void reset() = 0;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_VERIFIABLE_HPP_INCLUDED
|
||||
|
|
@ -1,67 +1,67 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_ERROR_HPP_INCLUDED
|
||||
#define MOCK_ERROR_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#ifdef MOCK_USE_BOOST_TEST
|
||||
#include "exception.hpp"
|
||||
#include <boost/test/framework.hpp>
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test_suite.hpp>
|
||||
#include <boost/exception/enable_current_exception.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
template< typename Result >
|
||||
struct error
|
||||
{
|
||||
static Result abort()
|
||||
{
|
||||
boost::unit_test::framework::test_unit_aborted(
|
||||
boost::unit_test::framework::current_test_case() );
|
||||
throw boost::enable_current_exception( exception() );
|
||||
}
|
||||
|
||||
static void pass( const char* file, int line )
|
||||
{
|
||||
boost::unit_test::unit_test_log.set_checkpoint( file,
|
||||
static_cast< std::size_t >( line ) );
|
||||
}
|
||||
|
||||
template< typename Context >
|
||||
static void fail( const char* message, const Context& context,
|
||||
const char* file = "unknown location", int line = 0 )
|
||||
{
|
||||
boost::unit_test::framework::assertion_result( false );
|
||||
boost::unit_test::unit_test_log
|
||||
<< boost::unit_test::log::begin( file,
|
||||
static_cast< std::size_t >( line ) )
|
||||
<< boost::unit_test::log_all_errors
|
||||
<< message << ": " << context
|
||||
<< boost::unit_test::log::end();
|
||||
}
|
||||
|
||||
template< typename Context >
|
||||
static void call( const Context& context, const char* file, int line )
|
||||
{
|
||||
boost::unit_test::framework::assertion_result( true );
|
||||
boost::unit_test::unit_test_log
|
||||
<< boost::unit_test::log::begin( file,
|
||||
static_cast< std::size_t >( line ) )
|
||||
<< boost::unit_test::log_successful_tests
|
||||
<< "mock expectation fulfilled: " << context
|
||||
<< boost::unit_test::log::end();
|
||||
}
|
||||
};
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_USE_BOOST_TEST
|
||||
|
||||
#endif // MOCK_ERROR_HPP_INCLUDED
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_ERROR_HPP_INCLUDED
|
||||
#define MOCK_ERROR_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#ifdef MOCK_USE_BOOST_TEST
|
||||
#include "exception.hpp"
|
||||
#include <boost/test/framework.hpp>
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test_suite.hpp>
|
||||
#include <boost/exception/enable_current_exception.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
template< typename Result >
|
||||
struct error
|
||||
{
|
||||
static Result abort()
|
||||
{
|
||||
boost::unit_test::framework::test_unit_aborted(
|
||||
boost::unit_test::framework::current_test_case() );
|
||||
throw boost::enable_current_exception( exception() );
|
||||
}
|
||||
|
||||
static void pass( const char* file, int line )
|
||||
{
|
||||
boost::unit_test::unit_test_log.set_checkpoint( file,
|
||||
static_cast< std::size_t >( line ) );
|
||||
}
|
||||
|
||||
template< typename Context >
|
||||
static void fail( const char* message, const Context& context,
|
||||
const char* file = "unknown location", int line = 0 )
|
||||
{
|
||||
boost::unit_test::framework::assertion_result( false );
|
||||
boost::unit_test::unit_test_log
|
||||
<< boost::unit_test::log::begin( file,
|
||||
static_cast< std::size_t >( line ) )
|
||||
<< boost::unit_test::log_all_errors
|
||||
<< message << ": " << context
|
||||
<< boost::unit_test::log::end();
|
||||
}
|
||||
|
||||
template< typename Context >
|
||||
static void call( const Context& context, const char* file, int line )
|
||||
{
|
||||
boost::unit_test::framework::assertion_result( true );
|
||||
boost::unit_test::unit_test_log
|
||||
<< boost::unit_test::log::begin( file,
|
||||
static_cast< std::size_t >( line ) )
|
||||
<< boost::unit_test::log_successful_tests
|
||||
<< "mock expectation fulfilled: " << context
|
||||
<< boost::unit_test::log::end();
|
||||
}
|
||||
};
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_USE_BOOST_TEST
|
||||
|
||||
#endif // MOCK_ERROR_HPP_INCLUDED
|
||||
|
|
@ -1,24 +1,24 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2012
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_EXCEPTION_HPP_INCLUDED
|
||||
#define MOCK_EXCEPTION_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#ifdef MOCK_USE_BOOST_TEST
|
||||
#include <boost/test/execution_monitor.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
struct exception : virtual boost::execution_aborted
|
||||
{};
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_USE_BOOST_TEST
|
||||
|
||||
#endif // MOCK_EXCEPTION_HPP_INCLUDED
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2012
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_EXCEPTION_HPP_INCLUDED
|
||||
#define MOCK_EXCEPTION_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#ifdef MOCK_USE_BOOST_TEST
|
||||
#include <boost/test/execution_monitor.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
struct exception : virtual boost::execution_aborted
|
||||
{};
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_USE_BOOST_TEST
|
||||
|
||||
#endif // MOCK_EXCEPTION_HPP_INCLUDED
|
||||
|
|
@ -1,25 +1,25 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2011
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_FORMAT_HPP_INCLUDED
|
||||
#define MOCK_FORMAT_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include "detail/formatter.hpp"
|
||||
|
||||
namespace mock
|
||||
{
|
||||
template< typename T >
|
||||
detail::formatter< T > format( const T& t )
|
||||
{
|
||||
return detail::formatter< T >( t );
|
||||
}
|
||||
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_FORMAT_HPP_INCLUDED
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2011
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_FORMAT_HPP_INCLUDED
|
||||
#define MOCK_FORMAT_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include "detail/formatter.hpp"
|
||||
|
||||
namespace mock
|
||||
{
|
||||
template< typename T >
|
||||
detail::formatter< T > format( const T& t )
|
||||
{
|
||||
return detail::formatter< T >( t );
|
||||
}
|
||||
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_FORMAT_HPP_INCLUDED
|
||||
|
|
@ -1,188 +1,188 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2011
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_LOG_HPP_INCLUDED
|
||||
#define MOCK_LOG_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include "stream.hpp"
|
||||
#include "format.hpp"
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/detail/container_fwd.hpp>
|
||||
#include <boost/function_types/is_callable_builtin.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
template< typename T > class shared_ptr;
|
||||
template< typename T > class weak_ptr;
|
||||
template< typename T > class reference_wrapper;
|
||||
|
||||
namespace phoenix
|
||||
{
|
||||
template< typename T > struct actor;
|
||||
}
|
||||
namespace lambda
|
||||
{
|
||||
template< typename T > class lambda_functor;
|
||||
}
|
||||
namespace assign_detail
|
||||
{
|
||||
template< typename T > class generic_list;
|
||||
}
|
||||
}
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template< typename T >
|
||||
void serialize( stream& s, const T& begin, const T& end )
|
||||
{
|
||||
s << '(';
|
||||
for( T it = begin; it != end; ++it )
|
||||
s << (it == begin ? "" : ",") << mock::format( *it );
|
||||
s << ')';
|
||||
}
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
stream& operator<<( stream& s, const std::auto_ptr< T >& t )
|
||||
{
|
||||
return s << mock::format( t.get() );
|
||||
}
|
||||
template< typename T1, typename T2 >
|
||||
stream& operator<<( stream& s, const std::pair< T1, T2 >& p )
|
||||
{
|
||||
return s << '(' << mock::format( p.first )
|
||||
<< ',' << mock::format( p.second ) << ')';
|
||||
}
|
||||
|
||||
template< typename T, typename A >
|
||||
stream& operator<<( stream& s, const std::deque< T, A >& t )
|
||||
{
|
||||
detail::serialize( s, t.begin(), t.end() );
|
||||
return s;
|
||||
}
|
||||
template< typename T, typename A >
|
||||
stream& operator<<( stream& s, const std::list< T, A >& t )
|
||||
{
|
||||
detail::serialize( s, t.begin(), t.end() );
|
||||
return s;
|
||||
}
|
||||
template< typename T, typename A >
|
||||
stream& operator<<( stream& s, const std::vector< T, A >& t )
|
||||
{
|
||||
detail::serialize( s, t.begin(), t.end() );
|
||||
return s;
|
||||
}
|
||||
template< typename K, typename T, typename C, typename A >
|
||||
stream& operator<<( stream& s, const std::map< K, T, C, A >& t )
|
||||
{
|
||||
detail::serialize( s, t.begin(), t.end() );
|
||||
return s;
|
||||
}
|
||||
template< typename K, typename T, typename C, typename A >
|
||||
stream& operator<<( stream& s, const std::multimap< K, T, C, A >& t )
|
||||
{
|
||||
detail::serialize( s, t.begin(), t.end() );
|
||||
return s;
|
||||
}
|
||||
template< typename T, typename C, typename A >
|
||||
stream& operator<<( stream& s, const std::set< T, C, A >& t )
|
||||
{
|
||||
detail::serialize( s, t.begin(), t.end() );
|
||||
return s;
|
||||
}
|
||||
template< typename T, typename C, typename A >
|
||||
stream& operator<<( stream& s, const std::multiset< T, C, A >& t )
|
||||
{
|
||||
detail::serialize( s, t.begin(), t.end() );
|
||||
return s;
|
||||
}
|
||||
template< typename T >
|
||||
stream& operator<<( stream& s,
|
||||
const boost::assign_detail::generic_list< T >& t )
|
||||
{
|
||||
detail::serialize( s, t.begin(), t.end() );
|
||||
return s;
|
||||
}
|
||||
template< typename T >
|
||||
stream& operator<<( stream& s, const boost::reference_wrapper< T >& t )
|
||||
{
|
||||
return s << mock::format( t.get() );
|
||||
}
|
||||
template< typename T >
|
||||
stream& operator<<( stream& s, const boost::shared_ptr< T >& t )
|
||||
{
|
||||
return s << mock::format( t.get() );
|
||||
}
|
||||
template< typename T >
|
||||
stream& operator<<( stream& s, const boost::weak_ptr< T >& t )
|
||||
{
|
||||
return s << mock::format( t.lock() );
|
||||
}
|
||||
|
||||
#ifdef MOCK_SMART_PTR
|
||||
template< typename T >
|
||||
stream& operator<<( stream& s, const std::shared_ptr< T >& t )
|
||||
{
|
||||
return s << mock::format( t.get() );
|
||||
}
|
||||
template< typename T >
|
||||
stream& operator<<( stream& s, const std::weak_ptr< T >& t )
|
||||
{
|
||||
return s << mock::format( t.lock() );
|
||||
}
|
||||
template< typename T, typename D >
|
||||
inline stream& operator<<( stream& s, const std::unique_ptr< T, D >& p )
|
||||
{
|
||||
return s << mock::format( p.get() );
|
||||
}
|
||||
#endif
|
||||
|
||||
template< typename T >
|
||||
stream& operator<<( stream& s, const boost::lambda::lambda_functor< T >& )
|
||||
{
|
||||
return s << '?';
|
||||
}
|
||||
template< typename T >
|
||||
stream& operator<<( stream& s, const boost::phoenix::actor< T >& )
|
||||
{
|
||||
return s << '?';
|
||||
}
|
||||
|
||||
#ifdef MOCK_NULLPTR
|
||||
inline stream& operator<<( stream& s, std::nullptr_t )
|
||||
{
|
||||
return s << "nullptr";
|
||||
}
|
||||
#endif
|
||||
|
||||
template< typename T >
|
||||
typename boost::enable_if<
|
||||
boost::function_types::is_callable_builtin< T >,
|
||||
stream&
|
||||
>::type
|
||||
operator<<( stream& s, T* )
|
||||
{
|
||||
return s << '?';
|
||||
}
|
||||
template< typename T >
|
||||
typename boost::disable_if<
|
||||
boost::function_types::is_callable_builtin< T >,
|
||||
stream&
|
||||
>::type
|
||||
operator<<( stream& s, T* t )
|
||||
{
|
||||
*s.s_ << t;
|
||||
return s;
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_LOG_HPP_INCLUDED
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2011
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_LOG_HPP_INCLUDED
|
||||
#define MOCK_LOG_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include "stream.hpp"
|
||||
#include "format.hpp"
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/detail/container_fwd.hpp>
|
||||
#include <boost/function_types/is_callable_builtin.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
template< typename T > class shared_ptr;
|
||||
template< typename T > class weak_ptr;
|
||||
template< typename T > class reference_wrapper;
|
||||
|
||||
namespace phoenix
|
||||
{
|
||||
template< typename T > struct actor;
|
||||
}
|
||||
namespace lambda
|
||||
{
|
||||
template< typename T > class lambda_functor;
|
||||
}
|
||||
namespace assign_detail
|
||||
{
|
||||
template< typename T > class generic_list;
|
||||
}
|
||||
}
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template< typename T >
|
||||
void serialize( stream& s, const T& begin, const T& end )
|
||||
{
|
||||
s << '(';
|
||||
for( T it = begin; it != end; ++it )
|
||||
s << (it == begin ? "" : ",") << mock::format( *it );
|
||||
s << ')';
|
||||
}
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
stream& operator<<( stream& s, const std::auto_ptr< T >& t )
|
||||
{
|
||||
return s << mock::format( t.get() );
|
||||
}
|
||||
template< typename T1, typename T2 >
|
||||
stream& operator<<( stream& s, const std::pair< T1, T2 >& p )
|
||||
{
|
||||
return s << '(' << mock::format( p.first )
|
||||
<< ',' << mock::format( p.second ) << ')';
|
||||
}
|
||||
|
||||
template< typename T, typename A >
|
||||
stream& operator<<( stream& s, const std::deque< T, A >& t )
|
||||
{
|
||||
detail::serialize( s, t.begin(), t.end() );
|
||||
return s;
|
||||
}
|
||||
template< typename T, typename A >
|
||||
stream& operator<<( stream& s, const std::list< T, A >& t )
|
||||
{
|
||||
detail::serialize( s, t.begin(), t.end() );
|
||||
return s;
|
||||
}
|
||||
template< typename T, typename A >
|
||||
stream& operator<<( stream& s, const std::vector< T, A >& t )
|
||||
{
|
||||
detail::serialize( s, t.begin(), t.end() );
|
||||
return s;
|
||||
}
|
||||
template< typename K, typename T, typename C, typename A >
|
||||
stream& operator<<( stream& s, const std::map< K, T, C, A >& t )
|
||||
{
|
||||
detail::serialize( s, t.begin(), t.end() );
|
||||
return s;
|
||||
}
|
||||
template< typename K, typename T, typename C, typename A >
|
||||
stream& operator<<( stream& s, const std::multimap< K, T, C, A >& t )
|
||||
{
|
||||
detail::serialize( s, t.begin(), t.end() );
|
||||
return s;
|
||||
}
|
||||
template< typename T, typename C, typename A >
|
||||
stream& operator<<( stream& s, const std::set< T, C, A >& t )
|
||||
{
|
||||
detail::serialize( s, t.begin(), t.end() );
|
||||
return s;
|
||||
}
|
||||
template< typename T, typename C, typename A >
|
||||
stream& operator<<( stream& s, const std::multiset< T, C, A >& t )
|
||||
{
|
||||
detail::serialize( s, t.begin(), t.end() );
|
||||
return s;
|
||||
}
|
||||
template< typename T >
|
||||
stream& operator<<( stream& s,
|
||||
const boost::assign_detail::generic_list< T >& t )
|
||||
{
|
||||
detail::serialize( s, t.begin(), t.end() );
|
||||
return s;
|
||||
}
|
||||
template< typename T >
|
||||
stream& operator<<( stream& s, const boost::reference_wrapper< T >& t )
|
||||
{
|
||||
return s << mock::format( t.get() );
|
||||
}
|
||||
template< typename T >
|
||||
stream& operator<<( stream& s, const boost::shared_ptr< T >& t )
|
||||
{
|
||||
return s << mock::format( t.get() );
|
||||
}
|
||||
template< typename T >
|
||||
stream& operator<<( stream& s, const boost::weak_ptr< T >& t )
|
||||
{
|
||||
return s << mock::format( t.lock() );
|
||||
}
|
||||
|
||||
#ifdef MOCK_SMART_PTR
|
||||
template< typename T >
|
||||
stream& operator<<( stream& s, const std::shared_ptr< T >& t )
|
||||
{
|
||||
return s << mock::format( t.get() );
|
||||
}
|
||||
template< typename T >
|
||||
stream& operator<<( stream& s, const std::weak_ptr< T >& t )
|
||||
{
|
||||
return s << mock::format( t.lock() );
|
||||
}
|
||||
template< typename T, typename D >
|
||||
inline stream& operator<<( stream& s, const std::unique_ptr< T, D >& p )
|
||||
{
|
||||
return s << mock::format( p.get() );
|
||||
}
|
||||
#endif
|
||||
|
||||
template< typename T >
|
||||
stream& operator<<( stream& s, const boost::lambda::lambda_functor< T >& )
|
||||
{
|
||||
return s << '?';
|
||||
}
|
||||
template< typename T >
|
||||
stream& operator<<( stream& s, const boost::phoenix::actor< T >& )
|
||||
{
|
||||
return s << '?';
|
||||
}
|
||||
|
||||
#ifdef MOCK_NULLPTR
|
||||
inline stream& operator<<( stream& s, std::nullptr_t )
|
||||
{
|
||||
return s << "nullptr";
|
||||
}
|
||||
#endif
|
||||
|
||||
template< typename T >
|
||||
typename boost::enable_if<
|
||||
boost::function_types::is_callable_builtin< T >,
|
||||
stream&
|
||||
>::type
|
||||
operator<<( stream& s, T* )
|
||||
{
|
||||
return s << '?';
|
||||
}
|
||||
template< typename T >
|
||||
typename boost::disable_if<
|
||||
boost::function_types::is_callable_builtin< T >,
|
||||
stream&
|
||||
>::type
|
||||
operator<<( stream& s, T* t )
|
||||
{
|
||||
*s.s_ << t;
|
||||
return s;
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_LOG_HPP_INCLUDED
|
||||
|
|
@ -1,107 +1,107 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_MATCHER_HPP_INCLUDED
|
||||
#define MOCK_MATCHER_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include "log.hpp"
|
||||
#include "constraint.hpp"
|
||||
#include "detail/is_functor.hpp"
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/ref.hpp>
|
||||
#include <cstring>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
template< typename Actual, typename Expected, typename Enable = void >
|
||||
class matcher
|
||||
{
|
||||
public:
|
||||
explicit matcher( Expected expected )
|
||||
: expected_( expected )
|
||||
{}
|
||||
bool operator()( Actual actual )
|
||||
{
|
||||
return actual == boost::unwrap_ref( expected_ );
|
||||
}
|
||||
friend std::ostream& operator<<(
|
||||
std::ostream& s, const matcher& m )
|
||||
{
|
||||
return s << mock::format( m.expected_ );
|
||||
}
|
||||
private:
|
||||
Expected expected_;
|
||||
};
|
||||
|
||||
template<>
|
||||
class matcher< const char*, const char* >
|
||||
{
|
||||
public:
|
||||
explicit matcher( const char* expected )
|
||||
: expected_( expected )
|
||||
{}
|
||||
bool operator()( const char* actual )
|
||||
{
|
||||
return std::strcmp( actual, expected_ ) == 0;
|
||||
}
|
||||
friend std::ostream& operator<<(
|
||||
std::ostream& s, const matcher& m )
|
||||
{
|
||||
return s << mock::format( m.expected_ );
|
||||
}
|
||||
private:
|
||||
const char* expected_;
|
||||
};
|
||||
|
||||
template< typename Actual, typename Constraint >
|
||||
class matcher< Actual, mock::constraint< Constraint > >
|
||||
{
|
||||
public:
|
||||
explicit matcher( const constraint< Constraint >& c )
|
||||
: c_( c.c_ )
|
||||
{}
|
||||
bool operator()( Actual actual )
|
||||
{
|
||||
return c_( actual );
|
||||
}
|
||||
friend std::ostream& operator<<(
|
||||
std::ostream& s, const matcher& m )
|
||||
{
|
||||
return s << mock::format( m.c_ );
|
||||
}
|
||||
private:
|
||||
Constraint c_;
|
||||
};
|
||||
|
||||
template< typename Actual, typename Functor >
|
||||
class matcher< Actual, Functor,
|
||||
typename boost::enable_if<
|
||||
detail::is_functor< Functor, Actual >
|
||||
>::type
|
||||
>
|
||||
{
|
||||
public:
|
||||
explicit matcher( const Functor& f )
|
||||
: c_( f )
|
||||
{}
|
||||
bool operator()( Actual actual )
|
||||
{
|
||||
return c_( actual );
|
||||
}
|
||||
friend std::ostream& operator<<(
|
||||
std::ostream& s, const matcher& m )
|
||||
{
|
||||
return s << mock::format( m.c_ );
|
||||
}
|
||||
private:
|
||||
Functor c_;
|
||||
};
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_MATCHER_HPP_INCLUDED
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_MATCHER_HPP_INCLUDED
|
||||
#define MOCK_MATCHER_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include "log.hpp"
|
||||
#include "constraint.hpp"
|
||||
#include "detail/is_functor.hpp"
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/ref.hpp>
|
||||
#include <cstring>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
template< typename Actual, typename Expected, typename Enable = void >
|
||||
class matcher
|
||||
{
|
||||
public:
|
||||
explicit matcher( Expected expected )
|
||||
: expected_( expected )
|
||||
{}
|
||||
bool operator()( Actual actual )
|
||||
{
|
||||
return actual == boost::unwrap_ref( expected_ );
|
||||
}
|
||||
friend std::ostream& operator<<(
|
||||
std::ostream& s, const matcher& m )
|
||||
{
|
||||
return s << mock::format( m.expected_ );
|
||||
}
|
||||
private:
|
||||
Expected expected_;
|
||||
};
|
||||
|
||||
template<>
|
||||
class matcher< const char*, const char* >
|
||||
{
|
||||
public:
|
||||
explicit matcher( const char* expected )
|
||||
: expected_( expected )
|
||||
{}
|
||||
bool operator()( const char* actual )
|
||||
{
|
||||
return std::strcmp( actual, expected_ ) == 0;
|
||||
}
|
||||
friend std::ostream& operator<<(
|
||||
std::ostream& s, const matcher& m )
|
||||
{
|
||||
return s << mock::format( m.expected_ );
|
||||
}
|
||||
private:
|
||||
const char* expected_;
|
||||
};
|
||||
|
||||
template< typename Actual, typename Constraint >
|
||||
class matcher< Actual, mock::constraint< Constraint > >
|
||||
{
|
||||
public:
|
||||
explicit matcher( const constraint< Constraint >& c )
|
||||
: c_( c.c_ )
|
||||
{}
|
||||
bool operator()( Actual actual )
|
||||
{
|
||||
return c_( actual );
|
||||
}
|
||||
friend std::ostream& operator<<(
|
||||
std::ostream& s, const matcher& m )
|
||||
{
|
||||
return s << mock::format( m.c_ );
|
||||
}
|
||||
private:
|
||||
Constraint c_;
|
||||
};
|
||||
|
||||
template< typename Actual, typename Functor >
|
||||
class matcher< Actual, Functor,
|
||||
typename boost::enable_if<
|
||||
detail::is_functor< Functor, Actual >
|
||||
>::type
|
||||
>
|
||||
{
|
||||
public:
|
||||
explicit matcher( const Functor& f )
|
||||
: c_( f )
|
||||
{}
|
||||
bool operator()( Actual actual )
|
||||
{
|
||||
return c_( actual );
|
||||
}
|
||||
friend std::ostream& operator<<(
|
||||
std::ostream& s, const matcher& m )
|
||||
{
|
||||
return s << mock::format( m.c_ );
|
||||
}
|
||||
private:
|
||||
Functor c_;
|
||||
};
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_MATCHER_HPP_INCLUDED
|
||||
|
|
@ -1,242 +1,242 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_MOCK_HPP_INCLUDED
|
||||
#define MOCK_MOCK_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include "object.hpp"
|
||||
#include "reset.hpp"
|
||||
#include "verify.hpp"
|
||||
#include "detail/functor.hpp"
|
||||
#include "detail/function.hpp"
|
||||
#include "detail/type_name.hpp"
|
||||
#include "detail/signature.hpp"
|
||||
#include "detail/parameter.hpp"
|
||||
#include "detail/cleanup.hpp"
|
||||
#include <boost/preprocessor/repetition/repeat.hpp>
|
||||
#include <boost/preprocessor/stringize.hpp>
|
||||
#include <boost/utility/identity_type.hpp>
|
||||
#include <boost/mpl/assert.hpp>
|
||||
|
||||
#define MOCK_CLASS(T) \
|
||||
struct T : mock::object
|
||||
|
||||
#define MOCK_FUNCTION_TYPE(S, tpn) \
|
||||
tpn boost::remove_pointer< tpn BOOST_IDENTITY_TYPE((S)) >::type
|
||||
|
||||
#ifdef MOCK_VARIADIC_MACROS
|
||||
|
||||
#define MOCK_BASE_CLASS(T, ...) \
|
||||
struct T : __VA_ARGS__, mock::object, mock::detail::base< __VA_ARGS__ >
|
||||
|
||||
#define MOCK_FUNCTOR(f, ...) \
|
||||
mock::detail::functor< MOCK_FUNCTION_TYPE((__VA_ARGS__),) > f, f##_mock
|
||||
#define MOCK_FUNCTOR_TPL(f, ...) \
|
||||
mock::detail::functor< \
|
||||
MOCK_FUNCTION_TYPE((__VA_ARGS__), typename) > f, f##_mock
|
||||
|
||||
#else // MOCK_VARIADIC_MACROS
|
||||
|
||||
#define MOCK_BASE_CLASS(T, I) \
|
||||
struct T : I, mock::object, mock::detail::base< I >
|
||||
|
||||
#define MOCK_FUNCTOR(f, S) \
|
||||
mock::detail::functor< MOCK_FUNCTION_TYPE(S,) > f, f##_mock
|
||||
#define MOCK_FUNCTOR_TPL(f, S) \
|
||||
mock::detail::functor< \
|
||||
MOCK_FUNCTION_TYPE(S, typename) > f, f##_mock
|
||||
|
||||
#endif // MOCK_VARIADIC_MACROS
|
||||
|
||||
#define MOCK_HELPER(t) \
|
||||
t##_mock( mock::detail::root, BOOST_PP_STRINGIZE(t) )
|
||||
#define MOCK_ANONYMOUS_HELPER(t) \
|
||||
t##_mock( mock::detail::root, "?." )
|
||||
|
||||
#define MOCK_METHOD_HELPER(S, t, tpn) \
|
||||
mutable mock::detail::function< MOCK_FUNCTION_TYPE(S, tpn) > t##_mock_; \
|
||||
mock::detail::function< MOCK_FUNCTION_TYPE(S, tpn) >& t##_mock( \
|
||||
const mock::detail::context&, \
|
||||
boost::unit_test::const_string instance ) const \
|
||||
{ \
|
||||
mock::detail::configure( *this, t##_mock_, \
|
||||
instance.substr( 0, instance.rfind( BOOST_PP_STRINGIZE(t) ) ), \
|
||||
MOCK_TYPE_NAME(*this), \
|
||||
BOOST_PP_STRINGIZE(t) ); \
|
||||
return t##_mock_; \
|
||||
}
|
||||
|
||||
#define MOCK_PARAM(z, n, d) \
|
||||
BOOST_PP_COMMA_IF(n) d, n >::type p##n
|
||||
#define MOCK_PARAMS(n, S, tpn) \
|
||||
BOOST_PP_REPEAT(n, MOCK_PARAM, \
|
||||
tpn mock::detail::parameter< MOCK_FUNCTION_TYPE(S, tpn))
|
||||
#define MOCK_DECL(M, n, S, c, tpn) \
|
||||
tpn boost::function_types::result_type< \
|
||||
MOCK_FUNCTION_TYPE(S, tpn) >::type M( \
|
||||
MOCK_PARAMS(n, S, tpn) ) c
|
||||
|
||||
#define MOCK_METHOD_AUX(M, n, S, t, c, tpn) \
|
||||
MOCK_DECL(M, n, S, c, tpn) \
|
||||
{ \
|
||||
BOOST_MPL_ASSERT_RELATION( n, ==, \
|
||||
boost::function_types::function_arity< \
|
||||
MOCK_FUNCTION_TYPE(S, tpn) >::value ); \
|
||||
return MOCK_ANONYMOUS_HELPER(t)( \
|
||||
BOOST_PP_ENUM_PARAMS(n, p) ); \
|
||||
}
|
||||
|
||||
#define MOCK_METHOD_EXT(M, n, S, t) \
|
||||
MOCK_METHOD_AUX(M, n, S, t,,) \
|
||||
MOCK_METHOD_AUX(M, n, S, t, const,) \
|
||||
MOCK_METHOD_HELPER(S, t,)
|
||||
#define MOCK_CONST_METHOD_EXT(M, n, S, t) \
|
||||
MOCK_METHOD_AUX(M, n, S, t, const,) \
|
||||
MOCK_METHOD_HELPER(S, t,)
|
||||
#define MOCK_NON_CONST_METHOD_EXT(M, n, S, t) \
|
||||
MOCK_METHOD_AUX(M, n, S, t,,) \
|
||||
MOCK_METHOD_HELPER(S, t,)
|
||||
|
||||
#define MOCK_METHOD_EXT_TPL(M, n, S, t) \
|
||||
MOCK_METHOD_AUX(M, n, S, t,, typename) \
|
||||
MOCK_METHOD_AUX(M, n, S, t, const, typename) \
|
||||
MOCK_METHOD_HELPER(S, t, typename)
|
||||
#define MOCK_CONST_METHOD_EXT_TPL(M, n, S, t) \
|
||||
MOCK_METHOD_AUX(M, n, S, t, const, typename) \
|
||||
MOCK_METHOD_HELPER(S, t, typename)
|
||||
#define MOCK_NON_CONST_METHOD_EXT_TPL(M, n, S, t) \
|
||||
MOCK_METHOD_AUX(M, n, S, t,, typename) \
|
||||
MOCK_METHOD_HELPER(S, t, typename)
|
||||
|
||||
#define MOCK_CONVERSION_OPERATOR(M, T, t) \
|
||||
M T() const { return MOCK_ANONYMOUS_HELPER(t)(); } \
|
||||
M T() { return MOCK_ANONYMOUS_HELPER(t)(); } \
|
||||
MOCK_METHOD_HELPER(T(), t,)
|
||||
#define MOCK_CONST_CONVERSION_OPERATOR(M, T, t) \
|
||||
M T() const { return MOCK_ANONYMOUS_HELPER(t)(); } \
|
||||
MOCK_METHOD_HELPER(T(), t,)
|
||||
#define MOCK_NON_CONST_CONVERSION_OPERATOR(M, T, t) \
|
||||
M T() { return MOCK_ANONYMOUS_HELPER(t)(); } \
|
||||
MOCK_METHOD_HELPER(T(), t,)
|
||||
|
||||
#define MOCK_CONVERSION_OPERATOR_TPL(M, T, t) \
|
||||
M T() const { return MOCK_ANONYMOUS_HELPER(t)(); } \
|
||||
M T() { return MOCK_ANONYMOUS_HELPER(t)(); } \
|
||||
MOCK_METHOD_HELPER(T(), t, typename)
|
||||
#define MOCK_CONST_CONVERSION_OPERATOR_TPL(M, T, t) \
|
||||
M T() const { return MOCK_ANONYMOUS_HELPER(t)(); } \
|
||||
MOCK_METHOD_HELPER(T(), t, typename)
|
||||
#define MOCK_NON_CONST_CONVERSION_OPERATOR_TPL(M, T, t) \
|
||||
M T() { return MOCK_ANONYMOUS_HELPER(t)(); } \
|
||||
MOCK_METHOD_HELPER(T(), t, typename)
|
||||
|
||||
#define MOCK_FUNCTION_HELPER(S, t, s, tpn) \
|
||||
s mock::detail::function< MOCK_FUNCTION_TYPE(S, tpn) >& t##_mock( \
|
||||
mock::detail::context& context, \
|
||||
boost::unit_test::const_string instance ) \
|
||||
{ \
|
||||
static mock::detail::function< MOCK_FUNCTION_TYPE(S, tpn) > f; \
|
||||
return f( context, instance ); \
|
||||
}
|
||||
|
||||
#define MOCK_CONSTRUCTOR_AUX(T, n, A, t, tpn) \
|
||||
T( MOCK_PARAMS(n, void A, tpn) ) \
|
||||
{ \
|
||||
MOCK_HELPER(t)( BOOST_PP_ENUM_PARAMS(n, p) ); \
|
||||
} \
|
||||
MOCK_FUNCTION_HELPER(void A, t, static, tpn)
|
||||
|
||||
#define MOCK_CONSTRUCTOR(T, n, A, t) \
|
||||
MOCK_CONSTRUCTOR_AUX(T, n, A, t,)
|
||||
#define MOCK_CONSTRUCTOR_TPL(T, n, A, t) \
|
||||
MOCK_CONSTRUCTOR_AUX(T, n, A, t, typename)
|
||||
|
||||
#define MOCK_DESTRUCTOR(T, t) \
|
||||
T() { try { MOCK_ANONYMOUS_HELPER(t)(); } catch( ... ) {} } \
|
||||
MOCK_METHOD_HELPER(void(), t,)
|
||||
|
||||
#define MOCK_FUNCTION_AUX(F, n, S, t, s, tpn) \
|
||||
MOCK_FUNCTION_HELPER(S, t, s, tpn) \
|
||||
s MOCK_DECL(F, n, S,,tpn) \
|
||||
{ \
|
||||
BOOST_MPL_ASSERT_RELATION( n, ==, \
|
||||
boost::function_types::function_arity< \
|
||||
MOCK_FUNCTION_TYPE(S, tpn) >::value ); \
|
||||
return MOCK_HELPER(t)( BOOST_PP_ENUM_PARAMS(n, p) ); \
|
||||
}
|
||||
|
||||
#ifdef MOCK_VARIADIC_MACROS
|
||||
|
||||
#define MOCK_VARIADIC_ELEM_0(e0, ...) e0
|
||||
#define MOCK_VARIADIC_ELEM_1(e0, e1, ...) e1
|
||||
#define MOCK_VARIADIC_ELEM_2(e0, e1, e2, ...) e2
|
||||
|
||||
#define MOCK_METHOD(M, ... ) \
|
||||
MOCK_METHOD_EXT(M, \
|
||||
MOCK_VARIADIC_ELEM_0(__VA_ARGS__ ), \
|
||||
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, MOCK_SIGNATURE(M)), \
|
||||
MOCK_VARIADIC_ELEM_2(__VA_ARGS__, M, M))
|
||||
#define MOCK_CONST_METHOD(M, n, ... ) \
|
||||
MOCK_CONST_METHOD_EXT(M, n, \
|
||||
MOCK_VARIADIC_ELEM_0(__VA_ARGS__), \
|
||||
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, M))
|
||||
#define MOCK_NON_CONST_METHOD(M, n, ... ) \
|
||||
MOCK_NON_CONST_METHOD_EXT(M, n, \
|
||||
MOCK_VARIADIC_ELEM_0(__VA_ARGS__), \
|
||||
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, M))
|
||||
|
||||
#define MOCK_METHOD_TPL(M, n, ... ) \
|
||||
MOCK_METHOD_EXT_TPL(M, n, \
|
||||
MOCK_VARIADIC_ELEM_0(__VA_ARGS__), \
|
||||
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, M))
|
||||
#define MOCK_CONST_METHOD_TPL(M, n, ... ) \
|
||||
MOCK_CONST_METHOD_EXT_TPL(M, n, \
|
||||
MOCK_VARIADIC_ELEM_0(__VA_ARGS__), \
|
||||
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, M))
|
||||
#define MOCK_NON_CONST_METHOD_TPL(M, n, ... ) \
|
||||
MOCK_NON_CONST_METHOD_EXT_TPL(M, n, \
|
||||
MOCK_VARIADIC_ELEM_0(__VA_ARGS__), \
|
||||
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, M))
|
||||
|
||||
#define MOCK_FUNCTION(F, n, ...) \
|
||||
MOCK_FUNCTION_AUX(F, n, \
|
||||
MOCK_VARIADIC_ELEM_0(__VA_ARGS__), \
|
||||
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, F),,)
|
||||
|
||||
#define MOCK_STATIC_METHOD(F, n, ...) \
|
||||
MOCK_FUNCTION_AUX(F, n, \
|
||||
MOCK_VARIADIC_ELEM_0(__VA_ARGS__), \
|
||||
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, F), static,)
|
||||
|
||||
#define MOCK_STATIC_METHOD_TPL(F, n, ...) \
|
||||
MOCK_FUNCTION_AUX(F, n, \
|
||||
MOCK_VARIADIC_ELEM_0(__VA_ARGS__), \
|
||||
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, F), \
|
||||
static, typename)
|
||||
|
||||
#else // MOCK_VARIADIC_MACROS
|
||||
|
||||
#define MOCK_METHOD(M, n) \
|
||||
MOCK_METHOD_EXT(M, n, MOCK_SIGNATURE(M), M)
|
||||
|
||||
#define MOCK_FUNCTION(F, n, S, t) \
|
||||
MOCK_FUNCTION_AUX(F, n, S, t,,)
|
||||
|
||||
#define MOCK_STATIC_METHOD(F, n, S, t) \
|
||||
MOCK_FUNCTION_AUX(F, n, S, t, static,)
|
||||
#define MOCK_STATIC_METHOD_TPL(F, n, S, t) \
|
||||
MOCK_FUNCTION_AUX(F, n, S, t, static, typename)
|
||||
|
||||
#endif // MOCK_VARIADIC_MACROS
|
||||
|
||||
#define MOCK_EXPECT(t) MOCK_HELPER(t).expect( __FILE__, __LINE__ )
|
||||
#define MOCK_RESET(t) MOCK_HELPER(t).reset( __FILE__, __LINE__ )
|
||||
#define MOCK_VERIFY(t) MOCK_HELPER(t).verify( __FILE__, __LINE__ )
|
||||
|
||||
#endif // MOCK_MOCK_HPP_INCLUDED
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_MOCK_HPP_INCLUDED
|
||||
#define MOCK_MOCK_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include "object.hpp"
|
||||
#include "reset.hpp"
|
||||
#include "verify.hpp"
|
||||
#include "detail/functor.hpp"
|
||||
#include "detail/function.hpp"
|
||||
#include "detail/type_name.hpp"
|
||||
#include "detail/signature.hpp"
|
||||
#include "detail/parameter.hpp"
|
||||
#include "detail/cleanup.hpp"
|
||||
#include <boost/preprocessor/repetition/repeat.hpp>
|
||||
#include <boost/preprocessor/stringize.hpp>
|
||||
#include <boost/utility/identity_type.hpp>
|
||||
#include <boost/mpl/assert.hpp>
|
||||
|
||||
#define MOCK_CLASS(T) \
|
||||
struct T : mock::object
|
||||
|
||||
#define MOCK_FUNCTION_TYPE(S, tpn) \
|
||||
tpn boost::remove_pointer< tpn BOOST_IDENTITY_TYPE((S)) >::type
|
||||
|
||||
#ifdef MOCK_VARIADIC_MACROS
|
||||
|
||||
#define MOCK_BASE_CLASS(T, ...) \
|
||||
struct T : __VA_ARGS__, mock::object, mock::detail::base< __VA_ARGS__ >
|
||||
|
||||
#define MOCK_FUNCTOR(f, ...) \
|
||||
mock::detail::functor< MOCK_FUNCTION_TYPE((__VA_ARGS__),) > f, f##_mock
|
||||
#define MOCK_FUNCTOR_TPL(f, ...) \
|
||||
mock::detail::functor< \
|
||||
MOCK_FUNCTION_TYPE((__VA_ARGS__), typename) > f, f##_mock
|
||||
|
||||
#else // MOCK_VARIADIC_MACROS
|
||||
|
||||
#define MOCK_BASE_CLASS(T, I) \
|
||||
struct T : I, mock::object, mock::detail::base< I >
|
||||
|
||||
#define MOCK_FUNCTOR(f, S) \
|
||||
mock::detail::functor< MOCK_FUNCTION_TYPE(S,) > f, f##_mock
|
||||
#define MOCK_FUNCTOR_TPL(f, S) \
|
||||
mock::detail::functor< \
|
||||
MOCK_FUNCTION_TYPE(S, typename) > f, f##_mock
|
||||
|
||||
#endif // MOCK_VARIADIC_MACROS
|
||||
|
||||
#define MOCK_HELPER(t) \
|
||||
t##_mock( mock::detail::root, BOOST_PP_STRINGIZE(t) )
|
||||
#define MOCK_ANONYMOUS_HELPER(t) \
|
||||
t##_mock( mock::detail::root, "?." )
|
||||
|
||||
#define MOCK_METHOD_HELPER(S, t, tpn) \
|
||||
mutable mock::detail::function< MOCK_FUNCTION_TYPE(S, tpn) > t##_mock_; \
|
||||
mock::detail::function< MOCK_FUNCTION_TYPE(S, tpn) >& t##_mock( \
|
||||
const mock::detail::context&, \
|
||||
boost::unit_test::const_string instance ) const \
|
||||
{ \
|
||||
mock::detail::configure( *this, t##_mock_, \
|
||||
instance.substr( 0, instance.rfind( BOOST_PP_STRINGIZE(t) ) ), \
|
||||
MOCK_TYPE_NAME(*this), \
|
||||
BOOST_PP_STRINGIZE(t) ); \
|
||||
return t##_mock_; \
|
||||
}
|
||||
|
||||
#define MOCK_PARAM(z, n, d) \
|
||||
BOOST_PP_COMMA_IF(n) d, n >::type p##n
|
||||
#define MOCK_PARAMS(n, S, tpn) \
|
||||
BOOST_PP_REPEAT(n, MOCK_PARAM, \
|
||||
tpn mock::detail::parameter< MOCK_FUNCTION_TYPE(S, tpn))
|
||||
#define MOCK_DECL(M, n, S, c, tpn) \
|
||||
tpn boost::function_types::result_type< \
|
||||
MOCK_FUNCTION_TYPE(S, tpn) >::type M( \
|
||||
MOCK_PARAMS(n, S, tpn) ) c
|
||||
|
||||
#define MOCK_METHOD_AUX(M, n, S, t, c, tpn) \
|
||||
MOCK_DECL(M, n, S, c, tpn) \
|
||||
{ \
|
||||
BOOST_MPL_ASSERT_RELATION( n, ==, \
|
||||
boost::function_types::function_arity< \
|
||||
MOCK_FUNCTION_TYPE(S, tpn) >::value ); \
|
||||
return MOCK_ANONYMOUS_HELPER(t)( \
|
||||
BOOST_PP_ENUM_PARAMS(n, p) ); \
|
||||
}
|
||||
|
||||
#define MOCK_METHOD_EXT(M, n, S, t) \
|
||||
MOCK_METHOD_AUX(M, n, S, t,,) \
|
||||
MOCK_METHOD_AUX(M, n, S, t, const,) \
|
||||
MOCK_METHOD_HELPER(S, t,)
|
||||
#define MOCK_CONST_METHOD_EXT(M, n, S, t) \
|
||||
MOCK_METHOD_AUX(M, n, S, t, const,) \
|
||||
MOCK_METHOD_HELPER(S, t,)
|
||||
#define MOCK_NON_CONST_METHOD_EXT(M, n, S, t) \
|
||||
MOCK_METHOD_AUX(M, n, S, t,,) \
|
||||
MOCK_METHOD_HELPER(S, t,)
|
||||
|
||||
#define MOCK_METHOD_EXT_TPL(M, n, S, t) \
|
||||
MOCK_METHOD_AUX(M, n, S, t,, typename) \
|
||||
MOCK_METHOD_AUX(M, n, S, t, const, typename) \
|
||||
MOCK_METHOD_HELPER(S, t, typename)
|
||||
#define MOCK_CONST_METHOD_EXT_TPL(M, n, S, t) \
|
||||
MOCK_METHOD_AUX(M, n, S, t, const, typename) \
|
||||
MOCK_METHOD_HELPER(S, t, typename)
|
||||
#define MOCK_NON_CONST_METHOD_EXT_TPL(M, n, S, t) \
|
||||
MOCK_METHOD_AUX(M, n, S, t,, typename) \
|
||||
MOCK_METHOD_HELPER(S, t, typename)
|
||||
|
||||
#define MOCK_CONVERSION_OPERATOR(M, T, t) \
|
||||
M T() const { return MOCK_ANONYMOUS_HELPER(t)(); } \
|
||||
M T() { return MOCK_ANONYMOUS_HELPER(t)(); } \
|
||||
MOCK_METHOD_HELPER(T(), t,)
|
||||
#define MOCK_CONST_CONVERSION_OPERATOR(M, T, t) \
|
||||
M T() const { return MOCK_ANONYMOUS_HELPER(t)(); } \
|
||||
MOCK_METHOD_HELPER(T(), t,)
|
||||
#define MOCK_NON_CONST_CONVERSION_OPERATOR(M, T, t) \
|
||||
M T() { return MOCK_ANONYMOUS_HELPER(t)(); } \
|
||||
MOCK_METHOD_HELPER(T(), t,)
|
||||
|
||||
#define MOCK_CONVERSION_OPERATOR_TPL(M, T, t) \
|
||||
M T() const { return MOCK_ANONYMOUS_HELPER(t)(); } \
|
||||
M T() { return MOCK_ANONYMOUS_HELPER(t)(); } \
|
||||
MOCK_METHOD_HELPER(T(), t, typename)
|
||||
#define MOCK_CONST_CONVERSION_OPERATOR_TPL(M, T, t) \
|
||||
M T() const { return MOCK_ANONYMOUS_HELPER(t)(); } \
|
||||
MOCK_METHOD_HELPER(T(), t, typename)
|
||||
#define MOCK_NON_CONST_CONVERSION_OPERATOR_TPL(M, T, t) \
|
||||
M T() { return MOCK_ANONYMOUS_HELPER(t)(); } \
|
||||
MOCK_METHOD_HELPER(T(), t, typename)
|
||||
|
||||
#define MOCK_FUNCTION_HELPER(S, t, s, tpn) \
|
||||
s mock::detail::function< MOCK_FUNCTION_TYPE(S, tpn) >& t##_mock( \
|
||||
mock::detail::context& context, \
|
||||
boost::unit_test::const_string instance ) \
|
||||
{ \
|
||||
static mock::detail::function< MOCK_FUNCTION_TYPE(S, tpn) > f; \
|
||||
return f( context, instance ); \
|
||||
}
|
||||
|
||||
#define MOCK_CONSTRUCTOR_AUX(T, n, A, t, tpn) \
|
||||
T( MOCK_PARAMS(n, void A, tpn) ) \
|
||||
{ \
|
||||
MOCK_HELPER(t)( BOOST_PP_ENUM_PARAMS(n, p) ); \
|
||||
} \
|
||||
MOCK_FUNCTION_HELPER(void A, t, static, tpn)
|
||||
|
||||
#define MOCK_CONSTRUCTOR(T, n, A, t) \
|
||||
MOCK_CONSTRUCTOR_AUX(T, n, A, t,)
|
||||
#define MOCK_CONSTRUCTOR_TPL(T, n, A, t) \
|
||||
MOCK_CONSTRUCTOR_AUX(T, n, A, t, typename)
|
||||
|
||||
#define MOCK_DESTRUCTOR(T, t) \
|
||||
T() { try { MOCK_ANONYMOUS_HELPER(t)(); } catch( ... ) {} } \
|
||||
MOCK_METHOD_HELPER(void(), t,)
|
||||
|
||||
#define MOCK_FUNCTION_AUX(F, n, S, t, s, tpn) \
|
||||
MOCK_FUNCTION_HELPER(S, t, s, tpn) \
|
||||
s MOCK_DECL(F, n, S,,tpn) \
|
||||
{ \
|
||||
BOOST_MPL_ASSERT_RELATION( n, ==, \
|
||||
boost::function_types::function_arity< \
|
||||
MOCK_FUNCTION_TYPE(S, tpn) >::value ); \
|
||||
return MOCK_HELPER(t)( BOOST_PP_ENUM_PARAMS(n, p) ); \
|
||||
}
|
||||
|
||||
#ifdef MOCK_VARIADIC_MACROS
|
||||
|
||||
#define MOCK_VARIADIC_ELEM_0(e0, ...) e0
|
||||
#define MOCK_VARIADIC_ELEM_1(e0, e1, ...) e1
|
||||
#define MOCK_VARIADIC_ELEM_2(e0, e1, e2, ...) e2
|
||||
|
||||
#define MOCK_METHOD(M, ... ) \
|
||||
MOCK_METHOD_EXT(M, \
|
||||
MOCK_VARIADIC_ELEM_0(__VA_ARGS__ ), \
|
||||
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, MOCK_SIGNATURE(M)), \
|
||||
MOCK_VARIADIC_ELEM_2(__VA_ARGS__, M, M))
|
||||
#define MOCK_CONST_METHOD(M, n, ... ) \
|
||||
MOCK_CONST_METHOD_EXT(M, n, \
|
||||
MOCK_VARIADIC_ELEM_0(__VA_ARGS__), \
|
||||
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, M))
|
||||
#define MOCK_NON_CONST_METHOD(M, n, ... ) \
|
||||
MOCK_NON_CONST_METHOD_EXT(M, n, \
|
||||
MOCK_VARIADIC_ELEM_0(__VA_ARGS__), \
|
||||
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, M))
|
||||
|
||||
#define MOCK_METHOD_TPL(M, n, ... ) \
|
||||
MOCK_METHOD_EXT_TPL(M, n, \
|
||||
MOCK_VARIADIC_ELEM_0(__VA_ARGS__), \
|
||||
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, M))
|
||||
#define MOCK_CONST_METHOD_TPL(M, n, ... ) \
|
||||
MOCK_CONST_METHOD_EXT_TPL(M, n, \
|
||||
MOCK_VARIADIC_ELEM_0(__VA_ARGS__), \
|
||||
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, M))
|
||||
#define MOCK_NON_CONST_METHOD_TPL(M, n, ... ) \
|
||||
MOCK_NON_CONST_METHOD_EXT_TPL(M, n, \
|
||||
MOCK_VARIADIC_ELEM_0(__VA_ARGS__), \
|
||||
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, M))
|
||||
|
||||
#define MOCK_FUNCTION(F, n, ...) \
|
||||
MOCK_FUNCTION_AUX(F, n, \
|
||||
MOCK_VARIADIC_ELEM_0(__VA_ARGS__), \
|
||||
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, F),,)
|
||||
|
||||
#define MOCK_STATIC_METHOD(F, n, ...) \
|
||||
MOCK_FUNCTION_AUX(F, n, \
|
||||
MOCK_VARIADIC_ELEM_0(__VA_ARGS__), \
|
||||
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, F), static,)
|
||||
|
||||
#define MOCK_STATIC_METHOD_TPL(F, n, ...) \
|
||||
MOCK_FUNCTION_AUX(F, n, \
|
||||
MOCK_VARIADIC_ELEM_0(__VA_ARGS__), \
|
||||
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, F), \
|
||||
static, typename)
|
||||
|
||||
#else // MOCK_VARIADIC_MACROS
|
||||
|
||||
#define MOCK_METHOD(M, n) \
|
||||
MOCK_METHOD_EXT(M, n, MOCK_SIGNATURE(M), M)
|
||||
|
||||
#define MOCK_FUNCTION(F, n, S, t) \
|
||||
MOCK_FUNCTION_AUX(F, n, S, t,,)
|
||||
|
||||
#define MOCK_STATIC_METHOD(F, n, S, t) \
|
||||
MOCK_FUNCTION_AUX(F, n, S, t, static,)
|
||||
#define MOCK_STATIC_METHOD_TPL(F, n, S, t) \
|
||||
MOCK_FUNCTION_AUX(F, n, S, t, static, typename)
|
||||
|
||||
#endif // MOCK_VARIADIC_MACROS
|
||||
|
||||
#define MOCK_EXPECT(t) MOCK_HELPER(t).expect( __FILE__, __LINE__ )
|
||||
#define MOCK_RESET(t) MOCK_HELPER(t).reset( __FILE__, __LINE__ )
|
||||
#define MOCK_VERIFY(t) MOCK_HELPER(t).verify( __FILE__, __LINE__ )
|
||||
|
||||
#endif // MOCK_MOCK_HPP_INCLUDED
|
||||
|
|
@ -1,74 +1,74 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_OBJECT_HPP_INCLUDED
|
||||
#define MOCK_OBJECT_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include "detail/root.hpp"
|
||||
#include "detail/type_name.hpp"
|
||||
#include "detail/object_impl.hpp"
|
||||
#include <boost/test/utils/basic_cstring/basic_cstring.hpp>
|
||||
#include <boost/type_traits/is_base_of.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
class object;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template< typename E >
|
||||
E& configure( const object& o, E& e,
|
||||
boost::unit_test::const_string instance,
|
||||
boost::optional< type_name > type,
|
||||
boost::unit_test::const_string name );
|
||||
|
||||
template< typename T, typename E >
|
||||
E& configure( const T& t, E& e,
|
||||
boost::unit_test::const_string instance,
|
||||
boost::optional< type_name > type,
|
||||
boost::unit_test::const_string name,
|
||||
typename boost::disable_if<
|
||||
typename boost::is_base_of< object, T >
|
||||
>::type* = 0 )
|
||||
{
|
||||
e.configure( detail::root, &t, instance, type, name );
|
||||
return e;
|
||||
}
|
||||
}
|
||||
class object
|
||||
{
|
||||
public:
|
||||
object()
|
||||
: impl_( boost::make_shared< detail::object_impl >() )
|
||||
{}
|
||||
protected:
|
||||
~object()
|
||||
{}
|
||||
public:
|
||||
boost::shared_ptr< detail::object_impl > impl_;
|
||||
};
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template< typename E >
|
||||
E& configure( const object& o, E& e,
|
||||
boost::unit_test::const_string instance,
|
||||
boost::optional< type_name > type,
|
||||
boost::unit_test::const_string name )
|
||||
{
|
||||
e.configure( *o.impl_, o.impl_.get(), instance, type, name );
|
||||
return e;
|
||||
}
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_OBJECT_HPP_INCLUDED
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_OBJECT_HPP_INCLUDED
|
||||
#define MOCK_OBJECT_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include "detail/root.hpp"
|
||||
#include "detail/type_name.hpp"
|
||||
#include "detail/object_impl.hpp"
|
||||
#include <boost/test/utils/basic_cstring/basic_cstring.hpp>
|
||||
#include <boost/type_traits/is_base_of.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
class object;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template< typename E >
|
||||
E& configure( const object& o, E& e,
|
||||
boost::unit_test::const_string instance,
|
||||
boost::optional< type_name > type,
|
||||
boost::unit_test::const_string name );
|
||||
|
||||
template< typename T, typename E >
|
||||
E& configure( const T& t, E& e,
|
||||
boost::unit_test::const_string instance,
|
||||
boost::optional< type_name > type,
|
||||
boost::unit_test::const_string name,
|
||||
typename boost::disable_if<
|
||||
typename boost::is_base_of< object, T >
|
||||
>::type* = 0 )
|
||||
{
|
||||
e.configure( detail::root, &t, instance, type, name );
|
||||
return e;
|
||||
}
|
||||
}
|
||||
class object
|
||||
{
|
||||
public:
|
||||
object()
|
||||
: impl_( boost::make_shared< detail::object_impl >() )
|
||||
{}
|
||||
protected:
|
||||
~object()
|
||||
{}
|
||||
public:
|
||||
boost::shared_ptr< detail::object_impl > impl_;
|
||||
};
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template< typename E >
|
||||
E& configure( const object& o, E& e,
|
||||
boost::unit_test::const_string instance,
|
||||
boost::optional< type_name > type,
|
||||
boost::unit_test::const_string name )
|
||||
{
|
||||
e.configure( *o.impl_, o.impl_.get(), instance, type, name );
|
||||
return e;
|
||||
}
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_OBJECT_HPP_INCLUDED
|
||||
|
|
@ -1,34 +1,34 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2012
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_RESET_HPP_INCLUDED
|
||||
#define MOCK_RESET_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include "object.hpp"
|
||||
#include "detail/root.hpp"
|
||||
#include "detail/functor.hpp"
|
||||
|
||||
namespace mock
|
||||
{
|
||||
inline void reset()
|
||||
{
|
||||
detail::root.reset();
|
||||
}
|
||||
inline void reset( const object& o )
|
||||
{
|
||||
o.impl_->reset();
|
||||
}
|
||||
template< typename Signature >
|
||||
void reset( detail::functor< Signature >& f )
|
||||
{
|
||||
f.reset();
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_RESET_HPP_INCLUDED
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2012
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_RESET_HPP_INCLUDED
|
||||
#define MOCK_RESET_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include "object.hpp"
|
||||
#include "detail/root.hpp"
|
||||
#include "detail/functor.hpp"
|
||||
|
||||
namespace mock
|
||||
{
|
||||
inline void reset()
|
||||
{
|
||||
detail::root.reset();
|
||||
}
|
||||
inline void reset( const object& o )
|
||||
{
|
||||
o.impl_->reset();
|
||||
}
|
||||
template< typename Signature >
|
||||
void reset( detail::functor< Signature >& f )
|
||||
{
|
||||
f.reset();
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_RESET_HPP_INCLUDED
|
||||
|
|
@ -1,29 +1,29 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_SEQUENCE_HPP_INCLUDED
|
||||
#define MOCK_SEQUENCE_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include "detail/sequence_impl.hpp"
|
||||
#include <boost/make_shared.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
class sequence
|
||||
{
|
||||
public:
|
||||
sequence()
|
||||
: impl_( boost::make_shared< detail::sequence_impl >() )
|
||||
{}
|
||||
|
||||
boost::shared_ptr< detail::sequence_impl > impl_;
|
||||
};
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_SEQUENCE_HPP_INCLUDED
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_SEQUENCE_HPP_INCLUDED
|
||||
#define MOCK_SEQUENCE_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include "detail/sequence_impl.hpp"
|
||||
#include <boost/make_shared.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
class sequence
|
||||
{
|
||||
public:
|
||||
sequence()
|
||||
: impl_( boost::make_shared< detail::sequence_impl >() )
|
||||
{}
|
||||
|
||||
boost::shared_ptr< detail::sequence_impl > impl_;
|
||||
};
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_SEQUENCE_HPP_INCLUDED
|
||||
|
|
@ -1,142 +1,142 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2011
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_STREAM_HPP_INCLUDED
|
||||
#define MOCK_STREAM_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <ostream>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
struct stream
|
||||
{
|
||||
explicit stream( std::ostream& s )
|
||||
: s_( &s )
|
||||
{}
|
||||
std::ostream* s_;
|
||||
};
|
||||
|
||||
#ifdef MOCK_USE_CONVERSIONS
|
||||
|
||||
namespace detail
|
||||
{
|
||||
namespace conversion
|
||||
{
|
||||
struct sink
|
||||
{
|
||||
template< typename T >
|
||||
sink( const T& )
|
||||
{}
|
||||
};
|
||||
|
||||
inline std::ostream& operator<<( std::ostream& s, const sink& )
|
||||
{
|
||||
return s << '?';
|
||||
}
|
||||
|
||||
struct holder : boost::noncopyable
|
||||
{
|
||||
virtual ~holder()
|
||||
{}
|
||||
virtual void serialize( std::ostream& s ) const = 0;
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
struct holder_imp : holder
|
||||
{
|
||||
explicit holder_imp( const T& t )
|
||||
: t_( t )
|
||||
{}
|
||||
virtual void serialize( std::ostream& s ) const
|
||||
{
|
||||
// if an error about an ambiguous conversion is generated by the
|
||||
// line below the solution is to add a serialization operator to a
|
||||
// mock::stream for T
|
||||
s << t_;
|
||||
}
|
||||
const T& t_;
|
||||
};
|
||||
|
||||
struct any : boost::noncopyable
|
||||
{
|
||||
template< typename T >
|
||||
any( const T& t )
|
||||
: h_( new holder_imp< T >( t ) )
|
||||
{}
|
||||
~any()
|
||||
{
|
||||
delete h_;
|
||||
}
|
||||
holder* h_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
inline stream& operator<<( stream& s, const detail::conversion::any& d )
|
||||
{
|
||||
d.h_->serialize( *s.s_ );
|
||||
return s;
|
||||
}
|
||||
|
||||
#else // MOCK_USE_CONVERSIONS
|
||||
|
||||
namespace detail
|
||||
{
|
||||
namespace conversion
|
||||
{
|
||||
template< typename S, typename T >
|
||||
S& operator<<( S &s, const T& )
|
||||
{
|
||||
return s << '?';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
stream& operator<<( stream& s, const T& t )
|
||||
{
|
||||
using namespace detail::conversion;
|
||||
*s.s_ << t;
|
||||
return s;
|
||||
}
|
||||
|
||||
#endif // MOCK_USE_CONVERSIONS
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template< typename T >
|
||||
void serialize( stream& s, const T& t )
|
||||
{
|
||||
// if an error about an ambiguous conversion is generated by the
|
||||
// line below the solution is to add a serialization operator to a
|
||||
// mock::stream for T
|
||||
s << t;
|
||||
}
|
||||
inline void serialize( stream& s, bool b )
|
||||
{
|
||||
s << (b ? "true" : "false");
|
||||
}
|
||||
template< typename C, typename T, typename A >
|
||||
void serialize( stream& s, const std::basic_string< C, T, A >& str )
|
||||
{
|
||||
s << '"' << str << '"';
|
||||
}
|
||||
inline void serialize( stream& s, const char* const str )
|
||||
{
|
||||
s << '"' << str << '"';
|
||||
}
|
||||
inline void serialize( stream& s, unsigned char c )
|
||||
{
|
||||
s << static_cast< int >( c );
|
||||
}
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_STREAM_HPP_INCLUDED
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2011
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_STREAM_HPP_INCLUDED
|
||||
#define MOCK_STREAM_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <ostream>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
struct stream
|
||||
{
|
||||
explicit stream( std::ostream& s )
|
||||
: s_( &s )
|
||||
{}
|
||||
std::ostream* s_;
|
||||
};
|
||||
|
||||
#ifdef MOCK_USE_CONVERSIONS
|
||||
|
||||
namespace detail
|
||||
{
|
||||
namespace conversion
|
||||
{
|
||||
struct sink
|
||||
{
|
||||
template< typename T >
|
||||
sink( const T& )
|
||||
{}
|
||||
};
|
||||
|
||||
inline std::ostream& operator<<( std::ostream& s, const sink& )
|
||||
{
|
||||
return s << '?';
|
||||
}
|
||||
|
||||
struct holder : boost::noncopyable
|
||||
{
|
||||
virtual ~holder()
|
||||
{}
|
||||
virtual void serialize( std::ostream& s ) const = 0;
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
struct holder_imp : holder
|
||||
{
|
||||
explicit holder_imp( const T& t )
|
||||
: t_( t )
|
||||
{}
|
||||
virtual void serialize( std::ostream& s ) const
|
||||
{
|
||||
// if an error about an ambiguous conversion is generated by the
|
||||
// line below the solution is to add a serialization operator to a
|
||||
// mock::stream for T
|
||||
s << t_;
|
||||
}
|
||||
const T& t_;
|
||||
};
|
||||
|
||||
struct any : boost::noncopyable
|
||||
{
|
||||
template< typename T >
|
||||
any( const T& t )
|
||||
: h_( new holder_imp< T >( t ) )
|
||||
{}
|
||||
~any()
|
||||
{
|
||||
delete h_;
|
||||
}
|
||||
holder* h_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
inline stream& operator<<( stream& s, const detail::conversion::any& d )
|
||||
{
|
||||
d.h_->serialize( *s.s_ );
|
||||
return s;
|
||||
}
|
||||
|
||||
#else // MOCK_USE_CONVERSIONS
|
||||
|
||||
namespace detail
|
||||
{
|
||||
namespace conversion
|
||||
{
|
||||
template< typename S, typename T >
|
||||
S& operator<<( S &s, const T& )
|
||||
{
|
||||
return s << '?';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
stream& operator<<( stream& s, const T& t )
|
||||
{
|
||||
using namespace detail::conversion;
|
||||
*s.s_ << t;
|
||||
return s;
|
||||
}
|
||||
|
||||
#endif // MOCK_USE_CONVERSIONS
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template< typename T >
|
||||
void serialize( stream& s, const T& t )
|
||||
{
|
||||
// if an error about an ambiguous conversion is generated by the
|
||||
// line below the solution is to add a serialization operator to a
|
||||
// mock::stream for T
|
||||
s << t;
|
||||
}
|
||||
inline void serialize( stream& s, bool b )
|
||||
{
|
||||
s << (b ? "true" : "false");
|
||||
}
|
||||
template< typename C, typename T, typename A >
|
||||
void serialize( stream& s, const std::basic_string< C, T, A >& str )
|
||||
{
|
||||
s << '"' << str << '"';
|
||||
}
|
||||
inline void serialize( stream& s, const char* const str )
|
||||
{
|
||||
s << '"' << str << '"';
|
||||
}
|
||||
inline void serialize( stream& s, unsigned char c )
|
||||
{
|
||||
s << static_cast< int >( c );
|
||||
}
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_STREAM_HPP_INCLUDED
|
||||
|
|
@ -1,34 +1,34 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2012
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_VERIFY_HPP_INCLUDED
|
||||
#define MOCK_VERIFY_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include "object.hpp"
|
||||
#include "detail/root.hpp"
|
||||
#include "detail/functor.hpp"
|
||||
|
||||
namespace mock
|
||||
{
|
||||
inline bool verify()
|
||||
{
|
||||
return detail::root.verify();
|
||||
}
|
||||
inline bool verify( const object& o )
|
||||
{
|
||||
return o.impl_->verify();
|
||||
}
|
||||
template< typename Signature >
|
||||
bool verify( const detail::functor< Signature >& f )
|
||||
{
|
||||
return f.verify();
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_VERIFY_HPP_INCLUDED
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2012
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_VERIFY_HPP_INCLUDED
|
||||
#define MOCK_VERIFY_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include "object.hpp"
|
||||
#include "detail/root.hpp"
|
||||
#include "detail/functor.hpp"
|
||||
|
||||
namespace mock
|
||||
{
|
||||
inline bool verify()
|
||||
{
|
||||
return detail::root.verify();
|
||||
}
|
||||
inline bool verify( const object& o )
|
||||
{
|
||||
return o.impl_->verify();
|
||||
}
|
||||
template< typename Signature >
|
||||
bool verify( const detail::functor< Signature >& f )
|
||||
{
|
||||
return f.verify();
|
||||
}
|
||||
} // mock
|
||||
|
||||
#endif // MOCK_VERIFY_HPP_INCLUDED
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
<!-- boost-no-inspect -->
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0; URL=doc/html/index.html">
|
||||
|
|
@ -30,7 +30,7 @@ rule run-test ( name )
|
|||
run $(name) undefined.cpp /boost//unit_test_framework : : : <define>MOCK_USE_CONVERSIONS : $(name)_use_conversions ;
|
||||
run $(name) undefined.cpp /boost//unit_test_framework : : : <define>MOCK_NO_DECLTYPE : $(name)_no_decltype ;
|
||||
run $(name) undefined.cpp /boost//unit_test_framework : : : <define>MOCK_NO_VARIADIC_MACROS : $(name)_no_variadic_macros ;
|
||||
run $(name) undefined.cpp /boost//unit_test_framework : : : <define>MOCK_THREAD_SAFE : $(name)_thread_safe ;
|
||||
run $(name) undefined.cpp /boost//unit_test_framework /boost//thread : : : <define>MOCK_THREAD_SAFE <define>BOOST_THREAD_USES_MOVE : $(name)_thread_safe ;
|
||||
}
|
||||
|
||||
rule run-tests
|
||||
|
|
@ -1,14 +1,14 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2011
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2011
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2011
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define MOCK_MAX_ARGS 10
|
||||
#include <turtle/mock.hpp>
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2011
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define MOCK_MAX_ARGS 10
|
||||
#include <turtle/mock.hpp>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2011
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define MOCK_MAX_ARGS 20
|
||||
#include <turtle/mock.hpp>
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2011
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define MOCK_MAX_ARGS 20
|
||||
#include <turtle/mock.hpp>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2011
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define MOCK_MAX_ARGS 30
|
||||
#include <turtle/mock.hpp>
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2011
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define MOCK_MAX_ARGS 30
|
||||
#include <turtle/mock.hpp>
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -1,76 +1,76 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <turtle/detail/invocation.hpp>
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
|
||||
BOOST_AUTO_TEST_CASE( unlimited )
|
||||
{
|
||||
mock::detail::unlimited invocation;
|
||||
BOOST_CHECK( invocation.verify() );
|
||||
BOOST_CHECK( ! invocation.exhausted() );
|
||||
BOOST_CHECK( invocation.invoke() );
|
||||
BOOST_CHECK( invocation.verify() );
|
||||
BOOST_CHECK( ! invocation.exhausted() );
|
||||
BOOST_CHECK( invocation.invoke() );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( once )
|
||||
{
|
||||
mock::detail::once invocation;
|
||||
BOOST_CHECK( ! invocation.verify() );
|
||||
BOOST_CHECK( ! invocation.exhausted() );
|
||||
BOOST_CHECK( invocation.invoke() );
|
||||
BOOST_CHECK( invocation.verify() );
|
||||
BOOST_CHECK( invocation.exhausted() );
|
||||
BOOST_CHECK( ! invocation.invoke() );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( never )
|
||||
{
|
||||
mock::detail::never invocation;
|
||||
BOOST_CHECK( invocation.verify() );
|
||||
BOOST_CHECK( invocation.exhausted() );
|
||||
BOOST_CHECK( ! invocation.invoke() );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( at_most )
|
||||
{
|
||||
mock::detail::at_most invocation( 1 );
|
||||
BOOST_CHECK( invocation.verify() );
|
||||
BOOST_CHECK( ! invocation.exhausted() );
|
||||
BOOST_CHECK( invocation.invoke() );
|
||||
BOOST_CHECK( invocation.verify() );
|
||||
BOOST_CHECK( invocation.exhausted() );
|
||||
BOOST_CHECK( ! invocation.invoke() );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( at_least )
|
||||
{
|
||||
mock::detail::at_least invocation( 1 );
|
||||
BOOST_CHECK( ! invocation.verify() );
|
||||
BOOST_CHECK( ! invocation.exhausted() );
|
||||
BOOST_CHECK( invocation.invoke() );
|
||||
BOOST_CHECK( invocation.verify() );
|
||||
BOOST_CHECK( ! invocation.exhausted() );
|
||||
BOOST_CHECK( invocation.invoke() );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( between )
|
||||
{
|
||||
mock::detail::between invocation( 1, 2 );
|
||||
BOOST_CHECK( ! invocation.verify() );
|
||||
BOOST_CHECK( ! invocation.exhausted() );
|
||||
BOOST_CHECK( invocation.invoke() );
|
||||
BOOST_CHECK( invocation.verify() );
|
||||
BOOST_CHECK( ! invocation.exhausted() );
|
||||
BOOST_CHECK( invocation.invoke() );
|
||||
BOOST_CHECK( invocation.verify() );
|
||||
BOOST_CHECK( invocation.exhausted() );
|
||||
BOOST_CHECK( ! invocation.invoke() );
|
||||
}
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <turtle/detail/invocation.hpp>
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
|
||||
BOOST_AUTO_TEST_CASE( unlimited )
|
||||
{
|
||||
mock::detail::unlimited invocation;
|
||||
BOOST_CHECK( invocation.verify() );
|
||||
BOOST_CHECK( ! invocation.exhausted() );
|
||||
BOOST_CHECK( invocation.invoke() );
|
||||
BOOST_CHECK( invocation.verify() );
|
||||
BOOST_CHECK( ! invocation.exhausted() );
|
||||
BOOST_CHECK( invocation.invoke() );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( once )
|
||||
{
|
||||
mock::detail::once invocation;
|
||||
BOOST_CHECK( ! invocation.verify() );
|
||||
BOOST_CHECK( ! invocation.exhausted() );
|
||||
BOOST_CHECK( invocation.invoke() );
|
||||
BOOST_CHECK( invocation.verify() );
|
||||
BOOST_CHECK( invocation.exhausted() );
|
||||
BOOST_CHECK( ! invocation.invoke() );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( never )
|
||||
{
|
||||
mock::detail::never invocation;
|
||||
BOOST_CHECK( invocation.verify() );
|
||||
BOOST_CHECK( invocation.exhausted() );
|
||||
BOOST_CHECK( ! invocation.invoke() );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( at_most )
|
||||
{
|
||||
mock::detail::at_most invocation( 1 );
|
||||
BOOST_CHECK( invocation.verify() );
|
||||
BOOST_CHECK( ! invocation.exhausted() );
|
||||
BOOST_CHECK( invocation.invoke() );
|
||||
BOOST_CHECK( invocation.verify() );
|
||||
BOOST_CHECK( invocation.exhausted() );
|
||||
BOOST_CHECK( ! invocation.invoke() );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( at_least )
|
||||
{
|
||||
mock::detail::at_least invocation( 1 );
|
||||
BOOST_CHECK( ! invocation.verify() );
|
||||
BOOST_CHECK( ! invocation.exhausted() );
|
||||
BOOST_CHECK( invocation.invoke() );
|
||||
BOOST_CHECK( invocation.verify() );
|
||||
BOOST_CHECK( ! invocation.exhausted() );
|
||||
BOOST_CHECK( invocation.invoke() );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( between )
|
||||
{
|
||||
mock::detail::between invocation( 1, 2 );
|
||||
BOOST_CHECK( ! invocation.verify() );
|
||||
BOOST_CHECK( ! invocation.exhausted() );
|
||||
BOOST_CHECK( invocation.invoke() );
|
||||
BOOST_CHECK( invocation.verify() );
|
||||
BOOST_CHECK( ! invocation.exhausted() );
|
||||
BOOST_CHECK( invocation.invoke() );
|
||||
BOOST_CHECK( invocation.verify() );
|
||||
BOOST_CHECK( invocation.exhausted() );
|
||||
BOOST_CHECK( ! invocation.invoke() );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,155 +1,155 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2009
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <turtle/detail/is_functor.hpp>
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning( push, 0 )
|
||||
#endif
|
||||
#include <boost/lambda/lambda.hpp>
|
||||
#include <boost/phoenix/phoenix.hpp>
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning( pop )
|
||||
#endif
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
struct declared_but_not_defined;
|
||||
BOOST_MPL_ASSERT_NOT((
|
||||
mock::detail::is_functor< declared_but_not_defined, int > ));
|
||||
|
||||
template< typename T >
|
||||
void is_functor( T )
|
||||
{
|
||||
BOOST_MPL_ASSERT(( mock::detail::is_functor< T, int > ));
|
||||
}
|
||||
template< typename T >
|
||||
void is_not_functor( T )
|
||||
{
|
||||
BOOST_MPL_ASSERT_NOT(( mock::detail::is_functor< T, int > ));
|
||||
}
|
||||
|
||||
void f0() {}
|
||||
bool f1( int ) { return false; }
|
||||
bool f2( std::string, int ) { return false; }
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( data_is_not_functor )
|
||||
{
|
||||
is_not_functor( 42 );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( function_is_functor )
|
||||
{
|
||||
is_functor( f0 );
|
||||
is_functor( f1 );
|
||||
is_functor( f2 );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( function_pointer_is_functor )
|
||||
{
|
||||
is_functor( &f0 );
|
||||
is_functor( &f1 );
|
||||
is_functor( &f2 );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( std_ptr_fun_is_functor )
|
||||
{
|
||||
is_functor( std::ptr_fun( &f1 ) );
|
||||
is_functor( std::ptr_fun( &f2 ) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( std_bind_first_is_functor )
|
||||
{
|
||||
is_functor( std::bind1st( std::ptr_fun( &f2 ), "" ) );
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
struct unary_functor0 : public std::unary_function< void, void >
|
||||
{};
|
||||
struct unary_functor1 : public std::unary_function< int, void >
|
||||
{};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( std_unary_functor_is_functor )
|
||||
{
|
||||
is_functor( unary_functor0() );
|
||||
is_functor( unary_functor1() );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( boost_bind_is_functor )
|
||||
{
|
||||
is_functor( boost::bind( &f0 ) );
|
||||
is_functor( boost::bind( &f1, _1 ) );
|
||||
is_functor( boost::bind( &f2, "", _1 ) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( boost_lambda_is_functor )
|
||||
{
|
||||
is_functor( boost::lambda::_1 < 42 );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( boost_phoenix_is_functor )
|
||||
{
|
||||
is_functor( boost::phoenix::arg_names::arg1 < 42 );
|
||||
is_functor( boost::phoenix::arg_names::_1 < 42 );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( boost_function_is_functor )
|
||||
{
|
||||
is_functor( boost::function< void() >() );
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
struct result_type_functor
|
||||
{
|
||||
typedef void result_type;
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( class_with_result_type_is_functor )
|
||||
{
|
||||
is_functor( result_type_functor() );
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
struct sig_functor
|
||||
{
|
||||
template< typename Args >
|
||||
struct sig
|
||||
{
|
||||
typedef void type;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( class_with_sig_is_functor )
|
||||
{
|
||||
is_functor( sig_functor() );
|
||||
}
|
||||
|
||||
#ifdef MOCK_LAMBDAS
|
||||
|
||||
BOOST_AUTO_TEST_CASE( cxx11_lambda_is_functor )
|
||||
{
|
||||
is_not_functor( []() {} );
|
||||
#ifdef MOCK_DECLTYPE
|
||||
is_functor( []( int ) {} );
|
||||
#else
|
||||
is_not_functor( []( int ) {} );
|
||||
#endif
|
||||
is_not_functor( []( const std::string&, int ) {} );
|
||||
is_not_functor( []( int, const std::string& ) {} );
|
||||
}
|
||||
|
||||
#endif
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2009
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <turtle/detail/is_functor.hpp>
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning( push, 0 )
|
||||
#endif
|
||||
#include <boost/lambda/lambda.hpp>
|
||||
#include <boost/phoenix/phoenix.hpp>
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning( pop )
|
||||
#endif
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
struct declared_but_not_defined;
|
||||
BOOST_MPL_ASSERT_NOT((
|
||||
mock::detail::is_functor< declared_but_not_defined, int > ));
|
||||
|
||||
template< typename T >
|
||||
void is_functor( T )
|
||||
{
|
||||
BOOST_MPL_ASSERT(( mock::detail::is_functor< T, int > ));
|
||||
}
|
||||
template< typename T >
|
||||
void is_not_functor( T )
|
||||
{
|
||||
BOOST_MPL_ASSERT_NOT(( mock::detail::is_functor< T, int > ));
|
||||
}
|
||||
|
||||
void f0() {}
|
||||
bool f1( int ) { return false; }
|
||||
bool f2( std::string, int ) { return false; }
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( data_is_not_functor )
|
||||
{
|
||||
is_not_functor( 42 );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( function_is_functor )
|
||||
{
|
||||
is_functor( f0 );
|
||||
is_functor( f1 );
|
||||
is_functor( f2 );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( function_pointer_is_functor )
|
||||
{
|
||||
is_functor( &f0 );
|
||||
is_functor( &f1 );
|
||||
is_functor( &f2 );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( std_ptr_fun_is_functor )
|
||||
{
|
||||
is_functor( std::ptr_fun( &f1 ) );
|
||||
is_functor( std::ptr_fun( &f2 ) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( std_bind_first_is_functor )
|
||||
{
|
||||
is_functor( std::bind1st( std::ptr_fun( &f2 ), "" ) );
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
struct unary_functor0 : public std::unary_function< void, void >
|
||||
{};
|
||||
struct unary_functor1 : public std::unary_function< int, void >
|
||||
{};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( std_unary_functor_is_functor )
|
||||
{
|
||||
is_functor( unary_functor0() );
|
||||
is_functor( unary_functor1() );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( boost_bind_is_functor )
|
||||
{
|
||||
is_functor( boost::bind( &f0 ) );
|
||||
is_functor( boost::bind( &f1, _1 ) );
|
||||
is_functor( boost::bind( &f2, "", _1 ) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( boost_lambda_is_functor )
|
||||
{
|
||||
is_functor( boost::lambda::_1 < 42 );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( boost_phoenix_is_functor )
|
||||
{
|
||||
is_functor( boost::phoenix::arg_names::arg1 < 42 );
|
||||
is_functor( boost::phoenix::arg_names::_1 < 42 );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( boost_function_is_functor )
|
||||
{
|
||||
is_functor( boost::function< void() >() );
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
struct result_type_functor
|
||||
{
|
||||
typedef void result_type;
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( class_with_result_type_is_functor )
|
||||
{
|
||||
is_functor( result_type_functor() );
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
struct sig_functor
|
||||
{
|
||||
template< typename Args >
|
||||
struct sig
|
||||
{
|
||||
typedef void type;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( class_with_sig_is_functor )
|
||||
{
|
||||
is_functor( sig_functor() );
|
||||
}
|
||||
|
||||
#ifdef MOCK_LAMBDAS
|
||||
|
||||
BOOST_AUTO_TEST_CASE( cxx11_lambda_is_functor )
|
||||
{
|
||||
is_not_functor( []() {} );
|
||||
#ifdef MOCK_DECLTYPE
|
||||
is_functor( []( int ) {} );
|
||||
#else
|
||||
is_not_functor( []( int ) {} );
|
||||
#endif
|
||||
is_not_functor( []( const std::string&, int ) {} );
|
||||
is_not_functor( []( int, const std::string& ) {} );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,29 +1,29 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2012
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <turtle/detail/signature.hpp>
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <boost/mpl/assert.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
struct base
|
||||
{
|
||||
void method_1();
|
||||
float method_2( int ) const;
|
||||
};
|
||||
typedef base base_type;
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( mock_signature_generates_signature )
|
||||
{
|
||||
BOOST_MPL_ASSERT((
|
||||
boost::is_same< void(), MOCK_SIGNATURE( method_1 ) > ));
|
||||
BOOST_MPL_ASSERT((
|
||||
boost::is_same< float( int ), MOCK_SIGNATURE( method_2 ) > ));
|
||||
}
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2012
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <turtle/detail/signature.hpp>
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <boost/mpl/assert.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
struct base
|
||||
{
|
||||
void method_1();
|
||||
float method_2( int ) const;
|
||||
};
|
||||
typedef base base_type;
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( mock_signature_generates_signature )
|
||||
{
|
||||
BOOST_MPL_ASSERT((
|
||||
boost::is_same< void(), MOCK_SIGNATURE( method_1 ) > ));
|
||||
BOOST_MPL_ASSERT((
|
||||
boost::is_same< float( int ), MOCK_SIGNATURE( method_2 ) > ));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,225 +1,225 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <turtle/detail/type_name.hpp>
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
template< typename T >
|
||||
std::string to_string( const T& )
|
||||
{
|
||||
return boost::lexical_cast< std::string >( MOCK_TYPE_NAME(T) );
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_base_type_is_extracted )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "char", to_string( 'a' ) );
|
||||
BOOST_CHECK_EQUAL( "bool", to_string( true ) );
|
||||
BOOST_CHECK_EQUAL( "int", to_string< int >( 0 ) );
|
||||
BOOST_CHECK_EQUAL( "short", to_string< short >( 0 ) );
|
||||
BOOST_CHECK_EQUAL( "long", to_string< long >( 0 ) );
|
||||
BOOST_CHECK_EQUAL( "unsigned int", to_string< unsigned int >( 0 ) );
|
||||
BOOST_CHECK_EQUAL( "unsigned short", to_string< unsigned short >( 0 ) );
|
||||
BOOST_CHECK_EQUAL( "unsigned long", to_string< unsigned long >( 0 ) );
|
||||
}
|
||||
|
||||
struct my_type_in_default_namespace
|
||||
{
|
||||
struct inner {};
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_type_in_default_namespace_is_extracted )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "my_type_in_default_namespace", to_string( my_type_in_default_namespace() ) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_inner_type_from_type_in_default_namespace_is_extracted )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "inner", to_string( my_type_in_default_namespace::inner() ) );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
struct my_template_type_in_default_namespace
|
||||
{
|
||||
struct inner {};
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_template_type_in_default_namespace_is_extracted )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "my_template_type_in_default_namespace<int>", to_string( my_template_type_in_default_namespace<int>() ) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_inner_type_from_template_type_in_default_namespace_is_extracted )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type_in_default_namespace<int>::inner() ) );
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
struct my_type_in_anonymous_namespace {};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_type_in_anonymous_namespace_is_extracted )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "my_type_in_anonymous_namespace", to_string( my_type_in_anonymous_namespace() ) );
|
||||
}
|
||||
|
||||
namespace nm
|
||||
{
|
||||
struct my_type_from_named_namespace {};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_type_from_named_namespace_is_extracted )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "my_type_from_named_namespace", to_string( nm::my_type_from_named_namespace() ) );
|
||||
}
|
||||
|
||||
namespace nm
|
||||
{
|
||||
namespace inner
|
||||
{
|
||||
struct my_type_in_named_inner_namespace {};
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_type_in_named_inner_namespace_is_extracted )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "my_type_in_named_inner_namespace", to_string( nm::inner::my_type_in_named_inner_namespace() ) );
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace inner
|
||||
{
|
||||
struct my_type_in_unnamed_inner_namespace {};
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_type_in_unnamed_inner_namespace_is_extracted )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "my_type_in_unnamed_inner_namespace", to_string( inner::my_type_in_unnamed_inner_namespace() ) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_local_type_is_extracted )
|
||||
{
|
||||
struct my_local_type {};
|
||||
BOOST_CHECK_EQUAL( "my_local_type", boost::lexical_cast< std::string >( MOCK_TYPE_NAME(my_local_type) ) );
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
template< typename T >
|
||||
struct my_template_type
|
||||
{
|
||||
struct inner {};
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_template_type_in_anonymous_namespace_is_extracted )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "my_template_type<int>", to_string( my_template_type< int >() ) );
|
||||
BOOST_CHECK_EQUAL( "my_template_type<exception>", to_string( my_template_type< std::exception >() ) );
|
||||
BOOST_CHECK_EQUAL( "my_template_type<int const&>", to_string( my_template_type< int const& >() ) );
|
||||
BOOST_CHECK_EQUAL( "my_template_type<exception const&>", to_string( my_template_type< std::exception const& >() ) );
|
||||
BOOST_CHECK_EQUAL( "my_template_type<int const*>", to_string( my_template_type< int const* >() ) );
|
||||
BOOST_CHECK_EQUAL( "my_template_type<exception const*>", to_string( my_template_type< std::exception const* >() ) );
|
||||
BOOST_CHECK_EQUAL( "my_template_type<int const*&>", to_string( my_template_type< int const*& >() ) );
|
||||
BOOST_CHECK_EQUAL( "my_template_type<exception const*&>", to_string( my_template_type< std::exception const*& >() ) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_inner_type_from_template_type_in_anonymous_namespace_is_extracted )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< int >::inner() ) );
|
||||
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< std::exception >::inner() ) );
|
||||
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< int const& >::inner() ) );
|
||||
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< std::exception const& >::inner() ) );
|
||||
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< int const* >::inner() ) );
|
||||
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< std::exception const* >::inner() ) );
|
||||
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< int const*& >::inner() ) );
|
||||
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< std::exception const*& >::inner() ) );
|
||||
}
|
||||
|
||||
namespace nm
|
||||
{
|
||||
template< typename T >
|
||||
struct my_template_type
|
||||
{
|
||||
struct inner {};
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_template_type_in_named_namespace_is_extracted )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "my_template_type<int>", to_string( nm::my_template_type< int >() ) );
|
||||
BOOST_CHECK_EQUAL( "my_template_type<exception>", to_string( nm::my_template_type< std::exception >() ) );
|
||||
BOOST_CHECK_EQUAL( "my_template_type<int const&>", to_string( nm::my_template_type< int const& >() ) );
|
||||
BOOST_CHECK_EQUAL( "my_template_type<exception const&>", to_string( nm::my_template_type< std::exception const& >() ) );
|
||||
BOOST_CHECK_EQUAL( "my_template_type<int const*>", to_string( nm::my_template_type< int const* >() ) );
|
||||
BOOST_CHECK_EQUAL( "my_template_type<exception const*>", to_string( nm::my_template_type< std::exception const* >() ) );
|
||||
BOOST_CHECK_EQUAL( "my_template_type<int const*&>", to_string( nm::my_template_type< int const*& >() ) );
|
||||
BOOST_CHECK_EQUAL( "my_template_type<exception const*&>", to_string( nm::my_template_type< std::exception const*& >() ) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_inner_type_from_template_type_in_named_namespace_is_extracted )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< int >::inner() ) );
|
||||
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< std::exception >::inner() ) );
|
||||
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< int const& >::inner() ) );
|
||||
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< std::exception const& >::inner() ) );
|
||||
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< int const* >::inner() ) );
|
||||
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< std::exception const* >::inner() ) );
|
||||
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< int const*& >::inner() ) );
|
||||
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< std::exception const*& >::inner() ) );
|
||||
}
|
||||
|
||||
namespace nm2
|
||||
{
|
||||
template< typename T >
|
||||
struct my_template_type
|
||||
{
|
||||
template< typename U >
|
||||
struct inner {};
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_template_inner_type_from_template_type_in_named_namespace_is_extracted )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< int >::inner< int >() ) );
|
||||
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< std::exception >::inner< int >() ) );
|
||||
|
||||
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< int const& >::inner< int >() ) );
|
||||
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< std::exception const& >::inner< int >() ) );
|
||||
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< int const* >::inner< int >() ) );
|
||||
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< std::exception const* >::inner< int >() ) );
|
||||
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< int const*& >::inner< int >() ) );
|
||||
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< std::exception const*& >::inner< int >() ) );
|
||||
|
||||
BOOST_CHECK_EQUAL( "inner<int const&>", to_string( nm2::my_template_type< int >::inner< int const& >() ) );
|
||||
BOOST_CHECK_EQUAL( "inner<int const&>", to_string( nm2::my_template_type< std::exception >::inner< int const& >() ) );
|
||||
BOOST_CHECK_EQUAL( "inner<int const*>", to_string( nm2::my_template_type< int >::inner< int const* >() ) );
|
||||
BOOST_CHECK_EQUAL( "inner<int const*>", to_string( nm2::my_template_type< std::exception >::inner< int const* >() ) );
|
||||
BOOST_CHECK_EQUAL( "inner<int const*&>", to_string( nm2::my_template_type< int >::inner< int const*& >() ) );
|
||||
BOOST_CHECK_EQUAL( "inner<int const*&>", to_string( nm2::my_template_type< std::exception >::inner< int const*& >() ) );
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
template< typename T1, typename T2, typename T3 >
|
||||
struct my_tpl
|
||||
{};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_nested_template_with_multiple_arguments_is_extracted )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "vector<int, allocator<int>>", to_string( std::vector< int >() ) );
|
||||
BOOST_CHECK_EQUAL( "vector<vector<int, allocator<int>>, allocator<vector<int, allocator<int>>>>", to_string( std::vector< std::vector< int > >() ) );
|
||||
BOOST_CHECK_EQUAL( "my_tpl<my_tpl<int, int, int>, my_tpl<int, int, int>, my_tpl<int, int, int>>", to_string( my_tpl< my_tpl< int, int, int >, my_tpl< int, int, int >, my_tpl< int, int, int > >() ) );
|
||||
}
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <turtle/detail/type_name.hpp>
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
template< typename T >
|
||||
std::string to_string( const T& )
|
||||
{
|
||||
return boost::lexical_cast< std::string >( MOCK_TYPE_NAME(T) );
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_base_type_is_extracted )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "char", to_string( 'a' ) );
|
||||
BOOST_CHECK_EQUAL( "bool", to_string( true ) );
|
||||
BOOST_CHECK_EQUAL( "int", to_string< int >( 0 ) );
|
||||
BOOST_CHECK_EQUAL( "short", to_string< short >( 0 ) );
|
||||
BOOST_CHECK_EQUAL( "long", to_string< long >( 0 ) );
|
||||
BOOST_CHECK_EQUAL( "unsigned int", to_string< unsigned int >( 0 ) );
|
||||
BOOST_CHECK_EQUAL( "unsigned short", to_string< unsigned short >( 0 ) );
|
||||
BOOST_CHECK_EQUAL( "unsigned long", to_string< unsigned long >( 0 ) );
|
||||
}
|
||||
|
||||
struct my_type_in_default_namespace
|
||||
{
|
||||
struct inner {};
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_type_in_default_namespace_is_extracted )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "my_type_in_default_namespace", to_string( my_type_in_default_namespace() ) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_inner_type_from_type_in_default_namespace_is_extracted )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "inner", to_string( my_type_in_default_namespace::inner() ) );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
struct my_template_type_in_default_namespace
|
||||
{
|
||||
struct inner {};
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_template_type_in_default_namespace_is_extracted )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "my_template_type_in_default_namespace<int>", to_string( my_template_type_in_default_namespace<int>() ) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_inner_type_from_template_type_in_default_namespace_is_extracted )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type_in_default_namespace<int>::inner() ) );
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
struct my_type_in_anonymous_namespace {};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_type_in_anonymous_namespace_is_extracted )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "my_type_in_anonymous_namespace", to_string( my_type_in_anonymous_namespace() ) );
|
||||
}
|
||||
|
||||
namespace nm
|
||||
{
|
||||
struct my_type_from_named_namespace {};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_type_from_named_namespace_is_extracted )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "my_type_from_named_namespace", to_string( nm::my_type_from_named_namespace() ) );
|
||||
}
|
||||
|
||||
namespace nm
|
||||
{
|
||||
namespace inner
|
||||
{
|
||||
struct my_type_in_named_inner_namespace {};
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_type_in_named_inner_namespace_is_extracted )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "my_type_in_named_inner_namespace", to_string( nm::inner::my_type_in_named_inner_namespace() ) );
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace inner
|
||||
{
|
||||
struct my_type_in_unnamed_inner_namespace {};
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_type_in_unnamed_inner_namespace_is_extracted )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "my_type_in_unnamed_inner_namespace", to_string( inner::my_type_in_unnamed_inner_namespace() ) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_local_type_is_extracted )
|
||||
{
|
||||
struct my_local_type {};
|
||||
BOOST_CHECK_EQUAL( "my_local_type", boost::lexical_cast< std::string >( MOCK_TYPE_NAME(my_local_type) ) );
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
template< typename T >
|
||||
struct my_template_type
|
||||
{
|
||||
struct inner {};
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_template_type_in_anonymous_namespace_is_extracted )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "my_template_type<int>", to_string( my_template_type< int >() ) );
|
||||
BOOST_CHECK_EQUAL( "my_template_type<exception>", to_string( my_template_type< std::exception >() ) );
|
||||
BOOST_CHECK_EQUAL( "my_template_type<int const&>", to_string( my_template_type< int const& >() ) );
|
||||
BOOST_CHECK_EQUAL( "my_template_type<exception const&>", to_string( my_template_type< std::exception const& >() ) );
|
||||
BOOST_CHECK_EQUAL( "my_template_type<int const*>", to_string( my_template_type< int const* >() ) );
|
||||
BOOST_CHECK_EQUAL( "my_template_type<exception const*>", to_string( my_template_type< std::exception const* >() ) );
|
||||
BOOST_CHECK_EQUAL( "my_template_type<int const*&>", to_string( my_template_type< int const*& >() ) );
|
||||
BOOST_CHECK_EQUAL( "my_template_type<exception const*&>", to_string( my_template_type< std::exception const*& >() ) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_inner_type_from_template_type_in_anonymous_namespace_is_extracted )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< int >::inner() ) );
|
||||
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< std::exception >::inner() ) );
|
||||
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< int const& >::inner() ) );
|
||||
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< std::exception const& >::inner() ) );
|
||||
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< int const* >::inner() ) );
|
||||
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< std::exception const* >::inner() ) );
|
||||
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< int const*& >::inner() ) );
|
||||
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< std::exception const*& >::inner() ) );
|
||||
}
|
||||
|
||||
namespace nm
|
||||
{
|
||||
template< typename T >
|
||||
struct my_template_type
|
||||
{
|
||||
struct inner {};
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_template_type_in_named_namespace_is_extracted )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "my_template_type<int>", to_string( nm::my_template_type< int >() ) );
|
||||
BOOST_CHECK_EQUAL( "my_template_type<exception>", to_string( nm::my_template_type< std::exception >() ) );
|
||||
BOOST_CHECK_EQUAL( "my_template_type<int const&>", to_string( nm::my_template_type< int const& >() ) );
|
||||
BOOST_CHECK_EQUAL( "my_template_type<exception const&>", to_string( nm::my_template_type< std::exception const& >() ) );
|
||||
BOOST_CHECK_EQUAL( "my_template_type<int const*>", to_string( nm::my_template_type< int const* >() ) );
|
||||
BOOST_CHECK_EQUAL( "my_template_type<exception const*>", to_string( nm::my_template_type< std::exception const* >() ) );
|
||||
BOOST_CHECK_EQUAL( "my_template_type<int const*&>", to_string( nm::my_template_type< int const*& >() ) );
|
||||
BOOST_CHECK_EQUAL( "my_template_type<exception const*&>", to_string( nm::my_template_type< std::exception const*& >() ) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_inner_type_from_template_type_in_named_namespace_is_extracted )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< int >::inner() ) );
|
||||
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< std::exception >::inner() ) );
|
||||
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< int const& >::inner() ) );
|
||||
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< std::exception const& >::inner() ) );
|
||||
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< int const* >::inner() ) );
|
||||
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< std::exception const* >::inner() ) );
|
||||
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< int const*& >::inner() ) );
|
||||
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< std::exception const*& >::inner() ) );
|
||||
}
|
||||
|
||||
namespace nm2
|
||||
{
|
||||
template< typename T >
|
||||
struct my_template_type
|
||||
{
|
||||
template< typename U >
|
||||
struct inner {};
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_template_inner_type_from_template_type_in_named_namespace_is_extracted )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< int >::inner< int >() ) );
|
||||
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< std::exception >::inner< int >() ) );
|
||||
|
||||
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< int const& >::inner< int >() ) );
|
||||
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< std::exception const& >::inner< int >() ) );
|
||||
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< int const* >::inner< int >() ) );
|
||||
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< std::exception const* >::inner< int >() ) );
|
||||
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< int const*& >::inner< int >() ) );
|
||||
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< std::exception const*& >::inner< int >() ) );
|
||||
|
||||
BOOST_CHECK_EQUAL( "inner<int const&>", to_string( nm2::my_template_type< int >::inner< int const& >() ) );
|
||||
BOOST_CHECK_EQUAL( "inner<int const&>", to_string( nm2::my_template_type< std::exception >::inner< int const& >() ) );
|
||||
BOOST_CHECK_EQUAL( "inner<int const*>", to_string( nm2::my_template_type< int >::inner< int const* >() ) );
|
||||
BOOST_CHECK_EQUAL( "inner<int const*>", to_string( nm2::my_template_type< std::exception >::inner< int const* >() ) );
|
||||
BOOST_CHECK_EQUAL( "inner<int const*&>", to_string( nm2::my_template_type< int >::inner< int const*& >() ) );
|
||||
BOOST_CHECK_EQUAL( "inner<int const*&>", to_string( nm2::my_template_type< std::exception >::inner< int const*& >() ) );
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
template< typename T1, typename T2, typename T3 >
|
||||
struct my_tpl
|
||||
{};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_nested_template_with_multiple_arguments_is_extracted )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "vector<int, allocator<int>>", to_string( std::vector< int >() ) );
|
||||
BOOST_CHECK_EQUAL( "vector<vector<int, allocator<int>>, allocator<vector<int, allocator<int>>>>", to_string( std::vector< std::vector< int > >() ) );
|
||||
BOOST_CHECK_EQUAL( "my_tpl<my_tpl<int, int, int>, my_tpl<int, int, int>, my_tpl<int, int, int>>", to_string( my_tpl< my_tpl< int, int, int >, my_tpl< int, int, int >, my_tpl< int, int, int > >() ) );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +1,24 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2011
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
struct my_base
|
||||
{
|
||||
virtual ~my_base() {}
|
||||
virtual void my_method() = 0;
|
||||
virtual void my_method( int ) = 0;
|
||||
};
|
||||
|
||||
MOCK_BASE_CLASS( my_class, my_base )
|
||||
{
|
||||
MOCK_METHOD( my_method, 0 )
|
||||
};
|
||||
}
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2011
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
struct my_base
|
||||
{
|
||||
virtual ~my_base() {}
|
||||
virtual void my_method() = 0;
|
||||
virtual void my_method( int ) = 0;
|
||||
};
|
||||
|
||||
MOCK_BASE_CLASS( my_class, my_base )
|
||||
{
|
||||
MOCK_METHOD( my_method, 0 )
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +1,24 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2011
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
MOCK_CLASS( my_class )
|
||||
{
|
||||
MOCK_METHOD_EXT( my_method, 1, void( int ), my_method )
|
||||
};
|
||||
bool constraint( int, int );
|
||||
|
||||
void test_case()
|
||||
{
|
||||
my_class c;
|
||||
MOCK_EXPECT( c.my_method ).with( &constraint );
|
||||
}
|
||||
}
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2011
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
MOCK_CLASS( my_class )
|
||||
{
|
||||
MOCK_METHOD_EXT( my_method, 1, void( int ), my_method )
|
||||
};
|
||||
bool constraint( int, int );
|
||||
|
||||
void test_case()
|
||||
{
|
||||
my_class c;
|
||||
MOCK_EXPECT( c.my_method ).with( &constraint );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,22 +1,22 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2011
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
MOCK_CLASS( my_class )
|
||||
{
|
||||
MOCK_METHOD_EXT( my_method, 1, void( int ), my_method )
|
||||
};
|
||||
void test_case()
|
||||
{
|
||||
my_class c;
|
||||
MOCK_EXPECT( c.my_method ).with( "42" );
|
||||
}
|
||||
}
|
||||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2011
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
MOCK_CLASS( my_class )
|
||||
{
|
||||
MOCK_METHOD_EXT( my_method, 1, void( int ), my_method )
|
||||
};
|
||||
void test_case()
|
||||
{
|
||||
my_class c;
|
||||
MOCK_EXPECT( c.my_method ).with( "42" );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue