test_color.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #include <catch2/catch.hpp>
  2. #include "libslic3r/libslic3r.h"
  3. #include "libslic3r/Color.hpp"
  4. using namespace Slic3r;
  5. SCENARIO("Color encoding/decoding cycle", "[Color]") {
  6. GIVEN("Color") {
  7. const ColorRGB src_rgb(static_cast<unsigned char>(255), static_cast<unsigned char>(127), static_cast<unsigned char>(63));
  8. WHEN("apply encode/decode cycle") {
  9. const std::string encoded = encode_color(src_rgb);
  10. ColorRGB res_rgb;
  11. decode_color(encoded, res_rgb);
  12. const bool ret = res_rgb.r_uchar() == src_rgb.r_uchar() && res_rgb.g_uchar() == src_rgb.g_uchar() && res_rgb.b_uchar() == src_rgb.b_uchar();
  13. THEN("result matches source") {
  14. REQUIRE(ret);
  15. }
  16. }
  17. }
  18. }
  19. SCENARIO("Color picking encoding/decoding cycle", "[Color]") {
  20. GIVEN("Picking color") {
  21. const ColorRGB src_rgb(static_cast<unsigned char>(255), static_cast<unsigned char>(127), static_cast<unsigned char>(63));
  22. WHEN("apply encode/decode cycle") {
  23. const unsigned int encoded = picking_encode(src_rgb.r_uchar(), src_rgb.g_uchar(), src_rgb.b_uchar());
  24. const ColorRGBA res_rgba = picking_decode(encoded);
  25. const bool ret = res_rgba.r_uchar() == src_rgb.r_uchar() && res_rgba.g_uchar() == src_rgb.g_uchar() && res_rgba.b_uchar() == src_rgb.b_uchar();
  26. THEN("result matches source") {
  27. REQUIRE(ret);
  28. }
  29. }
  30. }
  31. }