-
Notifications
You must be signed in to change notification settings - Fork 37
/
Atom-test.c
89 lines (69 loc) · 2.19 KB
/
Atom-test.c
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Atom-test.c
// unit tests
#include <assert.h>
#include <inttypes.h>
#include <string.h>
#include "UnitTest.h"
#include "Atom.h"
////////////////////////////////////////////////////////////////////////////////
// testLength
////////////////////////////////////////////////////////////////////////////////
static void testLength()
{
int valueA = 123;
Atom_T a = Atom_new((char *) &valueA, sizeof(valueA));
EXPECT_EQ_UNSIGNED(4, Atom_length(a));
Atom_T b = Atom_newFromString("abc");
EXPECT_EQ_UNSIGNED(3, Atom_length(b));
Atom_T c = Atom_newFromInt64(123);
EXPECT_EQ_UNSIGNED(8, Atom_length(c));
}
////////////////////////////////////////////////////////////////////////////////
// testNew
////////////////////////////////////////////////////////////////////////////////
static void testNew()
{
int valueA = 123;
Atom_T a = Atom_new((char *) &valueA, sizeof(valueA));
EXPECT_NOT_NULL(a);
Atom_T b = Atom_newFromString("abc");
EXPECT_NOT_NULL(b);
Atom_T c = Atom_newFromInt64(123);
EXPECT_NOT_NULL(c);
}
////////////////////////////////////////////////////////////////////////////////
// testStr
////////////////////////////////////////////////////////////////////////////////
static void testStr()
{
int valueA = 123;
Atom_T a = Atom_new((char *) &valueA, sizeof(valueA));
char *strA = Atom_str(a);
EXPECT_EQ_UNSIGNED(1, strlen(strA)); //*strA = [123][0] ...
EXPECT_EQ_UNSIGNED(123, strA[0]);
EXPECT_EQ_UNSIGNED(0, strA[1]); // assume little endian machine
EXPECT_EQ_UNSIGNED(0, strA[2]);
EXPECT_EQ_UNSIGNED(0, strA[3]);
EXPECT_EQ_UNSIGNED(0, strA[4]);
Atom_T b = Atom_newFromString("abc");
char *strB = Atom_str(b);
EXPECT_EQ_UNSIGNED(3, Atom_length(b));
EXPECT_EQ_STR("abc", strB);
Atom_T c = Atom_newFromInt64(123);
char *strC = Atom_str(c);
EXPECT_EQ_UNSIGNED(1, strlen(strC));
EXPECT_EQ_UNSIGNED(123, strC[0]);
EXPECT_EQ_UNSIGNED(0, strC[1]);
EXPECT_EQ_UNSIGNED(0, strC[8]);
}
////////////////////////////////////////////////////////////////////////////////
// main
////////////////////////////////////////////////////////////////////////////////
int
main(int argc, char **argv)
{
testLength();
testNew();
testStr();
UnitTest_report();
}