2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 // Enable debug log for test coverage
19 #define DEBUG_ENABLED 1
21 #include "dali-scene3d/public-api/loader/alpha-function-helper.h"
22 #include <dali-test-suite-utils.h>
25 using namespace Dali::Scene3D::Loader;
27 #define ALPHA_FN_PAIR(x) { #x, AlphaFunction::x }
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),
43 ALPHA_FN_PAIR(EASE_OUT_BACK),
46 int UtcDaliAlphaFunctionHelperGet(void)
49 for (auto& a: BUILTIN_FUNCTIONS)
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);
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);
65 int UtcDaliAlphaFunctionHelperRegister(void)
67 for (auto& a: BUILTIN_FUNCTIONS)
69 DALI_TEST_ASSERTION(RegisterAlphaFunction(a.first, AlphaFunction()), "given key already exists");
72 AlphaFunctionPrototype testFn = [](float f) {
73 return f > .5f ? 1.f : 0.f;
75 RegisterAlphaFunction("step", AlphaFunction(testFn));
78 auto result = GetAlphaFunction("step", &found);
79 DALI_TEST_EQUAL(result.GetMode(), AlphaFunction::CUSTOM_FUNCTION);
80 DALI_TEST_EQUAL(result.GetCustomFunction(), testFn);