All tests now output results to xml files
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-scene-loader-internal / utc-Dali-Hash.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/hash.h"
22 #include <dali-test-suite-utils.h>
23 #include <string>
24
25 using namespace Dali;
26 using namespace Dali::SceneLoader;
27
28 int UtcDaliHash(void)
29 {
30   DALI_TEST_EQUAL(Hash(0).Add(true), 0);
31   DALI_TEST_EQUAL(Hash(0).Add(false), 1);
32
33   int32_t myInt32 = std::numeric_limits<int32_t>::min();
34   DALI_TEST_EQUAL(Hash(0).Add(myInt32), myInt32);
35
36   uint32_t myUint32 = std::numeric_limits<uint32_t>::max();
37   DALI_TEST_EQUAL(Hash(0).Add(myUint32), myUint32);
38
39   uint64_t myUint64 = std::numeric_limits<uint64_t>::max();
40   DALI_TEST_EQUAL(uint64_t(Hash(0).Add(myUint64)), myUint64);
41
42   constexpr uint32_t multiplier = 31;
43   uint64_t expected = 0;
44   float f = 1928.46852;
45   for (auto i0 = reinterpret_cast<uint8_t const*>(&f), i1 = i0 + sizeof(f); i0 != i1; ++i0)
46   {
47     expected = expected * multiplier + *i0;
48   }
49
50   DALI_TEST_EQUAL(uint64_t(Hash(0).Add(f)), expected);
51
52   END_TEST;
53 }
54