Brian Muramatsu | 7f64e85 | 2011-02-17 16:52:16 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | import vogar.Expectation; |
| 18 | import vogar.ExpectationStore; |
| 19 | import vogar.ModeId; |
| 20 | |
| 21 | import java.io.File; |
| 22 | import java.io.FilenameFilter; |
| 23 | import java.io.IOException; |
| 24 | import java.util.Arrays; |
| 25 | import java.util.HashSet; |
| 26 | import java.util.Set; |
| 27 | |
| 28 | public class VogarUtils { |
| 29 | |
Brian Carlstrom | 022aff4 | 2011-05-17 23:16:51 -0700 | [diff] [blame] | 30 | public static boolean isVogarKnownFailure(ExpectationStore[] expectationStores, |
| 31 | final String testClassName, |
| 32 | final String testMethodName) { |
| 33 | for (ExpectationStore expectationStore : expectationStores) { |
| 34 | if (isVogarKnownFailure(expectationStore, testClassName, testMethodName)) { |
| 35 | return true; |
| 36 | } |
| 37 | } |
| 38 | return false; |
| 39 | } |
| 40 | |
Brian Muramatsu | 7f64e85 | 2011-02-17 16:52:16 -0800 | [diff] [blame] | 41 | public static boolean isVogarKnownFailure(ExpectationStore expectationStore, |
| 42 | final String testClassName, |
| 43 | final String testMethodName) { |
| 44 | String fullTestName = String.format("%s#%s", testClassName, testMethodName); |
| 45 | return expectationStore != null |
| 46 | && expectationStore.get(fullTestName) != Expectation.SUCCESS; |
| 47 | } |
| 48 | |
| 49 | public static ExpectationStore provideExpectationStore(String dir) throws IOException { |
| 50 | if (dir == null) { |
| 51 | return null; |
| 52 | } |
| 53 | ExpectationStore result = ExpectationStore.parse(getExpectationFiles(dir), ModeId.DEVICE); |
| 54 | return result; |
| 55 | } |
| 56 | |
| 57 | private static Set<File> getExpectationFiles(String dir) { |
| 58 | Set<File> expectSet = new HashSet<File>(); |
| 59 | File[] files = new File(dir).listFiles(new FilenameFilter() { |
| 60 | // ignore obviously temporary files |
| 61 | public boolean accept(File dir, String name) { |
| 62 | return !name.endsWith("~") && !name.startsWith("."); |
| 63 | } |
| 64 | }); |
| 65 | if (files != null) { |
| 66 | expectSet.addAll(Arrays.asList(files)); |
| 67 | } |
| 68 | return expectSet; |
| 69 | } |
| 70 | } |