Skip to content

Commit ef49bc9

Browse files
authored
Merge pull request #172 from scratchcpp/iblocksection_test
Add IBlockSection test
2 parents c03ad04 + 8827fbb commit ef49bc9

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed

test/extensions/CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,21 @@ target_link_libraries(
1515
)
1616

1717
gtest_discover_tests(iextension_test)
18+
19+
# iblocksection_test
20+
add_executable(
21+
iblocksection_test
22+
iblocksection_test.cpp
23+
testsection.cpp
24+
testsection.h
25+
)
26+
27+
target_link_libraries(
28+
iblocksection_test
29+
GTest::gtest_main
30+
GTest::gmock_main
31+
scratchcpp
32+
scratchcpp_mocks
33+
)
34+
35+
gtest_discover_tests(iblocksection_test)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <enginemock.h>
2+
3+
#include "../common.h"
4+
#include "testsection.h"
5+
6+
using namespace libscratchcpp;
7+
8+
class IBlockSectionTest : public testing::Test
9+
{
10+
public:
11+
void SetUp() override { m_section = std::make_unique<TestSection>(); };
12+
13+
std::unique_ptr<IBlockSection> m_section;
14+
EngineMock m_engine;
15+
};
16+
17+
TEST_F(IBlockSectionTest, Name)
18+
{
19+
ASSERT_EQ(m_section->name(), "Test");
20+
}
21+
22+
TEST_F(IBlockSectionTest, CategoryVisible)
23+
{
24+
ASSERT_TRUE(m_section->categoryVisible());
25+
}
26+
27+
TEST_F(IBlockSectionTest, RegisterBlocks)
28+
{
29+
EXPECT_CALL(m_engine, addCompileFunction(m_section.get(), "", nullptr)).Times(1);
30+
m_section->registerBlocks(&m_engine);
31+
}

test/extensions/testsection.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <scratchcpp/iengine.h>
2+
3+
#include "testsection.h"
4+
5+
using namespace libscratchcpp;
6+
7+
std::string TestSection::name() const
8+
{
9+
return "Test";
10+
}
11+
12+
bool TestSection::categoryVisible() const
13+
{
14+
return IBlockSection::categoryVisible();
15+
}
16+
17+
void TestSection::registerBlocks(IEngine *engine)
18+
{
19+
engine->addCompileFunction(this, "", nullptr);
20+
}

test/extensions/testsection.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#pragma once
2+
3+
#include <scratchcpp/iblocksection.h>
4+
5+
namespace libscratchcpp
6+
{
7+
8+
class TestSection : public IBlockSection
9+
{
10+
public:
11+
std::string name() const override;
12+
13+
bool categoryVisible() const override;
14+
15+
void registerBlocks(IEngine *engine) override;
16+
};
17+
18+
} // namespace libscratchcpp

0 commit comments

Comments
 (0)