test parameters and mock objects

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

test parameters and mock objects

Samba - samba-technical mailing list
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

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: test parameters and mock objects

Samba - samba-technical mailing list
Hi Dimitris,

On Thu, 3 Aug 2017 19:33:04 +0300, Dimitris Gravanis via samba-technical wrote:

> 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?

test_err is a WERROR type. It's defined in werror.h - you shouldn't need
to mock it, but perhaps I'm misunderstanding your question.

Cheers, David

Loading...