Back to index

opendkim  2.6.4
Defines | Functions | Variables
t-test113.c File Reference
#include "build-config.h"
#include <sys/types.h>
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include "../dkim-internal.h"
#include "../dkim-util.h"

Go to the source code of this file.

Defines

#define TESTBUFRSZ   4096
#define TESTJOBID   "x"
#define TESTSTRING   "Hello, world!\n"

Functions

int main (int argc, char **argv)

Variables

static char t_test113_c_id [] = "@(#)$Id: t-test113.c,v 1.2 2009/12/08 19:14:27 cm-msk Exp $"

Define Documentation

#define TESTBUFRSZ   4096

Definition at line 28 of file t-test113.c.

#define TESTJOBID   "x"

Definition at line 29 of file t-test113.c.

#define TESTSTRING   "Hello, world!\n"

Definition at line 30 of file t-test113.c.


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 43 of file t-test113.c.

{
       int c;
       DKIM_STAT status;
       DKIM_LIB *lib;
       DKIM *dkim;
       struct dkim_dstring *dstring;
       char *p;
       char testbuf[TESTBUFRSZ + 1];

       printf("*** exercise dstring functions\n");

#ifdef USE_GNUTLS
       (void) gnutls_global_init();
#endif /* USE_GNUTLS */

       /* instantiate the library */
       lib = dkim_init(NULL, NULL);
       assert(lib != NULL);
       dkim = dkim_verify(lib, TESTJOBID, NULL, &status);
       assert(dkim != NULL);

       /* make a dstring */
       dstring = dkim_dstring_new(dkim, 0, 0);
       assert(dstring != NULL);

       /* confirm that it's empty */
       assert(dkim_dstring_len(dstring) == 0);
       p = dkim_dstring_get(dstring);
       assert(p != NULL);
       assert(p[0] == '\0');

       /* put something in it */
       for (c = 0; c < sizeof testbuf; c++)
              testbuf[c] = (random() % 94) + 32;
       testbuf[sizeof testbuf - 1] = '\0';
       assert(dkim_dstring_copy(dstring, testbuf));
       assert(dkim_dstring_len(dstring) == sizeof testbuf - 1);
       p = dkim_dstring_get(dstring);
       assert(p != NULL);
       assert(strlen(p) == sizeof testbuf - 1);
       assert(strcmp(p, testbuf) == 0);

       /* blank it */
       dkim_dstring_blank(dstring);
       p = dkim_dstring_get(dstring);
       assert(p != NULL);
       assert(p[0] == '\0');

       /* put something small in it using "cat" */
       assert(dkim_dstring_cat(dstring, TESTSTRING));
       p = dkim_dstring_get(dstring);
       assert(p != NULL);
       assert(strcmp(p, TESTSTRING) == 0);
       assert(dkim_dstring_cat(dstring, TESTSTRING));
       p = dkim_dstring_get(dstring);
       assert(p != NULL);
       assert(strcmp(p, TESTSTRING TESTSTRING) == 0);

       /* try cat1 */
       dkim_dstring_blank(dstring);
       assert(dkim_dstring_cat1(dstring, 'H'));
       assert(dkim_dstring_len(dstring) == 1);
       p = dkim_dstring_get(dstring);
       assert(p != NULL);
       assert(strcmp(p, "H") == 0);

       /* try catn */
       dkim_dstring_blank(dstring);
       assert(dkim_dstring_catn(dstring, TESTSTRING, 5));
       assert(dkim_dstring_len(dstring) == 5);
       p = dkim_dstring_get(dstring);
       assert(p != NULL);
       assert(strcmp(p, "Hello") == 0);

       /* start over */
       dkim_dstring_free(dstring);
       dstring = dkim_dstring_new(dkim, 0, (sizeof testbuf) / 2);
       assert(dstring != NULL);

       /* try an oversized append */
       assert(!dkim_dstring_copy(dstring, testbuf));

       /* clean up */
       dkim_dstring_free(dstring);
       dkim_free(dkim);
       dkim_close(lib);

       return 0;
}

Here is the call graph for this function:


Variable Documentation

char t_test113_c_id[] = "@(#)$Id: t-test113.c,v 1.2 2009/12/08 19:14:27 cm-msk Exp $" [static]

Definition at line 9 of file t-test113.c.