| OLD | NEW |
| (Empty) | |
| 1 # Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import unittest |
| 6 |
| 7 from crash.project import Project |
| 8 from crash.stacktrace import StackFrame |
| 9 from libs.gitiles.change_log import FileChangeInfo |
| 10 from libs.gitiles.diff import ChangeType |
| 11 |
| 12 |
| 13 class ProjectTest(unittest.TestCase): |
| 14 """Tests ``Project`` class.""" |
| 15 |
| 16 def setUp(self): |
| 17 super(ProjectTest, self).setUp() |
| 18 self.android_project = Project('android_os', |
| 19 path_regexes=['.*googleplex-android/'], |
| 20 function_regexes=['android.']) |
| 21 self.chromium_project = Project('chromium', |
| 22 function_regexes=['org.chromium'], |
| 23 host_directories=['src/']) |
| 24 |
| 25 def testMatchesStackFrame(self): |
| 26 """Tests that ``MatchesStackFrame`` matches frames.""" |
| 27 chromium_frame = StackFrame(0, 'src/', 'func', 'f.cc', 'src/f.cc', [2]) |
| 28 self.assertTrue(self.chromium_project.MatchesStackFrame(chromium_frame)) |
| 29 self.assertFalse(self.android_project.MatchesStackFrame(chromium_frame)) |
| 30 |
| 31 android_frame1 = StackFrame(0, '', 'android.a', 'comp1.cc', |
| 32 'src/comp1.cc', [2]) |
| 33 self.assertFalse(self.chromium_project.MatchesStackFrame(android_frame1)) |
| 34 self.assertTrue(self.android_project.MatchesStackFrame(android_frame1)) |
| 35 |
| 36 android_frame2 = StackFrame(0, '', 'func', 'comp2.cc', |
| 37 'googleplex-android/src/comp2.cc', [32]) |
| 38 self.assertFalse(self.chromium_project.MatchesStackFrame(android_frame2)) |
| 39 self.assertTrue(self.android_project.MatchesStackFrame(android_frame2)) |
| 40 |
| 41 def testMatchesTouchedFile(self): |
| 42 """Tests that ``MatchesTouchedFile`` matches touched files correctly.""" |
| 43 touched_file = FileChangeInfo(ChangeType.MODIFY, 'a/b.h', 'a/b.h') |
| 44 self.assertFalse(self.chromium_project.MatchesTouchedFile( |
| 45 'dummy', touched_file.changed_path)) |
| 46 self.assertTrue(self.chromium_project.MatchesTouchedFile( |
| 47 'src/', touched_file.changed_path)) |
| 48 |
| 49 deleted_file = FileChangeInfo(ChangeType.DELETE, 'a/b.h', None) |
| 50 self.assertTrue(self.chromium_project.MatchesTouchedFile( |
| 51 'src/', deleted_file.changed_path)) |
| 52 self.assertFalse(self.android_project.MatchesTouchedFile( |
| 53 'src/', deleted_file.changed_path)) |
| 54 |
| 55 add_file = FileChangeInfo(ChangeType.ADD, None, 'googleplex-android/b.java') |
| 56 self.assertTrue(self.android_project.MatchesTouchedFile( |
| 57 'android_path/', add_file.changed_path)) |
| 58 |
| 59 def testGetName(self): |
| 60 """Tests ``GetName`` method return the project or subproject name.""" |
| 61 self.assertEquals(self.android_project.GetName(), self.android_project.name) |
| 62 self.assertEquals(self.chromium_project.GetName(), |
| 63 self.chromium_project.name) |
| 64 self.assertEquals(self.chromium_project.GetName('src/'), 'chromium') |
| 65 self.assertEquals(self.chromium_project.GetName('src/dep'), 'chromium-dep') |
| 66 self.assertEquals(self.chromium_project.GetName('dummy/dep'), |
| 67 'chromium-dummy_dep') |
| OLD | NEW |