Removed redundant resource loading & rendering code
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Image.cpp
1 /*
2  * Copyright (c) 2016 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 #include <algorithm>
20 #include <stdlib.h>
21 #include <dali/public-api/dali-core.h>
22 #include <dali/integration-api/bitmap.h>
23 #include <dali-test-suite-utils.h>
24 #include <test-native-image.h>
25
26 using namespace Dali;
27
28 void utc_dali_image_startup(void)
29 {
30   test_return_value = TET_UNDEF;
31 }
32
33 void utc_dali_image_cleanup(void)
34 {
35   test_return_value = TET_PASS;
36 }
37
38 static const char* gTestImageFilename = "icon_wrt.png";
39
40 namespace
41 {
42
43 }
44
45 int UtcDaliImageDownCast(void)
46 {
47   TestApplication application;
48   tet_infoline("Testing Dali::Image::DownCast()");
49
50   Image image = ResourceImage::New(gTestImageFilename);
51
52   BaseHandle object(image);
53
54   Image image2 = Image::DownCast(object);
55   DALI_TEST_CHECK(image2);
56
57   Image image3 = DownCast< Image >(object);
58   DALI_TEST_CHECK(image3);
59
60   BaseHandle unInitializedObject;
61   Image image4 = Image::DownCast(unInitializedObject);
62   DALI_TEST_CHECK(!image4);
63
64   Image image5 = DownCast< Image >(unInitializedObject);
65   DALI_TEST_CHECK(!image5);
66   END_TEST;
67 }
68
69 int UtcDaliImageGetWidthHeight(void)
70 {
71   TestApplication application;
72
73   tet_infoline("UtcDaliImageGetWidthHeight - Image::GetWidth() & Image::GetHeight");
74
75   Vector2 testSize(8.0f, 16.0f);
76   application.GetPlatform().SetClosestImageSize(testSize);
77   PrepareResourceImage( application, testSize.x, testSize.y, Pixel::RGBA8888 );
78   Image image1 = ResourceImage::New(gTestImageFilename);
79   DALI_TEST_EQUALS( image1.GetWidth(), testSize.x, TEST_LOCATION );
80   DALI_TEST_EQUALS( image1.GetHeight(), testSize.y, TEST_LOCATION );
81
82   testSize = Vector2(128.0f, 256.0f);
83   PrepareResourceImage( application, testSize.x, testSize.y, Pixel::RGBA8888 );
84   Image image2 = ResourceImage::New( gTestImageFilename, ImageDimensions(testSize.x, testSize.y), FittingMode::SCALE_TO_FILL, SamplingMode::DEFAULT );
85   DALI_TEST_EQUALS( image2.GetWidth(), testSize.x, TEST_LOCATION );
86   DALI_TEST_EQUALS( image2.GetHeight(), testSize.y, TEST_LOCATION );
87
88   testSize = Vector2(16.0f, 32.0f);
89   Image image3 = FrameBufferImage::New(testSize.x, testSize.y);
90   DALI_TEST_EQUALS(image3.GetWidth(), testSize.x, TEST_LOCATION);
91   DALI_TEST_EQUALS(image3.GetHeight(), testSize.y, TEST_LOCATION);
92
93   testSize = Vector2(32.0f, 64.0f);
94   PrepareResourceImage( application, testSize.x, testSize.y, Pixel::RGBA8888 );
95   TestNativeImagePointer nativeImage = TestNativeImage::New(testSize.x, testSize.y);
96   Image image4 = NativeImage::New(*(nativeImage.Get()));
97   DALI_TEST_EQUALS(image4.GetWidth(), testSize.x, TEST_LOCATION);
98   DALI_TEST_EQUALS(image4.GetHeight(), testSize.y, TEST_LOCATION);
99
100   END_TEST;
101 }
102
103 int UtcDaliImageDiscard01(void)
104 {
105   TestApplication application;
106   tet_infoline("UtcDaliImageDiscard01 - no actors");
107
108   {
109     Image image = ResourceImage::New(gTestImageFilename);
110
111     // Load image
112     application.SendNotification();
113     application.Render(16);
114     std::vector<GLuint> ids;
115     ids.push_back( 23 );
116     application.GetGlAbstraction().SetNextTextureIds( ids );
117     application.Render(16);
118     application.SendNotification();
119   } // Drop image handle
120
121   application.SendNotification();
122   application.Render(16);
123   application.Render(16);
124   application.SendNotification();
125
126   // Shouldn't have been sent to GL...
127   const std::vector<GLuint>& texIds = application.GetGlAbstraction().GetNextTextureIds();
128   DALI_TEST_CHECK( texIds.size() == 1 );
129   DALI_TEST_CHECK( texIds[0] == 23 );
130   END_TEST;
131 }