summaryrefslogtreecommitdiff
path: root/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@nokia.com>2012-02-03 09:55:33 +0100
committerSimon Hausmann <simon.hausmann@nokia.com>2012-02-03 09:55:33 +0100
commitcd44dc59cdfc39534aef4d417e9f3c412e3be139 (patch)
tree8d89889ba95ed6ec9322e733846cc9cce9d7dff1 /Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py
parentd11f84f5b5cdc0d92a08af01b13472fdd5f9acb9 (diff)
downloadqtwebkit-cd44dc59cdfc39534aef4d417e9f3c412e3be139.tar.gz
Imported WebKit commit fce473cb4d55aa9fe9d0b0322a2fffecb731b961 (http://svn.webkit.org/repository/webkit/trunk@106560)
Diffstat (limited to 'Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py')
-rw-r--r--Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py b/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py
index 31a86c5d8..0c5c6041f 100644
--- a/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py
+++ b/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py
@@ -292,6 +292,12 @@ class CppStyleTestBase(unittest.TestCase):
'+readability/pass_ptr')
return self.perform_lint(code, 'test.cpp', basic_error_rules)
+ # Only keep leaky pattern errors.
+ def perform_leaky_pattern_check(self, code):
+ basic_error_rules = ('-',
+ '+runtime/leaky_pattern')
+ return self.perform_lint(code, 'test.cpp', basic_error_rules)
+
# Only include what you use errors.
def perform_include_what_you_use(self, code, filename='foo.h', io=codecs):
basic_error_rules = ('-',
@@ -1709,6 +1715,7 @@ class CppStyleTest(CppStyleTestBase):
def test_operator_methods(self):
self.assert_lint('String operator+(const String&, const String&);', '')
+ self.assert_lint('String operator/(const String&, const String&);', '')
self.assert_lint('bool operator==(const String&, const String&);', '')
self.assert_lint('String& operator-=(const String&, const String&);', '')
self.assert_lint('String& operator+=(const String&, const String&);', '')
@@ -3327,6 +3334,55 @@ class PassPtrTest(CppStyleTestBase):
'')
+class LeakyPatternTest(CppStyleTestBase):
+
+ def assert_leaky_pattern_check(self, code, expected_message):
+ """Check warnings for leaky patterns are as expected.
+
+ Args:
+ code: C++ source code expected to generate a warning message.
+ expected_message: Message expected to be generated by the C++ code.
+ """
+ self.assertEquals(expected_message,
+ self.perform_leaky_pattern_check(code))
+
+ def test_get_dc(self):
+ self.assert_leaky_pattern_check(
+ 'HDC hdc = GetDC(hwnd);',
+ 'Use the class HWndDC instead of calling GetDC to avoid potential '
+ 'memory leaks. [runtime/leaky_pattern] [5]')
+
+ def test_get_dc(self):
+ self.assert_leaky_pattern_check(
+ 'HDC hdc = GetDCEx(hwnd, 0, 0);',
+ 'Use the class HWndDC instead of calling GetDCEx to avoid potential '
+ 'memory leaks. [runtime/leaky_pattern] [5]')
+
+ def test_own_get_dc(self):
+ self.assert_leaky_pattern_check(
+ 'HWndDC hdc(hwnd);',
+ '')
+
+ def test_create_dc(self):
+ self.assert_leaky_pattern_check(
+ 'HDC dc2 = ::CreateDC();',
+ 'Use adoptPtr and OwnPtr<HDC> when calling CreateDC to avoid potential '
+ 'memory leaks. [runtime/leaky_pattern] [5]')
+
+ self.assert_leaky_pattern_check(
+ 'adoptPtr(CreateDC());',
+ '')
+
+ def test_create_compatible_dc(self):
+ self.assert_leaky_pattern_check(
+ 'HDC dc2 = CreateCompatibleDC(dc);',
+ 'Use adoptPtr and OwnPtr<HDC> when calling CreateCompatibleDC to avoid potential '
+ 'memory leaks. [runtime/leaky_pattern] [5]')
+ self.assert_leaky_pattern_check(
+ 'adoptPtr(CreateCompatibleDC(dc));',
+ '')
+
+
class WebKitStyleTest(CppStyleTestBase):
# for http://webkit.org/coding/coding-style.html