Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/tests/scene/test_parallax_2d.cpp
45993 views
1
/**************************************************************************/
2
/* test_parallax_2d.cpp */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#include "tests/test_macros.h"
32
33
TEST_FORCE_LINK(test_parallax_2d)
34
35
#include "scene/2d/parallax_2d.h"
36
37
// Test cases for the Parallax2D class to ensure its properties are set and retrieved correctly.
38
39
namespace TestParallax2D {
40
41
TEST_CASE("[SceneTree][Parallax2D] Scroll Scale") {
42
// Test setting and getting the scroll scale.
43
Parallax2D *parallax = memnew(Parallax2D);
44
Size2 scale(2, 2);
45
parallax->set_scroll_scale(scale);
46
CHECK(parallax->get_scroll_scale() == scale);
47
memdelete(parallax);
48
}
49
50
TEST_CASE("[SceneTree][Parallax2D] Repeat Size") {
51
// Test setting and getting the repeat size.
52
Parallax2D *parallax = memnew(Parallax2D);
53
Size2 size(100, 100);
54
parallax->set_repeat_size(size);
55
CHECK(parallax->get_repeat_size() == size);
56
memdelete(parallax);
57
}
58
59
TEST_CASE("[SceneTree][Parallax2D] Repeat Times") {
60
// Test setting and getting the repeat times.
61
Parallax2D *parallax = memnew(Parallax2D);
62
int times = 5;
63
parallax->set_repeat_times(times);
64
CHECK(parallax->get_repeat_times() == times);
65
memdelete(parallax);
66
}
67
68
TEST_CASE("[SceneTree][Parallax2D] Autoscroll") {
69
// Test setting and getting the autoscroll values.
70
Parallax2D *parallax = memnew(Parallax2D);
71
Point2 autoscroll(1, 1);
72
parallax->set_autoscroll(autoscroll);
73
CHECK(parallax->get_autoscroll() == autoscroll);
74
memdelete(parallax);
75
}
76
77
TEST_CASE("[SceneTree][Parallax2D] Scroll Offset") {
78
// Test setting and getting the scroll offset.
79
Parallax2D *parallax = memnew(Parallax2D);
80
Point2 offset(10, 10);
81
parallax->set_scroll_offset(offset);
82
CHECK(parallax->get_scroll_offset() == offset);
83
memdelete(parallax);
84
}
85
86
TEST_CASE("[SceneTree][Parallax2D] Screen Offset") {
87
// Test setting and getting the screen offset.
88
Parallax2D *parallax = memnew(Parallax2D);
89
Point2 offset(20, 20);
90
parallax->set_screen_offset(offset);
91
CHECK(parallax->get_screen_offset() == offset);
92
memdelete(parallax);
93
}
94
95
TEST_CASE("[SceneTree][Parallax2D] Limit Begin") {
96
// Test setting and getting the limit begin values.
97
Parallax2D *parallax = memnew(Parallax2D);
98
Point2 limit_begin(-100, -100);
99
parallax->set_limit_begin(limit_begin);
100
CHECK(parallax->get_limit_begin() == limit_begin);
101
memdelete(parallax);
102
}
103
104
TEST_CASE("[SceneTree][Parallax2D] Limit End") {
105
// Test setting and getting the limit end values.
106
Parallax2D *parallax = memnew(Parallax2D);
107
Point2 limit_end(100, 100);
108
parallax->set_limit_end(limit_end);
109
CHECK(parallax->get_limit_end() == limit_end);
110
memdelete(parallax);
111
}
112
113
TEST_CASE("[SceneTree][Parallax2D] Follow Viewport") {
114
// Test setting and getting the follow viewport flag.
115
Parallax2D *parallax = memnew(Parallax2D);
116
parallax->set_follow_viewport(false);
117
CHECK_FALSE(parallax->get_follow_viewport());
118
memdelete(parallax);
119
}
120
121
TEST_CASE("[SceneTree][Parallax2D] Ignore Camera Scroll") {
122
// Test setting and getting the ignore camera scroll flag.
123
Parallax2D *parallax = memnew(Parallax2D);
124
parallax->set_ignore_camera_scroll(true);
125
CHECK(parallax->is_ignore_camera_scroll());
126
memdelete(parallax);
127
}
128
129
} // namespace TestParallax2D
130
131