1#!/usr/bin/env python 2# Copyright (c) 2012 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'''Unit test that checks preprocessing of files. 7 Tests preprocessing by adding having the preprocessor 8 provide the actual rctext data. 9''' 10 11import os 12import sys 13if __name__ == '__main__': 14 sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) 15 16import unittest 17 18import grit.tool.preprocess_interface 19from grit.tool import rc2grd 20 21 22class PreProcessingUnittest(unittest.TestCase): 23 24 def testPreProcessing(self): 25 tool = rc2grd.Rc2Grd() 26 class DummyOpts(object): 27 verbose = False 28 extra_verbose = False 29 tool.o = DummyOpts() 30 tool.pre_process = 'grit.tool.preprocess_unittest.DummyPreProcessor' 31 result = tool.Process('', '.\resource.rc') 32 33 self.failUnless( 34 result.children[2].children[2].children[0].attrs['name'] == 'DUMMY_STRING_1') 35 36class DummyPreProcessor(grit.tool.preprocess_interface.PreProcessor): 37 def Process(self, rctext, rcpath): 38 rctext = '''STRINGTABLE 39BEGIN 40 DUMMY_STRING_1 "String 1" 41 // Some random description 42 DUMMY_STRING_2 "This text was added during preprocessing" 43END 44 ''' 45 return rctext 46 47if __name__ == '__main__': 48 unittest.main() 49 50