<update!> assert_in_set() for WERROR

Dimitris Gravanis dimgrav at gmail.com
Sat Aug 26 13:06:25 UTC 2017


On 26/08/2017 02:54 μμ, Dimitris Gravanis wrote:
>
> I want to check if a function returns one of the following WERROR 
> definitions:
>
> In werror_gen.h:
>
>   * |WERR_NERR_SUCCESS W_ERROR=0x0|
>   * |WERR_NOT_ENOUGH_MEMORY W_ERROR=0x8|
>   * |WERR_DNS_ERROR_RCODE_NOTAUTH W_ERROR=0x2331|
>   * |WERR_DNS_ERROR_RCODE_FORMAT_ERROR W_ERROR=0x2329|
>

After some more reading cmocka assertion macros and trial-and-error, my 
code for this is:

|    TALLOC_CTX *mem_ctx;||
||    DATA_BLOB *in_test = {NULL, SIZE_MAX};||
||    unsigned long werr_set[4];||
||    werr_set[0] = 0x0;||
||    werr_set[1] = 0x8;||
||    werr_set[2] = 0x2329;||
||    werr_set[3] = 0x2331;||
||||
||    struct dns_client *test_client;||
||    test_client->samdb = NULL;||
||    test_client->zones = NULL;||
||    test_client->tkeys = NULL;||
||    test_client->client_credentials = NULL;||
||    test_client->max_payload = UINT16_MAX;||
||||
||    struct dns_request_cli_state *test_state;||
||    test_state->flags = UINT16_MAX;||
||    test_state->authenticated = true;||
||    test_state->sign = true;||
||    test_state->key_name = "TKEY_NAME";||
||    test_state->tsig->name = "TSIG_RECORD";||
||    test_state->tsig->rr_type = DNS_QTYPE_TSIG;||
||    test_state->tsig->rr_class = DNS_QCLASS_ANY;||
||    test_state->tsig->ttl = 0;||
||    test_state->tsig->length = UINT16_MAX;||
||    test_state->tsig_error = UINT16_MAX;||
||||
||    struct dns_name_packet *test_packet;||
||    test_packet->id = UINT16_MAX;||
||    test_packet->qdcount = UINT16_MAX;||
||    test_packet->ancount = UINT16_MAX;||
||    test_packet->nscount = UINT16_MAX;||
||    test_packet->arcount = UINT16_MAX;||
||
||    /* test error codes */||
||*WERROR test_werr* = (unsigned long) 
dns_cli_generate_tsig(test_client, mem_ctx,||
||                                test_state, test_packet, in_test);||
||
||    assert_in_set(test_werr, werr_set, 4);

|Which obviously fails, due to type casting. How could I extract x from 
the W_ERROR(x) format to make it work in assert_in_set()?

assert_string_equal() probably won't do the trick as well, since WERROR 
is not of type const char.

This is the only build error I get when trying to incorporate the test 
suite in Samba builds right now, so any ideas would be immensely 
appreciated.

Cheers,
Dimitris

-- 
Δ. Γραβάνης | D. Gravanis



More information about the samba-technical mailing list