Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Tools / Scripts / webkitpy / style / checkers / cpp_unittest.py
index 6df53da..42ffe18 100644 (file)
@@ -38,7 +38,8 @@
 import os
 import random
 import re
-import webkitpy.thirdparty.unittest2 as unittest
+import unittest
+
 import cpp as cpp_style
 from cpp import CppChecker
 from ..filter import FilterConfiguration
@@ -1601,10 +1602,10 @@ class CppStyleTest(CppStyleTestBase):
             'int foo() const {',
             'Place brace on its own line for function definitions.  [whitespace/braces] [4]')
         self.assert_multi_line_lint(
-            'int foo() const OVERRIDE {',
+            'int foo() override {',
             'Place brace on its own line for function definitions.  [whitespace/braces] [4]')
         self.assert_multi_line_lint(
-            'int foo() OVERRIDE {',
+            'int foo() final {',
             'Place brace on its own line for function definitions.  [whitespace/braces] [4]')
         self.assert_multi_line_lint(
             'int foo() const\n'
@@ -1612,7 +1613,12 @@ class CppStyleTest(CppStyleTestBase):
             '}\n',
             '')
         self.assert_multi_line_lint(
-            'int foo() OVERRIDE\n'
+            'int foo() override\n'
+            '{\n'
+            '}\n',
+            '')
+        self.assert_multi_line_lint(
+            'int foo() final\n'
             '{\n'
             '}\n',
             '')
@@ -1773,6 +1779,15 @@ class CppStyleTest(CppStyleTestBase):
         self.assert_lint('a<Foo*> t <<= *b / &c; // Test', '')
         self.assert_lint('if (a=b == 1)', 'Missing spaces around =  [whitespace/operators] [4]')
         self.assert_lint('a = 1<<20', 'Missing spaces around <<  [whitespace/operators] [3]')
+        self.assert_lint('a = 1>> 20', 'Missing spaces around >>  [whitespace/operators] [3]')
+        self.assert_lint('a = 1 >>20', 'Missing spaces around >>  [whitespace/operators] [3]')
+        self.assert_lint('a = 1>>20', 'Missing spaces around >>  [whitespace/operators] [3]')
+        self.assert_lint('func(OwnPtr<Vector<Foo>>)', '')
+        self.assert_lint('func(OwnPtr<Vector<Foo>> foo)', '')
+        self.assert_lint('func(OwnPtr<HashMap<Foo, Member<Bar>>>)', '')
+        # FIXME: The following test should not show any error.
+        self.assert_lint('func(OwnPtr<HashMap<Foo, Member<Bar\n    >>>)',
+                         'Missing spaces around <  [whitespace/operators] [3]')
         self.assert_lint('if (a = b == 1)', '')
         self.assert_lint('a = 1 << 20', '')
         self.assert_multi_line_lint('#include <sys/io.h>\n', '')
@@ -1900,25 +1915,11 @@ class CppStyleTest(CppStyleTestBase):
         self.assert_lint('printf("\\"%s // In quotes.")', '')
         self.assert_lint('printf("%s", "// In quotes.")', '')
 
-    def test_one_spaces_after_punctuation_in_comments(self):
+    def test_line_ending_in_whitespace(self):
         self.assert_lint('int a; // This is a sentence.',
                          '')
         self.assert_lint('int a; // This is a sentence.  ',
                          'Line ends in whitespace.  Consider deleting these extra spaces.  [whitespace/end_of_line] [4]')
-        self.assert_lint('int a; // This is a sentence. This is a another sentence.',
-                         '')
-        self.assert_lint('int a; // This is a sentence.  This is a another sentence.',
-                         'Should have only a single space after a punctuation in a comment.  [whitespace/comments] [5]')
-        self.assert_lint('int a; // This is a sentence!  This is a another sentence.',
-                         'Should have only a single space after a punctuation in a comment.  [whitespace/comments] [5]')
-        self.assert_lint('int a; // Why did I write this?  This is a another sentence.',
-                         'Should have only a single space after a punctuation in a comment.  [whitespace/comments] [5]')
-        self.assert_lint('int a; // Elementary,  my dear.',
-                         'Should have only a single space after a punctuation in a comment.  [whitespace/comments] [5]')
-        self.assert_lint('int a; // The following should be clear:  Is it?',
-                         'Should have only a single space after a punctuation in a comment.  [whitespace/comments] [5]')
-        self.assert_lint('int a; // Look at the follow semicolon;  I hope this gives an error.',
-                         'Should have only a single space after a punctuation in a comment.  [whitespace/comments] [5]')
 
     def test_space_after_comment_marker(self):
         self.assert_lint('//', '')
