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@32:50b777bab5a4, 2017-03-27 (annotated)
- Committer:
- Maxime Dupuis
- Date:
- Mon Mar 27 20:39:08 2017 -0400
- Revision:
- 32:50b777bab5a4
- Parent:
- 31:c6dc9811ed14
- Child:
- 34:85994e0501fb
Implement TargetManager
A TargetManager manages a group of targets, listens for
events (hit/miss) and dispatch them to the appropriate target
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 |
32:50b777bab5a4 | 43 | std::vector<TargetInfo> sequence; |
Maxime Dupuis |
32:50b777bab5a4 | 44 | sequence.push_back(make_TargetInfo(0, TARGET_TYPE_ALLY, 1000)); |
Maxime Dupuis |
32:50b777bab5a4 | 45 | target_manager.execute(sequence); |
Maxime Dupuis |
32:50b777bab5a4 | 46 | } |
Maxime Dupuis |
32:50b777bab5a4 | 47 | |
Maxime Dupuis |
32:50b777bab5a4 | 48 | TEST_F(TargetManagerTest, WhenExecutingEnemyTargetThenUseTheCorrectTargetTypeAndTimeout) |
Maxime Dupuis |
32:50b777bab5a4 | 49 | { |
Maxime Dupuis |
32:50b777bab5a4 | 50 | EXPECT_CALL(mock_target_b, enemy_command()); |
Maxime Dupuis |
32:50b777bab5a4 | 51 | EXPECT_CALL(mock_nerfus_ticker, start(2000)); |
Maxime Dupuis |
32:50b777bab5a4 | 52 | |
Maxime Dupuis |
32:50b777bab5a4 | 53 | TargetManager target_manager(targets, mock_nerfus_ticker); |
Maxime Dupuis |
32:50b777bab5a4 | 54 | std::vector<TargetInfo> sequence; |
Maxime Dupuis |
32:50b777bab5a4 | 55 | sequence.push_back(make_TargetInfo(1, TARGET_TYPE_ENEMY, 2000)); |
Maxime Dupuis |
32:50b777bab5a4 | 56 | target_manager.execute(sequence); |
Maxime Dupuis |
32:50b777bab5a4 | 57 | } |
Maxime Dupuis |
32:50b777bab5a4 | 58 | |
Maxime Dupuis |
32:50b777bab5a4 | 59 | TEST_F(TargetManagerTest, WhenActiveTargetIsHitThenSendTheEvent) |
Maxime Dupuis |
32:50b777bab5a4 | 60 | { |
Maxime Dupuis |
32:50b777bab5a4 | 61 | EXPECT_CALL(mock_target_a, ally_command()); |
Maxime Dupuis |
32:50b777bab5a4 | 62 | EXPECT_CALL(mock_nerfus_ticker, start(1000)); |
Maxime Dupuis |
32:50b777bab5a4 | 63 | EXPECT_CALL(mock_nerfus_ticker, get_time_ms()) |
Maxime Dupuis |
32:50b777bab5a4 | 64 | .WillOnce(::testing::Return(42)); |
Maxime Dupuis |
32:50b777bab5a4 | 65 | EXPECT_CALL(mock_nerfus_ticker, stop()); |
Maxime Dupuis |
32:50b777bab5a4 | 66 | EXPECT_CALL(mock_target_a, hit(42)); |
Maxime Dupuis |
32:50b777bab5a4 | 67 | |
Maxime Dupuis |
32:50b777bab5a4 | 68 | TargetManager target_manager(targets, mock_nerfus_ticker); |
Maxime Dupuis |
32:50b777bab5a4 | 69 | std::vector<TargetInfo> sequence; |
Maxime Dupuis |
32:50b777bab5a4 | 70 | sequence.push_back(make_TargetInfo(0, TARGET_TYPE_ALLY, 1000)); |
Maxime Dupuis |
32:50b777bab5a4 | 71 | target_manager.execute(sequence); |
Maxime Dupuis |
32:50b777bab5a4 | 72 | |
Maxime Dupuis |
32:50b777bab5a4 | 73 | target_manager.target_hit(0); |
Maxime Dupuis |
32:50b777bab5a4 | 74 | } |
Maxime Dupuis |
32:50b777bab5a4 | 75 | |
Maxime Dupuis |
32:50b777bab5a4 | 76 | TEST_F(TargetManagerTest, WhenActiveTargetIsMissedThenSendTheEvent) |
Maxime Dupuis |
32:50b777bab5a4 | 77 | { |
Maxime Dupuis |
32:50b777bab5a4 | 78 | EXPECT_CALL(mock_target_a, ally_command()); |
Maxime Dupuis |
32:50b777bab5a4 | 79 | EXPECT_CALL(mock_nerfus_ticker, start(1000)); |
Maxime Dupuis |
32:50b777bab5a4 | 80 | EXPECT_CALL(mock_nerfus_ticker, get_time_ms()) |
Maxime Dupuis |
32:50b777bab5a4 | 81 | .WillOnce(::testing::Return(42)); |
Maxime Dupuis |
32:50b777bab5a4 | 82 | EXPECT_CALL(mock_nerfus_ticker, stop()); |
Maxime Dupuis |
32:50b777bab5a4 | 83 | EXPECT_CALL(mock_target_a, timeout(42)); |
Maxime Dupuis |
32:50b777bab5a4 | 84 | |
Maxime Dupuis |
32:50b777bab5a4 | 85 | TargetManager target_manager(targets, mock_nerfus_ticker); |
Maxime Dupuis |
32:50b777bab5a4 | 86 | std::vector<TargetInfo> sequence; |
Maxime Dupuis |
32:50b777bab5a4 | 87 | sequence.push_back(make_TargetInfo(0, TARGET_TYPE_ALLY, 1000)); |
Maxime Dupuis |
32:50b777bab5a4 | 88 | target_manager.execute(sequence); |
Maxime Dupuis |
32:50b777bab5a4 | 89 | |
Maxime Dupuis |
32:50b777bab5a4 | 90 | target_manager.target_missed(0); |
Maxime Dupuis |
32:50b777bab5a4 | 91 | } |
Maxime Dupuis |
32:50b777bab5a4 | 92 |