From 5197b928f899e8402d532066adff4df56cbd64b1 Mon Sep 17 00:00:00 2001 From: David Steele Date: Wed, 9 Mar 2016 14:00:06 +0000 Subject: [PATCH] Added string writers for Property::MAP and Property::ARRAY Change-Id: Id507f8d1bde9a72cf07105156bcb65512f92dd22 --- .../src/dali/utc-Dali-PropertyArray.cpp | 36 +++++++++++++++++++ automated-tests/src/dali/utc-Dali-PropertyMap.cpp | 40 ++++++++++++++++++++- .../src/dali/utc-Dali-PropertyValue.cpp | 41 +++++++++++++++++++--- dali/public-api/object/property-array.cpp | 17 +++++++++ dali/public-api/object/property-array.h | 16 +++++++++ dali/public-api/object/property-map.cpp | 16 +++++++++ dali/public-api/object/property-map.h | 17 +++++++++ dali/public-api/object/property-value.cpp | 4 +-- 8 files changed, 180 insertions(+), 7 deletions(-) diff --git a/automated-tests/src/dali/utc-Dali-PropertyArray.cpp b/automated-tests/src/dali/utc-Dali-PropertyArray.cpp index f55004b..d48b334 100644 --- a/automated-tests/src/dali/utc-Dali-PropertyArray.cpp +++ b/automated-tests/src/dali/utc-Dali-PropertyArray.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -219,3 +220,38 @@ int UtcDaliPropertyArrayResize(void) END_TEST; } + +int UtcDaliPropertyArrayOstream01(void) +{ + std::ostringstream oss; + + Property::Array array; + array.PushBack( 0 ); + array.PushBack( 1 ); + array.PushBack( 2 ); + + oss << array; + DALI_TEST_EQUALS( oss.str().compare("Array(3) = [0, 1, 2]"), 0, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliPropertyArrayOstream02(void) +{ + std::ostringstream oss; + + Property::Array array1; + array1.PushBack( 0 ); + array1.PushBack( 1 ); + array1.PushBack( 2 ); + + Property::Array array2; + array2.PushBack(array1); + array2.PushBack( 1 ); + array2.PushBack( 2 ); + + oss << array2; + DALI_TEST_EQUALS( oss.str().compare("Array(3) = [Array(3) = [0, 1, 2], 1, 2]"), 0, TEST_LOCATION ); + + END_TEST; +} diff --git a/automated-tests/src/dali/utc-Dali-PropertyMap.cpp b/automated-tests/src/dali/utc-Dali-PropertyMap.cpp index b26655d..94c5437 100644 --- a/automated-tests/src/dali/utc-Dali-PropertyMap.cpp +++ b/automated-tests/src/dali/utc-Dali-PropertyMap.cpp @@ -16,7 +16,7 @@ */ #include - +#include #include #include #include @@ -273,3 +273,41 @@ int UtcDaliPropertyMapMerge(void) END_TEST; } + +int UtcDaliPropertyMapOstream01(void) +{ + Property::Map map; + + map.Insert("duration", 5.0f); + map.Insert("delay", 1.0f); + map.Insert("value", 100); + + std::ostringstream oss; + oss << map; + + tet_printf("Testing ouput of map: %s\n", oss.str().c_str()); + + DALI_TEST_EQUALS( oss.str().compare("Map(3) = {duration:5, delay:1, value:100}"), 0, TEST_LOCATION ); + + END_TEST; +} + + +int UtcDaliPropertyMapOstream02(void) +{ + Property::Map map, map2; + + map2.Insert("duration", 5.0f); + map2.Insert("delay", 1.0f); + map.Insert("timePeriod", map2); + map.Insert("value", 100); + + std::ostringstream oss; + oss << map; + + tet_printf("Testing ouput of map: %s\n", oss.str().c_str()); + + DALI_TEST_EQUALS( oss.str().compare("Map(2) = {timePeriod:Map(2) = {duration:5, delay:1}, value:100}"), 0, TEST_LOCATION ); + + END_TEST; +} diff --git a/automated-tests/src/dali/utc-Dali-PropertyValue.cpp b/automated-tests/src/dali/utc-Dali-PropertyValue.cpp index 37922ff..e51dc07 100644 --- a/automated-tests/src/dali/utc-Dali-PropertyValue.cpp +++ b/automated-tests/src/dali/utc-Dali-PropertyValue.cpp @@ -1222,21 +1222,54 @@ int UtcDaliPropertyValueOutputStream(void) DALI_TEST_CHECK( stream.str() == "Foo" ); } - // Maps and arrays currently not supported, we just check a message is output { Property::Map map; + map.Insert("key", "value"); + map.Insert("duration", 10); + map.Insert("color", Vector4(1.0, 0.5, 1.0, 1.0)); + value = Property::Value( map ); std::ostringstream stream; - stream << value; - DALI_TEST_CHECK( !stream.str().empty() ); + stream << value; + tet_printf("Checking Property::Value is %s", stream.str().c_str()); + DALI_TEST_CHECK( !stream.str().compare("Map(3) = {key:value, duration:10, color:[1, 0.5, 1, 1]}")); } { Property::Array array; + array.PushBack(0); + array.PushBack(2); + array.PushBack(3); value = Property::Value( array ); std::ostringstream stream; stream << value; - DALI_TEST_CHECK( !stream.str().empty() ); + tet_printf("Checking Property::Value is %s", stream.str().c_str()); + DALI_TEST_CHECK( !stream.str().compare("Array(3) = [0, 2, 3]") ); + } + + { + Property::Map map; + Property::Map map2; + Property::Array array; + + map2.Insert("key", "value"); + map2.Insert("duration", 10); + map.Insert("color", Vector4(1.0, 0.5, 1.0, 1.0)); + map.Insert("timePeriod", map2); + array.PushBack(Vector2(1, 0)); + array.PushBack(Vector2(0, 1)); + array.PushBack(Vector2(1, 0)); + array.PushBack(Vector2(0, 0.5)); + map.Insert("texCoords", array); + value = Property::Value( map ); + + std::ostringstream stream; + stream << value; + + tet_printf("Checking Property::Value is %s", stream.str().c_str()); + + DALI_TEST_CHECK( !stream.str().compare("Map(3) = {color:[1, 0.5, 1, 1], timePeriod:Map(2) = {key:value, duration:10}, texCoords:Array(4) = [[1, 0], [0, 1], [1, 0], [0, 0.5]]}")); } + END_TEST; } diff --git a/dali/public-api/object/property-array.cpp b/dali/public-api/object/property-array.cpp index e401f32..eca8182 100644 --- a/dali/public-api/object/property-array.cpp +++ b/dali/public-api/object/property-array.cpp @@ -102,4 +102,21 @@ Property::Array& Property::Array::operator=( const Property::Array& other ) return *this; } +std::ostream& operator<<( std::ostream& stream, const Property::Array& array ) +{ + stream << "Array(" << array.Count() << ") = ["; + for( unsigned int i=0; i0 ) + { + stream << ", "; + } + stream << array.GetElementAt(i); + } + stream << "]"; + + return stream; +} + + } // namespace Dali diff --git a/dali/public-api/object/property-array.h b/dali/public-api/object/property-array.h index 5fd3f86..d2ffa7a 100644 --- a/dali/public-api/object/property-array.h +++ b/dali/public-api/object/property-array.h @@ -185,12 +185,28 @@ public: */ Array& operator=( const Array& other ); + /** + * @brief output to stream + * @SINCE_1_1.28 + */ + friend std::ostream& operator<<( std::ostream& stream, const Property::Array& array ); + private: struct DALI_INTERNAL Impl; ///< Private data Impl* mImpl; ///< Pointer to private data }; /** + * @brief Convert the values of the property array into a string and append to an output stream. + * + * @SINCE_1_1.28 + * @param [in] stream The output stream operator. + * @param [in] array The array to insert + * @return The output stream operator. + */ +DALI_IMPORT_API std::ostream& operator<<( std::ostream& stream, const Property::Array& array ); + +/** * @} */ } // namespace Dali diff --git a/dali/public-api/object/property-map.cpp b/dali/public-api/object/property-map.cpp index fdf1cef..6caeb11 100644 --- a/dali/public-api/object/property-map.cpp +++ b/dali/public-api/object/property-map.cpp @@ -187,4 +187,20 @@ Property::Map& Property::Map::operator=( const Property::Map& other ) return *this; } +std::ostream& operator<<( std::ostream& stream, const Property::Map& map ) +{ + stream << "Map(" << map.Count() << ") = {"; + for( unsigned int i=0; i0 ) + { + stream << ", "; + } + stream << map.GetKey(i) << ":" << map.GetValue( i ); + } + stream << "}"; + + return stream; +} + } // namespace Dali diff --git a/dali/public-api/object/property-map.h b/dali/public-api/object/property-map.h index edd2b0b..902947d 100644 --- a/dali/public-api/object/property-map.h +++ b/dali/public-api/object/property-map.h @@ -212,12 +212,29 @@ public: */ Map& operator=( const Map& other ); + /** + * @brief output to stream + * @SINCE_1_1.28 + */ + friend std::ostream& operator<<( std::ostream& stream, const Property::Map& map ); + private: struct DALI_INTERNAL Impl; ///< Private data Impl* mImpl; ///< Pointer to private data }; /** + * @brief Convert the key/value pairs of the property map into a string and append to an output stream. + * + * @SINCE_1_1.28 + * @param [in] stream The output stream operator. + * @param [in] map The map to insert + * @return The output stream operator. + */ +DALI_IMPORT_API std::ostream& operator<<( std::ostream& stream, const Property::Map& map ); + + +/** * @} */ } // namespace Dali diff --git a/dali/public-api/object/property-value.cpp b/dali/public-api/object/property-value.cpp index 85f407f..ce9f560 100644 --- a/dali/public-api/object/property-value.cpp +++ b/dali/public-api/object/property-value.cpp @@ -836,12 +836,12 @@ std::ostream& operator<<( std::ostream& stream, const Property::Value& value ) } case Dali::Property::ARRAY: { - stream << "Array containing" << impl.arrayValue->Count() << " elements"; // TODO add ostream<< operator in array + stream << *(value.GetArray()); break; } case Dali::Property::MAP: { - stream << "Map containing " << impl.mapValue->Count() << " elements"; // TODO add ostream<< operator in map + stream << *(value.GetMap()); break; } case Dali::Property::NONE: -- 2.7.4