Change dali-scene-loader to dali-scene3d
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-scene3d / utc-Dali-ResourceBundle.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/resource-bundle.h"
22 #include "dali-scene3d/public-api/loader/utils.h"
23 #include <dali-test-suite-utils.h>
24 #include <string_view>
25
26 using namespace Dali;
27 using namespace Dali::Scene3D::Loader;
28
29 int UtcDaliResourceRefCounts(void)
30 {
31   ResourceBundle resourceBundle;
32   resourceBundle.mEnvironmentMaps.resize(4);
33   resourceBundle.mShaders.resize(13);
34   resourceBundle.mMeshes.resize(17);
35   resourceBundle.mMaterials.resize(19);
36
37   int i = 0;
38   std::vector<int> testEnvironmentReferences(resourceBundle.mEnvironmentMaps.size());
39   for (auto& m : resourceBundle.mMaterials)
40   {
41     Index iEnv = 0;
42     iEnv += (i % 3) == 0;
43     iEnv += ((i % 4) == 0) * 2;
44     m.first.mEnvironmentIdx = iEnv;
45
46     printf("%d : %d, ", i, iEnv);
47
48     ++testEnvironmentReferences[iEnv];
49     ++i;
50   }
51
52   auto counter = resourceBundle.CreateRefCounter();
53   DALI_TEST_EQUAL(counter[ResourceType::Environment].Size(), resourceBundle.mEnvironmentMaps.size());
54   DALI_TEST_EQUAL(counter[ResourceType::Shader].Size(), resourceBundle.mShaders.size());
55   DALI_TEST_EQUAL(counter[ResourceType::Mesh].Size(), resourceBundle.mMeshes.size());
56   DALI_TEST_EQUAL(counter[ResourceType::Material].Size(), resourceBundle.mMaterials.size());
57
58   std::fill(counter[ResourceType::Material].begin(), counter[ResourceType::Material].end(), 1u);
59   resourceBundle.CountEnvironmentReferences(counter);
60   i = 0;
61   for (auto& er: counter[ResourceType::Environment])
62   {
63     DALI_TEST_EQUAL(er, testEnvironmentReferences[i]);
64     ++i;
65   }
66
67   END_TEST;
68 }