Merge "(Automated Tests) All tests passing on Ubuntu 16.04" into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-internal / 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
18 #include <iostream>
19
20 #include <stdlib.h>
21
22 #include <dali-toolkit-test-suite-utils.h>
23 #include <dali-toolkit/internal/visuals/texture-manager-impl.h>
24 #include <dali-toolkit/internal/visuals/texture-upload-observer.h>
25
26 using namespace Dali::Toolkit::Internal;
27
28
29 void utc_dali_toolkit_texture_manager_startup(void)
30 {
31   setenv( "LOG_TEXTURE_MANAGER", "3", 1 );
32   test_return_value = TET_UNDEF;
33 }
34
35 void utc_dali_toolkit_texture_manager_cleanup(void)
36 {
37   test_return_value = TET_PASS;
38 }
39
40 class TestObserver : public Dali::Toolkit::TextureUploadObserver
41 {
42 public:
43   TestObserver()
44   : mLoaded(false),
45     mObserverCalled(false)
46   {
47   }
48
49   virtual void UploadComplete( bool loadSuccess, int32_t textureId, TextureSet textureSet,
50                                bool useAtlasing, const Vector4& atlasRect, bool preMultiplied ) override
51   {
52     mLoaded = loadSuccess;
53     mObserverCalled = true;
54   }
55
56   bool mLoaded;
57   bool mObserverCalled;
58 };
59
60
61 int UtcTextureManagerRequestLoad(void)
62 {
63   ToolkitTestApplication application;
64
65   TextureManager textureManager; // Create new texture manager
66
67   TestObserver observer;
68   std::string filename("image.png");
69   auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
70   TextureManager::TextureId textureId = textureManager.RequestLoad(
71     filename,
72     ImageDimensions(),
73     FittingMode::SCALE_TO_FILL,
74     SamplingMode::BOX_THEN_LINEAR,
75     TextureManager::NO_ATLAS,
76     &observer,
77     true,
78     TextureManager::ReloadPolicy::CACHED,
79     preMultiply);
80
81   VisualUrl url = textureManager.GetVisualUrl( textureId );
82
83   DALI_TEST_EQUALS( url.GetUrl().compare( filename ), 0, TEST_LOCATION );
84
85   END_TEST;
86 }
87
88 int UtcTextureManagerGenerateHash(void)
89 {
90   ToolkitTestApplication application;
91
92   TextureManager textureManager; // Create new texture manager
93
94   TestObserver observer;
95   std::string filename( "image.png" );
96   auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
97   TextureManager::TextureId textureId = textureManager.RequestLoad(
98     filename,
99     ImageDimensions(),
100     FittingMode::SCALE_TO_FILL,
101     SamplingMode::BOX_THEN_LINEAR,
102     TextureManager::USE_ATLAS,
103     &observer,
104     true,
105     TextureManager::ReloadPolicy::CACHED,
106     preMultiply);
107
108   VisualUrl url = textureManager.GetVisualUrl( textureId );
109
110   DALI_TEST_EQUALS( url.GetUrl().compare( filename ), 0, TEST_LOCATION );
111
112   END_TEST;
113 }