Home | History | Annotate | Download | only in writeexternalstorageapp
      1 /*
      2  * Copyright (C) 2015 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 
     17 package com.android.cts.writeexternalstorageapp;
     18 
     19 import static com.android.cts.externalstorageapp.CommonExternalStorageTest.PACKAGE_NONE;
     20 import static com.android.cts.externalstorageapp.CommonExternalStorageTest.PACKAGE_READ;
     21 import static com.android.cts.externalstorageapp.CommonExternalStorageTest.PACKAGE_WRITE;
     22 import static com.android.cts.externalstorageapp.CommonExternalStorageTest.assertFileReadWriteAccess;
     23 import static com.android.cts.externalstorageapp.CommonExternalStorageTest.getAllPackageSpecificGiftPaths;
     24 import static com.android.cts.externalstorageapp.CommonExternalStorageTest.readInt;
     25 import static com.android.cts.externalstorageapp.CommonExternalStorageTest.writeInt;
     26 
     27 import android.test.AndroidTestCase;
     28 
     29 import java.io.File;
     30 import java.util.List;
     31 
     32 public class WriteGiftTest extends AndroidTestCase {
     33     /**
     34      * Leave gifts for other packages in their primary external cache dirs.
     35      */
     36     public void testGifts() throws Exception {
     37         final List<File> noneList = getAllPackageSpecificGiftPaths(getContext(), PACKAGE_NONE);
     38         for (File none : noneList) {
     39             none.getParentFile().mkdirs();
     40             none.createNewFile();
     41             assertFileReadWriteAccess(none);
     42 
     43             writeInt(none, 100);
     44             assertEquals(100, readInt(none));
     45         }
     46 
     47         final List<File> readList = getAllPackageSpecificGiftPaths(getContext(), PACKAGE_READ);
     48         for (File read : readList) {
     49             read.getParentFile().mkdirs();
     50             read.createNewFile();
     51             assertFileReadWriteAccess(read);
     52 
     53             writeInt(read, 101);
     54             assertEquals(101, readInt(read));
     55         }
     56 
     57         final List<File> writeList = getAllPackageSpecificGiftPaths(getContext(), PACKAGE_WRITE);
     58         for (File write : writeList) {
     59             write.getParentFile().mkdirs();
     60             write.createNewFile();
     61             assertFileReadWriteAccess(write);
     62 
     63             writeInt(write, 102);
     64             assertEquals(102, readInt(write));
     65         }
     66     }
     67 }
     68