Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: LedController mbed-rtos mbed NerfUSXbee Servomotor TargetManager
Fork of NerfUS by
TESTS/ServomotorTest.cpp@16:fba7c8e39388, 2017-02-26 (annotated)
- Committer:
- Maxime Dupuis
- Date:
- Sun Feb 26 10:20:18 2017 -0500
- Revision:
- 16:fba7c8e39388
- Child:
- 27:3ae7c62008ea
Add tests for servomotor
Test strategy:
- Servomotor depends on PwmOutInterface (via dependency injection)
- In the real app, we will use RealPwmOut, which will simply
delegate all calls to mbed's PwmOut
- In unit tests, we will create a MockPwmOut to test that it gets
used properly
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Maxime Dupuis |
16:fba7c8e39388 | 1 | #include "gmock/gmock.h" |
| Maxime Dupuis |
16:fba7c8e39388 | 2 | #include "gtest/gtest.h" |
| Maxime Dupuis |
16:fba7c8e39388 | 3 | |
| Maxime Dupuis |
16:fba7c8e39388 | 4 | #include "Servomotor.hpp" |
| Maxime Dupuis |
16:fba7c8e39388 | 5 | #include "MockPwmOut.hpp" |
| Maxime Dupuis |
16:fba7c8e39388 | 6 | |
| Maxime Dupuis |
16:fba7c8e39388 | 7 | TEST(ServomotorTest, SetPositionDown) |
| Maxime Dupuis |
16:fba7c8e39388 | 8 | { |
| Maxime Dupuis |
16:fba7c8e39388 | 9 | MockPwmOut mock_pwm_out; |
| Maxime Dupuis |
16:fba7c8e39388 | 10 | Servomotor servomotor(mock_pwm_out); |
| Maxime Dupuis |
16:fba7c8e39388 | 11 | |
| Maxime Dupuis |
16:fba7c8e39388 | 12 | EXPECT_CALL(mock_pwm_out, pulsewidth_ms(1)) |
| Maxime Dupuis |
16:fba7c8e39388 | 13 | .Times(1); |
| Maxime Dupuis |
16:fba7c8e39388 | 14 | |
| Maxime Dupuis |
16:fba7c8e39388 | 15 | servomotor.set_position_down(); |
| Maxime Dupuis |
16:fba7c8e39388 | 16 | } |
| Maxime Dupuis |
16:fba7c8e39388 | 17 | |
| Maxime Dupuis |
16:fba7c8e39388 | 18 | TEST(ServomotorTest, SetPositionUp) |
| Maxime Dupuis |
16:fba7c8e39388 | 19 | { |
| Maxime Dupuis |
16:fba7c8e39388 | 20 | MockPwmOut mock_pwm_out; |
| Maxime Dupuis |
16:fba7c8e39388 | 21 | Servomotor servomotor(mock_pwm_out); |
| Maxime Dupuis |
16:fba7c8e39388 | 22 | |
| Maxime Dupuis |
16:fba7c8e39388 | 23 | EXPECT_CALL(mock_pwm_out, pulsewidth_ms(1.5)) |
| Maxime Dupuis |
16:fba7c8e39388 | 24 | .Times(1); |
| Maxime Dupuis |
16:fba7c8e39388 | 25 | |
| Maxime Dupuis |
16:fba7c8e39388 | 26 | servomotor.set_position_up(); |
| Maxime Dupuis |
16:fba7c8e39388 | 27 | } |
| Maxime Dupuis |
16:fba7c8e39388 | 28 |
