Skip to content

Commit 0afb4ef

Browse files
committed
Replace TestSection with BlockSectionMock
1 parent 279cd24 commit 0afb4ef

File tree

5 files changed

+51
-52
lines changed

5 files changed

+51
-52
lines changed

test/engine/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
add_executable(
22
engine_test
33
engine_test.cpp
4-
testsection.cpp
5-
testsection.h
64
)
75

86
target_link_libraries(

test/engine/engine_test.cpp

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
#include <audiooutputmock.h>
1818
#include <audioplayermock.h>
1919
#include <monitorhandlermock.h>
20+
#include <blocksectionmock.h>
2021
#include <thread>
2122

2223
#include "../common.h"
23-
#include "testsection.h"
2424
#include "engine/internal/engine.h"
2525
#include "engine/internal/clock.h"
2626

@@ -77,7 +77,8 @@ TEST(EngineTest, Clear)
7777
auto broadcast2 = std::make_shared<Broadcast>("", "");
7878
engine.setBroadcasts({ broadcast1, broadcast2 });
7979

80-
auto section = std::make_shared<TestSection>();
80+
auto section = std::make_shared<BlockSectionMock>();
81+
EXPECT_CALL(*section, registerBlocks);
8182
engine.registerSection(section);
8283

8384
auto monitor1 = std::make_shared<Monitor>("", "");
@@ -126,7 +127,8 @@ TEST(EngineTest, CompileAndExecuteMonitors)
126127
m2->setSprite(sprite.get());
127128
engine.setMonitors({ m1, m2 });
128129

129-
auto section = std::make_shared<TestSection>();
130+
auto section = std::make_shared<BlockSectionMock>();
131+
EXPECT_CALL(*section, registerBlocks);
130132
engine.registerSection(section);
131133
engine.addCompileFunction(section.get(), m1->opcode(), [](Compiler *compiler) { compiler->addConstValue(5.4); });
132134
engine.addCompileFunction(section.get(), m2->opcode(), [](Compiler *compiler) { compiler->addConstValue("test"); });
@@ -859,12 +861,16 @@ TEST(EngineTest, Sections)
859861
{
860862
Engine engine;
861863

862-
auto section1 = std::make_shared<TestSection>();
864+
auto section1 = std::make_shared<BlockSectionMock>();
865+
EXPECT_CALL(*section1, registerBlocks(&engine));
863866
engine.registerSection(section1);
864867

865-
auto section2 = std::make_shared<TestSection>();
868+
auto section2 = std::make_shared<BlockSectionMock>();
869+
EXPECT_CALL(*section2, registerBlocks(&engine));
866870
engine.registerSection(section2);
867871

872+
EXPECT_CALL(*section1, name()).WillOnce(Return("test"));
873+
EXPECT_CALL(*section1, registerBlocks).Times(0);
868874
engine.registerSection(section1); // register existing section
869875

870876
ASSERT_EQ(engine.registeredSections().size(), 2);
@@ -908,15 +914,17 @@ TEST(EngineTest, CompileFunctions)
908914
{
909915
Engine engine;
910916

911-
auto section1 = std::make_shared<TestSection>();
917+
auto section1 = std::make_shared<BlockSectionMock>();
918+
EXPECT_CALL(*section1, registerBlocks);
912919
engine.registerSection(section1);
913920
auto container1 = engine.blockSectionContainer(section1.get());
914921

915-
auto section2 = std::make_shared<TestSection>();
922+
auto section2 = std::make_shared<BlockSectionMock>();
923+
EXPECT_CALL(*section2, registerBlocks);
916924
engine.registerSection(section2);
917925
auto container2 = engine.blockSectionContainer(section2.get());
918926

919-
TestSection section3;
927+
BlockSectionMock section3;
920928

921929
engine.addCompileFunction(section1.get(), "test1", &compileTest1);
922930
engine.addCompileFunction(section2.get(), "test2", &compileTest2);
@@ -933,15 +941,17 @@ TEST(EngineTest, HatBlocks)
933941
{
934942
Engine engine;
935943

936-
auto section1 = std::make_shared<TestSection>();
944+
auto section1 = std::make_shared<BlockSectionMock>();
945+
EXPECT_CALL(*section1, registerBlocks);
937946
engine.registerSection(section1);
938947
auto container1 = engine.blockSectionContainer(section1.get());
939948

940-
auto section2 = std::make_shared<TestSection>();
949+
auto section2 = std::make_shared<BlockSectionMock>();
950+
EXPECT_CALL(*section2, registerBlocks);
941951
engine.registerSection(section2);
942952
auto container2 = engine.blockSectionContainer(section2.get());
943953

944-
TestSection section3;
954+
BlockSectionMock section3;
945955

946956
engine.addHatBlock(section1.get(), "test1");
947957
engine.addHatBlock(section2.get(), "test2");
@@ -958,15 +968,17 @@ TEST(EngineTest, Inputs)
958968
{
959969
Engine engine;
960970

961-
auto section1 = std::make_shared<TestSection>();
971+
auto section1 = std::make_shared<BlockSectionMock>();
972+
EXPECT_CALL(*section1, registerBlocks);
962973
engine.registerSection(section1);
963974
auto container1 = engine.blockSectionContainer(section1.get());
964975

965-
auto section2 = std::make_shared<TestSection>();
976+
auto section2 = std::make_shared<BlockSectionMock>();
977+
EXPECT_CALL(*section2, registerBlocks);
966978
engine.registerSection(section2);
967979
auto container2 = engine.blockSectionContainer(section2.get());
968980

969-
TestSection section3;
981+
BlockSectionMock section3;
970982

971983
engine.addInput(section1.get(), "VALUE1", 1);
972984
engine.addInput(section2.get(), "VALUE2", 2);
@@ -985,15 +997,17 @@ TEST(EngineTest, Fields)
985997
{
986998
Engine engine;
987999

988-
auto section1 = std::make_shared<TestSection>();
1000+
auto section1 = std::make_shared<BlockSectionMock>();
1001+
EXPECT_CALL(*section1, registerBlocks);
9891002
engine.registerSection(section1);
9901003
auto container1 = engine.blockSectionContainer(section1.get());
9911004

992-
auto section2 = std::make_shared<TestSection>();
1005+
auto section2 = std::make_shared<BlockSectionMock>();
1006+
EXPECT_CALL(*section2, registerBlocks);
9931007
engine.registerSection(section2);
9941008
auto container2 = engine.blockSectionContainer(section2.get());
9951009

996-
TestSection section3;
1010+
BlockSectionMock section3;
9971011

9981012
engine.addField(section1.get(), "VALUE1", 1);
9991013
engine.addField(section2.get(), "VALUE2", 2);
@@ -1012,15 +1026,17 @@ TEST(EngineTest, FieldValues)
10121026
{
10131027
Engine engine;
10141028

1015-
auto section1 = std::make_shared<TestSection>();
1029+
auto section1 = std::make_shared<BlockSectionMock>();
1030+
EXPECT_CALL(*section1, registerBlocks);
10161031
engine.registerSection(section1);
10171032
auto container1 = engine.blockSectionContainer(section1.get());
10181033

1019-
auto section2 = std::make_shared<TestSection>();
1034+
auto section2 = std::make_shared<BlockSectionMock>();
1035+
EXPECT_CALL(*section2, registerBlocks);
10201036
engine.registerSection(section2);
10211037
auto container2 = engine.blockSectionContainer(section2.get());
10221038

1023-
TestSection section3;
1039+
BlockSectionMock section3;
10241040

10251041
engine.addFieldValue(section1.get(), "value1", 1);
10261042
engine.addFieldValue(section2.get(), "value2", 2);

test/engine/testsection.cpp

Lines changed: 0 additions & 14 deletions
This file was deleted.

test/engine/testsection.h

Lines changed: 0 additions & 16 deletions
This file was deleted.

test/mocks/blocksectionmock.h

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

0 commit comments

Comments
 (0)