reorganized tests

This commit is contained in:
jkriege2 2024-01-27 14:43:23 +01:00
parent bcbce121c1
commit 0c314a5b83
6 changed files with 298 additions and 117 deletions

View File

@ -62,29 +62,6 @@ endfunction()
include(GNUInstallDirs)
function(jkqtplotter_installlibrary lib_name libIncludeSubdir BuildTypePart)
install(TARGETS ${lib_name} EXPORT ${lib_name}_TARGETS
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${libIncludeSubdir}
)
if(WIN32 AND MSVC AND (NOT MSVC_VERSION LESS 1600) AND (NOT CMAKE_VERSION VERSION_LESS "3.1") AND (NOT BuildTypePart STREQUAL ""))
install(FILES $<TARGET_PDB_FILE:${lib_name}> DESTINATION ${CMAKE_INSTALL_BINDIR} OPTIONAL)
endif()
set(JKQTP_CURRENT_TARGET_SHAREDPART "${BuildTypePart}")
set(JKQTP_CURRENT_TARGET_FILENAME "${lib_name}Targets.cmake")
configure_file(LibTarget.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${lib_name}Config.cmake" @ONLY)
install(EXPORT ${lib_name}_TARGETS
FILE "${JKQTP_CURRENT_TARGET_FILENAME}"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${lib_name}Version.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake )
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${lib_name}Config.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake )
endfunction(jkqtplotter_installlibrary)
@ -132,3 +109,44 @@ function(jkqtplotter_installlibrary_new lib_name libIncludeSubdir libSrcDir)
# install license
install(FILES "${PROJECT_SOURCE_DIR}/LICENSE" DESTINATION ${CMAKE_INSTALL_DOCDIR}) # RENAME "${lib_name}_LICENSE.txt" )
endfunction(jkqtplotter_installlibrary_new)
function(jkqtplotter_add_test TEST_NAME)
set(EXENAME ${TEST_NAME})
message( STATUS ".. Building Unit Test ${TEST_NAME}" )
add_executable(${EXENAME} WIN32)
target_include_directories(${EXENAME} PRIVATE ../../lib)
target_link_libraries(${EXENAME} PRIVATE Qt${QT_VERSION_MAJOR}::Test)
target_sources(${EXENAME} PRIVATE ${TEST_NAME}.cpp)
# Installation
install(TARGETS ${EXENAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
add_test(NAME ${TEST_NAME} COMMAND COMMAND $<TARGET_FILE:${EXENAME}>)
#Installation of Qt DLLs on Windows
jkqtplotter_deployqt(${EXENAME})
endfunction(jkqtplotter_add_test)
function(jkqtplotter_add_jkqtcommmon_test TEST_NAME)
jkqtplotter_add_test(${TEST_NAME})
target_link_libraries(${TEST_NAME} PRIVATE ${jkqtplotter_namespace}JKQTCommon${jkqtplotter_LIBNAME_VERSION_PART})
endfunction(jkqtplotter_add_test)
function(jkqtplotter_add_jkqtmath_test TEST_NAME)
jkqtplotter_add_test(${TEST_NAME})
target_link_libraries(${TEST_NAME} PRIVATE ${jkqtplotter_namespace}JKQTMath${jkqtplotter_LIBNAME_VERSION_PART})
endfunction(jkqtplotter_add_test)
function(jkqtplotter_add_jkqtmathtext_test TEST_NAME)
jkqtplotter_add_test(${TEST_NAME})
target_link_libraries(${TEST_NAME} PRIVATE ${jkqtplotter_namespace}JKQTMathText${jkqtplotter_LIBNAME_VERSION_PART})
endfunction(jkqtplotter_add_test)
function(jkqtplotter_add_jkqtplotter_test TEST_NAME)
jkqtplotter_add_test(${TEST_NAME})
target_link_libraries(${TEST_NAME} PRIVATE ${jkqtplotter_namespace}JKQTPlotter${jkqtplotter_LIBNAME_VERSION_PART})
endfunction(jkqtplotter_add_test)

View File

@ -1,28 +1,10 @@
cmake_minimum_required(VERSION 3.23)
set(TEST_NAME jkqtcommon_test)
set(EXENAME ${TEST_NAME})
message( STATUS ".. Building Unit Test ${TEST_NAME}" )
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
add_executable(${EXENAME} WIN32 ${SOURCES} ${HEADERS} ${RESOURCES} ${UIS})
target_include_directories(${EXENAME} PRIVATE ../../lib)
target_link_libraries(${EXENAME} PRIVATE ${jkqtplotter_namespace}JKQTCommon${jkqtplotter_LIBNAME_VERSION_PART})
target_link_libraries(${EXENAME} PRIVATE Qt${QT_VERSION_MAJOR}::Test)
target_sources(${EXENAME}
PRIVATE
${TEST_NAME}.cpp
)
# Installation
install(TARGETS ${EXENAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
add_test(NAME ${TEST_NAME} COMMAND COMMAND $<TARGET_FILE:${EXENAME}>)
#Installation of Qt DLLs on Windows
jkqtplotter_deployqt(${EXENAME})
jkqtplotter_add_jkqtcommmon_test(JKQTPStringTools_test)
jkqtplotter_add_jkqtcommmon_test(JKQTPCSSParser_test)
jkqtplotter_add_jkqtcommmon_test(JKQTPDataCache_test)
jkqtplotter_add_jkqtcommmon_test(JKQTPDataCache_benchmark)

View File

@ -25,15 +25,15 @@ namespace QTest {
}
class testJKQTCommmon : public QObject
class JKQTPCSSParserTest : public QObject
{
Q_OBJECT
public:
inline testJKQTCommmon() {
inline JKQTPCSSParserTest() {
}
inline ~testJKQTCommmon() {
inline ~JKQTPCSSParserTest() {
}
private slots:
@ -240,76 +240,9 @@ private slots:
}
inline void test_JKQTPCSSParser_JKQTPDataCache_ThreadSafe() {
JKQTPDataCache<QString, int, JKQTPDataCacheThreadSafe> cache([](int key) { return QString::number(key);}, 100,0.8);
QString sum;
for (int i=0; i<100; i++) {
sum+=cache.get(i);
}
qDebug()<<"sum.size()="<<sum.size();
QCOMPARE_EQ(cache.size(), 100);
for (int i=0; i<100; i++) {
QVERIFY(cache.contains(i));
}
sum+=cache.get(5000);
QCOMPARE_EQ(cache.size(), 81);
for (int i=1000; i<1005; i++) {
sum+=cache.get(i);
}
QCOMPARE_EQ(cache.size(), 86);
qDebug()<<"sum.size()="<<sum.size();
}
inline void test_JKQTPCSSParser_JKQTPDataCache_NotThreadSafe() {
JKQTPDataCache<QString, int, JKQTPDataCacheNotThreadSafe> cache([](int key) { return QString::number(key);}, 100,0.8);
QString sum;
for (int i=0; i<100; i++) {
sum+=cache.get(i);
}
qDebug()<<"sum.size()="<<sum.size();
QCOMPARE_EQ(cache.size(), 100);
for (int i=0; i<100; i++) {
QVERIFY(cache.contains(i));
}
sum+=cache.get(5000);
QCOMPARE_EQ(cache.size(), 81);
for (int i=1000; i<1005; i++) {
sum+=cache.get(i);
}
QCOMPARE_EQ(cache.size(), 86);
qDebug()<<"sum.size()="<<sum.size();
}
inline void benchmark_JKQTPCSSParser_JKQTPDataCache_ThreadSafe() {
JKQTPDataCache<QString, int, JKQTPDataCacheThreadSafe> cache([](int key) { return QString::number(key);}, 100,0.8);
int sum=cache.get(1).size();
QBENCHMARK(sum+=cache.get(1).size());
int i=1;
QBENCHMARK(sum+=cache.get(++i).size());
qDebug()<<"sum.size()="<<sum<<", i="<<i;
}
inline void benchmark_JKQTPCSSParser_JKQTPDataCache_NotThreadSafe() {
JKQTPDataCache<QString, int, JKQTPDataCacheNotThreadSafe> cache([](int key) { return QString::number(key);}, 100,0.8);
int sum=cache.get(1).size();
QBENCHMARK(sum+=cache.get(1).size());
int i=1;
QBENCHMARK(sum+=cache.get(++i).size());
qDebug()<<"sum.size()="<<sum<<", i="<<i;
}
};
QTEST_APPLESS_MAIN(testJKQTCommmon)
QTEST_APPLESS_MAIN(JKQTPCSSParserTest)
#include "jkqtcommon_test.moc"
#include "JKQTPCSSParser_test.moc"

View File

@ -0,0 +1,56 @@
#include <QObject>
#include <QtTest>
#include "jkqtcommon/jkqtpcachingtools.h"
#ifndef QCOMPARE_EQ
#define QCOMPARE_EQ(A,B) if (!static_cast<bool>((A)==(B))) {qDebug()<<QTest::toString(A)<< "!=" << QTest::toString(B); } QVERIFY((A)==(B))
#endif
#ifndef QVERIFY_THROWS_NO_EXCEPTION
#define QVERIFY_THROWS_NO_EXCEPTION(B) B
#endif
#ifndef QVERIFY_THROWS_EXCEPTION
#define QVERIFY_THROWS_EXCEPTION(type, A) QVERIFY_EXCEPTION_THROWN(A, type)
#endif
class JKQTPDataCacheBenchmark : public QObject
{
Q_OBJECT
public:
inline JKQTPDataCacheBenchmark() {
}
inline ~JKQTPDataCacheBenchmark() {
}
private slots:
inline void benchmark_JKQTPDataCache_ThreadSafe() {
JKQTPDataCache<QString, int, JKQTPDataCacheThreadSafe> cache([](int key) { return QString::number(key);}, 100,0.8);
int sum=cache.get(1).size();
QBENCHMARK(sum+=cache.get(1).size());
int i=1;
QBENCHMARK(sum+=cache.get(++i).size());
qDebug()<<"sum.size()="<<sum<<", i="<<i;
}
inline void benchmark_JKQTPDataCache_NotThreadSafe() {
JKQTPDataCache<QString, int, JKQTPDataCacheNotThreadSafe> cache([](int key) { return QString::number(key);}, 100,0.8);
int sum=cache.get(1).size();
QBENCHMARK(sum+=cache.get(1).size());
int i=1;
QBENCHMARK(sum+=cache.get(++i).size());
qDebug()<<"sum.size()="<<sum<<", i="<<i;
}
};
QTEST_APPLESS_MAIN(JKQTPDataCacheBenchmark)
#include "JKQTPDataCache_benchmark.moc"

View File

@ -0,0 +1,81 @@
#include <QObject>
#include <QtTest>
#include "jkqtcommon/jkqtpcachingtools.h"
#ifndef QCOMPARE_EQ
#define QCOMPARE_EQ(A,B) if (!static_cast<bool>((A)==(B))) {qDebug()<<QTest::toString(A)<< "!=" << QTest::toString(B); } QVERIFY((A)==(B))
#endif
#ifndef QVERIFY_THROWS_NO_EXCEPTION
#define QVERIFY_THROWS_NO_EXCEPTION(B) B
#endif
#ifndef QVERIFY_THROWS_EXCEPTION
#define QVERIFY_THROWS_EXCEPTION(type, A) QVERIFY_EXCEPTION_THROWN(A, type)
#endif
class JKQTPDataCacheTest : public QObject
{
Q_OBJECT
public:
inline JKQTPDataCacheTest() {
}
inline ~JKQTPDataCacheTest() {
}
private slots:
inline void test_JKQTPDataCache_ThreadSafe() {
JKQTPDataCache<QString, int, JKQTPDataCacheThreadSafe> cache([](int key) { return QString::number(key);}, 100,0.8);
QString sum;
for (int i=0; i<100; i++) {
sum+=cache.get(i);
}
qDebug()<<"sum.size()="<<sum.size();
QCOMPARE_EQ(cache.size(), 100);
for (int i=0; i<100; i++) {
QVERIFY(cache.contains(i));
}
sum+=cache.get(5000);
QCOMPARE_EQ(cache.size(), 81);
for (int i=1000; i<1005; i++) {
sum+=cache.get(i);
}
QCOMPARE_EQ(cache.size(), 86);
qDebug()<<"sum.size()="<<sum.size();
}
inline void test_JKQTPDataCache_NotThreadSafe() {
JKQTPDataCache<QString, int, JKQTPDataCacheNotThreadSafe> cache([](int key) { return QString::number(key);}, 100,0.8);
QString sum;
for (int i=0; i<100; i++) {
sum+=cache.get(i);
}
qDebug()<<"sum.size()="<<sum.size();
QCOMPARE_EQ(cache.size(), 100);
for (int i=0; i<100; i++) {
QVERIFY(cache.contains(i));
}
sum+=cache.get(5000);
QCOMPARE_EQ(cache.size(), 81);
for (int i=1000; i<1005; i++) {
sum+=cache.get(i);
}
QCOMPARE_EQ(cache.size(), 86);
qDebug()<<"sum.size()="<<sum.size();
}
};
QTEST_APPLESS_MAIN(JKQTPDataCacheTest)
#include "JKQTPDataCache_test.moc"

View File

@ -0,0 +1,111 @@
#include <QObject>
#include <QtTest>
#include "jkqtcommon/jkqtpstringtools.h"
#ifndef QCOMPARE_EQ
#define QCOMPARE_EQ(A,B) if (!static_cast<bool>((A)==(B))) {qDebug()<<QTest::toString(A)<< "!=" << QTest::toString(B); } QVERIFY((A)==(B))
#endif
#ifndef QVERIFY_THROWS_NO_EXCEPTION
#define QVERIFY_THROWS_NO_EXCEPTION(B) B
#endif
#ifndef QVERIFY_THROWS_EXCEPTION
#define QVERIFY_THROWS_EXCEPTION(type, A) QVERIFY_EXCEPTION_THROWN(A, type)
#endif
class JKQTPStringToolsTest : public QObject
{
Q_OBJECT
public:
inline JKQTPStringToolsTest() {
}
inline ~JKQTPStringToolsTest() {
}
private slots:
inline void test_jkqtp_String2QBrushStyleExt() {
Qt::BrushStyle bs;
QGradient n, g;
QLinearGradient lg;
QVERIFY_THROWS_NO_EXCEPTION(bs=jkqtp_String2QBrushStyleExt("warmflame", &n, nullptr));
g = QGradient(QGradient::WarmFlame);
g.setCoordinateMode(QGradient::ObjectBoundingMode);
QCOMPARE_EQ(n, g);
QCOMPARE_EQ(bs, Qt::LinearGradientPattern);
QVERIFY_THROWS_NO_EXCEPTION(bs=jkqtp_String2QBrushStyleExt("d1", &n, nullptr));
QCOMPARE_EQ(bs, Qt::Dense1Pattern);
QVERIFY_THROWS_NO_EXCEPTION(bs=jkqtp_String2QBrushStyleExt("linear-gradient(to left, red, blue)", &n, nullptr));
lg = QLinearGradient(1,0.5,0,0.5);
lg.setCoordinateMode(QGradient::ObjectBoundingMode);
lg.setStops({QGradientStop(0, QColor("red")), QGradientStop(1, QColor("blue"))});
QCOMPARE_EQ(n, lg);
QCOMPARE_EQ(bs, Qt::LinearGradientPattern);
}
inline void test_jkqtp_String2QColor() {
QColor n;
QVERIFY_THROWS_NO_EXCEPTION(n=jkqtp_String2QColor("black"));
QCOMPARE_EQ(n, QColor(Qt::black));
QVERIFY_THROWS_NO_EXCEPTION(n=jkqtp_String2QColor("red"));
QCOMPARE_EQ(n, QColor(Qt::red));
QVERIFY_THROWS_NO_EXCEPTION(n=jkqtp_String2QColor("salmon"));
QCOMPARE_EQ(n, QColor("salmon"));
QVERIFY_THROWS_NO_EXCEPTION(n=jkqtp_String2QColor("transparent"));
QCOMPARE_EQ(n.alpha(), 0);
QVERIFY_THROWS_NO_EXCEPTION(n=jkqtp_String2QColor("window"));
QCOMPARE_EQ(n, QGuiApplication::palette().color(QPalette::Window));
QVERIFY_THROWS_NO_EXCEPTION(n=jkqtp_String2QColor("#F0F"));
QCOMPARE_EQ(n, QColor::fromRgb(255,0,255));
QVERIFY_THROWS_NO_EXCEPTION(n=jkqtp_String2QColor("#FF00FF"));
QCOMPARE_EQ(n, QColor::fromRgb(255,0,255));
QVERIFY_THROWS_NO_EXCEPTION(n=jkqtp_String2QColor("#F0F1"));
QCOMPARE_EQ(n, QColor::fromRgb(0xFF,0,0xFF,0x11));
QVERIFY_THROWS_NO_EXCEPTION(n=jkqtp_String2QColor("#FF00FF11"));
QCOMPARE_EQ(n, QColor::fromRgb(255,0,255,17));
QVERIFY_THROWS_NO_EXCEPTION(n=jkqtp_String2QColor("rgb(50,100,200)"));
QCOMPARE_EQ(n, QColor::fromRgb(50,100,200));
QVERIFY_THROWS_NO_EXCEPTION(n=jkqtp_String2QColor("grey50"));
QCOMPARE_EQ(n, QColor::fromRgbF(0.5,0.5,0.5));
QVERIFY_THROWS_NO_EXCEPTION(n=jkqtp_String2QColor("grey52"));
QCOMPARE_EQ(n, QColor::fromRgbF(0.52,0.52,0.52));
QVERIFY_THROWS_NO_EXCEPTION(n=jkqtp_String2QColor("grey52,20%"));
QCOMPARE_EQ(n, QColor::fromRgbF(0.52,0.52,0.52,0.8));
QVERIFY_THROWS_NO_EXCEPTION(n=jkqtp_String2QColor("grey52,a20%"));
QCOMPARE_EQ(n, QColor::fromRgbF(0.52,0.52,0.52,0.2));
QVERIFY_THROWS_NO_EXCEPTION(n=jkqtp_String2QColor("grey52,a240"));
QCOMPARE_EQ(n, QColor::fromRgbF(0.52,0.52,0.52,240.0/255.0));
}
};
QTEST_APPLESS_MAIN(JKQTPStringToolsTest)
#include "JKQTPStringTools_test.moc"