@Test public void testSeek() throws IOException { CloudStorageFileSystem testBucket = getTestBucket(); Path path = testBucket.getPath(BIG_FILE); int size = BIG_SIZE; byte[] contents = randomContents(size); byte[] sample = new byte[100]; byte[] wanted; byte[] wanted2; SeekableByteChannel chan = Files.newByteChannel(path, StandardOpenOption.READ); assertThat(chan.size()).isEqualTo(size); // check seek int dest = size / 2; chan.position(dest); readFully(chan, sample); wanted = Arrays.copyOfRange(contents, dest, dest + 100); assertThat(wanted).isEqualTo(sample); // now go back and check the beginning // (we do 2 locations because 0 is sometimes a special case). chan.position(0); readFully(chan, sample); wanted2 = Arrays.copyOf(contents, 100); assertThat(wanted2).isEqualTo(sample); // if the two spots in the file have the same contents, then this isn't a good file for this // test. assertThat(wanted).isNotEqualTo(wanted2); }
byte[] mergedDexData = TestUtils.getEntryContent(mergedDexEntry); assertThat(mergedDexData.length).isGreaterThan(0); assertThat(mergedDexData).isNotEqualTo(TestData.readBytes("testdata/dex/classes.dex")); assertThat(mergedDexData).isNotEqualTo(TestData.readBytes("testdata/dex/classes-other.dex"));
@Test public void differentManifests_ok() throws Exception { String filePath = "manifest/AndroidManifest.xml"; byte[] fileContentA = XmlNode.getDefaultInstance().toByteArray(); byte[] fileContentB = XmlNode.newBuilder().setElement(XmlElement.newBuilder()).build().toByteArray(); assertThat(fileContentA).isNotEqualTo(fileContentB); BundleModule moduleA = new BundleModuleBuilder("a").addFile(filePath, fileContentA).build(); BundleModule moduleB = new BundleModuleBuilder("b").addFile(filePath, fileContentB).build(); new EntryClashValidator().validateAllModules(ImmutableList.of(moduleA, moduleB)); }
ByteStreams.toByteArray(shardZip.getInputStream(new ZipEntry("classes.dex"))); assertThat(mergedDexData.length).isGreaterThan(0); assertThat(mergedDexData).isNotEqualTo(TestData.readBytes("testdata/dex/classes-large.dex")); assertThat(mergedDexData).isNotEqualTo(TestData.readBytes("testdata/dex/classes-large2.dex")); byte[] mergedDex2Data = ByteStreams.toByteArray(shardZip.getInputStream(new ZipEntry("classes.dex"))); assertThat(mergedDex2Data.length).isGreaterThan(0); assertThat(mergedDex2Data).isNotEqualTo(TestData.readBytes("testdata/dex/classes-large.dex")); assertThat(mergedDex2Data) .isNotEqualTo(TestData.readBytes("testdata/dex/classes-large2.dex"));
@Test public void differentAssetsConfig_ok() throws Exception { String filePath = "assets.pb"; byte[] fileContentA = Assets.getDefaultInstance().toByteArray(); byte[] fileContentB = Assets.newBuilder() .addDirectory(TargetedAssetsDirectory.getDefaultInstance()) .build() .toByteArray(); assertThat(fileContentA).isNotEqualTo(fileContentB); BundleModule moduleA = new BundleModuleBuilder("a") .addFile(filePath, fileContentA) .setManifest(androidManifest("com.test.app")) .build(); BundleModule moduleB = new BundleModuleBuilder("b") .addFile(filePath, fileContentB) .setManifest(androidManifest("com.test.app")) .build(); new EntryClashValidator().validateAllModules(ImmutableList.of(moduleA, moduleB)); }
@Test public void differentNativeConfig_ok() throws Exception { String filePath = "native.pb"; byte[] fileContentA = NativeLibraries.getDefaultInstance().toByteArray(); byte[] fileContentB = NativeLibraries.newBuilder() .addDirectory(TargetedNativeDirectory.getDefaultInstance()) .build() .toByteArray(); assertThat(fileContentA).isNotEqualTo(fileContentB); BundleModule moduleA = new BundleModuleBuilder("a") .addFile(filePath, fileContentA) .setManifest(androidManifest("com.test.app")) .build(); BundleModule moduleB = new BundleModuleBuilder("b") .addFile(filePath, fileContentB) .setManifest(androidManifest("com.test.app")) .build(); new EntryClashValidator().validateAllModules(ImmutableList.of(moduleA, moduleB)); }
@Test public void differentResourceTables_ok() throws Exception { String filePath = "resources.pb"; byte[] fileContentA = ResourceTable.getDefaultInstance().toByteArray(); byte[] fileContentB = ResourceTable.newBuilder().addPackage(Package.getDefaultInstance()).build().toByteArray(); assertThat(fileContentA).isNotEqualTo(fileContentB); BundleModule moduleA = new BundleModuleBuilder("a") .addFile(filePath, fileContentA) .setManifest(androidManifest("com.test.app")) .build(); BundleModule moduleB = new BundleModuleBuilder("b") .addFile(filePath, fileContentB) .setManifest(androidManifest("com.test.app")) .build(); new EntryClashValidator().validateAllModules(ImmutableList.of(moduleA, moduleB)); }
ByteStreams.toByteArray(shardZip.getInputStream(new ZipEntry("classes.dex"))); assertThat(mergedDexData.length).isGreaterThan(0); assertThat(mergedDexData).isNotEqualTo(TestData.readBytes("testdata/dex/classes.dex")); assertThat(mergedDexData).isNotEqualTo(TestData.readBytes("testdata/dex/classes-other.dex"));