diff options
author | Zhomart Mukhamejanov <zhomart@google.com> | 2018-05-09 03:04:59 +0200 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2018-05-09 03:04:59 +0200 |
commit | daa86e9024d32d39c1d2617d96dc80a659aec76b (patch) | |
tree | 3ff8ca73b2c609d889b88fd7f147a843fda52579 /updater_sample/tests/src/com | |
parent | Merge "updater_sample: add streaming support" (diff) | |
parent | updater_sample: update tools (diff) | |
download | android_bootable_recovery-daa86e9024d32d39c1d2617d96dc80a659aec76b.tar android_bootable_recovery-daa86e9024d32d39c1d2617d96dc80a659aec76b.tar.gz android_bootable_recovery-daa86e9024d32d39c1d2617d96dc80a659aec76b.tar.bz2 android_bootable_recovery-daa86e9024d32d39c1d2617d96dc80a659aec76b.tar.lz android_bootable_recovery-daa86e9024d32d39c1d2617d96dc80a659aec76b.tar.xz android_bootable_recovery-daa86e9024d32d39c1d2617d96dc80a659aec76b.tar.zst android_bootable_recovery-daa86e9024d32d39c1d2617d96dc80a659aec76b.zip |
Diffstat (limited to 'updater_sample/tests/src/com')
2 files changed, 18 insertions, 42 deletions
diff --git a/updater_sample/tests/src/com/example/android/systemupdatersample/util/FileDownloaderTest.java b/updater_sample/tests/src/com/example/android/systemupdatersample/util/FileDownloaderTest.java index 80506ee6d..009610e86 100644 --- a/updater_sample/tests/src/com/example/android/systemupdatersample/util/FileDownloaderTest.java +++ b/updater_sample/tests/src/com/example/android/systemupdatersample/util/FileDownloaderTest.java @@ -70,11 +70,11 @@ public class FileDownloaderTest { .toFile(); Files.deleteIfExists(outFile.toPath()); // download a chunk of ota.zip - FileDownloader downloader = new FileDownloader(url, 160, 8, outFile); + FileDownloader downloader = new FileDownloader(url, 1674, 12, outFile); downloader.download(); String downloadedContent = String.join("\n", Files.readAllLines(outFile.toPath())); // archive contains text files with uppercase filenames - assertEquals("CARE_MAP", downloadedContent); + assertEquals("CARE_MAP-TXT", downloadedContent); } } diff --git a/updater_sample/tests/src/com/example/android/systemupdatersample/util/PayloadSpecsTest.java b/updater_sample/tests/src/com/example/android/systemupdatersample/util/PayloadSpecsTest.java index 2912e209e..d9e54652f 100644 --- a/updater_sample/tests/src/com/example/android/systemupdatersample/util/PayloadSpecsTest.java +++ b/updater_sample/tests/src/com/example/android/systemupdatersample/util/PayloadSpecsTest.java @@ -17,8 +17,6 @@ package com.example.android.systemupdatersample.util; import static com.example.android.systemupdatersample.util.PackageFiles.PAYLOAD_BINARY_FILE_NAME; -import static com.example.android.systemupdatersample.util.PackageFiles - .PAYLOAD_PROPERTIES_FILE_NAME; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; @@ -29,6 +27,7 @@ import android.support.test.filters.SmallTest; import android.support.test.runner.AndroidJUnit4; import com.example.android.systemupdatersample.PayloadSpec; +import com.example.android.systemupdatersample.tests.R; import com.google.common.base.Charsets; import com.google.common.io.Files; @@ -39,12 +38,8 @@ import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.zip.CRC32; -import java.util.zip.ZipEntry; -import java.util.zip.ZipOutputStream; +import java.nio.file.Paths; /** * Tests if PayloadSpecs parses update package zip file correctly. @@ -54,12 +49,11 @@ import java.util.zip.ZipOutputStream; public class PayloadSpecsTest { private static final String PROPERTIES_CONTENTS = "k1=val1\nkey2=val2"; - private static final String PAYLOAD_CONTENTS = "hello\nworld"; - private static final int PAYLOAD_SIZE = PAYLOAD_CONTENTS.length(); private File mTestDir; private Context mTargetContext; + private Context mTestContext; @Rule public final ExpectedException thrown = ExpectedException.none(); @@ -67,21 +61,30 @@ public class PayloadSpecsTest { @Before public void setUp() { mTargetContext = InstrumentationRegistry.getTargetContext(); + mTestContext = InstrumentationRegistry.getContext(); mTestDir = mTargetContext.getFilesDir(); } @Test public void forNonStreaming_works() throws Exception { - File packageFile = createMockZipFile(); + // Prepare the target file + File packageFile = Paths + .get(mTargetContext.getCacheDir().getAbsolutePath(), "ota.zip") + .toFile(); + java.nio.file.Files.deleteIfExists(packageFile.toPath()); + java.nio.file.Files.copy(mTestContext.getResources().openRawResource(R.raw.ota_002_package), + packageFile.toPath()); PayloadSpec spec = PayloadSpecs.forNonStreaming(packageFile); assertEquals("correct url", "file://" + packageFile.getAbsolutePath(), spec.getUrl()); assertEquals("correct payload offset", 30 + PAYLOAD_BINARY_FILE_NAME.length(), spec.getOffset()); - assertEquals("correct payload size", PAYLOAD_SIZE, spec.getSize()); - assertArrayEquals("correct properties", - new String[]{"k1=val1", "key2=val2"}, spec.getProperties().toArray(new String[0])); + assertEquals("correct payload size", 1392, spec.getSize()); + assertEquals(4, spec.getProperties().size()); + assertEquals( + "FILE_HASH=sEAK/NMbU7GGe01xt55FsPafIPk8IYyBOAd6SiDpiMs=", + spec.getProperties().get(0)); } @Test @@ -105,33 +108,6 @@ public class PayloadSpecsTest { new String[]{"k1=val1", "key2=val2"}, spec.getProperties().toArray(new String[0])); } - /** - * Creates package zip file that contains payload.bin and payload_properties.txt - */ - private File createMockZipFile() throws IOException { - File testFile = new File(mTestDir, "test.zip"); - try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(testFile))) { - // Add payload.bin entry. - ZipEntry entry = new ZipEntry(PAYLOAD_BINARY_FILE_NAME); - entry.setMethod(ZipEntry.STORED); - entry.setCompressedSize(PAYLOAD_SIZE); - entry.setSize(PAYLOAD_SIZE); - CRC32 crc = new CRC32(); - crc.update(PAYLOAD_CONTENTS.getBytes(StandardCharsets.UTF_8)); - entry.setCrc(crc.getValue()); - zos.putNextEntry(entry); - zos.write(PAYLOAD_CONTENTS.getBytes(StandardCharsets.UTF_8)); - zos.closeEntry(); - - // Add payload properties entry. - ZipEntry propertiesEntry = new ZipEntry(PAYLOAD_PROPERTIES_FILE_NAME); - zos.putNextEntry(propertiesEntry); - zos.write(PROPERTIES_CONTENTS.getBytes(StandardCharsets.UTF_8)); - zos.closeEntry(); - } - return testFile; - } - private File createMockPropertiesFile() throws IOException { File propertiesFile = new File(mTestDir, PackageFiles.PAYLOAD_PROPERTIES_FILE_NAME); Files.asCharSink(propertiesFile, Charsets.UTF_8).write(PROPERTIES_CONTENTS); |