Updating code formatting
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-TextureManager.cpp
1 /*
2  * Copyright (c) 2022 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 #include <dali-toolkit-test-suite-utils.h>
18 #include <dali-toolkit/devel-api/image-loader/texture-manager.h>
19 #include <dali/public-api/rendering/texture-set.h>
20 #include <dali/public-api/rendering/texture.h>
21 #include <stdlib.h>
22 #include <iostream>
23
24 using namespace Dali;
25 using namespace Dali::Toolkit;
26
27 namespace
28 {
29 } // namespace
30
31 void dali_texture_manager_startup(void)
32 {
33   test_return_value = TET_UNDEF;
34 }
35
36 void dali_texture_manager_cleanup(void)
37 {
38   test_return_value = TET_PASS;
39 }
40
41 int UtcDaliTextureManagerAddRemoveP(void)
42 {
43   ToolkitTestApplication application;
44   tet_infoline("UtcDaliTextureManager");
45
46   std::string url;
47   std::string url2;
48   std::string url3;
49   std::string url4;
50   // scope to ensure texturesets are kept alive by texture manager
51   {
52     auto texture = Texture::New(Dali::TextureType::TEXTURE_2D, Pixel::RGBA8888, 88, 99);
53     url          = TextureManager::AddTexture(texture);
54     DALI_TEST_CHECK(url.size() > 0u);
55
56     auto textureSet = TextureSet::New();
57     textureSet.SetTexture(0u, texture);
58     url2 = TextureManager::AddTexture(textureSet);
59     DALI_TEST_CHECK(url2.size() > 0u);
60     DALI_TEST_CHECK(url2 != url);
61
62     // add same texture again, should give new Url
63     url3 = TextureManager::AddTexture(texture);
64     DALI_TEST_CHECK(url3.size() > 0u);
65     DALI_TEST_CHECK(url3 != url);
66     DALI_TEST_CHECK(url3 != url2);
67
68     textureSet = TextureSet::New();
69     url4       = TextureManager::AddTexture(textureSet);
70     DALI_TEST_CHECK(url4.size() > 0u);
71     DALI_TEST_CHECK(url4 != url);
72     DALI_TEST_CHECK(url4 != url2);
73     DALI_TEST_CHECK(url4 != url3);
74   }
75
76   auto textureSet = TextureManager::RemoveTexture(url);
77   DALI_TEST_CHECK(textureSet && "Texture needs to be non empty handle");
78   auto texture = textureSet.GetTexture(0u);
79   DALI_TEST_EQUAL(texture.GetWidth(), 88u);
80   DALI_TEST_EQUAL(texture.GetHeight(), 99u);
81   textureSet = TextureManager::RemoveTexture(url);
82   DALI_TEST_CHECK(!textureSet && "Texture needs to be removed from texture manager");
83
84   textureSet = TextureManager::RemoveTexture(url2);
85   DALI_TEST_CHECK(textureSet && "Texture needs to be non empty handle");
86   texture = textureSet.GetTexture(0u);
87   DALI_TEST_EQUAL(texture.GetWidth(), 88u);
88   DALI_TEST_EQUAL(texture.GetHeight(), 99u);
89   textureSet = TextureManager::RemoveTexture(url2);
90   DALI_TEST_CHECK(!textureSet && "Texture needs to be removed from texture manager");
91
92   textureSet = TextureManager::RemoveTexture(url3);
93   DALI_TEST_CHECK(textureSet && "Texture needs to be non empty handle");
94   texture = textureSet.GetTexture(0u);
95   DALI_TEST_EQUAL(texture.GetWidth(), 88u);
96   DALI_TEST_EQUAL(texture.GetHeight(), 99u);
97   textureSet = TextureManager::RemoveTexture(url3);
98   DALI_TEST_CHECK(!textureSet && "Texture needs to be removed from texture manager");
99
100   textureSet = TextureManager::RemoveTexture(url4);
101   DALI_TEST_CHECK(textureSet && "Texture needs to be non empty handle");
102   textureSet = TextureManager::RemoveTexture(url4);
103   DALI_TEST_CHECK(!textureSet && "Texture needs to be removed from texture manager");
104
105   END_TEST;
106 }
107
108 int UtcDaliTextureManagerAddN(void)
109 {
110   ToolkitTestApplication application;
111   tet_infoline("UtcDaliTextureManager");
112
113   // empty texture is ok, though pointless from app point of view
114   TextureSet  empty;
115   std::string url = TextureManager::AddTexture(empty);
116   DALI_TEST_CHECK(url.size() > 0u);
117
118   END_TEST;
119 }
120
121 int UtcDaliTextureManagerRemoveN(void)
122 {
123   ToolkitTestApplication application;
124   tet_infoline("UtcDaliTextureManager");
125
126   // removing empty texture returns empty handle
127   auto texture = TextureManager::RemoveTexture("");
128   DALI_TEST_CHECK(!texture && "Texture should not be found");
129
130   // removing empty texture returns empty handle
131   texture = TextureManager::RemoveTexture("dali://");
132   DALI_TEST_CHECK(!texture && "Texture should not be found");
133
134   // empty texture is ok, though pointless from app point of view
135   TextureSet  empty;
136   std::string url = TextureManager::AddTexture(empty);
137   DALI_TEST_CHECK(url.size() > 0u);
138   // removing texture with wrong URL returns empty handle
139   texture = TextureManager::RemoveTexture("dali://");
140   DALI_TEST_CHECK(!texture && "Texture should not be found");
141
142   // removing ftp texture returns empty handle
143   texture = TextureManager::RemoveTexture("ftp://foobar");
144   DALI_TEST_CHECK(!texture && "Texture should not be found");
145
146   // add a texture
147   url     = TextureManager::AddTexture(texture);
148   texture = TextureManager::RemoveTexture(url + "foo");
149   DALI_TEST_CHECK(!texture && "Texture should not be found");
150
151   END_TEST;
152 }