Decode PPI face payloads
This commit is contained in:
67
tests/assets/image_pixels_tests.cpp
Normal file
67
tests/assets/image_pixels_tests.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
#include "assets/image_pixels.h"
|
||||
#include "test_harness.h"
|
||||
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <span>
|
||||
|
||||
using pp::assets::decode_png_rgba8;
|
||||
using pp::foundation::StatusCode;
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr std::array<std::byte, 68> transparent_png_1x1 {
|
||||
std::byte { 0x89 }, std::byte { 0x50 }, std::byte { 0x4e }, std::byte { 0x47 },
|
||||
std::byte { 0x0d }, std::byte { 0x0a }, std::byte { 0x1a }, std::byte { 0x0a },
|
||||
std::byte { 0x00 }, std::byte { 0x00 }, std::byte { 0x00 }, std::byte { 0x0d },
|
||||
std::byte { 0x49 }, std::byte { 0x48 }, std::byte { 0x44 }, std::byte { 0x52 },
|
||||
std::byte { 0x00 }, std::byte { 0x00 }, std::byte { 0x00 }, std::byte { 0x01 },
|
||||
std::byte { 0x00 }, std::byte { 0x00 }, std::byte { 0x00 }, std::byte { 0x01 },
|
||||
std::byte { 0x08 }, std::byte { 0x06 }, std::byte { 0x00 }, std::byte { 0x00 },
|
||||
std::byte { 0x00 }, std::byte { 0x1f }, std::byte { 0x15 }, std::byte { 0xc4 },
|
||||
std::byte { 0x89 }, std::byte { 0x00 }, std::byte { 0x00 }, std::byte { 0x00 },
|
||||
std::byte { 0x0b }, std::byte { 0x49 }, std::byte { 0x44 }, std::byte { 0x41 },
|
||||
std::byte { 0x54 }, std::byte { 0x78 }, std::byte { 0x9c }, std::byte { 0x63 },
|
||||
std::byte { 0x60 }, std::byte { 0x00 }, std::byte { 0x02 }, std::byte { 0x00 },
|
||||
std::byte { 0x00 }, std::byte { 0x05 }, std::byte { 0x00 }, std::byte { 0x01 },
|
||||
std::byte { 0x7a }, std::byte { 0x5e }, std::byte { 0xab }, std::byte { 0x3f },
|
||||
std::byte { 0x00 }, std::byte { 0x00 }, std::byte { 0x00 }, std::byte { 0x00 },
|
||||
std::byte { 0x49 }, std::byte { 0x45 }, std::byte { 0x4e }, std::byte { 0x44 },
|
||||
std::byte { 0xae }, std::byte { 0x42 }, std::byte { 0x60 }, std::byte { 0x82 },
|
||||
};
|
||||
|
||||
void decodes_png_to_rgba8_pixels(pp::tests::Harness& h)
|
||||
{
|
||||
const auto image = decode_png_rgba8(transparent_png_1x1);
|
||||
|
||||
PP_EXPECT(h, image.ok());
|
||||
PP_EXPECT(h, image.value().width == 1U);
|
||||
PP_EXPECT(h, image.value().height == 1U);
|
||||
PP_EXPECT(h, image.value().pixels.size() == 4U);
|
||||
PP_EXPECT(h, image.value().pixels[0] == 0U);
|
||||
PP_EXPECT(h, image.value().pixels[1] == 0U);
|
||||
PP_EXPECT(h, image.value().pixels[2] == 0U);
|
||||
PP_EXPECT(h, image.value().pixels[3] == 0U);
|
||||
}
|
||||
|
||||
void rejects_corrupt_png_payload(pp::tests::Harness& h)
|
||||
{
|
||||
auto corrupt = transparent_png_1x1;
|
||||
corrupt[0] = std::byte { 0x00 };
|
||||
|
||||
const auto image = decode_png_rgba8(corrupt);
|
||||
|
||||
PP_EXPECT(h, !image.ok());
|
||||
PP_EXPECT(h, image.status().code == StatusCode::invalid_argument);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
pp::tests::Harness harness;
|
||||
harness.run("decodes_png_to_rgba8_pixels", decodes_png_to_rgba8_pixels);
|
||||
harness.run("rejects_corrupt_png_payload", rejects_corrupt_png_payload);
|
||||
return harness.finish();
|
||||
}
|
||||
Reference in New Issue
Block a user