| Index: PRESUBMIT_test.py
|
| diff --git a/PRESUBMIT_test.py b/PRESUBMIT_test.py
|
| index a3eef95fbf026a5e2aa0297b57eaa3ec2a48d304..099fab566ec2faec8caea9de558b6c020f9e0180 100755
|
| --- a/PRESUBMIT_test.py
|
| +++ b/PRESUBMIT_test.py
|
| @@ -413,6 +413,181 @@ class InvalidOSMacroNamesTest(unittest.TestCase):
|
| self.assertEqual(0, len(errors))
|
|
|
|
|
| +class InvalidWeakPtrOrderCheck(unittest.TestCase):
|
| + def testForValidWeakPtrOrderBeingLastMember(self):
|
| + mock_input_api = MockInputApi()
|
| + lines_h = ['#include "base/memory/weak_ptr.h"',
|
| + 'class A {',
|
| + ' int a;',
|
| + ' float b;',
|
| + ' char c;',
|
| + '',
|
| + ' //WeakPtrFactory should be last one,',
|
| + ' //all the member variables should appear above it.',
|
| + ' base::WeakPtrFactory<A> weak_factory_;',
|
| + '};']
|
| + mock_file_h = MockFile('something.h', lines_h)
|
| + mock_input_api.files = [mock_file_h]
|
| + errors = PRESUBMIT._CheckForWeakPtrOrder(mock_input_api, MockOutputApi())
|
| + self.assertEqual(0, len(errors))
|
| +
|
| + def testForValidWeakPtrOrderBeingMemberBeforeDisallowMacro(self):
|
| + mock_input_api = MockInputApi()
|
| + lines_h = ['#include "base/memory/weak_ptr.h"',
|
| + 'class A {',
|
| + ' int a;',
|
| + ' float b;',
|
| + ' char c;',
|
| + '',
|
| + ' //WeakPtrFactory should be last one,',
|
| + ' //all the member variables should appear above it.',
|
| + ' base::WeakPtrFactory<A> weak_factory_;',
|
| + ' DISALLOW_COPY_AND_ASSIGN(A);',
|
| + '};']
|
| + mock_file_h = MockFile('something.h', lines_h)
|
| + mock_input_api.files = [mock_file_h]
|
| + errors = PRESUBMIT._CheckForWeakPtrOrder(mock_input_api, MockOutputApi())
|
| + self.assertEqual(0, len(errors))
|
| +
|
| + def testForValidWeakPtrOrderNestedWeakPtrMember(self):
|
| + mock_input_api = MockInputApi()
|
| + lines_h = ['#include "base/memory/weak_ptr.h"',
|
| + 'class A {',
|
| + ' int a;',
|
| + ' float b;',
|
| + ' char c;',
|
| + '',
|
| + ' //WeakPtrFactory should be last one,',
|
| + ' //all the member variables should appear above it.',
|
| + ' base::WeakPtrFactory<A> weak_factory_;',
|
| + ' base::WeakPtrFactory<A> weak_factory_1;',
|
| + ' DISALLOW_COPY_AND_ASSIGN(A);',
|
| + '};']
|
| + mock_file_h = MockFile('something.h', lines_h)
|
| + mock_input_api.files = [mock_file_h]
|
| + errors = PRESUBMIT._CheckForWeakPtrOrder(mock_input_api, MockOutputApi())
|
| + self.assertEqual(0, len(errors))
|
| +
|
| + def testForInvalidWeakPtrOrderBeingFirstMember(self):
|
| + mock_input_api = MockInputApi()
|
| + lines_cc = ['#include "base/memory/weak_ptr.h"',
|
| + 'class A {',
|
| + ' //WeakPtrFactory should be last one,',
|
| + ' //all the member variables should appear above it.',
|
| + ' base::WeakPtrFactory<A> weak_factory_;',
|
| + '',
|
| + ' int a;',
|
| + ' float b;',
|
| + ' char c;',
|
| + '',
|
| + ' DISALLOW_COPY_AND_ASSIGN(A);',
|
| + '};']
|
| + mock_file_cc = MockFile('something.cc', lines_cc)
|
| + mock_input_api.files = [mock_file_cc]
|
| + errors = PRESUBMIT._CheckForWeakPtrOrder(mock_input_api, MockOutputApi())
|
| + self.assertEqual(1, len(errors))
|
| +
|
| + def testForInvalidWeakPtrOrderBeingInMiddle(self):
|
| + mock_input_api = MockInputApi()
|
| + lines_cpp = ['#include "base/memory/weak_ptr.h"',
|
| + 'class A {',
|
| + ' int a;',
|
| + ' float b;',
|
| + '',
|
| + ' //WeakPtrFactory should be last one,',
|
| + ' //all the member variables should appear above it.',
|
| + ' base::WeakPtrFactory<A> weak_factory_;',
|
| + '',
|
| + ' char c;',
|
| + ' long d;',
|
| + '',
|
| + ' //WeakPtrFactory should be last one,',
|
| + ' //all the member variables should appear above it.',
|
| + ' base::WeakPtrFactory<A> weak_factory_1;',
|
| + ' DISALLOW_COPY_AND_ASSIGN(A);',
|
| + '};']
|
| + mock_file_cpp = MockFile('something.cpp', lines_cpp)
|
| + mock_input_api.files = [mock_file_cpp]
|
| + errors = PRESUBMIT._CheckForWeakPtrOrder(mock_input_api, MockOutputApi())
|
| + self.assertEqual(1, len(errors))
|
| +
|
| + def testForInvalidWeakPtrOrderVaribleAfterWeakptr(self):
|
| + mock_input_api = MockInputApi()
|
| + lines_mm = ['#include "base/memory/weak_ptr.h"',
|
| + 'class A {',
|
| + ' int a;',
|
| + ' float b;',
|
| + '',
|
| + ' //WeakPtrFactory should be last one,',
|
| + ' //all the member variables should appear above it.',
|
| + ' base::WeakPtrFactory<A> weak_factory_;',
|
| + ' char c;',
|
| + ' DISALLOW_COPY_AND_ASSIGN(A);',
|
| + '};']
|
| + mock_file_mm = MockFile('something.mm', lines_mm)
|
| + mock_input_api.files = [mock_file_mm]
|
| + errors = PRESUBMIT._CheckForWeakPtrOrder(mock_input_api, MockOutputApi())
|
| + self.assertEqual(1, len(errors))
|
| +
|
| + def testForInvalidWeakPtrOrderMultipleFiles(self):
|
| + mock_input_api = MockInputApi()
|
| + lines_cc = ['#include "base/memory/weak_ptr.h"',
|
| + 'class B {',
|
| + ' //WeakPtrFactory should be last one,',
|
| + ' //all the member variables should appear above it.',
|
| + ' base::WeakPtrFactory<B> weak_factory_;',
|
| + '',
|
| + ' int a;',
|
| + ' float b;',
|
| + ' char c;',
|
| + ' DISALLOW_COPY_AND_ASSIGN(B);',
|
| + '};']
|
| + lines_cpp = ['#include "base/memory/weak_ptr.h"',
|
| + 'class C {',
|
| + ' int a;',
|
| + ' float b;',
|
| + '',
|
| + ' //WeakPtrFactory should be last one,',
|
| + ' //all the member variables should appear above it.',
|
| + ' base::WeakPtrFactory<C> weak_factory_;',
|
| + ' char c;',
|
| + ' DISALLOW_COPY_AND_ASSIGN(C);',
|
| + '};']
|
| + lines_h = ['#include "base/memory/weak_ptr.h"',
|
| + 'class A {',
|
| + ' int a;',
|
| + ' float b;',
|
| + ' char c;',
|
| + '',
|
| + ' //WeakPtrFactory should be last one,',
|
| + ' //all the member variables should appear above it.',
|
| + ' base::WeakPtrFactory<A> weak_factory_;',
|
| + ' DISALLOW_COPY_AND_ASSIGN(A);',
|
| + '};']
|
| + lines_mm = ['#include "base/memory/weak_ptr.h"',
|
| + 'class D {',
|
| + ' int a;',
|
| + ' float b;',
|
| + '',
|
| + ' //WeakPtrFactory should be last one,',
|
| + ' //all the member variables should appear above it.',
|
| + ' base::WeakPtrFactory<D> weak_factory_;',
|
| + ' char c;',
|
| + ' long abc;',
|
| + ' DISALLOW_COPY_AND_ASSIGN(D);',
|
| + '};']
|
| + mock_file_cc = MockFile('something.cc', lines_cc)
|
| + mock_file_cpp = MockFile('something.cpp', lines_cpp)
|
| + mock_file_h = MockFile('something.h', lines_h)
|
| + mock_file_mm = MockFile('something.mm', lines_mm)
|
| + mock_input_api.files = [mock_file_cc,
|
| + mock_file_cpp,
|
| + mock_file_h,
|
| + mock_file_mm]
|
| + errors = PRESUBMIT._CheckForWeakPtrOrder(mock_input_api, MockOutputApi())
|
| + self.assertEqual(1, len(errors))
|
| +
|
| +
|
| class InvalidIfDefinedMacroNamesTest(unittest.TestCase):
|
| def testInvalidIfDefinedMacroNames(self):
|
| lines = ['#if defined(TARGET_IPHONE_SIMULATOR)',
|
|
|