Port tst_viewguard.cpp to doctest
doctest will be the unit-test framework for new tests, since we'll have a lot of non-Qt code.
This commit is contained in:
@@ -170,6 +170,7 @@ if(${PROJECT_NAME}_DEVELOPER_MODE)
|
||||
set(${PROJECT_NAME}_TESTS ON)
|
||||
set(${PROJECT_NAME}_WERROR ON)
|
||||
include(ECMEnableSanitizers)
|
||||
find_package(doctest REQUIRED)
|
||||
endif()
|
||||
|
||||
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||
|
||||
@@ -9,40 +9,32 @@
|
||||
Contact KDAB at <info@kdab.com> for commercial licensing options.
|
||||
*/
|
||||
|
||||
#include <ViewGuard.h>
|
||||
#include <qtwidgets/views/ViewWrapper_qtwidgets.h>
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include "ViewGuard.h"
|
||||
#include "qtwidgets/views/ViewWrapper_qtwidgets.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <doctest/doctest.h>
|
||||
|
||||
using namespace KDDockWidgets;
|
||||
|
||||
void test(bool cond, const char *stmt, int line)
|
||||
{
|
||||
if (!cond) {
|
||||
printf("[FAILED] %s line; %d\n", stmt, line);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
#define TEST(cond) test(cond, #cond, __LINE__)
|
||||
|
||||
int main()
|
||||
TEST_CASE("ViewGuard test")
|
||||
{
|
||||
ViewGuard g(nullptr);
|
||||
TEST(g.isNull());
|
||||
CHECK(g.isNull());
|
||||
|
||||
{
|
||||
Views::ViewWrapper_qtwidgets wv(static_cast<QWidget *>(nullptr));
|
||||
g = &wv;
|
||||
TEST(!g.isNull());
|
||||
CHECK(!g.isNull());
|
||||
}
|
||||
|
||||
TEST(g.isNull());
|
||||
CHECK(g.isNull());
|
||||
|
||||
// Test when ViewGuard is destroyed before view
|
||||
// May not crash without ASAN
|
||||
Views::ViewWrapper_qtwidgets wv(static_cast<QWidget*>(nullptr));
|
||||
Views::ViewWrapper_qtwidgets wv(static_cast<QWidget *>(nullptr));
|
||||
{
|
||||
ViewGuard gg(&wv);
|
||||
TEST(!gg.isNull());
|
||||
CHECK(!gg.isNull());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user