mirror of
https://pdfium.googlesource.com/pdfium
synced 2026-07-30 10:21:46 +08:00
Under certain conditions, FPDF_RenderPage() will render into a CPDF_WindowsRenderDevice directly. Otherwise, it renders into a bitmap first, and then render the bitmap into the CPDF_WindowsRenderDevice. In the latter case, when Skia is the default renderer, the bitmap needs to be un-premultiply before being passed to CPDF_WindowsRenderDevice. The bitmap also does not need to be cleared, like with AGG. Skia renders just fine into the newly created bitmap. Unsuppress several pixel and corpus tests that are rendering better as a result of this change. The new expectation files are using the updated file name scheme from https://pdfium-review.googlesource.com/112092, so update the presubmit to allow these new names. Using test expectation update by rolling DEPS for testing/corpus: https://pdfium.googlesource.com/pdfium_tests/+log/dc2cd9afdd1b..dcc9273d7f2a Bug: pdfium:2080 Change-Id: Icb04c4c7e06b5d44a9007305e73c9ab2f9096573 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/112091 Reviewed-by: Nigi <nigi@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
97 lines
4.0 KiB
Python
Executable File
97 lines
4.0 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# Copyright 2020 The PDFium Authors
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
# found in the LICENSE file.
|
|
|
|
import unittest
|
|
|
|
import PRESUBMIT
|
|
from PRESUBMIT_test_mocks import MockInputApi, MockOutputApi, MockFile
|
|
|
|
|
|
class BannedTypeCheckTest(unittest.TestCase):
|
|
|
|
def testBannedCppFunctions(self):
|
|
input_api = MockInputApi()
|
|
input_api.files = [
|
|
MockFile('some/cpp/problematic/file.cc', ['using namespace std;']),
|
|
MockFile('third_party/some/cpp/problematic/file.cc',
|
|
['using namespace std;']),
|
|
MockFile('some/cpp/ok/file.cc', ['using std::string;']),
|
|
MockFile('some/cpp/nocheck/file.cc',
|
|
['using namespace std; // nocheck']),
|
|
MockFile('some/cpp/comment/file.cc',
|
|
[' // A comment about `using namespace std;`']),
|
|
MockFile('some/cpp/v8/get-current.cc', ['v8::Isolate::GetCurrent()']),
|
|
MockFile('some/cpp/v8/try-get-current.cc',
|
|
['v8::Isolate::TryGetCurrent()']),
|
|
]
|
|
|
|
results = PRESUBMIT._CheckNoBannedFunctions(input_api, MockOutputApi())
|
|
|
|
# There are no warnings to test, so add an empty warning to keep the test
|
|
# extendable for the future. This block can be removed once warnings are
|
|
# added.
|
|
self.assertEqual(1, len(results))
|
|
results.insert(0, MockOutputApi().PresubmitPromptWarning(''))
|
|
|
|
# warnings are results[0], errors are results[1]
|
|
self.assertEqual(2, len(results))
|
|
self.assertTrue('some/cpp/problematic/file.cc' in results[1].message)
|
|
self.assertFalse(
|
|
'third_party/some/cpp/problematic/file.cc' in results[1].message)
|
|
self.assertFalse('some/cpp/ok/file.cc' in results[1].message)
|
|
self.assertFalse('some/cpp/nocheck/file.cc' in results[0].message)
|
|
self.assertFalse('some/cpp/nocheck/file.cc' in results[1].message)
|
|
self.assertFalse('some/cpp/comment/file.cc' in results[0].message)
|
|
self.assertFalse('some/cpp/comment/file.cc' in results[1].message)
|
|
self.assertTrue('some/cpp/v8/get-current.cc' in results[1].message)
|
|
self.assertTrue('some/cpp/v8/try-get-current.cc' in results[1].message)
|
|
|
|
|
|
class CheckChangeOnUploadTest(unittest.TestCase):
|
|
|
|
def testCheckPngNames(self):
|
|
correct_paths = [
|
|
'test_expected.pdf.0.png',
|
|
'test_expected_win.pdf.1.png',
|
|
'test_expected_agg.pdf.3.png',
|
|
'test_expected_agg_linux.pdf.3.png',
|
|
'test_expected_skia.pdf.2.png',
|
|
'test_expected_skia_mac.pdf.4.png',
|
|
'test_expected_gdi_agg.pdf.3.png',
|
|
'test_expected_gdi_agg_win.pdf.4.png',
|
|
'test_expected_gdi_skia.pdf.10.png',
|
|
'test_expected_gdi_skia_linux.pdf.5.png',
|
|
'test_expected_gdi.pdf.99.png',
|
|
'test_expected_gdi_mac.pdf.0.png',
|
|
'notpng.cc', # Check will be skipped for non-PNG files
|
|
]
|
|
wrong_paths = [
|
|
'expected.pdf.0.png', # Missing '_expected'
|
|
'test1_expected.0.png', # Missing '.pdf'
|
|
'test2_expected.pdf.png', # Missing page number
|
|
'test3_expected.pdf.x.png', # Wrong character for page number
|
|
'test4_expected_agg_gdi.pdf.0.png', # Wrong order of keywords
|
|
'test4_expected_linux_agg.pdf.0.png', # Wrong order of keywords
|
|
'test4_expected_mac_skia.pdf.0.png', # Wrong order of keywords
|
|
'test4_expected_skia_gdi.pdf.0.png', # Wrong order of keywords
|
|
'test5_expected_useskia.pdf.0.png', # Wrong keyword
|
|
'test6_expected_win_mac.pdf.0.png', # Too many platforms
|
|
'test7_expected_agg_skia.pdf.0.png', # Too many renderers
|
|
]
|
|
mock_input_api = MockInputApi()
|
|
mock_output_api = MockOutputApi()
|
|
mock_input_api.files = map(MockFile, correct_paths + wrong_paths)
|
|
errors = list(
|
|
map(str, PRESUBMIT._CheckPngNames(mock_input_api, mock_output_api)))
|
|
|
|
self.assertEqual(len(wrong_paths), len(errors))
|
|
self.assertFalse('notpng.cc' in errors[0])
|
|
for path, error in zip(wrong_paths, errors):
|
|
self.assertIn(path, error)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|