-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into version_format
- Loading branch information
Showing
6 changed files
with
197 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#include "DeviceModeling/device_net.h" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include <memory> | ||
|
||
// This fixture will help in setting up some common setup and teardown for each | ||
// test | ||
class DeviceNetTest : public ::testing::Test { | ||
protected: | ||
void SetUp() override { | ||
// Common setup if required | ||
} | ||
|
||
void TearDown() override { | ||
// Common cleanup if required | ||
} | ||
}; | ||
|
||
// Testing the constructor | ||
TEST_F(DeviceNetTest, ConstructWithNameOnly) { | ||
device_net net("test_net"); | ||
EXPECT_EQ(net.get_net_name(), "test_net"); | ||
EXPECT_EQ(net.get_signal(), nullptr); | ||
} | ||
|
||
// Testing the copy constructor | ||
TEST_F(DeviceNetTest, CopyConstructor) { | ||
device_net net_original("test_net"); | ||
device_net net_copy(net_original); | ||
EXPECT_EQ(net_copy.get_net_name(), "test_net"); | ||
EXPECT_EQ(net_copy.get_signal(), nullptr); | ||
} | ||
|
||
// Testing setter and getter of net name | ||
TEST_F(DeviceNetTest, SetAndGetNetName) { | ||
device_net net("initial_name"); | ||
net.set_net_name("new_name"); | ||
EXPECT_EQ(net.get_net_name(), "new_name"); | ||
} | ||
|
||
// Testing source and sink relationships | ||
TEST_F(DeviceNetTest, SetAndGetSource) { | ||
device_net net("test_net"); | ||
std::shared_ptr<device_net> source_net = | ||
std::make_shared<device_net>("source_net"); | ||
net.set_source(source_net); | ||
EXPECT_EQ(net.get_source(), source_net); | ||
} | ||
|
||
TEST_F(DeviceNetTest, AddAndGetSinks) { | ||
device_net net("test_net"); | ||
std::shared_ptr<device_net> sink1 = std::make_shared<device_net>("sink1"); | ||
std::shared_ptr<device_net> sink2 = std::make_shared<device_net>("sink2"); | ||
|
||
net.add_sink(sink1); | ||
net.add_sink(sink2); | ||
|
||
const auto& sinks = net.get_sink_set(); | ||
EXPECT_EQ(sinks.size(), 2); | ||
EXPECT_NE(sinks.find(sink1), sinks.end()); | ||
EXPECT_NE(sinks.find(sink2), sinks.end()); | ||
} | ||
|
||
// Testing equality functions | ||
TEST_F(DeviceNetTest, EqualityOperators) { | ||
device_net net1("test_net"); | ||
device_net net2("test_net"); | ||
device_net net3("another_net"); | ||
|
||
EXPECT_FALSE(net1 == net2); // Since your == checks for same object reference | ||
EXPECT_TRUE(net1 != net2); // Inverse | ||
EXPECT_FALSE(net1 == net3); | ||
EXPECT_TRUE(net1 != net3); | ||
} | ||
|
||
TEST_F(DeviceNetTest, CheckEqualityFunction) { | ||
device_net net1("test_net"); | ||
device_net net2("test_net"); | ||
device_net net3("another_net"); | ||
|
||
EXPECT_TRUE(net1.equal(net2)); // Since they are separate instances with | ||
// potentially separate sinks, sources etc. | ||
EXPECT_FALSE(net1.equal(net3)); | ||
} | ||
|
||
// Testing string representation functions | ||
TEST_F(DeviceNetTest, ToStringFunction) { | ||
device_net net("test_net"); | ||
std::string expected_start = "Net Name: test_net"; | ||
EXPECT_TRUE(net.to_string().find(expected_start) != std::string::npos); | ||
} | ||
|
||
TEST_F(DeviceNetTest, FormattedStringFunction) { | ||
device_net net("test_net"); | ||
std::string expected_start = "device_net: Net Name: test_net"; | ||
EXPECT_TRUE(net.to_formatted_string().find(expected_start) != | ||
std::string::npos); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* @file rs_parameter_test.cpp | ||
* @author Manadher Kharroubi ([email protected]) | ||
* @brief | ||
* @version 0.1 | ||
* @date 2023-05-18 | ||
* | ||
* @copyright Copyright (c) 2023 | ||
* | ||
*/ | ||
|
||
#include "DeviceModeling/rs_parameter.h" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
TEST(ParameterTest, Constructor) { | ||
auto type = std::make_shared<ParameterType<int>>(); | ||
Parameter<int> param("test", 5, type); | ||
|
||
EXPECT_EQ(param.get_name(), "test"); | ||
EXPECT_EQ(param.get_value(), 5); | ||
} | ||
|
||
TEST(ParameterTest, SetValue) { | ||
auto type = std::make_shared<ParameterType<int>>(); | ||
Parameter<int> param("test", 5, type); | ||
param.set_value(10); | ||
|
||
EXPECT_EQ(param.get_value(), 10); | ||
} | ||
|
||
TEST(ParameterTest, InvalidValue) { | ||
auto type = std::make_shared<ParameterType<int>>(); | ||
|
||
type->set_lower_bound(0); | ||
type->set_upper_bound(10); | ||
EXPECT_THROW(Parameter<int>("test", -1, type), std::runtime_error); | ||
} | ||
|
||
TEST(ParameterTest, SetAddress) { | ||
auto type = std::make_shared<ParameterType<int>>(); | ||
Parameter<int> param("test", 5, type); | ||
param.set_address(123); | ||
|
||
EXPECT_EQ(param.get_address(), 123); | ||
} | ||
|
||
TEST(ParameterTest, IntToString) { | ||
auto type = std::make_shared<ParameterType<int>>(); | ||
Parameter<int> param("test", 5, type); | ||
|
||
EXPECT_EQ(param.to_string(), "Parameter test: 5 of type int"); | ||
} | ||
|
||
TEST(ParameterTest, DoubleToString) { | ||
auto type = std::make_shared<ParameterType<double>>(); | ||
Parameter<double> param("test", 5.5, type); | ||
|
||
EXPECT_EQ(param.to_string(), "Parameter test: 5.5 of type double"); | ||
} | ||
|
||
TEST(ParameterTest, StringToString) { | ||
auto type = std::make_shared<ParameterType<std::string>>(); | ||
Parameter<std::string> param("test", "Test", type); | ||
|
||
EXPECT_EQ(param.to_string(), "Parameter test: Test of type string"); | ||
} | ||
|
||
TEST(ParameterTest, InvalidSetAddress) { | ||
auto type = std::make_shared<ParameterType<double>>(); | ||
Parameter<double> param("test", 5.5, type); | ||
|
||
EXPECT_THROW(param.set_address(123), std::runtime_error); | ||
} |