[Spice-devel] [PATCH spice-server v6 02/10] test-sasl: Add code to mocking functions to test state

Christophe de Dinechin cdupontd at redhat.com
Tue Jan 9 09:23:03 UTC 2018


Oh. I’m not very awake this morning.
I don’t see how a test with G_DISABLE_ASSERT would make any sense…
Please ignore this one :-)

> On 9 Jan 2018, at 10:19, Christophe de Dinechin <christophe.de.dinechin at gmail.com> wrote:
> 
> 
> 
>> On 9 Jan 2018, at 08:44, Frediano Ziglio <fziglio at redhat.com> wrote:
>> 
>> Check some functions are called in a given sequence.
>> 
>> Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
>> ---
>> server/tests/test-sasl.c | 19 +++++++++++++++++++
>> 1 file changed, 19 insertions(+)
>> 
>> diff --git a/server/tests/test-sasl.c b/server/tests/test-sasl.c
>> index 0e4c633c..85332974 100644
>> --- a/server/tests/test-sasl.c
>> +++ b/server/tests/test-sasl.c
>> @@ -29,6 +29,10 @@
>> #include "basic-event-loop.h"
>> 
>> static char *mechlist;
> 
>> +static bool mechlist_called;
>> +static bool start_called;
>> +static bool step_called;
>> +static bool encode_called;
> 
> Variables are used only for assertions.
> What about putting declarations under #ifndef G_DISABLE_ASSERT?
> 
>> 
>> static void
>> check_sasl_conn(sasl_conn_t *conn)
>> @@ -49,6 +53,8 @@ sasl_decode(sasl_conn_t *conn,
>>            const char **output, unsigned *outputlen)
>> {
>>    check_sasl_conn(conn);
>> +    g_assert(start_called);
>> +
>>    return SASL_NOTDONE;
>> }
>> 
>> @@ -58,6 +64,9 @@ sasl_encode(sasl_conn_t *conn,
>>            const char **output, unsigned *outputlen)
>> {
>>    check_sasl_conn(conn);
>> +    g_assert(start_called);
>> +
>> +    encode_called = true;
> 
> Also #ifndef G_DISABLE_ASSERT.
> 
> Alternative is to use:
> 
> 	g_assert(encode_called = true);
> 
> but I’m afraid some readers might be surprised by this use of g_assert.
> 
>>    return SASL_NOTDONE;
>> }
>> 
>> @@ -139,6 +148,10 @@ sasl_listmech(sasl_conn_t *conn,
>>    g_assert_nonnull(prefix);
>>    g_assert_nonnull(sep);
>>    g_assert_nonnull(suffix);
>> +    g_assert(!mechlist_called);
>> +    g_assert(!start_called);
>> +    g_assert(!step_called);
>> +    mechlist_called = true;
>> 
>>    g_free(mechlist);
>>    mechlist = g_strjoin("", prefix, "ONE", sep, "TWO", sep, "THREE", suffix, NULL);
>> @@ -156,6 +169,10 @@ sasl_server_start(sasl_conn_t *conn,
>> {
>>    check_sasl_conn(conn);
>>    g_assert_nonnull(serverout);
>> +    g_assert(mechlist_called);
>> +    g_assert(!start_called);
>> +    g_assert(!step_called);
>> +    start_called = true;
>> 
>>    *serverout = "foo";
>>    *serveroutlen = 3;
>> @@ -171,6 +188,8 @@ sasl_server_step(sasl_conn_t *conn,
>> {
>>    check_sasl_conn(conn);
>>    g_assert_nonnull(serverout);
>> +    g_assert(start_called);
>> +    step_called = true;
>> 
>>    *serverout = "foo";
>>    *serveroutlen = 3;
>> -- 
>> 2.14.3
>> 
>> _______________________________________________
>> Spice-devel mailing list
>> Spice-devel at lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/spice-devel
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel



More information about the Spice-devel mailing list