NerfUS mobile node that manages a target for the Nerf gun firing range
Dependencies: LedController mbed-rtos mbed NerfUSXbee Servomotor TargetManager
Fork of NerfUS by
TESTS/TargetManagerTest.cpp@34:85994e0501fb, 2017-03-30 (annotated)
- Committer:
- Maxime Dupuis
- Date:
- Thu Mar 30 14:38:38 2017 -0400
- Revision:
- 34:85994e0501fb
- Parent:
- 32:50b777bab5a4
- Child:
- 35:7ee45f6d6484
Remove support for TargetInfo sequence
It will only execute a single command at a time when
it is received.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Maxime Dupuis |
28:8fc53a870691 | 1 | #include "gmock/gmock.h" |
Maxime Dupuis |
28:8fc53a870691 | 2 | #include "gtest/gtest.h" |
Maxime Dupuis |
28:8fc53a870691 | 3 | |
Maxime Dupuis |
30:412a779cf607 | 4 | #include "mocks/MockNerfusTicker.hpp" |
Maxime Dupuis |
28:8fc53a870691 | 5 | #include "mocks/MockTarget.hpp" |
Maxime Dupuis |
28:8fc53a870691 | 6 | #include "TargetManager.hpp" |
Maxime Dupuis |
28:8fc53a870691 | 7 | |
Maxime Dupuis |
28:8fc53a870691 | 8 | class TargetManagerTest : public ::testing::Test |
Maxime Dupuis |
28:8fc53a870691 | 9 | { |
Maxime Dupuis |
28:8fc53a870691 | 10 | public: |
Maxime Dupuis |
28:8fc53a870691 | 11 | TargetManagerTest() |
Maxime Dupuis |
28:8fc53a870691 | 12 | { |
Maxime Dupuis |
30:412a779cf607 | 13 | targets.push_back(&mock_target_a); |
Maxime Dupuis |
30:412a779cf607 | 14 | targets.push_back(&mock_target_b); |
Maxime Dupuis |
28:8fc53a870691 | 15 | } |
Maxime Dupuis |
28:8fc53a870691 | 16 | |
Maxime Dupuis |
30:412a779cf607 | 17 | MockTarget mock_target_a; |
Maxime Dupuis |
30:412a779cf607 | 18 | MockTarget mock_target_b; |
Maxime Dupuis |
30:412a779cf607 | 19 | std::vector<TargetInterface*> targets; |
Maxime Dupuis |
30:412a779cf607 | 20 | |
Maxime Dupuis |
30:412a779cf607 | 21 | MockNerfusTicker mock_nerfus_ticker; |
Maxime Dupuis |
28:8fc53a870691 | 22 | }; |
Maxime Dupuis |
28:8fc53a870691 | 23 | |
Maxime Dupuis |
28:8fc53a870691 | 24 | TEST_F(TargetManagerTest, LibraryBuilds) |
Maxime Dupuis |
28:8fc53a870691 | 25 | { |
Maxime Dupuis |
30:412a779cf607 | 26 | TargetManager target_manager(targets, mock_nerfus_ticker); |
Maxime Dupuis |
28:8fc53a870691 | 27 | } |
Maxime Dupuis |
28:8fc53a870691 | 28 | |
Maxime Dupuis |
31:c6dc9811ed14 | 29 | TEST_F(TargetManagerTest, WhenNoTargetIsActiveThenCallsToTargetHitAndTargetMissedDoNothing) |
Maxime Dupuis |
31:c6dc9811ed14 | 30 | { |
Maxime Dupuis |
31:c6dc9811ed14 | 31 | TargetManager target_manager(targets, mock_nerfus_ticker); |
Maxime Dupuis |
31:c6dc9811ed14 | 32 | |
Maxime Dupuis |
31:c6dc9811ed14 | 33 | target_manager.target_missed(0); |
Maxime Dupuis |
31:c6dc9811ed14 | 34 | target_manager.target_hit(0); |
Maxime Dupuis |
31:c6dc9811ed14 | 35 | } |
Maxime Dupuis |
32:50b777bab5a4 | 36 | |
Maxime Dupuis |
32:50b777bab5a4 | 37 | TEST_F(TargetManagerTest, WhenExecutingAllyTargetThenUseTheCorrectTargetTypeAndTimeout) |
Maxime Dupuis |
32:50b777bab5a4 | 38 | { |
Maxime Dupuis |
32:50b777bab5a4 | 39 | EXPECT_CALL(mock_target_a, ally_command()); |
Maxime Dupuis |
32:50b777bab5a4 | 40 | EXPECT_CALL(mock_nerfus_ticker, start(1000)); |
Maxime Dupuis |
32:50b777bab5a4 | 41 | |
Maxime Dupuis |
32:50b777bab5a4 | 42 | TargetManager target_manager(targets, mock_nerfus_ticker); |
Maxime Dupuis |
34:85994e0501fb | 43 | target_manager.execute(make_TargetInfo(0, TARGET_TYPE_ALLY, 1000)); |
Maxime Dupuis |
32:50b777bab5a4 | 44 | } |
Maxime Dupuis |
32:50b777bab5a4 | 45 | |
Maxime Dupuis |
32:50b777bab5a4 | 46 | TEST_F(TargetManagerTest, WhenExecutingEnemyTargetThenUseTheCorrectTargetTypeAndTimeout) |
Maxime Dupuis |
32:50b777bab5a4 | 47 | { |
Maxime Dupuis |
32:50b777bab5a4 | 48 | EXPECT_CALL(mock_target_b, enemy_command()); |
Maxime Dupuis |
32:50b777bab5a4 | 49 | EXPECT_CALL(mock_nerfus_ticker, start(2000)); |
Maxime Dupuis |
32:50b777bab5a4 | 50 | |
Maxime Dupuis |
32:50b777bab5a4 | 51 | TargetManager target_manager(targets, mock_nerfus_ticker); |
Maxime Dupuis |
34:85994e0501fb | 52 | target_manager.execute(make_TargetInfo(1, TARGET_TYPE_ENEMY, 2000)); |
Maxime Dupuis |
32:50b777bab5a4 | 53 | } |
Maxime Dupuis |
32:50b777bab5a4 | 54 | |
Maxime Dupuis |
32:50b777bab5a4 | 55 | TEST_F(TargetManagerTest, WhenActiveTargetIsHitThenSendTheEvent) |
Maxime Dupuis |
32:50b777bab5a4 | 56 | { |
Maxime Dupuis |
32:50b777bab5a4 | 57 | EXPECT_CALL(mock_target_a, ally_command()); |
Maxime Dupuis |
32:50b777bab5a4 | 58 | EXPECT_CALL(mock_nerfus_ticker, start(1000)); |
Maxime Dupuis |
32:50b777bab5a4 | 59 | EXPECT_CALL(mock_nerfus_ticker, get_time_ms()) |
Maxime Dupuis |
32:50b777bab5a4 | 60 | .WillOnce(::testing::Return(42)); |
Maxime Dupuis |
32:50b777bab5a4 | 61 | EXPECT_CALL(mock_nerfus_ticker, stop()); |
Maxime Dupuis |
32:50b777bab5a4 | 62 | EXPECT_CALL(mock_target_a, hit(42)); |
Maxime Dupuis |
32:50b777bab5a4 | 63 | |
Maxime Dupuis |
32:50b777bab5a4 | 64 | TargetManager target_manager(targets, mock_nerfus_ticker); |
Maxime Dupuis |
34:85994e0501fb | 65 | target_manager.execute(make_TargetInfo(0, TARGET_TYPE_ALLY, 1000)); |
Maxime Dupuis |
32:50b777bab5a4 | 66 | |
Maxime Dupuis |
32:50b777bab5a4 | 67 | target_manager.target_hit(0); |
Maxime Dupuis |
32:50b777bab5a4 | 68 | } |
Maxime Dupuis |
32:50b777bab5a4 | 69 | |
Maxime Dupuis |
32:50b777bab5a4 | 70 | TEST_F(TargetManagerTest, WhenActiveTargetIsMissedThenSendTheEvent) |
Maxime Dupuis |
32:50b777bab5a4 | 71 | { |
Maxime Dupuis |
32:50b777bab5a4 | 72 | EXPECT_CALL(mock_target_a, ally_command()); |
Maxime Dupuis |
32:50b777bab5a4 | 73 | EXPECT_CALL(mock_nerfus_ticker, start(1000)); |
Maxime Dupuis |
32:50b777bab5a4 | 74 | EXPECT_CALL(mock_nerfus_ticker, get_time_ms()) |
Maxime Dupuis |
32:50b777bab5a4 | 75 | .WillOnce(::testing::Return(42)); |
Maxime Dupuis |
32:50b777bab5a4 | 76 | EXPECT_CALL(mock_nerfus_ticker, stop()); |
Maxime Dupuis |
32:50b777bab5a4 | 77 | EXPECT_CALL(mock_target_a, timeout(42)); |
Maxime Dupuis |
32:50b777bab5a4 | 78 | |
Maxime Dupuis |
32:50b777bab5a4 | 79 | TargetManager target_manager(targets, mock_nerfus_ticker); |
Maxime Dupuis |
34:85994e0501fb | 80 | target_manager.execute(make_TargetInfo(0, TARGET_TYPE_ALLY, 1000)); |
Maxime Dupuis |
32:50b777bab5a4 | 81 | |
Maxime Dupuis |
32:50b777bab5a4 | 82 | target_manager.target_missed(0); |
Maxime Dupuis |
32:50b777bab5a4 | 83 | } |
Maxime Dupuis |
32:50b777bab5a4 | 84 |