Skip to content

Commit

Permalink
Merge branch 'feat/cgnode-tests' into 'devel'
Browse files Browse the repository at this point in the history
[Graph] Adds CgNode unit tests

See merge request tuda-sc/projects/metacg!172
  • Loading branch information
jplehr committed Nov 4, 2024
2 parents 7dcae47 + e43f600 commit 1fd81fd
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
81 changes: 81 additions & 0 deletions graph/test/unit/CGNodeTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* File: CGNodeTests.cpp
* License: Part of the MetaCG project. Licensed under BSD 3 clause license. See LICENSE.txt file at
* https://github.com/tudasc/metacg/LICENSE.txt
*/

#include "CgNode.h"
#include "gtest/gtest.h"

TEST(CgNode, CreateNodeOnlyName) {
auto n = new metacg::CgNode("foo");
EXPECT_NE(n, nullptr);
EXPECT_EQ(n->getFunctionName(), "foo");

delete n;
}

TEST(CgNode, CreateNodeNameAndOrigin) {
auto n = new metacg::CgNode("foo", "origin:21");

EXPECT_NE(n, nullptr);
EXPECT_EQ(n->getFunctionName(), "foo");
EXPECT_EQ((n->getOrigin()), "origin:21");

delete n;
}

TEST(CgNode, NodesSame) {
auto n = new metacg::CgNode("foo");
auto nn = new metacg::CgNode("foo");

EXPECT_NE(n, nullptr);
EXPECT_NE(nn, nullptr);
EXPECT_TRUE(n->isSameFunctionName(*nn));
EXPECT_TRUE(nn->isSameFunctionName(*n));

delete n;
delete nn;
}

TEST(CgNode, NodesNotSameName) {
auto n = new metacg::CgNode("foo");
auto nn = new metacg::CgNode("bar");

EXPECT_NE(n, nullptr);
EXPECT_NE(nn, nullptr);
EXPECT_FALSE(n->isSameFunctionName(*nn));
EXPECT_FALSE(nn->isSameFunctionName(*n));

delete n;
delete nn;
}

TEST(CgNode, NodesNameAndOriginSame) {
auto n = new metacg::CgNode("foo", "origin:a");
auto nn = new metacg::CgNode("foo", "origin:a");

EXPECT_NE(n, nullptr);
EXPECT_NE(nn, nullptr);
EXPECT_TRUE(n->isSameFunctionName(*nn));
EXPECT_TRUE(nn->isSameFunctionName(*n));

delete n;
delete nn;
}

TEST(CgNode, NodesNameAndOriginNotSame) {
auto n = new metacg::CgNode("foo", "origin:a");
auto nn = new metacg::CgNode("foo", "origin:b");

EXPECT_NE(n, nullptr);
EXPECT_NE(nn, nullptr);
EXPECT_TRUE(n->isSameFunctionName(*nn));
EXPECT_TRUE(nn->isSameFunctionName(*n));

EXPECT_FALSE(n->isSameFunction(*nn));
EXPECT_FALSE(nn->isSameFunction(*n));

delete n;
delete nn;
}
1 change: 1 addition & 0 deletions graph/test/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Now simply link against gtest or gtest_main as needed.Eg
add_executable(
libtests
CGNodeTests.cpp
DotIOTest.cpp
MCGManagerTest.cpp
ReachabilityAnalysisTest.cpp
Expand Down

0 comments on commit 1fd81fd

Please sign in to comment.