Skip to content

Instantly share code, notes, and snippets.

@r7vme
Created January 25, 2021 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save r7vme/819ca1847f10142a53beaf2e1eef0c2b to your computer and use it in GitHub Desktop.
Save r7vme/819ca1847f10142a53beaf2e1eef0c2b to your computer and use it in GitHub Desktop.
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do
// this in one cpp file
#include <catch2/catch.hpp>
#include <fff/fff.h>
DEFINE_FFF_GLOBALS;
extern "C" {
// include our library header
#include "lib.h"
// define a fake function
FAKE_VALUE_FUNC(int, __wrap_get_nprocs_conf);
}
TEST_CASE("if more than one core then return true", "[is_multicore_system]")
{
// always reset globally-defined fff objects
// This is a limitation of pure-C fff, that it uses global objects.
RESET_FAKE(__wrap_get_nprocs_conf);
// if get_nprocs_conf will return 2
__wrap_get_nprocs_conf_fake.return_val = 2;
// then return true
REQUIRE(is_multicore_system() == true);
// also check that get_nprocs_conf was called once
REQUIRE(__wrap_get_nprocs_conf_fake.call_count == 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment