Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/libraries/AP_Common/tests/test_ap_common.cpp
Views: 1799
#include <AP_gtest.h>12#include <AP_Common/AP_Common.h>34TEST(AP_Common, HexToUint8)5{6uint8_t res;7for (uint8_t test_value = '0', expected_res = 0; test_value < ':'; test_value++, expected_res++) {8EXPECT_TRUE(hex_to_uint8(test_value, res));9EXPECT_EQ(expected_res, res);10}11for (uint8_t test_value = 'A', expected_res = 10; test_value < 'G'; test_value++, expected_res++) {12EXPECT_TRUE(hex_to_uint8(test_value, res));13EXPECT_EQ(expected_res, res);14}15for (uint8_t test_value = 'a', expected_res = 10; test_value < 'g'; test_value++, expected_res++) {16EXPECT_TRUE(hex_to_uint8(test_value, res));17EXPECT_EQ(expected_res, res);18}19EXPECT_FALSE(hex_to_uint8('G', res));20EXPECT_FALSE(hex_to_uint8('g', res));21EXPECT_FALSE(hex_to_uint8(';', res));22EXPECT_FALSE(hex_to_uint8('/', res));23EXPECT_FALSE(hex_to_uint8('@', res));24EXPECT_FALSE(hex_to_uint8('`', res));25}2627TEST(AP_Common, BoundedInt32)28{29EXPECT_TRUE(is_bounded_int32(1, 0, 2));30EXPECT_FALSE(is_bounded_int32(3, 0, 2));31EXPECT_FALSE(is_bounded_int32(-1, 0, 2));32EXPECT_TRUE(is_bounded_int32(0, -1, 2));33EXPECT_TRUE(is_bounded_int32(-1, -2, 0));34}3536TEST(AP_Common, BitSet)37{38uint16_t test_value1 = 128;39BIT_SET(test_value1, 3);40EXPECT_EQ(test_value1, 136u);41BIT_CLEAR(test_value1, 7);42EXPECT_EQ(test_value1, 8u);4344uint32_t test_value2 = 128;45BIT_SET(test_value2, 3);46EXPECT_EQ(test_value2, 136u);47BIT_CLEAR(test_value2, 7);48EXPECT_EQ(test_value2, 8u);4950unsigned long test_value3 = 128;51BIT_SET(test_value3, 3);52EXPECT_EQ(test_value3, 136u);53BIT_CLEAR(test_value3, 7);54EXPECT_EQ(test_value3, 8u);55}565758TEST(AP_Common, StrcpyNoTerm)59{60const char src[] = "This is ArduPilot";61char dest[ARRAY_SIZE(src)-5]{};6263strncpy_noterm(dest, src, 12);64EXPECT_STRNE(dest, src);65EXPECT_STREQ("This is Ardu", dest);6667const char src2[] = "ArduPilot";68char dest2[ARRAY_SIZE(src)-5]{};69strncpy_noterm(dest2, src2, 12);70EXPECT_STREQ(dest2, src2);71}72AP_GTEST_MAIN()737475