--- /dev/null
+/***************************************************************************
+ *
+ * Copyright 2010,2011 BMW Car IT GmbH
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ****************************************************************************/
+
+#include <gtest/gtest.h>
+
+#include "Layer.h"
+
+class LayerTest : public ::testing::Test
+{
+public:
+ void SetUp()
+ {
+ m_pLayer = new Layer();
+ ASSERT_TRUE(m_pLayer);
+ }
+
+ void TearDown()
+ {
+ if (m_pLayer)
+ {
+ delete m_pLayer;
+ m_pLayer = 0;
+ }
+ }
+
+ Layer* m_pLayer;
+};
+
+TEST_F(LayerTest, defaultConstructor)
+{
+ Layer layer;
+
+ /// make sure, Layer was not added to any layer
+ //EXPECT_EQ(INVALID_ID, Layer.getContainingLayerId());
+
+ /// make sure, Layer has default size
+ EXPECT_EQ(0, layer.OriginalSourceHeight);
+ EXPECT_EQ(0, layer.OriginalSourceWidth);
+
+ /// make sure, Layer has default visibility
+ EXPECT_EQ(false, layer.getVisibility());
+
+ /// make sure, Layer has default opacity
+ EXPECT_DOUBLE_EQ(1.0, layer.getOpacity());
+
+ /// make sure, Layer has default orientation
+ EXPECT_EQ(Zero, layer.getOrientation());
+
+ /// make sure, Layer has default source rectangle
+ const Rectangle& srcRect = layer.getSourceRegion();
+ EXPECT_EQ(0, srcRect.height);
+ EXPECT_EQ(0, srcRect.width);
+ EXPECT_EQ(0, srcRect.x);
+ EXPECT_EQ(0, srcRect.y);
+
+ /// make sure, Layer has default destination rectangle
+ const Rectangle& destRect = layer.getDestinationRegion();
+ EXPECT_EQ(0, destRect.height);
+ EXPECT_EQ(0, destRect.width);
+ EXPECT_EQ(0, destRect.x);
+ EXPECT_EQ(0, destRect.y);
+
+ /// make sure, layer layer has default type
+ EXPECT_EQ(Software_2D, layer.getLayerType());
+}
+
+TEST_F(LayerTest, specialConstructor)
+{
+ unsigned int expectedId = 144;
+ Layer layer(expectedId);
+
+ /// make sure Layer has specified id
+ EXPECT_EQ(expectedId, layer.getID());
+
+ /// make sure, Layer was not added to any layer
+ //EXPECT_EQ(INVALID_ID, Layer.getContainingLayerId());
+
+ /// make sure, Layer has default size
+ EXPECT_EQ(0, layer.OriginalSourceHeight);
+ EXPECT_EQ(0, layer.OriginalSourceWidth);
+
+ /// make sure, Layer has default visibility
+ EXPECT_EQ(false, layer.getVisibility());
+
+ /// make sure, Layer has default opacity
+ EXPECT_DOUBLE_EQ(1.0, layer.getOpacity());
+
+ /// make sure, Layer has default orientation
+ EXPECT_EQ(Zero, layer.getOrientation());
+
+ /// make sure, Layer has default source rectangle
+ const Rectangle& srcRect = layer.getSourceRegion();
+ EXPECT_EQ(0, srcRect.height);
+ EXPECT_EQ(0, srcRect.width);
+ EXPECT_EQ(0, srcRect.x);
+ EXPECT_EQ(0, srcRect.y);
+
+ /// make sure, Layer has default destination rectangle
+ const Rectangle& destRect = layer.getDestinationRegion();
+ EXPECT_EQ(0, destRect.height);
+ EXPECT_EQ(0, destRect.width);
+ EXPECT_EQ(0, destRect.x);
+ EXPECT_EQ(0, destRect.y);
+
+ /// make sure, layer layer has default type
+ EXPECT_EQ(Software_2D, layer.getLayerType());
+}
+
+TEST_F(LayerTest, getLayerType)
+{
+ /// make sure, layer has default layer type
+ EXPECT_EQ(Software_2D, m_pLayer->getLayerType());
+
+ /// set different layer type
+ m_pLayer->setLayerType(Software_2_5D);
+
+ /// make sure, layer type of layer was updated
+ EXPECT_EQ(Software_2_5D, m_pLayer->getLayerType());
+}
+
+TEST_F(LayerTest, setLayerType)
+{
+ /// make sure, layer has default layer type
+ EXPECT_EQ(Software_2D, m_pLayer->getLayerType());
+
+ /// set different layer type
+ m_pLayer->setLayerType(Software_2_5D);
+
+ /// make sure, layer type of layer was updated
+ EXPECT_EQ(Software_2_5D, m_pLayer->getLayerType());
+
+ /// set layer type to default value
+ m_pLayer->setLayerType(Software_2D);
+
+ /// make sure, layer type of layer was updated
+ EXPECT_EQ(Software_2D, m_pLayer->getLayerType());
+}
+
+TEST_F(LayerTest, setLayerCapabilities)
+{
+ unsigned int expectedCapabilities = LayerScalable | LayerOrientable;
+
+ /// make sure, layer has default capabilities set
+ EXPECT_EQ(0, m_pLayer->getCapabilities());
+
+ /// enable expected capabilities of layer
+ m_pLayer->setLayerCapabilities(expectedCapabilities);
+
+ /// make sure, the capabilities of layer were updated
+ EXPECT_EQ(expectedCapabilities, m_pLayer->getCapabilities());
+
+ /// reset capabilities of layer to default value
+ m_pLayer->setLayerCapabilities(0);
+
+ /// make sure, the capabilities of layer were updated
+ EXPECT_EQ(0, m_pLayer->getCapabilities());
+}
+
+TEST_F(LayerTest, getCapabilities)
+{
+ unsigned int expectedCapabilities = LayerScalable | LayerOrientable;
+
+ /// make sure, layer has default capabilities set
+ EXPECT_EQ(0, m_pLayer->getCapabilities());
+
+ /// enable expected capabilities of layer
+ m_pLayer->setLayerCapabilities(expectedCapabilities);
+
+ /// make sure, the capabilities of layer were updated
+ EXPECT_EQ(expectedCapabilities, m_pLayer->getCapabilities());
+}
+
+TEST_F(LayerTest, addSurface)
+{
+ unsigned int expectedSurfaceId;
+ Surface surface(expectedSurfaceId);
+
+ /// make sure, layer contains no surfaces
+ SurfaceList& slist = m_pLayer->getAllSurfaces();
+ EXPECT_EQ(0, slist.size());
+
+ /// add surface to layer
+ m_pLayer->addSurface(&surface);
+
+ /// make sure, layer contains one surface
+ slist = m_pLayer->getAllSurfaces();
+ EXPECT_EQ(1, slist.size());
+}
+
+TEST_F(LayerTest, addSurface_twice)
+{
+ unsigned int expectedSurfaceId;
+ Surface surface(expectedSurfaceId);
+
+ /// make sure, layer contains no surfaces
+ SurfaceList& slist = m_pLayer->getAllSurfaces();
+ EXPECT_EQ(0, slist.size());
+
+ /// add surface to layer
+ m_pLayer->addSurface(&surface);
+
+ /// make sure, layer contains one surface
+ slist = m_pLayer->getAllSurfaces();
+ EXPECT_EQ(1, slist.size());
+
+ /// add surface to layer again
+ m_pLayer->addSurface(&surface);
+
+ /// make sure, layer still contains one surface
+ slist = m_pLayer->getAllSurfaces();
+ EXPECT_EQ(1, slist.size());
+}
+
+TEST_F(LayerTest, addSurface_alreadyOnOtherLayer)
+{
+ unsigned int expectedSurfaceId;
+ Surface surface(expectedSurfaceId);
+ Layer layer;
+
+ /// make sure, layer contains no surfaces
+ SurfaceList& slist = m_pLayer->getAllSurfaces();
+ EXPECT_EQ(0, slist.size());
+
+ /// add surface to layer
+ m_pLayer->addSurface(&surface);
+
+ /// make sure, layer contains one surface
+ slist = m_pLayer->getAllSurfaces();
+ EXPECT_EQ(1, slist.size());
+
+ /// add surface to other layer
+ layer.addSurface(&surface);
+
+ /// make sure, layer still contains one surface
+ slist = m_pLayer->getAllSurfaces();
+ EXPECT_EQ(1, slist.size());
+
+ /// make sure, other layer contains no surfaces
+ slist = layer.getAllSurfaces();
+ EXPECT_EQ(0, slist.size());
+}
+
+TEST_F(LayerTest, removeSurface)
+{
+ Surface s1, s2, s3;
+
+ /// make sure, layer contains no surfaces
+ SurfaceList& slist = m_pLayer->getAllSurfaces();
+ EXPECT_EQ(0, slist.size());
+
+ /// add 3 surfaces to layer
+ m_pLayer->addSurface(&s1);
+ m_pLayer->addSurface(&s2);
+ m_pLayer->addSurface(&s3);
+
+ /// make sure, layer contains the 3 surfaces
+ slist = m_pLayer->getAllSurfaces();
+ EXPECT_EQ(3, slist.size());
+ SurfaceListIterator iter = slist.begin();
+ EXPECT_EQ(&s1, *iter++);
+ EXPECT_EQ(&s2, *iter++);
+ EXPECT_EQ(&s3, *iter++);
+ EXPECT_EQ(slist.end(), iter);
+
+ /// remove 2 surfaces from layer
+ m_pLayer->removeSurface(&s1);
+ m_pLayer->removeSurface(&s3);
+
+ /// make sure, layer contains 1 surface
+ slist = m_pLayer->getAllSurfaces();
+ EXPECT_EQ(1, slist.size());
+ iter = slist.begin();
+ EXPECT_EQ(&s2, *iter++);
+ EXPECT_EQ(slist.end(), iter);
+
+ /// remove 1 surface from layer
+ m_pLayer->removeSurface(&s2);
+
+ /// make sure, layer contains no surfaces
+ slist = m_pLayer->getAllSurfaces();
+ EXPECT_EQ(0, slist.size());
+ EXPECT_EQ(slist.end(), slist.begin());
+}
+
+TEST_F(LayerTest, getAllSurfaces)
+{
+ Surface s1, s2, s3, s4, s5;
+
+ /// make sure, getAllSurfaces returns empty list, if layer contains no surfaces
+ SurfaceList& slist = m_pLayer->getAllSurfaces();
+ EXPECT_EQ(0, slist.size());
+
+ /// add 5 surfaces to layer
+ m_pLayer->addSurface(&s1);
+ m_pLayer->addSurface(&s2);
+ m_pLayer->addSurface(&s3);
+ m_pLayer->addSurface(&s4);
+ m_pLayer->addSurface(&s5);
+
+ /// check if all added surfaces are returned by getAllSurfaces
+ slist = m_pLayer->getAllSurfaces();
+ EXPECT_EQ(5, slist.size());
+ SurfaceListIterator iter = slist.begin();
+ EXPECT_EQ(&s1, *iter++);
+ EXPECT_EQ(&s2, *iter++);
+ EXPECT_EQ(&s3, *iter++);
+ EXPECT_EQ(&s4, *iter++);
+ EXPECT_EQ(&s5, *iter++);
+ EXPECT_EQ(slist.end(), iter);
+}
+
+TEST_F(LayerTest, removeAllSurfaces)
+{
+ Surface s1, s2, s3, s4, s5;
+
+ /// make sure, getAllSurfaces returns empty list, if layer contains no surfaces
+ SurfaceList& slist = m_pLayer->getAllSurfaces();
+ EXPECT_EQ(0, slist.size());
+
+ /// add 5 surfaces to layer
+ m_pLayer->addSurface(&s1);
+ m_pLayer->addSurface(&s2);
+ m_pLayer->addSurface(&s3);
+ m_pLayer->addSurface(&s4);
+ m_pLayer->addSurface(&s5);
+
+ /// make sure, layer contains 5 surfaces
+ slist = m_pLayer->getAllSurfaces();
+ EXPECT_EQ(5, slist.size());
+
+ /// remove all surfaces from layer
+ m_pLayer->removeAllSurfaces();
+
+ /// make sure, layer contains no surfaces
+ slist = m_pLayer->getAllSurfaces();
+ EXPECT_EQ(0, slist.size());
+
+ /// add 3 surfaces to layer
+ m_pLayer->addSurface(&s1);
+ m_pLayer->addSurface(&s2);
+ m_pLayer->addSurface(&s3);
+
+ /// make sure, layer contains 3 surfaces
+ slist = m_pLayer->getAllSurfaces();
+ EXPECT_EQ(3, slist.size());
+
+ /// remove all surfaces from layer
+ m_pLayer->removeAllSurfaces();
+
+ /// make sure, layer contains no surfaces
+ slist = m_pLayer->getAllSurfaces();
+ EXPECT_EQ(0, slist.size());
+}
+
uint size;
uint* array;
Layer* pLayer;
+ int expected = 91;
/// make sure, scene contains no layers
m_pScene->getLayerIDs(&size, &array);
ASSERT_EQ(0, size) << "Scene should contain 0 layers";
- /// create layer with id 91
- int expected = 91;
- m_pScene->createLayer(expected);
+ /// create layer with expected id
+ pLayer = m_pScene->createLayer(expected);
+ ASSERT_TRUE(pLayer) << "Layer was not created.";
+
+ /// make sure layer has expected id
+ EXPECT_EQ(expected, pLayer->getID());
/// make sure, scene contains one layer
m_pScene->getLayerIDs(&size, &array);
ASSERT_EQ(1, size) << "Scene should contain 1 layer";
- /// make sure layer has id 91
- pLayer = m_pScene->getLayer(expected);
- ASSERT_TRUE(pLayer) << "Layer was not found.";
- EXPECT_EQ(expected, pLayer->getID());
+ /// make sure, layer contains no surfaces (TODO)
+}
- /// make sure, layer has default size
- EXPECT_EQ(0, pLayer->OriginalSourceHeight);
- EXPECT_EQ(0, pLayer->OriginalSourceWidth);
+TEST_F(SceneTest, createLayer_twice)
+{
+ uint size;
+ uint* array;
+ int expected = 55;
+ double expectedOpacity = 0.322;
+ Layer* pLayer1;
+ Layer* pLayer2;
- /// make sure, layer has default visibility
- EXPECT_EQ(false, pLayer->visibility);
+ /// create Layer with id 55
+ pLayer1 = m_pScene->createLayer(expected);
+ ASSERT_EQ(expected, pLayer1->getID());
- /// make sure, layer has default opacity
- EXPECT_DOUBLE_EQ(1.0, pLayer->opacity);
+ /// make sure, scene contains one layer
+ m_pScene->getLayerIDs(&size, &array);
+ ASSERT_EQ(1, size) << "Scene should contain 1 layer";
- /// make sure, layer has default source rectangle
- const Rectangle& srcRect = pLayer->getSourceRegion();
- EXPECT_EQ(0, srcRect.height);
- EXPECT_EQ(0, srcRect.width);
- EXPECT_EQ(0, srcRect.x);
- EXPECT_EQ(0, srcRect.y);
+ /// try to create existing layer 55, handle to existing layer should be returned
+ pLayer2 = m_pScene->createLayer(expected);
+ ASSERT_EQ(expected, pLayer2->getID());
- /// make sure, layer has default destination rectangle
- const Rectangle& destRect = pLayer->getDestinationRegion();
- EXPECT_EQ(0, destRect.height);
- EXPECT_EQ(0, destRect.width);
- EXPECT_EQ(0, destRect.x);
- EXPECT_EQ(0, destRect.y);
+ /// make sure, scene still contains one layer
+ m_pScene->getLayerIDs(&size, &array);
+ ASSERT_EQ(1, size) << "Scene should contain 1 layer";
- /// make sure, layer layer has default type
- EXPECT_EQ(Software_2D, pLayer->getLayerType());
+ /// change opacity using first layer handle
+ pLayer1->setOpacity(expectedOpacity);
- /// make sure, layer contains no surfaces (TODO)
+ /// check opacity of layer using second handle
+ EXPECT_DOUBLE_EQ(expectedOpacity, pLayer2->getOpacity());
}
-TEST_F(SceneTest, createLayer_InvalidInput)
+TEST_F(SceneTest, createSurface)
{
- /// create Layer with id 55 (TODO)
+ uint size;
+ uint* array;
+ Surface* pSurface;
+ int expected = 131;
+
+ /// make sure, scene contains no surfaces
+ m_pScene->getSurfaceIDs(&size, &array);
+ ASSERT_EQ(0, size) << "Scene should contain 0 surfaces";
+
+ /// create surface with expected id
+ pSurface = m_pScene->createSurface(expected);
+ ASSERT_TRUE(pSurface) << "Surface was not created.";
+
+ /// make sure surface has expected id
+ EXPECT_EQ(expected, pSurface->getID());
+
+ /// make sure, scene contains one surface
+ m_pScene->getSurfaceIDs(&size, &array);
+ ASSERT_EQ(1, size) << "Scene should contain 1 surface";
- /// try to create existing layer 55 (TODO)
+ /// make sure, surface was not added to any layer
+ //EXPECT_EQ(INVALID_ID, pSurface->getContainingLayerId());
}
-TEST_F(SceneTest, createSurface)
+TEST_F(SceneTest, createSurface_twice)
{
+ uint size;
+ uint* array;
+ Surface* pSurface1;
+ Surface* pSurface2;
+ int expected = 135;
+ double expectedOpacity = 0.718;
+
+ /// make sure, scene contains no surfaces
+ m_pScene->getSurfaceIDs(&size, &array);
+ ASSERT_EQ(0, size) << "Scene should contain 0 surfaces";
+
+ /// create surface with expected id
+ pSurface1 = m_pScene->createSurface(expected);
+ ASSERT_TRUE(pSurface1) << "Surface was not created.";
+
+ /// make sure surface has expected id
+ EXPECT_EQ(expected, pSurface1->getID());
+
+ /// make sure, scene contains one surface
+ m_pScene->getSurfaceIDs(&size, &array);
+ ASSERT_EQ(1, size) << "Scene should contain 1 surface";
+
+ /// create surface with expected id again
+ pSurface2 = m_pScene->createSurface(expected);
+ ASSERT_TRUE(pSurface2) << "Surface was not created.";
+
+ /// make sure surface has expected id again
+ EXPECT_EQ(expected, pSurface2->getID());
+
+ /// make sure, scene still contains one surface
+ m_pScene->getSurfaceIDs(&size, &array);
+ ASSERT_EQ(1, size) << "Scene should contain 1 surface";
+
+ /// change opacity using first surface handle
+ pSurface1->setOpacity(expectedOpacity);
+
+ /// check opacity of surface using second surface handle
+ EXPECT_DOUBLE_EQ(expectedOpacity, pSurface2->getOpacity());
}
TEST_F(SceneTest, createLayerGroup)
Surface* m_pSurface;
};
+TEST_F(SurfaceTest, defaultConstructor)
+{
+ Surface surface;
+
+ /// make sure, surface was not added to any layer
+ //EXPECT_EQ(INVALID_ID, surface.getContainingLayerId());
+
+ /// make sure, surface has default size
+ EXPECT_EQ(0, surface.OriginalSourceHeight);
+ EXPECT_EQ(0, surface.OriginalSourceWidth);
+
+ /// make sure, surface has default visibility
+ EXPECT_EQ(false, surface.getVisibility());
+
+ /// make sure, surface has default opacity
+ EXPECT_DOUBLE_EQ(1.0, surface.getOpacity());
+
+ /// make sure, surface has default orientation
+ EXPECT_EQ(Zero, surface.getOrientation());
+
+ /// make sure, surface has default pixel format
+ EXPECT_EQ(PIXELFORMAT_UNKNOWN, surface.getPixelFormat());
+
+ /// make sure, surface has default source rectangle
+ const Rectangle& srcRect = surface.getSourceRegion();
+ EXPECT_EQ(0, srcRect.height);
+ EXPECT_EQ(0, srcRect.width);
+ EXPECT_EQ(0, srcRect.x);
+ EXPECT_EQ(0, srcRect.y);
+
+ /// make sure, surface has default destination rectangle
+ const Rectangle& destRect = surface.getDestinationRegion();
+ EXPECT_EQ(0, destRect.height);
+ EXPECT_EQ(0, destRect.width);
+ EXPECT_EQ(0, destRect.x);
+ EXPECT_EQ(0, destRect.y);
+}
+
+TEST_F(SurfaceTest, specialConstructor)
+{
+ unsigned int expectedId = 144;
+ Surface surface(expectedId);
+
+ /// make sure surface has specified id
+ EXPECT_EQ(expectedId, surface.getID());
+
+ /// make sure, surface was not added to any layer
+ //EXPECT_EQ(INVALID_ID, surface.getContainingLayerId());
+
+ /// make sure, surface has default size
+ EXPECT_EQ(0, surface.OriginalSourceHeight);
+ EXPECT_EQ(0, surface.OriginalSourceWidth);
+
+ /// make sure, surface has default visibility
+ EXPECT_EQ(false, surface.getVisibility());
+
+ /// make sure, surface has default opacity
+ EXPECT_DOUBLE_EQ(1.0, surface.getOpacity());
+
+ /// make sure, surface has default orientation
+ EXPECT_EQ(Zero, surface.getOrientation());
+
+ /// make sure, surface has default pixel format
+ EXPECT_EQ(PIXELFORMAT_UNKNOWN, surface.getPixelFormat());
+
+ /// make sure, surface has default source rectangle
+ const Rectangle& srcRect = surface.getSourceRegion();
+ EXPECT_EQ(0, srcRect.height);
+ EXPECT_EQ(0, srcRect.width);
+ EXPECT_EQ(0, srcRect.x);
+ EXPECT_EQ(0, srcRect.y);
+
+ /// make sure, surface has default destination rectangle
+ const Rectangle& destRect = surface.getDestinationRegion();
+ EXPECT_EQ(0, destRect.height);
+ EXPECT_EQ(0, destRect.width);
+ EXPECT_EQ(0, destRect.x);
+ EXPECT_EQ(0, destRect.y);
+}
+
TEST_F(SurfaceTest, getPixelFormat)
{