TestStatusWord.cpp
Go to the documentation of this file.
1 
7 #include <gtest/gtest.h>
8 
10 
11 namespace rokubimini
12 {
13 class StatusWordTest : public ::testing::Test
14 {
15 protected:
18  {
19  statusword = new Statusword();
20  }
21 
22  ~StatusWordTest() override
23  {
24  delete statusword;
25  // You can do clean-up work that doesn't throw exceptions here.
26  }
27 
28  // If the constructor and destructor are not enough for setting up
29  // and cleaning up each test, you can define the following methods:
30 
31  void SetUp() override
32  {
33  // Code here will be called immediately after the constructor (right
34  // before each test).
35  }
36 
37  void TearDown() override
38  {
39  // Code here will be called immediately after each test (right
40  // before the destructor).
41  }
42 };
43 
44 TEST_F(StatusWordTest, CopyConstructorWorksCorrectly)
45 {
46  auto word_expected = Statusword(*statusword);
47  EXPECT_EQ(statusword->getData(), word_expected.getData());
48  EXPECT_EQ(statusword->getStamp(), word_expected.getStamp());
49  EXPECT_EQ(statusword->hasErrorAdcSaturated(), word_expected.hasErrorAdcSaturated());
50  EXPECT_EQ(statusword->hasErrorAccSaturated(), word_expected.hasErrorAccSaturated());
51  EXPECT_EQ(statusword->hasErrorGyroSaturated(), word_expected.hasErrorGyroSaturated());
52  EXPECT_EQ(statusword->hasErrorAdcOutOfSync(), word_expected.hasErrorAdcOutOfSync());
53  EXPECT_EQ(statusword->hasErrorSensingRangeExceeded(), word_expected.hasErrorSensingRangeExceeded());
54  EXPECT_EQ(statusword->hasWarningOvertemperature(), word_expected.hasWarningOvertemperature());
55  EXPECT_EQ(statusword->hasFatalSupplyVoltage(), word_expected.hasFatalSupplyVoltage());
56 }
57 
58 TEST_F(StatusWordTest, assignmentOperatorWorksCorrectly)
59 {
60  auto new_statusword = Statusword();
61 
62  new_statusword = *statusword;
63 
64  EXPECT_EQ(statusword->getData(), new_statusword.getData());
65  EXPECT_EQ(statusword->getStamp(), new_statusword.getStamp());
66  EXPECT_EQ(statusword->hasErrorAdcSaturated(), new_statusword.hasErrorAdcSaturated());
67  EXPECT_EQ(statusword->hasErrorAccSaturated(), new_statusword.hasErrorAccSaturated());
68  EXPECT_EQ(statusword->hasErrorGyroSaturated(), new_statusword.hasErrorGyroSaturated());
69  EXPECT_EQ(statusword->hasErrorAdcOutOfSync(), new_statusword.hasErrorAdcOutOfSync());
70  EXPECT_EQ(statusword->hasErrorSensingRangeExceeded(), new_statusword.hasErrorSensingRangeExceeded());
71  EXPECT_EQ(statusword->hasWarningOvertemperature(), new_statusword.hasWarningOvertemperature());
72  EXPECT_EQ(statusword->hasFatalSupplyVoltage(), new_statusword.hasFatalSupplyVoltage());
73 }
74 
75 TEST_F(StatusWordTest, ExplicitConstructorWorksCorrectly)
76 {
77  Statusword::Data data = Statusword::Data(0xff000000);
78  Statusword::Data data2 = Statusword::Data(0xfe000000);
80  data3.all_ = 0xff000000;
81  EXPECT_TRUE(data != data2);
82  EXPECT_TRUE(data == data3);
83  EXPECT_EQ(statusword->isEmpty(), true);
84  Statusword newword = Statusword(data.all_);
85  statusword->setData(data.all_);
86  EXPECT_EQ(statusword->getData(), newword.getData());
87  EXPECT_EQ(statusword->hasErrorAdcSaturated(), newword.hasErrorAdcSaturated());
88  EXPECT_EQ(statusword->hasErrorAccSaturated(), newword.hasErrorAccSaturated());
89  EXPECT_EQ(statusword->hasErrorGyroSaturated(), newword.hasErrorGyroSaturated());
90  EXPECT_EQ(statusword->hasErrorAdcOutOfSync(), newword.hasErrorAdcOutOfSync());
91  EXPECT_EQ(statusword->hasErrorSensingRangeExceeded(), newword.hasErrorSensingRangeExceeded());
92  EXPECT_EQ(statusword->hasWarningOvertemperature(), newword.hasWarningOvertemperature());
93  EXPECT_EQ(statusword->hasFatalSupplyVoltage(), newword.hasFatalSupplyVoltage());
94 }
95 
96 TEST_F(StatusWordTest, ProblemMessagesWorksCorrectly)
97 {
99  .errorAccSaturated_ = 0,
100  .errorGyroSaturated_ = 0,
101  .errorAdcOutOfSync_ = 0,
102  .errorSensingRangeExceeded_ = 0,
103  .warningOvertemperature_ = 0,
104  .fatalSupplyVoltage_ = 0 };
106  data.bits_ = databits;
107 
109  .errorAccSaturated_ = 1,
110  .errorGyroSaturated_ = 1,
111  .errorAdcOutOfSync_ = 1,
112  .errorSensingRangeExceeded_ = 1,
113  .warningOvertemperature_ = 1,
114  .fatalSupplyVoltage_ = 1 };
116  data2.bits_ = databits2;
117 
118  std::vector<std::string> infos, warnings, errors, fatals;
119  Statusword newword = Statusword(data.all_);
120  statusword->setData(data2.all_);
121  statusword->getMessagesDiff(newword, infos, warnings, errors, fatals);
122  EXPECT_EQ(infos.size(), (uint32_t)0);
123  ASSERT_EQ(warnings.size(), (uint32_t)1);
124  ASSERT_EQ(errors.size(), (uint32_t)5);
125  ASSERT_EQ(fatals.size(), (uint32_t)1);
126  EXPECT_STREQ(warnings[0].c_str(), "High temperature in Rokubimini Sensor");
127  EXPECT_STREQ(errors[0].c_str(), "Force/Torque is invalid. ADC saturation");
128  EXPECT_STREQ(errors[1].c_str(), "Acceleration has saturated.");
129  EXPECT_STREQ(errors[2].c_str(), "Angular rates have saturated.");
130  EXPECT_STREQ(errors[3].c_str(), "Force/Torque is invalid. ADCs are not synced");
131  EXPECT_STREQ(errors[4].c_str(), "Sensing range exceeded.");
132  EXPECT_STREQ(fatals[0].c_str(), "Supply voltage exceeds limits.");
133 }
134 
135 TEST_F(StatusWordTest, InfoMessagesWorksCorrectly)
136 {
138  .errorAccSaturated_ = 0,
139  .errorGyroSaturated_ = 0,
140  .errorAdcOutOfSync_ = 0,
141  .errorSensingRangeExceeded_ = 0,
142  .warningOvertemperature_ = 0,
143  .fatalSupplyVoltage_ = 0 };
145  data.bits_ = databits;
146 
148  .errorAccSaturated_ = 1,
149  .errorGyroSaturated_ = 1,
150  .errorAdcOutOfSync_ = 1,
151  .errorSensingRangeExceeded_ = 1,
152  .warningOvertemperature_ = 1,
153  .fatalSupplyVoltage_ = 1 };
155  data2.bits_ = databits2;
156  std::vector<std::string> infos, warnings, errors, fatals;
157  Statusword newword = Statusword(data2.all_);
158  statusword->setData(data.all_);
159  statusword->getMessagesDiff(newword, infos, warnings, errors, fatals);
160  EXPECT_EQ(warnings.size(), (uint32_t)0);
161  EXPECT_EQ(errors.size(), (uint32_t)0);
162  EXPECT_EQ(fatals.size(), (uint32_t)0);
163  ASSERT_EQ(infos.size(), (uint32_t)7);
164  EXPECT_STREQ(infos[0].c_str(), "Temperature in Rokubimini Sensor is normal again");
165  EXPECT_STREQ(infos[1].c_str(), "Force/Torque is valid again. ADC is not saturated");
166  EXPECT_STREQ(infos[2].c_str(), "Acceleration is not saturated anymore.");
167  EXPECT_STREQ(infos[3].c_str(), "Angular rates are not saturated anymore.");
168  EXPECT_STREQ(infos[4].c_str(), "Force/Torque is valid again. ADCs are synced");
169  EXPECT_STREQ(infos[5].c_str(), "Sensing range is not exceeded.");
170  EXPECT_STREQ(infos[6].c_str(), "Supply voltage is normal.");
171 }
172 } // namespace rokubimini
bool hasErrorAccSaturated() const
Checks if the statusword has error ACC saturated.
Definition: Statusword.cpp:162
bool hasErrorSensingRangeExceeded() const
Checks if the statusword has error sensing range exceeded.
Definition: Statusword.cpp:180
void setData(const uint32_t data)
Sets the data variable.
Definition: Statusword.cpp:56
Class representing the different states the communication or the sensors can be in.
Definition: Statusword.hpp:20
uint32_t all_
All the bits in a "raw" uint32_t format.
Definition: Statusword.hpp:67
TEST_F(ReadingTest, StatusWordWorksCorrectly)
Definition: TestReading.cpp:68
bool isEmpty() const
Checks whether the statusword is empty.
Definition: Statusword.cpp:37
Bits representing errors.
Definition: Statusword.hpp:29
uint32_t getData() const
Gets the data variable.
Definition: Statusword.cpp:63
void getMessagesDiff(Statusword &previousStatusword, std::vector< std::string > &infos, std::vector< std::string > &warnings, std::vector< std::string > &errors, std::vector< std::string > &fatals) const
Gets the different messages form the previous statusword.
Definition: Statusword.cpp:89
bool hasErrorGyroSaturated() const
Checks if the statusword has error gyro saturated.
Definition: Statusword.cpp:168
bool hasErrorAdcOutOfSync() const
Checks if the statusword has error ADC out-of-sync.
Definition: Statusword.cpp:174
bool hasFatalSupplyVoltage() const
Checks if the statusword has fatal supply voltage.
Definition: Statusword.cpp:192
TimePoint getStamp() const
Gets the stamp variable.
Definition: Statusword.cpp:50
Data associated with a Status Word.
Definition: Statusword.hpp:51
bool hasWarningOvertemperature() const
Checks if the statusword has warning over temperature.
Definition: Statusword.cpp:186
bool hasErrorAdcSaturated() const
Checks if the statusword has error ADC saturated.
Definition: Statusword.cpp:156
Tests Configuration.
DataBits bits_
The bits of the data.
Definition: Statusword.hpp:59


rokubimini
Author(s):
autogenerated on Wed Mar 3 2021 03:09:12