1 /* 2 * Copyright (C) 2014 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.compatibility.common.scanner; 18 19 import com.android.compatibility.common.scanner.NativeScanner; 20 21 import junit.framework.TestCase; 22 23 import java.io.BufferedReader; 24 import java.io.IOException; 25 import java.io.StringReader; 26 import java.util.List; 27 import java.util.Iterator; 28 29 public class NativeScannerTest extends TestCase { 30 testSingleTestNamesCase()31 public void testSingleTestNamesCase() throws Exception { 32 StringReader singleTestString = new StringReader("FakeTestCase.\n FakeTestName\n"); 33 BufferedReader reader = new BufferedReader(singleTestString); 34 35 List<String> names = NativeScanner.getTestNames(reader, "TestSuite"); 36 Iterator<String> it = names.iterator(); 37 assertEquals("suite:TestSuite", it.next()); 38 assertEquals("case:FakeTestCase", it.next()); 39 assertEquals("test:FakeTestName", it.next()); 40 assertFalse(it.hasNext()); 41 } 42 testMultipleTestNamesCase()43 public void testMultipleTestNamesCase() throws Exception { 44 StringReader singleTestString = new StringReader( 45 "Case1.\n Test1\n Test2\nCase2.\n Test3\n Test4\n"); 46 BufferedReader reader = new BufferedReader(singleTestString); 47 48 List<String> names = NativeScanner.getTestNames(reader, "TestSuite"); 49 50 Iterator<String> it = names.iterator(); 51 assertEquals("suite:TestSuite", it.next()); 52 assertEquals("case:Case1", it.next()); 53 assertEquals("test:Test1", it.next()); 54 assertEquals("test:Test2", it.next()); 55 assertEquals("case:Case2", it.next()); 56 assertEquals("test:Test3", it.next()); 57 assertEquals("test:Test4", it.next()); 58 assertFalse(it.hasNext()); 59 } 60 testMissingTestCaseNameCase()61 public void testMissingTestCaseNameCase() throws IOException { 62 StringReader singleTestString = new StringReader(" Test1\n"); 63 BufferedReader reader = new BufferedReader(singleTestString); 64 65 try { 66 NativeScanner.getTestNames(reader, "TestSuite"); 67 fail("Expected RuntimeException"); 68 } catch (RuntimeException expected) {} 69 } 70 } 71