Skip to content

Commit

Permalink
pxPixel.h code coverage (pxscene#805)
Browse files Browse the repository at this point in the history
* pxPixel.h code coverage

* Fixed mac compilation error
  • Loading branch information
arun-govindan authored and mfiess committed Jan 30, 2018
1 parent 1b6a966 commit 0e6d4b0
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
6 changes: 3 additions & 3 deletions tests/pxScene2d/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
if (DEFINED ENV{CODE_COVERAGE})
message("enabling code coverage support")
add_definitions(-DENABLE_CODE_COVERAGE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -fno-inline")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -fno-inline -fno-elide-constructors")
set(PLATFORM_LIBRARIES ${PLATFORM_LIBRARIES} gcov)
endif ()
endif (HOSTNAME STREQUAL "raspberrypi")
Expand All @@ -112,7 +112,7 @@ elseif (APPLE)
if (DEFINED ENV{CODE_COVERAGE})
message("enabling code coverage support")
add_definitions(-DENABLE_CODE_COVERAGE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -fno-inline")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -fno-inline -fno-elide-constructors")
execute_process(COMMAND clang --version OUTPUT_VARIABLE LLVM_VERSION1 ERROR_VARIABLE ERROR_VARIABLE1 COMMAND grep "LLVM version" OUTPUT_VARIABLE LLVM_VERSION2 ERROR_VARIABLE LLVM_ERROR2 COMMAND awk "{print $4}" OUTPUT_FILE llvmoutput OUTPUT_VARIABLE LLVM_VERSION3 ERROR_VARIABLE LLVM_ERROR3)
execute_process(COMMAND awk "{ printf \"%s\", $0 }" llvmoutput OUTPUT_VARIABLE LLVM_VERSION)
execute_process(COMMAND rm llvmoutput)
Expand All @@ -128,7 +128,7 @@ add_definitions(-D${PX_PLATFORM} -DENABLE_RT_NODE -DRUNINMAIN -DENABLE_HTTP_CACH
set(TEST_SOURCE_FILES pxscene2dtestsmain.cpp test_example.cpp test_api.cpp test_pxcontext.cpp test_memoryleak.cpp test_rtnode.cpp test_rtMutex.cpp
test_pxAnimate.cpp test_rtFile.cpp test_rtZip.cpp test_rtString.cpp test_rtValue.cpp test_pxImage.cpp test_pxOffscreen.cpp test_pxMatrix4T.cpp test_rtObject.cpp
test_pxWindowUtil.cpp test_pxTexture.cpp test_pxWindow.cpp test_ioapi.cpp test_rtLog.cpp test_pxTimerNative.cpp
test_rtUrlUtils.cpp test_pxArchive.cpp ${PLATFORM_TEST_FILES} ${TEST_WAYLAND_SOURCE_FILES})
test_rtUrlUtils.cpp test_pxArchive.cpp test_pxPixel_h.cpp ${PLATFORM_TEST_FILES} ${TEST_WAYLAND_SOURCE_FILES})

if (DEFINED ENV{USE_HTTP_CACHE})
message("Include http cache tests")
Expand Down
60 changes: 60 additions & 0 deletions tests/pxScene2d/test_pxPixel_h.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include "pxCore.h"
#include "pxPixel.h"
#include "test_includes.h" // Needs to be included last

using namespace std;

class pxPixelTest : public testing::Test
{
public:
virtual void SetUp()
{
}

virtual void TearDown()
{
}
void pxPixelParam0()
{
pxPixel p = pxPixel();
EXPECT_TRUE(sizeof(p) == sizeof(pxPixel));
}
void pxPixelParam1()
{
uint32_t u = 1;
pxPixel p = pxPixel(u);
EXPECT_TRUE(1 == p.u);
}
void pxPixelParam1Struct()
{
uint32_t u = 2;
pxPixel p = pxPixel(u);
EXPECT_TRUE(2 == p.u);
p = pxPixel((const pxPixel&)p);
}
void pxPixelParam4()
{
uint32_t r= 1;
uint32_t g= 1;
uint32_t b= 1;
uint32_t a= 1;
pxPixel p = pxPixel(r, g, b, a);
EXPECT_TRUE(1 == p.r);
EXPECT_TRUE(1 == p.g);
EXPECT_TRUE(1 == p.b);
EXPECT_TRUE(1 == p.a);

p = pxPixel(r, g, b);
EXPECT_TRUE(1 == p.r);
EXPECT_TRUE(1 == p.g);
EXPECT_TRUE(1 == p.b);
EXPECT_TRUE(255 == p.a);
}
};
TEST_F(pxPixelTest, pxPixelCompleteTest)
{
pxPixelParam0();
pxPixelParam1();
pxPixelParam1Struct();
pxPixelParam4();
}

0 comments on commit 0e6d4b0

Please sign in to comment.