commit 7910502b8e38d0aaa7cb42340c3f04b2aa5f6db0
Author: Georg Baum <[email protected]>
Date: Sun Jul 12 18:08:41 2015 +0200
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.
diff --git a/src/Makefile.am b/src/Makefile.am
index dfc292c..cf25556 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -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
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
index 4b31921..d440bf6 100644
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -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)
+
diff --git a/src/tests/check_Length.cpp b/src/tests/check_Length.cpp
new file mode 100644
index 0000000..8311e45
--- /dev/null
+++ b/src/tests/check_Length.cpp
@@ -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();
+}
diff --git a/src/tests/regfiles/Length b/src/tests/regfiles/Length
new file mode 100644
index 0000000..581ec15
--- /dev/null
+++ b/src/tests/regfiles/Length
@@ -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
diff --git a/src/tests/test_Length b/src/tests/test_Length
new file mode 100755
index 0000000..e4035ba
--- /dev/null
+++ b/src/tests/test_Length
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+regfile=`cat ${srcdir}/tests/regfiles/Length`
+output=`./check_Length`
+
+test "$regfile" = "$output"
+exit $?