std::replace(s.begin(), s.end(), '\'', '"');
return s;
}
+
+void CompareTrees(const TreeNode& a, const TreeNode& b)
+{
+ DALI_TEST_CHECK( a.GetType() == b.GetType() );
+
+ DALI_TEST_CHECK( a.Size() == b.Size() );
+
+ if( a.GetName() )
+ {
+ DALI_TEST_CHECK( std::string( a.GetName() ) == std::string( b.GetName() ) );
+ }
+
+ DALI_TEST_CHECK( a.HasSubstitution() == b.HasSubstitution() );
+
+ switch( a.GetType() )
+ {
+ case TreeNode::OBJECT:
+ case TreeNode::ARRAY:
+ {
+ for( TreeNode::ConstIterator aiter = a.CBegin(), biter = b.CBegin();
+ aiter != a.CEnd() && biter != b.CEnd(); ++aiter, ++biter )
+ {
+ CompareTrees( (*aiter).second, (*biter).second );
+ }
+ break;
+ }
+ case TreeNode::STRING:
+ {
+ DALI_TEST_CHECK( std::string( a.GetString() ) == std::string( b.GetString() ) );
+ break;
+ }
+ case TreeNode::FLOAT:
+ {
+ DALI_TEST_CHECK( a.GetFloat() == b.GetFloat() );
+ break;
+ }
+ case TreeNode::INTEGER:
+ {
+ DALI_TEST_CHECK( a.GetInteger() == b.GetInteger());
+ break;
+ }
+ case TreeNode::BOOLEAN:
+ {
+ DALI_TEST_CHECK( a.GetBoolean() == b.GetBoolean() );
+ break;
+ }
+ }
+}
+
+
}
'nil':null, \
'array':[1,2,3], \
'object':{'key':'value'} \
-END_TEST; \
}"));
JsonParser parser = JsonParser::New();
namespace
{
-static const int NUMBER_FAIL_TESTS = 32;
+static const int NUMBER_FAIL_TESTS = 34;
const char *TEST_FAIL[] = {
"[' tab\t character \t in\t string ']",
"['Extra close']]",
"[0e+-1]",
"{'Numbers cannot be hex': 0x14}",
"[ , '<-- missing value']",
+ "[{'no comma':1} {'b:2}]",
+ "{'extra comma':1,}",
};
}
{
ToolkitTestApplication application;
- tet_infoline("JSON basic test");
+ tet_infoline("JSON empty data");
std::string s1( "" );
tet_result(TET_PASS);
END_TEST;
}
+
+int UtcDaliJsonParserMethod11(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline("JSON tree copy");
+
+ std::string s1( ReplaceQuotes(" \
+{ \
+ 'animations': \
+ { \
+ 'bump': \
+ { \
+ 'properties': \
+ [ \
+ { \
+ 'actor':'bump-image', \
+ 'property':'uLightPosition', \
+ 'value':[0.8, 0.0, -1.5], \
+ 'alpha-function': 'BOUNCE', \
+ 'time-period': { 'duration': 2.5 } \
+ } \
+ ] \
+ } \
+ } \
+} \
+"));
+
+ JsonParser parser = JsonParser::New();
+
+ parser.Parse( s1 );
+
+ JsonParser parser2 = JsonParser::New(*parser.GetRoot());
+
+ DALI_TEST_CHECK(parser.GetRoot());
+ DALI_TEST_CHECK(parser2.GetRoot());
+
+ CompareTrees( *parser.GetRoot(), *parser2.GetRoot() );
+
+ tet_result(TET_PASS);
+ END_TEST;
+}
{
if( '}' == currentChar )
{
+ if(',' == lastCharacter)
+ {
+ return Error("Unexpected comma");
+ }
+
if( !UpToParent() )
{
return false;
}
else if( '{' == currentChar )
{
- NewNode(name, TreeNode::OBJECT);
- mState = STATE_OBJECT;
- AdvanceSkipWhiteSpace(1);
+ if( '}' == lastCharacter )
+ {
+ return Error("Expected a comma");
+ }
+ else
+ {
+ NewNode(name, TreeNode::OBJECT);
+ mState = STATE_OBJECT;
+ AdvanceSkipWhiteSpace(1);
+ }
}
else if( '}' == currentChar )
{
if(',' == lastCharacter)
{
- return Error("Expected a value");
+ return Error("Expected another value");
}
if(mCurrent.GetType() != TreeNode::OBJECT)
typedef const T& ReturnType;
static ReturnType Get(const ValueType& v) { return v; }
static ValueType Set(const ReturnType v) { return v; }
- static bool Ok(const ValueType v) { return true; }
+ static bool Ok(const ValueType& v) { return true; }
};
template <typename T>
return mOk == true ? &OptionalValue::this_type_does_not_support_comparisons : 0;
}
- template <typename OT>
- bool operator!=( const OT& rhs )
- {
- this->this_type_does_not_support_comparisons();
- return false;
- }
-
- template <typename OT>
- bool operator==( const OT& rhs )
- {
- this->this_type_does_not_support_comparisons();
- return false;
- }
-
private:
bool mOk;
ValueType mValue;
void this_type_does_not_support_comparisons() const {}
- // todo operator=() ? use OptionalTypes<T>::Ok(mValue)
};
+template <typename T, typename U>
+bool operator==( const OptionalValue<T>& lhs, const OptionalValue<U>& rhs )
+{
+ lhs.this_type_does_not_support_comparisons();
+ return false;
+}
+
+template <typename T, typename U>
+bool operator!=( const OptionalValue<T>& lhs, const OptionalValue<U>& rhs )
+{
+ lhs.this_type_does_not_support_comparisons();
+ return false;
+}
#endif // header