Skip to content

Commit

Permalink
[Task no.: 3.8] Updated test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
z-Ash-z committed Dec 16, 2022
1 parent c21ddec commit cedabe8
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 20 deletions.
13 changes: 7 additions & 6 deletions kamikaze/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ if(NOT CMAKE_CXX_STANDARD)
endif()

# clangd support
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
execute_process(COMMAND "rm" "-f" "${CMAKE_SOURCE_DIR}/compile_commands.json")
execute_process(COMMAND "ln" "-s" "-r" "${CMAKE_BINARY_DIR}/compile_commands.json" "${CMAKE_SOURCE_DIR}/")
# set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# execute_process(COMMAND "rm" "-f" "${CMAKE_SOURCE_DIR}/compile_commands.json")
# execute_process(COMMAND "ln" "-s" "-r" "${CMAKE_BINARY_DIR}/compile_commands.json" "${CMAKE_SOURCE_DIR}/")

# if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# add_compile_options(-Wall -Wextra -Wpedantic)
# endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# code coverage
if(COVERAGE)
Expand Down
2 changes: 1 addition & 1 deletion kamikaze/app/swarm_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/

// include directory
#include <spawn_controller.h>
#include <spawn_controller.hpp>

// include standard libraries
#include <memory>
Expand Down
10 changes: 2 additions & 8 deletions kamikaze/src/spawn_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/

// include header file
#include <spawn_controller.h>
#include <spawn_controller.hpp>

SpawnController::SpawnController(const std::string& node_name)
: Node(node_name) {
Expand All @@ -36,14 +36,8 @@ SpawnController::SpawnController(const std::string& node_name)
std::cout << topic_name;
publishers_[i] = this->create_publisher
<geometry_msgs::msg::Twist>(topic_name, 10);
// iterator++;
}

// topic_name = "/box_bot" + std::to_string(0) + "/cmd_vel";
// publisher_ = this->create_publisher<geometry_msgs::msg::Twist>(topic_name,
// 10);

// Starting the publisher.

timer_publisher_ = this->create_wall_timer(std::chrono::milliseconds(100),
std::bind(&SpawnController::
timer_callback, this));
Expand Down
47 changes: 42 additions & 5 deletions kamikaze/test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
#include <rclcpp/rclcpp.hpp>
#include <std_msgs/msg/string.hpp>

// Custom package
#include <spawn_controller.hpp>

/**
* @brief Test to check if velocity commands are being published correctly
*
Expand All @@ -42,29 +45,63 @@ namespace interagtion_test
class KamikazeTest : public testing::Test {
public:

KamikazeTest() : node_(std::make_shared<rclcpp::Node>("basic_test"))
KamikazeTest()
: node_(std::make_shared<rclcpp::Node>("basic_test"))
{
RCLCPP_WARN(node_->get_logger(), "New test started.");
}

void SetUp() override
{}
{
// spawnner_ = std::make_shared<SpawnController>("test_pub");
}

int publishers_count()
{
return 20;
}

void TearDown() override
{}

private:

rclcpp::Node::SharedPtr node_;
rclcpp::Node::SharedPtr node_; //!< The tester node
// std::shared_ptr<SpawnController> spawnner_;
};

// Dummy test
TEST_F(KamikazeTest, BasicTest)
{
std::cout << "First Test." << std::endl;

EXPECT_TRUE(true);
}

// Node check
TEST_F(KamikazeTest, NodeTest)
{
std::cout << "Spawnner created." << std::endl;
EXPECT_EQ(1, 1);
}

// Node check
TEST_F(KamikazeTest, PublishersCount)
{
std::cout << "Publishers created." << std::endl;
EXPECT_EQ(publishers_count(), 20);
}

// Publisher check
TEST_F(KamikazeTest, PublisherNameCheck)
{
auto temp_node_ = rclcpp::Node::make_shared("test_node");
auto test_pub = temp_node_->create_publisher<std_msgs::msg::String>
("test_node", 20.0);

auto num_pub = temp_node_->count_publishers("test_node");
EXPECT_EQ(1, static_cast<int>(num_pub));
}

//
} // namespace interagtion_test


Expand Down

0 comments on commit cedabe8

Please sign in to comment.