Skip to content

Commit 70805a4

Browse files
brettchabotcopybara-androidxtest
authored andcommitted
Initial change to upstream TestStorage get*Uri methods to PlatformTestStorage.
This change is part of series of changes to promote PlatformTestStorage as the canonical API for managing storage. TestStorage, from an API POV, will become an implementation detail. Unfortunately the get*Uri methods are static, so this change requires changing the methods from static to non-static. PiperOrigin-RevId: 604438295
1 parent 4a23812 commit 70805a4

File tree

9 files changed

+107
-1
lines changed

9 files changed

+107
-1
lines changed

core/javatests/androidx/test/core/graphics/BitmapStorageTest.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package androidx.test.core.graphics
1717

1818
import android.graphics.Bitmap
19+
import android.net.Uri
1920
import androidx.test.ext.junit.runners.AndroidJUnit4
2021
import androidx.test.platform.io.PlatformTestStorage
2122
import java.io.IOException
@@ -80,6 +81,14 @@ class BitmapStorageTest {
8081
TODO("Not yet implemented")
8182
}
8283

84+
override fun getInputFileUri2(pathname: String): Uri {
85+
TODO("Not yet implemented")
86+
}
87+
88+
override fun getOutputFileUri2(pathname: String): Uri {
89+
TODO("Not yet implemented")
90+
}
91+
8392
override fun isTestStorageFilePath(pathname: String): Boolean {
8493
TODO("Not yet implemented")
8594
}

