|
| 1 | +/* |
| 2 | + * Copyright (C) 2021 The Android Open Source Project |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package androidx.test.platform.io; |
| 17 | + |
| 18 | +import java.io.IOException; |
| 19 | +import java.io.InputStream; |
| 20 | +import java.io.OutputStream; |
| 21 | +import java.io.Serializable; |
| 22 | +import java.util.Map; |
| 23 | + |
| 24 | +/** |
| 25 | + * An interface represents on-device I/O operations in an Android test. |
| 26 | + * |
| 27 | + * <p>This is a low level API, typically used by higher level test frameworks. It is generally not |
| 28 | + * recommended for direct use by most tests. |
| 29 | + * |
| 30 | + * <p>Use a concrete implementation class of this interface if you need to read/write files in your |
| 31 | + * tests. For example, in an Android Instrumentation test, use {@code |
| 32 | + * androidx.test.services.storage.TestStorage} when the test services is installed on the device. |
| 33 | + */ |
| 34 | +public interface PlatformTestStorage { |
| 35 | + /** |
| 36 | + * Provides an InputStream to a test file dependency. |
| 37 | + * |
| 38 | + * @param pathname path to the test file dependency. Should not be null. This is a relative path |
| 39 | + * to where the storage service stores the input files. For example, if the storage service |
| 40 | + * stores the input files under "/sdcard/test_input_files", with a pathname |
| 41 | + * "/path/to/my_input.txt", the file will end up at |
| 42 | + * "/sdcard/test_input_files/path/to/my_input.txt" on device. |
| 43 | + * @return an InputStream to the given test file. |
| 44 | + */ |
| 45 | + InputStream openInputFile(String pathname) throws IOException; |
| 46 | + |
| 47 | + /** |
| 48 | + * Returns the value of a given argument name. |
| 49 | + * |
| 50 | + * <p>There should be one and only one argument defined with the given argument name. Otherwise, |
| 51 | + * it will throw a TestStorageException if zero or more than one arguments are found. |
| 52 | + * |
| 53 | + * <p>We suggest using some naming convention when defining the argument name to avoid possible |
| 54 | + * conflict, e.g. defining "namespaces" for your arguments which helps clarify how the argument is |
| 55 | + * used and also its scope. For example, for arguments used for authentication purposes, you could |
| 56 | + * name the account email argument as something like "google_account.email" and its password as |
| 57 | + * "google_account.password". |
| 58 | + * |
| 59 | + * @param argName the argument name. Should not be null. |
| 60 | + */ |
| 61 | + String getInputArg(String argName); |
| 62 | + |
| 63 | + /** |
| 64 | + * Returns the name/value map of all test arguments or an empty map if no arguments are defined. |
| 65 | + */ |
| 66 | + Map<String, String> getInputArgs(); |
| 67 | + |
| 68 | + /** |
| 69 | + * Provides an OutputStream to a test output file. |
| 70 | + * |
| 71 | + * @param pathname path to the test output file. Should not be null. This is a relative path to |
| 72 | + * where the storage service stores the output files. For example, if the storage service |
| 73 | + * stores the output files under "/sdcard/test_output_files", with a pathname |
| 74 | + * "/path/to/my_output.txt", the file will end up at |
| 75 | + * "/sdcard/test_output_files/path/to/my_output.txt" on device. |
| 76 | + * @return an OutputStream to the given output file. |
| 77 | + */ |
| 78 | + OutputStream openOutputFile(String pathname) throws IOException; |
| 79 | + |
| 80 | + /** |
| 81 | + * Adds the given properties. |
| 82 | + * |
| 83 | + * <p>Adding a property with the same name would append new values and overwrite the old values if |
| 84 | + * keys already exist. |
| 85 | + */ |
| 86 | + void addOutputProperties(Map<String, Serializable> properties); |
| 87 | + |
| 88 | + /** |
| 89 | + * Returns a map of all the output test properties. If no properties exist, an empty map will be |
| 90 | + * returned. |
| 91 | + */ |
| 92 | + Map<String, Serializable> getOutputProperties(); |
| 93 | +} |
0 commit comments