1# Copyright (C) 2012 Jelmer Vernooij <jelmer@samba.org> 2 3# This program is free software; you can redistribute it and/or modify 4# it under the terms of the GNU Lesser General Public License as published by 5# the Free Software Foundation; either version 2.1 of the License, or 6# (at your option) any later version. 7 8# This program is distributed in the hope that it will be useful, 9# but WITHOUT ANY WARRANTY; without even the implied warranty of 10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11# GNU Lesser General Public License for more details. 12 13# You should have received a copy of the GNU Lesser General Public License 14# along with this program; if not, write to the Free Software 15# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 17from wafsamba.tests import TestCase 18 19from wafsamba.samba_abi import ( 20 abi_write_vscript, 21 normalise_signature, 22 ) 23 24from samba.compat import StringIO 25 26 27class NormaliseSignatureTests(TestCase): 28 29 def test_function_simple(self): 30 self.assertEquals("int (const struct GUID *, const struct GUID *)", 31 normalise_signature("$2 = {int (const struct GUID *, const struct GUID *)} 0xe871 <GUID_compare>")) 32 33 def test_maps_Bool(self): 34 # Some types have different internal names 35 self.assertEquals("bool (const struct GUID *)", 36 normalise_signature("$1 = {_Bool (const struct GUID *)} 0xe75b <GUID_all_zero>")) 37 38 def test_function_keep(self): 39 self.assertEquals( 40 "enum ndr_err_code (struct ndr_push *, int, const union winreg_Data *)", 41 normalise_signature("enum ndr_err_code (struct ndr_push *, int, const union winreg_Data *)")) 42 43 def test_struct_constant(self): 44 self.assertEquals( 45 'uuid = {time_low = 0, time_mid = 0, time_hi_and_version = 0, clock_seq = "\\000", node = "\\000\\000\\000\\000\\000"}, if_version = 0', 46 normalise_signature('$239 = {uuid = {time_low = 0, time_mid = 0, time_hi_and_version = 0, clock_seq = "\\000", node = "\\000\\000\\000\\000\\000"}, if_version = 0}')) 47 48 def test_incomplete_sequence(self): 49 # Newer versions of gdb insert these incomplete sequence elements 50 self.assertEquals( 51 'uuid = {time_low = 2324192516, time_mid = 7403, time_hi_and_version = 4553, clock_seq = "\\237\\350", node = "\\b\\000+\\020H`"}, if_version = 2', 52 normalise_signature('$244 = {uuid = {time_low = 2324192516, time_mid = 7403, time_hi_and_version = 4553, clock_seq = "\\237", <incomplete sequence \\350>, node = "\\b\\000+\\020H`"}, if_version = 2}')) 53 self.assertEquals( 54 'uuid = {time_low = 2324192516, time_mid = 7403, time_hi_and_version = 4553, clock_seq = "\\237\\350", node = "\\b\\000+\\020H`"}, if_version = 2', 55 normalise_signature('$244 = {uuid = {time_low = 2324192516, time_mid = 7403, time_hi_and_version = 4553, clock_seq = "\\237\\350", node = "\\b\\000+\\020H`"}, if_version = 2}')) 56 57 58class WriteVscriptTests(TestCase): 59 60 def test_one(self): 61 f = StringIO() 62 abi_write_vscript(f, "MYLIB", "1.0", [], { 63 "old": "1.0", 64 "new": "1.0"}, ["*"]) 65 self.assertEquals(f.getvalue(), """\ 661.0 { 67\tglobal: 68\t\t*; 69\tlocal: 70\t\t_end; 71\t\t__bss_start; 72\t\t_edata; 73}; 74""") 75 76 def test_simple(self): 77 # No restrictions. 78 f = StringIO() 79 abi_write_vscript(f, "MYLIB", "1.0", ["0.1"], { 80 "old": "0.1", 81 "new": "1.0"}, ["*"]) 82 self.assertEquals(f.getvalue(), """\ 83MYLIB_0.1 { 84\tglobal: 85\t\told; 86}; 87 881.0 { 89\tglobal: 90\t\t*; 91\tlocal: 92\t\t_end; 93\t\t__bss_start; 94\t\t_edata; 95}; 96""") 97 98 def test_exclude(self): 99 f = StringIO() 100 abi_write_vscript(f, "MYLIB", "1.0", [], { 101 "exc_old": "0.1", 102 "old": "0.1", 103 "new": "1.0"}, ["!exc_*"]) 104 self.assertEquals(f.getvalue(), """\ 1051.0 { 106\tglobal: 107\t\t*; 108\tlocal: 109\t\texc_*; 110\t\t_end; 111\t\t__bss_start; 112\t\t_edata; 113}; 114""") 115 116 def test_excludes_and_includes(self): 117 f = StringIO() 118 abi_write_vscript(f, "MYLIB", "1.0", [], { 119 "pub_foo": "1.0", 120 "exc_bar": "1.0", 121 "other": "1.0" 122 }, ["pub_*", "!exc_*"]) 123 self.assertEquals(f.getvalue(), """\ 1241.0 { 125\tglobal: 126\t\tpub_*; 127\tlocal: 128\t\texc_*; 129\t\t_end; 130\t\t__bss_start; 131\t\t_edata; 132\t\t*; 133}; 134""") 135