storage_marshaller.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Pavel Kirienko <pavel.kirienko@gmail.com>
3  */
4 
5 #include <gtest/gtest.h>
8 
9 TEST(dynamic_node_id_server_StorageMarshaller, Basic)
10 {
12 
14 
16 
17  /*
18  * uint32
19  */
20  uint32_t u32 = 0;
21 
22  key = "foo";
23  u32 = 0;
24  ASSERT_LE(0, marshaler.setAndGetBack(key, u32));
25  ASSERT_EQ(0, u32);
26 
27  key = "bar";
28  u32 = 0xFFFFFFFF;
29  ASSERT_LE(0, marshaler.setAndGetBack(key, u32));
30  ASSERT_EQ(0xFFFFFFFF, u32);
31  ASSERT_LE(0, marshaler.get(key, u32));
32  ASSERT_EQ(0xFFFFFFFF, u32);
33 
34  key = "foo";
35  ASSERT_LE(0, marshaler.get(key, u32));
36  ASSERT_EQ(0, u32);
37 
38  key = "the_cake_is_a_lie";
39  ASSERT_GT(0, marshaler.get(key, u32));
40  ASSERT_EQ(0, u32);
41 
42  /*
43  * uint8[16]
44  */
45  uavcan::protocol::dynamic_node_id::server::Entry::FieldTypes::unique_id array;
46 
47  key = "a";
48  // Set zero
49  ASSERT_LE(0, marshaler.setAndGetBack(key, array));
50  for (uint8_t i = 0; i < 16; i++)
51  {
52  ASSERT_EQ(0, array[i]);
53  }
54 
55  // Make sure this will not be interpreted as uint32
56  ASSERT_GT(0, marshaler.get(key, u32));
57  ASSERT_EQ(0, u32);
58 
59  // Set pattern
60  for (uint8_t i = 0; i < 16; i++)
61  {
62  array[i] = uint8_t(i + 1);
63  }
64  ASSERT_LE(0, marshaler.setAndGetBack(key, array));
65  for (uint8_t i = 0; i < 16; i++)
66  {
67  ASSERT_EQ(i + 1, array[i]);
68  }
69 
70  // Set another pattern
71  for (uint8_t i = 0; i < 16; i++)
72  {
73  array[i] = uint8_t(i | (i << 4));
74  }
75  ASSERT_LE(0, marshaler.setAndGetBack(key, array));
76  for (uint8_t i = 0; i < 16; i++)
77  {
78  ASSERT_EQ(uint8_t(i | (i << 4)), array[i]);
79  }
80 
81  // Make sure uint32 cannot be interpreted as an array
82  key = "foo";
83  ASSERT_GT(0, marshaler.get(key, array));
84 
85  // Nonexistent key
86  key = "the_cake_is_a_lie";
87  ASSERT_GT(0, marshaler.get(key, array));
88 }
uavcan::uint32_t
std::uint32_t uint32_t
Definition: std.hpp:26
uavcan::dynamic_node_id_server::StorageMarshaller
Definition: storage_marshaller.hpp:25
TEST
TEST(dynamic_node_id_server_StorageMarshaller, Basic)
Definition: storage_marshaller.cpp:9
uavcan::dynamic_node_id_server::StorageMarshaller::setAndGetBack
int setAndGetBack(const IStorageBackend::String &key, uint32_t &inout_value)
Definition: storage_marshaller.hpp:62
uavcan::dynamic_node_id_server::StorageMarshaller::get
int get(const IStorageBackend::String &key, uint32_t &out_value) const
Definition: storage_marshaller.hpp:90
uavcan::Array
Definition: array.hpp:424
uavcan::uint8_t
std::uint8_t uint8_t
Definition: std.hpp:24
memory_storage_backend.hpp
MemoryStorageBackend
Definition: memory_storage_backend.hpp:10
storage_marshaller.hpp


uavcan_communicator
Author(s):
autogenerated on Fri Dec 13 2024 03:10:03