kandi background
Explore Kits

trompeloeil | Header only C14 mocking framework | Mock library

 by   rollbear C++ Version: v42 License: BSL-1.0

 by   rollbear C++ Version: v42 License: BSL-1.0

Download this library from

kandi X-RAY | trompeloeil Summary

trompeloeil is a C++ library typically used in Testing, Mock, Framework applications. trompeloeil has no bugs, it has no vulnerabilities, it has a Permissive License and it has low support. You can download it from GitHub.
A thread-safe header-only mocking framework for C++11/14 using the Boost Software License 1.0.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • trompeloeil has a low active ecosystem.
  • It has 591 star(s) with 67 fork(s). There are 29 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 41 open issues and 118 have been closed. On average issues are closed in 251 days. There are 2 open pull requests and 0 closed requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of trompeloeil is v42
trompeloeil Support
Best in #Mock
Average in #Mock
trompeloeil Support
Best in #Mock
Average in #Mock

quality kandi Quality

  • trompeloeil has 0 bugs and 0 code smells.
trompeloeil Quality
Best in #Mock
Average in #Mock
trompeloeil Quality
Best in #Mock
Average in #Mock

securitySecurity

  • trompeloeil has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • trompeloeil code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
trompeloeil Security
Best in #Mock
Average in #Mock
trompeloeil Security
Best in #Mock
Average in #Mock

license License

  • trompeloeil is licensed under the BSL-1.0 License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
trompeloeil License
Best in #Mock
Average in #Mock
trompeloeil License
Best in #Mock
Average in #Mock

buildReuse

  • trompeloeil releases are available to install and integrate.
  • Installation instructions are not available. Examples and code snippets are available.
trompeloeil Reuse
Best in #Mock
Average in #Mock
trompeloeil Reuse
Best in #Mock
Average in #Mock
Top functions reviewed by kandi - BETA

kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample Here

Get all kandi verified functions for this library.

Get all kandi verified functions for this library.

trompeloeil Key Features

Header only C++14 mocking framework

trompeloeil Examples and Code Snippets

See all related Code Snippets

Teaser

copy iconCopydownload iconDownload
#include <trompeloeil.hpp>

class Interface
{
public:
  virtual ~Interface() = default;
  virtual bool foo(int, std::string& s) = 0;
  virtual bool bar(int) = 0;
  virtual bool bar(std::string) = 0;
};

void interface_func(Interface*); // function to test

class Mock : public Interface
{
public:
  MAKE_MOCK2(foo, bool(int, std::string&),override);
  MAKE_MOCK1(bar, bool(int),override);
  MAKE_MOCK1(bar, bool(std::string),override);
  MAKE_MOCK0(baz, void()); // not from Interface
};

TEST(exercise_interface_func)
{
  using trompeloeil::_;  // wild card for matching any value
  using trompeloeil::gt; // greater-than match

  Mock m;

  trompeloeil::sequence seq1, seq2;  // control order of matching calls

  int local_var = 0;

  REQUIRE_CALL(m, bar(ANY(int)))     // expect call to m.bar(int)
    .LR_SIDE_EFFECT(local_var = _1)  // set captured variable to value of param
    .RETURN(_1 > 0)                  // return value depending on param value
    .IN_SEQUENCE(seq1)               // must be first match for seq1
    .TIMES(AT_LEAST(1));             // can be called several times

  FORBID_CALL(m, bar(0));            // but m.bar(0) is not allowed

  REQUIRE_CALL(m, bar("word"))       // expect one call to m.bar(std::string)
    .RETURN(true)
    .IN_SEQUENCE(seq2);              // must be first match for seq2

  REQUIRE_CALL(m, foo(gt(2), _))     // expect call to foo(int,std::string&)
    .WITH(_2 == "")                  // with int > 2 and empty string
    .IN_SEQUENCE(seq1, seq2)         // last for both seq1 and seq2
    .SIDE_EFFECT(_2 = "cat")         // and set param string to "cat"
    .RETURN(true);

  interface_func(&m);

  // all the above expectations must be fulfilled here
}

Trompeloeil MAKE_MOCK0 with a template as a return type

copy iconCopydownload iconDownload
// Bad
MAKE_MOCK0(my_function, std::unordered_map<std::string, int>(), override);

// Good
MAKE_MOCK0(my_function, (std::unordered_map<std::string, int>()), override);
typedef std::unordered_map<std::string, int> My_Type;
...
MAKE_MOCK0(my_function, (My_Type()), override);
// Bad
MAKE_MOCK0(my_function, std::unordered_map<std::string, int>(), override);

// Good
MAKE_MOCK0(my_function, (std::unordered_map<std::string, int>()), override);
typedef std::unordered_map<std::string, int> My_Type;
...
MAKE_MOCK0(my_function, (My_Type()), override);

How to create a template for creating a test executable using catch2 with qt and trompeloeil?

