mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-02 03:10:42 +08:00
Start building tests with Catch; also use ON/OFF syntax for build options.
testableframe borrowed from wxWidgets tests.
This commit is contained in:
parent
333a27aada
commit
5bcf807909
@ -4,7 +4,7 @@ before_install:
|
||||
script:
|
||||
- bash package/linux/travis-setup.sh
|
||||
- mkdir build && cd build
|
||||
- cmake -DBOOST_ROOT=$BOOST_DIR -DSLIC3R_STATIC=1 ../src
|
||||
- cmake -DBOOST_ROOT=$BOOST_DIR -DSLIC3R_STATIC=ON ../src
|
||||
- cmake --build .
|
||||
branches:
|
||||
only:
|
||||
|
@ -2,6 +2,9 @@ cmake_minimum_required (VERSION 3.9)
|
||||
project (slic3r)
|
||||
|
||||
|
||||
option(GUI_BUILD_TESTS "Build tests for Slic3r GUI." ON)
|
||||
option(SLIC3R_BUILD_TESTS "Build tests for libslic3r." ON)
|
||||
|
||||
# only on newer GCCs: -ftemplate-backtrace-limit=0
|
||||
set(CMAKE_CXX_FLAGS "-g ${CMAKE_CXX_FLAGS} -Wall -DM_PI=3.14159265358979323846 -D_GLIBCXX_USE_C99 -DHAS_BOOL -DNOGDI -DBOOST_ASIO_DISABLE_KQUEUE")
|
||||
|
||||
@ -37,13 +40,15 @@ ELSE(CMAKE_HOST_APPLE)
|
||||
# set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -L.")
|
||||
ENDIF(CMAKE_HOST_APPLE)
|
||||
|
||||
if(DEFINED ENV{SLIC3R_STATIC})
|
||||
option(SLIC3R_STATIC "Build and link Slic3r statically." ON)
|
||||
|
||||
if(SLIC3R_STATIC)
|
||||
set(Boost_USE_STATIC_LIBS ON)
|
||||
set(Boost_USE_STATIC_RUNTIME ON)
|
||||
else(DEFINED ENV{SLIC3R_STATIC})
|
||||
else(SLIC3R_STATIC)
|
||||
set(Boost_USE_STATIC_LIBS OFF)
|
||||
set(Boost_USE_STATIC_RUNTIME OFF)
|
||||
endif(DEFINED ENV{SLIC3R_STATIC})
|
||||
endif(SLIC3R_STATIC)
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
@ -51,6 +56,8 @@ find_package(Boost REQUIRED COMPONENTS system thread filesystem)
|
||||
|
||||
set(LIBDIR ${CMAKE_CURRENT_SOURCE_DIR}/../xs/src/)
|
||||
set(GUI_LIBDIR ${CMAKE_CURRENT_SOURCE_DIR}/GUI/)
|
||||
set(TESTDIR ${CMAKE_CURRENT_SOURCE_DIR}/test)
|
||||
set(GUI_TESTDIR ${CMAKE_CURRENT_SOURCE_DIR}/test/GUI/)
|
||||
|
||||
include_directories(${LIBDIR})
|
||||
include_directories(${LIBDIR}/libslic3r)
|
||||
@ -154,6 +161,12 @@ add_library(poly2tri STATIC
|
||||
${LIBDIR}/poly2tri/sweep/sweep.cc
|
||||
)
|
||||
|
||||
set(UI_TEST_SOURCES
|
||||
${GUI_TESTDIR}/testableframe.cpp
|
||||
${GUI_TESTDIR}/test_harness_gui.cpp
|
||||
${GUI_TESTDIR}/test_field_checkbox.cpp
|
||||
)
|
||||
|
||||
add_executable(slic3r slic3r.cpp)
|
||||
#set_target_properties(slic3r PROPERTIES LINK_SEARCH_START_STATIC 1)
|
||||
#set_target_properties(slic3r PROPERTIES LINK_SEARCH_END_STATIC 1)
|
||||
@ -224,6 +237,43 @@ IF(wxWidgets_FOUND)
|
||||
#only build GUI lib if building with wx
|
||||
target_link_libraries (slic3r slic3r_gui ${wxWidgets_LIBRARIES})
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_WX")
|
||||
|
||||
if (GUI_BUILD_TESTS)
|
||||
enable_testing()
|
||||
if (NOT TARGET Catch)
|
||||
include (ExternalProject)
|
||||
if(IS_TRAVIS_BUILD) # on travis, use git for fetching instead of wget
|
||||
set(FETCH_EXTERNAL_CATCH
|
||||
GIT_REPOSITORY https://github.com/philsquared/Catch.git
|
||||
GIT_TAG 19ab2117c5bac2f376f8da4a4b25e183137bcec0)
|
||||
elseif(WIN32)
|
||||
set(FETCH_EXTERNAL_CATCH
|
||||
URL https://github.com/catchorg/Catch2/archive/v2.0.1.zip
|
||||
URL_HASH MD5=1abca1b324b99b1631e999119b172620)
|
||||
else()
|
||||
set(FETCH_EXTERNAL_CATCH
|
||||
URL https://github.com/catchorg/Catch2/archive/v2.0.1.tar.gz
|
||||
URL_HASH MD5=2080f4696579351d9323b3b5a8c3c71b)
|
||||
endif()
|
||||
ExternalProject_Add(Catch-External
|
||||
PREFIX ${CMAKE_BINARY_DIR}/external/Catch
|
||||
${FETCH_EXTERNAL_CATCH}
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/external/Catch/src/Catch-External/single_include/catch.hpp
|
||||
${CMAKE_BINARY_DIR}/external/Catch/include/catch.hpp
|
||||
)
|
||||
add_library(Catch INTERFACE)
|
||||
add_dependencies(Catch Catch-External)
|
||||
|
||||
target_include_directories(Catch INTERFACE ${CMAKE_BINARY_DIR}/external/Catch/include)
|
||||
target_compile_definitions(Catch INTERFACE $<$<CXX_COMPILER_ID:MSVC>:_SILENCE_CXX17_UNCAUGHT_EXCEPTION_DEPRECATION_WARNING>)
|
||||
endif()
|
||||
add_executable(gui_test ${UI_TEST_SOURCES})
|
||||
add_test(NAME TestBase COMMAND gui_test)
|
||||
target_link_libraries(gui_test PUBLIC libslic3r slic3r_gui Catch ${wxWidgets_LIBRARIES})
|
||||
|
||||
endif()
|
||||
ELSE(wxWidgets_FOUND)
|
||||
# For convenience. When we cannot continue, inform the user
|
||||
MESSAGE("wx not found!")
|
||||
@ -249,4 +299,9 @@ IF (WIN32)
|
||||
# target_link_libraries(extrude-tin boost-nowide)
|
||||
ENDIF(WIN32)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#target_link_libraries (extrude-tin libslic3r admesh BSpline clipper expat polypartition poly2tri ${Boost_LIBRARIES})
|
||||
|
11
src/test/GUI/test_field_checkbox.cpp
Normal file
11
src/test/GUI/test_field_checkbox.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
#include "test/catch.hpp"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/app.h"
|
||||
#include "wx/checkbox.h"
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
#include "testableframe.h"
|
||||
|
||||
TEST_CASE( "Dummy" ) {
|
||||
}
|
2
src/test/GUI/test_harness_gui.cpp
Normal file
2
src/test/GUI/test_harness_gui.cpp
Normal file
@ -0,0 +1,2 @@
|
||||
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
|
||||
#include "test/catch.hpp"
|
61
src/test/GUI/testableframe.cpp
Normal file
61
src/test/GUI/testableframe.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: testableframe.cpp
|
||||
// Purpose: An improved wxFrame for unit-testing
|
||||
// Author: Steven Lamerton
|
||||
// Copyright: (c) 2010 Steven Lamerton
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/app.h"
|
||||
#include "testableframe.h"
|
||||
|
||||
wxTestableFrame::wxTestableFrame() : wxFrame(NULL, wxID_ANY, "Test Frame")
|
||||
{
|
||||
// Use fixed position to facilitate debugging.
|
||||
Move(200, 200);
|
||||
|
||||
Show();
|
||||
}
|
||||
|
||||
void wxTestableFrame::OnEvent(wxEvent& evt)
|
||||
{
|
||||
m_count[evt.GetEventType()]++;
|
||||
|
||||
if(! evt.IsCommandEvent() )
|
||||
evt.Skip();
|
||||
}
|
||||
|
||||
int wxTestableFrame::GetEventCount(wxEventType type)
|
||||
{
|
||||
return m_count[type];
|
||||
}
|
||||
|
||||
void wxTestableFrame::ClearEventCount(wxEventType type)
|
||||
{
|
||||
m_count[type] = 0;
|
||||
}
|
||||
|
||||
EventCounter::EventCounter(wxWindow* win, wxEventType type) : m_type(type),
|
||||
m_win(win)
|
||||
|
||||
{
|
||||
m_frame = wxStaticCast(wxTheApp->GetTopWindow(), wxTestableFrame);
|
||||
|
||||
m_win->Connect(m_type, wxEventHandler(wxTestableFrame::OnEvent),
|
||||
NULL, m_frame);
|
||||
}
|
||||
|
||||
EventCounter::~EventCounter()
|
||||
{
|
||||
m_win->Disconnect(m_type, wxEventHandler(wxTestableFrame::OnEvent),
|
||||
NULL, m_frame);
|
||||
|
||||
//This stops spurious counts from previous tests
|
||||
Clear();
|
||||
|
||||
m_frame = NULL;
|
||||
m_win = NULL;
|
||||
}
|
42
src/test/GUI/testableframe.h
Normal file
42
src/test/GUI/testableframe.h
Normal file
@ -0,0 +1,42 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: testableframe.h
|
||||
// Purpose: An improved wxFrame for unit-testing
|
||||
// Author: Steven Lamerton
|
||||
// Copyright: (c) 2010 Steven Lamerton
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "wx/frame.h"
|
||||
#include "wx/hashmap.h"
|
||||
#include "wx/event.h"
|
||||
|
||||
class wxTestableFrame : public wxFrame
|
||||
{
|
||||
public:
|
||||
wxTestableFrame();
|
||||
|
||||
void OnEvent(wxEvent& evt);
|
||||
|
||||
private:
|
||||
friend class EventCounter;
|
||||
|
||||
int GetEventCount(wxEventType type);
|
||||
void ClearEventCount(wxEventType type);
|
||||
|
||||
wxLongToLongHashMap m_count;
|
||||
};
|
||||
|
||||
class EventCounter
|
||||
{
|
||||
public:
|
||||
EventCounter(wxWindow* win, wxEventType type);
|
||||
~EventCounter();
|
||||
|
||||
int GetCount() { return m_frame->GetEventCount(m_type); }
|
||||
void Clear() { m_frame->ClearEventCount(m_type); }
|
||||
|
||||
private:
|
||||
wxEventType m_type;
|
||||
wxTestableFrame* m_frame;
|
||||
wxWindow* m_win;
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user