3 # Unix SMB/CIFS implementation. Tests for xattr manipulation
4 # Copyright (C) Matthieu Patou <mat@matws.net> 2009
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 import samba
.xattr_native
, samba
.xattr_tdb
21 from samba
.dcerpc
import xattr
22 from samba
.ndr
import ndr_pack
, ndr_unpack
23 from unittest
import TestCase
29 class XattrTests(TestCase
):
31 def test_set_xattr_native(self
):
32 if samba
.xattr_native
.is_xattr_supported():
34 path
=os
.environ
['SELFTEST_PREFIX']
35 tempf
=os
.path
.join(path
,"pytests"+str(int(100000*random
.random())))
38 open(tempf
, 'w').write("empty")
40 samba
.xattr_native
.wrap_setxattr(tempf
,"user.unittests",ndr_pack(ntacl
))
42 print >>sys
.stderr
, "WARNING: the filesystem where the tests are runned do not support XATTR, tests SKIPED"
45 print >>sys
.stderr
, "WARNING: the filesystem where the tests are runned do not support XATTR, tests SKIPED"
47 def test_set_and_get_native(self
):
48 if samba
.xattr_native
.is_xattr_supported():
50 path
= os
.environ
['SELFTEST_PREFIX']
51 tempf
=os
.path
.join(path
,"pytests"+str(int(100000*random
.random())))
52 reftxt
="this is a test"
53 open(tempf
, 'w').write("empty")
55 samba
.xattr_native
.wrap_setxattr(tempf
,"user.unittests",reftxt
)
56 text
= samba
.xattr_native
.wrap_getxattr(tempf
,"user.unittests")
57 self
.assertEquals(text
,reftxt
)
59 print >>sys
.stderr
,"WARNING: the filesystem where the tests are runned do not support XATTR, tests SKIPED"
62 print >>sys
.stderr
,"WARNING: the filesystem where the tests are runned do not support XATTR, tests SKIPED"
64 def test_set_xattr_tdb(self
):
65 path
=os
.environ
['SELFTEST_PREFIX']
66 eadb
=tdb
.Tdb(os
.path
.join(path
,"eadb.tdb"), 50000, tdb
.DEFAULT
, os
.O_CREAT|os
.O_RDWR
)
68 tempf
=os
.path
.join(path
,"pytests"+str(int(100000*random
.random())))
71 open(tempf
, 'w').write("empty")
72 samba
.xattr_tdb
.wrap_setxattr(os
.path
.join(path
,"eadb.tdb"),tempf
,"user.unittests",ndr_pack(ntacl
))
74 os
.unlink(os
.path
.join(path
,"eadb.tdb"))
76 def test_set_tdb_not_open(self
):
77 path
=os
.environ
['SELFTEST_PREFIX']
78 eadb
=tdb
.Tdb(os
.path
.join(path
,"eadb.tdb"), 50000, tdb
.DEFAULT
, os
.O_CREAT|os
.O_RDWR
)
80 tempf
=os
.path
.join(path
,"pytests"+str(int(100000*random
.random())))
83 open(tempf
, 'w').write("empty")
84 self
.assertRaises(IOError,samba
.xattr_tdb
.wrap_setxattr
,os
.path
.join(path
,os
.path
.join("nonexistent","eadb.tdb")),tempf
,"user.unittests",ndr_pack(ntacl
))
87 def test_set_and_get_tdb(self
):
88 path
=os
.environ
['SELFTEST_PREFIX']
90 tempf
=os
.path
.join(path
,"pytests"+str(int(100000*random
.random())))
91 reftxt
="this is a test"
92 open(tempf
, 'w').write("empty")
93 samba
.xattr_tdb
.wrap_setxattr(os
.path
.join(path
,"eadb.tdb"),tempf
,"user.unittests",reftxt
)
94 text
= samba
.xattr_tdb
.wrap_getxattr(os
.path
.join(path
,"eadb.tdb"),tempf
,"user.unittests")
95 self
.assertEquals(text
,reftxt
)
97 os
.unlink(os
.path
.join(path
,"eadb.tdb"))