aboutsummaryrefslogtreecommitdiff
path: root/drive-sdk/test/test_vehicle_advertisement.c
blob: c7ae3642838c575240c25c26187e23054b7868e0 (plain)
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
/*
 * Copyright (c) 2014 Anki, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stdio.h>
#include <stdlib.h>

#include "greatest.h"

#include "advertisement.h"
#include "adv_data.h"

SUITE(vehicle_advertisement);

TEST test_is_anki_vehicle(void) {
    int is_anki = 0;
    is_anki =  anki_vehicle_adv_record_has_anki_uuid(adv0_scan, sizeof(adv0_scan));
    ASSERT_EQ(is_anki, 1);

    is_anki =  anki_vehicle_adv_record_has_anki_uuid(adv1_scan, sizeof(adv1_scan));
    ASSERT_EQ(is_anki, 0);

    PASS();
}

TEST test_is_anki_vehicle_ignores_sensortag(void) {
    int is_anki = 0;
    is_anki =  anki_vehicle_adv_record_has_anki_uuid(st0_scan, sizeof(st0_scan));
    ASSERT_EQ(is_anki, 0);

    is_anki =  anki_vehicle_adv_record_has_anki_uuid(st1_scan, sizeof(st1_scan));
    ASSERT_EQ(is_anki, 0);

    PASS();
}

TEST test_anki_vehicle_parse_adv_record(void) {
    anki_vehicle_adv_t adv;

    // parse first packet
    uint8_t err = 0;
    err = anki_vehicle_parse_adv_record(adv0_scan, sizeof(adv0_scan), &adv);
    ASSERT_EQ(err, 0);

    err = anki_vehicle_parse_adv_record(adv1_scan, sizeof(adv1_scan), &adv);
    ASSERT_EQ(err, 0);

    PASS();
}

TEST test_vehicle_parse_mfg_data(void) {
    uint8_t data0[] = { 0xBE, 0xEF, 0x00, 0x01, 0x00, 0xE0, 0x0A, 0xA3 };
    anki_vehicle_adv_mfg_t mfg_data;
    int err = anki_vehicle_parse_mfg_data(data0, 8, &mfg_data);
    ASSERT_EQ(err, 0);

    ASSERT_EQ(mfg_data.product_id, 0xbeef);
    ASSERT_EQ(mfg_data.model_id, 0x01);
    ASSERT_EQ(mfg_data.identifier & 0xffff, 0x0aa3);

    PASS();
}

TEST test_vehicle_parse_local_name(void) {
    uint8_t data0[] = { 0x50, 0x20, 0x21, 0x01, 0x20, 0x20, 0x5A, 0x39, 0x41, 0x41, 0x33, 0x20, 0x54, 0x4F, 0x4D, 0x4D, 0x59, 0x00 };
    anki_vehicle_adv_info_t info;
    uint8_t err = anki_vehicle_parse_local_name(data0, sizeof(data0), &info);
    ASSERT_EQ(err, 0);
    ASSERT_EQ(info.state.full_battery, 1);
    ASSERT_EQ(info.state.low_battery, 0);
    ASSERT_EQ(info.state.on_charger, 1);
    ASSERT_EQ(info.version, 0x2120);
    ASSERT_STR_EQ((const char *)info.name, (const char *)&data0[8]);

    PASS();
}

GREATEST_SUITE(vehicle_advertisement) {
    RUN_TEST(test_is_anki_vehicle);
    RUN_TEST(test_is_anki_vehicle_ignores_sensortag);
    RUN_TEST(test_anki_vehicle_parse_adv_record);
    RUN_TEST(test_vehicle_parse_mfg_data);
    RUN_TEST(test_vehicle_parse_local_name);
}