#!/usr/bin/python2.4 # Copyright 2009, Google Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following disclaimer # in the documentation and/or other materials provided with the # distribution. # * Neither the name of Google Inc. nor the names of its # contributors may be used to endorse or promote products derived from # this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """Test for ezt_formatter.""" import os import os.path import ezt_formatter import unittest class EZTFormatterUnitTest(unittest.TestCase): def setUp(self): self.formatter = ezt_formatter.EZTFormatter('.') self.java = ezt_formatter.DoxygenJavascriptifier() def tearDown(self): os.rmdir(self.formatter.originals_directory) def CreateContentList(self, inner_content): content = ['[BOILERPLATE - DO NOT EDIT THIS BLOCK]'] content += ['[END OF BOILERPLATE]'] content += inner_content content += ['[BOILERPLATE - DO NOT EDIT THIS BLOCK]'] content += ['[END OF BOILERPLATE]'] return content def testJavascriptify(self): # test numbers content = ['int myInt()'] content += ['myFloat(float f);'] java_content = self.java.Javascriptify(content) self.assertTrue(java_content[0] == 'Number myInt()') self.assertTrue(java_content[1] == 'myFloat(Number f);') # test non-javascript tags content = ['pure test::myVar [pure virtual] Static'] content += ['const void testFunction() [virtual] [pure]'] content += ['testing [explicit]'] content += ['virtual [protected] test;'] content += ['static unsigned int function();'] content += ['const float testing::test()=0'] content += ['protected testing() [pure]'] content += ['[pure]'] java_content = self.java.Javascriptify(content) self.assertTrue(java_content[0] == ' test.myVar Global') self.assertTrue(java_content[1] == ' testFunction() ') self.assertTrue(java_content[2] == 'testing ') self.assertTrue(java_content[3] == ' test;') self.assertTrue(java_content[4] == ' Number function();') self.assertTrue(java_content[5] == ' Number testing.test()') self.assertTrue(java_content[6] == ' testing() ') self.assertFalse(java_content[7]) # test static tag content = ['myTestFunction() [static]'] java_content = self.java.Javascriptify(content) self.assertTrue(java_content[0] == ('myTestFunction() [global function]')) # test null content = ['return NULL;'] java_content = self.java.Javascriptify(content) self.assertTrue(java_content[0] == 'return null;') # test Array content = ['std.vector<test::arrayType> myArray'] java_content = self.java.Javascriptify(content) self.assertTrue(java_content[0] == 'Array myArray') def testJavascriptifyGlobal(self): content = '