Hello Michal
Are those functions in the same file? If so you need Bar to be a function pointer so you can override it.
Or, but Bar in its own C file and you can use the linker to override it.
James
--
You received this message because you are subscribed to the Google Groups "cpputest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cpputest+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
James Grenning
Author of Test-Driven Development for Embedded C
wingman-sw.com
wingman-sw.com/blog
@jwgrenning
facebook.com/wingman.sw
Cell: +1 847-630-0998
From your question, you must be very new to C. Here is a stack overflow on function pointers. You should be able to figure it out from this.
https://stackoverflow.com/questions/840501/how-do-function-pointers-in-c-work
in an h file:
extern int (*Bar)(void);
In the C file:
static int bar(void)
{
// the real implementation
}
int (*Bar)(void) = bar;
In the test file:
Thank you for the quick reply!The Bar() is in the same folder.Can you please provide an example?
--
extern int (*myDependency)(void);
int MyPublicFunction(int param1);
static int myDependency_impl(void)
{
return 5;
}
int (*myDependency)(void) = &myDependency_impl;
int MyPublicFunction(int param1)
{
return myDependency();
}
extern "C"
{
#include "..\my_header.h"
}
#include "CppUTest/TestHarness.h"
#include "CppUtestExt/MockSupport.h"
TEST_GROUP(MockTest)
{
void setup() {}
void teardown()
{
mock("MyMock").clear();
}
};
int myDependency_test(void)
{
return mock("MyMock")
.actualCall("myDependency")
.returnValue().getIntValue();
}
TEST(MockTest, FirstMockTest)
{
mock("MyMock")
.expectOneCall("myDependency")
.andReturnValue(10);
int (*myDependency)(void) = &myDependency_test;
int retval = MyPublicFunction(0);
mock("MyMock")
.checkExpectations();
}
static int FooImpl(void)
{
return 5;
}
void (*Foo)(void) = &FooImpl;
static int BarImpl(void)
{
return Foo();
}
void (*Bar)(void) = &BarImpl;
No worries. Sorry for my assumption.
--
You received this message because you are subscribed to the Google Groups "cpputest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cpputest+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
What recording was that?
--
You received this message because you are subscribed to the Google Groups "cpputest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cpputest+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You have access to the statics through the function pointer.
If a static cannot be tested through the compilation unit's public interface, you have a design problem.
Having to include the .c in a test is a good legacy code test technique, but it tells you the compilation unit has too much stuff in it.
--
You received this message because you are subscribed to the Google Groups "cpputest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cpputest+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You have access to the statics through the function pointer.
static int FooImpl(void)
{
return 5;
}
void (*Foo)(void) = &FooImpl;
int Bar(void)
{
// Do stuff dependent on Foo()
return return_value;
}
static int FooImpl(void)
{
return 5;
}
void (*Foo)(void) = &FooImpl;
FOO_P FooImpl_p(void){ return &FooImpl;}
typedef int (*FOO_P)(void);FOO_P FooImpl_p(void);
TEST_GROUP(Bar) {FOO_P savedFoo;setup() {savedFoo = foo;foo = testFoo;}teardown() {foo = savedFoo;}};TEST_GROUP(fooImpl) {};
--
You received this message because you are subscribed to the Google Groups "cpputest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cpputest+unsubscribe@googlegroups.com.
Note that your foo pointer should be declared returning int, not void.
FOO_P savedFoo;