mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-22 07:42:02 +00:00
Add unit test for the Length class
I noticed that inBP() is wrong for several units and want to fix it. The unit test will help me to find regressions.
This commit is contained in:
parent
3f6b034167
commit
7910502b8e
@ -702,9 +702,11 @@ endif
|
||||
EXTRA_DIST += \
|
||||
tests/test_ExternalTransforms \
|
||||
tests/regfiles/ExternalTransforms \
|
||||
tests/test_layout
|
||||
tests/regfiles/Length \
|
||||
tests/test_layout \
|
||||
tests/test_Length
|
||||
|
||||
TESTS = tests/test_ExternalTransforms
|
||||
TESTS = tests/test_ExternalTransforms tests/test_Length
|
||||
|
||||
alltests: check alltests-recursive
|
||||
|
||||
@ -722,6 +724,7 @@ updatetests:
|
||||
|
||||
check_PROGRAMS = \
|
||||
check_ExternalTransforms \
|
||||
check_Length \
|
||||
check_layout
|
||||
|
||||
if INSTALL_MACOSX
|
||||
@ -760,4 +763,14 @@ check_ExternalTransforms_SOURCES = \
|
||||
tests/boost.cpp \
|
||||
tests/dummy_functions.cpp
|
||||
|
||||
check_Length_CPPFLAGS = $(AM_CPPFLAGS)
|
||||
check_Length_LDADD = support/liblyxsupport.a $(LIBICONV) $(BOOST_LIBS) @LIBS@ $(QT_LIB) $(LIBSHLWAPI)
|
||||
check_Length_LDFLAGS = $(QT_LDFLAGS) $(ADD_FRAMEWORKS)
|
||||
check_Length_SOURCES = \
|
||||
Length.cpp \
|
||||
lengthcommon.cpp \
|
||||
tests/check_Length.cpp \
|
||||
tests/boost.cpp \
|
||||
tests/dummy_functions.cpp
|
||||
|
||||
.PHONY: alltests alltests-recursive updatetests
|
||||
|
@ -75,3 +75,28 @@ add_test(NAME "check_ExternalTransforms"
|
||||
-P "${TOP_SRC_DIR}/src/support/tests/supporttest.cmake")
|
||||
add_dependencies(lyx_run_tests check_ExternalTransforms)
|
||||
|
||||
set(check_ExternalTransforms_SOURCES)
|
||||
foreach(_f graphics/GraphicsParams.cpp insets/ExternalTransforms.cpp
|
||||
Length.cpp lengthcommon.cpp tests/check_ExternalTransforms.cpp
|
||||
tests/boost.cpp tests/dummy_functions.cpp)
|
||||
list(APPEND check_ExternalTransforms_SOURCES ${TOP_SRC_DIR}/src/${_f})
|
||||
endforeach()
|
||||
|
||||
include_directories(${TOP_SRC_DIR}/src/tests)
|
||||
add_executable(check_Length ${check_Length_SOURCES})
|
||||
|
||||
target_link_libraries(check_Length support
|
||||
${Lyx_Boost_Libraries} ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY})
|
||||
lyx_target_link_libraries(check_Length Magic)
|
||||
|
||||
add_dependencies(lyx_run_tests check_Length)
|
||||
set_target_properties(check_Length PROPERTIES FOLDER "tests/src")
|
||||
target_link_libraries(check_Length ${ICONV_LIBRARY})
|
||||
|
||||
add_test(NAME "check_Length"
|
||||
COMMAND ${CMAKE_COMMAND} -DCommand=$<TARGET_FILE:check_Length>
|
||||
"-DInput=${TOP_SRC_DIR}/src/tests/regfiles/Length"
|
||||
"-DOutput=${CMAKE_CURRENT_BINARY_DIR}/Length_data"
|
||||
-P "${TOP_SRC_DIR}/src/support/tests/supporttest.cmake")
|
||||
add_dependencies(lyx_run_tests check_Length)
|
||||
|
||||
|
41
src/tests/check_Length.cpp
Normal file
41
src/tests/check_Length.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "../Length.h"
|
||||
#include "../LyXRC.h"
|
||||
#include "../support/debug.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using namespace lyx;
|
||||
using namespace std;
|
||||
|
||||
|
||||
void test_inPixels()
|
||||
{
|
||||
// want to see non-zero SP
|
||||
lyxrc.zoom = 100000;
|
||||
lyxrc.dpi = 72;
|
||||
for (int i = Length::BP; i <= Length::UNIT_NONE; ++i) {
|
||||
Length const l(2342, static_cast<Length::UNIT>(i));
|
||||
cout << l.inPixels(250) << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void test_inBP()
|
||||
{
|
||||
for (int i = Length::BP; i <= Length::UNIT_NONE; ++i) {
|
||||
Length const l(2342, static_cast<Length::UNIT>(i));
|
||||
cout << l.inBP() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int, char **)
|
||||
{
|
||||
// Connect lyxerr with cout instead of cerr to catch error output
|
||||
lyx::lyxerr.setStream(cout);
|
||||
test_inPixels();
|
||||
test_inBP();
|
||||
}
|
38
src/tests/regfiles/Length
Normal file
38
src/tests/regfiles/Length
Normal file
@ -0,0 +1,38 @@
|
||||
2342000
|
||||
29951094
|
||||
66387402
|
||||
2495925
|
||||
23332503
|
||||
10044643
|
||||
168624000
|
||||
6638740
|
||||
1296250
|
||||
27999004
|
||||
2333250
|
||||
36
|
||||
5855
|
||||
5855
|
||||
9954
|
||||
5855
|
||||
10463
|
||||
12881
|
||||
0
|
||||
2342
|
||||
2342
|
||||
66386
|
||||
2342
|
||||
2342
|
||||
2342
|
||||
168624
|
||||
6639
|
||||
2342
|
||||
2342
|
||||
2342
|
||||
2342
|
||||
2342
|
||||
2342
|
||||
2342
|
||||
2342
|
||||
2342
|
||||
2342
|
||||
2342
|
7
src/tests/test_Length
Executable file
7
src/tests/test_Length
Executable file
@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
regfile=`cat ${srcdir}/tests/regfiles/Length`
|
||||
output=`./check_Length`
|
||||
|
||||
test "$regfile" = "$output"
|
||||
exit $?
|
Loading…
x
Reference in New Issue
Block a user