test parameters and mock objects

Dimitris Gravanis dimgrav at gmail.com
Thu Aug 3 16:33:04 UTC 2017


Hello!

The following code is from a test I'm writing for the function 
dns_cli_generate_sig(params), which is located in another .c file.

|static int gen_tsig_test(void **state)||
||{||
||    /* incomplete declarations */||
||    TALLOC_CTX *mem_ctx;||
||    DATA_BLOB in_test = (DATA_BLOB) {.data = NULL, .length = SIZE_MAX};||
||    struct dns_client *test_client;||
||    struct dns_request_state *test_state;||
||    struct dns_name_packet *test_packet;||
||
||    /* test error codes */||
||    WERROR test_err = dns_cli_generate_tsig(test_client, mem_ctx,||
||                                    test_state, test_packet, in_test);||
|

|    int err;
     switch (test_err) {
         case WERR_OK:
             return 0;
         case WERR_NOT_ENOUGH_MEMORY:
             err = -1;
             fprintf(stderr, "WERR_NOMEM: %s\n", strerror(err));
             return err;
         case DNS_ERR(FORMAT_ERROR):
         case DNS_ERR(NOTAUTH):
             err = -2;
             fprintf(stderr, "DNS_ERR: %s\n", strerror(err));
             return err;
         default:
             err = -3;
             fprintf(stderr, "Unexpected ERROR: %s\n", strerror(err));
             return err;
     };

     TALLOC_FREE(mem_ctx);|

|}
|

How would I initialize the parameters that are used in test_err? If mock 
objects are needed (or could be used instead), could you provide me with 
an example?

Cheers,

Dimitris



More information about the samba-technical mailing list