Home | History | Annotate | Download | only in tests
      1 #!/usr/bin/env python
      2 # Copyright (c) 2013 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 
      6 import cStringIO
      7 import logging
      8 import os
      9 import sys
     10 import textwrap
     11 import unittest
     12 
     13 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
     14 sys.path.insert(0, ROOT_DIR)
     15 
     16 import reduce_debugline
     17 
     18 
     19 class ReduceDebuglineTest(unittest.TestCase):
     20   _DECODED_DEBUGLINE = textwrap.dedent("""\
     21       Decoded dump of debug contents of section .debug_line:
     22 
     23       CU: ../../chrome/service/service_main.cc:
     24       File name                            Line number    Starting address
     25       service_main.cc                               21            0xa41210
     26 
     27       service_main.cc                               24            0xa4141f
     28       service_main.cc                               30            0xa4142b
     29       service_main.cc                               31            0xa4143e
     30 
     31       ../../base/message_loop.h:
     32       message_loop.h                               550            0xa41300
     33 
     34       message_loop.h                               551            0xa41310
     35 
     36       ../../base/logging.h:
     37       logging.h                                    246            0xa41710
     38 
     39       logging.h                                    247            0xa41726
     40 
     41       ../../base/logging.h:
     42       logging.h                                    846            0xa3fd90
     43 
     44       logging.h                                    846            0xa3fda0
     45 
     46       """)
     47 
     48   _EXPECTED_REDUCED_DEBUGLINE = [
     49       (0xa3fd90, '../../base/logging.h'),
     50       (0xa41210, '../../chrome/service/service_main.cc'),
     51       (0xa41300, '../../base/message_loop.h'),
     52       (0xa4141f, '../../chrome/service/service_main.cc'),
     53       (0xa41710, '../../base/logging.h'),
     54       ]
     55 
     56   def test(self):
     57     ranges_dict = reduce_debugline.reduce_decoded_debugline(
     58         cStringIO.StringIO(self._DECODED_DEBUGLINE))
     59     self.assertEqual(self._EXPECTED_REDUCED_DEBUGLINE, ranges_dict)
     60 
     61 
     62 if __name__ == '__main__':
     63   logging.basicConfig(
     64       level=logging.DEBUG if '-v' in sys.argv else logging.ERROR,
     65       format='%(levelname)5s %(filename)15s(%(lineno)3d): %(message)s')
     66   unittest.main()
     67