Merge branch 'devel/master' into sandbox/dkdk/tizen
[platform/core/uifw/dali-adaptor.git] / automated-tests / src / dali-platform-abstraction / utc-image-loading-common.cpp
1 /*
2  * Copyright (c) 2020 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 double GetTimeMilliseconds(Integration::PlatformAbstraction& abstraction)
21 {
22   timespec timeSpec;
23   clock_gettime(CLOCK_MONOTONIC, &timeSpec);
24   return (timeSpec.tv_sec * 1e3) + (timeSpec.tv_nsec / 1e6);
25 }
26
27 /** Live platform abstraction recreated for each test case. */
28 TizenPlatform::TizenPlatformAbstraction* gAbstraction = 0;
29
30 /** A variety of parameters to reach different code paths in image loading code. */
31 std::vector<ImageParameters> gCancelAttributes;
32
33 void utc_dali_loading_startup(void)
34 {
35   test_return_value = TET_UNDEF;
36   gAbstraction      = TizenPlatform::CreatePlatformAbstraction();
37
38   // Setup some loading parameters to engage post-processing stages:
39
40   ImageParameters scaleToFillAttributes;
41   scaleToFillAttributes.second.first = FittingMode::SCALE_TO_FILL;
42   scaleToFillAttributes.first        = ImageDimensions(160, 120);
43   gCancelAttributes.push_back(scaleToFillAttributes);
44
45   // Hit the derived dimensions code:
46   ImageParameters scaleToFillAttributesDeriveWidth = scaleToFillAttributes;
47   scaleToFillAttributesDeriveWidth.first           = ImageDimensions(0, 120);
48   gCancelAttributes.push_back(scaleToFillAttributesDeriveWidth);
49
50   ImageParameters scaleToFillAttributesDeriveHeight = scaleToFillAttributes;
51   scaleToFillAttributesDeriveHeight.first           = ImageDimensions(160, 0);
52   gCancelAttributes.push_back(scaleToFillAttributesDeriveHeight);
53
54   // Try to push a tall crop:
55   ImageParameters scaleToFillAttributesTall  = scaleToFillAttributes;
56   scaleToFillAttributesTall.first            = ImageDimensions(160, 480);
57   ImageParameters scaleToFillAttributesTall2 = scaleToFillAttributes;
58   scaleToFillAttributesTall2.first           = ImageDimensions(160, 509);
59   ImageParameters scaleToFillAttributesTall3 = scaleToFillAttributes;
60   scaleToFillAttributesTall3.first           = ImageDimensions(37, 251);
61   gCancelAttributes.push_back(scaleToFillAttributesTall);
62   gCancelAttributes.push_back(scaleToFillAttributesTall2);
63   gCancelAttributes.push_back(scaleToFillAttributesTall3);
64
65   // Try to push a wide crop:
66   ImageParameters scaleToFillAttributesWide  = scaleToFillAttributes;
67   scaleToFillAttributesWide.first            = ImageDimensions(320, 60);
68   ImageParameters scaleToFillAttributesWide2 = scaleToFillAttributes;
69   scaleToFillAttributesWide2.first           = ImageDimensions(317, 60);
70   ImageParameters scaleToFillAttributesWide3 = scaleToFillAttributes;
71   scaleToFillAttributesWide3.first           = ImageDimensions(317, 53);
72   gCancelAttributes.push_back(scaleToFillAttributesWide);
73   gCancelAttributes.push_back(scaleToFillAttributesWide2);
74   gCancelAttributes.push_back(scaleToFillAttributesWide3);
75
76   ImageParameters shrinkToFitAttributes = scaleToFillAttributes;
77   shrinkToFitAttributes.second.first    = FittingMode::SHRINK_TO_FIT;
78   gCancelAttributes.push_back(shrinkToFitAttributes);
79
80   ImageParameters fitWidthAttributes = scaleToFillAttributes;
81   fitWidthAttributes.second.first    = FittingMode::FIT_WIDTH;
82   gCancelAttributes.push_back(fitWidthAttributes);
83
84   ImageParameters fitHeightAttributes = scaleToFillAttributes;
85   fitHeightAttributes.second.first    = FittingMode::FIT_HEIGHT;
86   gCancelAttributes.push_back(fitHeightAttributes);
87
88   ///@ToDo: Add attribute variants for all scale modes.
89   ///@ToDo: Add attribute variants for all filter modes.
90
91   // Pad the array to a prime number to mitigate any accidental periodic
92   // patterns in which image file has which attributes applied to its load:
93   srand48(104729);
94   const float lastUniques = gCancelAttributes.size() - 0.001f;
95   while(gCancelAttributes.size() < 61u)
96   {
97     gCancelAttributes.push_back(gCancelAttributes[unsigned(drand48() * lastUniques)]);
98   }
99 }
100
101 void utc_dali_loading_cleanup(void)
102 {
103   delete gAbstraction;
104   gAbstraction = 0;
105
106   test_return_value = TET_PASS;
107 }