Update CTS to follow FontConfig API changes.
Bug: 36660849
Test: android.text.cts.FontManagerTest passed
Change-Id: Ifcf5400f7e53e0fa935239fe116a22b19b389b71
diff --git a/tests/tests/text/src/android/text/cts/FontManagerTest.java b/tests/tests/text/src/android/text/cts/FontManagerTest.java
index 036c4e1..3729217 100644
--- a/tests/tests/text/src/android/text/cts/FontManagerTest.java
+++ b/tests/tests/text/src/android/text/cts/FontManagerTest.java
@@ -19,14 +19,12 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import android.content.ContentResolver;
import android.content.Context;
import android.os.ParcelFileDescriptor;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
-import android.system.ErrnoException;
-import android.system.Os;
-import android.system.OsConstants;
import android.text.FontConfig;
import android.text.FontManager;
@@ -34,7 +32,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
-import java.io.FileDescriptor;
+import java.io.FileNotFoundException;
/**
* Tests {@link FontManager}.
@@ -61,34 +59,26 @@
assertTrue("Each font family should have at least one font",
family.getFonts().length > 0);
for (final FontConfig.Font font : family.getFonts()) {
- assertNotNull("FontManager should provide a FileDescriptor for each system font",
- font.getFd());
+ assertNotNull("FontManager should provide a URI for each system font",
+ font.getUri());
}
}
}
@Test
- public void testFileDescriptorsAreReadOnly() throws Exception {
+ public void testFilesAreReadOnly() throws Exception {
final FontConfig fc = mFontManager.getSystemFonts();
+ ContentResolver cr = InstrumentationRegistry.getTargetContext().getContentResolver();
for (final FontConfig.Family family : fc.getFamilies()) {
for (final FontConfig.Font font : family.getFonts()) {
- final ParcelFileDescriptor pfd = font.getFd();
- assertNotNull(pfd);
- final FileDescriptor fd = pfd.getFileDescriptor();
- long size = Os.lseek(fd, 0, OsConstants.SEEK_END);
- // Read only mapping should success.
- final long addr = Os.mmap(0, size, OsConstants.PROT_READ, OsConstants.MAP_SHARED,
- fd, 0);
- Os.munmap(addr, size);
+ ParcelFileDescriptor fd = cr.openFileDescriptor(font.getUri(), "r");
+ fd.close();
- // Mapping with PROT_WRITE should fail with EPERM.
- try {
- Os.mmap(0, size, OsConstants.PROT_READ | OsConstants.PROT_WRITE,
- OsConstants.MAP_SHARED, fd, 0);
+ try (ParcelFileDescriptor fd2 = cr.openFileDescriptor(font.getUri(), "w")) {
fail();
- } catch (ErrnoException e) {
- // EPERM should be raised.
+ } catch (FileNotFoundException e) {
+ // System font file must not be writable.
}
}
}