mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-12-22 04:50:09 +00:00
check more c++11 features
use local browser to test
This commit is contained in:
parent
a9ab233f2b
commit
abb278c3e2
@ -4,10 +4,10 @@ before_install:
|
||||
- sudo add-apt-repository ppa:fontforge/fontforge --yes
|
||||
- sudo add-apt-repository ppa:coolwanglu/pdf2htmlex --yes
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get install -qq libpoppler-dev libpoppler-private-dev libspiro-dev libcairo-dev libpango1.0-dev libfreetype6-dev libltdl-dev libfontforge-dev python-imaging ttfautohint
|
||||
install:
|
||||
- wget 'http://downloads.sourceforge.net/project/wkhtmltopdf/0.12.1/wkhtmltox-0.12.1_linux-precise-amd64.deb' -O wkhtmltox.deb
|
||||
- sudo dpkg -i wkhtmltox.deb
|
||||
- sudo apt-get install -qq libpoppler-dev libpoppler-private-dev libspiro-dev libcairo-dev libpango1.0-dev libfreetype6-dev libltdl-dev libfontforge-dev python-imaging ttfautohint firefox xvfb
|
||||
- export DISPLAY=:99.0
|
||||
- test/start_xvfb.sh
|
||||
- sleep 5
|
||||
before_script:
|
||||
- cmake -DENABLE_SVG=ON .
|
||||
script:
|
||||
|
@ -84,10 +84,20 @@ else()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
|
||||
endif()
|
||||
|
||||
include(CheckCXXCompilerFlag)
|
||||
check_cxx_compiler_flag("${CMAKE_CXX_FLAGS}" CXX0X_SUPPORT)
|
||||
# check the C++11 features we need
|
||||
include(CheckCXXSourceCompiles)
|
||||
check_cxx_source_compiles("
|
||||
#include <vector>
|
||||
int main()
|
||||
{
|
||||
char * ptr = nullptr;
|
||||
std::vector<int> v;
|
||||
auto f = [&](){ for(auto & i : v) ++i; };
|
||||
f();
|
||||
}
|
||||
" CXX0X_SUPPORT)
|
||||
if(NOT CXX0X_SUPPORT)
|
||||
message(FATAL_ERROR "Error: your compiler does not support C++0x, please update it.")
|
||||
message(FATAL_ERROR "Error: your compiler does not support C++0x/C++11, please update it.")
|
||||
endif()
|
||||
|
||||
|
||||
|
1
test/.gitattributes
vendored
Normal file
1
test/.gitattributes
vendored
Normal file
@ -0,0 +1 @@
|
||||
*.pdf binary
|
@ -1,14 +1,18 @@
|
||||
### Dependencies
|
||||
|
||||
- wkhtmltoimage
|
||||
- python2
|
||||
- python2 and packages
|
||||
- Python Imaging Library
|
||||
- Selenium
|
||||
- unittest
|
||||
- Firefox
|
||||
|
||||
### Usage
|
||||
- Run all tests:
|
||||
- `./test.py`
|
||||
- Run selected tests:
|
||||
- `./test.py test_A test_B ...`
|
||||
- Run selected test suites:
|
||||
- `./test.py test_local_browser`
|
||||
- Run selected test case:
|
||||
- `./test.py test_basic_text
|
||||
- Environment variables:
|
||||
- set `P2H_TEST_SAVE_TMP=1` to keep the temporary files
|
||||
- set `P2H_TEST_GEN=1` to generate new reference images instead of comparing with old ones
|
||||
@ -21,6 +25,5 @@
|
||||
- One page only, unless the test case is about multiple pages.
|
||||
- Grayscale only, unless the test case is about colors.
|
||||
- Remove unnecessary elements.
|
||||
- Set proper parameters for cropping in `wkhtml2image_args`.
|
||||
- [Optional] Include the source files that the PDF file is generated from.
|
||||
|
||||
|
2
test/start_xvfb.sh
Executable file
2
test/start_xvfb.sh
Executable file
@ -0,0 +1,2 @@
|
||||
#!/bin/sh
|
||||
/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1280x1920x16
|
17
test/test.py
17
test/test.py
@ -14,6 +14,8 @@ class Common(object):
|
||||
PDF2HTMLEX_PATH = os.path.join(SRC_DIR, 'pdf2htmlEX')
|
||||
|
||||
SAVE_TMP = os.environ.get('P2H_TEST_SAVE_TMP')
|
||||
GENERATING_MODE = os.environ.get('P2H_TEST_GEN')
|
||||
|
||||
CANONICAL_TEMPDIR = '/tmp/pdf2htmlEX_test'
|
||||
|
||||
def setUp(self):
|
||||
@ -83,12 +85,21 @@ if __name__ == '__main__':
|
||||
exit(1)
|
||||
suites = []
|
||||
loader = unittest.TestLoader()
|
||||
test_names = list(map(lambda x: 'T.'+x, sys.argv[1:]))
|
||||
for module_name in ['test_naming', 'test_conversion']:
|
||||
all_modules = ['test_output', 'test_local_browser']
|
||||
test_names = []
|
||||
for name in sys.argv[1:]:
|
||||
if name in all_modules or name.find('.') != -1:
|
||||
test_names.append(name)
|
||||
else:
|
||||
for m in all_modules:
|
||||
test_names.append(m + '.' + name)
|
||||
|
||||
for module_name in all_modules:
|
||||
__import__(module_name)
|
||||
if len(test_names) > 0:
|
||||
for n in test_names:
|
||||
try:
|
||||
suites.append(loader.loadTestsFromNames(test_names, sys.modules[module_name]))
|
||||
suites.append(loader.loadTestsFromName(n, sys.modules[module_name]))
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 12 KiB |
Binary file not shown.
Before Width: | Height: | Size: 3.4 MiB |
Binary file not shown.
Before Width: | Height: | Size: 127 KiB |
@ -3,38 +3,42 @@
|
||||
import unittest
|
||||
import os
|
||||
import subprocess
|
||||
import shutil
|
||||
|
||||
from PIL import Image, ImageChops
|
||||
from selenium import webdriver
|
||||
from test import Common
|
||||
|
||||
class T(Common, unittest.TestCase):
|
||||
GENERATING_MODE = os.environ.get('P2H_TEST_GEN')
|
||||
|
||||
WKHTML2IMAGE = 'wkhtmltoimage'
|
||||
class test_local_browser(Common, unittest.TestCase):
|
||||
TTFAUTOHINT = 'ttfautohint'
|
||||
TEST_DATA_DIR = os.path.join(Common.TEST_DIR, 'test_conversion')
|
||||
TEST_DATA_DIR = os.path.join(Common.TEST_DIR, 'test_local_browser')
|
||||
|
||||
DEFAULT_PDF2HTMLEX_ARGS = [
|
||||
'--external-hint-tool', 'ttfautohint',
|
||||
'--fit-width', 800,
|
||||
'--last-page', 1,
|
||||
'--correct-text-visibility', 1,
|
||||
'--embed', 'fi', # avoid base64 to make it faster
|
||||
]
|
||||
|
||||
DEFAULT_WKHTML2IMAGE_ARGS = [
|
||||
'-f', 'png',
|
||||
'--height', 600,
|
||||
'--width', 800,
|
||||
'--quality', 0,
|
||||
'--quiet'
|
||||
]
|
||||
BROWSER_WIDTH=800
|
||||
BROWSER_HEIGHT=1200
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
subprocess.check_call([cls.WKHTML2IMAGE, '--version'])
|
||||
subprocess.check_call([cls.TTFAUTOHINT, '--version'])
|
||||
exit_code = subprocess.call([cls.TTFAUTOHINT, '--version'])
|
||||
assert (exit_code == 0), 'Cannot execute ' + cls.TTFAUTOHINT
|
||||
cls.browser = webdriver.Firefox()
|
||||
cls.browser.maximize_window()
|
||||
size = cls.browser.get_window_size()
|
||||
assert ((size['width'] >= cls.BROWSER_WIDTH) and (size['height'] >= cls.BROWSER_HEIGHT)), 'Screen is not large enough'
|
||||
cls.browser.set_window_size(cls.BROWSER_WIDTH, cls.BROWSER_HEIGHT)
|
||||
|
||||
def run_test_case(self, filename, pdf2htmlEX_args=[], wkhtml2image_args=[]):
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
cls.browser.quit()
|
||||
|
||||
def run_test_case(self, filename, pdf2htmlEX_args=[]):
|
||||
basefilename, extension = os.path.splitext(filename)
|
||||
htmlfilename = basefilename + '.html'
|
||||
pngfilename = basefilename + '.png'
|
||||
@ -56,21 +60,14 @@ class T(Common, unittest.TestCase):
|
||||
pngfilename_out_fullpath = os.path.join(png_out_dir, pngfilename)
|
||||
pngfilename_raw_fullpath = os.path.join(self.TEST_DATA_DIR, pngfilename)
|
||||
|
||||
wkhtml2image_args = [self.WKHTML2IMAGE] \
|
||||
+ self.DEFAULT_WKHTML2IMAGE_ARGS \
|
||||
+ list(wkhtml2image_args) + [
|
||||
os.path.join(self.cur_output_dir, htmlfilename),
|
||||
pngfilename_out_fullpath
|
||||
]
|
||||
self.generate_image(os.path.join(self.cur_output_dir, htmlfilename), pngfilename_out_fullpath)
|
||||
|
||||
return_code = subprocess.call(list(map(str, wkhtml2image_args)))
|
||||
self.assertEquals(return_code, 0, 'cannot execute ' + self.WKHTML2IMAGE)
|
||||
|
||||
if self.GENERATING_MODE:
|
||||
shutil.copy(pngfilename_out_fullpath, pngfilename_raw_fullpath)
|
||||
else:
|
||||
original_img = Image.open(pngfilename_raw_fullpath)
|
||||
new_img = Image.open(pngfilename_out_fullpath)
|
||||
original_img = Image.open(pngfilename_raw_fullpath)
|
||||
|
||||
diff_img = ImageChops.difference(original_img, new_img);
|
||||
|
||||
@ -81,18 +78,16 @@ class T(Common, unittest.TestCase):
|
||||
diff_img.convert('RGB').save(os.path.join(png_out_dir, basefilename + '.diff.png'))
|
||||
self.fail('PNG files differ')
|
||||
|
||||
def generate_image(self, html_file, png_file):
|
||||
self.browser.get('file://' + html_file)
|
||||
self.browser.save_screenshot(png_file)
|
||||
|
||||
def test_basic_text(self):
|
||||
self.run_test_case('basic_text.pdf',
|
||||
wkhtml2image_args=[
|
||||
'--crop-x', 180,
|
||||
'--crop-y', 150,
|
||||
'--crop-w', 220,
|
||||
'--crop-h', 260
|
||||
])
|
||||
self.run_test_case('basic_text.pdf')
|
||||
|
||||
def test_geneve_1564(self):
|
||||
self.run_test_case('geneve_1564.pdf', wkhtml2image_args=['--height', 1100])
|
||||
self.run_test_case('geneve_1564.pdf')
|
||||
|
||||
def test_text_visibility(self):
|
||||
self.run_test_case('text_visibility.pdf', wkhtml2image_args=['--height', 1200])
|
||||
self.run_test_case('text_visibility.pdf')
|
||||
|
BIN
test/test_local_browser/basic_text.png
Normal file
BIN
test/test_local_browser/basic_text.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
BIN
test/test_local_browser/geneve_1564.png
Normal file
BIN
test/test_local_browser/geneve_1564.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 369 KiB |
BIN
test/test_local_browser/text_visibility.png
Normal file
BIN
test/test_local_browser/text_visibility.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 108 KiB |
@ -1,16 +1,18 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Test --split-page and --page-filename
|
||||
# Test output files
|
||||
|
||||
import unittest
|
||||
import os
|
||||
|
||||
from test import Common
|
||||
|
||||
class T(Common, unittest.TestCase):
|
||||
class test_output(Common, unittest.TestCase):
|
||||
def run_test_case(self, input_file, expected_output_files, args=[]):
|
||||
if self.GENERATING_MODE:
|
||||
self.skipTest("Skipping test_output test cases in generating mode")
|
||||
args = list(args)
|
||||
args.insert(0, os.path.join(self.TEST_DIR, 'test_naming', input_file))
|
||||
args.insert(0, os.path.join(self.TEST_DIR, 'test_output', input_file))
|
||||
self.assertItemsEqual(self.run_pdf2htmlEX(args)['output_files'], expected_output_files)
|
||||
|
||||
def test_generate_single_html_default_name_single_page_pdf(self):
|
Loading…
Reference in New Issue
Block a user