Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2072)

Unified Diff: Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py

Issue 24406002: Add code style check error for using static_cast instead of toFoo function. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Corrected base_dir to Source to avoid searching header file in LayoutTests Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Tools/Scripts/webkitpy/style/checkers/cpp.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py
diff --git a/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py b/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py
index ab53f175ab62f010f666f6647fd8fee0791511c1..a7442044c83d0f5f6689af1509b516f9cc4ac6e7 100644
--- a/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py
+++ b/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py
@@ -310,6 +310,12 @@ class CppStyleTestBase(unittest.TestCase):
unit_test_config = {cpp_style.INCLUDE_IO_INJECTION_KEY: io}
return self.perform_lint(code, filename, basic_error_rules, unit_test_config)
+ def perform_avoid_static_cast_of_objects(self, code, filename='foo.cpp', io=codecs):
+ basic_error_rules = ('-',
+ '+runtime/casting')
+ unit_test_config = {cpp_style.INCLUDE_IO_INJECTION_KEY: io}
+ return self.perform_lint(code, filename, basic_error_rules, unit_test_config)
+
# Perform lint and compare the error message with "expected_message".
def assert_lint(self, code, expected_message, file_name='foo.cpp'):
self.assertEqual(expected_message, self.perform_single_line_lint(code, file_name))
@@ -764,13 +770,24 @@ class CppStyleTest(CppStyleTestBase):
self.assert_language_rules_check('foo.cpp', statement, error_message)
self.assert_language_rules_check('foo.h', statement, error_message)
- # Test for static_cast readability.
- def test_static_cast_readability(self):
- self.assert_lint(
- 'Text* x = static_cast<Text*>(foo);',
- 'Consider using toText helper function in WebCore/dom/Text.h '
- 'instead of static_cast<Text*>'
- ' [readability/check] [4]')
+ # Tests for static_cast readability.
+ def test_static_cast_on_objects_with_toFoo(self):
+ mock_header_contents = ['inline Foo* toFoo(Bar* bar)']
+ message = self.perform_avoid_static_cast_of_objects(
+ 'Foo* x = static_cast<Foo*>(bar);',
+ filename='casting.cpp',
+ io=MockIo(mock_header_contents))
+ self.assertEqual(message, 'static_cast of class objects is not allowed. Use toFoo defined in Foo.h.'
+ ' [runtime/casting] [4]')
+
+ def test_static_cast_on_objects_without_toFoo(self):
+ mock_header_contents = ['inline FooBar* toFooBar(Bar* bar)']
+ message = self.perform_avoid_static_cast_of_objects(
+ 'Foo* x = static_cast<Foo*>(bar);',
+ filename='casting.cpp',
+ io=MockIo(mock_header_contents))
+ self.assertEqual(message, 'static_cast of class objects is not allowed. Add toFoo in Foo.h and use it instead.'
+ ' [runtime/casting] [4]')
# We cannot test this functionality because of difference of
# function definitions. Anyway, we may never enable this.
« no previous file with comments | « Tools/Scripts/webkitpy/style/checkers/cpp.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698