5#include "testing/testing.h"
24 ASSERT_NE(value,
nullptr);
30 const std::shared_ptr<Value> &item = value->
elements()[0];
35 const std::string expected_key,
36 const std::string expected_value)
39 const std::shared_ptr<Value> &
element = *lookup.lookup_ptr(expected_key);
45 const std::string expected_key,
49 const std::shared_ptr<Value> &
element = *lookup.lookup_ptr(expected_key);
55 const std::string expected_key,
56 const float expected_value)
59 const std::shared_ptr<Value> &
element = *lookup.lookup_ptr(expected_key);
65 const std::string expected_key,
66 const double expected_value)
69 const std::shared_ptr<Value> &
element = *lookup.lookup_ptr(expected_key);
76 std::unique_ptr<IDProperty, IDPropertyDeleter>
property =
create(prop_name, prop_content);
80 const std::shared_ptr<Value> &item = value->elements()[0];
97 std::unique_ptr<IDProperty, IDPropertyDeleter>
property =
create(prop_name, prop_content);
101 const std::shared_ptr<Value> &item = value->elements()[0];
118 std::unique_ptr<IDProperty, IDPropertyDeleter>
property =
create(prop_name, prop_content);
122 const std::shared_ptr<Value> &item = value->elements()[0];
139 std::unique_ptr<IDProperty, IDPropertyDeleter>
property =
create(prop_name, prop_content);
143 const std::shared_ptr<Value> &item = value->elements()[0];
158template<
typename PrimitiveType,
typename ValueType>
161 std::unique_ptr<IDProperty, IDPropertyDeleter>
property =
create(prop_name, prop_content);
165 const std::shared_ptr<Value> &item = value->elements()[0];
173 const std::shared_ptr<Value> &
element = *lookup.lookup_ptr(
"value");
175 ASSERT_NE(subvalues,
nullptr);
177 ASSERT_EQ(subitems.
size(), prop_content.
size());
179 for (
size_t i = 0; i < prop_content.
size(); i++) {
180 EXPECT_EQ(
static_cast<ValueType *
>(subitems[i].get())->value(), prop_content[i]);
187 {-16, -8, -4, -2, -1, 0, 1, 2, 4, 8, 16});
193 "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});
199 "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});
204 std::stringstream is(input);
206 std::unique_ptr<Value> value =
json.deserialize(is);
212 std::stringstream
out;
222 ASSERT_NE(id_property,
nullptr);
232 ASSERT_NE(id_property,
nullptr);
240 float expected_value)
242 ASSERT_NE(id_property,
nullptr);
250 double expected_value)
252 ASSERT_NE(id_property,
nullptr);
262 ASSERT_NE(id_property,
nullptr);
268 for (
int i = 0; i < values.
size(); i++) {
277 ASSERT_NE(id_property,
nullptr);
283 for (
int i = 0; i < values.
size(); i++) {
292 ASSERT_NE(id_property,
nullptr);
298 for (
int i = 0; i < values.
size(); i++) {
303template<
typename Type>
308 std::unique_ptr<Value> value =
parse_json(input);
310 test_idprop(id_property, expected_name, expected_value);
317 R
"([{"name":"MyStringName","type":"IDP_STRING","value":"MyString"}])",
325 R
"([{"name":"MyIntegerName","type":"IDP_INT","value":42}])", "MyIntegerName", 42);
331 R
"([{"name":"MyFloatName","type":"IDP_FLOAT","value":42.24}])", "MyFloatName", 42.24f);
337 R
"([{"name":"MyDoubleName","type":"IDP_DOUBLE","value":42.24}])", "MyDoubleName", 42.24);
343 R
"([{"name":"MyArrayName","type":"IDP_ARRAY","subtype":"IDP_INT","value":[42, 24, 35]}])",
351 R
"([{"name":"MyArrayName","type":"IDP_ARRAY","subtype":"IDP_FLOAT","value":[42.0, 24.4, 35.2]}])",
359 R
"([{"name":"MyArrayName","type":"IDP_ARRAY","subtype":"IDP_DOUBLE","value":[42.43,24.5,35.8]}])",
366 static const std::string input_json =
367 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}])";
368 std::unique_ptr<Value> value = parse_json(input_json);
372 ASSERT_NE(id_property_1, nullptr);
374 ASSERT_NE(id_property_2,
nullptr);
376 ASSERT_NE(id_property_3,
nullptr);
378 ASSERT_NE(id_property_4,
nullptr);
387 test_idprop(id_property_2,
"MyStringName",
"MyString");
399 static const std::string input_json =
400 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}])";
401 std::unique_ptr<Value> value = parse_json(input_json);
405 ASSERT_NE(id_property_1, nullptr);
407 ASSERT_NE(id_property_2,
nullptr);
409 ASSERT_NE(id_property_3,
nullptr);
411 ASSERT_NE(id_property_4,
nullptr);
414 std::string output_json =
to_json(*value_from_id_properties);
425 static const std::string input_json =
426 R
"([{"name":"AssetMetaData.properties","type":"IDP_GROUP","value":[{"name":"dimensions","type":"IDP_ARRAY","subtype":"IDP_FLOAT","value":[2.0,2.0,2.0]}]}])";
427 std::unique_ptr<Value> value = parse_json(input_json);
430 ASSERT_NE(id_property, nullptr);
#define IDP_float_get(prop)
#define IDP_int_get(prop)
#define IDP_array_double_get(prop)
#define IDP_string_get(prop)
#define IDP_double_get(prop)
#define IDP_array_int_get(prop)
#define IDP_array_float_get(prop)
ID and Library types, which are fundamental for SDNA.
constexpr int64_t size() const
constexpr bool is_empty() const
Span< std::shared_ptr< Value > > elements() const
Map< std::string, std::shared_ptr< Value > > Lookup
const DictionaryValue * as_dictionary_value() const
#define EXPECT_FALSE(result)
#define EXPECT_TRUE(result)
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)
static void check_object_attribute(const DictionaryValue::Lookup &lookup, const std::string expected_key, const std::string expected_value)
TEST_F(IDPropertySerializeTest, convert_idp_string_to_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< IDProperty, IDPropertyDeleter > create(StringRef 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 io::serialize::Value &value)
Convert the given value (which must be an array) to an IDProperty.
std::unique_ptr< io::serialize::ArrayValue > convert_to_serialize_values(const IDProperty *properties)
Convert the given properties to Value objects for serialization.
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
void IDP_FreeProperty(IDProperty *prop)
ATTR_WARN_UNUSED_RESULT const void * element
ListBaseT< struct IDProperty > group