5#include "testing/testing.h"
17namespace blender::bke::cryptomatte::tests {
19TEST(cryptomatte, meta_data_key)
21 ASSERT_EQ(
"cryptomatte/c7dbf5e/key",
23 ASSERT_EQ(
"cryptomatte/b990b65/𝓴𝓮𝔂",
27TEST(cryptomatte, extract_layer_name)
29 ASSERT_EQ(
"ViewLayer.CryptoMaterial",
32 ASSERT_EQ(
"NoTrailingSampleNumber",
39TEST(cryptomatte, layer)
42 ASSERT_EQ(
"{}", layer.manifest());
44 layer.add_hash(
"Object", 123);
45 ASSERT_EQ(
"{\"Object\":\"0000007b\"}", layer.manifest());
47 layer.add_hash(
"Object2", 123245678);
48 ASSERT_EQ(
"{\"Object\":\"0000007b\",\"Object2\":\"0758946e\"}", layer.manifest());
51TEST(cryptomatte, layer_quoted)
55 ASSERT_EQ(
"{\"\\\"Object\\\"\":\"0000007b\"}", layer.manifest());
58static void test_cryptomatte_manifest(std::string expected, std::string manifest)
61 blender::bke::cryptomatte::CryptomatteLayer::read_from_manifest(manifest)->manifest());
64TEST(cryptomatte, layer_from_manifest)
66 test_cryptomatte_manifest(
"{}",
"{}");
67 test_cryptomatte_manifest(R
"({"Object":"12345678"})", R"({"Object": "12345678"})");
68 test_cryptomatte_manifest(R"({"Object":"12345678","Object2":"87654321"})",
69 R"({"Object":"12345678","Object2":"87654321"})");
70 test_cryptomatte_manifest(R"({"Object":"12345678","Object2":"87654321"})",
71 R"( { "Object" : "12345678" , "Object2" : "87654321" } )");
72 test_cryptomatte_manifest(R"({"Object\"01\"":"12345678"})", R"({"Object\"01\"": "12345678"})");
73 test_cryptomatte_manifest(
74 R"({"Object\"01\"":"12345678","Object":"12345678","Object2":"87654321"})",
75 R"({"Object\"01\"":"12345678","Object":"12345678", "Object2":"87654321"})");
78TEST(cryptomatte, extract_layer_hash_from_metadata_key)
82 "cryptomatte/eb4c67b/conversion"));
85 "cryptomatte/qwerty/name"));
95static void validate_cryptomatte_session_from_stamp_data(
void * ,
101 if (!prop_name.startswith(
"cryptomatte/")) {
105 if (prop_name ==
"cryptomatte/67da54b/name") {
106 EXPECT_STREQ(
"layer1", propvalue);
108 else if (prop_name ==
"cryptomatte/67da54b/hash") {
109 EXPECT_STREQ(
"MurmurHash3_32", propvalue);
111 else if (prop_name ==
"cryptomatte/67da54b/conversion") {
112 EXPECT_STREQ(
"uint32_to_float32", propvalue);
114 else if (prop_name ==
"cryptomatte/67da54b/manifest") {
115 EXPECT_STREQ(R
"({"Object":"12345678"})", propvalue);
118 else if (prop_name ==
"cryptomatte/79b2306/name") {
119 EXPECT_STREQ(
"layer2", propvalue);
121 else if (prop_name ==
"cryptomatte/79b2306/hash") {
122 EXPECT_STREQ(
"MurmurHash3_32", propvalue);
124 else if (prop_name ==
"cryptomatte/79b2306/conversion") {
125 EXPECT_STREQ(
"uint32_to_float32", propvalue);
127 else if (prop_name ==
"cryptomatte/79b2306/manifest") {
128 EXPECT_STREQ(R
"({"Object2":"87654321"})", propvalue);
132 EXPECT_EQ(
"Unhandled", std::string(propname) +
": " + propvalue);
136TEST(cryptomatte, session_from_stamp_data)
143 render_result,
"cryptomatte/qwerty/manifest", R
"({"Object":"12345678"})");
146 render_result,
"cryptomatte/uiop/manifest", R
"({"Object2":"87654321"})");
148 EXPECT_NE(session.get(), nullptr);
158 nullptr, render_result2->
stamp_data, validate_cryptomatte_session_from_stamp_data,
false);
166TEST(cryptomatte, parsing_malformed_manifests)
169 test_cryptomatte_manifest(
170 R
"({"/obj/instance1:instances:0":"0d54c6cc","/obj/instance1:instances:1":"293d9340","/obj/instance1:instances:110":"ccb9e1f2","/obj/instance1:instances:111":"f8dd3a48","/obj/instance1:instances:112":"a99e07a8","/obj/instance1:instances:113":"e75599a4","/obj/instance1:instances:114":"794200f3","/obj/instance1:instances:115":"2a3a1728","/obj/instance1:instances:116":"478544a1","/obj/instance1:instances:117":"b2bd969a","/obj/instance1:instances:10":"3a0c8681","/obj/instance1:instances:11":"01e5970d","/obj/box:polygons:1":"9d416418","/obj/instance1:instances:100":"2dcd2966","/obj/instance1:instances:101":"9331cd82","/obj/instance1:instances:102":"df50fccb","/obj/instance1:instances:103":"97f8590d","/obj/instance1:instances:104":"bbcd220d","/obj/instance1:instances:105":"4ae06139","/obj/instance1:instances:106":"8873d5ea","/obj/instance1:instances:107":"39d8af8d","/obj/instance1:instances:108":"bb11bd4e","/obj/instance1:instances:109":"a32bba35"})",
171 R"({"\/obj\/box:polygons:1":"9d416418","\/obj\/instance1:instances:0":"0d54c6cc","\/obj\/instance1:instances:1":"293d9340","\/obj\/instance1:instances:10":"3a0c8681","\/obj\/instance1:instances:100":"2dcd2966","\/obj\/instance1:instances:101":"9331cd82","\/obj\/instance1:instances:102":"df50fccb","\/obj\/instance1:instances:103":"97f8590d","\/obj\/instance1:instances:104":"bbcd220d","\/obj\/instance1:instances:105":"4ae06139","\/obj\/instance1:instances:106":"8873d5ea","\/obj\/instance1:instances:107":"39d8af8d","\/obj\/instance1:instances:108":"bb11bd4e","\/obj\/instance1:instances:109":"a32bba35","\/obj\/instance1:instances:11":"01e5970d","\/obj\/instance1:instances:110":"ccb9e1f2","\/obj\/instance1:instances:111":"f8dd3a48","\/obj\/instance1:instances:112":"a99e07a8","\/obj\/instance1:instances:113":"e75599a4","\/obj\/instance1:instances:114":"794200f3","\/obj\/instance1:instances:115":"2a3a1728","\/obj\/instance1:instances:116":"478544a1","\/obj\/instance1:instances:117":"b2bd969a","\/obj\/instance1:instance)");
void BKE_cryptomatte_store_metadata(const struct CryptomatteSession *session, struct RenderResult *render_result)
struct CryptomatteSession * BKE_cryptomatte_init_from_render_result(const struct RenderResult *render_result)
void BKE_stamp_info_callback(void *data, StampData *stamp_data, StampCallback callback, bool noskip)
void BKE_render_result_stamp_data(RenderResult *rr, const char *key, const char *value)
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
Read Guarded memory(de)allocation.
void *(* MEM_callocN)(size_t len, const char *str)
std::unique_ptr< CryptomatteSession, CryptomatteSessionDeleter > CryptomatteSessionPtr
StringRef BKE_cryptomatte_extract_layer_name(const StringRef render_pass_name)
std::string BKE_cryptomatte_meta_data_key(const StringRef layer_name, const StringRefNull key_name)
void RE_FreeRenderResult(RenderResult *rr)
struct StampData * stamp_data
void add_hash(blender::StringRef name, CryptomatteHash cryptomatte_hash)
static blender::StringRef extract_layer_hash(blender::StringRefNull key)