Rendering Engine 0.2.0
Modular Graphics Rendering Engine | v0.2.0
Loading...
Searching...
No Matches
image_data_tests.cpp File Reference
#include <stdio.h>
#include <cstdint>
#include "gtest/gtest.h"
#include "../RenderingLibrary/Include/image_data.hpp"

Go to the source code of this file.

Functions

 TEST (ImageDataTests, PixelAssignment)
 TEST (ImageDataTests, ImageDataAssignment)
 TEST (ImageDataTests, GetImageDataEmpty)
 TEST (ImageDataTests, InappropriateAccess)
 TEST (ImageDataTest, SaveLoadTextureJpg)
 TEST (ImageDataTest, SaveLoadTexturePng)
 TEST (ImageDataTest, IncorrectTextureFilepath)

Function Documentation

◆ TEST() [1/7]

TEST ( ImageDataTest ,
IncorrectTextureFilepath  )

Definition at line 94 of file image_data_tests.cpp.

95{
96 std::string const filepath{ "missing_texture_file.png" };
97
98 EXPECT_THROW(ImageData image(filepath), std::runtime_error);
99}
Represents raw 2D image data stored in memory.

◆ TEST() [2/7]

TEST ( ImageDataTest ,
SaveLoadTextureJpg  )

Definition at line 66 of file image_data_tests.cpp.

67{
68 std::string const filepath{"test_jpeg_texture_file.jpg"};
69 ImageData image1(10U, 10U);
70 image1.Fill(Color(255, 0, 0, 255));
71 image1.WriteJpegFile(filepath.c_str());
72
73 ImageData image2("test_jpeg_texture_file.jpg");
74
75 EXPECT_EQ( image1.GetHeight(), image2.GetHeight() );
76 EXPECT_EQ( image1.GetWidth(), image2.GetWidth() );
77 //Pixels in the output jpeg file don't match completely to source pixels, because the compression algorithm in jpeg might slightly change values.
78}
Represents a color with red, green, blue, and alpha channels.

◆ TEST() [3/7]

TEST ( ImageDataTest ,
SaveLoadTexturePng  )

Definition at line 80 of file image_data_tests.cpp.

81{
82 std::string const filepath{ "test_png_texture_file.png" };
83 ImageData image1(10U, 10U);
84 image1.Fill(Color(255, 0, 0, 255));
85 image1.WritePngFile(filepath.c_str());
86
87 ImageData image2("test_png_texture_file.png");
88
89 EXPECT_EQ(image1.GetHeight(), image2.GetHeight());
90 EXPECT_EQ(image1.GetWidth(), image2.GetWidth());
91 EXPECT_EQ(image1.GetImageDataRGBA(), image2.GetImageDataRGBA());
92}

◆ TEST() [4/7]

TEST ( ImageDataTests ,
GetImageDataEmpty  )

Definition at line 49 of file image_data_tests.cpp.

50{
51 ImageData image;
52 EXPECT_TRUE(image.GetImageDataRGBA().empty());
53 image = ImageData(3, 3);
54 image.Fill(Color(255, 255, 255, 255));
55 EXPECT_FALSE(image.GetImageDataRGBA().empty());
56}
void Fill(Color color)
Fills the image with a solid color.
std::vector< uint8_t > GetImageDataRGBA() const
Gets raw image data in RGBA format.

◆ TEST() [5/7]

TEST ( ImageDataTests ,
ImageDataAssignment  )

Definition at line 28 of file image_data_tests.cpp.

29{
30 ImageData image1(3U, 3U);
31 Color const testColor(115U, 100U, 10U, 150U);
32 image1.Fill(testColor);
33
34 ImageData image2(1, 1);
35 image2 = image1;
36
37 ASSERT_EQ(image2.GetHeight(), image1.GetHeight());
38 ASSERT_EQ(image2.GetWidth(), image1.GetWidth());
39
40 for( unsigned int y = 0; y < image1.GetHeight(); ++y )
41 {
42 for( unsigned int x = 0; x < image1.GetWidth(); ++x )
43 {
44 EXPECT_EQ(image1.GetPixel(x, y), image2.GetPixel(x, y));
45 }
46 }
47}

◆ TEST() [6/7]

TEST ( ImageDataTests ,
InappropriateAccess  )

Definition at line 58 of file image_data_tests.cpp.

59{
60 ImageData image(3, 3);
61 image.Fill(Color(255, 255, 255, 255));
62
63 EXPECT_THROW(image.GetPixel(4, 4), std::runtime_error);
64}

◆ TEST() [7/7]

TEST ( ImageDataTests ,
PixelAssignment  )

Definition at line 17 of file image_data_tests.cpp.

18{
19 Color pixel1(1,2,3, 50);
20 Color pixel2 = pixel1;
21
22 EXPECT_EQ(pixel1.a, pixel2.a);
23 EXPECT_EQ(pixel1.r, pixel2.r);
24 EXPECT_EQ(pixel1.g, pixel2.g);
25 EXPECT_EQ(pixel1.b, pixel2.b);
26}