1 /* 2 * Copyright 2022 Google LLC 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 com.google.android.libraries.mobiledatadownload.file.openers; 17 18 import static org.junit.Assert.assertThrows; 19 20 import android.os.Build; 21 import com.google.android.libraries.mobiledatadownload.file.common.UnsupportedFileStorageOperation; 22 import com.google.thirdparty.robolectric.GoogleRobolectricTestRunner; 23 import java.io.File; 24 import java.util.concurrent.atomic.AtomicInteger; 25 import org.junit.Rule; 26 import org.junit.Test; 27 import org.junit.rules.TemporaryFolder; 28 import org.junit.runner.RunWith; 29 import org.robolectric.annotation.Config; 30 31 /** Basic test to ensure that named pipes are only attempted at compatible sdk levels. */ 32 @RunWith(GoogleRobolectricTestRunner.class) 33 public final class PipesTest { 34 35 @Rule public TemporaryFolder tmpFolder = new TemporaryFolder(); 36 37 private static final String TAG = "PipesTest"; 38 private static final AtomicInteger FIFO_COUNTER = new AtomicInteger(); 39 40 @Test 41 @Config(sdk = {Build.VERSION_CODES.KITKAT}) makeFifo_belowLollipop_throwsUnsupportedFileStorageOperation()42 public void makeFifo_belowLollipop_throwsUnsupportedFileStorageOperation() throws Exception { 43 assertThrows( 44 UnsupportedFileStorageOperation.class, 45 () -> Pipes.makeFifo(tmpFolder.newFolder(), TAG, FIFO_COUNTER)); 46 } 47 48 @Test 49 @Config(sdk = {Build.VERSION_CODES.LOLLIPOP}) makeFifo_onLollipop_doesNotThrow()50 public void makeFifo_onLollipop_doesNotThrow() throws Exception { 51 // NOTE: the resultant pipe is invalid because Robolectric doesn't fully support 52 // Os.mkFifo, but we're happy as long as the call succeeds 53 File unusedFifo = Pipes.makeFifo(tmpFolder.newFolder(), TAG, FIFO_COUNTER); 54 } 55 } 56