Home | History | Annotate | Download | only in file
      1 /*
      2  * Copyright (C) 2016 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 libcore.java.nio.file;
     18 
     19 import java.nio.file.FileSystemNotFoundException;
     20 import java.nio.file.InvalidPathException;
     21 import java.util.ArrayList;
     22 import java.util.List;
     23 
     24 /**
     25  * The class provides test cases to libcore.java.nio.file.PathsTest#test_get_URI,
     26  * libcore.java.nio.file.PathsTest#test_get_String,
     27  * libcore.java.nio.file.LinuxFileSystemTest#test_getPath
     28  */
     29 class LinuxFileSystemTestData {
     30     static List<TestData> getPathInputOutputTestData() {
     31         List<TestData> inputOutputTestCases = new ArrayList<>();
     32         inputOutputTestCases.add(new TestData("d1", "d1"));
     33         inputOutputTestCases.add(new TestData("", ""));
     34         inputOutputTestCases.add(new TestData("/", "//"));
     35         inputOutputTestCases.add(new TestData("d1/d2/d3", "d1//d2/d3"));
     36         inputOutputTestCases.add(new TestData("d1/d2", "d1", "", "d2"));
     37         inputOutputTestCases.add(new TestData("foo", "", "foo"));
     38 
     39         // If the name separator is "/" and getPath("/foo","bar","gus") is invoked, then the path
     40         // string "/foo/bar/gus" is converted to a Path.
     41         inputOutputTestCases.add(new TestData("/foo/bar/gus", "/foo", "bar", "gus"));
     42         return inputOutputTestCases;
     43     }
     44 
     45     static List<TestData> getPathExceptionTestData() {
     46         List<TestData> exceptionTestCases = new ArrayList<>();
     47         exceptionTestCases.add(new TestData(InvalidPathException.class, "'\u0000'"));
     48         exceptionTestCases.add(new TestData(NullPointerException.class, null));
     49         return exceptionTestCases;
     50     }
     51 
     52     static List<TestData> getPath_URI_InputOutputTestData() {
     53         // As of today, there is only one installed provider - LinuxFileSystemProvider and
     54         // only scheme supported by it is "file".
     55         List<TestData> inputOutputTestCases = new ArrayList<>();
     56         inputOutputTestCases.add(new TestData("/d1", "file:///d1"));
     57         inputOutputTestCases.add(new TestData("/", "file:///"));
     58         inputOutputTestCases.add(new TestData("/d1//d2/d3", "file:///d1//d2/d3"));
     59         return inputOutputTestCases;
     60     }
     61 
     62     static List<TestData> getPath_URI_ExceptionTestData() {
     63         List<TestData> exceptionTestCases = new ArrayList<>();
     64         exceptionTestCases.add(new TestData(IllegalArgumentException.class, "d1"));
     65         exceptionTestCases.add(new TestData(FileSystemNotFoundException.class, "scheme://d"));
     66         exceptionTestCases.add(new TestData(NullPointerException.class, null));
     67         exceptionTestCases.add(new TestData(IllegalArgumentException.class, "file:///d#row=4"));
     68         exceptionTestCases.add(new TestData(IllegalArgumentException.class, "file:///d?q=5"));
     69         exceptionTestCases.add(new TestData(IllegalArgumentException.class, "file://d:5000"));
     70         return exceptionTestCases;
     71     }
     72 
     73     static class TestData {
     74         public String output;
     75         public String input;
     76         public String[] inputArray;
     77         public Class exceptionClass;
     78 
     79         TestData(String output, String input, String... inputArray) {
     80             this.output = output;
     81             this.input = input;
     82             this.inputArray = inputArray;
     83         }
     84 
     85         TestData(Class exceptionClass, String input, String... inputArray) {
     86             this.exceptionClass = exceptionClass;
     87             this.input = input;
     88             this.inputArray = inputArray;
     89         }
     90     }
     91 }