Home | History | Annotate | Download | only in testtype
      1 /*
      2  * Copyright (C) 2010 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.tradefed.testtype;
     17 
     18 import junit.framework.TestCase;
     19 
     20 /**
     21  * Unit tests for {@link NativeStressTestParser}.
     22  */
     23 public class NativeStressTestParserTest extends TestCase {
     24 
     25     private static final String RUN_NAME = "run-name";
     26     private NativeStressTestParser mParser;
     27 
     28     /**
     29      * {@inheritDoc}
     30      */
     31     @Override
     32     protected void setUp() throws Exception {
     33         super.setUp();
     34         mParser = new NativeStressTestParser(RUN_NAME);
     35     }
     36 
     37     /**
     38      * Test a run with no content.
     39      * <p/>
     40      * Expect 0 iterations to be reported
     41      */
     42     public void testParse_empty() {
     43         mParser.processNewLines(new String[] {});
     44         mParser.done();
     45         verifyExpectedIterations(0);
     46     }
     47 
     48     /**
     49      * Test a run with garbage content.
     50      * <p/>
     51      * Expect 0 iterations to be reported
     52      */
     53     public void testParse_garbage() {
     54         mParser.processNewLines(new String[] {"blah blah", "more blah"});
     55         mParser.done();
     56         verifyExpectedIterations(0);
     57     }
     58 
     59     /**
     60      * Test a run with valid one iteration.
     61      * <p/>
     62      * Expect 1 iterations to be reported
     63      */
     64     public void testParse_oneIteration() {
     65         mParser.processNewLines(new String[] {"==== Completed pass: 0"});
     66         mParser.done();
     67         verifyExpectedIterations(1);
     68     }
     69 
     70     /**
     71      * Test that iteration data with varying whitespace is parsed successfully.
     72      * <p/>
     73      * Expect 2 iterations to be reported
     74      */
     75     public void testParse_whitespace() {
     76         mParser.processNewLines(new String[] {"====Completedpass:0succeeded",
     77                 "====  Completed  pass:   1  "});
     78         mParser.done();
     79         verifyExpectedIterations(2);
     80     }
     81 
     82     /**
     83      * Test that an invalid iteration value is ignored
     84      */
     85     public void testParse_invalidIterationValue() {
     86         mParser.processNewLines(new String[] {"==== Completed pass: 0", "==== Completed pass: 1",
     87                 "==== Completed pass: b", "Successfully completed 3 passes"});
     88         mParser.done();
     89         verifyExpectedIterations(2);
     90     }
     91 
     92     /**
     93      * Test that failed iterations are ignored
     94      */
     95     public void testParse_failedIteration() {
     96         mParser.processNewLines(new String[] {"==== Completed pass: 0", "==== pass: 1 failed"});
     97         mParser.done();
     98         verifyExpectedIterations(1);
     99     }
    100 
    101     /**
    102      * Verify the iteration count collected by the parser
    103      */
    104     private void verifyExpectedIterations(int iterations) {
    105         assertEquals(iterations, mParser.getIterationsCompleted());
    106     }
    107 }
    108