Conversion to Apache 2.0 license
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-unmanaged / utc-Dali-JsonParser.cpp
index 4864733..8a85198 100644 (file)
@@ -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 <iostream>
 #include <stdlib.h>
@@ -43,6 +44,56 @@ 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;
+    }
+  }
+}
+
+
 }
 
 
@@ -61,7 +112,6 @@ int UtcDaliJsonParserMethod01(void)
   'nil':null, \
   'array':[1,2,3], \
   'object':{'key':'value'} \
-END_TEST; \
 }"));
 
   JsonParser parser = JsonParser::New();
@@ -468,7 +518,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 +552,8 @@ const char *TEST_FAIL[] = {
   "[0e+-1]",
   "{'Numbers cannot be hex': 0x14}",
   "[   , '<-- missing value']",
+  "[{'no comma':1} {'b:2}]",
+  "{'extra comma':1,}",
 };
 }
 
@@ -612,7 +664,7 @@ int UtcDaliJsonParserMethod10(void)
 {
   ToolkitTestApplication application;
 
-  tet_infoline("JSON basic test");
+  tet_infoline("JSON empty data");
 
   std::string s1( "" );
 
@@ -625,3 +677,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;
+}