Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/tests/cdt/tevent.c
1810 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1999-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* *
19
***********************************************************************/
20
#include "dttest.h"
21
22
static int Event[8];
23
static int Index;
24
25
static int event(Dt_t* dt, int type, Void_t* obj, Dtdisc_t* disc)
26
{
27
if(Index >= sizeof(Event)/sizeof(Event[0]))
28
Index = 0;
29
Event[Index++] = type;
30
31
if(type == DT_HASHSIZE)
32
{ *(ssize_t*)obj = 1024;
33
return 1;
34
}
35
36
return 0;
37
}
38
39
static int chkevent(int type)
40
{
41
int i, cnt;
42
43
if(type < 0)
44
{ memset(Event, 0, sizeof(Event));
45
Index = 0;
46
return 0;
47
}
48
else
49
{ cnt = 0;
50
for(i = 0; i < sizeof(Event)/sizeof(Event[0]); ++i )
51
if(Event[i] == type)
52
cnt += 1;
53
return cnt;
54
}
55
}
56
57
static Void_t* memory(Dt_t* dt, Void_t* obj, size_t size, Dtdisc_t* disc)
58
{
59
if(!obj)
60
return malloc(size);
61
else
62
{ free(obj);
63
return NIL(Void_t*);
64
}
65
}
66
67
Dtdisc_t Disc =
68
{ 0, sizeof(long), -1,
69
newint, NIL(Dtfree_f), compare, hashint, memory, event
70
};
71
72
tmain()
73
{
74
Dt_t *dt;
75
long k;
76
77
chkevent(-1);
78
if(!(dt = dtopen(&Disc,Dtset)) )
79
terror("Opening Dtset");
80
if(chkevent(DT_OPEN) != 1 )
81
terror("Bad count of DT_OPEN event");
82
if(chkevent(DT_ENDOPEN) != 1 )
83
terror("Bad count of DT_ENDOPEN event");
84
85
dtinsert(dt, 1);
86
if(chkevent(DT_HASHSIZE) != 1 )
87
terror("No hash table size event");
88
89
chkevent(-1);
90
dtmethod(dt,Dtoset);
91
if(chkevent(DT_METH) < 1 )
92
terror("No meth event");
93
94
chkevent(-1);
95
dtdisc(dt,&Disc,0);
96
if(chkevent(DT_DISC) < 1 )
97
terror("No disc event");
98
99
chkevent(-1);
100
dtclose(dt);
101
if(chkevent(DT_CLOSE) != 1 )
102
terror("Bad count of DT_CLOSE event");
103
if(chkevent(DT_ENDCLOSE) != 1 )
104
terror("Bad count of DT_ENDCLOSE event");
105
106
texit(0);
107
}
108
109