Merge "(Automated Tests) All tests passing on Ubuntu 16.04" into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-TextureManager.cpp
1 /*
2  * Copyright (c) 2019 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 } // namespace
30
31
32 void dali_texture_manager_startup(void)
33 {
34   test_return_value = TET_UNDEF;
35 }
36
37 void dali_texture_manager_cleanup(void)
38 {
39   test_return_value = TET_PASS;
40 }
41
42 int UtcDaliTextureManagerAddRemoveP(void)
43 {
44   ToolkitTestApplication application;
45   tet_infoline( "UtcDaliTextureManager" );
46
47   std::string url;
48   std::string url2;
49   std::string url3;
50   std::string url4;
51   // scope to ensure texturesets are kept alive by texture manager
52   {
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 );
56
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 );
62
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 );
68
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 );
75   }
76
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" );
84
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" );
92
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" );
100
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" );
105
106   END_TEST;
107 }
108
109 int UtcDaliTextureManagerAddN(void)
110 {
111   ToolkitTestApplication application;
112   tet_infoline( "UtcDaliTextureManager" );
113
114   // empty texture is ok, though pointless from app point of view
115   TextureSet empty;
116   std::string url = TextureManager::AddTexture( empty );
117   DALI_TEST_CHECK( url.size() > 0u );
118
119   END_TEST;
120 }
121
122 int UtcDaliTextureManagerRemoveN(void)
123 {
124   ToolkitTestApplication application;
125   tet_infoline( "UtcDaliTextureManager" );
126
127   // removing empty texture returns empty handle
128   auto texture = TextureManager::RemoveTexture( "" );
129   DALI_TEST_CHECK( !texture && "Texture should not be found" );
130
131   // removing empty texture returns empty handle
132   texture = TextureManager::RemoveTexture( "dali://" );
133   DALI_TEST_CHECK( !texture && "Texture should not be found" );
134
135   // empty texture is ok, though pointless from app point of view
136   TextureSet empty;
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" );
142
143   // removing ftp texture returns empty handle
144   texture = TextureManager::RemoveTexture( "ftp://foobar" );
145   DALI_TEST_CHECK( !texture && "Texture should not be found" );
146
147   // add a texture
148   url = TextureManager::AddTexture( texture );
149   texture = TextureManager::RemoveTexture( url + "foo" );
150   DALI_TEST_CHECK( !texture && "Texture should not be found" );
151
152   END_TEST;
153 }