[dali_1.9.0] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-internal / utc-Dali-TextureManager.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 #include <iostream>
19
20 #include <stdlib.h>
21
22 #include <dali-toolkit-test-suite-utils.h>
23 #include <dali-toolkit/internal/visuals/texture-manager-impl.h>
24 #include <dali-toolkit/internal/visuals/texture-upload-observer.h>
25
26 using namespace Dali::Toolkit::Internal;
27
28
29 void utc_dali_toolkit_texture_manager_startup(void)
30 {
31   setenv( "LOG_TEXTURE_MANAGER", "3", 1 );
32   test_return_value = TET_UNDEF;
33 }
34
35 void utc_dali_toolkit_texture_manager_cleanup(void)
36 {
37   test_return_value = TET_PASS;
38 }
39
40 class TestObserver : public Dali::Toolkit::TextureUploadObserver
41 {
42 public:
43   TestObserver()
44   : mLoaded(false),
45     mObserverCalled(false)
46   {
47   }
48
49   virtual void UploadComplete( bool loadSuccess, int32_t textureId, TextureSet textureSet,
50                                bool useAtlasing, const Vector4& atlasRect, bool preMultiplied ) override
51   {
52     mLoaded = loadSuccess;
53     mObserverCalled = true;
54   }
55
56   virtual void LoadComplete( bool loadSuccess, Devel::PixelBuffer pixelBuffer, const VisualUrl& url, bool preMultiplied ) override
57   {
58     mLoaded = loadSuccess;
59     mObserverCalled = true;
60   }
61
62   bool mLoaded;
63   bool mObserverCalled;
64 };
65
66
67 int UtcTextureManagerRequestLoad(void)
68 {
69   ToolkitTestApplication application;
70
71   TextureManager textureManager; // Create new texture manager
72
73   TestObserver observer;
74   std::string filename("image.png");
75   auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
76   TextureManager::TextureId textureId = textureManager.RequestLoad(
77     filename,
78     ImageDimensions(),
79     FittingMode::SCALE_TO_FILL,
80     SamplingMode::BOX_THEN_LINEAR,
81     TextureManager::NO_ATLAS,
82     &observer,
83     true,
84     TextureManager::ReloadPolicy::CACHED,
85     preMultiply);
86
87   VisualUrl url = textureManager.GetVisualUrl( textureId );
88
89   DALI_TEST_EQUALS( url.GetUrl().compare( filename ), 0, TEST_LOCATION );
90
91   END_TEST;
92 }
93
94 int UtcTextureManagerGenerateHash(void)
95 {
96   ToolkitTestApplication application;
97
98   TextureManager textureManager; // Create new texture manager
99
100   TestObserver observer;
101   std::string filename( "image.png" );
102   auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
103   TextureManager::TextureId textureId = textureManager.RequestLoad(
104     filename,
105     ImageDimensions(),
106     FittingMode::SCALE_TO_FILL,
107     SamplingMode::BOX_THEN_LINEAR,
108     TextureManager::USE_ATLAS,
109     &observer,
110     true,
111     TextureManager::ReloadPolicy::CACHED,
112     preMultiply);
113
114   VisualUrl url = textureManager.GetVisualUrl( textureId );
115
116   DALI_TEST_EQUALS( url.GetUrl().compare( filename ), 0, TEST_LOCATION );
117
118   END_TEST;
119 }