Skip to content

Commit

Permalink
cherry-picked tests/ commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz Włostowski committed Sep 27, 2016
1 parent 263e2e5 commit bec4608
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 9 deletions.
32 changes: 23 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ option( KICAD_INSTALL_DEMOS
"Install kicad demos and examples (default ON)"
ON )

option( KICAD_BUILD_TESTS
"Builds C++ tests (default OFF)"
)

# when option KICAD_SCRIPTING OR KICAD_SCRIPTING_MODULES is enabled:
# PYTHON_EXECUTABLE can be defined when invoking cmake
# ( use -DPYTHON_EXECUTABLE=<python path>/python.exe or python2 )
Expand All @@ -95,9 +99,14 @@ option( KICAD_SPICE "Build Kicad with internal Spice simulator." OFF )
set( KICAD_REPO_NAME "unknown" CACHE STRING "Name of the tree from which this build came." )


# Global setting: exports are explicit
set( CMAKE_CXX_VISIBILITY_PRESET "hidden" )
set( CMAKE_VISIBILITY_INLINES_HIDDEN ON )
# Global setting: exports are explicit by default
if ( KICAD_BUILD_TESTS )
set( CMAKE_CXX_VISIBILITY_PRESET "default" )
set( CMAKE_VISIBILITY_INLINES_HIDDEN OFF )
else()
set( CMAKE_CXX_VISIBILITY_PRESET "hidden" )
set( CMAKE_VISIBILITY_INLINES_HIDDEN ON )
endif()


# Global setting: build everything position independent
Expand All @@ -119,11 +128,13 @@ if( POLICY CMP0063 )
cmake_policy( SET CMP0063 NEW )
endif()
else()
if( CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY AND NOT APPLE )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY}hidden" )
endif()
if( CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN AND NOT APPLE )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN}" )
if( CMAKE_CXX_VISIBILITY_PRESET STREQUAL "hidden" )
if( CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY AND NOT APPLE )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY}hidden" )
endif()
if( CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN AND NOT APPLE )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN}" )
endif()
endif()
endif()

Expand Down Expand Up @@ -529,7 +540,7 @@ find_package( Cairo 1.8.8 REQUIRED )
#
# Note: Prior to Boost 1.59, the Boost context library is not built when compiling on windows
# with GCC. You must patch the Boost sources.
find_package( Boost 1.54.0 REQUIRED COMPONENTS context system thread )
find_package( Boost 1.54.0 REQUIRED COMPONENTS context system thread unit_test_framework )

# Include MinGW resource compiler.
include( MinGWResourceCompiler )
Expand Down Expand Up @@ -835,6 +846,9 @@ add_subdirectory( kicad ) # should follow pcbnew, eeschema
add_subdirectory( tools )
add_subdirectory( utils )
add_subdirectory( qa )
if ( KICAD_BUILD_TESTS )
add_subdirectory( tests )
endif()

# Resources
if ( KICAD_INSTALL_DEMOS )
Expand Down
12 changes: 12 additions & 0 deletions pcbnew/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,18 @@ set_target_properties( pcbnew_kiface PROPERTIES
SUFFIX ${KIFACE_SUFFIX}
)

if ( KICAD_BUILD_TESTS )
if ( UNIX )
add_custom_command(TARGET pcbnew_kiface POST_BUILD
COMMAND ln -sf _pcbnew.kiface lib_pcbnew_kiface.so )
else()
add_custom_command(TARGET pcbnew_kiface POST_BUILD
COMMAND copy _pcbnew.kiface lib_pcbnew_kiface.dll )
endif()


endif ()

if( ${OPENMP_FOUND} )
set_target_properties( pcbnew_kiface PROPERTIES
COMPILE_FLAGS ${OpenMP_CXX_FLAGS}
Expand Down
24 changes: 24 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
add_definitions( -DPCBNEW )


include_directories (
${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/polygon
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/pcbnew
${CMAKE_SOURCE_DIR}/pcbnew/router )

link_directories ( ${CMAKE_BINARY_DIR}/pcbnew )

function( add_test_case name )
add_executable ( ${name} ${name}.cpp )
target_link_libraries (
${name}
_pcbnew_kiface
${wxWidgets_LIBRARIES}
${Boost_LIBRARIES}
)
endfunction( add_test_case )

add_subdirectory ( pns )
add_subdirectory ( windowed )
3 changes: 3 additions & 0 deletions tests/pns/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_test_case( test_node )


21 changes: 21 additions & 0 deletions tests/pns/test_node.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE PNS_NODE

#include <boost/test/unit_test.hpp>

#include "pns_item.h"
#include "pns_node.h"

using namespace PNS;
using namespace std;

BOOST_AUTO_TEST_CASE( PnsNode )
{
unique_ptr<NODE> node ( new NODE );
BOOST_REQUIRE( node->JointCount() == 0 );

unique_ptr<SEGMENT> segment( new SEGMENT ( SEG ( VECTOR2I (0, 0), VECTOR2I( 1000, 1000) ), 0 ) );
node->Add( move ( segment ) );

BOOST_REQUIRE( node->JointCount() == 2 );
}

0 comments on commit bec4608

Please sign in to comment.