aboutsummaryrefslogtreecommitdiff
path: root/drive-sdk/test
diff options
context:
space:
mode:
Diffstat (limited to 'drive-sdk/test')
-rw-r--r--drive-sdk/test/CMakeLists.txt18
-rw-r--r--drive-sdk/test/adv_data.h39
-rw-r--r--drive-sdk/test/anki_greatest.h54
-rw-r--r--drive-sdk/test/greatest.h591
-rw-r--r--drive-sdk/test/test_ble_advertisement.c75
-rw-r--r--drive-sdk/test/test_protocol.c243
-rw-r--r--drive-sdk/test/test_suite.c36
-rw-r--r--drive-sdk/test/test_vehicle_advertisement.c96
8 files changed, 1152 insertions, 0 deletions
diff --git a/drive-sdk/test/CMakeLists.txt b/drive-sdk/test/CMakeLists.txt
new file mode 100644
index 0000000..d1e1534
--- /dev/null
+++ b/drive-sdk/test/CMakeLists.txt
@@ -0,0 +1,18 @@
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+include_directories(${drivekit_SOURCE_DIR}/src
+ )
+
+# Add sources
+set(test_SOURCES greatest.h
+ anki_greatest.h
+ test_suite.c
+ test_ble_advertisement.c
+ test_vehicle_advertisement.c
+ test_protocol.c
+)
+
+add_executable(Test ${test_SOURCES})
+target_link_libraries(Test
+ ankidrive
+ )
diff --git a/drive-sdk/test/adv_data.h b/drive-sdk/test/adv_data.h
new file mode 100644
index 0000000..c5581be
--- /dev/null
+++ b/drive-sdk/test/adv_data.h
@@ -0,0 +1,39 @@
+/*
+ * 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.
+ */
+
+#ifndef ADV_DATA_H
+#define ADV_DATA_H
+
+// scan data from Anki Drive vehicles
+static uint8_t adv0_scan[] = {
+ 0x02, 0x01, 0x06,
+ 0x11, 0x07, 0xF4, 0x8D, 0x4D, 0x9C, 0xD8, 0x0B, 0x81, 0x83, 0x7E, 0x40, 0x86, 0x61, 0xEF, 0xBE, 0x15, 0xBE,
+ 0x09, 0xFF, 0xBE, 0xEF, 0x00, 0x01, 0x00, 0xE0, 0x0A, 0xA3
+};
+static uint8_t adv1_scan[] = {
+ 0x13, 0x09, 0x50, 0x20, 0x21, 0x01, 0x20, 0x20, 0x5A, 0x39, 0x41, 0x41, 0x33, 0x20, 0x54, 0x4F, 0x4D, 0x4D, 0x59, 0x00,
+ 0x02, 0x0A, 0x00
+};
+
+// scan data from Ti SensorTag
+static uint8_t st0_scan[] = { 0x02, 0x01, 0x05 };
+static uint8_t st1_scan[] = {
+ 0x0A, 0x09, 0x53, 0x65, 0x6E, 0x73, 0x6F, 0x72, 0x54, 0x61, 0x67,
+ 0x05, 0x12, 0x50, 0x00, 0x20, 0x03,
+ 0x02, 0x0A, 0x00
+};
+
+#endif // ADV_DATA_H
diff --git a/drive-sdk/test/anki_greatest.h b/drive-sdk/test/anki_greatest.h
new file mode 100644
index 0000000..2d39a2b
--- /dev/null
+++ b/drive-sdk/test/anki_greatest.h
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ */
+
+#ifndef INCLUDE_anki_greatest_h__
+#define INCLUDE_anki_greatest_h__
+
+#define ANKI_GREATEST_HEX_DUMP(buffer, len) \
+ do { \
+ const uint8_t *b = (const uint8_t *)buffer; \
+ int i; \
+ for (i = 0; i < (len); ++i) { \
+ fprintf(GREATEST_STDOUT, "%02x ", b[i]); \
+ } \
+ } while(0)
+
+#define ANKI_GREATEST_ASSERT_BYTES_EQm(MSG, EXP, GOT, LEN) \
+ do { \
+ const void *exp_s = (const void *)(EXP); \
+ const void *got_s = (const void *)(GOT); \
+ const size_t len_s = (const size_t)(LEN); \
+ greatest_info.msg = MSG; \
+ greatest_info.fail_file = __FILE__; \
+ greatest_info.fail_line = __LINE__; \
+ if (0 != memcmp(exp_s, got_s, len_s)) { \
+ fprintf(GREATEST_STDOUT, "Expected:\n####\n"); \
+ ANKI_GREATEST_HEX_DUMP(exp_s, len_s); \
+ fprintf(GREATEST_STDOUT, "\n####\n"); \
+ fprintf(GREATEST_STDOUT, "Got:\n####\n"); \
+ ANKI_GREATEST_HEX_DUMP(got_s, len_s); \
+ fprintf(GREATEST_STDOUT, "\n####\n"); \
+ return -1; \
+ } \
+ greatest_info.msg = NULL; \
+ } while (0)
+
+#define ANKI_GREATEST_ASSERT_BYTES_EQ(EXP, GOT, LEN) ANKI_GREATEST_ASSERT_BYTES_EQm(#EXP " != " #GOT, EXP, GOT, LEN)
+
+#define ASSERT_BYTES_EQm(MSG, EXP, GOT, LEN) ANKI_GREATEST_ASSERT_BYTES_EQm(MSG, EXP, GOT, LEN)
+#define ASSERT_BYTES_EQ(EXP, GOT, LEN) ANKI_GREATEST_ASSERT_BYTES_EQ(EXP, GOT, LEN)
+
+#endif
diff --git a/drive-sdk/test/greatest.h b/drive-sdk/test/greatest.h
new file mode 100644
index 0000000..a92c642
--- /dev/null
+++ b/drive-sdk/test/greatest.h
@@ -0,0 +1,591 @@
+/*
+ * Copyright (c) 2011 Scott Vokes <vokes.s@gmail.com>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef GREATEST_H
+#define GREATEST_H
+
+#define GREATEST_VERSION_MAJOR 0
+#define GREATEST_VERSION_MINOR 9
+#define GREATEST_VERSION_PATCH 3
+
+/* A unit testing system for C, contained in 1 file.
+ * It doesn't use dynamic allocation or depend on anything
+ * beyond ANSI C89. */
+
+
+/*********************************************************************
+ * Minimal test runner template
+ *********************************************************************/
+#if 0
+
+#include "greatest.h"
+
+TEST foo_should_foo() {
+ PASS();
+}
+
+static void setup_cb(void *data) {
+ printf("setup callback for each test case\n");
+}
+
+static void teardown_cb(void *data) {
+ printf("teardown callback for each test case\n");
+}
+
+SUITE(suite) {
+ /* Optional setup/teardown callbacks which will be run before/after
+ * every test case in the suite.
+ * Cleared when the suite finishes. */
+ SET_SETUP(setup_cb, voidp_to_callback_data);
+ SET_TEARDOWN(teardown_cb, voidp_to_callback_data);
+
+ RUN_TEST(foo_should_foo);
+}
+
+/* Add all the definitions that need to be in the test runner's main file. */
+GREATEST_MAIN_DEFS();
+
+int main(int argc, char **argv) {
+ GREATEST_MAIN_BEGIN(); /* command-line arguments, initialization. */
+ RUN_SUITE(suite);
+ GREATEST_MAIN_END(); /* display results */
+}
+
+#endif
+/*********************************************************************/
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+
+
+/***********
+ * Options *
+ ***********/
+
+/* Default column width for non-verbose output. */
+#ifndef GREATEST_DEFAULT_WIDTH
+#define GREATEST_DEFAULT_WIDTH 72
+#endif
+
+/* FILE *, for test logging. */
+#ifndef GREATEST_STDOUT
+#define GREATEST_STDOUT stdout
+#endif
+
+/* Remove GREATEST_ prefix from most commonly used symbols? */
+#ifndef GREATEST_USE_ABBREVS
+#define GREATEST_USE_ABBREVS 1
+#endif
+
+
+/*********
+ * Types *
+ *********/
+
+/* Info for the current running suite. */
+typedef struct greatest_suite_info {
+ unsigned int tests_run;
+ unsigned int passed;
+ unsigned int failed;
+ unsigned int skipped;
+
+ /* timers, pre/post running suite and individual tests */
+ clock_t pre_suite;
+ clock_t post_suite;
+ clock_t pre_test;
+ clock_t post_test;
+} greatest_suite_info;
+
+/* Type for a suite function. */
+typedef void (greatest_suite_cb)(void);
+
+/* Types for setup/teardown callbacks. If non-NULL, these will be run
+ * and passed the pointer to their additional data. */
+typedef void (greatest_setup_cb)(void *udata);
+typedef void (greatest_teardown_cb)(void *udata);
+
+typedef enum {
+ GREATEST_FLAG_VERBOSE = 0x01,
+ GREATEST_FLAG_FIRST_FAIL = 0x02,
+ GREATEST_FLAG_LIST_ONLY = 0x04
+} GREATEST_FLAG;
+
+typedef struct greatest_run_info {
+ unsigned int flags;
+ unsigned int tests_run; /* total test count */
+
+ /* Overall pass/fail/skip counts. */
+ unsigned int passed;
+ unsigned int failed;
+ unsigned int skipped;
+
+ /* currently running test suite */
+ greatest_suite_info suite;
+
+ /* info to print about the most recent failure */
+ const char *fail_file;
+ unsigned int fail_line;
+ const char *msg;
+
+ /* current setup/teardown hooks and userdata */
+ greatest_setup_cb *setup;
+ void *setup_udata;
+ greatest_teardown_cb *teardown;
+ void *teardown_udata;
+
+ /* formatting info for ".....s...F"-style output */
+ unsigned int col;
+ unsigned int width;
+
+ /* only run a specific suite or test */
+ char *suite_filter;
+ char *test_filter;
+
+ /* overall timers */
+ clock_t begin;
+ clock_t end;
+} greatest_run_info;
+
+/* Global var for the current testing context.
+ * Initialized by GREATEST_MAIN_DEFS(). */
+extern greatest_run_info greatest_info;
+
+
+/**********************
+ * Exported functions *
+ **********************/
+
+void greatest_do_pass(const char *name);
+void greatest_do_fail(const char *name);
+void greatest_do_skip(const char *name);
+int greatest_pre_test(const char *name);
+void greatest_post_test(const char *name, int res);
+void greatest_usage(const char *name);
+void GREATEST_SET_SETUP_CB(greatest_setup_cb *cb, void *udata);
+void GREATEST_SET_TEARDOWN_CB(greatest_teardown_cb *cb, void *udata);
+
+
+/**********
+ * Macros *
+ **********/
+
+/* Define a suite. */
+#define GREATEST_SUITE(NAME) void NAME(void)
+
+/* Start defining a test function.
+ * The arguments are not included, to allow parametric testing. */
+#define GREATEST_TEST static int
+
+/* Run a suite. */
+#define GREATEST_RUN_SUITE(S_NAME) greatest_run_suite(S_NAME, #S_NAME)
+
+/* Run a test in the current suite. */
+#define GREATEST_RUN_TEST(TEST) \
+ do { \
+ if (greatest_pre_test(#TEST) == 1) { \
+ int res = TEST(); \
+ greatest_post_test(#TEST, res); \
+ } else if (GREATEST_LIST_ONLY()) { \
+ fprintf(GREATEST_STDOUT, " %s\n", #TEST); \
+ } \
+ } while (0)
+
+/* Run a test in the current suite with one void* argument,
+ * which can be a pointer to a struct with multiple arguments. */
+#define GREATEST_RUN_TEST1(TEST, ENV) \
+ do { \
+ if (greatest_pre_test(#TEST) == 1) { \
+ int res = TEST(ENV); \
+ greatest_post_test(#TEST, res); \
+ } else if (GREATEST_LIST_ONLY()) { \
+ fprintf(GREATEST_STDOUT, " %s\n", #TEST); \
+ } \
+ } while (0)
+
+/* If __VA_ARGS__ (C99) is supported, allow parametric testing
+ * without needing to manually manage the argument struct. */
+#if __STDC_VERSION__ >= 19901L
+#define GREATEST_RUN_TESTp(TEST, ...) \
+ do { \
+ if (greatest_pre_test(#TEST) == 1) { \
+ int res = TEST(__VA_ARGS__); \
+ greatest_post_test(#TEST, res); \
+ } else if (GREATEST_LIST_ONLY()) { \
+ fprintf(GREATEST_STDOUT, " %s\n", #TEST); \
+ } \
+ } while (0)
+#endif
+
+
+/* Check if the test runner is in verbose mode. */
+#define GREATEST_IS_VERBOSE() (greatest_info.flags & GREATEST_FLAG_VERBOSE)
+#define GREATEST_LIST_ONLY() (greatest_info.flags & GREATEST_FLAG_LIST_ONLY)
+#define GREATEST_FIRST_FAIL() (greatest_info.flags & GREATEST_FLAG_FIRST_FAIL)
+#define GREATEST_FAILURE_ABORT() (greatest_info.suite.failed > 0 && GREATEST_FIRST_FAIL())
+
+/* Message-less forms. */
+#define GREATEST_PASS() GREATEST_PASSm(NULL)
+#define GREATEST_FAIL() GREATEST_FAILm(NULL)
+#define GREATEST_SKIP() GREATEST_SKIPm(NULL)
+#define GREATEST_ASSERT(COND) GREATEST_ASSERTm(#COND, COND)
+#define GREATEST_ASSERT_FALSE(COND) GREATEST_ASSERT_FALSEm(#COND, COND)
+#define GREATEST_ASSERT_EQ(EXP, GOT) GREATEST_ASSERT_EQm(#EXP " != " #GOT, EXP, GOT)
+#define GREATEST_ASSERT_STR_EQ(EXP, GOT) GREATEST_ASSERT_STR_EQm(#EXP " != " #GOT, EXP, GOT)
+
+/* The following forms take an additional message argument first,
+ * to be displayed by the test runner. */
+
+/* Fail if a condition is not true, with message. */
+#define GREATEST_ASSERTm(MSG, COND) \
+ do { \
+ greatest_info.msg = MSG; \
+ greatest_info.fail_file = __FILE__; \
+ greatest_info.fail_line = __LINE__; \
+ if (!(COND)) return -1; \
+ greatest_info.msg = NULL; \
+ } while (0)
+
+#define GREATEST_ASSERT_FALSEm(MSG, COND) \
+ do { \
+ greatest_info.msg = MSG; \
+ greatest_info.fail_file = __FILE__; \
+ greatest_info.fail_line = __LINE__; \
+ if ((COND)) return -1; \
+ greatest_info.msg = NULL; \
+ } while (0)
+
+#define GREATEST_ASSERT_EQm(MSG, EXP, GOT) \
+ do { \
+ greatest_info.msg = MSG; \
+ greatest_info.fail_file = __FILE__; \
+ greatest_info.fail_line = __LINE__; \
+ if ((EXP) != (GOT)) return -1; \
+ greatest_info.msg = NULL; \
+ } while (0)
+
+#define GREATEST_ASSERT_STR_EQm(MSG, EXP, GOT) \
+ do { \
+ const char *exp_s = (EXP); \
+ const char *got_s = (GOT); \
+ greatest_info.msg = MSG; \
+ greatest_info.fail_file = __FILE__; \
+ greatest_info.fail_line = __LINE__; \
+ if (0 != strcmp(exp_s, got_s)) { \
+ fprintf(GREATEST_STDOUT, \
+ "Expected:\n####\n%s\n####\n", exp_s); \
+ fprintf(GREATEST_STDOUT, \
+ "Got:\n####\n%s\n####\n", got_s); \
+ return -1; \
+ } \
+ greatest_info.msg = NULL; \
+ } while (0)
+
+#define GREATEST_PASSm(MSG) \
+ do { \
+ greatest_info.msg = MSG; \
+ return 0; \
+ } while (0)
+
+#define GREATEST_FAILm(MSG) \
+ do { \
+ greatest_info.fail_file = __FILE__; \
+ greatest_info.fail_line = __LINE__; \
+ greatest_info.msg = MSG; \
+ return -1; \
+ } while (0)
+
+#define GREATEST_SKIPm(MSG) \
+ do { \
+ greatest_info.msg = MSG; \
+ return 1; \
+ } while (0)
+
+#define GREATEST_SET_TIME(NAME) \
+ NAME = clock(); \
+ if (NAME == (clock_t) -1) { \
+ fprintf(GREATEST_STDOUT, \
+ "clock error: %s\n", #NAME); \
+ exit(EXIT_FAILURE); \
+ }
+
+#define GREATEST_CLOCK_DIFF(C1, C2) \
+ fprintf(GREATEST_STDOUT, " (%lu ticks, %.3f sec)", \
+ (long unsigned int) (C2) - (C1), \
+ (double)((C2) - (C1)) / (1.0 * (double)CLOCKS_PER_SEC)) \
+
+/* Include several function definitions in the main test file. */
+#define GREATEST_MAIN_DEFS() \
+ \
+/* Is FILTER a subset of NAME? */ \
+static int greatest_name_match(const char *name, \
+ const char *filter) { \
+ size_t offset = 0; \
+ size_t filter_len = strlen(filter); \
+ while (name[offset] != '\0') { \
+ if (name[offset] == filter[0]) { \
+ if (0 == strncmp(&name[offset], filter, filter_len)) { \
+ return 1; \
+ } \
+ } \
+ offset++; \
+ } \
+ \
+ return 0; \
+} \
+ \
+int greatest_pre_test(const char *name) { \
+ if (!GREATEST_LIST_ONLY() \
+ && (!GREATEST_FIRST_FAIL() || greatest_info.suite.failed == 0) \
+ && (greatest_info.test_filter == NULL || \
+ greatest_name_match(name, greatest_info.test_filter))) { \
+ GREATEST_SET_TIME(greatest_info.suite.pre_test); \
+ if (greatest_info.setup) { \
+ greatest_info.setup(greatest_info.setup_udata); \
+ } \
+ return 1; /* test should be run */ \
+ } else { \
+ return 0; /* skipped */ \
+ } \
+} \
+ \
+void greatest_post_test(const char *name, int res) { \
+ GREATEST_SET_TIME(greatest_info.suite.post_test); \
+ if (greatest_info.teardown) { \
+ void *udata = greatest_info.teardown_udata; \
+ greatest_info.teardown(udata); \
+ } \
+ \
+ if (res < 0) { \
+ greatest_do_fail(name); \
+ } else if (res > 0) { \
+ greatest_do_skip(name); \
+ } else if (res == 0) { \
+ greatest_do_pass(name); \
+ } \
+ greatest_info.suite.tests_run++; \
+ greatest_info.col++; \
+ if (GREATEST_IS_VERBOSE()) { \
+ GREATEST_CLOCK_DIFF(greatest_info.suite.pre_test, \
+ greatest_info.suite.post_test); \
+ fprintf(GREATEST_STDOUT, "\n"); \
+ } else if (greatest_info.col % greatest_info.width == 0) { \
+ fprintf(GREATEST_STDOUT, "\n"); \
+ greatest_info.col = 0; \
+ } \
+ if (GREATEST_STDOUT == stdout) fflush(stdout); \
+} \
+ \
+static void greatest_run_suite(greatest_suite_cb *suite_cb, \
+ const char *suite_name) { \
+ if (greatest_info.suite_filter && \
+ !greatest_name_match(suite_name, greatest_info.suite_filter)) \
+ return; \
+ if (GREATEST_FIRST_FAIL() && greatest_info.failed > 0) return; \
+ greatest_info.suite.tests_run = 0; \
+ greatest_info.suite.failed = 0; \
+ greatest_info.suite.passed = 0; \
+ greatest_info.suite.skipped = 0; \
+ greatest_info.suite.pre_suite = 0; \
+ greatest_info.suite.post_suite = 0; \
+ greatest_info.suite.pre_test = 0; \
+ greatest_info.suite.post_test = 0; \
+ greatest_info.col = 0; \
+ fprintf(GREATEST_STDOUT, "\n* Suite %s:\n", suite_name); \
+ GREATEST_SET_TIME(greatest_info.suite.pre_suite); \
+ suite_cb(); \
+ GREATEST_SET_TIME(greatest_info.suite.post_suite); \
+ if (greatest_info.suite.tests_run > 0) { \
+ fprintf(GREATEST_STDOUT, \
+ "\n%u tests - %u pass, %u fail, %u skipped", \
+ greatest_info.suite.tests_run, \
+ greatest_info.suite.passed, \
+ greatest_info.suite.failed, \
+ greatest_info.suite.skipped); \
+ GREATEST_CLOCK_DIFF(greatest_info.suite.pre_suite, \
+ greatest_info.suite.post_suite); \
+ fprintf(GREATEST_STDOUT, "\n"); \
+ } \
+ greatest_info.setup = NULL; \
+ greatest_info.setup_udata = NULL; \
+ greatest_info.teardown = NULL; \
+ greatest_info.teardown_udata = NULL; \
+ greatest_info.passed += greatest_info.suite.passed; \
+ greatest_info.failed += greatest_info.suite.failed; \
+ greatest_info.skipped += greatest_info.suite.skipped; \
+ greatest_info.tests_run += greatest_info.suite.tests_run; \
+} \
+ \
+void greatest_do_pass(const char *name) { \
+ if (GREATEST_IS_VERBOSE()) { \
+ fprintf(GREATEST_STDOUT, "PASS %s: %s", \
+ name, greatest_info.msg ? greatest_info.msg : ""); \
+ } else { \
+ fprintf(GREATEST_STDOUT, "."); \
+ } \
+ greatest_info.suite.passed++; \
+} \
+ \
+void greatest_do_fail(const char *name) { \
+ if (GREATEST_IS_VERBOSE()) { \
+ fprintf(GREATEST_STDOUT, \
+ "FAIL %s: %s (%s:%u)", \
+ name, greatest_info.msg ? greatest_info.msg : "", \
+ greatest_info.fail_file, greatest_info.fail_line); \
+ } else { \
+ fprintf(GREATEST_STDOUT, "F"); \
+ /* add linebreak if in line of '.'s */ \
+ if (greatest_info.col % greatest_info.width != 0) \
+ fprintf(GREATEST_STDOUT, "\n"); \
+ greatest_info.col = 0; \
+ fprintf(GREATEST_STDOUT, "FAIL %s: %s (%s:%u)\n", \
+ name, \
+ greatest_info.msg ? greatest_info.msg : "", \
+ greatest_info.fail_file, greatest_info.fail_line); \
+ } \
+ greatest_info.suite.failed++; \
+} \
+ \
+void greatest_do_skip(const char *name) { \
+ if (GREATEST_IS_VERBOSE()) { \
+ fprintf(GREATEST_STDOUT, "SKIP %s: %s", \
+ name, \
+ greatest_info.msg ? \
+ greatest_info.msg : "" ); \
+ } else { \
+ fprintf(GREATEST_STDOUT, "s"); \
+ } \
+ greatest_info.suite.skipped++; \
+} \
+ \
+void greatest_usage(const char *name) { \
+ fprintf(GREATEST_STDOUT, \
+ "Usage: %s [-hlfv] [-s SUITE] [-t TEST]\n" \
+ " -h print this Help\n" \
+ " -l List suites and their tests, then exit\n" \
+ " -f Stop runner after first failure\n" \
+ " -v Verbose output\n" \
+ " -s SUITE only run suite named SUITE\n" \
+ " -t TEST only run test named TEST\n", \
+ name); \
+} \
+ \
+void GREATEST_SET_SETUP_CB(greatest_setup_cb *cb, void *udata) { \
+ greatest_info.setup = cb; \
+ greatest_info.setup_udata = udata; \
+} \
+ \
+void GREATEST_SET_TEARDOWN_CB(greatest_teardown_cb *cb, \
+ void *udata) { \
+ greatest_info.teardown = cb; \
+ greatest_info.teardown_udata = udata; \
+} \
+ \
+greatest_run_info greatest_info
+
+/* Handle command-line arguments, etc. */
+#define GREATEST_MAIN_BEGIN() \
+ do { \
+ int i = 0; \
+ memset(&greatest_info, 0, sizeof(greatest_info)); \
+ if (greatest_info.width == 0) { \
+ greatest_info.width = GREATEST_DEFAULT_WIDTH; \
+ } \
+ for (i = 1; i < argc; i++) { \
+ if (0 == strcmp("-t", argv[i])) { \
+ if (argc <= i + 1) { \
+ greatest_usage(argv[0]); \
+ exit(EXIT_FAILURE); \
+ } \
+ greatest_info.test_filter = argv[i+1]; \
+ i++; \
+ } else if (0 == strcmp("-s", argv[i])) { \
+ if (argc <= i + 1) { \
+ greatest_usage(argv[0]); \
+ exit(EXIT_FAILURE); \
+ } \
+ greatest_info.suite_filter = argv[i+1]; \
+ i++; \
+ } else if (0 == strcmp("-f", argv[i])) { \
+ greatest_info.flags |= GREATEST_FLAG_FIRST_FAIL; \
+ } else if (0 == strcmp("-v", argv[i])) { \
+ greatest_info.flags |= GREATEST_FLAG_VERBOSE; \
+ } else if (0 == strcmp("-l", argv[i])) { \
+ greatest_info.flags |= GREATEST_FLAG_LIST_ONLY; \
+ } else if (0 == strcmp("-h", argv[i])) { \
+ greatest_usage(argv[0]); \
+ exit(EXIT_SUCCESS); \
+ } else { \
+ fprintf(GREATEST_STDOUT, \
+ "Unknown argument '%s'\n", argv[i]); \
+ greatest_usage(argv[0]); \
+ exit(EXIT_FAILURE); \
+ } \
+ } \
+ } while (0); \
+ GREATEST_SET_TIME(greatest_info.begin)
+
+#define GREATEST_MAIN_END() \
+ do { \
+ if (!GREATEST_LIST_ONLY()) { \
+ GREATEST_SET_TIME(greatest_info.end); \
+ fprintf(GREATEST_STDOUT, \
+ "\nTotal: %u tests", greatest_info.tests_run); \
+ GREATEST_CLOCK_DIFF(greatest_info.begin, \
+ greatest_info.end); \
+ fprintf(GREATEST_STDOUT, "\n"); \
+ fprintf(GREATEST_STDOUT, \
+ "Pass: %u, fail: %u, skip: %u.\n", \
+ greatest_info.passed, \
+ greatest_info.failed, greatest_info.skipped); \
+ } \
+ return (greatest_info.failed > 0 \
+ ? EXIT_FAILURE : EXIT_SUCCESS); \
+ } while (0)
+
+/* Make abbreviations without the GREATEST_ prefix for the
+ * most commonly used symbols. */
+#if GREATEST_USE_ABBREVS
+#define TEST GREATEST_TEST
+#define SUITE GREATEST_SUITE
+#define RUN_TEST GREATEST_RUN_TEST
+#define RUN_TEST1 GREATEST_RUN_TEST1
+#define RUN_SUITE GREATEST_RUN_SUITE
+#define ASSERT GREATEST_ASSERT
+#define ASSERTm GREATEST_ASSERTm
+#define ASSERT_FALSE GREATEST_ASSERT_FALSE
+#define ASSERT_EQ GREATEST_ASSERT_EQ
+#define ASSERT_STR_EQ GREATEST_ASSERT_STR_EQ
+#define ASSERT_FALSEm GREATEST_ASSERT_FALSEm
+#define ASSERT_EQm GREATEST_ASSERT_EQm
+#define ASSERT_STR_EQm GREATEST_ASSERT_STR_EQm
+#define PASS GREATEST_PASS
+#define FAIL GREATEST_FAIL
+#define SKIP GREATEST_SKIP
+#define PASSm GREATEST_PASSm
+#define FAILm GREATEST_FAILm
+#define SKIPm GREATEST_SKIPm
+#define SET_SETUP GREATEST_SET_SETUP_CB
+#define SET_TEARDOWN GREATEST_SET_TEARDOWN_CB
+
+#if __STDC_VERSION__ >= 19901L
+#endif /* C99 */
+#define RUN_TESTp GREATEST_RUN_TESTp
+#endif /* USE_ABBREVS */
+
+#endif
diff --git a/drive-sdk/test/test_ble_advertisement.c b/drive-sdk/test/test_ble_advertisement.c
new file mode 100644
index 0000000..b9e084e
--- /dev/null
+++ b/drive-sdk/test/test_ble_advertisement.c
@@ -0,0 +1,75 @@
+/*
+ * 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 "eir.h"
+#include "adv_data.h"
+
+SUITE(ble_advertisement);
+
+TEST ble_adv_parse_scan_record_count(void) {
+ size_t count = 0;
+ int err = 0;
+
+ err = ble_adv_parse_scan(adv0_scan, sizeof(adv0_scan), &count, NULL);
+ ASSERT_EQ(err, 0);
+ ASSERT_EQ(count, 3);
+
+ err = ble_adv_parse_scan(adv1_scan, sizeof(adv1_scan), &count, NULL);
+ ASSERT_EQ(err, 0);
+ ASSERT_EQ(count, 2);
+
+ err = ble_adv_parse_scan(st0_scan, sizeof(st0_scan), &count, NULL);
+ ASSERT_EQ(err, 0);
+ ASSERT_EQ(count, 1);
+
+ err = ble_adv_parse_scan(st1_scan, sizeof(st1_scan), &count, NULL);
+ ASSERT_EQ(err, 0);
+ ASSERT_EQ(count, 3);
+
+ PASS();
+}
+
+TEST ble_adv_parse_scan_records(void) {
+ size_t count = 0;
+ int err = 0;
+
+ err = ble_adv_parse_scan(adv0_scan, sizeof(adv0_scan), &count, NULL);
+ ASSERT_EQ(err, 0);
+ ASSERT_EQ(count, 3);
+
+ ble_adv_record_t records[3];
+ memset(records, 0, sizeof(ble_adv_record_t) * 3);
+ err = ble_adv_parse_scan(adv0_scan, sizeof(adv0_scan), &count, records);
+
+ ble_adv_record_type_t expected_types[3] = { ADV_TYPE_FLAGS, ADV_TYPE_UUID_128, ADV_TYPE_MANUFACTURER_DATA };
+
+ int i = 0;
+ for (i = 0; i < count; ++i) {
+ ASSERT_EQ(records[i].type, expected_types[i]);
+ }
+
+ PASS();
+}
+
+GREATEST_SUITE(ble_advertisement) {
+ RUN_TEST(ble_adv_parse_scan_record_count);
+ RUN_TEST(ble_adv_parse_scan_records);
+}
diff --git a/drive-sdk/test/test_protocol.c b/drive-sdk/test/test_protocol.c
new file mode 100644
index 0000000..1bb2768
--- /dev/null
+++ b/drive-sdk/test/test_protocol.c
@@ -0,0 +1,243 @@
+/*
+ * 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 <string.h>
+
+#include "greatest.h"
+#include "anki_greatest.h"
+
+#include "protocol.h"
+#include "anki_util.h"
+
+SUITE(vehicle_protocol);
+
+TEST test_struct_attribute_packed(void) {
+ ASSERT_EQ(sizeof(anki_vehicle_msg_sdk_mode_t), ANKI_VEHICLE_MSG_SDK_MODE_SIZE+ANKI_VEHICLE_MSG_BASE_SIZE);
+ PASS();
+}
+
+TEST test_set_sdk_mode(void) {
+ anki_vehicle_msg_t msg;
+ uint8_t size = anki_vehicle_msg_set_sdk_mode(&msg, 1, ANKI_VEHICLE_SDK_OPTION_OVERRIDE_LOCALIZATION);
+ ASSERT_EQ(size, 4);
+
+ uint8_t expect[4] = { 0x03, 0x90, 0x01, 0x01 };
+ ASSERT_BYTES_EQ(&msg, expect, 4);
+ PASS();
+}
+
+TEST test_set_speed(void) {
+ anki_vehicle_msg_t msg;
+ uint8_t size = anki_vehicle_msg_set_speed(&msg, 1000, 25000);
+ ASSERT_EQ(size, sizeof(anki_vehicle_msg_set_speed_t));
+
+ uint8_t expect[7] = { 0x06, 0x24, 0xe8, 0x03, 0xa8, 0x61, 0x00 };
+ ASSERT_BYTES_EQ(&msg, expect, 7);
+ PASS();
+}
+
+TEST test_set_offset_from_center(void) {
+ anki_vehicle_msg_t msg;
+ memset(&msg, 0, sizeof(anki_vehicle_msg_t));
+ uint8_t size = anki_vehicle_msg_set_offset_from_road_center(&msg, 0.0);
+
+ ASSERT_EQ(size, sizeof(anki_vehicle_msg_set_offset_from_road_center_t));
+
+ uint8_t expect[6] = { 0x5, 0x2c, 0, 0, 0, 0 };
+ ASSERT_BYTES_EQ(&msg, expect, 6);
+ PASS();
+}
+
+TEST test_change_lane(void) {
+ anki_vehicle_msg_t msg;
+ memset(&msg, 0, sizeof(anki_vehicle_msg_change_lane_t));
+ uint8_t size = anki_vehicle_msg_change_lane(&msg, 1000, 10000, 20.f);
+ ASSERT_EQ(size, sizeof(anki_vehicle_msg_change_lane_t));
+
+ uint8_t expect[12] = { 0x0b, 0x25, 0xe8, 0x03, 0x10, 0x27, 0x00, 0x00, 0xa0, 0x41, 0, 0 };
+ ASSERT_BYTES_EQ(&msg, expect, 12);
+ PASS();
+}
+
+TEST test_light_config(void) {
+ anki_vehicle_light_config_t config;
+ memset(&config, 0, sizeof(anki_vehicle_light_config_t));
+ //uint8_t size = anki_vehicle_light_config(&config, LIGHT_RED, EFFECT_THROB, 0, 20, 5);
+ anki_vehicle_light_config(&config, LIGHT_RED, EFFECT_THROB, 0, 10, 10);
+ ASSERT(config.cycles_per_10_sec > 0);
+
+ anki_vehicle_msg_lights_pattern_t msg;
+ memset(&msg, 0, sizeof(anki_vehicle_msg_lights_pattern_t));
+
+ const uint8_t size = anki_vehicle_msg_lights_pattern_append(&msg, &config);
+ ASSERT_EQ(size, sizeof(config));
+
+ ASSERT_EQ(msg.msg_id, ANKI_VEHICLE_MSG_C2V_LIGHTS_PATTERN);
+ ASSERT_EQ(msg.size, ANKI_VEHICLE_MSG_C2V_LIGHTS_PATTERN_SIZE);
+ ASSERT_EQ(msg.channel_count, 1);
+ ASSERT_BYTES_EQ(&(msg.channel_config[0]), &config, sizeof(config));
+
+ PASS();
+}
+
+// Regression test against a STEADY LIGHT_BLUE, max intensity
+TEST test_lights_steady_blue(void) {
+ anki_vehicle_msg_lights_pattern_t msg;
+ memset(&msg, 0, sizeof(anki_vehicle_msg_lights_pattern_t));
+
+ uint8_t intensity = ANKI_VEHICLE_MAX_LIGHT_INTENSITY;
+ uint8_t cycles_per_min = 0;
+
+ anki_vehicle_light_config_t config;
+ {
+ memset(&config, 0, sizeof(anki_vehicle_light_config_t));
+ anki_vehicle_light_config(&config, LIGHT_RED, EFFECT_STEADY, 0, 0, cycles_per_min);
+ uint8_t append_size = anki_vehicle_msg_lights_pattern_append(&msg, &config);
+ ASSERT_EQ(append_size, sizeof(config));
+ ASSERT_EQ(msg.channel_count, 1);
+ }
+ {
+ memset(&config, 0, sizeof(anki_vehicle_light_config_t));
+ anki_vehicle_light_config(&config, LIGHT_GREEN, EFFECT_STEADY, 0, 0, cycles_per_min);
+ uint8_t append_size = anki_vehicle_msg_lights_pattern_append(&msg, &config);
+ ASSERT_EQ(append_size, sizeof(config));
+ ASSERT_EQ(msg.channel_count, 2);
+ }
+ {
+ memset(&config, 0, sizeof(anki_vehicle_light_config_t));
+ anki_vehicle_light_config(&config, LIGHT_BLUE, EFFECT_STEADY, intensity, intensity, cycles_per_min);
+ uint8_t append_size = anki_vehicle_msg_lights_pattern_append(&msg, &config);
+ ASSERT_EQ(append_size, sizeof(config));
+ ASSERT_EQ(msg.channel_count, 3);
+ }
+
+ uint8_t expected[18] = {
+ 0x11, 0x33,
+ 0x03,
+ 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x03, 0x00, 0x00, 0x00, 0x00,
+ 0x02, 0x00, 0x0e, 0x0e, 0x00
+ };
+
+ ASSERT_BYTES_EQ(&msg, expected, sizeof(expected));
+ PASS();
+}
+
+TEST test_turn_180(void) {
+ anki_vehicle_msg_t msg;
+ memset(&msg, 0, sizeof(anki_vehicle_msg_turn_t));
+
+ uint8_t size = anki_vehicle_msg_turn(&msg, VEHICLE_TURN_UTURN, VEHICLE_TURN_TRIGGER_IMMEDIATE);
+ ASSERT_EQ(size, sizeof(anki_vehicle_msg_turn_t));
+
+ uint8_t expect[4] = { ANKI_VEHICLE_MSG_C2V_TURN_SIZE,
+ ANKI_VEHICLE_MSG_C2V_TURN,
+ VEHICLE_TURN_UTURN,
+ VEHICLE_TURN_TRIGGER_IMMEDIATE };
+ ASSERT_BYTES_EQ(&msg, expect, 4);
+ PASS();
+}
+
+TEST test_lights_pattern(void) {
+ anki_vehicle_msg_lights_pattern_t msg;
+ memset(&msg, 0, sizeof(anki_vehicle_msg_lights_pattern_t));
+
+ uint8_t intensity = ANKI_VEHICLE_MAX_LIGHT_INTENSITY;
+ uint8_t cycles_per_min = 6;
+
+ anki_vehicle_light_config_t config;
+ {
+ memset(&config, 0, sizeof(anki_vehicle_light_config_t));
+ anki_vehicle_light_config(&config, LIGHT_RED, EFFECT_THROB, 0, intensity, cycles_per_min);
+ uint8_t append_size = anki_vehicle_msg_lights_pattern_append(&msg, &config);
+ ASSERT_EQ(append_size, sizeof(config));
+ ASSERT_EQ(msg.channel_count, 1);
+ }
+ {
+ memset(&config, 0, sizeof(anki_vehicle_light_config_t));
+ anki_vehicle_light_config(&config, LIGHT_GREEN, EFFECT_THROB, 0, ANKI_VEHICLE_MAX_LIGHT_INTENSITY, cycles_per_min);
+ uint8_t append_size = anki_vehicle_msg_lights_pattern_append(&msg, &config);
+ ASSERT_EQ(append_size, sizeof(config));
+ ASSERT_EQ(msg.channel_count, 2);
+ }
+ {
+ memset(&config, 0, sizeof(anki_vehicle_light_config_t));
+ anki_vehicle_light_config(&config, LIGHT_BLUE, EFFECT_THROB, 0, ANKI_VEHICLE_MAX_LIGHT_INTENSITY, cycles_per_min);
+ uint8_t append_size = anki_vehicle_msg_lights_pattern_append(&msg, &config);
+ ASSERT_EQ(append_size, sizeof(config));
+ ASSERT_EQ(msg.channel_count, 3);
+ }
+
+ ASSERT_EQ(msg.msg_id, ANKI_VEHICLE_MSG_C2V_LIGHTS_PATTERN);
+ ASSERT_EQ(msg.size, ANKI_VEHICLE_MSG_C2V_LIGHTS_PATTERN_SIZE);
+
+ ASSERT_EQ(msg.channel_config[0].channel, LIGHT_RED);
+ ASSERT_EQ(msg.channel_config[1].channel, LIGHT_GREEN);
+ ASSERT_EQ(msg.channel_config[2].channel, LIGHT_BLUE);
+
+ PASS();
+}
+
+TEST test_disconnect(void) {
+ anki_vehicle_msg_t msg;
+ anki_vehicle_msg_disconnect(&msg);
+
+ uint8_t expect[2] = { ANKI_VEHICLE_MSG_BASE_SIZE, ANKI_VEHICLE_MSG_C2V_DISCONNECT };
+ ASSERT_BYTES_EQ(&msg, expect, 2);
+
+ PASS();
+}
+
+TEST test_get_version(void) {
+ anki_vehicle_msg_t msg;
+ uint8_t size = anki_vehicle_msg_get_version(&msg);
+
+ ASSERT_EQ(size, 2);
+
+ uint8_t expect[2] = { ANKI_VEHICLE_MSG_BASE_SIZE, ANKI_VEHICLE_MSG_C2V_VERSION_REQUEST };
+ ASSERT_BYTES_EQ(&msg, expect, sizeof(expect));
+
+ PASS();
+}
+
+TEST test_get_battery_level(void) {
+ anki_vehicle_msg_t msg;
+ uint8_t size = anki_vehicle_msg_get_battery_level(&msg);
+
+ ASSERT_EQ(size, 2);
+
+ uint8_t expect[2] = { ANKI_VEHICLE_MSG_BASE_SIZE, ANKI_VEHICLE_MSG_C2V_BATTERY_LEVEL_REQUEST };
+ ASSERT_BYTES_EQ(&msg, expect, sizeof(expect));
+
+ PASS();
+}
+
+GREATEST_SUITE(vehicle_protocol) {
+ RUN_TEST(test_struct_attribute_packed);
+ RUN_TEST(test_set_sdk_mode);
+ RUN_TEST(test_set_speed);
+ RUN_TEST(test_set_offset_from_center);
+ RUN_TEST(test_change_lane);
+ RUN_TEST(test_light_config);
+ RUN_TEST(test_lights_pattern);
+ RUN_TEST(test_lights_steady_blue);
+ RUN_TEST(test_turn_180);
+ RUN_TEST(test_disconnect);
+ RUN_TEST(test_get_version);
+ RUN_TEST(test_get_battery_level);
+}
diff --git a/drive-sdk/test/test_suite.c b/drive-sdk/test/test_suite.c
new file mode 100644
index 0000000..dd83bf5
--- /dev/null
+++ b/drive-sdk/test/test_suite.c
@@ -0,0 +1,36 @@
+/*
+ * 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 <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+
+#include "greatest.h"
+
+extern SUITE(ble_advertisement);
+extern SUITE(vehicle_advertisement);
+extern SUITE(vehicle_protocol);
+
+/* Add all the definitions that need to be in the test runner's main file. */
+GREATEST_MAIN_DEFS();
+
+int main(int argc, char **argv) {
+ GREATEST_MAIN_BEGIN(); /* command-line arguments, initialization. */
+ RUN_SUITE(ble_advertisement);
+ RUN_SUITE(vehicle_advertisement);
+ RUN_SUITE(vehicle_protocol);
+ GREATEST_MAIN_END(); /* display results */
+}
diff --git a/drive-sdk/test/test_vehicle_advertisement.c b/drive-sdk/test/test_vehicle_advertisement.c
new file mode 100644
index 0000000..c7ae364
--- /dev/null
+++ b/drive-sdk/test/test_vehicle_advertisement.c
@@ -0,0 +1,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);
+}