X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit-unmanaged%2Futc-Dali-JsonParser.cpp;h=a1ebacd02de3cedef25da8bbf3d7b2231898e94b;hp=48647339bd8d81a6dff3b9f4a9c3fd0967808005;hb=e58197b2ce320f167a24865cdd048f0cc0c05e45;hpb=fa6279fb2830427d5ab569ca14e6ade1557ef2fa diff --git a/automated-tests/src/dali-toolkit-unmanaged/utc-Dali-JsonParser.cpp b/automated-tests/src/dali-toolkit-unmanaged/utc-Dali-JsonParser.cpp index 4864733..a1ebacd 100644 --- a/automated-tests/src/dali-toolkit-unmanaged/utc-Dali-JsonParser.cpp +++ b/automated-tests/src/dali-toolkit-unmanaged/utc-Dali-JsonParser.cpp @@ -1,18 +1,19 @@ -// -// Copyright (c) 2014 Samsung Electronics Co., Ltd. -// -// Licensed under the Flora License, Version 1.0 (the License); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://floralicense.org/license/ -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an AS IS BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ #include #include @@ -43,6 +44,60 @@ std::string ReplaceQuotes(const std::string &in_s) 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; + } + default: + { + break; + } + } +} + + } @@ -61,7 +116,6 @@ int UtcDaliJsonParserMethod01(void) 'nil':null, \ 'array':[1,2,3], \ 'object':{'key':'value'} \ -END_TEST; \ }")); JsonParser parser = JsonParser::New(); @@ -468,7 +522,7 @@ int UtcDaliJsonParserMethod06(void) 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']]", @@ -502,6 +556,8 @@ const char *TEST_FAIL[] = { "[0e+-1]", "{'Numbers cannot be hex': 0x14}", "[ , '<-- missing value']", + "[{'no comma':1} {'b:2}]", + "{'extra comma':1,}", }; } @@ -612,7 +668,7 @@ int UtcDaliJsonParserMethod10(void) { ToolkitTestApplication application; - tet_infoline("JSON basic test"); + tet_infoline("JSON empty data"); std::string s1( "" ); @@ -625,3 +681,44 @@ int UtcDaliJsonParserMethod10(void) 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; +}