|
1 | 1 | // Copyright 2020 Project March.
|
2 |
| -#include "march_hardware/encoder/Encoder.h" |
| 2 | +#include "../mocks/MockEncoder.cpp" |
3 | 3 | #include "march_hardware/error/hardware_exception.h"
|
4 | 4 |
|
5 | 5 | #include <cmath>
|
6 | 6 |
|
7 | 7 | #include <gtest/gtest.h>
|
8 | 8 |
|
| 9 | +/** |
| 10 | + * This test fixture uses the MockEncoder to test non virtual methods |
| 11 | + * of the Encoder abstract class. Otherwise it is not possible to |
| 12 | + * instantiate a pure abstract class. So as long as the non virtual |
| 13 | + * methods are tested all is ok. |
| 14 | + */ |
9 | 15 | class TestEncoder : public testing::Test
|
10 | 16 | {
|
11 | 17 | protected:
|
12 | 18 | const size_t resolution = 12;
|
13 |
| - march::Encoder encoder = march::Encoder(this->resolution); |
14 | 19 | };
|
15 | 20 |
|
16 | 21 | TEST_F(TestEncoder, ResolutionBelowRange)
|
17 | 22 | {
|
18 |
| - ASSERT_THROW(march::Encoder(0), march::error::HardwareException); |
| 23 | + ASSERT_THROW(MockEncoder(0), march::error::HardwareException); |
19 | 24 | }
|
20 | 25 |
|
21 | 26 | TEST_F(TestEncoder, ResolutionAboveRange)
|
22 | 27 | {
|
23 |
| - ASSERT_THROW(march::Encoder(50), march::error::HardwareException); |
| 28 | + ASSERT_THROW(MockEncoder(50), march::error::HardwareException); |
24 | 29 | }
|
25 | 30 |
|
26 | 31 | TEST_F(TestEncoder, SetSlaveIndex)
|
27 | 32 | {
|
| 33 | + MockEncoder encoder(this->resolution); |
28 | 34 | const int expected = 10;
|
29 |
| - this->encoder.setSlaveIndex(expected); |
30 |
| - ASSERT_EQ(expected, this->encoder.getSlaveIndex()); |
| 35 | + encoder.setSlaveIndex(expected); |
| 36 | + ASSERT_EQ(expected, encoder.getSlaveIndex()); |
31 | 37 | }
|
32 | 38 |
|
33 | 39 | TEST_F(TestEncoder, CorrectTotalPositions)
|
34 | 40 | {
|
35 |
| - ASSERT_EQ(std::pow(2, this->resolution), this->encoder.getTotalPositions()); |
| 41 | + MockEncoder encoder(this->resolution); |
| 42 | + ASSERT_EQ(std::pow(2, this->resolution), encoder.getTotalPositions()); |
36 | 43 | }
|
0 commit comments