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@38:70a1c8bd2877, 2017-04-09 (annotated)
- Committer:
- Maxime Dupuis
- Date:
- Sun Apr 09 13:12:22 2017 -0400
- Revision:
- 38:70a1c8bd2877
- Parent:
- 37:8fc7845ae95b
- Child:
- 51:6bf268cd1a1b
TargetManager constructor takes array of tickers
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 |
35:7ee45f6d6484 | 8 | #include "stdint.h" |
Maxime Dupuis |
35:7ee45f6d6484 | 9 | |
Maxime Dupuis |
28:8fc53a870691 | 10 | class TargetManagerTest : public ::testing::Test |
Maxime Dupuis |
28:8fc53a870691 | 11 | { |
Maxime Dupuis |
28:8fc53a870691 | 12 | public: |
Maxime Dupuis |
28:8fc53a870691 | 13 | TargetManagerTest() |
Maxime Dupuis |
28:8fc53a870691 | 14 | { |
Maxime Dupuis |
30:412a779cf607 | 15 | targets.push_back(&mock_target_a); |
Maxime Dupuis |
30:412a779cf607 | 16 | targets.push_back(&mock_target_b); |
Maxime Dupuis |
38:70a1c8bd2877 | 17 | |
Maxime Dupuis |
38:70a1c8bd2877 | 18 | tickers.push_back(&mock_nerfus_ticker_a); |
Maxime Dupuis |
38:70a1c8bd2877 | 19 | tickers.push_back(&mock_nerfus_ticker_b); |
Maxime Dupuis |
28:8fc53a870691 | 20 | } |
Maxime Dupuis |
28:8fc53a870691 | 21 | |
Maxime Dupuis |
30:412a779cf607 | 22 | MockTarget mock_target_a; |
Maxime Dupuis |
30:412a779cf607 | 23 | MockTarget mock_target_b; |
Maxime Dupuis |
30:412a779cf607 | 24 | std::vector<TargetInterface*> targets; |
Maxime Dupuis |
30:412a779cf607 | 25 | |
Maxime Dupuis |
38:70a1c8bd2877 | 26 | MockNerfusTicker mock_nerfus_ticker_a; |
Maxime Dupuis |
38:70a1c8bd2877 | 27 | MockNerfusTicker mock_nerfus_ticker_b; |
Maxime Dupuis |
38:70a1c8bd2877 | 28 | std::vector<NerfusTickerInterface*> tickers; |
Maxime Dupuis |
28:8fc53a870691 | 29 | }; |
Maxime Dupuis |
28:8fc53a870691 | 30 | |
Maxime Dupuis |
28:8fc53a870691 | 31 | TEST_F(TargetManagerTest, LibraryBuilds) |
Maxime Dupuis |
28:8fc53a870691 | 32 | { |
Maxime Dupuis |
38:70a1c8bd2877 | 33 | TargetManager target_manager(targets, tickers); |
Maxime Dupuis |
28:8fc53a870691 | 34 | } |
Maxime Dupuis |
28:8fc53a870691 | 35 | |
Maxime Dupuis |
31:c6dc9811ed14 | 36 | TEST_F(TargetManagerTest, WhenNoTargetIsActiveThenCallsToTargetHitAndTargetMissedDoNothing) |
Maxime Dupuis |
31:c6dc9811ed14 | 37 | { |
Maxime Dupuis |
38:70a1c8bd2877 | 38 | TargetManager target_manager(targets, tickers); |
Maxime Dupuis |
31:c6dc9811ed14 | 39 | |
Maxime Dupuis |
31:c6dc9811ed14 | 40 | target_manager.target_missed(0); |
Maxime Dupuis |
31:c6dc9811ed14 | 41 | target_manager.target_hit(0); |
Maxime Dupuis |
31:c6dc9811ed14 | 42 | } |
Maxime Dupuis |
32:50b777bab5a4 | 43 | |
Maxime Dupuis |
32:50b777bab5a4 | 44 | TEST_F(TargetManagerTest, WhenExecutingAllyTargetThenUseTheCorrectTargetTypeAndTimeout) |
Maxime Dupuis |
32:50b777bab5a4 | 45 | { |
Maxime Dupuis |
32:50b777bab5a4 | 46 | EXPECT_CALL(mock_target_a, ally_command()); |
Maxime Dupuis |
38:70a1c8bd2877 | 47 | EXPECT_CALL(mock_nerfus_ticker_a, start(1000)); |
Maxime Dupuis |
32:50b777bab5a4 | 48 | |
Maxime Dupuis |
38:70a1c8bd2877 | 49 | TargetManager target_manager(targets, tickers); |
Maxime Dupuis |
34:85994e0501fb | 50 | target_manager.execute(make_TargetInfo(0, TARGET_TYPE_ALLY, 1000)); |
Maxime Dupuis |
32:50b777bab5a4 | 51 | } |
Maxime Dupuis |
32:50b777bab5a4 | 52 | |
Maxime Dupuis |
32:50b777bab5a4 | 53 | TEST_F(TargetManagerTest, WhenExecutingEnemyTargetThenUseTheCorrectTargetTypeAndTimeout) |
Maxime Dupuis |
32:50b777bab5a4 | 54 | { |
Maxime Dupuis |
32:50b777bab5a4 | 55 | EXPECT_CALL(mock_target_b, enemy_command()); |
Maxime Dupuis |
38:70a1c8bd2877 | 56 | EXPECT_CALL(mock_nerfus_ticker_b, start(2000)); |
Maxime Dupuis |
32:50b777bab5a4 | 57 | |
Maxime Dupuis |
38:70a1c8bd2877 | 58 | TargetManager target_manager(targets, tickers); |
Maxime Dupuis |
34:85994e0501fb | 59 | target_manager.execute(make_TargetInfo(1, TARGET_TYPE_ENEMY, 2000)); |
Maxime Dupuis |
32:50b777bab5a4 | 60 | } |
Maxime Dupuis |
32:50b777bab5a4 | 61 | |
Maxime Dupuis |
32:50b777bab5a4 | 62 | TEST_F(TargetManagerTest, WhenActiveTargetIsHitThenSendTheEvent) |
Maxime Dupuis |
32:50b777bab5a4 | 63 | { |
Maxime Dupuis |
32:50b777bab5a4 | 64 | EXPECT_CALL(mock_target_a, ally_command()); |
Maxime Dupuis |
38:70a1c8bd2877 | 65 | EXPECT_CALL(mock_nerfus_ticker_a, start(1000)); |
Maxime Dupuis |
38:70a1c8bd2877 | 66 | EXPECT_CALL(mock_nerfus_ticker_a, get_time_ms()) |
Maxime Dupuis |
32:50b777bab5a4 | 67 | .WillOnce(::testing::Return(42)); |
Maxime Dupuis |
38:70a1c8bd2877 | 68 | EXPECT_CALL(mock_nerfus_ticker_a, stop()); |
Maxime Dupuis |
32:50b777bab5a4 | 69 | EXPECT_CALL(mock_target_a, hit(42)); |
Maxime Dupuis |
32:50b777bab5a4 | 70 | |
Maxime Dupuis |
38:70a1c8bd2877 | 71 | TargetManager target_manager(targets, tickers); |
Maxime Dupuis |
34:85994e0501fb | 72 | target_manager.execute(make_TargetInfo(0, TARGET_TYPE_ALLY, 1000)); |
Maxime Dupuis |
32:50b777bab5a4 | 73 | |
Maxime Dupuis |
32:50b777bab5a4 | 74 | target_manager.target_hit(0); |
Maxime Dupuis |
32:50b777bab5a4 | 75 | } |
Maxime Dupuis |
32:50b777bab5a4 | 76 | |
Maxime Dupuis |
32:50b777bab5a4 | 77 | TEST_F(TargetManagerTest, WhenActiveTargetIsMissedThenSendTheEvent) |
Maxime Dupuis |
32:50b777bab5a4 | 78 | { |
Maxime Dupuis |
32:50b777bab5a4 | 79 | EXPECT_CALL(mock_target_a, ally_command()); |
Maxime Dupuis |
38:70a1c8bd2877 | 80 | EXPECT_CALL(mock_nerfus_ticker_a, start(1000)); |
Maxime Dupuis |
38:70a1c8bd2877 | 81 | EXPECT_CALL(mock_nerfus_ticker_a, get_time_ms()) |
Maxime Dupuis |
32:50b777bab5a4 | 82 | .WillOnce(::testing::Return(42)); |
Maxime Dupuis |
38:70a1c8bd2877 | 83 | EXPECT_CALL(mock_nerfus_ticker_a, stop()); |
Maxime Dupuis |
32:50b777bab5a4 | 84 | EXPECT_CALL(mock_target_a, timeout(42)); |
Maxime Dupuis |
32:50b777bab5a4 | 85 | |
Maxime Dupuis |
38:70a1c8bd2877 | 86 | TargetManager target_manager(targets, tickers); |
Maxime Dupuis |
34:85994e0501fb | 87 | target_manager.execute(make_TargetInfo(0, TARGET_TYPE_ALLY, 1000)); |
Maxime Dupuis |
32:50b777bab5a4 | 88 | |
Maxime Dupuis |
32:50b777bab5a4 | 89 | target_manager.target_missed(0); |
Maxime Dupuis |
32:50b777bab5a4 | 90 | } |
Maxime Dupuis |
32:50b777bab5a4 | 91 | |
Maxime Dupuis |
35:7ee45f6d6484 | 92 | TEST_F(TargetManagerTest, WhenReceivingCommandInBytesThenExecuteIt) |
Maxime Dupuis |
35:7ee45f6d6484 | 93 | { |
Maxime Dupuis |
38:70a1c8bd2877 | 94 | TargetManager target_manager(targets, tickers); |
Maxime Dupuis |
35:7ee45f6d6484 | 95 | |
Maxime Dupuis |
35:7ee45f6d6484 | 96 | EXPECT_CALL(mock_target_b, ally_command()); |
Maxime Dupuis |
38:70a1c8bd2877 | 97 | EXPECT_CALL(mock_nerfus_ticker_b, start(0x1234)); |
Maxime Dupuis |
35:7ee45f6d6484 | 98 | |
Maxime Dupuis |
35:7ee45f6d6484 | 99 | std::vector<uint8_t> target_info_bytes; |
Maxime Dupuis |
35:7ee45f6d6484 | 100 | target_info_bytes.push_back(0x01); //Second target |
Maxime Dupuis |
35:7ee45f6d6484 | 101 | target_info_bytes.push_back(0x00); //Mode ally |
Maxime Dupuis |
35:7ee45f6d6484 | 102 | target_info_bytes.push_back(0x12); //Timeout MSB |
Maxime Dupuis |
35:7ee45f6d6484 | 103 | target_info_bytes.push_back(0x34); //Timeout MSB |
Maxime Dupuis |
35:7ee45f6d6484 | 104 | |
Maxime Dupuis |
35:7ee45f6d6484 | 105 | target_manager.execute(target_info_bytes); |
Maxime Dupuis |
35:7ee45f6d6484 | 106 | } |
Maxime Dupuis |
35:7ee45f6d6484 | 107 |