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-test-suite-utils.h>
22 #include <string_view>
23 #include "dali-scene3d/public-api/loader/resource-bundle.h"
24 #include "dali-scene3d/public-api/loader/utils.h"
27 using namespace Dali::Scene3D::Loader;
29 int UtcDaliResourceRefCounts(void)
31 ResourceBundle resourceBundle;
32 resourceBundle.mEnvironmentMaps.resize(4);
33 resourceBundle.mShaders.resize(13);
34 resourceBundle.mMeshes.resize(17);
35 resourceBundle.mMaterials.resize(19);
38 std::vector<int> testEnvironmentReferences(resourceBundle.mEnvironmentMaps.size());
39 for(auto& m : resourceBundle.mMaterials)
43 iEnv += ((i % 4) == 0) * 2;
44 m.first.mEnvironmentIdx = iEnv;
46 printf("%d : %d, ", i, iEnv);
48 ++testEnvironmentReferences[iEnv];
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());
58 std::fill(counter[ResourceType::Material].begin(), counter[ResourceType::Material].end(), 1u);
59 resourceBundle.mReferenceCounts = std::move(counter);
60 resourceBundle.CountEnvironmentReferences();
62 const ResourceRefCounts& referenceCounts = resourceBundle.mReferenceCounts;
64 for(auto& er : referenceCounts[ResourceType::Environment])
66 DALI_TEST_EQUAL(er, testEnvironmentReferences[i]);