Add renderer API validation tests
This commit is contained in:
86
tests/renderer_api/renderer_api_tests.cpp
Normal file
86
tests/renderer_api/renderer_api_tests.cpp
Normal file
@@ -0,0 +1,86 @@
|
||||
#include "renderer_api/renderer_api.h"
|
||||
#include "test_harness.h"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
using pp::foundation::StatusCode;
|
||||
using pp::renderer::Extent2D;
|
||||
using pp::renderer::ReadbackRegion;
|
||||
using pp::renderer::TextureDesc;
|
||||
using pp::renderer::TextureFormat;
|
||||
using pp::renderer::max_texture_dimension;
|
||||
using pp::renderer::texture_byte_size;
|
||||
using pp::renderer::texture_format_name;
|
||||
using pp::renderer::validate_extent;
|
||||
using pp::renderer::validate_readback_region;
|
||||
|
||||
namespace {
|
||||
|
||||
void computes_texture_sizes(pp::tests::Harness& h)
|
||||
{
|
||||
const auto rgba = texture_byte_size(TextureDesc {
|
||||
.extent = Extent2D { .width = 16, .height = 8 },
|
||||
.format = TextureFormat::rgba8,
|
||||
});
|
||||
const auto r8 = texture_byte_size(TextureDesc {
|
||||
.extent = Extent2D { .width = 16, .height = 8 },
|
||||
.format = TextureFormat::r8,
|
||||
});
|
||||
|
||||
PP_EXPECT(h, rgba.ok());
|
||||
PP_EXPECT(h, rgba.value() == 512U);
|
||||
PP_EXPECT(h, r8.ok());
|
||||
PP_EXPECT(h, r8.value() == 128U);
|
||||
PP_EXPECT(h, texture_format_name(TextureFormat::depth24_stencil8) == std::string_view("depth24_stencil8"));
|
||||
}
|
||||
|
||||
void rejects_invalid_or_excessive_extents(pp::tests::Harness& h)
|
||||
{
|
||||
const auto zero = validate_extent(Extent2D { .width = 0, .height = 1 });
|
||||
const auto huge = validate_extent(Extent2D { .width = max_texture_dimension + 1U, .height = 1 });
|
||||
const auto excessive_bytes = texture_byte_size(TextureDesc {
|
||||
.extent = Extent2D { .width = max_texture_dimension, .height = max_texture_dimension },
|
||||
.format = TextureFormat::rgba8,
|
||||
});
|
||||
|
||||
PP_EXPECT(h, !zero.ok());
|
||||
PP_EXPECT(h, zero.code == StatusCode::invalid_argument);
|
||||
PP_EXPECT(h, !huge.ok());
|
||||
PP_EXPECT(h, huge.code == StatusCode::out_of_range);
|
||||
PP_EXPECT(h, !excessive_bytes.ok());
|
||||
PP_EXPECT(h, excessive_bytes.status().code == StatusCode::out_of_range);
|
||||
}
|
||||
|
||||
void validates_readback_bounds(pp::tests::Harness& h)
|
||||
{
|
||||
const TextureDesc desc {
|
||||
.extent = Extent2D { .width = 64, .height = 32 },
|
||||
.format = TextureFormat::rgba8,
|
||||
.render_target = true,
|
||||
};
|
||||
|
||||
PP_EXPECT(h, validate_readback_region(desc, ReadbackRegion { .x = 0, .y = 0, .width = 64, .height = 32 }).ok());
|
||||
PP_EXPECT(h, validate_readback_region(desc, ReadbackRegion { .x = 63, .y = 31, .width = 1, .height = 1 }).ok());
|
||||
|
||||
const auto empty = validate_readback_region(desc, ReadbackRegion { .x = 0, .y = 0, .width = 0, .height = 1 });
|
||||
const auto origin_outside = validate_readback_region(desc, ReadbackRegion { .x = 65, .y = 0, .width = 1, .height = 1 });
|
||||
const auto overrun = validate_readback_region(desc, ReadbackRegion { .x = 63, .y = 31, .width = 2, .height = 1 });
|
||||
|
||||
PP_EXPECT(h, !empty.ok());
|
||||
PP_EXPECT(h, empty.code == StatusCode::invalid_argument);
|
||||
PP_EXPECT(h, !origin_outside.ok());
|
||||
PP_EXPECT(h, origin_outside.code == StatusCode::out_of_range);
|
||||
PP_EXPECT(h, !overrun.ok());
|
||||
PP_EXPECT(h, overrun.code == StatusCode::out_of_range);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
pp::tests::Harness harness;
|
||||
harness.run("computes_texture_sizes", computes_texture_sizes);
|
||||
harness.run("rejects_invalid_or_excessive_extents", rejects_invalid_or_excessive_extents);
|
||||
harness.run("validates_readback_bounds", validates_readback_bounds);
|
||||
return harness.finish();
|
||||
}
|
||||
Reference in New Issue
Block a user