1 /* 2 * Copyright 2012 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 package com.android.cts.nativescanner; 17 18 import com.android.cts.nativescanner.TestScanner; 19 20 import junit.framework.TestCase; 21 22 import java.io.File; 23 import java.io.StringReader; 24 import java.lang.StringBuilder; 25 import java.util.Scanner; 26 import java.util.List; 27 import java.util.ArrayList; 28 import java.util.Iterator; 29 30 /** 31 * Unit tests for {@link TestScanner}. 32 */ 33 public class TestScannerTest extends TestCase { 34 testScanFile()35 public void testScanFile() { 36 TestScanner testScanner = new TestScanner(new File("unused"), "TestSuite"); 37 38 String newLine = System.getProperty("line.separator"); 39 StringBuilder sb = new StringBuilder(); 40 sb.append("foobar" + newLine); // ignored 41 sb.append("TEST_F(TestCase1, TestName1)" + newLine); // valid 42 sb.append("TEST_F(TestCase1, TestName2)" + newLine); // valid 43 sb.append("TEST_F(TestCase2, TestName1) foo" + newLine); // valid 44 sb.append("TEST_F(TestCase2, TestName1 foo)" + newLine); // ignored 45 sb.append("foo TEST_F(TestCase2, TestName1)" + newLine); // ignored 46 47 List<String> names = new ArrayList<String>(); 48 Scanner scanner = new Scanner(new StringReader(sb.toString())); 49 testScanner.scanFile(scanner, names); 50 Iterator it = names.iterator(); 51 52 assertEquals("suite:TestSuite", it.next()); 53 assertEquals("case:TestCase1", it.next()); 54 assertEquals("test:TestName1", it.next()); 55 assertEquals("test:TestName2", it.next()); 56 assertEquals("suite:TestSuite", it.next()); 57 assertEquals("case:TestCase2", it.next()); 58 assertEquals("test:TestName1", it.next()); 59 assertFalse(it.hasNext()); 60 scanner.close(); 61 } 62 } 63