RDK Documentation (Open Sourced RDK Components)
GetAttributesFontSizeTests.cpp
1 /*
2 * If not stated otherwise in this file or this component's license file the
3 * following copyright and licenses apply:
4 *
5 * Copyright 2022 RDK Management
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19 
20 #include <gtest/gtest.h>
21 #include <gmock/gmock.h>
22 #include "AampLogManager.h"
23 #include "MockAampConfig.h"
24 #include "MockAampJsonObject.h"
26 
27 using ::testing::_;
28 using ::testing::Return;
29 using ::testing::SetArgReferee;
30 using ::testing::StrictMock;
31 using ::testing::An;
32 using ::testing::DoAll;
33 
35 AampLogManager *mLogObj = NULL;
36 
37 class GetAttributesFontSizeTests : public ::testing::Test
38 {
39 protected:
40 
41  std::unique_ptr<TextStyleAttributes> mAttributes;
42 
43  void SetUp() override
44  {
45  mAttributes = std::unique_ptr<TextStyleAttributes>(new TextStyleAttributes(mLogObj));
46 
47  g_mockAampJsonObject = std::make_shared<StrictMock<MockAampJsonObject>>();
48  }
49 
50  void TearDown() override
51  {
52  mAttributes = nullptr;
53 
54  g_mockAampJsonObject = nullptr;
55  }
56 };
57 
58 ACTION(ThrowJsonException)
59 {
60  throw AampJsonParseException();
61 }
62 
63 /*
64  Test the getAttributes function supplying it with empty Json string
65  In this case getAttributes must set the attributeMask to 0; informing caller nothing to proceed
66 */
67 TEST_F(GetAttributesFontSizeTests, EmptyJsonOptionsString)
68 {
69  std::string options{};
70  std::uint32_t attributesMask = 0x1234;
71  attributesType attributesValues = {0};
72 
73  EXPECT_EQ(-1, mAttributes->getAttributes(options, attributesValues, attributesMask));
74  EXPECT_EQ(attributesMask, 0);
75 }
76 
77 /*
78  Test the getAttributes function when AampJsonObject throws exception
79  In this case getAttributes must set the attributeMask to 0; informing caller nothing to proceed
80 */
81 TEST_F(GetAttributesFontSizeTests, JsonExceptionThrown)
82 {
83  std::string options = "{\"fontSize\":\"32.4px\"}";
84  std::uint32_t attributesMask = 0x1234;
85  attributesType attributesValues = {0};
86 
87  EXPECT_CALL(*g_mockAampJsonObject, get("penSize", An<std::string&>())).WillOnce(ThrowJsonException());
88  EXPECT_EQ(-1, mAttributes->getAttributes(options, attributesValues, attributesMask));
89  EXPECT_EQ(attributesMask, 0);
90 }
91 
92 /*
93  Test the getAttributes function when AampJsonObject unsuccessfully retrieves value
94  A wrong key in the Json object (as set in options) is used to test the function.
95  In this case getAttributes must set the attributeMask to 0; informing caller nothing to proceed
96 */
97 TEST_F(GetAttributesFontSizeTests, JsonValueNotReturned)
98 {
99  std::string options = "{\"fontSize\":\"32.4px\"}";
100  std::uint32_t attributesMask = 0x1234;
101  attributesType attributesValues = {0};
102 
103  EXPECT_CALL(*g_mockAampJsonObject, get("penSize", An<std::string&>())).WillOnce(Return(false));
104  EXPECT_EQ(0, mAttributes->getAttributes(options, attributesValues, attributesMask));
105  EXPECT_EQ(attributesMask, 0);
106 }
107 
108 /*
109  Test the getAttributes function supplying it with Right Key but invalid corresponding value.
110  In this case getAttributes must set the attributeMask to 0; informing caller nothing to proceed
111 */
112 TEST_F(GetAttributesFontSizeTests, RightKeyInvalidValueJsonOptionsString)
113 {
114  std::string penSizeValue = "32.4px";
115  std::string options = "{\"penSize\":\"" + penSizeValue + "\"}";
116  std::uint32_t attributesMask = 0x1234;
117  attributesType attributesValues = {0};
118 
119  EXPECT_CALL(*g_mockAampJsonObject, get("penSize", An<std::string&>()))
120  .WillOnce(DoAll(SetArgReferee<1>(penSizeValue), Return(true)));
121 
122  EXPECT_EQ(0, mAttributes->getAttributes(options, attributesValues, attributesMask));
123  EXPECT_EQ(attributesMask, 0);
124 }
125 
126 /*
127  Test the getAttributes with font size small, penSizevalue expressed in lower case
128  This will also test the output expected from the getFontSize function.
129  Expected values are: - a valid attributesMask and attributeValues as per penSizeValue
130 */
131 TEST_F(GetAttributesFontSizeTests, ExpectedJsonOptionsStringValueSmallLowerCase)
132 {
133  std::string penSizeValue = "small";
134  std::string options = "{\"penSize\":\"" + penSizeValue + "\"}";
135  std::uint32_t attributesMask = 0;
136  attributesType attributesValues = {0};
137 
138  EXPECT_CALL(*g_mockAampJsonObject, get("penSize", An<std::string&>()))
139  .WillOnce(DoAll(SetArgReferee<1>(penSizeValue), Return(true)));
140 
141  EXPECT_EQ(0, mAttributes->getAttributes(options, attributesValues, attributesMask));
142  EXPECT_EQ(attributesMask, (1<<mAttributes->FONT_SIZE_ARR_POSITION));
143  EXPECT_EQ(attributesValues[mAttributes->FONT_SIZE_ARR_POSITION], mAttributes->FONT_SIZE_SMALL);
144 }
145 
146 /*
147  Test the getAttributes with font size small, penSizevalue expressed in Upper case
148  This will also test the output expected from the getFontSize function.
149  Expected values are: - a valid attributesMask and attributeValues as per penSizeValue
150 */
151 TEST_F(GetAttributesFontSizeTests, ExpectedJsonOptionsStringValueSmallUpperCase)
152 {
153  std::string penSizeValue = "SMALL";
154  std::string options = "{\"penSize\":\"" + penSizeValue + "\"}";
155  std::uint32_t attributesMask = 0;
156  attributesType attributesValues = {0};
157 
158  EXPECT_CALL(*g_mockAampJsonObject, get("penSize", An<std::string&>()))
159  .WillOnce(DoAll(SetArgReferee<1>(penSizeValue), Return(true)));
160 
161  EXPECT_EQ(0, mAttributes->getAttributes(options, attributesValues, attributesMask));
162  EXPECT_EQ(attributesMask, (1<<mAttributes->FONT_SIZE_ARR_POSITION));
163  EXPECT_EQ(attributesValues[mAttributes->FONT_SIZE_ARR_POSITION], mAttributes->FONT_SIZE_SMALL);
164 }
165 
166 /*
167  Test the getAttributes with font size Medium, penSizevalue expressed in lower case
168  This will also test the output expected from the getFontSize function.
169  Expected values are: - a valid attributesMask and attributeValues as per penSizeValue
170 */
171 TEST_F(GetAttributesFontSizeTests, ExpectedJsonOptionsStringValueMediumLowerCase)
172 {
173  std::string penSizeValue = "medium";
174  std::string options = "{\"penSize\":\"" + penSizeValue + "\"}";
175  std::uint32_t attributesMask = 0;
176  attributesType attributesValues = {0};
177 
178  EXPECT_CALL(*g_mockAampJsonObject, get("penSize", An<std::string&>()))
179  .WillOnce(DoAll(SetArgReferee<1>(penSizeValue), Return(true)));
180 
181  EXPECT_EQ(0, mAttributes->getAttributes(options, attributesValues, attributesMask));
182  EXPECT_EQ(attributesMask, (1<<mAttributes->FONT_SIZE_ARR_POSITION));
183  EXPECT_EQ(attributesValues[mAttributes->FONT_SIZE_ARR_POSITION], mAttributes->FONT_SIZE_STANDARD);
184 }
185 
186 /*
187  Test the getAttributes with font size Medium, penSizevalue expressed in Upper case
188  This will also test the output expected from the getFontSize function.
189  Expected values are: - a valid attributesMask and attributeValues as per penSizeValue
190  Two test cases are sufficient to prove that Upper case Json values are handled appropriately
191 */
192 TEST_F(GetAttributesFontSizeTests, ExpectedJsonOptionsStringValueMediumUpperCase)
193 {
194  std::string penSizeValue = "MEDIUM";
195  std::string options = "{\"penSize\":\"" + penSizeValue + "\"}";
196  std::uint32_t attributesMask = 0;
197  attributesType attributesValues = {0};
198 
199  EXPECT_CALL(*g_mockAampJsonObject, get("penSize", An<std::string&>()))
200  .WillOnce(DoAll(SetArgReferee<1>(penSizeValue), Return(true)));
201 
202  EXPECT_EQ(0, mAttributes->getAttributes(options, attributesValues, attributesMask));
203  EXPECT_EQ(attributesMask, (1<<mAttributes->FONT_SIZE_ARR_POSITION));
204  EXPECT_EQ(attributesValues[mAttributes->FONT_SIZE_ARR_POSITION], mAttributes->FONT_SIZE_STANDARD);
205 }
206 
207 /*
208  Test the getAttributes with font size Standard
209  This will also test the output expected from the getFontSize function.
210  Expected values are: - a valid attributesMask and attributeValues as per penSizeValue
211 */
212 TEST_F(GetAttributesFontSizeTests, ExpectedJsonOptionsStringValueStandard)
213 {
214  std::string penSizeValue = "standard";
215  std::string options = "{\"penSize\":\"" + penSizeValue + "\"}";
216  std::uint32_t attributesMask = 0;
217  attributesType attributesValues = {0};
218 
219  EXPECT_CALL(*g_mockAampJsonObject, get("penSize", An<std::string&>()))
220  .WillOnce(DoAll(SetArgReferee<1>(penSizeValue), Return(true)));
221 
222  EXPECT_EQ(0, mAttributes->getAttributes(options, attributesValues, attributesMask));
223  EXPECT_EQ(attributesMask, (1<<mAttributes->FONT_SIZE_ARR_POSITION));
224  EXPECT_EQ(attributesValues[mAttributes->FONT_SIZE_ARR_POSITION], mAttributes->FONT_SIZE_STANDARD);
225 }
226 
227 /*
228  Test the getAttributes with font size large
229  This will also test the output expected from the getFontSize function.
230  Expected values are: - a valid attributesMask and attributeValues as per penSizeValue
231 */
232 TEST_F(GetAttributesFontSizeTests, ExpectedJsonOptionsStringValueLarge)
233 {
234  std::string penSizeValue = "large";
235  std::string options = "{\"penSize\":\"" + penSizeValue + "\"}";
236  std::uint32_t attributesMask = 0;
237  attributesType attributesValues = {0};
238 
239  EXPECT_CALL(*g_mockAampJsonObject, get("penSize", An<std::string&>()))
240  .WillOnce(DoAll(SetArgReferee<1>(penSizeValue), Return(true)));
241 
242  EXPECT_EQ(0, mAttributes->getAttributes(options, attributesValues, attributesMask));
243  EXPECT_EQ(attributesMask, (1<<mAttributes->FONT_SIZE_ARR_POSITION));
244  EXPECT_EQ(attributesValues[mAttributes->FONT_SIZE_ARR_POSITION], mAttributes->FONT_SIZE_LARGE);
245 }
246 
247 /*
248  Test the getAttributes with font size FONT_SIZE_EXTRALARGE
249  This will also test the output expected from the getFontSize function.
250  Expected values are: - a valid attributesMask and attributeValues as per penSizeValue
251 */
252 TEST_F(GetAttributesFontSizeTests, ExpectedJsonOptionsStringValueExtralarge)
253 {
254  std::string penSizeValue = "extra_large";
255  std::string options = "{\"penSize\":\"" + penSizeValue + "\"}";
256  std::uint32_t attributesMask = 0;
257  attributesType attributesValues = {0};
258 
259  EXPECT_CALL(*g_mockAampJsonObject, get("penSize", An<std::string&>()))
260  .WillOnce(DoAll(SetArgReferee<1>(penSizeValue), Return(true)));
261 
262  EXPECT_EQ(0, mAttributes->getAttributes(options, attributesValues, attributesMask));
263  EXPECT_EQ(attributesMask, (1<<mAttributes->FONT_SIZE_ARR_POSITION));
264  EXPECT_EQ(attributesValues[mAttributes->FONT_SIZE_ARR_POSITION], mAttributes->FONT_SIZE_EXTRALARGE);
265 }
266 
267 /*
268  Test the getAttributes with font size auto i.e. embedded
269  This will also test the output expected from the getFontSize function.
270  Expected values are: - a valid attributesMask and attributeValues as per penSizeValue
271 */
272 TEST_F(GetAttributesFontSizeTests, ExpectedJsonOptionsStringValueAuto)
273 {
274  std::string penSizeValue = "auto";
275  std::string options = "{\"penSize\":\"" + penSizeValue + "\"}";
276  std::uint32_t attributesMask = 0;
277  attributesType attributesValues = {0};
278 
279  EXPECT_CALL(*g_mockAampJsonObject, get("penSize", An<std::string&>()))
280  .WillOnce(DoAll(SetArgReferee<1>(penSizeValue), Return(true)));
281 
282  EXPECT_EQ(0, mAttributes->getAttributes(options, attributesValues, attributesMask));
283  EXPECT_EQ(attributesMask, (1<<mAttributes->FONT_SIZE_ARR_POSITION));
284  EXPECT_EQ(attributesValues[mAttributes->FONT_SIZE_ARR_POSITION], mAttributes->FONT_SIZE_EMBEDDED);
285 }
AampLogManager.h
Log managed for Aamp.
AampJsonParseException
Handles the exception for JSON parser.
Definition: AampJsonObject.h:252
gpGlobalConfig
AampConfig * gpGlobalConfig
Global configuration.
Definition: main_aamp.cpp:48
AampLogManager
AampLogManager Class.
Definition: AampLogManager.h:150
AampConfig
AAMP Config Class defn.
Definition: AampConfig.h:457
TextStyleAttributes
Definition: TextStyleAttributes.h:34
attributesType
std::array< uint32_t, 14 > attributesType
Definition: SubtecAttribute.hpp:30
TextStyleAttributes.h
This file provides class and other definition related to subtitle text attributes.
GetAttributesFontSizeTests
Definition: GetAttributesFontSizeTests.cpp:37