Skip to content

Commit

Permalink
Add test for load_image_asImage4f
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 216ca75d13adfc00abc024cef6e224b1eea1c041
  • Loading branch information
Vertexwahn committed Aug 14, 2024
1 parent 3613e18 commit 785c8ad
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions devertexwahn/imaging/io/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ Image3b load_image_asImage3b(std::string_view filename) {
}

Image4f load_image_asImage4f(std::string_view filename) {
if(std::filesystem::exists(filename) == false) {
throw std::runtime_error(fmt::format("File \"{}\" does not exist.", filename));
}

if (boost::ends_with(filename, ".png")) {
auto image = load_image_png_as_Image4b(filename);

Expand Down
21 changes: 21 additions & 0 deletions devertexwahn/imaging/io/io_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,24 @@ TEST(Image, try_to_store_image4f_with_invalid_extension) {
Image3f img{2,2};
EXPECT_THROW(store_image("test.invalid_extension", img), std::runtime_error);
}

TEST(Image, WhenTryToLoadNonExistingFile_ThenThrowException) {
EXPECT_THROW(load_image_asImage4f("non_existing_file.png"), std::runtime_error);
}

TEST(Image, load_image_asImage4f) {
// Arrange
auto image = make_reference_counted<Image3b>(100, 100);

for (int y = 0; y < image->height(); ++y) {
for (int x = 0; x < image->width(); ++x) {
image->set_pixel(x, y, Color3b{255, 128, 0});
}
}

// Act
store_image("test.png", image);

auto img = load_image_asImage4f("test.png");
EXPECT_THAT(img.get_pixel(0,0), (Color4f{1.f, 0.501960814f, 0.f, 1.f}));
}

0 comments on commit 785c8ad

Please sign in to comment.