Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
PRESUBMIT_test.py
Go to the documentation of this file.
1
#!/usr/bin/env python3
2
# Copyright 2020 The PDFium Authors
3
# Use of this source code is governed by a BSD-style license that can be
4
# found in the LICENSE file.
5
6
import
unittest
7
8
import
PRESUBMIT
9
from
PRESUBMIT_test_mocks
import
MockInputApi, MockOutputApi, MockFile
10
11
12
class
BannedTypeCheckTest
(unittest.TestCase):
13
14
def
testBannedCppFunctions
(self):
15
input_api =
MockInputApi
()
16
input_api.files = [
17
MockFile
(
'some/cpp/problematic/file.cc'
, [
'using namespace std;'
]),
18
MockFile
(
'third_party/some/cpp/problematic/file.cc'
,
19
[
'using namespace std;'
]),
20
MockFile
(
'some/cpp/ok/file.cc'
, [
'using std::string;'
]),
21
MockFile
(
'some/cpp/nocheck/file.cc'
,
22
[
'using namespace std; // nocheck'
]),
23
MockFile
(
'some/cpp/comment/file.cc'
,
24
[
' // A comment about `using namespace std;`'
]),
25
MockFile
(
'some/cpp/v8/get-current.cc'
, [
'v8::Isolate::GetCurrent()'
]),
26
MockFile
(
'some/cpp/v8/try-get-current.cc'
,
27
[
'v8::Isolate::TryGetCurrent()'
]),
28
]
29
30
results =
PRESUBMIT._CheckNoBannedFunctions
(input_api,
MockOutputApi
())
31
32
# There are no warnings to test, so add an empty warning to keep the test
33
# extendable for the future. This block can be removed once warnings are
34
# added.
35
self.assertEqual(1, len(results))
36
results.insert(0,
MockOutputApi
().PresubmitPromptWarning(
''
))
37
38
# warnings are results[0], errors are results[1]
39
self.assertEqual(2, len(results))
40
self.assertTrue(
'some/cpp/problematic/file.cc'
in
results[1].message)
41
self.assertFalse(
42
'third_party/some/cpp/problematic/file.cc'
in
results[1].message)
43
self.assertFalse(
'some/cpp/ok/file.cc'
in
results[1].message)
44
self.assertFalse(
'some/cpp/nocheck/file.cc'
in
results[0].message)
45
self.assertFalse(
'some/cpp/nocheck/file.cc'
in
results[1].message)
46
self.assertFalse(
'some/cpp/comment/file.cc'
in
results[0].message)
47
self.assertFalse(
'some/cpp/comment/file.cc'
in
results[1].message)
48
self.assertTrue(
'some/cpp/v8/get-current.cc'
in
results[1].message)
49
self.assertTrue(
'some/cpp/v8/try-get-current.cc'
in
results[1].message)
50
51
52
class
CheckChangeOnUploadTest
(unittest.TestCase):
53
54
def
testCheckPngNames
(self):
55
correct_paths = [
56
'test_expected.pdf.0.png'
,
57
'test_expected_win.pdf.1.png'
,
58
'test_expected_agg.pdf.3.png'
,
59
'test_expected_agg_linux.pdf.3.png'
,
60
'test_expected_skia.pdf.2.png'
,
61
'test_expected_skia_mac.pdf.4.png'
,
62
'test_expected_gdi_agg.pdf.3.png'
,
63
'test_expected_gdi_agg_win.pdf.4.png'
,
64
'test_expected_gdi_skia.pdf.10.png'
,
65
'test_expected_gdi_skia_linux.pdf.5.png'
,
66
'test_expected_gdi.pdf.99.png'
,
67
'test_expected_gdi_mac.pdf.0.png'
,
68
'notpng.cc'
,
# Check will be skipped for non-PNG files
69
]
70
wrong_paths = [
71
'expected.pdf.0.png'
,
# Missing '_expected'
72
'test1_expected.0.png'
,
# Missing '.pdf'
73
'test2_expected.pdf.png'
,
# Missing page number
74
'test3_expected.pdf.x.png'
,
# Wrong character for page number
75
'test4_expected_agg_gdi.pdf.0.png'
,
# Wrong order of keywords
76
'test4_expected_linux_agg.pdf.0.png'
,
# Wrong order of keywords
77
'test4_expected_mac_skia.pdf.0.png'
,
# Wrong order of keywords
78
'test4_expected_skia_gdi.pdf.0.png'
,
# Wrong order of keywords
79
'test5_expected_useskia.pdf.0.png'
,
# Wrong keyword
80
'test6_expected_win_mac.pdf.0.png'
,
# Too many platforms
81
'test7_expected_agg_skia.pdf.0.png'
,
# Too many renderers
82
]
83
mock_input_api =
MockInputApi
()
84
mock_output_api =
MockOutputApi
()
85
mock_input_api.files = map(MockFile, correct_paths + wrong_paths)
86
errors =
list
(
87
map(str,
PRESUBMIT._CheckPngNames
(mock_input_api, mock_output_api)))
88
89
self.assertEqual(len(wrong_paths), len(errors))
90
self.assertFalse(
'notpng.cc'
in
errors[0])
91
for
path, error
in
zip
(wrong_paths, errors):
92
self.assertIn(path, error)
93
94
95
if
__name__ ==
'__main__'
:
96
unittest.main()
PRESUBMIT_test.BannedTypeCheckTest
Definition
PRESUBMIT_test.py:12
PRESUBMIT_test.BannedTypeCheckTest.testBannedCppFunctions
testBannedCppFunctions(self)
Definition
PRESUBMIT_test.py:14
PRESUBMIT_test.CheckChangeOnUploadTest
Definition
PRESUBMIT_test.py:52
PRESUBMIT_test.CheckChangeOnUploadTest.testCheckPngNames
testCheckPngNames(self)
Definition
PRESUBMIT_test.py:54
PRESUBMIT_test_mocks.MockFile
Definition
PRESUBMIT_test_mocks.py:54
PRESUBMIT_test_mocks.MockInputApi
Definition
PRESUBMIT_test_mocks.py:8
PRESUBMIT_test_mocks.MockOutputApi
Definition
PRESUBMIT_test_mocks.py:24
PRESUBMIT._CheckNoBannedFunctions
_CheckNoBannedFunctions(input_api, output_api)
Definition
PRESUBMIT.py:103
PRESUBMIT._CheckPngNames
_CheckPngNames(input_api, output_api)
Definition
PRESUBMIT.py:451
zip
bool zip()
Definition
process.cpp:6
list
QList< int > list
[14]
Definition
src_concurrent_qtconcurrentfilter.cpp:140
qtwebengine
src
3rdparty
chromium
third_party
pdfium
PRESUBMIT_test.py
Generated on
for Qt by
1.18.0