[windows] Return the key name for ascii letters
[platform/core/uifw/dali-adaptor.git] / automated-tests / src / dali-adaptor-internal / utc-Dali-Internal-PixelBuffer.cpp
1 /*
2  * Copyright (c) 2014 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 <dali/public-api/dali-core.h>
21 #include <stdlib.h>
22
23 #include <dali-test-suite-utils.h>
24
25 // Internal headers are allowed here
26
27 #include <dali/internal/imaging/common/pixel-manipulation.h>
28
29 using namespace Dali;
30 using namespace Dali::Internal::Adaptor;
31 void utc_dali_internal_pixel_data_startup()
32 {
33   test_return_value = TET_UNDEF;
34 }
35
36 void utc_dali_internal_pixel_data_cleanup()
37 {
38   test_return_value = TET_PASS;
39 }
40
41 const char* ChannelToString(Dali::Internal::Adaptor::Channel channel)
42 {
43   switch(channel)
44   {
45     case LUMINANCE:
46       return "Luminance";
47     case RED:
48       return "Red";
49     case GREEN:
50       return "Green";
51     case BLUE:
52       return "Blue";
53     case ALPHA:
54       return "Alpha";
55     default:
56       return "Unknown";
57   }
58 }
59
60 const char* FormatToString(Dali::Pixel::Format format)
61 {
62   switch(format)
63   {
64     case Dali::Pixel::A8:
65       return "A8";
66     case Dali::Pixel::L8:
67       return "L8";
68     case Dali::Pixel::LA88:
69       return "LA88";
70     case Dali::Pixel::RGB565:
71       return "RGB565";
72     case Dali::Pixel::BGR565:
73       return "BGR565";
74     case Dali::Pixel::RGBA4444:
75       return "RGBA4444";
76     case Dali::Pixel::BGRA4444:
77       return "BGRA4444";
78     case Dali::Pixel::RGBA5551:
79       return "RGBA5551";
80     case Dali::Pixel::BGRA5551:
81       return "BGRA5551";
82
83     case Dali::Pixel::RGB888:
84       return "RGB888";
85     case Dali::Pixel::RGBA8888:
86       return "RGBA8888";
87     case Dali::Pixel::BGRA8888:
88       return "BGRA8888";
89
90     default:
91       return "Unknown";
92   }
93 }
94
95 int UtcDaliPixelManipulation01(void)
96 {
97   tet_infoline("Testing Dali::Internal::AdaptorManipulation HasChannel");
98
99   DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::A8, Dali::Internal::Adaptor::ALPHA), true, TEST_LOCATION);
100   DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::A8, Dali::Internal::Adaptor::LUMINANCE), false, TEST_LOCATION);
101
102   DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::L8, Dali::Internal::Adaptor::LUMINANCE), true, TEST_LOCATION);
103   DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::L8, Dali::Internal::Adaptor::ALPHA), false, TEST_LOCATION);
104
105   DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::LA88, Dali::Internal::Adaptor::LUMINANCE), true, TEST_LOCATION);
106   DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::LA88, Dali::Internal::Adaptor::ALPHA), true, TEST_LOCATION);
107   DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::LA88, Dali::Internal::Adaptor::RED), false, TEST_LOCATION);
108
109   DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::RGB565, Dali::Internal::Adaptor::RED), true, TEST_LOCATION);
110   DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::RGB565, Dali::Internal::Adaptor::GREEN), true, TEST_LOCATION);
111   DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::RGB565, Dali::Internal::Adaptor::BLUE), true, TEST_LOCATION);
112   DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::RGB565, Dali::Internal::Adaptor::LUMINANCE), false, TEST_LOCATION);
113
114   DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::RGBA8888, Dali::Internal::Adaptor::RED), true, TEST_LOCATION);
115   DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::RGBA8888, Dali::Internal::Adaptor::GREEN), true, TEST_LOCATION);
116   DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::RGBA8888, Dali::Internal::Adaptor::BLUE), true, TEST_LOCATION);
117   DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::RGBA8888, Dali::Internal::Adaptor::ALPHA), true, TEST_LOCATION);
118   DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::RGBA8888, Dali::Internal::Adaptor::LUMINANCE), false, TEST_LOCATION);
119
120   DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::COMPRESSED_RGBA_ASTC_10x6_KHR, Dali::Internal::Adaptor::BLUE), false, TEST_LOCATION);
121
122   END_TEST;
123 }
124
125 int UtcDaliPixelManipulation02(void)
126 {
127   tet_infoline("Testing Dali::Internal::AdaptorManipulation Read/WriteChannel");
128
129   unsigned char pixel[4] = {0, 0, 0, 0};
130
131   for(int formatIdx = 1; formatIdx < Dali::Pixel::COMPRESSED_R11_EAC; ++formatIdx)
132   {
133     pixel[0] = 0xFF;
134     pixel[1] = 0xFF;
135     pixel[2] = 0xFF;
136     pixel[3] = 0xFF;
137
138     for(int channelIdx = 0; channelIdx < Dali::Internal::Adaptor::MAX_NUMBER_OF_CHANNELS; ++channelIdx)
139     {
140       Dali::Pixel::Format              format  = static_cast<Dali::Pixel::Format>(formatIdx);
141       Dali::Internal::Adaptor::Channel channel = static_cast<Dali::Internal::Adaptor::Channel>(channelIdx);
142       if(Dali::Internal::Adaptor::HasChannel(format, channel))
143       {
144         Dali::Internal::Adaptor::WriteChannel(&pixel[0], format, channel, 0x15);
145         unsigned int value = Dali::Internal::Adaptor::ReadChannel(&pixel[0], format, channel);
146
147         tet_printf("Testing writing and reading to %s channel in %s format:\n",
148                    ChannelToString(channel),
149                    FormatToString(format));
150
151         if(channel == Dali::Internal::Adaptor::ALPHA && (format == Dali::Pixel::RGBA5551 || format == Dali::Pixel::BGRA5551))
152         {
153           DALI_TEST_EQUALS(value, 0x1, TEST_LOCATION);
154         }
155         else if(format == Dali::Pixel::RGBA4444 || format == Dali::Pixel::BGRA4444)
156         {
157           DALI_TEST_EQUALS(value, 0x05, TEST_LOCATION);
158         }
159         else
160         {
161           DALI_TEST_EQUALS(value, 0x15, TEST_LOCATION);
162         }
163       }
164     }
165   }
166
167   END_TEST;
168 }
169
170 int UtcDaliPixelManipulation03N(void)
171 {
172   tet_infoline("Testing Dali::Internal::AdaptorManipulation Read/WriteChannel");
173
174   unsigned char pixel[4] = {0, 0, 0, 0};
175
176   for(int formatIdx = 1; formatIdx < Dali::Pixel::COMPRESSED_R11_EAC; ++formatIdx)
177   {
178     pixel[0] = 0xFF;
179     pixel[1] = 0xFF;
180     pixel[2] = 0xFF;
181     pixel[3] = 0xFF;
182
183     for(int channelIdx = 0; channelIdx < Dali::Internal::Adaptor::MAX_NUMBER_OF_CHANNELS; ++channelIdx)
184     {
185       Dali::Pixel::Format              format  = static_cast<Dali::Pixel::Format>(formatIdx);
186       Dali::Internal::Adaptor::Channel channel = static_cast<Dali::Internal::Adaptor::Channel>(channelIdx);
187       if(!Dali::Internal::Adaptor::HasChannel(format, channel))
188       {
189         unsigned int value = Dali::Internal::Adaptor::ReadChannel(&pixel[0], format, channel);
190
191         tet_printf("Testing reading from %s channel in %s format:\n",
192                    ChannelToString(channel),
193                    FormatToString(format));
194
195         DALI_TEST_EQUALS(value, 0x00, TEST_LOCATION);
196       }
197     }
198   }
199
200   END_TEST;
201 }