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
28 class XattrTests(TestCase
):
30 def test_set_xattr_native(self
):
31 if samba
.xattr_native
.is_xattr_supported():
33 path
=os
.environ
['SELFTEST_PREFIX']
34 tempf
=os
.path
.join(path
,"pytests"+str(int(100000*random
.random())))
37 open(tempf
, 'w').write("empty")
38 samba
.xattr_native
.wrap_setxattr(tempf
,"user.unittests",ndr_pack(ntacl
))
41 def test_set_and_get_native(self
):
42 if samba
.xattr_native
.is_xattr_supported():
44 path
=os
.environ
['SELFTEST_PREFIX']
45 tempf
=os
.path
.join(path
,"pytests"+str(int(100000*random
.random())))
46 reftxt
="this is a test"
47 open(tempf
, 'w').write("empty")
48 samba
.xattr_native
.wrap_setxattr(tempf
,"user.unittests",reftxt
)
49 text
= samba
.xattr_native
.wrap_getxattr(tempf
,"user.unittests")
50 self
.assertEquals(text
,reftxt
)
53 def test_set_xattr_tdb(self
):
54 path
=os
.environ
['SELFTEST_PREFIX']
55 eadb
=tdb
.Tdb(os
.path
.join(path
,"eadb.tdb"), 50000, tdb
.DEFAULT
, os
.O_CREAT|os
.O_RDWR
)
57 tempf
=os
.path
.join(path
,"pytests"+str(int(100000*random
.random())))
60 open(tempf
, 'w').write("empty")
61 samba
.xattr_tdb
.wrap_setxattr(eadb
,tempf
,"user.unittests",ndr_pack(ntacl
))
63 os
.unlink(os
.path
.join(path
,"eadb.tdb"))
65 def test_set_and_get_tdb(self
):
66 path
=os
.environ
['SELFTEST_PREFIX']
67 eadb
=tdb
.Tdb(os
.path
.join(path
,"eadb.tdb"), 50000, tdb
.DEFAULT
, os
.O_CREAT|os
.O_RDWR
)
69 tempf
=os
.path
.join(path
,"pytests"+str(int(100000*random
.random())))
70 reftxt
="this is a test"
71 open(tempf
, 'w').write("empty")
72 samba
.xattr_tdb
.wrap_setxattr(eadb
,tempf
,"user.unittests",reftxt
)
73 text
= samba
.xattr_tdb
.wrap_getxattr(eadb
,tempf
,"user.unittests")
74 self
.assertEquals(text
,reftxt
)
76 os
.unlink(os
.path
.join(path
,"eadb.tdb"))