Compute min/max value if min/max is not defined.
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-scene3d / utc-Dali-AlphaFunctionHelper.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-scene3d/public-api/loader/alpha-function-helper.h"
22 #include <dali-test-suite-utils.h>
23
24 using namespace Dali;
25 using namespace Dali::Scene3D::Loader;
26
27 #define ALPHA_FN_PAIR(x) { #x, AlphaFunction::x }
28
29 const std::pair<std::string, AlphaFunction::BuiltinFunction> BUILTIN_FUNCTIONS[] {
30   ALPHA_FN_PAIR(DEFAULT),
31   ALPHA_FN_PAIR(LINEAR),
32   ALPHA_FN_PAIR(REVERSE),
33   ALPHA_FN_PAIR(EASE_IN),
34   ALPHA_FN_PAIR(EASE_OUT),
35   ALPHA_FN_PAIR(EASE_IN_OUT),
36   ALPHA_FN_PAIR(EASE_IN_SQUARE),
37   ALPHA_FN_PAIR(EASE_OUT_SQUARE),
38   ALPHA_FN_PAIR(EASE_IN_SINE),
39   ALPHA_FN_PAIR(EASE_OUT_SINE),
40   ALPHA_FN_PAIR(EASE_IN_OUT_SINE),
41   ALPHA_FN_PAIR(BOUNCE),
42   ALPHA_FN_PAIR(SIN),
43   ALPHA_FN_PAIR(EASE_OUT_BACK),
44 };
45
46 int UtcDaliAlphaFunctionHelperGet(void)
47 {
48   bool found;
49   for (auto& a: BUILTIN_FUNCTIONS)
50   {
51     auto result = GetAlphaFunction(a.first, &found);
52     DALI_TEST_EQUAL(result.GetBuiltinFunction(), a.second);
53     DALI_TEST_EQUAL(result.GetMode(), AlphaFunction::BUILTIN_FUNCTION);
54     DALI_TEST_CHECK(found);
55   }
56
57   auto result = GetAlphaFunction("made up function", &found);
58   DALI_TEST_EQUAL(result.GetBuiltinFunction(), AlphaFunction::DEFAULT);
59   DALI_TEST_EQUAL(result.GetMode(), AlphaFunction::BUILTIN_FUNCTION);
60   DALI_TEST_CHECK(!found);
61
62   END_TEST;
63 }
64
65 int UtcDaliAlphaFunctionHelperRegister(void)
66 {
67   for (auto& a: BUILTIN_FUNCTIONS)
68   {
69     DALI_TEST_ASSERTION(RegisterAlphaFunction(a.first, AlphaFunction()), "given key already exists");
70   }
71
72   AlphaFunctionPrototype testFn = [](float f) {
73     return f > .5f ? 1.f : 0.f;
74   };
75   RegisterAlphaFunction("step", AlphaFunction(testFn));
76
77   bool found;
78   auto result = GetAlphaFunction("step", &found);
79   DALI_TEST_EQUAL(result.GetMode(), AlphaFunction::CUSTOM_FUNCTION);
80   DALI_TEST_EQUAL(result.GetCustomFunction(), testFn);
81
82   END_TEST;
83 }