2 * Copyright (c) 2022 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.
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>
25 using namespace Dali::Toolkit;
31 void dali_texture_manager_startup(void)
33 test_return_value = TET_UNDEF;
36 void dali_texture_manager_cleanup(void)
38 test_return_value = TET_PASS;
41 int UtcDaliTextureManagerAddRemoveP(void)
43 ToolkitTestApplication application;
44 tet_infoline("UtcDaliTextureManager");
50 // scope to ensure texturesets are kept alive by texture manager
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);
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);
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);
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);
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");
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");
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");
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");
108 int UtcDaliTextureManagerAddN(void)
110 ToolkitTestApplication application;
111 tet_infoline("UtcDaliTextureManager");
113 // empty texture is ok, though pointless from app point of view
115 std::string url = TextureManager::AddTexture(empty);
116 DALI_TEST_CHECK(url.size() > 0u);
121 int UtcDaliTextureManagerRemoveN(void)
123 ToolkitTestApplication application;
124 tet_infoline("UtcDaliTextureManager");
126 // removing empty texture returns empty handle
127 auto texture = TextureManager::RemoveTexture("");
128 DALI_TEST_CHECK(!texture && "Texture should not be found");
130 // removing empty texture returns empty handle
131 texture = TextureManager::RemoveTexture("dali://");
132 DALI_TEST_CHECK(!texture && "Texture should not be found");
134 // empty texture is ok, though pointless from app point of view
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");
142 // removing ftp texture returns empty handle
143 texture = TextureManager::RemoveTexture("ftp://foobar");
144 DALI_TEST_CHECK(!texture && "Texture should not be found");
147 url = TextureManager::AddTexture(texture);
148 texture = TextureManager::RemoveTexture(url + "foo");
149 DALI_TEST_CHECK(!texture && "Texture should not be found");