gralloc4-vts: correctly instantiate std::optional
std::optional defaults to containing std::nullopt_t. Using "->" or
"." on an std::optional object that does not contain a value is
undefined. Clang seems to ignore the whole line.
SetSmpte2086 and SetCta861_3 both incorrectly instantiate their
std::optional types. The std::optional types contain std::nullopt_t
when they are passed into encode. When mapper decodes the fields,
they are empty.
Update std::optionals to be instantiated correctly.
Bug: 149931805
Test: VtsHalGraphicsMapperV4_0
Change-Id: I046242f8261a5378228231b89b2eedec242667cb
diff --git a/graphics/mapper/4.0/vts/functional/VtsHalGraphicsMapperV4_0TargetTest.cpp b/graphics/mapper/4.0/vts/functional/VtsHalGraphicsMapperV4_0TargetTest.cpp
index 1416fcc..ecf08dc 100644
--- a/graphics/mapper/4.0/vts/functional/VtsHalGraphicsMapperV4_0TargetTest.cpp
+++ b/graphics/mapper/4.0/vts/functional/VtsHalGraphicsMapperV4_0TargetTest.cpp
@@ -278,6 +278,8 @@
}
}
+ bool isEqual(float a, float b) { return abs(a - b) < 0.0001; }
+
std::unique_ptr<Gralloc> mGralloc;
IMapper::BufferDescriptorInfo mDummyDescriptorInfo{};
static const std::set<StandardMetadataType> sRequiredMetadataTypes;
@@ -1455,17 +1457,17 @@
* red 0.680 0.320
* white (D65) 0.3127 0.3290
*/
- std::optional<Smpte2086> smpte2086;
- smpte2086->primaryRed.x = 0.680;
- smpte2086->primaryRed.y = 0.320;
- smpte2086->primaryGreen.x = 0.265;
- smpte2086->primaryGreen.y = 0.690;
- smpte2086->primaryBlue.x = 0.150;
- smpte2086->primaryBlue.y = 0.060;
- smpte2086->whitePoint.x = 0.3127;
- smpte2086->whitePoint.y = 0.3290;
- smpte2086->maxLuminance = 100.0;
- smpte2086->minLuminance = 0.1;
+ Smpte2086 smpte2086;
+ smpte2086.primaryRed.x = 0.680;
+ smpte2086.primaryRed.y = 0.320;
+ smpte2086.primaryGreen.x = 0.265;
+ smpte2086.primaryGreen.y = 0.690;
+ smpte2086.primaryBlue.x = 0.150;
+ smpte2086.primaryBlue.y = 0.060;
+ smpte2086.whitePoint.x = 0.3127;
+ smpte2086.whitePoint.y = 0.3290;
+ smpte2086.maxLuminance = 100.0;
+ smpte2086.minLuminance = 0.1;
hidl_vec<uint8_t> vec;
ASSERT_EQ(NO_ERROR, gralloc4::encodeSmpte2086(smpte2086, &vec));
@@ -1475,16 +1477,16 @@
std::optional<Smpte2086> realSmpte2086;
ASSERT_EQ(NO_ERROR, gralloc4::decodeSmpte2086(vec, &realSmpte2086));
ASSERT_TRUE(realSmpte2086.has_value());
- EXPECT_EQ(smpte2086->primaryRed.x, realSmpte2086->primaryRed.x);
- EXPECT_EQ(smpte2086->primaryRed.y, realSmpte2086->primaryRed.y);
- EXPECT_EQ(smpte2086->primaryGreen.x, realSmpte2086->primaryGreen.x);
- EXPECT_EQ(smpte2086->primaryGreen.y, realSmpte2086->primaryGreen.y);
- EXPECT_EQ(smpte2086->primaryBlue.x, realSmpte2086->primaryBlue.x);
- EXPECT_EQ(smpte2086->primaryBlue.y, realSmpte2086->primaryBlue.y);
- EXPECT_EQ(smpte2086->whitePoint.x, realSmpte2086->whitePoint.x);
- EXPECT_EQ(smpte2086->whitePoint.y, realSmpte2086->whitePoint.y);
- EXPECT_EQ(smpte2086->maxLuminance, realSmpte2086->maxLuminance);
- EXPECT_EQ(smpte2086->minLuminance, realSmpte2086->minLuminance);
+ EXPECT_TRUE(isEqual(smpte2086.primaryRed.x, realSmpte2086->primaryRed.x));
+ EXPECT_TRUE(isEqual(smpte2086.primaryRed.y, realSmpte2086->primaryRed.y));
+ EXPECT_TRUE(isEqual(smpte2086.primaryGreen.x, realSmpte2086->primaryGreen.x));
+ EXPECT_TRUE(isEqual(smpte2086.primaryGreen.y, realSmpte2086->primaryGreen.y));
+ EXPECT_TRUE(isEqual(smpte2086.primaryBlue.x, realSmpte2086->primaryBlue.x));
+ EXPECT_TRUE(isEqual(smpte2086.primaryBlue.y, realSmpte2086->primaryBlue.y));
+ EXPECT_TRUE(isEqual(smpte2086.whitePoint.x, realSmpte2086->whitePoint.x));
+ EXPECT_TRUE(isEqual(smpte2086.whitePoint.y, realSmpte2086->whitePoint.y));
+ EXPECT_TRUE(isEqual(smpte2086.maxLuminance, realSmpte2086->maxLuminance));
+ EXPECT_TRUE(isEqual(smpte2086.minLuminance, realSmpte2086->minLuminance));
});
}
@@ -1492,9 +1494,9 @@
* Test IMapper::set(Cta8613)
*/
TEST_P(GraphicsMapperHidlTest, SetCta861_3) {
- std::optional<Cta861_3> cta861_3;
- cta861_3->maxContentLightLevel = 78.0;
- cta861_3->maxFrameAverageLightLevel = 62.0;
+ Cta861_3 cta861_3;
+ cta861_3.maxContentLightLevel = 78.0;
+ cta861_3.maxFrameAverageLightLevel = 62.0;
hidl_vec<uint8_t> vec;
ASSERT_EQ(NO_ERROR, gralloc4::encodeCta861_3(cta861_3, &vec));
@@ -1504,9 +1506,10 @@
std::optional<Cta861_3> realCta861_3;
ASSERT_EQ(NO_ERROR, gralloc4::decodeCta861_3(vec, &realCta861_3));
ASSERT_TRUE(realCta861_3.has_value());
- EXPECT_EQ(cta861_3->maxContentLightLevel, realCta861_3->maxContentLightLevel);
- EXPECT_EQ(cta861_3->maxFrameAverageLightLevel,
- realCta861_3->maxFrameAverageLightLevel);
+ EXPECT_TRUE(
+ isEqual(cta861_3.maxContentLightLevel, realCta861_3->maxContentLightLevel));
+ EXPECT_TRUE(isEqual(cta861_3.maxFrameAverageLightLevel,
+ realCta861_3->maxFrameAverageLightLevel));
});
}