espresso/core/javatests/androidx/test/espresso/internal/data/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ axt_android_library_test(
1414
"TestFlowVisualizerTest.java",
1515
],
1616
deps = [
17+
"//core/java/androidx/test/core",
1718
"//espresso/core/java/androidx/test/espresso",
1819
"//espresso/core/java/androidx/test/espresso/internal/data",
1920
"//espresso/core/java/androidx/test/espresso/internal/data/model",

runner/android_junit_runner/javatests/androidx/test/internal/runner/RunnerArgsTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import static org.junit.Assert.fail;
2828
import static org.junit.Assume.assumeFalse;
2929

30+
import android.net.Uri;
3031
import android.os.Build;
3132
import android.os.Bundle;
3233
import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -756,6 +757,16 @@ public OutputStream openInternalOutputFile(String pathname) throws IOException {
756757
throw new UnsupportedOperationException();
757758
}
758759

760+
@Override
761+
public Uri getInputFileUri2(String pathname) {
762+
throw new UnsupportedOperationException();
763+
}
764+
765+
@Override
766+
public Uri getOutputFileUri2(String pathname) {
767+
throw new UnsupportedOperationException();
768+
}
769+
759770
@Override
760771
public boolean isTestStorageFilePath(String pathname) {
761772
return false;

runner/monitor/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
**API Changes**
1414
* Make DeviceController an public API from ExperimentalTestApi
1515
* Upstream TestStorage.isTestStoragePath to PlatformTestStorage
16+
* Upstream TestStorage.getInputFileUri and getOutputFileUri to PlatformTestStorage
1617

1718
**Breaking API Changes**
1819

runner/monitor/java/androidx/test/platform/io/FileTestStorage.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package androidx.test.platform.io;
1717

18+
import android.net.Uri;
1819
import android.os.Bundle;
1920
import android.util.Log;
2021
import androidx.annotation.NonNull;
@@ -142,6 +143,20 @@ public OutputStream openInternalOutputFile(String pathname) throws IOException {
142143
return openOutputFile(pathname);
143144
}
144145

146+
@Override
147+
public Uri getInputFileUri2(@NonNull String pathname) {
148+
throw new UnsupportedOperationException();
149+
}
150+
151+
@Override
152+
public Uri getOutputFileUri2(@NonNull String pathname) {
153+
File outputFile = new File(pathname);
154+
if (!outputFile.isAbsolute()) {
155+
outputFile = new File(outputDirCalculator.getOutputDir(), pathname);
156+
}
157+
return Uri.fromFile(outputFile);
158+
}
159+
145160
@Override
146161
public boolean isTestStorageFilePath(@NonNull String pathname) {
147162
String outputDir = outputDirCalculator.getOutputDir().getAbsolutePath();

runner/monitor/java/androidx/test/platform/io/PlatformTestStorage.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package androidx.test.platform.io;
1717

18+
import android.net.Uri;
1819
import androidx.annotation.NonNull;
1920
import androidx.test.annotation.ExperimentalTestApi;
2021
import java.io.IOException;
@@ -106,6 +107,42 @@ public interface PlatformTestStorage {
106107
*/
107108
OutputStream openInternalOutputFile(String pathname) throws IOException;
108109

110+
/**
111+
* Provides a Uri to a test file dependency.
112+
*
113+
* <p>In most of the cases, you would use {@link #openInputFile(String)} for opening up an
114+
* InputStream to the input file content immediately. Only use this method if you would like to
115+
* store the file Uri and use it for I/O operations later.
116+
*
117+
* <p><b>Note:</b> temporary API - will be renamed to getInpFileUri in future
118+
*
119+
* @param pathname path to the test file dependency. Should not be null. This is a relative path
120+
* to where the storage service stores the input files. For example, if the storage service
121+
* stores the input files under "/sdcard/test_input_files", with a pathname
122+
* "/path/to/my_input.txt", the file will end up at
123+
* "/sdcard/test_input_files/path/to/my_input.txt" on device.
124+
* @return a content Uri to the test file dependency.
125+
* <p>Note: temporary API - will be renamed to getInputFileUri in future
126+
*/
127+
Uri getInputFileUri2(@NonNull String pathname);
128+
129+
/**
130+
* Provides a Uri to a test output file.
131+
*
132+
* <p>In most of the cases, you would use {@link #openOutputFile(String)} for opening up an
133+
* OutputStream to the output file content immediately. Only use this method if you would like to
134+
* store the file Uri and use it for I/O operations later.
135+
*
136+
* <p><b>Note:</b> temporary API - will be renamed to getOutputFileUri in future
137+
*
138+
* @param pathname path to the test output file. Should not be null. This is a relative path to
139+
* where the storage service stores the output files. For example, if the storage service
140+
* stores the output files under "/sdcard/test_output_files", with a pathname
141+
* "/path/to/my_output.txt", the file will end up at
142+
* "/sdcard/test_output_files/path/to/my_output.txt" on device.
143+
*/
144+
Uri getOutputFileUri2(@NonNull String pathname);
145+
109146
/**
110147
* Returns true if {@code pathname} corresponds to a file or directory that is in a directory
111148
* where the storage stores files.

runner/monitor/java/androidx/test/platform/io/PlatformTestStorageRegistry.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import static androidx.test.internal.util.Checks.checkNotNull;
1919

20+
import android.net.Uri;
2021
import androidx.annotation.NonNull;
2122
import androidx.test.annotation.ExperimentalTestApi;
2223
import androidx.test.internal.platform.ServiceLoaderWrapper;
@@ -117,6 +118,16 @@ public OutputStream openInternalOutputFile(String pathname) throws IOException {
117118
return new NullOutputStream();
118119
}
119120

121+
@Override
122+
public Uri getInputFileUri2(@NonNull String pathname) {
123+
return null;
124+
}
125+
126+
@Override
127+
public Uri getOutputFileUri2(@NonNull String pathname) {
128+
return null;
129+
}
130+
120131
@Override
121132
public boolean isTestStorageFilePath(@NonNull String pathname) {
122133
return false;

services/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
**API Changes**
1414

1515
* Upstream TestStorage.isTestStoragePath to PlatformTestStorage
16+
* Upstream TestStorage.getInputFileUri and getOutputFileUri to PlatformTestStorage
1617

1718
**Breaking API Changes**
1819

services/storage/java/androidx/test/services/storage/TestStorage.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ public TestStorage(@NonNull ContentResolver contentResolver) {
7676
this.contentResolver = contentResolver;
7777
}
7878

79+
/**
80+
* @deprecated call getInputFileUri2 instead
81+
*/
82+
@Deprecated
83+
public static Uri getInputFileUri(@NonNull String pathname) {
84+
checkNotNull(pathname);
85+
return HostedFile.buildUri(HostedFile.FileHost.TEST_FILE, pathname);
86+
}
87+
7988
/**
8089
* Provides a Uri to a test file dependency.
8190
*
@@ -90,7 +99,8 @@ public TestStorage(@NonNull ContentResolver contentResolver) {
9099
* "/sdcard/test_input_files/path/to/my_input.txt" on device.
91100
* @return a content Uri to the test file dependency.
92101
*/
93-
public static Uri getInputFileUri(@NonNull String pathname) {
102+
@Override
103+
public Uri getInputFileUri2(@NonNull String pathname) {
94104
checkNotNull(pathname);
95105
return HostedFile.buildUri(HostedFile.FileHost.TEST_FILE, pathname);
96106
}
@@ -108,6 +118,16 @@ public static Uri getInputFileUri(@NonNull String pathname) {
108118
* "/path/to/my_output.txt", the file will end up at
109119
* "/sdcard/test_output_files/path/to/my_output.txt" on device.
110120
*/
121+
@Override
122+
public Uri getOutputFileUri2(@NonNull String pathname) {
123+
checkNotNull(pathname);
124+
return HostedFile.buildUri(HostedFile.FileHost.OUTPUT, pathname);
125+
}
126+
127+
/**
128+
* @deprecated call getOutputFileUri2 instead
129+
*/
130+
@Deprecated
111131
public static Uri getOutputFileUri(@NonNull String pathname) {
112132
checkNotNull(pathname);
113133
return HostedFile.buildUri(HostedFile.FileHost.OUTPUT, pathname);

0 commit comments

Comments
 (0)