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

Side by Side Diff: Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py

Issue 23654034: 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: 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 unified diff | Download patch
OLDNEW
1 # -*- coding: utf-8; -*- 1 # -*- coding: utf-8; -*-
2 # 2 #
3 # Copyright (C) 2011 Google Inc. All rights reserved. 3 # Copyright (C) 2011 Google Inc. All rights reserved.
4 # Copyright (C) 2009 Torch Mobile Inc. 4 # Copyright (C) 2009 Torch Mobile Inc.
5 # Copyright (C) 2009 Apple Inc. All rights reserved. 5 # Copyright (C) 2009 Apple Inc. All rights reserved.
6 # Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org) 6 # Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org)
7 # 7 #
8 # Redistribution and use in source and binary forms, with or without 8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions are 9 # modification, are permitted provided that the following conditions are
10 # met: 10 # met:
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 def test_runtime_rtti(self): 757 def test_runtime_rtti(self):
758 statement = 'int* x = dynamic_cast<int*>(&foo);' 758 statement = 'int* x = dynamic_cast<int*>(&foo);'
759 error_message = ( 759 error_message = (
760 'Do not use dynamic_cast<>. If you need to cast within a class ' 760 'Do not use dynamic_cast<>. If you need to cast within a class '
761 'hierarchy, use static_cast<> to upcast. Google doesn\'t support ' 761 'hierarchy, use static_cast<> to upcast. Google doesn\'t support '
762 'RTTI. [runtime/rtti] [5]') 762 'RTTI. [runtime/rtti] [5]')
763 # dynamic_cast is disallowed in most files. 763 # dynamic_cast is disallowed in most files.
764 self.assert_language_rules_check('foo.cpp', statement, error_message) 764 self.assert_language_rules_check('foo.cpp', statement, error_message)
765 self.assert_language_rules_check('foo.h', statement, error_message) 765 self.assert_language_rules_check('foo.h', statement, error_message)
766 766
767 # Test for static_cast readability. 767 # Tests for static_cast readability.
768 def test_static_cast_readability(self): 768 def test_use_toFoo_readability(self):
769 self.assert_lint( 769 self.assert_lint(
770 'Text* x = static_cast<Text*>(foo);', 770 'Text* x = static_cast<Text*>(foo);',
771 'Consider using toText helper function in WebCore/dom/Text.h ' 771 'static_cast of class objects is not allowed. Use toText defined in Text.h.'
772 'instead of static_cast<Text*>' 772 ' [readability/check] [4]')
773
774 def test_create_and_use_toFoo_readability(self):
775 self.assert_lint(
776 'HTMLButtonElement* x = static_cast<HTMLButtonElement*>(foo);',
777 'static_cast of class objects is not allowed. Add toHTMLButtonElemen t in HTMLButtonElement.h and use it instead.'
773 ' [readability/check] [4]') 778 ' [readability/check] [4]')
774 779
775 # We cannot test this functionality because of difference of 780 # We cannot test this functionality because of difference of
776 # function definitions. Anyway, we may never enable this. 781 # function definitions. Anyway, we may never enable this.
777 # 782 #
778 # # Test for unnamed arguments in a method. 783 # # Test for unnamed arguments in a method.
779 # def test_check_for_unnamed_params(self): 784 # def test_check_for_unnamed_params(self):
780 # message = ('All parameters should be named in a function' 785 # message = ('All parameters should be named in a function'
781 # ' [readability/function] [3]') 786 # ' [readability/function] [3]')
782 # self.assert_lint('virtual void A(int*) const;', message) 787 # self.assert_lint('virtual void A(int*) const;', message)
(...skipping 4368 matching lines...) Expand 10 before | Expand all | Expand 10 after
5151 def test_ne(self): 5156 def test_ne(self):
5152 """Test __ne__ inequality function.""" 5157 """Test __ne__ inequality function."""
5153 checker1 = self._checker() 5158 checker1 = self._checker()
5154 checker2 = self._checker() 5159 checker2 = self._checker()
5155 5160
5156 # != calls __ne__. 5161 # != calls __ne__.
5157 # By default, __ne__ always returns true on different objects. 5162 # By default, __ne__ always returns true on different objects.
5158 # Thus, just check the distinguishing case to verify that the 5163 # Thus, just check the distinguishing case to verify that the
5159 # code defines __ne__. 5164 # code defines __ne__.
5160 self.assertFalse(checker1 != checker2) 5165 self.assertFalse(checker1 != checker2)
OLDNEW
« Tools/Scripts/webkitpy/style/checkers/cpp.py ('K') | « 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