4 #include "testing/testing.h"
16 ASSERT_NE(value,
nullptr);
19 EXPECT_FALSE(elements.is_empty());
23 ASSERT_EQ(item->type(), eValueType::Dictionary);
27 const std::string expected_key,
28 const std::string expected_value)
30 EXPECT_TRUE(
lookup.contains(expected_key));
31 const std::shared_ptr<Value> &
element = *
lookup.lookup_ptr(expected_key);
32 ASSERT_EQ(
element->type(), eValueType::String);
37 const std::string expected_key,
40 EXPECT_TRUE(
lookup.contains(expected_key));
41 const std::shared_ptr<Value> &
element = *
lookup.lookup_ptr(expected_key);
42 ASSERT_EQ(
element->type(), eValueType::Int);
47 const std::string expected_key,
48 const float expected_value)
50 EXPECT_TRUE(
lookup.contains(expected_key));
51 const std::shared_ptr<Value> &
element = *
lookup.lookup_ptr(expected_key);
52 ASSERT_EQ(
element->type(), eValueType::Double);
57 const std::string expected_key,
58 const double expected_value)
60 EXPECT_TRUE(
lookup.contains(expected_key));
61 const std::shared_ptr<Value> &
element = *
lookup.lookup_ptr(expected_key);
62 ASSERT_EQ(
element->type(), eValueType::Double);
68 std::unique_ptr<IDProperty, IDPropertyDeleter>
property =
create(prop_name, prop_content);
82 TEST(idprop, convert_idp_string_to_value)
89 std::unique_ptr<IDProperty, IDPropertyDeleter>
property =
create(prop_name, prop_content);
103 TEST(idprop, convert_idp_int_to_value)
110 std::unique_ptr<IDProperty, IDPropertyDeleter>
property =
create(prop_name, prop_content);
124 TEST(idprop, convert_idp_float_to_value)
131 std::unique_ptr<IDProperty, IDPropertyDeleter>
property =
create(prop_name, prop_content);
145 TEST(idprop, convert_idp_double_to_value)
150 template<
typename PrimitiveType,
typename ValueType>
153 std::unique_ptr<IDProperty, IDPropertyDeleter>
property =
create(prop_name, prop_content);
165 const std::shared_ptr<Value> &
element = *
lookup.lookup_ptr(
"value");
167 ASSERT_NE(subvalues,
nullptr);
169 ASSERT_EQ(subitems.size(), prop_content.
size());
171 for (
size_t i = 0; i < prop_content.
size(); i++) {
172 EXPECT_EQ(
static_cast<ValueType *
>(subitems[i].get())->value(), prop_content[i]);
176 TEST(idprop, convert_idp_int_array_to_value)
178 test_array_to_value<int32_t, IntValue>(
"my_integer_array",
179 {-16, -8, -4, -2, -1, 0, 1, 2, 4, 8, 16});
182 TEST(idprop, convert_idp_float_array_to_value)
184 test_array_to_value<float, DoubleValue>(
185 "my_float_array", {-16.8f, -8.4f, -4.2f, -2.1f, -1.0f, 0.0f, 1.0f, 2.1f, 4.2f, 8.4f, 16.8f});
188 TEST(idprop, convert_idp_double_array_to_value)
190 test_array_to_value<double, DoubleValue>(
191 "my_double_array", {-16.8, -8.4, -4.2, -2.1, -1.0, 0.0, 1.0, 2.1, 4.2, 8.4, 16.8});
196 std::stringstream is(
input);
198 std::unique_ptr<Value> value = json.
deserialize(is);
204 std::stringstream
out;
214 ASSERT_NE(id_property,
nullptr);
224 ASSERT_NE(id_property,
nullptr);
232 float expected_value)
234 ASSERT_NE(id_property,
nullptr);
242 double expected_value)
244 ASSERT_NE(id_property,
nullptr);
254 ASSERT_NE(id_property,
nullptr);
260 for (
int i = 0; i < values.
size(); i++) {
269 ASSERT_NE(id_property,
nullptr);
274 float *idprop_values =
static_cast<float *
>(
IDP_Array(id_property));
275 for (
int i = 0; i < values.
size(); i++) {
284 ASSERT_NE(id_property,
nullptr);
289 double *idprop_values =
static_cast<double *
>(
IDP_Array(id_property));
290 for (
int i = 0; i < values.
size(); i++) {
295 template<
typename Type>
302 test_idprop(id_property, expected_name, expected_value);
306 TEST(idprop, convert_idp_string_from_value)
309 R
"([{"name":"MyStringName","type":"IDP_STRING","value":"MyString"}])",
314 TEST(idprop, convert_idp_int_from_value)
317 R
"([{"name":"MyIntegerName","type":"IDP_INT","value":42}])", "MyIntegerName", 42);
320 TEST(idprop, convert_idp_float_from_value)
323 R
"([{"name":"MyFloatName","type":"IDP_FLOAT","value":42.24}])", "MyFloatName", 42.24f);
326 TEST(idprop, convert_idp_double_from_value)
329 R
"([{"name":"MyDoubleName","type":"IDP_DOUBLE","value":42.24}])", "MyDoubleName", 42.24);
332 TEST(idprop, convert_idp_array_int_from_value)
335 R
"([{"name":"MyArrayName","type":"IDP_ARRAY","subtype":"IDP_INT","value":[42, 24, 35]}])",
340 TEST(idprop, convert_idp_array_float_from_value)
343 R
"([{"name":"MyArrayName","type":"IDP_ARRAY","subtype":"IDP_FLOAT","value":[42.0, 24.4, 35.2]}])",
348 TEST(idprop, convert_idp_array_double_from_value)
351 R
"([{"name":"MyArrayName","type":"IDP_ARRAY","subtype":"IDP_DOUBLE","value":[42.43,24.5,35.8]}])",
356 TEST(idprop, convert_idp_multiple_from_value)
358 static const std::string input_json =
359 R
"([{"name":"MyIntegerName","type":"IDP_INT","value":42},{"name":"MyStringName","type":"IDP_STRING","value":"MyString"},{"name":"MyFloatName","type":"IDP_FLOAT","value":42.24},{"name":"MyDoubleName","type":"IDP_DOUBLE","value":42.24}])";
360 std::unique_ptr<Value> value = parse_json(input_json);
364 ASSERT_NE(id_property_1, nullptr);
366 ASSERT_NE(id_property_2,
nullptr);
368 ASSERT_NE(id_property_3,
nullptr);
370 ASSERT_NE(id_property_4,
nullptr);
379 test_idprop(id_property_2,
"MyStringName",
"MyString");
389 TEST(idprop, convert_idp_multiple_roundtrip)
391 static const std::string input_json =
392 R
"([{"name":"MyIntegerName","type":"IDP_INT","value":42},{"name":"MyStringName","type":"IDP_STRING","value":"MyString"},{"name":"MyFloatName","type":"IDP_FLOAT","value":42.2400016784668},{"name":"MyDoubleName","type":"IDP_DOUBLE","value":42.24}])";
393 std::unique_ptr<Value> value = parse_json(input_json);
397 ASSERT_NE(id_property_1, nullptr);
399 ASSERT_NE(id_property_2,
nullptr);
401 ASSERT_NE(id_property_3,
nullptr);
403 ASSERT_NE(id_property_4,
nullptr);
406 std::string output_json =
to_json(*value_from_id_properties);
415 TEST(idprop, convert_idp_group_from_value)
417 static const std::string input_json =
418 R
"([{"name":"AssetMetaData.properties","type":"IDP_GROUP","value":[{"name":"dimensions","type":"IDP_ARRAY","subtype":"IDP_FLOAT","value":[2.0,2.0,2.0]}]}])";
419 std::unique_ptr<Value> value = parse_json(input_json);
422 ASSERT_NE(id_property, nullptr);
void IDP_FreeProperty(struct IDProperty *prop)
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
int BLI_listbase_count(const struct ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
ID and Library types, which are fundamental for sdna.
ATTR_WARN_UNUSED_RESULT const void * element
const Container & elements() const
const DictionaryValue * as_dictionary_value() const
ccl_global KernelShaderEvalInput * input
GAttributeReader lookup(const void *owner, const AttributeIDRef &attribute_id)
static std::unique_ptr< Value > parse_json(StringRef input)
static void test_float_to_value(const StringRefNull prop_name, float prop_content)
static void test_string_to_value(const StringRefNull prop_name, const StringRefNull prop_content)
static void test_convert_idprop_from_value(StringRef input, StringRef expected_name, Type expected_value)
static void test_idprop(const IDProperty *id_property, StringRef expected_name, StringRef expected_value)
static void test_array_to_value(const StringRefNull prop_name, Vector< PrimitiveType > prop_content)
static void check_container_value(ArrayValue *value)
static void test_int_to_value(const StringRefNull prop_name, int32_t prop_content)
TEST(idprop, convert_idp_string_to_value)
static void check_object_attribute(const DictionaryValue::Lookup &lookup, const std::string expected_key, const std::string expected_value)
static void test_double_to_value(const StringRefNull prop_name, double prop_content)
static std::string to_json(const Value &value)
std::unique_ptr< io::serialize::ArrayValue > convert_to_serialize_values(const IDProperty *properties)
Convert the given properties to Value objects for serialization.
std::unique_ptr< IDProperty, IDPropertyDeleter > create(StringRefNull prop_name, int32_t value)
Allocate a new IDProperty of type IDP_INT, set its name and value.
IDProperty * convert_from_serialize_value(const blender::io::serialize::Value &value)
Convert the given value to an IDProperty.
static const pxr::TfToken out("out", pxr::TfToken::Immortal)