libsmb: Use clistr_smb2_extract_snapshot_token() in cli_smb2_create_fnum_send()
[Samba.git] / python / samba / tests / registry.py
blob51b280a63480424370310b10ba410179e74ab071
1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 """Tests for samba.registry."""
20 import os
21 from samba import registry
22 import samba.tests
23 from samba import WERRORError
24 from subprocess import Popen, PIPE
27 class HelperTests(samba.tests.TestCase):
29 def test_predef_to_name(self):
30 self.assertEqual("HKEY_LOCAL_MACHINE",
31 registry.get_predef_name(0x80000002))
33 def test_str_regtype(self):
34 self.assertEqual("REG_DWORD", registry.str_regtype(4))
37 class HiveTests(samba.tests.TestCaseInTempDir):
39 def setUp(self):
40 super(HiveTests, self).setUp()
41 self.hive_path = os.path.join(self.tempdir, "ldb_new.ldb")
42 self.hive = registry.open_ldb(self.hive_path)
44 def tearDown(self):
45 del self.hive
46 os.unlink(self.hive_path)
47 super(HiveTests, self).tearDown()
49 def test_ldb_new(self):
50 self.assertTrue(self.hive is not None)
52 def test_set_value(self):
53 self.assertIsNone(self.hive.set_value('foo1', 1, 'bar1'))
55 def test_flush(self):
56 self.assertIsNone(self.hive.set_value('foo2', 1, 'bar2'))
57 self.assertIsNone(self.hive.flush())
59 tdbdump_tool = 'tdbdump'
60 if os.path.isfile('bin/tdbdump'):
61 tdbdump_tool = 'bin/tdbdump'
63 proc = Popen([tdbdump_tool, self.hive_path], stdout=PIPE, stderr=PIPE)
64 tdb_dump, err = proc.communicate()
65 self.assertTrue(b'DN=VALUE=FOO2,HIVE=NONE' in tdb_dump)
67 def test_del_value(self):
68 self.assertIsNone(self.hive.set_value('foo3', 1, 'bar3'))
69 self.assertIsNone(self.hive.del_value('foo3'))
71 def test_del_nonexisting_value(self):
72 self.assertRaises(WERRORError, self.hive.del_value, 'foo4')
75 class RegistryTests(samba.tests.TestCase):
77 def test_new(self):
78 self.registry = registry.Registry()
79 self.assertIsNotNone(self.registry)