patch_orderfile_unittest.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/env vpython3
  2. # Copyright 2015 The Chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. import unittest
  6. import patch_orderfile
  7. import symbol_extractor
  8. class TestPatchOrderFile(unittest.TestCase):
  9. def testRemoveSuffixes(self):
  10. no_clone = 'this.does.not.contain.clone'
  11. self.assertEquals(no_clone, patch_orderfile.RemoveSuffixes(no_clone))
  12. with_clone = 'this.does.contain.clone.'
  13. self.assertEquals(
  14. 'this.does.contain', patch_orderfile.RemoveSuffixes(with_clone))
  15. with_part = 'this.is.a.part.42'
  16. self.assertEquals(
  17. 'this.is.a', patch_orderfile.RemoveSuffixes(with_part))
  18. def testUniqueGenerator(self):
  19. @patch_orderfile._UniqueGenerator
  20. def TestIterator():
  21. yield 1
  22. yield 2
  23. yield 1
  24. yield 3
  25. self.assertEqual(list(TestIterator()), [1,2,3])
  26. def testMaxOutlinedIndex(self):
  27. self.assertEquals(7, patch_orderfile._GetMaxOutlinedIndex(
  28. {'OUTLINED_FUNCTION_{}'.format(idx): None
  29. for idx in [1, 2, 3, 7]}))
  30. self.assertRaises(AssertionError, patch_orderfile._GetMaxOutlinedIndex,
  31. {'OUTLINED_FUNCTION_{}'.format(idx): None
  32. for idx in [1, 200, 3, 11]})
  33. self.assertEquals(None, patch_orderfile._GetMaxOutlinedIndex(
  34. {'a': None, 'b': None}))
  35. def testPatchedSymbols(self):
  36. # From input symbols a b c d, symbols a and d match themselves, symbol
  37. # b matches b and x, and symbol c is missing.
  38. self.assertEquals(list('abxd'),
  39. list(patch_orderfile._PatchedSymbols(
  40. {'a': 'a', 'b': 'bx', 'd': 'd'},
  41. 'abcd', None)))
  42. def testPatchedSymbolsWithOutlining(self):
  43. # As above, but add outlined functions at the end. The aliased outlined
  44. # function should be ignored.
  45. self.assertEquals(
  46. list('abd') + ['OUTLINED_FUNCTION_{}'.format(i) for i in range(5)],
  47. list(
  48. patch_orderfile._PatchedSymbols(
  49. {
  50. 'a': 'a',
  51. 'b': ['b', 'OUTLINED_FUNCTION_4'],
  52. 'd': 'd'
  53. }, ['a', 'b', 'OUTLINED_FUNCTION_2', 'c', 'd'], 2)))
  54. if __name__ == '__main__':
  55. unittest.main()