Comments (5)
I wasn't aware of these builtins, looks like perfect forwarding is possible after all. However I'm still not sure how you would use va_start
, va_arg
and va_end
to gather the variadic arguments in an array for inspection. It's up to each function to decide how many arguments should be provided, we can't figure out the number of arguments from the va_*
macros alone.
from narmock.
Just published a new version that incorporates the GCC builtins to forward the variadic arguments instead of ignoring them. This allows you to provide variadic stubs. For now the variadic arguments are not recorded in last_call
like the fixed arguments.
from narmock.
Nice additions!
I've outlined a rough sketch of how one could gather the variable arguments.
It requires a printf-like format string to specify the type of arguments to capture.
The arguments are then collected into a uint64_t array.
The user must then perform a cast when performing ASSERT_EQ.
main...Munken:varg-capture
This restricts the captured types to <= 64 bits. If this is too narrow then one could use a dummy struct instead.
Perhaps
struct narmock_vargs_capture_type {
uint64_t a,b,c,d;
};
from narmock.
Just revised the last idea a bit.
Instead of using uint64_t
and requiring a cast, I'm now using a union instead.
from narmock.
The idea of using a printf-like format string is interesting. Instead of parsing formatting syntax manually maybe it's worth considering just forwarding the arguments to vsnprintf()
to simply capture the arguments as a string in a static buffer. It would be pretty easy to implement but you would only be able to make assertions about the resulting string and not the individual arguments.
Of course your proposal looks pretty good but I just need to experiment a bit with it. I'm also thinking about something more structured:
int a;
int b;
int c;
MOCK(sum_variadic)
->mock_implementation(fake_sum_variadic1)
->capture_variadic()
->arg_int(&a)
->arg_int(&b)
->arg_int(&c);
sum_variadic(3, &value, 1, 2, 3);
ASSERT_EQ(a, 1);
ASSERT_EQ(b, 2);
ASSERT_EQ(c, 3);
I also wonder if instead of setting up a static variadic capture you could have something like capture_variadic_from_count_argument(0)
which would tell narmock the index of the fixed argument corresponding to the number of variadic arguments. Similarly something like capture_variadic_from_format_argument(0)
which would do the same but the specified argument index would correspond to a format string argument from which narmock would dynamically deduce the number and types of variadic arguments.
I'm gonna try to play with some of these concepts later.
from narmock.
Related Issues (10)
- Mocking a function taking void as its only argument does not work HOT 1
- Function declaration parsing fails HOT 2
- Suggestion: call_count as int HOT 1
- argument names in last_call HOT 7
- Reset all the mocks HOT 1
- mock_return_once() HOT 4
- Compiler error messages with and without function pointers in MOCK() HOT 1
- pycparser 2.21 breaks generation HOT 2
- mocking open fails HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from narmock.