[dali_1.0.21] Merge branch 'tizen'
[platform/core/uifw/dali-adaptor.git] / automated-tests / src / dali-platform-abstraction / utc-image-loading-common.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 "utc-image-loading-common.h"
19
20 /** Live platform abstraction recreated for each test case. */
21 Integration::PlatformAbstraction * gAbstraction = 0;
22
23 /** A variety of ImageAttributes to reach different code paths that have embedded code paths. */
24 std::vector<ImageAttributes> gCancelAttributes;
25
26 void utc_dali_loading_startup(void)
27 {
28   test_return_value = TET_UNDEF;
29   gAbstraction = CreatePlatformAbstraction();
30
31   // Setup some ImageAttributes to engage post-processing stages:
32
33   ImageAttributes scaleToFillAttributes;
34   scaleToFillAttributes.SetScalingMode( ImageAttributes::ScaleToFill );
35   scaleToFillAttributes.SetSize( 160, 120 );
36   gCancelAttributes.push_back( scaleToFillAttributes );
37
38   // Hit the derived dimensions code:
39   ImageAttributes scaleToFillAttributesDeriveWidth = scaleToFillAttributes;
40   scaleToFillAttributesDeriveWidth.SetSize( 0, 120 );
41   gCancelAttributes.push_back( scaleToFillAttributesDeriveWidth );
42
43   ImageAttributes scaleToFillAttributesDeriveHeight = scaleToFillAttributes;
44   scaleToFillAttributesDeriveHeight.SetSize( 160, 0 );
45   gCancelAttributes.push_back( scaleToFillAttributesDeriveHeight );
46
47   // Try to push a tall crop:
48   ImageAttributes scaleToFillAttributesTall = scaleToFillAttributes;
49   scaleToFillAttributesTall.SetSize( 160, 480 );
50   ImageAttributes scaleToFillAttributesTall2 = scaleToFillAttributes;
51   scaleToFillAttributesTall2.SetSize( 160, 509 );
52   ImageAttributes scaleToFillAttributesTall3 = scaleToFillAttributes;
53   scaleToFillAttributesTall3.SetSize( 37, 251 );
54   gCancelAttributes.push_back( scaleToFillAttributesTall );
55   gCancelAttributes.push_back( scaleToFillAttributesTall2 );
56   gCancelAttributes.push_back( scaleToFillAttributesTall3 );
57
58   // Try to push a wide crop:
59   ImageAttributes scaleToFillAttributesWide = scaleToFillAttributes;
60   scaleToFillAttributesWide.SetSize( 320, 60 );
61   ImageAttributes scaleToFillAttributesWide2 = scaleToFillAttributes;
62   scaleToFillAttributesWide2.SetSize( 317, 60 );
63   ImageAttributes scaleToFillAttributesWide3 = scaleToFillAttributes;
64   scaleToFillAttributesWide3.SetSize( 317, 53 );
65   gCancelAttributes.push_back( scaleToFillAttributesWide );
66   gCancelAttributes.push_back( scaleToFillAttributesWide2 );
67   gCancelAttributes.push_back( scaleToFillAttributesWide3 );
68
69   ImageAttributes shrinkToFitAttributes = scaleToFillAttributes;
70   shrinkToFitAttributes.SetScalingMode( ImageAttributes::ShrinkToFit );
71   gCancelAttributes.push_back( shrinkToFitAttributes );
72
73   ImageAttributes fitWidthAttributes = scaleToFillAttributes;
74   fitWidthAttributes.SetScalingMode( ImageAttributes::FitWidth );
75   gCancelAttributes.push_back( fitWidthAttributes );
76
77   ImageAttributes fitHeightAttributes = scaleToFillAttributes;
78   fitHeightAttributes.SetScalingMode( ImageAttributes::FitHeight );
79   gCancelAttributes.push_back( fitHeightAttributes );
80
81   ///@ToDo: Add attribute variants for all scale modes.
82
83   // Pad the array to a prime number to mitigate any accidental periodic
84   // patterns in which image file has which attributes applied to its load:
85   srand48( 104729 );
86   const float lastUniques = gCancelAttributes.size() - 0.001f;
87   while( gCancelAttributes.size() < 61u )
88   {
89     gCancelAttributes.push_back( gCancelAttributes[unsigned(drand48() * lastUniques)] );
90   }
91 }
92
93 void utc_dali_loading_cleanup(void)
94 {
95   delete gAbstraction;
96   gAbstraction = 0;
97
98   test_return_value = TET_PASS;
99 }