diff options
Diffstat (limited to 'tests/core/io')
-rw-r--r-- | tests/core/io/test_file_access.h | 23 | ||||
-rw-r--r-- | tests/core/io/test_image.h | 39 | ||||
-rw-r--r-- | tests/core/io/test_marshalls.h | 2 | ||||
-rw-r--r-- | tests/core/io/test_resource.h | 10 |
4 files changed, 50 insertions, 24 deletions
diff --git a/tests/core/io/test_file_access.h b/tests/core/io/test_file_access.h index f0e1cceacf..aab62955cb 100644 --- a/tests/core/io/test_file_access.h +++ b/tests/core/io/test_file_access.h @@ -78,6 +78,29 @@ TEST_CASE("[FileAccess] CSV read") { CHECK(row5[1] == "tab separated"); CHECK(row5[2] == "lines, good?"); } + +TEST_CASE("[FileAccess] Get as UTF-8 String") { + Ref<FileAccess> f_lf = FileAccess::open(TestUtils::get_data_path("line_endings_lf.test.txt"), FileAccess::READ); + String s_lf = f_lf->get_as_utf8_string(); + f_lf->seek(0); + String s_lf_nocr = f_lf->get_as_utf8_string(true); + CHECK(s_lf == "Hello darkness\nMy old friend\nI've come to talk\nWith you again\n"); + CHECK(s_lf_nocr == "Hello darkness\nMy old friend\nI've come to talk\nWith you again\n"); + + Ref<FileAccess> f_crlf = FileAccess::open(TestUtils::get_data_path("line_endings_crlf.test.txt"), FileAccess::READ); + String s_crlf = f_crlf->get_as_utf8_string(); + f_crlf->seek(0); + String s_crlf_nocr = f_crlf->get_as_utf8_string(true); + CHECK(s_crlf == "Hello darkness\r\nMy old friend\r\nI've come to talk\r\nWith you again\r\n"); + CHECK(s_crlf_nocr == "Hello darkness\nMy old friend\nI've come to talk\nWith you again\n"); + + Ref<FileAccess> f_cr = FileAccess::open(TestUtils::get_data_path("line_endings_cr.test.txt"), FileAccess::READ); + String s_cr = f_cr->get_as_utf8_string(); + f_cr->seek(0); + String s_cr_nocr = f_cr->get_as_utf8_string(true); + CHECK(s_cr == "Hello darkness\rMy old friend\rI've come to talk\rWith you again\r"); + CHECK(s_cr_nocr == "Hello darknessMy old friendI've come to talkWith you again"); +} } // namespace TestFileAccess #endif // TEST_FILE_ACCESS_H diff --git a/tests/core/io/test_image.h b/tests/core/io/test_image.h index 1c778c3228..36e6b83bfd 100644 --- a/tests/core/io/test_image.h +++ b/tests/core/io/test_image.h @@ -161,8 +161,8 @@ TEST_CASE("[Image] Basic getters") { CHECK(image->get_height() == 4); CHECK(image->get_size() == Vector2(8, 4)); CHECK(image->get_format() == Image::FORMAT_LA8); - CHECK(image->get_used_rect() == Rect2(0, 0, 0, 0)); - Ref<Image> image_get_rect = image->get_rect(Rect2(0, 0, 2, 1)); + CHECK(image->get_used_rect() == Rect2i(0, 0, 0, 0)); + Ref<Image> image_get_rect = image->get_rect(Rect2i(0, 0, 2, 1)); CHECK(image_get_rect->get_size() == Vector2(2, 1)); } @@ -213,8 +213,8 @@ TEST_CASE("[Image] Modifying pixels of an image") { image->get_pixelv(Vector2(0, 0)).is_equal_approx(Color(1, 1, 1, 1)), "Image's get_pixel() should return the same color value as the one being set with set_pixel() in the same position."); CHECK_MESSAGE( - image->get_used_rect() == Rect2(0, 0, 1, 1), - "Image's get_used_rect should return the expected value, larger than Rect2(0, 0, 0, 0) if it's visible."); + image->get_used_rect() == Rect2i(0, 0, 1, 1), + "Image's get_used_rect should return the expected value, larger than Rect2i(0, 0, 0, 0) if it's visible."); image->set_pixelv(Vector2(0, 0), Color(0.5, 0.5, 0.5, 0.5)); Ref<Image> image2 = memnew(Image(3, 3, false, Image::FORMAT_RGBA8)); @@ -233,19 +233,19 @@ TEST_CASE("[Image] Modifying pixels of an image") { { const int img_width = 3; const int img_height = 3; - Vector<Rect2> rects; - rects.push_back(Rect2()); - rects.push_back(Rect2(-5, -5, 3, 3)); - rects.push_back(Rect2(img_width, 0, 12, 12)); - rects.push_back(Rect2(0, img_height, 12, 12)); - rects.push_back(Rect2(img_width + 1, img_height + 2, 12, 12)); - rects.push_back(Rect2(1, 1, 1, 1)); - rects.push_back(Rect2(0, 1, 2, 3)); - rects.push_back(Rect2(-5, 0, img_width + 10, 2)); - rects.push_back(Rect2(0, -5, 2, img_height + 10)); - rects.push_back(Rect2(-1, -1, img_width + 1, img_height + 1)); - - for (const Rect2 &rect : rects) { + Vector<Rect2i> rects; + rects.push_back(Rect2i()); + rects.push_back(Rect2i(-5, -5, 3, 3)); + rects.push_back(Rect2i(img_width, 0, 12, 12)); + rects.push_back(Rect2i(0, img_height, 12, 12)); + rects.push_back(Rect2i(img_width + 1, img_height + 2, 12, 12)); + rects.push_back(Rect2i(1, 1, 1, 1)); + rects.push_back(Rect2i(0, 1, 2, 3)); + rects.push_back(Rect2i(-5, 0, img_width + 10, 2)); + rects.push_back(Rect2i(0, -5, 2, img_height + 10)); + rects.push_back(Rect2i(-1, -1, img_width + 1, img_height + 1)); + + for (const Rect2i &rect : rects) { Ref<Image> img = memnew(Image(img_width, img_height, false, Image::FORMAT_RGBA8)); CHECK_NOTHROW_MESSAGE( img->fill_rect(rect, Color(1, 1, 1, 1)), @@ -267,7 +267,7 @@ TEST_CASE("[Image] Modifying pixels of an image") { } // Blend two images together - image->blend_rect(image2, Rect2(Vector2(0, 0), image2->get_size()), Vector2(0, 0)); + image->blend_rect(image2, Rect2i(Vector2i(0, 0), image2->get_size()), Vector2i(0, 0)); CHECK_MESSAGE( image->get_pixel(0, 0).a > 0.7, "blend_rect() should blend the alpha values of the two images."); @@ -279,7 +279,7 @@ TEST_CASE("[Image] Modifying pixels of an image") { image3->set_pixel(0, 0, Color(0, 1, 0, 1)); //blit_rect() two images together - image->blit_rect(image3, Rect2(Vector2(0, 0), image3->get_size()), Vector2(0, 0)); + image->blit_rect(image3, Rect2i(Vector2i(0, 0), image3->get_size()), Vector2i(0, 0)); CHECK_MESSAGE( image->get_pixel(0, 0).is_equal_approx(Color(0, 1, 0, 1)), "blit_rect() should replace old colors and not blend them."); @@ -300,4 +300,5 @@ TEST_CASE("[Image] Modifying pixels of an image") { "flip_y() should not leave old pixels behind."); } } // namespace TestImage + #endif // TEST_IMAGE_H diff --git a/tests/core/io/test_marshalls.h b/tests/core/io/test_marshalls.h index 546a2e9358..7490df2b2c 100644 --- a/tests/core/io/test_marshalls.h +++ b/tests/core/io/test_marshalls.h @@ -254,11 +254,13 @@ TEST_CASE("[Marshalls] Invalid data Variant decoding") { uint8_t some_buffer[1] = { 0x00 }; uint8_t out_of_range_type_buffer[4] = { 0xff }; // Greater than Variant::VARIANT_MAX + ERR_PRINT_OFF; CHECK(decode_variant(variant, some_buffer, /* less than 4 */ 1, &r_len) == ERR_INVALID_DATA); CHECK(r_len == 0); CHECK(decode_variant(variant, out_of_range_type_buffer, 4, &r_len) == ERR_INVALID_DATA); CHECK(r_len == 0); + ERR_PRINT_ON; } TEST_CASE("[Marshalls] NIL Variant decoding") { diff --git a/tests/core/io/test_resource.h b/tests/core/io/test_resource.h index 84d651b63f..c880ca7d2a 100644 --- a/tests/core/io/test_resource.h +++ b/tests/core/io/test_resource.h @@ -28,8 +28,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef TEST_RESOURCE -#define TEST_RESOURCE +#ifndef TEST_RESOURCE_H +#define TEST_RESOURCE_H #include "core/io/resource.h" #include "core/io/resource_loader.h" @@ -76,8 +76,8 @@ TEST_CASE("[Resource] Saving and loading") { resource->set_meta("other_resource", child_resource); const String save_path_binary = OS::get_singleton()->get_cache_path().plus_file("resource.res"); const String save_path_text = OS::get_singleton()->get_cache_path().plus_file("resource.tres"); - ResourceSaver::save(save_path_binary, resource); - ResourceSaver::save(save_path_text, resource); + ResourceSaver::save(resource, save_path_binary); + ResourceSaver::save(resource, save_path_text); const Ref<Resource> &loaded_resource_binary = ResourceLoader::load(save_path_binary); CHECK_MESSAGE( @@ -111,4 +111,4 @@ TEST_CASE("[Resource] Saving and loading") { } } // namespace TestResource -#endif // TEST_RESOURCE +#endif // TEST_RESOURCE_H |