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 import unittest 7 8 from cpp_util import ( 9 Classname, CloseNamespace, GenerateIfndefName, OpenNamespace) 10 11 class CppUtilTest(unittest.TestCase): 12 def testClassname(self): 13 self.assertEquals('Permissions', Classname('permissions')) 14 self.assertEquals('UpdateAllTheThings', 15 Classname('updateAllTheThings')) 16 self.assertEquals('Aa_Bb_Cc', Classname('aa.bb.cc')) 17 18 def testNamespaceDeclaration(self): 19 self.assertEquals('namespace foo {', 20 OpenNamespace('foo').Render()) 21 self.assertEquals('} // namespace foo', 22 CloseNamespace('foo').Render()) 23 24 self.assertEquals( 25 'namespace extensions {\n' 26 'namespace foo {', 27 OpenNamespace('extensions::foo').Render()) 28 self.assertEquals( 29 '} // namespace foo\n' 30 '} // namespace extensions', 31 CloseNamespace('extensions::foo').Render()) 32 33 self.assertEquals( 34 'namespace extensions {\n' 35 'namespace gen {\n' 36 'namespace api {', 37 OpenNamespace('extensions::gen::api').Render()) 38 self.assertEquals( 39 '} // namespace api\n' 40 '} // namespace gen\n' 41 '} // namespace extensions', 42 CloseNamespace('extensions::gen::api').Render()) 43 44 self.assertEquals( 45 'namespace extensions {\n' 46 'namespace gen {\n' 47 'namespace api {\n' 48 'namespace foo {', 49 OpenNamespace('extensions::gen::api::foo').Render()) 50 self.assertEquals( 51 '} // namespace foo\n' 52 '} // namespace api\n' 53 '} // namespace gen\n' 54 '} // namespace extensions', 55 CloseNamespace('extensions::gen::api::foo').Render()) 56 57 def testGenerateIfndefName(self): 58 self.assertEquals('FOO_BAR_BAZ_H__', GenerateIfndefName('foo\\bar\\baz.h')) 59 self.assertEquals('FOO_BAR_BAZ_H__', GenerateIfndefName('foo/bar/baz.h')) 60 61 62 if __name__ == '__main__': 63 unittest.main() 64