Skip to content

Commit 0343ff2

Browse files
committed
Add IScratchStage tests
1 parent de1b314 commit 0343ff2

File tree

4 files changed

+98
-0
lines changed

4 files changed

+98
-0
lines changed

test/target_interfaces/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,19 @@ target_link_libraries(
1313
)
1414

1515
gtest_discover_tests(iscratchsprite_test)
16+
17+
# iscratchstage_test
18+
add_executable(
19+
iscratchstage_test
20+
iscratchstage_test.cpp
21+
teststageinterface.cpp
22+
teststageinterface.h
23+
)
24+
25+
target_link_libraries(
26+
iscratchstage_test
27+
GTest::gtest_main
28+
scratchcpp
29+
)
30+
31+
gtest_discover_tests(iscratchstage_test)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include "scratch/stage.h"
2+
#include "teststageinterface.h"
3+
#include "../common.h"
4+
5+
#define INIT_STAGE() stage.setInterface(&stageInterface);
6+
7+
using namespace libscratchcpp;
8+
9+
Stage stage;
10+
TestStageInterface stageInterface;
11+
12+
TEST(IScratchStageTest, Tempo)
13+
{
14+
INIT_STAGE();
15+
stage.setTempo(120);
16+
ASSERT_EQ(stageInterface.tempo, 120);
17+
stage.setTempo(55);
18+
ASSERT_EQ(stage.tempo(), 55);
19+
}
20+
21+
TEST(IScratchStageTest, VideoState)
22+
{
23+
INIT_STAGE();
24+
stage.setVideoState(Stage::VideoState::On);
25+
ASSERT_EQ(stageInterface.videoState, Stage::VideoState::On);
26+
stage.setVideoState(Stage::VideoState::OnFlipped);
27+
ASSERT_EQ(stageInterface.videoState, Stage::VideoState::OnFlipped);
28+
}
29+
30+
TEST(IScratchStageTest, CostumeData)
31+
{
32+
INIT_STAGE();
33+
// TODO: Add tests for costume data
34+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include "teststageinterface.h"
2+
3+
TestStageInterface::TestStageInterface()
4+
{
5+
}
6+
7+
void TestStageInterface::setTempo(int tempo)
8+
{
9+
this->tempo = tempo;
10+
}
11+
12+
void TestStageInterface::setVideoState(Stage::VideoState videoState)
13+
{
14+
this->videoState = videoState;
15+
}
16+
17+
void TestStageInterface::setVideoTransparency(int videoTransparency)
18+
{
19+
this->videoTrasparency = videoTransparency;
20+
}
21+
22+
void TestStageInterface::setCostume(const char *data)
23+
{
24+
costumeData = data;
25+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#pragma once
2+
3+
#include <iscratchstage.h>
4+
5+
using namespace libscratchcpp;
6+
7+
class TestStageInterface : public IScratchStage
8+
{
9+
public:
10+
TestStageInterface();
11+
12+
void setTempo(int tempo) override;
13+
void setVideoState(Stage::VideoState videoState) override;
14+
void setVideoTransparency(int videoTransparency) override;
15+
16+
void setCostume(const char *data) override;
17+
18+
int tempo = 60;
19+
Stage::VideoState videoState = Stage::VideoState::Off;
20+
int videoTrasparency = 50;
21+
22+
const char *costumeData = nullptr;
23+
};

0 commit comments

Comments
 (0)