Skip to content

Commit d8fe75e

Browse files
authored
Merge pull request #166 from scratchcpp/input_test
Add Input test
2 parents bc983f6 + e9b88d0 commit d8fe75e

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

test/scratch_classes/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,17 @@ target_link_libraries(
109109
)
110110

111111
gtest_discover_tests(broadcast_test)
112+
113+
# input_test
114+
add_executable(
115+
input_test
116+
input_test.cpp
117+
)
118+
119+
target_link_libraries(
120+
input_test
121+
GTest::gtest_main
122+
scratchcpp
123+
)
124+
125+
gtest_discover_tests(input_test)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#include <scratchcpp/input.h>
2+
#include <scratchcpp/inputvalue.h>
3+
#include <scratchcpp/block.h>
4+
5+
#include "../common.h"
6+
7+
using namespace libscratchcpp;
8+
9+
TEST(InputTest, Constructors)
10+
{
11+
Input input1("VALUE", Input::Type::Shadow);
12+
ASSERT_EQ(input1.name(), "VALUE");
13+
ASSERT_EQ(input1.type(), Input::Type::Shadow);
14+
15+
Input input2("custom_block", Input::Type::NoShadow);
16+
ASSERT_EQ(input2.name(), "custom_block");
17+
ASSERT_EQ(input2.type(), Input::Type::NoShadow);
18+
}
19+
20+
TEST(InputTest, InputId)
21+
{
22+
Input input("", Input::Type::Shadow);
23+
ASSERT_EQ(input.inputId(), -1);
24+
25+
input.setInputId(3);
26+
ASSERT_EQ(input.inputId(), 3);
27+
}
28+
29+
TEST(InputTest, PrimaryValue)
30+
{
31+
Input input("", Input::Type::Shadow);
32+
ASSERT_TRUE(input.primaryValue());
33+
34+
input.setPrimaryValue("test");
35+
ASSERT_EQ(input.primaryValue()->value().toString(), "test");
36+
}
37+
38+
TEST(InputTest, SecondaryValue)
39+
{
40+
Input input("", Input::Type::Shadow);
41+
ASSERT_TRUE(input.secondaryValue());
42+
43+
input.setSecondaryValue("test");
44+
ASSERT_EQ(input.secondaryValue()->value().toString(), "test");
45+
}
46+
47+
TEST(InputTest, ValueBlock)
48+
{
49+
Input input("", Input::Type::Shadow);
50+
ASSERT_EQ(input.valueBlock(), nullptr);
51+
ASSERT_EQ(input.valueBlockId(), "");
52+
53+
auto block = std::make_shared<Block>("abc", "");
54+
input.setValueBlock(block);
55+
ASSERT_EQ(input.valueBlock(), block);
56+
ASSERT_EQ(input.valueBlockId(), "abc");
57+
58+
input.setValueBlockId("hello");
59+
ASSERT_EQ(input.valueBlockId(), "hello");
60+
ASSERT_EQ(input.valueBlock(), nullptr);
61+
}

0 commit comments

Comments
 (0)