/
test_arrow_device.c
70 lines (64 loc) · 2.57 KB
/
test_arrow_device.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
#include "unity.h"
#include <config.h>
#include <debug.h>
#include <arrow/gateway.h>
#include <arrow/device.h>
#include <sys/mem.h>
#include <data/static_buf.h>
#include <data/static_alloc.h>
#include <data/linkedlist.h>
#include <data/property.h>
#include <data/property_base.h>
#include <data/property_const.h>
#include <data/property_dynamic.h>
#include <data/property_stack.h>
#include <json/property_json.h>
#include <json/json.h>
#include <sb.h>
#include <encode.h>
#include <decode.h>
#include "mock_mac.h"
#define GATEWAY_UID GATEWAY_UID_PREFIX "-111213141516"
#define TEST_GATEWAY_HID "000TEST000"
#define DEVICE_UID GATEWAY_UID "-" DEVICE_UID_SUFFIX
static arrow_gateway_t _test_gateway;
static arrow_device_t _test_device;
static int test_count = 0;
void setUp(void) {
if ( !test_count ) property_types_init();
char mac[6] = {0x11, 0x12, 0x13, 0x14, 0x15, 0x16};
get_mac_address_ExpectAnyArgsAndReturn(0);
get_mac_address_ReturnArrayThruPtr_mac(mac, 6);
arrow_gateway_init(&_test_gateway);
arrow_prepare_gateway(&_test_gateway);
property_copy(&_test_gateway.hid, p_const(TEST_GATEWAY_HID));
}
void tearDown(void) {
if ( test_count == 2 ) property_types_deinit();
}
void test_device_init(void) {
test_count++;
arrow_device_init(&_test_device);
TEST_ASSERT_EQUAL_STRING(NULL, P_VALUE(_test_device.hid));
TEST_ASSERT_EQUAL_STRING(NULL, P_VALUE(_test_device.gateway_hid));
TEST_ASSERT_EQUAL_PTR(NULL, _test_device.info);
TEST_ASSERT_EQUAL_STRING(NULL, P_VALUE(_test_device.name));
TEST_ASSERT_EQUAL_PTR(NULL, _test_device.prop);
TEST_ASSERT_EQUAL_STRING(NULL, P_VALUE(_test_device.softwareName));
TEST_ASSERT_EQUAL_STRING(NULL, P_VALUE(_test_device.softwareVersion));
TEST_ASSERT_EQUAL_STRING(NULL, P_VALUE(_test_device.type));
TEST_ASSERT_EQUAL_STRING(NULL, P_VALUE(_test_device.uid));
}
void test_device_prepare( void ) {
test_count++;
arrow_prepare_device(&_test_gateway, &_test_device);
TEST_ASSERT_EQUAL_STRING(NULL, P_VALUE(_test_device.hid));
TEST_ASSERT_EQUAL_STRING(TEST_GATEWAY_HID, P_VALUE(_test_device.gateway_hid));
TEST_ASSERT_EQUAL_PTR(NULL, _test_device.info);
TEST_ASSERT_EQUAL_PTR(NULL, _test_device.prop);
TEST_ASSERT_EQUAL_STRING(DEVICE_NAME, P_VALUE(_test_device.name));
TEST_ASSERT_EQUAL_STRING(DEVICE_SOFTWARE_NAME, P_VALUE(_test_device.softwareName));
TEST_ASSERT_EQUAL_STRING(DEVICE_SOFTWARE_VERSION, P_VALUE(_test_device.softwareVersion));
TEST_ASSERT_EQUAL_STRING(DEVICE_TYPE, P_VALUE(_test_device.type));
TEST_ASSERT_EQUAL_STRING(DEVICE_UID, P_VALUE(_test_device.uid));
}