Merge "Do not clear keyboard focus on touch when alwaysShowFocus is true." into devel...
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-TextureManager.cpp
1 /*
2  * Copyright (c) 2017 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 <iostream>
18 #include <stdlib.h>
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>
23
24 using namespace Dali;
25 using namespace Dali::Toolkit;
26
27 namespace
28 {
29
30 } // namespace
31
32
33 void dali_texture_manager_startup(void)
34 {
35   test_return_value = TET_UNDEF;
36 }
37
38 void dali_texture_manager_cleanup(void)
39 {
40   test_return_value = TET_PASS;
41 }
42
43 int UtcDaliTextureManagerAddRemoveP(void)
44 {
45   ToolkitTestApplication application;
46   tet_infoline( "UtcDaliTextureManager" );
47
48   std::string url;
49   std::string url2;
50   std::string url3;
51   std::string url4;
52   // scope to ensure texturesets are kept alive by texture manager
53   {
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 );
57
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 );
63
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 );
69
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 );
76   }
77
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" );
85
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" );
93
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" );
101
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" );
106
107   END_TEST;
108 }
109
110 int UtcDaliTextureManagerAddN(void)
111 {
112   ToolkitTestApplication application;
113   tet_infoline( "UtcDaliTextureManager" );
114
115   // empty texture is ok, though pointless from app point of view
116   TextureSet empty;
117   std::string url = TextureManager::AddTexture( empty );
118   DALI_TEST_CHECK( url.size() > 0u );
119
120   END_TEST;
121 }
122
123 int UtcDaliTextureManagerRemoveN(void)
124 {
125   ToolkitTestApplication application;
126   tet_infoline( "UtcDaliTextureManager" );
127
128   // removing empty texture returns empty handle
129   auto texture = TextureManager::RemoveTexture( "" );
130   DALI_TEST_CHECK( !texture && "Texture should not be found" );
131
132   // removing empty texture returns empty handle
133   texture = TextureManager::RemoveTexture( "dali://" );
134   DALI_TEST_CHECK( !texture && "Texture should not be found" );
135
136   // empty texture is ok, though pointless from app point of view
137   TextureSet empty;
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" );
143
144   // removing ftp texture returns empty handle
145   texture = TextureManager::RemoveTexture( "ftp://foobar" );
146   DALI_TEST_CHECK( !texture && "Texture should not be found" );
147
148   // add a texture
149   url = TextureManager::AddTexture( texture );
150   texture = TextureManager::RemoveTexture( url + "foo" );
151   DALI_TEST_CHECK( !texture && "Texture should not be found" );
152
153   END_TEST;
154 }
155
156
157