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
TargetManagerTest.cpp
00001 #include "gmock/gmock.h" 00002 #include "gtest/gtest.h" 00003 00004 #include "mocks/MockNerfusTicker.hpp" 00005 #include "mocks/MockTarget.hpp" 00006 #include "TargetManager.hpp" 00007 00008 #include "stdint.h" 00009 00010 class TargetManagerTest : public ::testing::Test 00011 { 00012 public: 00013 TargetManagerTest() 00014 { 00015 targets.push_back(&mock_target_a); 00016 targets.push_back(&mock_target_b); 00017 00018 tickers.push_back(&mock_nerfus_ticker_a); 00019 tickers.push_back(&mock_nerfus_ticker_b); 00020 } 00021 00022 MockTarget mock_target_a; 00023 MockTarget mock_target_b; 00024 std::vector<TargetInterface*> targets; 00025 00026 MockNerfusTicker mock_nerfus_ticker_a; 00027 MockNerfusTicker mock_nerfus_ticker_b; 00028 std::vector<NerfusTickerInterface*> tickers; 00029 }; 00030 00031 TEST_F(TargetManagerTest, LibraryBuilds) 00032 { 00033 TargetManager target_manager(targets, tickers); 00034 } 00035 00036 TEST_F(TargetManagerTest, WhenNoTargetIsActiveThenCallsToTargetHitAndTargetMissedDoNothing) 00037 { 00038 TargetManager target_manager(targets, tickers); 00039 00040 target_manager.target_missed(0); 00041 target_manager.target_hit(0); 00042 } 00043 00044 TEST_F(TargetManagerTest, WhenExecutingAllyTargetThenUseTheCorrectTargetTypeAndTimeout) 00045 { 00046 EXPECT_CALL(mock_target_a, ally_command()); 00047 EXPECT_CALL(mock_nerfus_ticker_a, start(1000)); 00048 00049 TargetManager target_manager(targets, tickers); 00050 target_manager.execute(make_TargetInfo(0, TARGET_TYPE_ALLY, 1000)); 00051 } 00052 00053 TEST_F(TargetManagerTest, WhenExecutingEnemyTargetThenUseTheCorrectTargetTypeAndTimeout) 00054 { 00055 EXPECT_CALL(mock_target_b, enemy_command()); 00056 EXPECT_CALL(mock_nerfus_ticker_b, start(2000)); 00057 00058 TargetManager target_manager(targets, tickers); 00059 target_manager.execute(make_TargetInfo(1, TARGET_TYPE_ENEMY, 2000)); 00060 } 00061 00062 TEST_F(TargetManagerTest, WhenActiveTargetIsHitThenSendTheEvent) 00063 { 00064 EXPECT_CALL(mock_target_a, ally_command()); 00065 EXPECT_CALL(mock_nerfus_ticker_a, start(1200)); 00066 EXPECT_CALL(mock_nerfus_ticker_a, get_time_ms()) 00067 .WillOnce(::testing::Return(1200)); 00068 EXPECT_CALL(mock_nerfus_ticker_a, stop()); 00069 EXPECT_CALL(mock_target_a, hit(1200)); 00070 00071 TargetManager target_manager(targets, tickers); 00072 target_manager.execute(make_TargetInfo(0, TARGET_TYPE_ALLY, 1200)); 00073 00074 target_manager.target_hit(0); 00075 } 00076 00077 TEST_F(TargetManagerTest, WhenActiveTargetIsHitTooSoonBefore750MsThenIgnoreTheEvent) 00078 { 00079 EXPECT_CALL(mock_target_a, ally_command()); 00080 EXPECT_CALL(mock_nerfus_ticker_a, start(700)); 00081 EXPECT_CALL(mock_nerfus_ticker_a, get_time_ms()) 00082 .WillOnce(::testing::Return(700)); 00083 00084 TargetManager target_manager(targets, tickers); 00085 target_manager.execute(make_TargetInfo(0, TARGET_TYPE_ALLY, 700)); 00086 00087 target_manager.target_hit(0); 00088 } 00089 00090 TEST_F(TargetManagerTest, WhenActiveTargetIsMissedThenSendTheEvent) 00091 { 00092 EXPECT_CALL(mock_target_a, ally_command()); 00093 EXPECT_CALL(mock_nerfus_ticker_a, start(1000)); 00094 EXPECT_CALL(mock_nerfus_ticker_a, get_time_ms()) 00095 .WillOnce(::testing::Return(42)); 00096 EXPECT_CALL(mock_nerfus_ticker_a, stop()); 00097 EXPECT_CALL(mock_target_a, timeout(42)); 00098 00099 TargetManager target_manager(targets, tickers); 00100 target_manager.execute(make_TargetInfo(0, TARGET_TYPE_ALLY, 1000)); 00101 00102 target_manager.target_missed(0); 00103 } 00104 00105 TEST_F(TargetManagerTest, WhenReceivingCommandInBytesThenExecuteIt) 00106 { 00107 TargetManager target_manager(targets, tickers); 00108 00109 EXPECT_CALL(mock_target_b, ally_command()); 00110 EXPECT_CALL(mock_nerfus_ticker_b, start(0x1234)); 00111 00112 std::vector<uint8_t> target_info_bytes; 00113 target_info_bytes.push_back(0x01); //Second target 00114 target_info_bytes.push_back(0x00); //Mode ally 00115 target_info_bytes.push_back(0x12); //Timeout MSB 00116 target_info_bytes.push_back(0x34); //Timeout MSB 00117 00118 target_manager.execute(target_info_bytes); 00119 } 00120
Generated on Thu Jul 14 2022 01:50:39 by
1.7.2
