Home | History | Annotate | Download | only in tests
      1 #!/usr/bin/env python
      2 # Copyright (c) 2012 Google Inc.
      3 # All rights reserved.
      4 #
      5 # Redistribution and use in source and binary forms, with or without
      6 # modification, are permitted provided that the following conditions are
      7 # met:
      8 #
      9 #     * Redistributions of source code must retain the above copyright
     10 # notice, this list of conditions and the following disclaimer.
     11 #     * Redistributions in binary form must reproduce the above
     12 # copyright notice, this list of conditions and the following disclaimer
     13 # in the documentation and/or other materials provided with the
     14 # distribution.
     15 #     * Neither the name of Google Inc. nor the names of its
     16 # contributors may be used to endorse or promote products derived from
     17 # this software without specific prior written permission.
     18 #
     19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     20 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     21 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     22 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     23 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30 
     31 """Unit tests for filter_syms.py"""
     32 
     33 import cStringIO
     34 import ntpath
     35 import os
     36 import StringIO
     37 import sys
     38 import unittest
     39 
     40 ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
     41 sys.path.insert(0, os.path.join(ROOT_DIR, '..'))
     42 
     43 # In root
     44 import filter_syms
     45 
     46 class FilterSysmsTest(unittest.TestCase):
     47   def assertParsed(self, input_data, ignored_prefixes, expected):
     48     input_io = cStringIO.StringIO(input_data)
     49     output_io = cStringIO.StringIO()
     50     parser = filter_syms.SymbolFileParser(input_io, output_io,
     51                                           ignored_prefixes, ntpath)
     52     parser.Process()
     53     self.assertEqual(output_io.getvalue(), expected)
     54     
     55   def testDuplicateFiles(self):
     56     """Tests that duplicate files in FILE records are correctly removed and
     57     that Line records are updated."""
     58 
     59     INPUT = \
     60 """MODULE windows x86 111111111111111111111111111111111 module1.pdb
     61 INFO CODE_ID FFFFFFFF module1.exe
     62 FILE 1 foo/../file1_1.cc
     63 FILE 2 bar/../file1_1.cc
     64 FILE 3 baz/../file1_1.cc
     65 FUNC 1000 c 0 Function1_1
     66 1000 8 45 2
     67 1008 4 46 3
     68 100c 4 44 1
     69 """
     70     EXPECTED_OUTPUT = \
     71 """MODULE windows x86 111111111111111111111111111111111 module1.pdb
     72 INFO CODE_ID FFFFFFFF module1.exe
     73 FILE 1 file1_1.cc
     74 FUNC 1000 c 0 Function1_1
     75 1000 8 45 1
     76 1008 4 46 1
     77 100c 4 44 1
     78 """
     79     self.assertParsed(INPUT, [], EXPECTED_OUTPUT)
     80 
     81   def testIgnoredPrefix(self):
     82     """Tests that prefixes in FILE records are correctly removed."""
     83 
     84     INPUT = \
     85 """MODULE windows x86 111111111111111111111111111111111 module1.pdb
     86 INFO CODE_ID FFFFFFFF module1.exe
     87 FILE 1 /src/build/foo/../file1_1.cc
     88 FILE 2 /src/build/bar/../file1_2.cc
     89 FILE 3 /src/build/baz/../file1_2.cc
     90 FUNC 1000 c 0 Function1_1
     91 1000 8 45 2
     92 1008 4 46 3
     93 100c 4 44 1
     94 """
     95     EXPECTED_OUTPUT = \
     96 """MODULE windows x86 111111111111111111111111111111111 module1.pdb
     97 INFO CODE_ID FFFFFFFF module1.exe
     98 FILE 1 file1_1.cc
     99 FILE 2 file1_2.cc
    100 FUNC 1000 c 0 Function1_1
    101 1000 8 45 2
    102 1008 4 46 2
    103 100c 4 44 1
    104 """
    105     IGNORED_PREFIXES = ['\\src\\build\\']
    106     self.assertParsed(INPUT, IGNORED_PREFIXES, EXPECTED_OUTPUT)
    107 
    108   def testIgnoredPrefixesDuplicateFiles(self):
    109     """Tests that de-duplication of FILE records happens BEFORE prefixes
    110     are removed."""
    111 
    112     INPUT = \
    113 """MODULE windows x86 111111111111111111111111111111111 module1.pdb
    114 INFO CODE_ID FFFFFFFF module1.exe
    115 FILE 1 /src/build/foo/../file1_1.cc
    116 FILE 2 /src/build/bar/../file1_2.cc
    117 FILE 3 D:/src/build2/baz/../file1_2.cc
    118 FUNC 1000 c 0 Function1_1
    119 1000 8 45 2
    120 1008 4 46 3
    121 100c 4 44 1
    122 """
    123     EXPECTED_OUTPUT = \
    124 """MODULE windows x86 111111111111111111111111111111111 module1.pdb
    125 INFO CODE_ID FFFFFFFF module1.exe
    126 FILE 1 file1_1.cc
    127 FILE 2 file1_2.cc
    128 FILE 3 file1_2.cc
    129 FUNC 1000 c 0 Function1_1
    130 1000 8 45 2
    131 1008 4 46 3
    132 100c 4 44 1
    133 """
    134     IGNORED_PREFIXES = ['\\src\\build\\', 'D:\\src\\build2\\']
    135     self.assertParsed(INPUT, IGNORED_PREFIXES, EXPECTED_OUTPUT)
    136 
    137 if __name__ == '__main__':
    138   unittest.main()