added unit tests for surface
authorTimo Lotterbach <timo.lotterbach@bmw-carit.de>
Wed, 7 Dec 2011 11:02:06 +0000 (12:02 +0100)
committerTimo Lotterbach <timo.lotterbach@bmw-carit.de>
Wed, 7 Dec 2011 11:02:06 +0000 (12:02 +0100)
LayerManagerService/tests/SurfaceTest.cpp

index ed53463..d3c9687 100644 (file)
@@ -20,6 +20,7 @@
 #include <gtest/gtest.h>
 
 #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());
 }