68 lines
2.7 KiB
C++
68 lines
2.7 KiB
C++
#include "../app/common/Pixel_Frame.h"
|
|
#include "../app/render_3D/Gallery_Scene3D.h"
|
|
|
|
#include <gtest/gtest.h>
|
|
#include <nlohmann/json.hpp>
|
|
|
|
#include <algorithm>
|
|
#include <array>
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <exception>
|
|
#include <string>
|
|
|
|
namespace renderive::web {
|
|
namespace {
|
|
std::uint32_t read_u32_le(const std::string& value, std::size_t offset) {
|
|
return static_cast<std::uint8_t>(value[offset]) |
|
|
(static_cast<std::uint32_t>(static_cast<std::uint8_t>(value[offset + 1])) << 8U) |
|
|
(static_cast<std::uint32_t>(static_cast<std::uint8_t>(value[offset + 2])) << 16U) |
|
|
(static_cast<std::uint32_t>(static_cast<std::uint8_t>(value[offset + 3])) << 24U);
|
|
}
|
|
|
|
TEST(RenderiveWebDatovizGallery, RgbaEncoderPreservesRowsAndRemovesPadding) {
|
|
std::array<std::uint8_t, 24> source{};
|
|
const std::array<std::uint8_t, 16> expected{
|
|
255, 1, 2, 255, 3, 254, 4, 255,
|
|
5, 6, 253, 255, 252, 7, 8, 255};
|
|
std::copy_n(expected.begin(), 8, source.begin());
|
|
std::copy_n(expected.begin() + 8, 8, source.begin() + 12);
|
|
|
|
const std::string frame = encode_rgba8_pixel_frame(
|
|
reinterpret_cast<const std::byte*>(source.data()), 2, 2, 12, 42);
|
|
ASSERT_EQ(frame.size(), pixel_frame_header_size + expected.size());
|
|
EXPECT_EQ(frame.substr(0, 4), "RVP2");
|
|
EXPECT_EQ(read_u32_le(frame, 4), 2U);
|
|
EXPECT_EQ(read_u32_le(frame, 8), 2U);
|
|
EXPECT_EQ(read_u32_le(frame, 12), 8U);
|
|
EXPECT_TRUE(std::equal(expected.begin(), expected.end(),
|
|
reinterpret_cast<const std::uint8_t*>(
|
|
frame.data() + pixel_frame_header_size)));
|
|
EXPECT_TRUE(encode_rgba8_pixel_frame(
|
|
reinterpret_cast<const std::byte*>(source.data()), 2, 2, 7, 42)
|
|
.empty());
|
|
}
|
|
|
|
TEST(RenderiveWebDatovizGallery, CurrentThreeDimensionalSceneRendersRgba) {
|
|
try {
|
|
auto scene = make_gallery_scene_3d(
|
|
1, "datoviz_3d", Gallery_Frame_Mode::Manual);
|
|
scene->resize(320, 200);
|
|
ASSERT_TRUE(scene->request_frame());
|
|
const auto frame = scene->encode_latest_pixels();
|
|
ASSERT_TRUE(frame);
|
|
ASSERT_GE(frame->size(), pixel_frame_header_size);
|
|
EXPECT_EQ(frame->substr(0, 4), "RVP2");
|
|
EXPECT_EQ(read_u32_le(*frame, 4), 320U);
|
|
EXPECT_EQ(read_u32_le(*frame, 8), 200U);
|
|
|
|
const auto telemetry = nlohmann::json::parse(scene->telemetry_json());
|
|
EXPECT_EQ(telemetry.at("kernel_observer").at("point_count"), 3U);
|
|
EXPECT_EQ(telemetry.at("performance").at("successful_render_count"), 1U);
|
|
} catch (const std::exception& error) {
|
|
GTEST_SKIP() << "Datoviz backend unavailable: " << error.what();
|
|
}
|
|
}
|
|
} // namespace
|
|
} // namespace renderive::web
|