Home | History | Annotate | Download | only in nativescanner
      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.BufferedReader;
     23 import java.io.IOException;
     24 import java.io.StringReader;
     25 import java.util.List;
     26 import java.util.Iterator;
     27 
     28 /**
     29  * Unit tests for {@link TestScanner}.
     30  */
     31 public class TestScannerTest extends TestCase {
     32 
     33     public void testSingleTestNamesCase() throws Exception {
     34         StringReader singleTestString = new StringReader("FakeTestCase.\n  FakeTestName\n");
     35         BufferedReader reader = new BufferedReader(singleTestString);
     36 
     37         TestScanner testScanner = new TestScanner(reader, "TestSuite");
     38 
     39         List<String> names = testScanner.getTestNames();
     40         Iterator it = names.iterator();
     41         assertEquals("suite:TestSuite", it.next());
     42         assertEquals("case:FakeTestCase", it.next());
     43         assertEquals("test:FakeTestName", it.next());
     44         assertFalse(it.hasNext());
     45     }
     46 
     47     public void testMultipleTestNamesCase() throws Exception {
     48         StringReader singleTestString = new StringReader(
     49           "Case1.\n  Test1\n  Test2\nCase2.\n  Test3\n Test4\n");
     50         BufferedReader reader = new BufferedReader(singleTestString);
     51 
     52         TestScanner testScanner = new TestScanner(reader, "TestSuite");
     53 
     54         List<String> names = testScanner.getTestNames();
     55         Iterator it = names.iterator();
     56         assertEquals("suite:TestSuite", it.next());
     57         assertEquals("case:Case1", it.next());
     58         assertEquals("test:Test1", it.next());
     59         assertEquals("test:Test2", it.next());
     60         assertEquals("case:Case2", it.next());
     61         assertEquals("test:Test3", it.next());
     62         assertEquals("test:Test4", it.next());
     63         assertFalse(it.hasNext());
     64     }
     65 
     66     public void testMissingTestCaseNameCase() {
     67         StringReader singleTestString = new StringReader("  Test1\n");
     68         BufferedReader reader = new BufferedReader(singleTestString);
     69 
     70         TestScanner testScanner = new TestScanner(reader, "TestSuite");
     71 
     72         try {
     73           List<String> names = testScanner.getTestNames();
     74           fail();
     75         } catch (IOException expected) {
     76         }
     77     }
     78 }
     79