mirror of
https://github.com/openappsec/openappsec.git
synced 2025-09-29 19:24:26 +03:00
First release of open-appsec source code
This commit is contained in:
13
external/C-Mock/.travis.yml
vendored
Normal file
13
external/C-Mock/.travis.yml
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
language: c++
|
||||
|
||||
dist: bionic
|
||||
|
||||
before_script:
|
||||
- git clone --depth=1 https://github.com/google/googletest/
|
||||
- cd googletest
|
||||
- cmake CMakeLists.txt
|
||||
- make
|
||||
- cd ..
|
||||
- GTEST_DIR=./googletest make
|
||||
|
||||
script: make test
|
9
external/C-Mock/LICENSE.md
vendored
Normal file
9
external/C-Mock/LICENSE.md
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
Copyright (c) 2013, Hubert Jagodziński
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
269
external/C-Mock/README.md
vendored
Normal file
269
external/C-Mock/README.md
vendored
Normal file
@@ -0,0 +1,269 @@
|
||||
C Mock - Google Mock Extension
|
||||
==============================
|
||||
|
||||
[](https://travis-ci.org/hjagodzinski/C-Mock)
|
||||
|
||||
Overview
|
||||
--------
|
||||
|
||||
C Mock is [Google Mock][1]'s extension allowing a function mocking. Only global (non-static) functions mocking is supported.
|
||||
|
||||
This is neither a patch to nor fork of Google Mock. This is just a set of headers providing a way to use tools for mock methods with mock functions in tests.
|
||||
|
||||
C Mock is not intended to promote a bad design. Its goal is to aid the developers to test their code.
|
||||
|
||||
Before the use of C Mock the following reading is recommended:
|
||||
|
||||
* [My code calls a static/global function. Can I mock it?][2]
|
||||
* [Defeat "Static Cling"][3]
|
||||
|
||||
Requirements
|
||||
------------
|
||||
|
||||
* Google Test (for 1.10 support use release [v0.3.1](https://github.com/hjagodzinski/C-Mock/releases/tag/v0.3.1))
|
||||
* GNU/Linux environment that Google Test supports
|
||||
|
||||
Guide
|
||||
-----
|
||||
|
||||
C Mock requires no prior build, it is just a set of header files you include in your code.
|
||||
|
||||
### Using CMockMocker class ###
|
||||
|
||||
C Mock comes with the `CMockMocker` class and two generic macros `CMOCK_MOCK_METHOD` and `CMOCK_MOCK_FUNCTION`.
|
||||
|
||||
#### Creating mock ####
|
||||
|
||||
C Mock does not know whether a mocked function is declared with a name mangling - whether this is a pure C function or a C++ function. Therefore C Mock does not redeclare mocked function. Original function prototype declaration should be used (i.e. use of original function header file).
|
||||
|
||||
Suppose you want to mock `int add(int, int)` and `int substract(int, int)` functions declared in *math.h* header file. To do that you create a single mock class for both of them called `MathMocker`:
|
||||
|
||||
*math_mocker.h*
|
||||
|
||||
```cpp
|
||||
#include <cmock/cmock.h>
|
||||
|
||||
#include "math.h"
|
||||
|
||||
class MathMocker : public CMockMocker<MathMocker>
|
||||
{
|
||||
public:
|
||||
CMOCK_MOCK_METHOD(int, add, (int, int));
|
||||
CMOCK_MOCK_METHOD(int, substract, (int, int));
|
||||
};
|
||||
```
|
||||
|
||||
*math_mocker.cc*
|
||||
|
||||
```cpp
|
||||
#include "math_mocker.h"
|
||||
|
||||
CMOCK_MOCK_FUNCTION(MathMocker, int, add, (int, int));
|
||||
CMOCK_MOCK_FUNCTION(MathMocker, int, substract, (int, int));
|
||||
```
|
||||
|
||||
#### Specifying expectations ####
|
||||
|
||||
To specify the expectations you use Google Mock's macros as you normally would do. The functions are mocked as long as its corresponding mocker class instance exists. This allows to easily control when the functions are mocked. If a mocker class instance does not exist, the real function is called.
|
||||
|
||||
```cpp
|
||||
{
|
||||
MathMocker mock;
|
||||
|
||||
EXPECT_CALL(mock, add(1, 1)).WillOnce(Return(11));
|
||||
ASSERT_EQ(11, add(1, 1)); // calling the mock
|
||||
|
||||
EXPECT_CALL(mock, substract(1, 2)).WillOnce(Return(12));
|
||||
ASSERT_EQ(12, substract(1, 2)); // calling the mock
|
||||
}
|
||||
|
||||
ASSERT_EQ(2, add(1, 1)); // calling the real function
|
||||
ASSERT_EQ(-1, substract(1, 2)); // calling the real function
|
||||
```
|
||||
|
||||
Still, you might want to call a real function. `CMockMocker` class has a static member holding a pointer to a real function. Use the `CMOCK_REAL_FUNCTION` macro to call a real function.
|
||||
|
||||
```cpp
|
||||
ASSERT_EQ(2, CMOCK_REAL_FUNCTION(MathMocker, add)(1, 2));
|
||||
```
|
||||
|
||||
Before the generic `CMOCK_MOCK_METHOD` and `CMOCK_MOCK_FUNCTION` macros were introduced, function mocks were created using `MOCK_METHOD`/`MOCK_METHODn` and `CMOCK_MOCK_FUNCTIONn` macros respectively. These macros are still supported as long as they are used consistently for a given method/function pair, though migration to the new ones is recommended. For instance, if you use `MOCK_METHOD`/`MOCK_METHODn` to mock a method, then you must use `CMOCK_MOCK_FUNCTIONn` to mock a corresponding function. Note that `CMOCK_REAL_FUNCTION` is only supported for functions mocked with new generic macros.
|
||||
|
||||
### Using macros (deprecated) ###
|
||||
|
||||
C Mock comes with four macros:
|
||||
|
||||
* `DECLARE_FUNCTION_MOCKn` and `IMPLEMENT_FUNCTION_MOCKn`
|
||||
* `EXPECT_FUNCTION_CALL`
|
||||
* `ON_FUNCTION_CALL`
|
||||
|
||||
These macros do what theirs' method counterparts do `MOCK_METHODn`, `EXPECT_CALL` and `ON_CALL`, respectively. There are small differences though.
|
||||
|
||||
#### Creating mock ####
|
||||
|
||||
Both `DECLARE_FUNCTION_MOCKn` and `IMPLEMENT_FUNCTION_MOCKn` stand for a series of macros for defining and implementing a function mock, respectively. These macros take three arguments: a mock class name, a function name, and a function prototype.
|
||||
|
||||
C Mock internally redefines a function being mocked. Because only one implementation of a function might exist in an executable, a splitting of a declaration and implementation is necessary. Especially, if mocking a certain function takes place in more than one compilation unit. Therefore declaration should be put in a header file whereas implementation in a source file.
|
||||
|
||||
C Mock does not know whether a mocked function is declared with a name mangling - whether this is a pure C function or a C++ function. Therefore C Mock does not redeclare mocked function. Original function prototype declaration should be used (i.e. use of original function header file).
|
||||
|
||||
Suppose you want to mock `int add(int, int)` function declared in *math.h* header file. To do that you create `AddFunctionMock` mock class:
|
||||
|
||||
*add_function_mock.h*
|
||||
|
||||
```cpp
|
||||
#include <cmock/cmock.h>
|
||||
|
||||
#include "math.h" // use original function declaration
|
||||
|
||||
DECLARE_FUNCTION_MOCK2(AddFunctionMock, add, int(int, int));
|
||||
```
|
||||
|
||||
*add_function_mock.cc*
|
||||
|
||||
```cpp
|
||||
IMPLEMENT_FUNCTION_MOCK2(AddFunctionMock, add, int(int, int));
|
||||
```
|
||||
|
||||
#### Specifying expectations ####
|
||||
|
||||
`EXPECT_FUNCTION_CALL` and `ON_FUNCTION_CALL` do exactly what theirs' method equivalents. Both take two arguments: a mock class instance and the arguments you expect - there is no need to repeat the function name since it is already known at this point. Suppose we expect the `add` function to be called once with arguments *1* and *2*, and want it to return *12*:
|
||||
|
||||
```cpp
|
||||
AddFunctionMock mock;
|
||||
EXPECT_FUNCTION_CALL(mock, (1, 2)).WillOnce(::testing::Return(12));
|
||||
```
|
||||
|
||||
A function is mocked as long as its corresponding mock class instance exists. This allows controlling when a function is mocked.
|
||||
|
||||
```cpp
|
||||
{
|
||||
AddFunctionMock mock;
|
||||
add(1, 2); // calling the mock
|
||||
}
|
||||
|
||||
add(1, 2); // calling the real function
|
||||
```
|
||||
|
||||
Still, you might want to call a real function. Each mock class exports a static `real` class member holding a pointer to a real function.
|
||||
|
||||
```cpp
|
||||
AddFunctionMock mock;
|
||||
EXPECT_FUNCTION_CALL(mock, (1, 2)).WillOnce(::testing::Invoke(AddFunctionMock::real));
|
||||
foo(1, 2); // calling the real function
|
||||
```
|
||||
|
||||
### Building ###
|
||||
|
||||
C Mock uses specific GNU/Linux features internally and a test build requires a few additional steps.
|
||||
|
||||
Firstly, all functions you want to mock must be compiled into a dynamic library. If it includes your project-specific functions you must put them into a dynamic library as well.
|
||||
|
||||
Secondly, you must pass the following options to a linker when building a test executable:
|
||||
|
||||
* *-rdynamic* - adds all symbols to a dynamic symbol table
|
||||
* *-Wl,--no-as-needed* - forces to link with the library during static linking when there are no dependencies to it
|
||||
* *-ldl* - links with dynamic linking loader library
|
||||
|
||||
C Mock comes with the *cmock-config* tool to hide all these details away from you. Run
|
||||
|
||||
```sh
|
||||
cmock-config --cflags [path to Google Test]
|
||||
```
|
||||
|
||||
and
|
||||
|
||||
```sh
|
||||
cmock-config --libs [path to Google Test]
|
||||
```
|
||||
|
||||
to get the compiler and linker options, respectively.
|
||||
|
||||
Since [it is not recommended to install a pre-compiled version of Google Test][4] many distributions don't provide pre-compiled Google Test anymore. You need to download and compile Google Test manually as described in [Google Test][1]. The optional second command argument is a path to a directory containing downloaded and built Google Test.
|
||||
|
||||
Suppose you have `foo.c` and `bar.c` files containing a code to test, a `spam.c` file containing project functions to mock, and a `foobar_test.cc` file containing the tests. To build your test executable:
|
||||
|
||||
1. Compile the code to test.
|
||||
|
||||
```sh
|
||||
cc -c foo.c -o foo.o
|
||||
cc -c bar.c -o bar.o
|
||||
```
|
||||
|
||||
Note that C-Mock does not require a code under test to be compiled with a C++ compiler. In the example above, a code under a test is compiled with a C compiler and the tests themselves are compiled with a C++ compiler.
|
||||
|
||||
2. Build a shared library containing project functions to mock.
|
||||
|
||||
```sh
|
||||
cc -c -fPIC spam.c -o spam.o
|
||||
cc -shared -Wl,-soname,$(pwd)/libspam.so -o libspam.so spam.o
|
||||
```
|
||||
|
||||
In general, this step is optional if the functions to mock are already provided by a dynamic library (i.e. third-party library).
|
||||
|
||||
When building a dynamic library it is handy to specify *soname* as an absolute pathname. Then when the test executable is run no additional environment setup is required for the dynamic linking loader to locate your library (i.e. setting `LD_LIBRARY_PATH`).
|
||||
|
||||
3. Compile the tests.
|
||||
|
||||
```sh
|
||||
g++ `cmock-config --cflags` -c foobar_test.cc -o foobar_test.o
|
||||
```
|
||||
|
||||
4. Build a test executable.
|
||||
|
||||
```sh
|
||||
g++ `cmock-config --libs` -pthread -lspam foobar_test.o foo.o bar.o -o foobar_test
|
||||
```
|
||||
|
||||
Google Test requires -pthread.
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
To install run:
|
||||
|
||||
```
|
||||
make install
|
||||
```
|
||||
|
||||
To uninstall run:
|
||||
|
||||
```
|
||||
make uninstall
|
||||
```
|
||||
|
||||
By default installation *PREFIX* is */usr/local*. You can change it as follows:
|
||||
|
||||
```
|
||||
make install PREFIX=/usr
|
||||
```
|
||||
|
||||
Test
|
||||
----
|
||||
|
||||
If your environment is supported and Google Test is installed, the following commands should succeed:
|
||||
|
||||
```
|
||||
make
|
||||
make test
|
||||
```
|
||||
|
||||
Optionally you can provide a directory containing downloaded and built Google Test by setting `GTEST_DIR`:
|
||||
|
||||
```
|
||||
GTEST_DIR=/path/to/googletest make
|
||||
```
|
||||
|
||||
Tests are quite simple and are a good source of usage examples.
|
||||
|
||||
References
|
||||
----------
|
||||
* [Google Mock][1]
|
||||
* [My code calls a static/global function. Can I mock it?][2]
|
||||
* [Defeat "Static Cling"][3]
|
||||
* [Why is it not recommended to install a pre-compiled copy of Google Test (for example, into /usr/local)][4]
|
||||
|
||||
[1]: https://github.com/google/googletest "Google Test"
|
||||
[2]: https://github.com/google/googletest/blob/3cfb4117f7e56f8a7075d83f3e59551dc9e9f328/googlemock/docs/gmock_faq.md#my-code-calls-a-staticglobal-function-can-i-mock-it "My code calls a static/global function. Can I mock it?"
|
||||
[3]: https://googletesting.blogspot.com/2008/06/defeat-static-cling.html "Defeat \"Static Cling\""
|
||||
[4]: https://github.com/google/googletest/blob/36066cfecf79267bdf46ff82ca6c3b052f8f633c/googletest/docs/faq.md#why-is-it-not-recommended-to-install-a-pre-compiled-copy-of-google-test-for-example-into-usrlocal "Why is it not recommended to install a pre-compiled copy of Google Test (for example, into /usr/local)"
|
76
external/C-Mock/bin/cmock-config
vendored
Executable file
76
external/C-Mock/bin/cmock-config
vendored
Executable file
@@ -0,0 +1,76 @@
|
||||
#!/bin/bash
|
||||
|
||||
function print_usage
|
||||
{
|
||||
echo "$0 OPTION [GOOGLE-TEST-DIRECTORY]"
|
||||
echo "Provide compilation and linker options required by C Mock."
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo ""
|
||||
echo " --cflags print compilation options"
|
||||
echo " --libs print linker options"
|
||||
echo " -h, --help print help"
|
||||
echo ""
|
||||
echo "GOOGLE-TEST-DIRECTORY is a directory contaning downloaded and built Google Test."
|
||||
}
|
||||
|
||||
function check_directory
|
||||
{
|
||||
DIR=$1
|
||||
|
||||
if [ -e "$DIR" ]; then
|
||||
if [ ! -d "$DIR" ]; then
|
||||
echo "'$DIR' is not a directory."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "'$DIR' does not exist."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function find_directories
|
||||
{
|
||||
DIR=$(readlink -f "$1")
|
||||
FILE_PATTERN=$2
|
||||
|
||||
find "$DIR" -regex $FILE_PATTERN -type f -exec dirname {} \; | sort | uniq
|
||||
}
|
||||
|
||||
if [ $# -lt 1 -o $# -gt 2 ]; then
|
||||
print_usage 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case $1 in
|
||||
'--cflags')
|
||||
CMOCK_DIR=$(dirname $(dirname $(readlink -f $0)))
|
||||
OPTIONS="-I'$CMOCK_DIR/include'"
|
||||
|
||||
if [ $# -eq 2 ]; then
|
||||
GTEST_DIR=$2
|
||||
check_directory "$GTEST_DIR"
|
||||
OPTIONS+=$(find_directories "$GTEST_DIR" '.*/\(gtest/gtest\.h\|gmock/gmock.h\)' | xargs -d '\n' dirname | xargs -d '\n' printf " -I'%s'")
|
||||
fi
|
||||
|
||||
echo $OPTIONS
|
||||
;;
|
||||
'--libs')
|
||||
OPTIONS="-rdynamic -Wl,--no-as-needed -ldl"
|
||||
|
||||
if [ $# -eq 2 ]; then
|
||||
GTEST_DIR=$2
|
||||
check_directory "$GTEST_DIR"
|
||||
OPTIONS+=$(find_directories "$GTEST_DIR" '.*/\(libgtest\|libgmock\|libgmock_main\)\.a' | xargs -d '\n' printf " -L'%s'")
|
||||
fi
|
||||
|
||||
echo $OPTIONS
|
||||
;;
|
||||
'-h'|'--help')
|
||||
print_usage
|
||||
;;
|
||||
*)
|
||||
print_usage 1>&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
370
external/C-Mock/include/cmock/cmock-function-class-mockers.h
vendored
Normal file
370
external/C-Mock/include/cmock/cmock-function-class-mockers.h
vendored
Normal file
@@ -0,0 +1,370 @@
|
||||
// This file was GENERATED by command:
|
||||
// pump.py cmock-function-class-mockers.h.pump
|
||||
// DO NOT EDIT BY HAND!!!
|
||||
|
||||
// Copyright 2013, Hubert Jagodziński
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: hubert.jagodzinski@gmail.com (Hubert Jagodziński)
|
||||
|
||||
// C Mock - extension to Google Mock framework allowing for writing C mock
|
||||
// functions.
|
||||
//
|
||||
// This file implements C function mockers of various arities.
|
||||
|
||||
#ifndef CMOCK_INCLUDE_CMOCK_CMOCK_FUNCTION_CLASS_MOCKERS_H_
|
||||
#define CMOCK_INCLUDE_CMOCK_CMOCK_FUNCTION_CLASS_MOCKERS_H_
|
||||
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
|
||||
// Allows finding an instance of a class:
|
||||
// class Foo : public CMockMocker<Foo> { ... }
|
||||
// Foo *p = CMockMocker<Foo>::cmock_get_instance();
|
||||
template<typename T>
|
||||
class CMockMocker
|
||||
{
|
||||
public:
|
||||
CMockMocker()
|
||||
{
|
||||
instance = (T *)this;
|
||||
}
|
||||
|
||||
~CMockMocker()
|
||||
{
|
||||
instance = (T *)NULL;
|
||||
}
|
||||
|
||||
static T *cmock_get_instance() { return instance; }
|
||||
|
||||
private:
|
||||
static T *instance;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
T *CMockMocker<T>::instance = NULL;
|
||||
|
||||
// Find the real implementation of a mocked function
|
||||
static inline void *
|
||||
cmock_lookup(const char *fname)
|
||||
{
|
||||
return dlsym(RTLD_NEXT, fname);
|
||||
}
|
||||
|
||||
#define CMOCK_MOCK_FUNCTION0(c, n, F) \
|
||||
static GMOCK_RESULT_(, F) (*__cmock_real_##c##_##n)() = \
|
||||
(GMOCK_RESULT_(, F) (*)())cmock_lookup(#n); \
|
||||
\
|
||||
GMOCK_RESULT_(, F) n() { \
|
||||
c *mock = c::cmock_get_instance(); \
|
||||
if (mock != NULL) { \
|
||||
return mock->n(); \
|
||||
} \
|
||||
\
|
||||
if (__cmock_real_##c##_##n == NULL) { \
|
||||
std::ostringstream msg; \
|
||||
msg << "Error: Function " << #n; \
|
||||
msg << " not found. Neither mock nor real function is present."; \
|
||||
throw std::logic_error(msg.str()); \
|
||||
} \
|
||||
return __cmock_real_##c##_##n(); \
|
||||
} \
|
||||
|
||||
#define CMOCK_MOCK_FUNCTION1(c, n, F) \
|
||||
static GMOCK_RESULT_(, F) (*__cmock_real_##c##_##n)(GMOCK_ARG_(, 1, \
|
||||
F) cmock_a1) = \
|
||||
(GMOCK_RESULT_(, F) (*)(GMOCK_ARG_(, 1, F) cmock_a1))cmock_lookup(#n); \
|
||||
\
|
||||
GMOCK_RESULT_(, F) n(GMOCK_ARG_(, 1, F) cmock_a1) { \
|
||||
c *mock = c::cmock_get_instance(); \
|
||||
if (mock != NULL) { \
|
||||
return mock->n(cmock_a1); \
|
||||
} \
|
||||
\
|
||||
if (__cmock_real_##c##_##n == NULL) { \
|
||||
std::ostringstream msg; \
|
||||
msg << "Error: Function " << #n; \
|
||||
msg << " not found. Neither mock nor real function is present."; \
|
||||
throw std::logic_error(msg.str()); \
|
||||
} \
|
||||
return __cmock_real_##c##_##n(cmock_a1); \
|
||||
} \
|
||||
|
||||
#define CMOCK_MOCK_FUNCTION2(c, n, F) \
|
||||
static GMOCK_RESULT_(, F) (*__cmock_real_##c##_##n)(GMOCK_ARG_(, 1, \
|
||||
F) cmock_a1, GMOCK_ARG_(, 2, F) cmock_a2) = \
|
||||
(GMOCK_RESULT_(, F) (*)(GMOCK_ARG_(, 1, F) cmock_a1, GMOCK_ARG_(, 2, \
|
||||
F) cmock_a2))cmock_lookup(#n); \
|
||||
\
|
||||
GMOCK_RESULT_(, F) n(GMOCK_ARG_(, 1, F) cmock_a1, GMOCK_ARG_(, 2, \
|
||||
F) cmock_a2) { \
|
||||
c *mock = c::cmock_get_instance(); \
|
||||
if (mock != NULL) { \
|
||||
return mock->n(cmock_a1, cmock_a2); \
|
||||
} \
|
||||
\
|
||||
if (__cmock_real_##c##_##n == NULL) { \
|
||||
std::ostringstream msg; \
|
||||
msg << "Error: Function " << #n; \
|
||||
msg << " not found. Neither mock nor real function is present."; \
|
||||
throw std::logic_error(msg.str()); \
|
||||
} \
|
||||
return __cmock_real_##c##_##n(cmock_a1, cmock_a2); \
|
||||
} \
|
||||
|
||||
#define CMOCK_MOCK_FUNCTION3(c, n, F) \
|
||||
static GMOCK_RESULT_(, F) (*__cmock_real_##c##_##n)(GMOCK_ARG_(, 1, \
|
||||
F) cmock_a1, GMOCK_ARG_(, 2, F) cmock_a2, GMOCK_ARG_(, 3, \
|
||||
F) cmock_a3) = \
|
||||
(GMOCK_RESULT_(, F) (*)(GMOCK_ARG_(, 1, F) cmock_a1, GMOCK_ARG_(, 2, \
|
||||
F) cmock_a2, GMOCK_ARG_(, 3, F) cmock_a3))cmock_lookup(#n); \
|
||||
\
|
||||
GMOCK_RESULT_(, F) n(GMOCK_ARG_(, 1, F) cmock_a1, GMOCK_ARG_(, 2, \
|
||||
F) cmock_a2, GMOCK_ARG_(, 3, F) cmock_a3) { \
|
||||
c *mock = c::cmock_get_instance(); \
|
||||
if (mock != NULL) { \
|
||||
return mock->n(cmock_a1, cmock_a2, cmock_a3); \
|
||||
} \
|
||||
\
|
||||
if (__cmock_real_##c##_##n == NULL) { \
|
||||
std::ostringstream msg; \
|
||||
msg << "Error: Function " << #n; \
|
||||
msg << " not found. Neither mock nor real function is present."; \
|
||||
throw std::logic_error(msg.str()); \
|
||||
} \
|
||||
return __cmock_real_##c##_##n(cmock_a1, cmock_a2, cmock_a3); \
|
||||
} \
|
||||
|
||||
#define CMOCK_MOCK_FUNCTION4(c, n, F) \
|
||||
static GMOCK_RESULT_(, F) (*__cmock_real_##c##_##n)(GMOCK_ARG_(, 1, \
|
||||
F) cmock_a1, GMOCK_ARG_(, 2, F) cmock_a2, GMOCK_ARG_(, 3, F) cmock_a3, \
|
||||
GMOCK_ARG_(, 4, F) cmock_a4) = \
|
||||
(GMOCK_RESULT_(, F) (*)(GMOCK_ARG_(, 1, F) cmock_a1, GMOCK_ARG_(, 2, \
|
||||
F) cmock_a2, GMOCK_ARG_(, 3, F) cmock_a3, GMOCK_ARG_(, 4, \
|
||||
F) cmock_a4))cmock_lookup(#n); \
|
||||
\
|
||||
GMOCK_RESULT_(, F) n(GMOCK_ARG_(, 1, F) cmock_a1, GMOCK_ARG_(, 2, \
|
||||
F) cmock_a2, GMOCK_ARG_(, 3, F) cmock_a3, GMOCK_ARG_(, 4, \
|
||||
F) cmock_a4) { \
|
||||
c *mock = c::cmock_get_instance(); \
|
||||
if (mock != NULL) { \
|
||||
return mock->n(cmock_a1, cmock_a2, cmock_a3, cmock_a4); \
|
||||
} \
|
||||
\
|
||||
if (__cmock_real_##c##_##n == NULL) { \
|
||||
std::ostringstream msg; \
|
||||
msg << "Error: Function " << #n; \
|
||||
msg << " not found. Neither mock nor real function is present."; \
|
||||
throw std::logic_error(msg.str()); \
|
||||
} \
|
||||
return __cmock_real_##c##_##n(cmock_a1, cmock_a2, cmock_a3, cmock_a4); \
|
||||
} \
|
||||
|
||||
#define CMOCK_MOCK_FUNCTION5(c, n, F) \
|
||||
static GMOCK_RESULT_(, F) (*__cmock_real_##c##_##n)(GMOCK_ARG_(, 1, \
|
||||
F) cmock_a1, GMOCK_ARG_(, 2, F) cmock_a2, GMOCK_ARG_(, 3, F) cmock_a3, \
|
||||
GMOCK_ARG_(, 4, F) cmock_a4, GMOCK_ARG_(, 5, F) cmock_a5) = \
|
||||
(GMOCK_RESULT_(, F) (*)(GMOCK_ARG_(, 1, F) cmock_a1, GMOCK_ARG_(, 2, \
|
||||
F) cmock_a2, GMOCK_ARG_(, 3, F) cmock_a3, GMOCK_ARG_(, 4, F) cmock_a4, \
|
||||
GMOCK_ARG_(, 5, F) cmock_a5))cmock_lookup(#n); \
|
||||
\
|
||||
GMOCK_RESULT_(, F) n(GMOCK_ARG_(, 1, F) cmock_a1, GMOCK_ARG_(, 2, \
|
||||
F) cmock_a2, GMOCK_ARG_(, 3, F) cmock_a3, GMOCK_ARG_(, 4, F) cmock_a4, \
|
||||
GMOCK_ARG_(, 5, F) cmock_a5) { \
|
||||
c *mock = c::cmock_get_instance(); \
|
||||
if (mock != NULL) { \
|
||||
return mock->n(cmock_a1, cmock_a2, cmock_a3, cmock_a4, cmock_a5); \
|
||||
} \
|
||||
\
|
||||
if (__cmock_real_##c##_##n == NULL) { \
|
||||
std::ostringstream msg; \
|
||||
msg << "Error: Function " << #n; \
|
||||
msg << " not found. Neither mock nor real function is present."; \
|
||||
throw std::logic_error(msg.str()); \
|
||||
} \
|
||||
return __cmock_real_##c##_##n(cmock_a1, cmock_a2, cmock_a3, cmock_a4, \
|
||||
cmock_a5); \
|
||||
} \
|
||||
|
||||
#define CMOCK_MOCK_FUNCTION6(c, n, F) \
|
||||
static GMOCK_RESULT_(, F) (*__cmock_real_##c##_##n)(GMOCK_ARG_(, 1, \
|
||||
F) cmock_a1, GMOCK_ARG_(, 2, F) cmock_a2, GMOCK_ARG_(, 3, F) cmock_a3, \
|
||||
GMOCK_ARG_(, 4, F) cmock_a4, GMOCK_ARG_(, 5, F) cmock_a5, GMOCK_ARG_(, 6, \
|
||||
F) cmock_a6) = \
|
||||
(GMOCK_RESULT_(, F) (*)(GMOCK_ARG_(, 1, F) cmock_a1, GMOCK_ARG_(, 2, \
|
||||
F) cmock_a2, GMOCK_ARG_(, 3, F) cmock_a3, GMOCK_ARG_(, 4, F) cmock_a4, \
|
||||
GMOCK_ARG_(, 5, F) cmock_a5, GMOCK_ARG_(, 6, \
|
||||
F) cmock_a6))cmock_lookup(#n); \
|
||||
\
|
||||
GMOCK_RESULT_(, F) n(GMOCK_ARG_(, 1, F) cmock_a1, GMOCK_ARG_(, 2, \
|
||||
F) cmock_a2, GMOCK_ARG_(, 3, F) cmock_a3, GMOCK_ARG_(, 4, F) cmock_a4, \
|
||||
GMOCK_ARG_(, 5, F) cmock_a5, GMOCK_ARG_(, 6, F) cmock_a6) { \
|
||||
c *mock = c::cmock_get_instance(); \
|
||||
if (mock != NULL) { \
|
||||
return mock->n(cmock_a1, cmock_a2, cmock_a3, cmock_a4, cmock_a5, \
|
||||
cmock_a6); \
|
||||
} \
|
||||
\
|
||||
if (__cmock_real_##c##_##n == NULL) { \
|
||||
std::ostringstream msg; \
|
||||
msg << "Error: Function " << #n; \
|
||||
msg << " not found. Neither mock nor real function is present."; \
|
||||
throw std::logic_error(msg.str()); \
|
||||
} \
|
||||
return __cmock_real_##c##_##n(cmock_a1, cmock_a2, cmock_a3, cmock_a4, \
|
||||
cmock_a5, cmock_a6); \
|
||||
} \
|
||||
|
||||
#define CMOCK_MOCK_FUNCTION7(c, n, F) \
|
||||
static GMOCK_RESULT_(, F) (*__cmock_real_##c##_##n)(GMOCK_ARG_(, 1, \
|
||||
F) cmock_a1, GMOCK_ARG_(, 2, F) cmock_a2, GMOCK_ARG_(, 3, F) cmock_a3, \
|
||||
GMOCK_ARG_(, 4, F) cmock_a4, GMOCK_ARG_(, 5, F) cmock_a5, GMOCK_ARG_(, 6, \
|
||||
F) cmock_a6, GMOCK_ARG_(, 7, F) cmock_a7) = \
|
||||
(GMOCK_RESULT_(, F) (*)(GMOCK_ARG_(, 1, F) cmock_a1, GMOCK_ARG_(, 2, \
|
||||
F) cmock_a2, GMOCK_ARG_(, 3, F) cmock_a3, GMOCK_ARG_(, 4, F) cmock_a4, \
|
||||
GMOCK_ARG_(, 5, F) cmock_a5, GMOCK_ARG_(, 6, F) cmock_a6, GMOCK_ARG_(, \
|
||||
7, F) cmock_a7))cmock_lookup(#n); \
|
||||
\
|
||||
GMOCK_RESULT_(, F) n(GMOCK_ARG_(, 1, F) cmock_a1, GMOCK_ARG_(, 2, \
|
||||
F) cmock_a2, GMOCK_ARG_(, 3, F) cmock_a3, GMOCK_ARG_(, 4, F) cmock_a4, \
|
||||
GMOCK_ARG_(, 5, F) cmock_a5, GMOCK_ARG_(, 6, F) cmock_a6, GMOCK_ARG_(, 7, \
|
||||
F) cmock_a7) { \
|
||||
c *mock = c::cmock_get_instance(); \
|
||||
if (mock != NULL) { \
|
||||
return mock->n(cmock_a1, cmock_a2, cmock_a3, cmock_a4, cmock_a5, \
|
||||
cmock_a6, cmock_a7); \
|
||||
} \
|
||||
\
|
||||
if (__cmock_real_##c##_##n == NULL) { \
|
||||
std::ostringstream msg; \
|
||||
msg << "Error: Function " << #n; \
|
||||
msg << " not found. Neither mock nor real function is present."; \
|
||||
throw std::logic_error(msg.str()); \
|
||||
} \
|
||||
return __cmock_real_##c##_##n(cmock_a1, cmock_a2, cmock_a3, cmock_a4, \
|
||||
cmock_a5, cmock_a6, cmock_a7); \
|
||||
} \
|
||||
|
||||
#define CMOCK_MOCK_FUNCTION8(c, n, F) \
|
||||
static GMOCK_RESULT_(, F) (*__cmock_real_##c##_##n)(GMOCK_ARG_(, 1, \
|
||||
F) cmock_a1, GMOCK_ARG_(, 2, F) cmock_a2, GMOCK_ARG_(, 3, F) cmock_a3, \
|
||||
GMOCK_ARG_(, 4, F) cmock_a4, GMOCK_ARG_(, 5, F) cmock_a5, GMOCK_ARG_(, 6, \
|
||||
F) cmock_a6, GMOCK_ARG_(, 7, F) cmock_a7, GMOCK_ARG_(, 8, \
|
||||
F) cmock_a8) = \
|
||||
(GMOCK_RESULT_(, F) (*)(GMOCK_ARG_(, 1, F) cmock_a1, GMOCK_ARG_(, 2, \
|
||||
F) cmock_a2, GMOCK_ARG_(, 3, F) cmock_a3, GMOCK_ARG_(, 4, F) cmock_a4, \
|
||||
GMOCK_ARG_(, 5, F) cmock_a5, GMOCK_ARG_(, 6, F) cmock_a6, GMOCK_ARG_(, \
|
||||
7, F) cmock_a7, GMOCK_ARG_(, 8, F) cmock_a8))cmock_lookup(#n); \
|
||||
\
|
||||
GMOCK_RESULT_(, F) n(GMOCK_ARG_(, 1, F) cmock_a1, GMOCK_ARG_(, 2, \
|
||||
F) cmock_a2, GMOCK_ARG_(, 3, F) cmock_a3, GMOCK_ARG_(, 4, F) cmock_a4, \
|
||||
GMOCK_ARG_(, 5, F) cmock_a5, GMOCK_ARG_(, 6, F) cmock_a6, GMOCK_ARG_(, 7, \
|
||||
F) cmock_a7, GMOCK_ARG_(, 8, F) cmock_a8) { \
|
||||
c *mock = c::cmock_get_instance(); \
|
||||
if (mock != NULL) { \
|
||||
return mock->n(cmock_a1, cmock_a2, cmock_a3, cmock_a4, cmock_a5, \
|
||||
cmock_a6, cmock_a7, cmock_a8); \
|
||||
} \
|
||||
\
|
||||
if (__cmock_real_##c##_##n == NULL) { \
|
||||
std::ostringstream msg; \
|
||||
msg << "Error: Function " << #n; \
|
||||
msg << " not found. Neither mock nor real function is present."; \
|
||||
throw std::logic_error(msg.str()); \
|
||||
} \
|
||||
return __cmock_real_##c##_##n(cmock_a1, cmock_a2, cmock_a3, cmock_a4, \
|
||||
cmock_a5, cmock_a6, cmock_a7, cmock_a8); \
|
||||
} \
|
||||
|
||||
#define CMOCK_MOCK_FUNCTION9(c, n, F) \
|
||||
static GMOCK_RESULT_(, F) (*__cmock_real_##c##_##n)(GMOCK_ARG_(, 1, \
|
||||
F) cmock_a1, GMOCK_ARG_(, 2, F) cmock_a2, GMOCK_ARG_(, 3, F) cmock_a3, \
|
||||
GMOCK_ARG_(, 4, F) cmock_a4, GMOCK_ARG_(, 5, F) cmock_a5, GMOCK_ARG_(, 6, \
|
||||
F) cmock_a6, GMOCK_ARG_(, 7, F) cmock_a7, GMOCK_ARG_(, 8, F) cmock_a8, \
|
||||
GMOCK_ARG_(, 9, F) cmock_a9) = \
|
||||
(GMOCK_RESULT_(, F) (*)(GMOCK_ARG_(, 1, F) cmock_a1, GMOCK_ARG_(, 2, \
|
||||
F) cmock_a2, GMOCK_ARG_(, 3, F) cmock_a3, GMOCK_ARG_(, 4, F) cmock_a4, \
|
||||
GMOCK_ARG_(, 5, F) cmock_a5, GMOCK_ARG_(, 6, F) cmock_a6, GMOCK_ARG_(, \
|
||||
7, F) cmock_a7, GMOCK_ARG_(, 8, F) cmock_a8, GMOCK_ARG_(, 9, \
|
||||
F) cmock_a9))cmock_lookup(#n); \
|
||||
\
|
||||
GMOCK_RESULT_(, F) n(GMOCK_ARG_(, 1, F) cmock_a1, GMOCK_ARG_(, 2, \
|
||||
F) cmock_a2, GMOCK_ARG_(, 3, F) cmock_a3, GMOCK_ARG_(, 4, F) cmock_a4, \
|
||||
GMOCK_ARG_(, 5, F) cmock_a5, GMOCK_ARG_(, 6, F) cmock_a6, GMOCK_ARG_(, 7, \
|
||||
F) cmock_a7, GMOCK_ARG_(, 8, F) cmock_a8, GMOCK_ARG_(, 9, \
|
||||
F) cmock_a9) { \
|
||||
c *mock = c::cmock_get_instance(); \
|
||||
if (mock != NULL) { \
|
||||
return mock->n(cmock_a1, cmock_a2, cmock_a3, cmock_a4, cmock_a5, \
|
||||
cmock_a6, cmock_a7, cmock_a8, cmock_a9); \
|
||||
} \
|
||||
\
|
||||
if (__cmock_real_##c##_##n == NULL) { \
|
||||
std::ostringstream msg; \
|
||||
msg << "Error: Function " << #n; \
|
||||
msg << " not found. Neither mock nor real function is present."; \
|
||||
throw std::logic_error(msg.str()); \
|
||||
} \
|
||||
return __cmock_real_##c##_##n(cmock_a1, cmock_a2, cmock_a3, cmock_a4, \
|
||||
cmock_a5, cmock_a6, cmock_a7, cmock_a8, cmock_a9); \
|
||||
} \
|
||||
|
||||
#define CMOCK_MOCK_FUNCTION10(c, n, F) \
|
||||
static GMOCK_RESULT_(, F) (*__cmock_real_##c##_##n)(GMOCK_ARG_(, 1, \
|
||||
F) cmock_a1, GMOCK_ARG_(, 2, F) cmock_a2, GMOCK_ARG_(, 3, F) cmock_a3, \
|
||||
GMOCK_ARG_(, 4, F) cmock_a4, GMOCK_ARG_(, 5, F) cmock_a5, GMOCK_ARG_(, 6, \
|
||||
F) cmock_a6, GMOCK_ARG_(, 7, F) cmock_a7, GMOCK_ARG_(, 8, F) cmock_a8, \
|
||||
GMOCK_ARG_(, 9, F) cmock_a9, GMOCK_ARG_(, 10, F) cmock_a10) = \
|
||||
(GMOCK_RESULT_(, F) (*)(GMOCK_ARG_(, 1, F) cmock_a1, GMOCK_ARG_(, 2, \
|
||||
F) cmock_a2, GMOCK_ARG_(, 3, F) cmock_a3, GMOCK_ARG_(, 4, F) cmock_a4, \
|
||||
GMOCK_ARG_(, 5, F) cmock_a5, GMOCK_ARG_(, 6, F) cmock_a6, GMOCK_ARG_(, \
|
||||
7, F) cmock_a7, GMOCK_ARG_(, 8, F) cmock_a8, GMOCK_ARG_(, 9, \
|
||||
F) cmock_a9, GMOCK_ARG_(, 10, F) cmock_a10))cmock_lookup(#n); \
|
||||
\
|
||||
GMOCK_RESULT_(, F) n(GMOCK_ARG_(, 1, F) cmock_a1, GMOCK_ARG_(, 2, \
|
||||
F) cmock_a2, GMOCK_ARG_(, 3, F) cmock_a3, GMOCK_ARG_(, 4, F) cmock_a4, \
|
||||
GMOCK_ARG_(, 5, F) cmock_a5, GMOCK_ARG_(, 6, F) cmock_a6, GMOCK_ARG_(, 7, \
|
||||
F) cmock_a7, GMOCK_ARG_(, 8, F) cmock_a8, GMOCK_ARG_(, 9, F) cmock_a9, \
|
||||
GMOCK_ARG_(, 10, F) cmock_a10) { \
|
||||
c *mock = c::cmock_get_instance(); \
|
||||
if (mock != NULL) { \
|
||||
return mock->n(cmock_a1, cmock_a2, cmock_a3, cmock_a4, cmock_a5, \
|
||||
cmock_a6, cmock_a7, cmock_a8, cmock_a9, cmock_a10); \
|
||||
} \
|
||||
\
|
||||
if (__cmock_real_##c##_##n == NULL) { \
|
||||
std::ostringstream msg; \
|
||||
msg << "Error: Function " << #n; \
|
||||
msg << " not found. Neither mock nor real function is present."; \
|
||||
throw std::logic_error(msg.str()); \
|
||||
} \
|
||||
return __cmock_real_##c##_##n(cmock_a1, cmock_a2, cmock_a3, cmock_a4, \
|
||||
cmock_a5, cmock_a6, cmock_a7, cmock_a8, cmock_a9, cmock_a10); \
|
||||
} \
|
||||
|
||||
#endif // CMOCK_INCLUDE_CMOCK_CMOCK_FUNCTION_CLASS_MOCKERS_H_
|
1082
external/C-Mock/include/cmock/cmock-function-mockers.h
vendored
Normal file
1082
external/C-Mock/include/cmock/cmock-function-mockers.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
43
external/C-Mock/include/cmock/cmock-internal.h
vendored
Normal file
43
external/C-Mock/include/cmock/cmock-internal.h
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
// Copyright 2021, Hubert Jagodziński
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: hubert.jagodzinski@gmail.com (Hubert Jagodziński)
|
||||
|
||||
// C Mock - Google Mock's extension allowing a function mocking.
|
||||
//
|
||||
// This file implements helper macros for internal use only.
|
||||
|
||||
#ifndef CMOCK_INCLUDE_CMOCK_CMOCK_INTERNAL_H_
|
||||
#define CMOCK_INCLUDE_CMOCK_CMOCK_INTERNAL_H_
|
||||
|
||||
#define CMOCK_INTERNAL_NO_PARAMETER_NAME(_i, _Signature, _) \
|
||||
GMOCK_PP_COMMA_IF(_i) \
|
||||
GMOCK_INTERNAL_ARG_O(_i, GMOCK_PP_REMOVE_PARENS(_Signature))
|
||||
|
||||
#define CMOCK_INTERNAL_RETURN_TYPE(_Signature) \
|
||||
typename ::testing::internal::Function<GMOCK_PP_REMOVE_PARENS(_Signature)>::Result
|
||||
|
||||
#endif // CMOCK_INCLUDE_CMOCK_CMOCK_INTERNAL_H_
|
45
external/C-Mock/include/cmock/cmock-spec-builders.h
vendored
Normal file
45
external/C-Mock/include/cmock/cmock-spec-builders.h
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
// Copyright 2013, Hubert Jagodziński
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: hubert.jagodzinski@gmail.com (Hubert Jagodziński)
|
||||
|
||||
// C Mock - extension to Google Mock framework allowing for writing C mock functions.
|
||||
//
|
||||
// This file implements the ON_FUNCTION_CALL() and EXPECT_FUNCTION_CALL() macros.
|
||||
|
||||
#ifndef CMOCK_INCLUDE_CMOCK_CMOCK_SPEC_BUILDERS_H_
|
||||
#define CMOCK_INCLUDE_CMOCK_CMOCK_SPEC_BUILDERS_H_
|
||||
|
||||
#define CMOCK_ON_FUNCTION_CALL_IMPL_(obj, call) \
|
||||
((obj).cmock_func call).InternalDefaultActionSetAt(__FILE__, __LINE__, \
|
||||
#obj, #call)
|
||||
#define ON_FUNCTION_CALL(obj, call) CMOCK_ON_FUNCTION_CALL_IMPL_(obj, call)
|
||||
|
||||
#define CMOCK_EXPECT_FUNCTION_CALL_IMPL_(obj, call) \
|
||||
((obj).cmock_func call).InternalExpectedAt(__FILE__, __LINE__, #obj, #call)
|
||||
#define EXPECT_FUNCTION_CALL(obj, call) CMOCK_EXPECT_FUNCTION_CALL_IMPL_(obj, call)
|
||||
|
||||
#endif // CMOCK_INCLUDE_CMOCK_CMOCK_SPEC_BUILDERS_H_
|
42
external/C-Mock/include/cmock/cmock.h
vendored
Normal file
42
external/C-Mock/include/cmock/cmock.h
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
// Copyright 2013, Hubert Jagodziński
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: hubert.jagodzinski@gmail.com (Hubert Jagodziński)
|
||||
|
||||
// C Mock - extension to Google Mock framework allowing for writing C mock functions.
|
||||
//
|
||||
// This is the main header file a user should include.
|
||||
|
||||
#ifndef CMOCK_INCLUDE_CMOCK_CMOCK_H_
|
||||
#define CMOCK_INCLUDE_CMOCK_CMOCK_H_
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
#include "cmock-function-mockers.h"
|
||||
#include "cmock-function-class-mockers.h"
|
||||
#include "cmock-spec-builders.h"
|
||||
|
||||
#endif // CMOCK_INCLUDE_CMOCK_CMOCK_H_
|
49
external/C-Mock/test/cmock-function-class-mockers-old-style_test.cc
vendored
Normal file
49
external/C-Mock/test/cmock-function-class-mockers-old-style_test.cc
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
#include <cmock/cmock.h>
|
||||
|
||||
#include "math.h"
|
||||
|
||||
using namespace ::testing;
|
||||
|
||||
class MathMocker : public CMockMocker<MathMocker>
|
||||
{
|
||||
public:
|
||||
MOCK_METHOD2(add, int(int, int));
|
||||
MOCK_METHOD2(substract, int(int, int));
|
||||
MOCK_METHOD1(negate, int(int));
|
||||
};
|
||||
|
||||
CMOCK_MOCK_FUNCTION2(MathMocker, add, int(int, int));
|
||||
CMOCK_MOCK_FUNCTION2(MathMocker, substract, int(int, int));
|
||||
CMOCK_MOCK_FUNCTION1(MathMocker, negate, int(int));
|
||||
|
||||
/**
|
||||
* Functions add and substract are mocked as long as MathMocker instance exists.
|
||||
* Once a mock function is destroyed, a call directs to a real function.
|
||||
*/
|
||||
TEST(FunctionClassMockersOldStyleTest, MocksFunctionAsLongAsMockerInstanceExists) {
|
||||
|
||||
{
|
||||
MathMocker mock;
|
||||
|
||||
EXPECT_CALL(mock, add(1, 1)).WillOnce(Return(11));
|
||||
ASSERT_EQ(11, add(1, 1));
|
||||
|
||||
EXPECT_CALL(mock, substract(1, 2)).WillOnce(Return(12));
|
||||
ASSERT_EQ(12, substract(1, 2));
|
||||
}
|
||||
|
||||
ASSERT_EQ(2, add(1, 1));
|
||||
ASSERT_EQ(-1, substract(1, 2));
|
||||
}
|
||||
|
||||
TEST(FunctionClassMockersOldStyleTest, ThrowsExceptionIfRealFunctionNotFound) {
|
||||
|
||||
{
|
||||
MathMocker mock;
|
||||
|
||||
EXPECT_CALL(mock, negate(3)).WillOnce(Return(-3));
|
||||
ASSERT_EQ(-3, negate(3));
|
||||
}
|
||||
|
||||
EXPECT_THROW(negate(3), std::logic_error);
|
||||
}
|
60
external/C-Mock/test/cmock-function-class-mockers_test.cc
vendored
Normal file
60
external/C-Mock/test/cmock-function-class-mockers_test.cc
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
#include <cmock/cmock.h>
|
||||
|
||||
#include "math.h"
|
||||
|
||||
using namespace ::testing;
|
||||
|
||||
class MathMocker : public CMockMocker<MathMocker>
|
||||
{
|
||||
public:
|
||||
CMOCK_MOCK_METHOD(int, add, (int, int));
|
||||
CMOCK_MOCK_METHOD(int, substract, (int, int));
|
||||
CMOCK_MOCK_METHOD(int, negate, (int));
|
||||
};
|
||||
|
||||
CMOCK_MOCK_FUNCTION(MathMocker, int, add, (int, int));
|
||||
CMOCK_MOCK_FUNCTION(MathMocker, int, substract, (int, int));
|
||||
CMOCK_MOCK_FUNCTION(MathMocker, int, negate, (int));
|
||||
|
||||
/**
|
||||
* Functions add and substract are mocked as long as MathMocker instance exists.
|
||||
* Once a mock function is destroyed, a call directs to a real function.
|
||||
*/
|
||||
TEST(FunctionClassMockersTest, MocksFunctionAsLongAsMockerInstanceExists) {
|
||||
|
||||
{
|
||||
MathMocker mock;
|
||||
|
||||
EXPECT_CALL(mock, add(1, 1)).WillOnce(Return(11));
|
||||
ASSERT_EQ(11, add(1, 1));
|
||||
|
||||
EXPECT_CALL(mock, substract(1, 2)).WillOnce(Return(12));
|
||||
ASSERT_EQ(12, substract(1, 2));
|
||||
}
|
||||
|
||||
ASSERT_EQ(2, add(1, 1));
|
||||
ASSERT_EQ(-1, substract(1, 2));
|
||||
}
|
||||
|
||||
TEST(FunctionClassMockersTest, ThrowsExceptionIfRealFunctionNotFound) {
|
||||
|
||||
{
|
||||
MathMocker mock;
|
||||
|
||||
EXPECT_CALL(mock, negate(3)).WillOnce(Return(-3));
|
||||
ASSERT_EQ(-3, negate(3));
|
||||
}
|
||||
|
||||
EXPECT_THROW(negate(3), std::logic_error);
|
||||
}
|
||||
|
||||
TEST(FunctionClassMockersTest, ProvidesMeansToCallRealFunction) {
|
||||
|
||||
{
|
||||
MathMocker mock;
|
||||
|
||||
ASSERT_EQ(2, CMOCK_REAL_FUNCTION(MathMocker, add)(1, 1));
|
||||
}
|
||||
|
||||
ASSERT_EQ(2, CMOCK_REAL_FUNCTION(MathMocker, add)(1, 1));
|
||||
}
|
50
external/C-Mock/test/cmock-function-mockers_test.cc
vendored
Normal file
50
external/C-Mock/test/cmock-function-mockers_test.cc
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
#include <cmock/cmock.h>
|
||||
|
||||
#include "math.h"
|
||||
|
||||
using namespace ::testing;
|
||||
|
||||
DECLARE_FUNCTION_MOCK2(AddFunctionMock, add, int(int, int));
|
||||
DECLARE_FUNCTION_MOCK1(NegateFunctionMock, negate, int(int));
|
||||
|
||||
IMPLEMENT_FUNCTION_MOCK2(AddFunctionMock, add, int(int, int));
|
||||
IMPLEMENT_FUNCTION_MOCK1(NegateFunctionMock, negate, int(int));
|
||||
|
||||
/**
|
||||
* Function add is mocked as long as AddFunctionMock instance exists.
|
||||
* Once mock function is destroyed, a call directs to a real function.
|
||||
*/
|
||||
TEST(FunctionMockersTest, MocksFunctionAsLongAsMockInstanceExists) {
|
||||
|
||||
{
|
||||
AddFunctionMock mock;
|
||||
|
||||
EXPECT_FUNCTION_CALL(mock, (1, 2)).WillOnce(Return(12));
|
||||
ASSERT_EQ(12, add(1, 2));
|
||||
}
|
||||
|
||||
ASSERT_EQ(3, add(1, 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* real static mock class field holds pointer to a real function.
|
||||
*/
|
||||
TEST(FunctionMockersTest, FunctionMockExportsRealFunctionPointer) {
|
||||
EXPECT_EQ(3, AddFunctionMock::real(1, 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Function negate doesn't exist, but can be mocked.
|
||||
*/
|
||||
TEST(FunctionMockersTest, ThrowsExceptionIfRealFunctionNotFound)
|
||||
{
|
||||
{
|
||||
NegateFunctionMock mock;
|
||||
|
||||
EXPECT_FUNCTION_CALL(mock, (9)).WillOnce(Return(3));
|
||||
|
||||
ASSERT_EQ(3, negate(9));
|
||||
}
|
||||
|
||||
EXPECT_THROW(negate(9), std::logic_error);
|
||||
}
|
17
external/C-Mock/test/cmock-spec-builders_test.cc
vendored
Normal file
17
external/C-Mock/test/cmock-spec-builders_test.cc
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
#include <cmock/cmock.h>
|
||||
|
||||
#include "math.h"
|
||||
|
||||
DECLARE_FUNCTION_MOCK2(AddFunctionMock, add, int(int, int));
|
||||
|
||||
IMPLEMENT_FUNCTION_MOCK2(AddFunctionMock, add, int(int, int));
|
||||
|
||||
TEST(SpecBuildersTest, ExpectFunctionCallCompiles) {
|
||||
AddFunctionMock mock;
|
||||
EXPECT_FUNCTION_CALL(mock, (1, 2)).Times(0);
|
||||
}
|
||||
|
||||
TEST(SpecBuildersTest, OnFunctionCallCompiles) {
|
||||
AddFunctionMock mock;
|
||||
ON_FUNCTION_CALL(mock, (1, 2));
|
||||
}
|
11
external/C-Mock/test/math.c
vendored
Normal file
11
external/C-Mock/test/math.c
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "math.h"
|
||||
|
||||
int add(int a1, int a2)
|
||||
{
|
||||
return a1 + a2;
|
||||
}
|
||||
|
||||
int substract(int a1, int a2)
|
||||
{
|
||||
return a1 - a2;
|
||||
}
|
18
external/C-Mock/test/math.h
vendored
Normal file
18
external/C-Mock/test/math.h
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef CMOCK_TEST_MATH_H_
|
||||
#define CMOCK_TEST_MATH_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int add(int a1, int a2);
|
||||
int substract(int a1, int a2);
|
||||
|
||||
/* This function isn't implemented, but still can be mocked. */
|
||||
int negate(int n);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CMOCK_TEST_MATH_H_ */
|
Reference in New Issue
Block a user