-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathmocks.cpp
223 lines (197 loc) · 5.21 KB
/
mocks.cpp
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/*********************************************************************
* _ _ _
* _ __ | |_ _ | | __ _ | |__ ___
* | '__|| __|(_)| | / _` || '_ \ / __|
* | | | |_ _ | || (_| || |_) |\__ \
* |_| \__|(_)|_| \__,_||_.__/ |___/
*
* www.rt-labs.com
* Copyright 2017 rt-labs AB, Sweden.
*
* This software is dual-licensed under GPLv3 and a commercial
* license. See the file LICENSE.md distributed with this software for
* full license information.
********************************************************************/
#include "mocks.h"
#include <gtest/gtest.h>
#include <string.h>
os_tick_t mock_os_tick_current_result = 0;
os_tick_t mock_os_tick_current (void)
{
return mock_os_tick_current_result;
}
os_tick_t mock_os_tick_from_us (uint32_t us)
{
return us;
}
unsigned int mock_os_channel_send_calls = 0;
uint32_t mock_os_channel_send_id;
uint8_t mock_os_channel_send_data[8];
size_t mock_os_channel_send_dlc;
int mock_os_channel_send_result;
int mock_os_channel_send (
os_channel_t * channel,
uint32_t id,
const uint8_t * data,
size_t dlc)
{
(void)channel;
EXPECT_LE (dlc, 8u);
mock_os_channel_send_calls++;
mock_os_channel_send_id = id;
mock_os_channel_send_dlc = dlc;
memcpy (mock_os_channel_send_data, data, dlc);
return mock_os_channel_send_result;
}
unsigned int mock_os_channel_receive_calls = 0;
uint32_t mock_os_channel_receive_id;
uint8_t mock_os_channel_receive_data[8];
size_t mock_os_channel_receive_dlc;
int mock_os_channel_receive_result;
int mock_os_channel_receive (
os_channel_t * channel,
uint32_t * id,
uint8_t * data,
size_t * dlc,
int tmo)
{
(void)channel;
(void)tmo;
mock_os_channel_receive_calls++;
*id = mock_os_channel_receive_id;
*dlc = mock_os_channel_receive_dlc;
memcpy (data, mock_os_channel_receive_data, *dlc);
return mock_os_channel_receive_result;
}
unsigned int mock_os_channel_bus_off_calls = 0;
int mock_os_channel_bus_off (os_channel_t * channel)
{
mock_os_channel_bus_off_calls++;
return 0;
}
unsigned int mock_os_channel_bus_on_calls = 0;
int mock_os_channel_bus_on (os_channel_t * channel)
{
mock_os_channel_bus_on_calls++;
return 0;
}
unsigned int mock_os_channel_set_bitrate_calls = 0;
int mock_os_channel_set_bitrate_bitrate = 0;
int mock_os_channel_set_bitrate (os_channel_t * channel, int bitrate)
{
mock_os_channel_set_bitrate_calls++;
mock_os_channel_set_bitrate_bitrate = bitrate;
return 0;
}
unsigned int mock_os_channel_set_filter_calls = 0;
int mock_os_channel_set_filter_filter = 0;
int mock_os_channel_set_filter (os_channel_t * channel, int filter)
{
mock_os_channel_set_filter_calls++;
mock_os_channel_set_filter_filter = filter;
return 0;
}
unsigned int mock_os_channel_get_state_calls = 0;
os_channel_state_t mock_os_channel_get_state_state;
int mock_os_channel_get_state (os_channel_t * channel, os_channel_state * state)
{
mock_os_channel_get_state_calls++;
*state = mock_os_channel_get_state_state;
return 0;
}
const co_obj_t * mock_co_obj_find_result;
const co_obj_t * mock_co_obj_find (co_net_t * net, uint16_t index)
{
return mock_co_obj_find_result;
}
const co_entry_t * mock_co_entry_find_result;
const co_entry_t * mock_co_entry_find (co_net_t * net, co_obj_t * obj, uint8_t subindex)
{
return mock_co_entry_find_result;
}
unsigned int mock_co_od_reset_calls = 0;
void mock_co_od_reset (co_net_t * net)
{
mock_co_od_reset_calls++;
}
unsigned int mock_co_emcy_tx_calls = 0;
uint16_t mock_co_emcy_tx_code = 0;
void mock_co_emcy_tx (co_net_t * net, uint16_t code)
{
mock_co_emcy_tx_calls++;
mock_co_emcy_tx_code = code;
}
unsigned int cb_reset_calls;
void cb_reset (co_net_t * net)
{
cb_reset_calls++;
}
unsigned int cb_nmt_calls;
void cb_nmt (co_net_t * net, co_state_t state)
{
cb_nmt_calls++;
}
unsigned int cb_emcy_calls;
uint8_t cb_emcy_node;
uint16_t cb_emcy_code;
uint8_t cb_emcy_reg;
uint8_t cb_emcy_msef[5];
bool cb_emcy_result;
bool cb_emcy (co_net_t * net, uint8_t node, uint16_t code, uint8_t reg, uint8_t msef[5])
{
cb_emcy_calls++;
cb_emcy_node = node;
cb_emcy_code = code;
cb_emcy_reg = reg;
if (msef != NULL)
memcpy (cb_emcy_msef, msef, sizeof (cb_emcy_msef));
return cb_emcy_result;
}
unsigned int cb_sync_calls;
void cb_sync (co_net_t * net)
{
cb_sync_calls++;
}
unsigned int cb_notify_calls;
uint16_t cb_notify_index;
uint16_t cb_notify_subindex;
void cb_notify (co_net_t * net, uint16_t index, uint8_t subindex, od_notify_event_t event, uint32_t value)
{
cb_notify_calls++;
cb_notify_index = index;
cb_notify_subindex = subindex;
}
uint8_t the_store[2 * 1024];
struct fd
{
uint8_t * p;
} _fd;
void store_init (void)
{
memset (the_store, 0, sizeof (the_store));
}
unsigned int store_open_calls;
void * store_open (co_store_t store, co_mode_t mode)
{
store_open_calls++;
_fd.p = the_store;
return &_fd;
}
int store_read (void * arg, void * data, size_t size)
{
struct fd * fd = (struct fd *)arg;
memcpy (data, fd->p, size);
fd->p += size;
return 0;
}
int store_write (void * arg, const void * data, size_t size)
{
struct fd * fd = (struct fd *)arg;
memcpy (fd->p, data, size);
fd->p += size;
return 0;
}
int store_close (void * arg)
{
return 0;
}