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']
67 tempf
=os
.path
.join(path
,"pytests"+str(int(100000*random
.random())))
70 open(tempf
, 'w').write("empty")
71 samba
.xattr_tdb
.wrap_setxattr(os
.path
.join(path
,"eadb.tdb"),tempf
,"user.unittests",ndr_pack(ntacl
))
73 os
.unlink(os
.path
.join(path
,"eadb.tdb"))
75 def test_set_tdb_not_open(self
):
76 path
=os
.environ
['SELFTEST_PREFIX']
78 tempf
=os
.path
.join(path
,"pytests"+str(int(100000*random
.random())))
81 open(tempf
, 'w').write("empty")
82 self
.assertRaises(IOError,samba
.xattr_tdb
.wrap_setxattr
,os
.path
.join(path
,os
.path
.join("nonexistent","eadb.tdb")),tempf
,"user.unittests",ndr_pack(ntacl
))
85 def test_set_and_get_tdb(self
):
86 path
=os
.environ
['SELFTEST_PREFIX']
88 tempf
=os
.path
.join(path
,"pytests"+str(int(100000*random
.random())))
89 reftxt
="this is a test"
90 open(tempf
, 'w').write("empty")
91 samba
.xattr_tdb
.wrap_setxattr(os
.path
.join(path
,"eadb.tdb"),tempf
,"user.unittests",reftxt
)
92 text
= samba
.xattr_tdb
.wrap_getxattr(os
.path
.join(path
,"eadb.tdb"),tempf
,"user.unittests")
93 self
.assertEquals(text
,reftxt
)
95 os
.unlink(os
.path
.join(path
,"eadb.tdb"))