summaryrefslogtreecommitdiffstats
path: root/src/lib/gssapi/generic/maptest.c
blob: 566d88c316f15e7bb386fa5fa8cf25a8951585ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
#include <stdio.h>
#include <stdarg.h>
#include <assert.h>

typedef struct { int a, b; } elt;
static int eltcp(elt *dest, elt src)
{
    *dest = src;
    return 0;
}
static int eltcmp(elt left, elt right)
{
    if (left.a < right.a)
        return -1;
    if (left.a > right.a)
        return 1;
    if (left.b < right.b)
        return -1;
    if (left.b > right.b)
        return 1;
    return 0;
}
static void eltprt(elt v, FILE *f)
{
    fprintf(f, "{%d,%d}", v.a, v.b);
}
static int intcmp(int left, int right)
{
    if (left < right)
        return -1;
    if (left > right)
        return 1;
    return 0;
}
static void intprt(int v, FILE *f)
{
    fprintf(f, "%d", v);
}

#include "maptest.h"

foo foo1;

int main ()
{
    elt v1 = { 1, 2 }, v2 = { 3, 4 };
    const elt *vp;
    const int *ip;

    assert(0 == foo_init(&foo1));
    vp = foo_findleft(&foo1, 47);
    assert(vp == NULL);
    assert(0 == foo_add(&foo1, 47, v1));
    vp = foo_findleft(&foo1, 47);
    assert(vp != NULL);
    assert(0 == eltcmp(*vp, v1));
    vp = foo_findleft(&foo1, 3);
    assert(vp == NULL);
    assert(0 == foo_add(&foo1, 93, v2));
    ip = foo_findright(&foo1, v1);
    assert(ip != NULL);
    assert(*ip == 47);
    printf("Map content: ");
    foo_printmap(&foo1, stdout);
    printf("\n");
    return 0;
}