2 * Copyright (c) 2017 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;
33 void dali_texture_manager_startup(void)
35 test_return_value = TET_UNDEF;
38 void dali_texture_manager_cleanup(void)
40 test_return_value = TET_PASS;
43 int UtcDaliTextureManagerAddRemoveP(void)
45 ToolkitTestApplication application;
46 tet_infoline( "UtcDaliTextureManager" );
52 // scope to ensure texturesets are kept alive by texture manager
54 auto texture = Texture::New( Dali::TextureType::TEXTURE_2D, Pixel::RGBA8888, 88, 99 );
55 url = TextureManager::AddTexture( texture );
56 DALI_TEST_CHECK( url.size() > 0u );
58 auto textureSet = TextureSet::New();
59 textureSet.SetTexture( 0u, texture );
60 url2 = TextureManager::AddTexture( textureSet );
61 DALI_TEST_CHECK( url2.size() > 0u );
62 DALI_TEST_CHECK( url2 != url );
64 // add same texture again, should give new Url
65 url3 = TextureManager::AddTexture( texture );
66 DALI_TEST_CHECK( url3.size() > 0u );
67 DALI_TEST_CHECK( url3 != url );
68 DALI_TEST_CHECK( url3 != url2 );
70 textureSet = TextureSet::New();
71 url4 = TextureManager::AddTexture( textureSet );
72 DALI_TEST_CHECK( url4.size() > 0u );
73 DALI_TEST_CHECK( url4 != url );
74 DALI_TEST_CHECK( url4 != url2 );
75 DALI_TEST_CHECK( url4 != url3 );
78 auto textureSet = TextureManager::RemoveTexture( url );
79 DALI_TEST_CHECK( textureSet && "Texture needs to be non empty handle" );
80 auto texture = textureSet.GetTexture( 0u );
81 DALI_TEST_EQUAL( texture.GetWidth(), 88u );
82 DALI_TEST_EQUAL( texture.GetHeight(), 99u );
83 textureSet = TextureManager::RemoveTexture( url );
84 DALI_TEST_CHECK( !textureSet && "Texture needs to be removed from texture manager" );
86 textureSet = TextureManager::RemoveTexture( url2 );
87 DALI_TEST_CHECK( textureSet && "Texture needs to be non empty handle" );
88 texture = textureSet.GetTexture( 0u );
89 DALI_TEST_EQUAL( texture.GetWidth(), 88u );
90 DALI_TEST_EQUAL( texture.GetHeight(), 99u );
91 textureSet = TextureManager::RemoveTexture( url2 );
92 DALI_TEST_CHECK( !textureSet && "Texture needs to be removed from texture manager" );
94 textureSet = TextureManager::RemoveTexture( url3 );
95 DALI_TEST_CHECK( textureSet && "Texture needs to be non empty handle" );
96 texture = textureSet.GetTexture( 0u );
97 DALI_TEST_EQUAL( texture.GetWidth(), 88u );
98 DALI_TEST_EQUAL( texture.GetHeight(), 99u );
99 textureSet = TextureManager::RemoveTexture( url3 );
100 DALI_TEST_CHECK( !textureSet && "Texture needs to be removed from texture manager" );
102 textureSet = TextureManager::RemoveTexture( url4 );
103 DALI_TEST_CHECK( textureSet && "Texture needs to be non empty handle" );
104 textureSet = TextureManager::RemoveTexture( url4 );
105 DALI_TEST_CHECK( !textureSet && "Texture needs to be removed from texture manager" );
110 int UtcDaliTextureManagerAddN(void)
112 ToolkitTestApplication application;
113 tet_infoline( "UtcDaliTextureManager" );
115 // empty texture is ok, though pointless from app point of view
117 std::string url = TextureManager::AddTexture( empty );
118 DALI_TEST_CHECK( url.size() > 0u );
123 int UtcDaliTextureManagerRemoveN(void)
125 ToolkitTestApplication application;
126 tet_infoline( "UtcDaliTextureManager" );
128 // removing empty texture returns empty handle
129 auto texture = TextureManager::RemoveTexture( "" );
130 DALI_TEST_CHECK( !texture && "Texture should not be found" );
132 // removing empty texture returns empty handle
133 texture = TextureManager::RemoveTexture( "dali://" );
134 DALI_TEST_CHECK( !texture && "Texture should not be found" );
136 // empty texture is ok, though pointless from app point of view
138 std::string url = TextureManager::AddTexture( empty );
139 DALI_TEST_CHECK( url.size() > 0u );
140 // removing texture with wrong URL returns empty handle
141 texture = TextureManager::RemoveTexture( "dali://" );
142 DALI_TEST_CHECK( !texture && "Texture should not be found" );
144 // removing ftp texture returns empty handle
145 texture = TextureManager::RemoveTexture( "ftp://foobar" );
146 DALI_TEST_CHECK( !texture && "Texture should not be found" );
149 url = TextureManager::AddTexture( texture );
150 texture = TextureManager::RemoveTexture( url + "foo" );
151 DALI_TEST_CHECK( !texture && "Texture should not be found" );