From b422f2f6afa144f3f140f9c7d9be0b1dd88f47f7 Mon Sep 17 00:00:00 2001 From: Timo Lotterbach Date: Wed, 7 Dec 2011 12:02:06 +0100 Subject: [PATCH] added unit tests for surface --- LayerManagerService/tests/SurfaceTest.cpp | 144 +++++++++++++++++++++++++++++- 1 file changed, 142 insertions(+), 2 deletions(-) diff --git a/LayerManagerService/tests/SurfaceTest.cpp b/LayerManagerService/tests/SurfaceTest.cpp index ed53463..d3c9687 100644 --- a/LayerManagerService/tests/SurfaceTest.cpp +++ b/LayerManagerService/tests/SurfaceTest.cpp @@ -20,6 +20,7 @@ #include #include "Surface.h" +#include "Layer.h" class SurfaceTest : public ::testing::Test { @@ -47,7 +48,7 @@ TEST_F(SurfaceTest, defaultConstructor) Surface surface; /// make sure, surface was not added to any layer - //EXPECT_EQ(INVALID_ID, surface.getContainingLayerId()); + EXPECT_EQ(GraphicalObject::INVALID_ID, surface.getContainingLayerId()); /// make sure, surface has default size EXPECT_EQ(0, surface.OriginalSourceHeight); @@ -78,6 +79,9 @@ TEST_F(SurfaceTest, defaultConstructor) EXPECT_EQ(0, destRect.width); EXPECT_EQ(0, destRect.x); EXPECT_EQ(0, destRect.y); + + /// make sure, surface has no native content associated + EXPECT_FALSE(m_pSurface->hasNativeContent()); } TEST_F(SurfaceTest, specialConstructor) @@ -89,7 +93,7 @@ TEST_F(SurfaceTest, specialConstructor) EXPECT_EQ(expectedId, surface.getID()); /// make sure, surface was not added to any layer - //EXPECT_EQ(INVALID_ID, surface.getContainingLayerId()); + EXPECT_EQ(GraphicalObject::INVALID_ID, surface.getContainingLayerId()); /// make sure, surface has default size EXPECT_EQ(0, surface.OriginalSourceHeight); @@ -120,44 +124,180 @@ TEST_F(SurfaceTest, specialConstructor) EXPECT_EQ(0, destRect.width); EXPECT_EQ(0, destRect.x); EXPECT_EQ(0, destRect.y); + + /// make sure, surface has no native content associated + EXPECT_FALSE(m_pSurface->hasNativeContent()); } TEST_F(SurfaceTest, getPixelFormat) { + PixelFormat expected1 = PIXELFORMAT_RGBA5551; + PixelFormat expected2 = PIXELFORMAT_RGB565; + + /// set pixel format of surface to expected value + m_pSurface->setPixelFormat(expected1); + + /// make sure, surface has expected pixel format + EXPECT_EQ(expected1, m_pSurface->getPixelFormat()); + + /// set pixel format of surface to other expected value + m_pSurface->setPixelFormat(expected2); + /// make sure, surface has other expected pixel format + EXPECT_EQ(expected2, m_pSurface->getPixelFormat()); } TEST_F(SurfaceTest, setPixelFormat) { + PixelFormat expected1 = PIXELFORMAT_R8; + PixelFormat expected2 = PIXELFORMAT_RGBA8888; + /// set pixel format of surface to expected value + m_pSurface->setPixelFormat(expected1); + + /// make sure, surface has expected pixel format + EXPECT_EQ(expected1, m_pSurface->getPixelFormat()); + + /// set pixel format of surface to other expected value + m_pSurface->setPixelFormat(expected2); + + /// make sure, surface has other expected pixel format + EXPECT_EQ(expected2, m_pSurface->getPixelFormat()); } TEST_F(SurfaceTest, getContainingLayerId) { + unsigned int expectedLayerId = 202; + Layer layer(expectedLayerId); + + /// make sure, surface has no containg layer + EXPECT_EQ(GraphicalObject::INVALID_ID, m_pSurface->getContainingLayerId()); + /// add surface to layer + layer.addSurface(m_pSurface); + + /// make sure, surface is contained by layer + EXPECT_EQ(expectedLayerId, m_pSurface->getContainingLayerId()); + + /// remove surface from layer + layer.removeSurface(m_pSurface); + + /// make sure, surface is no longer contained by layer + EXPECT_EQ(GraphicalObject::INVALID_ID, m_pSurface->getContainingLayerId()); } TEST_F(SurfaceTest, setContainingLayerId) { + unsigned int expectedLayerId = 207; + + /// make sure, surface has no containing layer + EXPECT_EQ(GraphicalObject::INVALID_ID, m_pSurface->getContainingLayerId()); + + /// set surface to be contained by expected layer + m_pSurface->setContainingLayerId(expectedLayerId); + /// make sure, surface is contained by layer + EXPECT_EQ(expectedLayerId, m_pSurface->getContainingLayerId()); + + /// set surface to be contained by no layer + m_pSurface->setContainingLayerId(GraphicalObject::INVALID_ID); + + /// make sure, surface is no longer contained by layer + EXPECT_EQ(GraphicalObject::INVALID_ID, m_pSurface->getContainingLayerId()); } TEST_F(SurfaceTest, hasNativeContent) { + unsigned int expectedNativeHandle = 211; + + /// make sure, surface has no native content associated + EXPECT_FALSE(m_pSurface->hasNativeContent()); + + /// set expected native content of surface + m_pSurface->setNativeContent(expectedNativeHandle); + /// make sure, surface has native content associated + EXPECT_TRUE(m_pSurface->hasNativeContent()); + + /// remove native content of surface + m_pSurface->removeNativeContent(); + + /// make sure, surface has no native content associated + EXPECT_FALSE(m_pSurface->hasNativeContent()); } TEST_F(SurfaceTest, removeNativeContent) { + unsigned int expectedNativeHandle = 213; + + /// set expected native content of surface + m_pSurface->setNativeContent(expectedNativeHandle); + + /// make sure, surface has native content associated + EXPECT_TRUE(m_pSurface->hasNativeContent()); + + /// remove native content of surface + m_pSurface->removeNativeContent(); + /// make sure, surface has no native content associated + EXPECT_FALSE(m_pSurface->hasNativeContent()); } TEST_F(SurfaceTest, setNativeContent) { + unsigned int expectedNativeHandle1 = 217; + unsigned int expectedNativeHandle2 = 218; + + /// make sure, surface has no native content associated + EXPECT_FALSE(m_pSurface->hasNativeContent()); + + /// set 1st expected native content of surface + m_pSurface->setNativeContent(expectedNativeHandle1); + + /// make sure, surface has 1st expected native content associated + EXPECT_TRUE(m_pSurface->hasNativeContent()); + EXPECT_EQ(expectedNativeHandle1, m_pSurface->getNativeContent()); + + /// set 2nd expected native content of surface + m_pSurface->setNativeContent(expectedNativeHandle2); + /// make sure, surface still has 1st expected native content associated + EXPECT_TRUE(m_pSurface->hasNativeContent()); + EXPECT_EQ(expectedNativeHandle1, m_pSurface->getNativeContent()); + + /// remove native content of surface + m_pSurface->removeNativeContent(); + + /// set 2nd expected native content of surface again + m_pSurface->setNativeContent(expectedNativeHandle2); + + /// make sure, surface has 2nd expected native content associated + EXPECT_TRUE(m_pSurface->hasNativeContent()); + EXPECT_EQ(expectedNativeHandle2, m_pSurface->getNativeContent()); } TEST_F(SurfaceTest, getNativeContent) { + unsigned int expectedNativeHandle1 = 217; + unsigned int expectedNativeHandle2 = 218; + + /// make sure, surface has no native content associated + EXPECT_FALSE(m_pSurface->hasNativeContent()); + + /// set 1st expected native content of surface + m_pSurface->setNativeContent(expectedNativeHandle1); + + /// make sure, surface has 1st expected native content associated + EXPECT_TRUE(m_pSurface->hasNativeContent()); + EXPECT_EQ(expectedNativeHandle1, m_pSurface->getNativeContent()); + + /// remove native content of surface + m_pSurface->removeNativeContent(); + + /// set 2nd expected native content of surface again + m_pSurface->setNativeContent(expectedNativeHandle2); + /// make sure, surface has 2nd expected native content associated + EXPECT_TRUE(m_pSurface->hasNativeContent()); + EXPECT_EQ(expectedNativeHandle2, m_pSurface->getNativeContent()); } -- 2.7.4