Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adev4a committed Aug 29, 2023
1 parent b36562f commit 8b28b06
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace subsystem_controllers
//! The time allocated for system startup in seconds
double startup_duration_;
//! The timeout threshold for essential drivers in ms
double driver_timeout_;
double driver_timeout_ = 1000;


// Stream operator for this config
Expand Down
3 changes: 3 additions & 0 deletions subsystem_controllers/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ add_executable(test_carma_lifecycle_node
ament_add_gtest(controllers_gtest
localization_controller_test.cpp
test_plugin_manager.cpp
test_driver_subsystem/test_entry_manager.cpp
test_driver_subsystem/test_driver_manager.cpp
)

target_link_libraries(controllers_gtest
localization_controller_core
guidance_controller_core
drivers_controller_core
)

ament_target_dependencies(test_carma_lifecycle_node ${dependencies} )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ namespace subsystem_controllers
msg0.name = "controller";
msg0.status = carma_driver_msgs::msg::DriverStatus::OPERATIONAL;

// carma_driver_msgs::msg::DriverStatus::SharedPtr msg0_pointer(new carma_driver_msgs::msg::DriverStatus(msg0));
auto msg0_pointer = std::make_shared<carma_driver_msgs::msg::DriverStatus>(msg0);

dm0.update_driver_status(msg0_pointer, 1000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,81 +20,73 @@

namespace subsystem_controllers
{
TEST(EntryManagerTest, testAddNewEntry)
TEST(EntryManagerTest, testNewEntry)
{
// Entry(bool available, bool active, const std::string& name, uint8_t type, const std::string& capability, bool is_ros1)
EntryManager em;
// params: bool available, bool active, std::string name, long timestamp, uint8_t type
Entry entry(true, false, "cruising_plugin", 1, "", 1000, true);
Entry entry(true,"cruising_plugin", 1000);
em.update_entry(entry);


std::vector<Entry> res = em.get_entries();
EXPECT_EQ(1, res.size());
EXPECT_EQ(true, res.begin()->available_);
EXPECT_EQ(false, res.begin()->active_);
EXPECT_EQ("cruising_plugin", res.begin()->name_);
EXPECT_EQ(1000, res.begin()->timestamp_);
EXPECT_EQ(1, res.begin()->type_);

}

TEST(EntryManagerTest, testUpdateEntry)
TEST(EntryManagerTest, testUpdatedEntry)
{
EntryManager em;
// params: bool available, bool active, std::string name, long timestamp, uint8_t type
Entry entry(true, false, "cruising_plugin", 1, "", 1000, true);
Entry entry(true, "cruising_plugin", 1000);
em.update_entry(entry);
Entry new_entry(false, true, "cruising_plugin", 3, "", 2000, true);
Entry new_entry(false, "cruising_plugin", 2000);
em.update_entry(new_entry);
std::vector<Entry> res = em.get_entries();
EXPECT_EQ(1, res.size());
EXPECT_EQ(false, res.begin()->available_);
EXPECT_EQ(true, res.begin()->active_);
EXPECT_EQ(2000, res.begin()->timestamp_);
// the following two attributes should not change once set
EXPECT_EQ("cruising_plugin", res.begin()->name_);
EXPECT_EQ(1, res.begin()->type_);
}

TEST(EntryManagerTest, testDeleteEntry)
TEST(EntryManagerTest, testDeletedEntry)
{
EntryManager em;
// params: bool available, bool active, std::string name, long timestamp, uint8_t type
Entry entry(true, false, "cruising_plugin", 1, "", 1000, true);
Entry entry(true, "cruising_plugin",1000);
em.update_entry(entry);
Entry new_entry(false, true, "cruising_plugin_2", 3, "", 2000, true);
Entry new_entry(false, "cruising_plugin_2", 2000);
em.update_entry(new_entry);
em.delete_entry("cruising_plugin");
std::vector<Entry> res = em.get_entries();
EXPECT_EQ(1, res.size());
EXPECT_EQ(false, res.begin()->available_);
EXPECT_EQ(true, res.begin()->active_);
EXPECT_EQ(2000, res.begin()->timestamp_);
// the following two attributes should not change once set
EXPECT_EQ("cruising_plugin_2", res.begin()->name_);
EXPECT_EQ(3, res.begin()->type_);
}

TEST(EntryManagerTest, testGetEntryByValidName)
TEST(EntryManagerTest, testGetEntryWithValidName)
{
EntryManager em;
// params: bool available, bool active, std::string name, long timestamp, uint8_t type
Entry entry(true, false, "cruising_plugin", 1, "", 1000, true);
Entry entry(true, "cruising_plugin", 1000);
em.update_entry(entry);
boost::optional<Entry> res = em.get_entry_by_name("cruising_plugin");
EXPECT_EQ(true, res->available_);
EXPECT_EQ(false, res->active_);
EXPECT_EQ(1000, res->timestamp_);
EXPECT_EQ(1, res->type_);
EXPECT_EQ("cruising_plugin", res->name_);
}

TEST(EntryManagerTest, testGetEntryByInvalidName)
TEST(EntryManagerTest, testGetEntryWithInvalidName)
{
EntryManager em;
// params: bool available, bool active, std::string name, long timestamp, uint8_t type
Entry entry(true, false, "cruising_plugin", 1, "", 1000, true);
Entry entry(true, "cruising_plugin", true);
em.update_entry(entry);
boost::optional<Entry> res = em.get_entry_by_name("plugin");
if(!res)
Expand All @@ -106,15 +98,15 @@ namespace subsystem_controllers
}
}

TEST(EntryManagerTest, testRequiredEntryCheck)
TEST(EntryManagerTest, testRequiredEntry)
{
std::vector<std::string> required_names;
required_names.push_back("cruising");
required_names.push_back("cruising_plugin");
EntryManager em(required_names);
Entry entry(true, false, "cruising_plugin", 1, "", 1000, true);
Entry entry(true, "cruising_plugin", 1000);
em.update_entry(entry);
Entry new_entry(false, true, "cruising_plugin_2", 3, "", 2000, true);
Entry new_entry(false, "cruising_plugin_2", 2000);
em.update_entry(new_entry);
EXPECT_EQ(true, em.is_entry_required("cruising_plugin"));
EXPECT_EQ(true, em.is_entry_required("cruising"));
Expand Down

0 comments on commit 8b28b06

Please sign in to comment.