diff options
author | Jeff Sharkey <jsharkey@android.com> | 2015-07-02 12:04:00 -0700 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2015-07-02 13:03:14 -0700 |
commit | 82d076b51f6fe7c1cbd1f37414be36eaaa9b0e56 (patch) | |
tree | 117517ea17821d4134f5b7cdd76d1e0d3d82cbeb /luni/src/test/java | |
parent | 505fb9201a6624009659b6083949c9e5428def11 (diff) | |
download | libcore-82d076b51f6fe7c1cbd1f37414be36eaaa9b0e56.zip libcore-82d076b51f6fe7c1cbd1f37414be36eaaa9b0e56.tar.gz libcore-82d076b51f6fe7c1cbd1f37414be36eaaa9b0e56.tar.bz2 |
Add getxattr/setxattr/removexattr syscalls.
Bug: 20275572
Change-Id: I958056f757f095ad6278624e293a5583d9cee822
Diffstat (limited to 'luni/src/test/java')
-rw-r--r-- | luni/src/test/java/libcore/io/OsTest.java | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/luni/src/test/java/libcore/io/OsTest.java b/luni/src/test/java/libcore/io/OsTest.java index e648e8a..9b38ee9 100644 --- a/luni/src/test/java/libcore/io/OsTest.java +++ b/luni/src/test/java/libcore/io/OsTest.java @@ -18,6 +18,7 @@ package libcore.io; import android.system.ErrnoException; import android.system.NetlinkSocketAddress; +import android.system.OsConstants; import android.system.PacketSocketAddress; import android.system.StructTimeval; import android.system.StructUcred; @@ -419,4 +420,59 @@ public class OsTest extends TestCase { checkSocketPing(fd, ipv4Loopback, packet, ICMP_ECHO, ICMP_ECHOREPLY, true); checkSocketPing(fd, ipv4Loopback, packet, ICMP_ECHO, ICMP_ECHOREPLY, false); } + + private static void assertPartial(byte[] expected, byte[] actual) { + for (int i = 0; i < expected.length; i++) { + if (expected[i] != actual[i]) { + fail("Expected " + Arrays.toString(expected) + " but found " + + Arrays.toString(actual)); + } + } + } + + public void test_xattr() throws Exception { + final String NAME_TEST = "user.meow"; + + final byte[] VALUE_CAKE = "cake cake cake".getBytes(StandardCharsets.UTF_8); + final byte[] VALUE_PIE = "pie".getBytes(StandardCharsets.UTF_8); + + File file = File.createTempFile("xattr", "test"); + String path = file.getAbsolutePath(); + + byte[] tmp = new byte[1024]; + try { + try { + Libcore.os.getxattr(path, NAME_TEST, tmp); + fail("Expected ENODATA"); + } catch (ErrnoException e) { + assertEquals(OsConstants.ENODATA, e.errno); + } + + Libcore.os.setxattr(path, NAME_TEST, VALUE_CAKE, OsConstants.XATTR_CREATE); + assertEquals(VALUE_CAKE.length, Libcore.os.getxattr(path, NAME_TEST, tmp)); + assertPartial(VALUE_CAKE, tmp); + + try { + Libcore.os.setxattr(path, NAME_TEST, VALUE_PIE, OsConstants.XATTR_CREATE); + fail("Expected EEXIST"); + } catch (ErrnoException e) { + assertEquals(OsConstants.EEXIST, e.errno); + } + + Libcore.os.setxattr(path, NAME_TEST, VALUE_PIE, OsConstants.XATTR_REPLACE); + assertEquals(VALUE_PIE.length, Libcore.os.getxattr(path, NAME_TEST, tmp)); + assertPartial(VALUE_PIE, tmp); + + Libcore.os.removexattr(path, NAME_TEST); + try { + Libcore.os.getxattr(path, NAME_TEST, tmp); + fail("Expected ENODATA"); + } catch (ErrnoException e) { + assertEquals(OsConstants.ENODATA, e.errno); + } + + } finally { + file.delete(); + } + } } |