yaze 0.2.0
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
snes_palette_test.cc
Go to the documentation of this file.
2
3#include <gmock/gmock.h>
4#include <gtest/gtest.h>
5
7
8namespace yaze {
9namespace test {
10namespace gfx {
11
12using ::testing::ElementsAreArray;
14using yaze::app::gfx::ConvertSnestoRGB;
17
18namespace {
19unsigned int test_convert(snes_color col) {
20 unsigned int toret;
21 toret = col.red << 16;
22 toret += col.green << 8;
23 toret += col.blue;
24 return toret;
25}
26} // namespace
27
28TEST(SnesPaletteTest, AddColor) {
31 palette.AddColor(color);
32 ASSERT_EQ(palette.size(), 1);
33}
34
35TEST(SnesColorTest, ConvertRgbToSnes) {
36 snes_color color = {132, 132, 132};
37 uint16_t snes = ConvertRgbToSnes(color);
38 ASSERT_EQ(snes, 0x4210);
39}
40
41TEST(SnesColorTest, ConvertSnestoRGB) {
42 uint16_t snes = 0x4210;
43 snes_color color = ConvertSnestoRGB(snes);
44 ASSERT_EQ(color.red, 132);
45 ASSERT_EQ(color.green, 132);
46 ASSERT_EQ(color.blue, 132);
47}
48
49TEST(SnesColorTest, ConvertSnesToRGB_Binary) {
50 uint16_t red = 0b0000000000011111;
51 uint16_t blue = 0b0111110000000000;
52 uint16_t green = 0b0000001111100000;
53 uint16_t purple = 0b0111110000011111;
54 snes_color testcolor;
55
56 testcolor = ConvertSnestoRGB(red);
57 ASSERT_EQ(0xFF0000, test_convert(testcolor));
58 testcolor = ConvertSnestoRGB(green);
59 ASSERT_EQ(0x00FF00, test_convert(testcolor));
60 testcolor = ConvertSnestoRGB(blue);
61 ASSERT_EQ(0x0000FF, test_convert(testcolor));
62 testcolor = ConvertSnestoRGB(purple);
63 ASSERT_EQ(0xFF00FF, test_convert(testcolor));
64}
65
66TEST(SnesColorTest, Extraction) {
67 // red, blue, green, purple
68 char data[8] = {0x1F, 0x00, 0x00, 0x7C, static_cast<char>(0xE0),
69 0x03, 0x1F, 0x7C};
70 auto pal = Extract(data, 0, 4);
71 ASSERT_EQ(4, pal.size());
72 ASSERT_EQ(0xFF0000, test_convert(pal[0]));
73 ASSERT_EQ(0x0000FF, test_convert(pal[1]));
74 ASSERT_EQ(0x00FF00, test_convert(pal[2]));
75 ASSERT_EQ(0xFF00FF, test_convert(pal[3]));
76}
77
78TEST(SnesColorTest, Convert) {
79 // red, blue, green, purple white
80 char data[10] = {0x1F,
81 0x00,
82 0x00,
83 0x7C,
84 static_cast<char>(0xE0),
85 0x03,
86 0x1F,
87 0x7C,
88 static_cast<char>(0xFF),
89 0x1F};
90 auto pal = Extract(data, 0, 5);
91 auto snes_string = yaze::app::gfx::Convert(pal);
92 EXPECT_EQ(10, snes_string.size());
93 EXPECT_THAT(data, ElementsAreArray(snes_string.data(), 10));
94}
95
96} // namespace gfx
97} // namespace test
98} // namespace yaze
SNES Color container.
Definition snes_color.h:39
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
void AddColor(const SnesColor &color)
std::vector< char > Convert(const std::vector< snes_color > &palette)
Definition snes_color.cc:70
uint16_t ConvertRgbToSnes(const snes_color &color)
Definition snes_color.cc:34
std::vector< snes_color > Extract(const char *data, unsigned int offset, unsigned int palette_size)
Definition snes_color.cc:59
TEST(LC_LZ2_CompressionTest, TrivialRepeatedBytes)
Definition common.cc:22
Primitive of 16-bit RGB SNES color.
Definition snes_color.h:13
uint16_t green
Definition snes_color.h:16
uint16_t red
Definition snes_color.h:14
uint16_t blue
Definition snes_color.h:15