blob: c7070a573ef0fa7fff167f9de8c1b3cdb67965fe [file] [log] [blame]
Brian Muramatsu7f64e852011-02-17 16:52:16 -08001/*
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
17import vogar.Expectation;
18import vogar.ExpectationStore;
19import vogar.ModeId;
20
21import java.io.File;
22import java.io.FilenameFilter;
23import java.io.IOException;
24import java.util.Arrays;
25import java.util.HashSet;
26import java.util.Set;
27
28public class VogarUtils {
29
Brian Carlstrom022aff42011-05-17 23:16:51 -070030 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 Muramatsu7f64e852011-02-17 16:52:16 -080041 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}