Back to index

opendkim  2.6.4
Defines | Functions | Variables
t-test49.c File Reference
#include "build-config.h"
#include <sys/types.h>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "../dkim.h"
#include "../dkim-cache.h"
#include "t-testdata.h"

Go to the source code of this file.

Defines

#define BUFRSZ   1024
#define QUERY   "Test Key"
#define DATA   "Cached Data"

Functions

int main (int argc, char **argv)

Variables

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

Define Documentation

#define BUFRSZ   1024

Definition at line 35 of file t-test49.c.

#define DATA   "Cached Data"

Definition at line 37 of file t-test49.c.

#define QUERY   "Test Key"

Definition at line 36 of file t-test49.c.


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 50 of file t-test49.c.

{
#ifndef QUERY_CACHE
       printf("*** query caching SKIPPED\n");

#else /* ! QUERY_CACHE */

       int status;
       int err;
       u_int s1, s2, s3;
       size_t buflen;
       DB *cache;
       char buf[BUFRSZ + 1];

       printf("*** query caching\n");

       cache = dkim_cache_init(NULL, NULL);

       err = 0;

       printf("--- empty cache\n");
       buflen = sizeof buf;
       status = dkim_cache_query(cache, QUERY, 0, buf, &buflen, &err);
       assert(err == 0);
       assert(status == 1);

       printf("--- insert record\n");
       status = dkim_cache_insert(cache, QUERY, DATA, 3, &err);
       assert(err == 0);
       assert(status == 0);

       printf("--- retrieve record\n");
       memset(buf, '\0', sizeof buf);
       buflen = sizeof buf;
       status = dkim_cache_query(cache, QUERY, 0, buf, &buflen, &err);
       assert(err == 0);
       assert(status == 0);
       assert(buflen == strlen(DATA));
       assert(strcmp(buf, DATA) == 0);

       printf("--- [pause for record to expire]\n");
       sleep(4);

       printf("--- retrieve expired record\n");
       buflen = sizeof buf;
       status = dkim_cache_query(cache, QUERY, 0, buf, &buflen, &err);
       assert(err == 0);
       assert(status == 1);

       printf("--- expire old records\n");
       status = dkim_cache_expire(cache, 3, &err);
       assert(err == 0);
       assert(status == 1);

       printf("--- retrieve cache stats\n");
       dkim_cache_stats(&s1, &s2, &s3);
       assert(s1 == 3);
       assert(s2 == 1);
       assert(s3 == 1);

       dkim_cache_close(cache);
#endif /* ! QUERY_CACHE */

       return 0;
}

Variable Documentation

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

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