2 * Copyright (c) 2019 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.
19 #include <dali-toolkit-test-suite-utils.h>
20 #include <dali/public-api/rendering/texture-set.h>
21 #include <dali/public-api/rendering/texture.h>
22 #include <dali-toolkit/devel-api/image-loader/texture-manager.h>
25 using namespace Dali::Toolkit;
32 void dali_texture_manager_startup(void)
34 test_return_value = TET_UNDEF;
37 void dali_texture_manager_cleanup(void)
39 test_return_value = TET_PASS;
42 int UtcDaliTextureManagerAddRemoveP(void)
44 ToolkitTestApplication application;
45 tet_infoline( "UtcDaliTextureManager" );
51 // scope to ensure texturesets are kept alive by texture manager
53 auto texture = Texture::New( Dali::TextureType::TEXTURE_2D, Pixel::RGBA8888, 88, 99 );
54 url = TextureManager::AddTexture( texture );
55 DALI_TEST_CHECK( url.size() > 0u );
57 auto textureSet = TextureSet::New();
58 textureSet.SetTexture( 0u, texture );
59 url2 = TextureManager::AddTexture( textureSet );
60 DALI_TEST_CHECK( url2.size() > 0u );
61 DALI_TEST_CHECK( url2 != url );
63 // add same texture again, should give new Url
64 url3 = TextureManager::AddTexture( texture );
65 DALI_TEST_CHECK( url3.size() > 0u );
66 DALI_TEST_CHECK( url3 != url );
67 DALI_TEST_CHECK( url3 != url2 );
69 textureSet = TextureSet::New();
70 url4 = TextureManager::AddTexture( textureSet );
71 DALI_TEST_CHECK( url4.size() > 0u );
72 DALI_TEST_CHECK( url4 != url );
73 DALI_TEST_CHECK( url4 != url2 );
74 DALI_TEST_CHECK( url4 != url3 );
77 auto textureSet = TextureManager::RemoveTexture( url );
78 DALI_TEST_CHECK( textureSet && "Texture needs to be non empty handle" );
79 auto texture = textureSet.GetTexture( 0u );
80 DALI_TEST_EQUAL( texture.GetWidth(), 88u );
81 DALI_TEST_EQUAL( texture.GetHeight(), 99u );
82 textureSet = TextureManager::RemoveTexture( url );
83 DALI_TEST_CHECK( !textureSet && "Texture needs to be removed from texture manager" );
85 textureSet = TextureManager::RemoveTexture( url2 );
86 DALI_TEST_CHECK( textureSet && "Texture needs to be non empty handle" );
87 texture = textureSet.GetTexture( 0u );
88 DALI_TEST_EQUAL( texture.GetWidth(), 88u );
89 DALI_TEST_EQUAL( texture.GetHeight(), 99u );
90 textureSet = TextureManager::RemoveTexture( url2 );
91 DALI_TEST_CHECK( !textureSet && "Texture needs to be removed from texture manager" );
93 textureSet = TextureManager::RemoveTexture( url3 );
94 DALI_TEST_CHECK( textureSet && "Texture needs to be non empty handle" );
95 texture = textureSet.GetTexture( 0u );
96 DALI_TEST_EQUAL( texture.GetWidth(), 88u );
97 DALI_TEST_EQUAL( texture.GetHeight(), 99u );
98 textureSet = TextureManager::RemoveTexture( url3 );
99 DALI_TEST_CHECK( !textureSet && "Texture needs to be removed from texture manager" );
101 textureSet = TextureManager::RemoveTexture( url4 );
102 DALI_TEST_CHECK( textureSet && "Texture needs to be non empty handle" );
103 textureSet = TextureManager::RemoveTexture( url4 );
104 DALI_TEST_CHECK( !textureSet && "Texture needs to be removed from texture manager" );
109 int UtcDaliTextureManagerAddN(void)
111 ToolkitTestApplication application;
112 tet_infoline( "UtcDaliTextureManager" );
114 // empty texture is ok, though pointless from app point of view
116 std::string url = TextureManager::AddTexture( empty );
117 DALI_TEST_CHECK( url.size() > 0u );
122 int UtcDaliTextureManagerRemoveN(void)
124 ToolkitTestApplication application;
125 tet_infoline( "UtcDaliTextureManager" );
127 // removing empty texture returns empty handle
128 auto texture = TextureManager::RemoveTexture( "" );
129 DALI_TEST_CHECK( !texture && "Texture should not be found" );
131 // removing empty texture returns empty handle
132 texture = TextureManager::RemoveTexture( "dali://" );
133 DALI_TEST_CHECK( !texture && "Texture should not be found" );
135 // empty texture is ok, though pointless from app point of view
137 std::string url = TextureManager::AddTexture( empty );
138 DALI_TEST_CHECK( url.size() > 0u );
139 // removing texture with wrong URL returns empty handle
140 texture = TextureManager::RemoveTexture( "dali://" );
141 DALI_TEST_CHECK( !texture && "Texture should not be found" );
143 // removing ftp texture returns empty handle
144 texture = TextureManager::RemoveTexture( "ftp://foobar" );
145 DALI_TEST_CHECK( !texture && "Texture should not be found" );
148 url = TextureManager::AddTexture( texture );
149 texture = TextureManager::RemoveTexture( url + "foo" );
150 DALI_TEST_CHECK( !texture && "Texture should not be found" );