copy iconCopydownload iconDownload
cmake_minimum_required(VERSION 3.12)
project(testing)
add_executable(testing ${sources})
#defining ${sources} later
set(sources a.cpp)
src/
|--lib/
|--tests/
|---- CMakeLists.txt
CMakeLists.txt
main.cpp
add_subdirectory(tests)
set(SOURCES
    ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp
    PARENT_SCOPE
)
add_executable(tests ${SOURCES})
cmake_minimum_required(VERSION 3.12)
project(testing)
add_executable(testing ${sources})
#defining ${sources} later
set(sources a.cpp)
src/
|--lib/
|--tests/
|---- CMakeLists.txt
CMakeLists.txt
main.cpp
add_subdirectory(tests)
set(SOURCES
    ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp
    PARENT_SCOPE
)
add_executable(tests ${SOURCES})
cmake_minimum_required(VERSION 3.12)
project(testing)
add_executable(testing ${sources})
#defining ${sources} later
set(sources a.cpp)
src/
|--lib/
|--tests/
|---- CMakeLists.txt
CMakeLists.txt
main.cpp
add_subdirectory(tests)
set(SOURCES
    ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp
    PARENT_SCOPE
)
add_executable(tests ${SOURCES})
cmake_minimum_required(VERSION 3.12)
project(testing)
add_executable(testing ${sources})
#defining ${sources} later
set(sources a.cpp)
src/
|--lib/
|--tests/
|---- CMakeLists.txt
CMakeLists.txt
main.cpp
add_subdirectory(tests)
set(SOURCES
    ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp
    PARENT_SCOPE
)
add_executable(tests ${SOURCES})
cmake_minimum_required(VERSION 3.12)
project(testing)
add_executable(testing ${sources})
#defining ${sources} later
set(sources a.cpp)
src/
|--lib/
|--tests/
|---- CMakeLists.txt
CMakeLists.txt
main.cpp
add_subdirectory(tests)
set(SOURCES
    ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp
    PARENT_SCOPE
)
add_executable(tests ${SOURCES})
add_executable(tests main.cpp)

...

# Later in the CMake file (or in another CMake file added via 'add_subdirectory').
target_sources(tests PRIVATE
    MyTestClass1.cpp
    MyTestClass2.cpp
    ...
)

See all related Code Snippets

Community Discussions

Trending Discussions on trompeloeil
  • Trompeloeil MAKE_MOCK0 with a template as a return type
  • How to create a template for creating a test executable using catch2 with qt and trompeloeil?
Trending Discussions on trompeloeil

QUESTION

Trompeloeil MAKE_MOCK0 with a template as a return type

Asked 2021-Mar-12 at 12:47

When using Trompeloeil to mock unit tests in C++, how can use an unordered_map as a return type?

// This example works fine
// return type is void, my_function takes no arguments 
MAKE_MOCK0(my_function, void(), override);


// This is what I'm trying to do but fails
MAKE_MOCK0(my_function, std::unordered_map<std::string, int>(), override);

Visual Studio is giving the following IntelliSense errors,

  • C2976 - std::unordered_map: too few template arguments
  • C2955 - std::unordered_map: use of class template requires template argument list
  • C2923 - trompeloeil::param_list: std::_Hash<_Traits::size> is not a valid template type argument for parameter type T
  • C2143 - syntax error missing > before ;
  • C2955 - trompeloeil::param_list use of class template requires template argument list
  • C2338 - function signature does not have 0 parameters
  • C3203 - unordered_map unspecialized class can't be used as a template argument for template parameter 'Sig', expected a real type
  • C4346 - std::unordered_map::type dependent name is not a type
  • C2923 - trompeloeil::identity_type: std::unordered_map::type is not a valid template type argument for parameter type T
  • C3203 - unordered_map unspecialized class can't be used as a template argument for template parameter 'T', expected a real type

ANSWER

Answered 2021-Jan-20 at 14:52

Templated return types need to be wrapped in (...). This is explained in: Q. Why can't I mock a function that returns a template?

// Bad
MAKE_MOCK0(my_function, std::unordered_map<std::string, int>(), override);

// Good
MAKE_MOCK0(my_function, (std::unordered_map<std::string, int>()), override);

The C++ preprocessor may have an issue parsing the template with multiple parameters std::string, int. If this occurs, moving the return type to a typedef can help. https://stackoverflow.com/a/38030161/2601293

typedef std::unordered_map<std::string, int> My_Type;
...
MAKE_MOCK0(my_function, (My_Type()), override);

Source https://stackoverflow.com/questions/65810026

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install trompeloeil

You can download it from GitHub.

Support

Also, follow up with the post on sequencing for examples on how to restrict or relax allowed sequences of matching calls.

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases
Explore Kits

Save this library and start creating your kit

Explore Related Topics

Share this Page

share link
Reuse Pre-built Kits with trompeloeil
Consider Popular Mock Libraries
Try Top Libraries by rollbear
Compare Mock Libraries with Highest Support
Compare Mock Libraries with Highest Quality
Compare Mock Libraries with Highest Security
Compare Mock Libraries with Permissive License
Compare Mock Libraries with Highest Reuse
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases
Explore Kits

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.