-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathAssert.bt
61 lines (53 loc) · 1.7 KB
/
Assert.bt
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
// -*- mode: c;-*-
string EXSWarning(string reason){
local string out;
SPrintf(out, "%s: @ 0x%Lx\n", reason, FTell());
return out;
}
void EXWarning(string reason){
Printf("%s: @ 0x%Lx\n", reason, FTell());
}
void NLAssert(uint64 cond, string msg){
if( !cond ){
Printf("\n");
}
Assert(cond, msg);
};
// == NULL
void AssertUBytesNull( ubyte b[], string msg ){
local uint64 i;
local string omsg;
for( i = 0; i < sizeof(b); i++ ){
if( b[i] != 0x00 ){
SPrintf(omsg, "%d of %d was not null in %s", i, sizeof(b), msg);
NLAssert( b[i] != 0x00, EXSWarning(omsg));
}
}
};
// == ZERO
void AssertUIntGTZero( uint a, string msg ){
local string omsg;
SPrintf(omsg, "%s %d was less not greater than zero", msg, a);
NLAssert( a > 0, EXSWarning(omsg));
};
void AssertUIntGTEZero( uint subject, string msg ){
local string omsg;
SPrintf(omsg, "%s %d was less not greater than or equal to zero", msg, subject);
NLAssert( subject >= 0, EXSWarning(omsg));
};
// == EQUALITY
void AssertNumberEquals( uint subject, uint expectation, string msg ){
local string omsg;
SPrintf(omsg, "%s was %d which isn't %d", msg, subject, expectation);
NLAssert( subject == expectation, EXSWarning(omsg));
}
void AssertKnownEnum( string e, uint64 d, string msg ){
local string omsg;
SPrintf(omsg, "%s had an unknown value 0x%04LX", msg, d);
NLAssert( e != "", EXSWarning(omsg));
};
void AssertNumberInBetween( uint subject, uint min, uint max, string msg ){
local string omsg;
SPrintf(omsg, "%s was %d which isn't between %d and %d", msg, subject, min, max);
NLAssert( subject >= min && subject <= max, EXSWarning(omsg));
};