This repository was archived by the owner on Dec 13, 2020. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathuTestGitRecords.pas
149 lines (129 loc) · 6.22 KB
/
uTestGitRecords.pas
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
unit uTestGitRecords;
interface
uses
TestFramework, SysUtils, Windows;
type
TTestGitRecords = class(TTestCase)
procedureTest_sizes;
procedureTest_git_odb_backend;
procedureTest_git_time;
procedureTest_git_signature;
procedureTest_git_index_entry_unmerged;
procedureTest_git_config_file;
end;
implementation
uses
uGitForDelphi;
{ TTestGitRecordSizes }
procedureTTestGitRecords.Test_git_config_file;
functionoffsetof(constValue: string): Integer;
var
item: git_config_file;
begin
ifValue = 'cfg'then Result := Integer(@item.cfg) - Integer(@item)
elseifValue = 'open'then Result := Integer(@item.open) - Integer(@item)
elseifValue = 'get'then Result := Integer(@item.get) - Integer(@item)
elseifValue = 'set'then Result := Integer(@item.set_) - Integer(@item)
elseifValue = 'del'then Result := Integer(@item.del) - Integer(@item)
elseifValue = 'foreach'then Result := Integer(@item.foreach) - Integer(@item)
elseifValue = 'free'then Result := Integer(@item.free) - Integer(@item)
else raise Exception.CreateFmt('Unhandled condition (%0:s)', [Value]);
end;
begin
CheckEquals( 28, sizeof(git_config_file), 'git_config_file size');
CheckEquals( 0, offsetof('cfg'), 'cfg');
CheckEquals( 4, offsetof('open'), 'open');
CheckEquals( 8, offsetof('get'), 'get');
CheckEquals( 12, offsetof('set'), 'set');
CheckEquals( 16, offsetof('del'), 'del');
CheckEquals( 20, offsetof('foreach'), 'foreach');
CheckEquals( 24, offsetof('free'), 'free');
end;
procedureTTestGitRecords.Test_git_index_entry_unmerged;
functionoffsetof(constValue: string): Integer;
var
item: git_index_entry_unmerged;
begin
ifValue = 'mode'then Result := Integer(@item.mode) - Integer(@item)
elseifValue = 'oid'then Result := Integer(@item.oid) - Integer(@item)
elseifValue = 'path'then Result := Integer(@item.path) - Integer(@item)
else raise Exception.CreateFmt('Unhandled condition (%0:s)', [Value]);
end;
begin
CheckEquals( 76, sizeof(git_index_entry_unmerged), 'git_index_entry_unmerged size');
CheckEquals( 0, offsetof('mode'), 'mode');
CheckEquals( 12, offsetof('oid'), 'oid');
CheckEquals( 72, offsetof('path'), 'path');
end;
procedureTTestGitRecords.Test_git_odb_backend;
functionoffsetof(constValue: string): Integer;
var
item: git_odb_backend;
begin
ifValue = 'odb'then Result := Integer(@item.odb) - Integer(@item)
elseifValue = 'read'then Result := Integer(@item.read) - Integer(@item)
elseifValue = 'read_prefix'then Result := Integer(@item.read_prefix) - Integer(@item)
elseifValue = 'read_header'then Result := Integer(@item.read_header) - Integer(@item)
elseifValue = 'write'then Result := Integer(@item.write) - Integer(@item)
elseifValue = 'writestream'then Result := Integer(@item.writestream) - Integer(@item)
elseifValue = 'readstream'then Result := Integer(@item.readstream) - Integer(@item)
elseifValue = 'exists'then Result := Integer(@item.exists) - Integer(@item)
elseifValue = 'free'then Result := Integer(@item.free) - Integer(@item)
else raise Exception.CreateFmt('Unhandled condition (%0:s)', [Value]);
end;
begin
CheckEquals( 36, sizeof(git_odb_backend), 'git_odb_backend size');
CheckEquals( 0, offsetof('odb'), 'odb');
CheckEquals( 4, offsetof('read'), 'read');
CheckEquals( 8, offsetof('read_prefix'), 'read_prefix');
CheckEquals( 12, offsetof('read_header'), 'read_header');
CheckEquals( 16, offsetof('write'), 'write');
CheckEquals( 20, offsetof('writestream'), 'writestream');
CheckEquals( 24, offsetof('readstream'), 'readstream');
CheckEquals( 28, offsetof('exists'), 'exists');
CheckEquals( 32, offsetof('free'), 'free');
end;
procedureTTestGitRecords.Test_git_signature;
functionoffsetof(constValue: string): Integer;
var
item: git_signature;
begin
ifValue = 'name'then Result := Integer(@item.name) - Integer(@item)
elseifValue = 'email'then Result := Integer(@item.email) - Integer(@item)
elseifValue = 'when'then Result := Integer(@item.when) - Integer(@item)
else raise Exception.CreateFmt('Unhandled condition (%0:s)', [Value]);
end;
begin
CheckEquals( 24, sizeof(git_signature), 'git_signature size');
CheckEquals( 0, offsetof('name'), 'name');
CheckEquals( 4, offsetof('email'), 'email');
CheckEquals( 8, offsetof('when'), 'when');
end;
procedureTTestGitRecords.Test_git_time;
functionoffsetof(constValue: string): Integer;
var
item: git_time;
begin
ifValue = 'time'then Result := Integer(@item.time) - Integer(@item)
elseifValue = 'offset'then Result := Integer(@item.offset) - Integer(@item)
else raise Exception.CreateFmt('Unhandled condition (%0:s)', [Value]);
end;
begin
CheckEquals( 16, sizeof(git_time), 'git_time size');
CheckEquals( 0, offsetof('time'), 'time');
CheckEquals( 8, offsetof('offset'), 'offset');
end;
procedureTTestGitRecords.Test_sizes;
begin
CheckEquals( 4, sizeof(size_t), 'size_t');
CheckEquals( 8, sizeof(time_t), 'time_t');
CheckEquals( 8, sizeof(git_time_t), 'git_time_t');
CheckEquals( 8, sizeof(git_off_t), 'git_off_t');
CheckEquals( 4, sizeof(git_file), 'git_file');
CheckEquals( 20, sizeof(git_oid), 'git_oid');
CheckEquals( 16, sizeof(git_index_time), 'git_index_time');
CheckEquals( 96, sizeof(git_index_entry), 'git_index_entry');
end;
initialization
RegisterTest(TTestGitRecords.Suite);
end.