summaryrefslogtreecommitdiffstats
path: root/buildtools/wafsamba/tests
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--buildtools/wafsamba/tests/__init__.py35
-rw-r--r--buildtools/wafsamba/tests/test_abi.py134
-rw-r--r--buildtools/wafsamba/tests/test_bundled.py27
-rw-r--r--buildtools/wafsamba/tests/test_utils.py76
4 files changed, 272 insertions, 0 deletions
diff --git a/buildtools/wafsamba/tests/__init__.py b/buildtools/wafsamba/tests/__init__.py
new file mode 100644
index 0000000..ae27418
--- /dev/null
+++ b/buildtools/wafsamba/tests/__init__.py
@@ -0,0 +1,35 @@
+# Copyright (C) 2012 Jelmer Vernooij <jelmer@samba.org>
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 2.1 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License for more details.
+
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+"""Tests for wafsamba."""
+
+from unittest import (
+ TestCase,
+ TestLoader,
+ )
+
+def test_suite():
+ names = [
+ 'abi',
+ 'bundled',
+ 'utils',
+ ]
+ module_names = ['wafsamba.tests.test_' + name for name in names]
+ loader = TestLoader()
+ result = loader.suiteClass()
+ suite = loader.loadTestsFromNames(module_names)
+ result.addTests(suite)
+ return result
diff --git a/buildtools/wafsamba/tests/test_abi.py b/buildtools/wafsamba/tests/test_abi.py
new file mode 100644
index 0000000..ffd5a56
--- /dev/null
+++ b/buildtools/wafsamba/tests/test_abi.py
@@ -0,0 +1,134 @@
+# Copyright (C) 2012 Jelmer Vernooij <jelmer@samba.org>
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 2.1 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License for more details.
+
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+from wafsamba.tests import TestCase
+
+from wafsamba.samba_abi import (
+ abi_write_vscript,
+ normalise_signature,
+ )
+
+from io import StringIO
+
+
+class NormaliseSignatureTests(TestCase):
+
+ def test_function_simple(self):
+ self.assertEqual("int (const struct GUID *, const struct GUID *)",
+ normalise_signature("$2 = {int (const struct GUID *, const struct GUID *)} 0xe871 <GUID_compare>"))
+
+ def test_maps_Bool(self):
+ # Some types have different internal names
+ self.assertEqual("bool (const struct GUID *)",
+ normalise_signature("$1 = {_Bool (const struct GUID *)} 0xe75b <GUID_all_zero>"))
+
+ def test_function_keep(self):
+ self.assertEqual(
+ "enum ndr_err_code (struct ndr_push *, int, const union winreg_Data *)",
+ normalise_signature("enum ndr_err_code (struct ndr_push *, int, const union winreg_Data *)"))
+
+ def test_struct_constant(self):
+ self.assertEqual(
+ 'uuid = {time_low = 0, time_mid = 0, time_hi_and_version = 0, clock_seq = "\\000", node = "\\000\\000\\000\\000\\000"}, if_version = 0',
+ 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}'))
+
+ def test_incomplete_sequence(self):
+ # Newer versions of gdb insert these incomplete sequence elements
+ self.assertEqual(
+ 'uuid = {time_low = 2324192516, time_mid = 7403, time_hi_and_version = 4553, clock_seq = "\\237\\350", node = "\\b\\000+\\020H`"}, if_version = 2',
+ 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}'))
+ self.assertEqual(
+ 'uuid = {time_low = 2324192516, time_mid = 7403, time_hi_and_version = 4553, clock_seq = "\\237\\350", node = "\\b\\000+\\020H`"}, if_version = 2',
+ 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}'))
+
+
+class WriteVscriptTests(TestCase):
+
+ def test_one(self):
+ f = StringIO()
+ abi_write_vscript(f, "MYLIB", "1.0", [], {
+ "old": "1.0",
+ "new": "1.0"}, ["*"])
+ self.assertEqual(f.getvalue(), """\
+1.0 {
+\tglobal:
+\t\t*;
+\tlocal:
+\t\t_end;
+\t\t__bss_start;
+\t\t_edata;
+};
+""")
+
+ def test_simple(self):
+ # No restrictions.
+ f = StringIO()
+ abi_write_vscript(f, "MYLIB", "1.0", ["0.1"], {
+ "old": "0.1",
+ "new": "1.0"}, ["*"])
+ self.assertEqual(f.getvalue(), """\
+MYLIB_0.1 {
+\tglobal:
+\t\told;
+};
+
+1.0 {
+\tglobal:
+\t\t*;
+\tlocal:
+\t\t_end;
+\t\t__bss_start;
+\t\t_edata;
+};
+""")
+
+ def test_exclude(self):
+ f = StringIO()
+ abi_write_vscript(f, "MYLIB", "1.0", [], {
+ "exc_old": "0.1",
+ "old": "0.1",
+ "new": "1.0"}, ["!exc_*"])
+ self.assertEqual(f.getvalue(), """\
+1.0 {
+\tglobal:
+\t\t*;
+\tlocal:
+\t\texc_*;
+\t\t_end;
+\t\t__bss_start;
+\t\t_edata;
+};
+""")
+
+ def test_excludes_and_includes(self):
+ f = StringIO()
+ abi_write_vscript(f, "MYLIB", "1.0", [], {
+ "pub_foo": "1.0",
+ "exc_bar": "1.0",
+ "other": "1.0"
+ }, ["pub_*", "!exc_*"])
+ self.assertEqual(f.getvalue(), """\
+1.0 {
+\tglobal:
+\t\tpub_*;
+\tlocal:
+\t\texc_*;
+\t\t_end;
+\t\t__bss_start;
+\t\t_edata;
+\t\t*;
+};
+""")
diff --git a/buildtools/wafsamba/tests/test_bundled.py b/buildtools/wafsamba/tests/test_bundled.py
new file mode 100644
index 0000000..a8e9821
--- /dev/null
+++ b/buildtools/wafsamba/tests/test_bundled.py
@@ -0,0 +1,27 @@
+# Copyright (C) 2012 Jelmer Vernooij <jelmer@samba.org>
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 2.1 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License for more details.
+
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+from wafsamba.tests import TestCase
+
+from wafsamba.samba_bundled import (
+ tuplize_version,
+ )
+
+
+class TuplizeVersionTests(TestCase):
+
+ def test_simple(self):
+ self.assertEqual((1, 2, 10), tuplize_version("1.2.10"))
diff --git a/buildtools/wafsamba/tests/test_utils.py b/buildtools/wafsamba/tests/test_utils.py
new file mode 100644
index 0000000..77fc55c
--- /dev/null
+++ b/buildtools/wafsamba/tests/test_utils.py
@@ -0,0 +1,76 @@
+# Copyright (C) 2012 Jelmer Vernooij <jelmer@samba.org>
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 2.1 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License for more details.
+
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+from wafsamba.tests import TestCase
+
+from wafsamba.samba_utils import (
+ TO_LIST,
+ dict_concat,
+ subst_vars_error,
+ unique_list,
+ )
+
+class ToListTests(TestCase):
+
+ def test_none(self):
+ self.assertEqual([], TO_LIST(None))
+
+ def test_already_list(self):
+ self.assertEqual(["foo", "bar", 1], TO_LIST(["foo", "bar", 1]))
+
+ def test_default_delimiter(self):
+ self.assertEqual(["foo", "bar"], TO_LIST("foo bar"))
+ self.assertEqual(["foo", "bar"], TO_LIST(" foo bar "))
+ self.assertEqual(["foo ", "bar"], TO_LIST(" \"foo \" bar "))
+
+ def test_delimiter(self):
+ self.assertEqual(["foo", "bar"], TO_LIST("foo,bar", ","))
+ self.assertEqual([" foo", "bar "], TO_LIST(" foo,bar ", ","))
+ self.assertEqual([" \" foo\"", " bar "], TO_LIST(" \" foo\", bar ", ","))
+
+
+class UniqueListTests(TestCase):
+
+ def test_unique_list(self):
+ self.assertEqual(["foo", "bar"], unique_list(["foo", "bar", "foo"]))
+
+
+class SubstVarsErrorTests(TestCase):
+
+ def test_valid(self):
+ self.assertEqual("", subst_vars_error("", {}))
+ self.assertEqual("FOO bar", subst_vars_error("${F} bar", {"F": "FOO"}))
+
+ def test_invalid(self):
+ self.assertRaises(KeyError, subst_vars_error, "${F}", {})
+
+
+class DictConcatTests(TestCase):
+
+ def test_empty(self):
+ ret = {}
+ dict_concat(ret, {})
+ self.assertEqual({}, ret)
+
+ def test_same(self):
+ ret = {"foo": "bar"}
+ dict_concat(ret, {"foo": "bla"})
+ self.assertEqual({"foo": "bar"}, ret)
+
+ def test_simple(self):
+ ret = {"foo": "bar"}
+ dict_concat(ret, {"blie": "bla"})
+ self.assertEqual({"foo": "bar", "blie": "bla"}, ret)