[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] cmocka: Allow to pass initial data to test cases
[Thread Prev] | [Thread Next]
- Subject: Re: [PATCH] cmocka: Allow to pass initial data to test cases
- From: Krzysztof Opasiak <k.opasiak@xxxxxxxxxxx>
- Date: Tue, 28 Jul 2015 10:38:25 +0200
- To: Pawel Szewczyk <p.szewczyk@xxxxxxxxxxx>, Andreas Schneider <asn@xxxxxxxxxxxxxx>
- Cc: cmocka@xxxxxxxxxxxxxx, Jakub Hrozek <jakub.hrozek@xxxxxxxxx>
Hello Andreas, On 07/01/2015 12:27 PM, Pawel Szewczyk wrote:
Hello On 07/01/2015 10:18 AM, Andreas Schneider wrote:You can still achieve that by creating a function you call at the beginning of the test which init's the state based on the function name or with a setup function. #define init_state(state) _init_state(state, __func__); void _init_state(void **state, const char *function) { if (strcmp(function, "mytest1") { *state = "my string"; } } void mytest1(**state) { init_state(state); do something; }
This is possible but you have to place init call in each test function. It is not possible to use this in test function or it require defining bunch of functions:
#define init_state(state) _init_state(state, __func__); void init_a(**state) { init_state(state) } void init_b(**state) { init_state(state) } void init_b(**state) { init_state(state) }I know that we can do this with macro but it is still bunch of rubbish which could be omitted if we add just one field in test case structure;)
The patch breaks the API. It would mean that all the projects using cmocka would break with a new release. I do not want to do that.I do not see how this breaks the API. All unit_test macros are not changed from user point of view. Even when you want to manually initialize CMUnitTest structure, initial_state field can be left uninitialized and nothing bad happens when you don't use new functionality.
I don't want to enforce this functionality but it is quite useful for us and I think that also other cmocka users will find it useful. In our project we could remove most of setup function and define different test states using one generic setup function and passing other initial data to it when defining a test cases.
Is there any chance for you to go through this patch once again and say how it breaks the API?
Best regards, -- Krzysztof Opasiak Samsung R&D Institute Poland Samsung Electronics
Re: [PATCH] cmocka: Allow to pass initial data to test cases | Andreas Schneider <asn@xxxxxxxxxxxxxx> |
Re: [PATCH] cmocka: Allow to pass initial data to test cases | Pawel Szewczyk <p.szewczyk@xxxxxxxxxxx> |