test_image_texture_3d.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /**************************************************************************/
  2. /* test_image_texture_3d.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. #ifndef TEST_IMAGE_TEXTURE_3D_H
  31. #define TEST_IMAGE_TEXTURE_3D_H
  32. #include "core/io/image.h"
  33. #include "scene/resources/image_texture.h"
  34. #include "tests/test_macros.h"
  35. #include "tests/test_utils.h"
  36. namespace TestImageTexture3D {
  37. // [SceneTree] in a test case name enables initializing a mock render server,
  38. // which ImageTexture3D is dependent on.
  39. TEST_CASE("[SceneTree][ImageTexture3D] Constructor") {
  40. Ref<ImageTexture3D> image_texture_3d = memnew(ImageTexture3D);
  41. CHECK(image_texture_3d->get_format() == Image::FORMAT_L8);
  42. CHECK(image_texture_3d->get_width() == 1);
  43. CHECK(image_texture_3d->get_height() == 1);
  44. CHECK(image_texture_3d->get_depth() == 1);
  45. CHECK(image_texture_3d->has_mipmaps() == false);
  46. }
  47. TEST_CASE("[SceneTree][ImageTexture3D] get_format") {
  48. Ref<ImageTexture3D> image_texture_3d = memnew(ImageTexture3D);
  49. CHECK(image_texture_3d->get_format() == Image::FORMAT_L8);
  50. }
  51. TEST_CASE("[SceneTree][ImageTexture3D] get_width") {
  52. Ref<ImageTexture3D> image_texture_3d = memnew(ImageTexture3D);
  53. CHECK(image_texture_3d->get_width() == 1);
  54. }
  55. TEST_CASE("[SceneTree][ImageTexture3D] get_height") {
  56. Ref<ImageTexture3D> image_texture_3d = memnew(ImageTexture3D);
  57. CHECK(image_texture_3d->get_height() == 1);
  58. }
  59. TEST_CASE("[SceneTree][ImageTexture3D] get_depth") {
  60. Ref<ImageTexture3D> image_texture_3d = memnew(ImageTexture3D);
  61. CHECK(image_texture_3d->get_depth() == 1);
  62. }
  63. TEST_CASE("[SceneTree][ImageTexture3D] has_mipmaps") {
  64. const Vector<Ref<Image>> images = { memnew(Image(8, 8, false, Image::FORMAT_RGBA8)), memnew(Image(8, 8, false, Image::FORMAT_RGBA8)) };
  65. Ref<ImageTexture3D> image_texture_3d = memnew(ImageTexture3D);
  66. CHECK(image_texture_3d->has_mipmaps() == false); // No mipmaps.
  67. image_texture_3d->create(Image::FORMAT_RGBA8, 2, 2, 2, true, images);
  68. CHECK(image_texture_3d->has_mipmaps() == true); // Mipmaps.
  69. }
  70. TEST_CASE("[SceneTree][ImageTexture3D] create") {
  71. const Vector<Ref<Image>> images = { memnew(Image(8, 8, false, Image::FORMAT_RGBA8)), memnew(Image(8, 8, false, Image::FORMAT_RGBA8)) };
  72. Ref<ImageTexture3D> image_texture_3d = memnew(ImageTexture3D);
  73. CHECK(image_texture_3d->create(Image::FORMAT_RGBA8, 2, 2, 2, true, images) == OK); // Run create and check return value simultaneously.
  74. CHECK(image_texture_3d->get_format() == Image::FORMAT_RGBA8);
  75. CHECK(image_texture_3d->get_width() == 2);
  76. CHECK(image_texture_3d->get_height() == 2);
  77. CHECK(image_texture_3d->get_depth() == 2);
  78. CHECK(image_texture_3d->has_mipmaps() == true);
  79. }
  80. TEST_CASE("[SceneTree][ImageTexture3D] set_path") {
  81. Ref<ImageTexture3D> image_texture_3d = memnew(ImageTexture3D);
  82. String path = TestUtils::get_data_path("images/icon.png");
  83. image_texture_3d->set_path(path, true);
  84. CHECK(image_texture_3d->get_path() == path);
  85. }
  86. } //namespace TestImageTexture3D
  87. #endif // TEST_IMAGE_TEXTURE_3D_H