5#include "testing/testing.h"
20 ASSERT_NE(value,
nullptr);
21 ASSERT_EQ(value->type(), eValueType::Array);
23 EXPECT_FALSE(elements.is_empty());
26 const std::shared_ptr<Value> &item = value->elements()[0];
27 ASSERT_EQ(item->type(), eValueType::Dictionary);
31 const std::string expected_key,
32 const std::string expected_value)
34 EXPECT_TRUE(lookup.contains(expected_key));
35 const std::shared_ptr<Value> &element = *lookup.lookup_ptr(expected_key);
36 ASSERT_EQ(element->type(), eValueType::String);
37 EXPECT_EQ(element->as_string_value()->value(), expected_value);
41 const std::string expected_key,
44 EXPECT_TRUE(lookup.contains(expected_key));
45 const std::shared_ptr<Value> &element = *lookup.lookup_ptr(expected_key);
46 ASSERT_EQ(element->type(), eValueType::Int);
47 EXPECT_EQ(element->as_int_value()->value(), expected_value);
51 const std::string expected_key,
52 const float expected_value)
54 EXPECT_TRUE(lookup.contains(expected_key));
55 const std::shared_ptr<Value> &element = *lookup.lookup_ptr(expected_key);
56 ASSERT_EQ(element->type(), eValueType::Double);
57 EXPECT_EQ(element->as_double_value()->value(), expected_value);
61 const std::string expected_key,
62 const double expected_value)
64 EXPECT_TRUE(lookup.contains(expected_key));
65 const std::shared_ptr<Value> &element = *lookup.lookup_ptr(expected_key);
66 ASSERT_EQ(element->type(), eValueType::Double);
67 EXPECT_EQ(element->as_double_value()->value(), expected_value);
72 std::unique_ptr<IDProperty, IDPropertyDeleter>
property =
create(prop_name, prop_content);
76 const std::shared_ptr<Value> &item = value->elements()[0];
86TEST(idprop, convert_idp_string_to_value)
93 std::unique_ptr<IDProperty, IDPropertyDeleter>
property =
create(prop_name, prop_content);
97 const std::shared_ptr<Value> &item = value->elements()[0];
107TEST(idprop, convert_idp_int_to_value)
114 std::unique_ptr<IDProperty, IDPropertyDeleter>
property =
create(prop_name, prop_content);
118 const std::shared_ptr<Value> &item = value->elements()[0];
128TEST(idprop, convert_idp_float_to_value)
135 std::unique_ptr<IDProperty, IDPropertyDeleter>
property =
create(prop_name, prop_content);
139 const std::shared_ptr<Value> &item = value->elements()[0];
149TEST(idprop, convert_idp_double_to_value)
154template<
typename PrimitiveType,
typename ValueType>
157 std::unique_ptr<IDProperty, IDPropertyDeleter>
property =
create(prop_name, prop_content);
161 const std::shared_ptr<Value> &item = value->elements()[0];
169 const std::shared_ptr<Value> &element = *lookup.lookup_ptr(
"value");
171 ASSERT_NE(subvalues,
nullptr);
173 ASSERT_EQ(subitems.
size(), prop_content.
size());
175 for (
size_t i = 0; i < prop_content.
size(); i++) {
176 EXPECT_EQ(
static_cast<ValueType *
>(subitems[i].get())->value(), prop_content[i]);
180TEST(idprop, convert_idp_int_array_to_value)
183 {-16, -8, -4, -2, -1, 0, 1, 2, 4, 8, 16});
186TEST(idprop, convert_idp_float_array_to_value)
189 "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});
192TEST(idprop, convert_idp_double_array_to_value)
195 "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});
200 std::stringstream is(input);
202 std::unique_ptr<Value> value = json.
deserialize(is);
208 std::stringstream out;
218 ASSERT_NE(id_property,
nullptr);
228 ASSERT_NE(id_property,
nullptr);
236 float expected_value)
238 ASSERT_NE(id_property,
nullptr);
246 double expected_value)
248 ASSERT_NE(id_property,
nullptr);
258 ASSERT_NE(id_property,
nullptr);
264 for (
int i = 0; i < values.size(); i++) {
273 ASSERT_NE(id_property,
nullptr);
278 float *idprop_values =
static_cast<float *
>(
IDP_Array(id_property));
279 for (
int i = 0; i < values.size(); i++) {
288 ASSERT_NE(id_property,
nullptr);
293 double *idprop_values =
static_cast<double *
>(
IDP_Array(id_property));
294 for (
int i = 0; i < values.size(); i++) {
299template<
typename Type>
304 std::unique_ptr<Value> value =
parse_json(input);
306 test_idprop(id_property, expected_name, expected_value);
310TEST(idprop, convert_idp_string_from_value)
313 R
"([{"name":"MyStringName","type":"IDP_STRING","value":"MyString"}])",
318TEST(idprop, convert_idp_int_from_value)
321 R
"([{"name":"MyIntegerName","type":"IDP_INT","value":42}])", "MyIntegerName", 42);
324TEST(idprop, convert_idp_float_from_value)
327 R
"([{"name":"MyFloatName","type":"IDP_FLOAT","value":42.24}])", "MyFloatName", 42.24f);
330TEST(idprop, convert_idp_double_from_value)
333 R
"([{"name":"MyDoubleName","type":"IDP_DOUBLE","value":42.24}])", "MyDoubleName", 42.24);
336TEST(idprop, convert_idp_array_int_from_value)
339 R
"([{"name":"MyArrayName","type":"IDP_ARRAY","subtype":"IDP_INT","value":[42, 24, 35]}])",
344TEST(idprop, convert_idp_array_float_from_value)
347 R
"([{"name":"MyArrayName","type":"IDP_ARRAY","subtype":"IDP_FLOAT","value":[42.0, 24.4, 35.2]}])",
352TEST(idprop, convert_idp_array_double_from_value)
355 R
"([{"name":"MyArrayName","type":"IDP_ARRAY","subtype":"IDP_DOUBLE","value":[42.43,24.5,35.8]}])",
360TEST(idprop, convert_idp_multiple_from_value)
362 static const std::string input_json =
363 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}])";
364 std::unique_ptr<Value> value = parse_json(input_json);
368 ASSERT_NE(id_property_1, nullptr);
370 ASSERT_NE(id_property_2,
nullptr);
372 ASSERT_NE(id_property_3,
nullptr);
374 ASSERT_NE(id_property_4,
nullptr);
383 test_idprop(id_property_2,
"MyStringName",
"MyString");
393TEST(idprop, convert_idp_multiple_roundtrip)
395 static const std::string input_json =
396 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}])";
397 std::unique_ptr<Value> value = parse_json(input_json);
401 ASSERT_NE(id_property_1, nullptr);
403 ASSERT_NE(id_property_2,
nullptr);
405 ASSERT_NE(id_property_3,
nullptr);
407 ASSERT_NE(id_property_4,
nullptr);
410 std::string output_json =
to_json(*value_from_id_properties);
419TEST(idprop, convert_idp_group_from_value)
421 static const std::string input_json =
422 R
"([{"name":"AssetMetaData.properties","type":"IDP_GROUP","value":[{"name":"dimensions","type":"IDP_ARRAY","subtype":"IDP_FLOAT","value":[2.0,2.0,2.0]}]}])";
423 std::unique_ptr<Value> value = parse_json(input_json);
426 ASSERT_NE(id_property, nullptr);
void IDP_FreeProperty(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.
constexpr int64_t size() const
Span< std::shared_ptr< Value > > elements() const
const ArrayValue * as_array_value() const
const DictionaryValue * as_dictionary_value() const
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 std::unique_ptr< Value > parse_json(StringRef input)
static void test_double_to_value(const StringRefNull prop_name, double prop_content)
static std::string to_json(const Value &value)
std::unique_ptr< blender::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, eIDPropertyFlag flags={})
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.