@@ -2317,6 +2318,15 @@ class CppStyleTest(CppStyleTestBase):
                 '  [build/header_guard] [5]'),
             error_collector.result_list())
 
+        # Verify that the Chromium-style header guard is allowed as well.
+        error_collector = ErrorCollector(self.assertTrue, header_guard_filter)
+        self.process_file_data('Source/foo/testname.h', 'h',
+                               ['#ifndef BLINK_FOO_TESTNAME_H_',
+                                '#define BLINK_FOO_TESTNAME_H_'],
+                              error_collector)
+        self.assertEqual(0, len(error_collector.result_list()),
+                          error_collector.result_list())
+
     def test_build_printf_format(self):
         self.assert_lint(
             r'printf("\%%d", value);',
@@ -4724,39 +4734,39 @@ class WebKitStyleTest(CppStyleTestBase):
         #    false. Objective-C BOOL values should be written as YES and NO.
         # FIXME: Implement this.
 
-        # 3. Tests for true/false, null/non-null, and zero/non-zero should
-        #    all be done without equality comparisons.
-        self.assert_lint(
-            'if (count == 0)',
-            'Tests for true/false, null/non-null, and zero/non-zero should all be done without equality comparisons.'
-            '  [readability/comparison_to_zero] [5]')
+        # 3. Tests for true/false and null/non-null should be done without
+        #    equality comparisons.
         self.assert_lint_one_of_many_errors_re(
             'if (string != NULL)',
-            r'Tests for true/false, null/non-null, and zero/non-zero should all be done without equality comparisons\.')
+            r'Tests for true/false and null/non-null should be done without equality comparisons\.')
+        self.assert_lint(
+            'if (p == nullptr)',
+            'Tests for true/false and null/non-null should be done without equality comparisons.'
+            '  [readability/comparison_to_boolean] [5]')
         self.assert_lint(
             'if (condition == true)',
-            'Tests for true/false, null/non-null, and zero/non-zero should all be done without equality comparisons.'
-            '  [readability/comparison_to_zero] [5]')
+            'Tests for true/false and null/non-null should be done without equality comparisons.'
+            '  [readability/comparison_to_boolean] [5]')
         self.assert_lint(
             'if (myVariable != /* Why would anyone put a comment here? */ false)',
-            'Tests for true/false, null/non-null, and zero/non-zero should all be done without equality comparisons.'
-            '  [readability/comparison_to_zero] [5]')
+            'Tests for true/false and null/non-null should be done without equality comparisons.'
+            '  [readability/comparison_to_boolean] [5]')
 
-        self.assert_lint(
-            'if (0 /* This comment also looks odd to me. */ != aLongerVariableName)',
-            'Tests for true/false, null/non-null, and zero/non-zero should all be done without equality comparisons.'
-            '  [readability/comparison_to_zero] [5]')
         self.assert_lint_one_of_many_errors_re(
             'if (NULL == thisMayBeNull)',
-            r'Tests for true/false, null/non-null, and zero/non-zero should all be done without equality comparisons\.')
+            r'Tests for true/false and null/non-null should be done without equality comparisons\.')
+        self.assert_lint(
+            'if (nullptr /* funny place for a comment */ == p)',
+            'Tests for true/false and null/non-null should be done without equality comparisons.'
+            '  [readability/comparison_to_boolean] [5]')
         self.assert_lint(
             'if (true != anotherCondition)',
-            'Tests for true/false, null/non-null, and zero/non-zero should all be done without equality comparisons.'
-            '  [readability/comparison_to_zero] [5]')
+            'Tests for true/false and null/non-null should be done without equality comparisons.'
+            '  [readability/comparison_to_boolean] [5]')
         self.assert_lint(
             'if (false == myBoolValue)',
-            'Tests for true/false, null/non-null, and zero/non-zero should all be done without equality comparisons.'
-            '  [readability/comparison_to_zero] [5]')
+            'Tests for true/false and null/non-null should be done without equality comparisons.'
+            '  [readability/comparison_to_boolean] [5]')
 
         self.assert_lint(
             'if (fontType == trueType)',
@@ -4797,6 +4807,12 @@ class WebKitStyleTest(CppStyleTestBase):
             "  [build/using_std] [4]",
             'foo.cpp')
 
+    def test_using_std_swap_ignored(self):
+        self.assert_lint(
+            'using std::swap;',
+            '',
+            'foo.cpp')
+
     def test_max_macro(self):
         self.assert_lint(
             'int i = MAX(0, 1);',