test_parallax_2d.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /**************************************************************************/
  2. /* test_parallax_2d.h */
  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. #pragma once
  31. #include "scene/2d/parallax_2d.h"
  32. #include "tests/test_macros.h"
  33. namespace TestParallax2D {
  34. // Test cases for the Parallax2D class to ensure its properties are set and retrieved correctly.
  35. TEST_CASE("[SceneTree][Parallax2D] Scroll Scale") {
  36. // Test setting and getting the scroll scale.
  37. Parallax2D *parallax = memnew(Parallax2D);
  38. Size2 scale(2, 2);
  39. parallax->set_scroll_scale(scale);
  40. CHECK(parallax->get_scroll_scale() == scale);
  41. memdelete(parallax);
  42. }
  43. TEST_CASE("[SceneTree][Parallax2D] Repeat Size") {
  44. // Test setting and getting the repeat size.
  45. Parallax2D *parallax = memnew(Parallax2D);
  46. Size2 size(100, 100);
  47. parallax->set_repeat_size(size);
  48. CHECK(parallax->get_repeat_size() == size);
  49. memdelete(parallax);
  50. }
  51. TEST_CASE("[SceneTree][Parallax2D] Repeat Times") {
  52. // Test setting and getting the repeat times.
  53. Parallax2D *parallax = memnew(Parallax2D);
  54. int times = 5;
  55. parallax->set_repeat_times(times);
  56. CHECK(parallax->get_repeat_times() == times);
  57. memdelete(parallax);
  58. }
  59. TEST_CASE("[SceneTree][Parallax2D] Autoscroll") {
  60. // Test setting and getting the autoscroll values.
  61. Parallax2D *parallax = memnew(Parallax2D);
  62. Point2 autoscroll(1, 1);
  63. parallax->set_autoscroll(autoscroll);
  64. CHECK(parallax->get_autoscroll() == autoscroll);
  65. memdelete(parallax);
  66. }
  67. TEST_CASE("[SceneTree][Parallax2D] Scroll Offset") {
  68. // Test setting and getting the scroll offset.
  69. Parallax2D *parallax = memnew(Parallax2D);
  70. Point2 offset(10, 10);
  71. parallax->set_scroll_offset(offset);
  72. CHECK(parallax->get_scroll_offset() == offset);
  73. memdelete(parallax);
  74. }
  75. TEST_CASE("[SceneTree][Parallax2D] Screen Offset") {
  76. // Test setting and getting the screen offset.
  77. Parallax2D *parallax = memnew(Parallax2D);
  78. Point2 offset(20, 20);
  79. parallax->set_screen_offset(offset);
  80. CHECK(parallax->get_screen_offset() == offset);
  81. memdelete(parallax);
  82. }
  83. TEST_CASE("[SceneTree][Parallax2D] Limit Begin") {
  84. // Test setting and getting the limit begin values.
  85. Parallax2D *parallax = memnew(Parallax2D);
  86. Point2 limit_begin(-100, -100);
  87. parallax->set_limit_begin(limit_begin);
  88. CHECK(parallax->get_limit_begin() == limit_begin);
  89. memdelete(parallax);
  90. }
  91. TEST_CASE("[SceneTree][Parallax2D] Limit End") {
  92. // Test setting and getting the limit end values.
  93. Parallax2D *parallax = memnew(Parallax2D);
  94. Point2 limit_end(100, 100);
  95. parallax->set_limit_end(limit_end);
  96. CHECK(parallax->get_limit_end() == limit_end);
  97. memdelete(parallax);
  98. }
  99. TEST_CASE("[SceneTree][Parallax2D] Follow Viewport") {
  100. // Test setting and getting the follow viewport flag.
  101. Parallax2D *parallax = memnew(Parallax2D);
  102. parallax->set_follow_viewport(false);
  103. CHECK_FALSE(parallax->get_follow_viewport());
  104. memdelete(parallax);
  105. }
  106. TEST_CASE("[SceneTree][Parallax2D] Ignore Camera Scroll") {
  107. // Test setting and getting the ignore camera scroll flag.
  108. Parallax2D *parallax = memnew(Parallax2D);
  109. parallax->set_ignore_camera_scroll(true);
  110. CHECK(parallax->is_ignore_camera_scroll());
  111. memdelete(parallax);
  112. }
  113. } // namespace TestParallax2D