Path: blob/main/crypto/krb5/src/lib/gssapi/generic/maptest.c
39562 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1#include <stdio.h>2#include <stdarg.h>3#include <assert.h>45typedef struct { int a, b; } elt;6static int eltcp(elt *dest, elt src)7{8*dest = src;9return 0;10}11static int eltcmp(elt left, elt right)12{13if (left.a < right.a)14return -1;15if (left.a > right.a)16return 1;17if (left.b < right.b)18return -1;19if (left.b > right.b)20return 1;21return 0;22}23static void eltprt(elt v, FILE *f)24{25fprintf(f, "{%d,%d}", v.a, v.b);26}27static int intcmp(int left, int right)28{29if (left < right)30return -1;31if (left > right)32return 1;33return 0;34}35static void intprt(int v, FILE *f)36{37fprintf(f, "%d", v);38}3940#include "maptest.h"4142foo foo1;4344int main (void)45{46elt v1 = { 1, 2 }, v2 = { 3, 4 };47const elt *vp;48const int *ip;4950assert(0 == foo_init(&foo1));51vp = foo_findleft(&foo1, 47);52assert(vp == NULL);53assert(0 == foo_add(&foo1, 47, v1));54vp = foo_findleft(&foo1, 47);55assert(vp != NULL);56assert(0 == eltcmp(*vp, v1));57vp = foo_findleft(&foo1, 3);58assert(vp == NULL);59assert(0 == foo_add(&foo1, 93, v2));60ip = foo_findright(&foo1, v1);61assert(ip != NULL);62assert(*ip == 47);63printf("Map content: ");64foo_printmap(&foo1, stdout);65printf("\n");66return 0;67}686970