Added libdli to dali-toolkit as dali-scene-loader.
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-scene-loader-internal / utc-Dali-JsonReader.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // Enable debug log for test coverage
19 #define DEBUG_ENABLED 1
20
21 #include "dali-scene-loader/internal/json-reader.h"
22 #include <dali-test-suite-utils.h>
23 #include <string>
24
25 using namespace Dali;
26
27 #define JSON_STRING(x) #x, strlen(#x)
28
29 int UtcDaliJsonReaderStrCmp(void)
30 {
31   json_string_s jstr[] {
32     { JSON_STRING(hello) },
33     { JSON_STRING(hellew) },
34   };
35   DALI_TEST_EQUAL(json::StrCmp(jstr[0], "hello"), 0);
36   DALI_TEST_EQUAL(json::StrCmp(jstr[1], "hello"), 'e' - 'o');
37
38   END_TEST;
39 }
40
41 int UtcDaliJsonReaderValidateThrow(void)
42 {
43   json_value_s jval { nullptr, json_type_array };
44   DALI_TEST_THROWS(json::Validate(jval, json_type_object), std::runtime_error);
45   json::Validate(jval, json_type_array);
46
47   END_TEST;
48 }
49
50 int UtcDaliJsonReaderFindObjectChild(void)
51 {
52   json_string_s jkey{ JSON_STRING(fudgeFactor) };
53   json_number_s jActualValue{ JSON_STRING(5.2) };
54   json_value_s jvalue { &jActualValue, json_type_number };
55   json_object_element_s jobjelem { &jkey, &jvalue, nullptr };
56
57   json_object_s jobj{ &jobjelem, 1 };
58
59   DALI_TEST_EQUAL(json::FindObjectChild(jkey.string, jobj), &jvalue);
60   DALI_TEST_EQUAL(json::FindObjectChild("fudgeFactory", jobj), static_cast<json_value_s*>(nullptr));
61
62   END_TEST;
63 }