diff options
author | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2018-11-15 00:00:00 +0000 |
---|---|---|
committer | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2018-11-15 23:43:53 +0100 |
commit | 08f7bda8af62791f88f92f0190954aa5214c779f (patch) | |
tree | 03662639c60ad0e5f41045b09b7ed8ec346dd20e /tests | |
parent | 1f5e6a04ab92acdb6ef3e6136af7ecf119d82d9b (diff) | |
download | dconf-08f7bda8af62791f88f92f0190954aa5214c779f.tar.gz |
tests: Update invalidates replaced database
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/test-dconf.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/test-dconf.py b/tests/test-dconf.py index 64d3337..b277b1f 100755 --- a/tests/test-dconf.py +++ b/tests/test-dconf.py @@ -15,6 +15,7 @@ # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, see <http://www.gnu.org/licenses/>. +import mmap import os import subprocess import sys @@ -568,6 +569,36 @@ class DBusTest(unittest.TestCase): self.assertEqual(a_conf, dconf('dump', '/').stdout) + def test_database_invalidation(self): + """Update invalidates previous database by overwriting the header with + null bytes. + """ + + db = os.path.join(self.temporary_dir.name, 'db') + local = os.path.join(db, 'local') + local_d = os.path.join(db, 'local.d') + + os.makedirs(local_d) + + with open(os.path.join(local_d, 'local.conf'), 'w') as file: + file.write(dedent('''\ + [org/gnome/desktop/background] + picture-uri = 'file:///usr/share/backgrounds/gnome/ColdWarm.jpg' + ''')) + + # Compile database for the first time. + dconf('update', db) + + with open(local, 'rb') as file: + with mmap.mmap(file.fileno(), 8, mmap.MAP_SHARED, prot=mmap.PROT_READ) as mm: + # Sanity check that database is valid. + self.assertNotEqual(b'\0'*8, mm[:8]) + + dconf('update', db) + + # Now database should be marked as invalid. + self.assertEqual(b'\0'*8, mm[:8]) + if __name__ == '__main__': # Make sure we don't pick up mandatory profile. |