Home | History | Annotate | Download | only in monkey
      1 /*
      2  * Copyright (C) 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 
     17 package com.android.cts.monkey;
     18 
     19 import java.util.Scanner;
     20 
     21 public class SeedTest extends AbstractMonkeyTest {
     22 
     23     public void testSeed() throws Exception {
     24         String cmd1 = MONKEY_CMD + " -s 1337 -v -p " + PKGS[0] + " 500";
     25         String out1 = mDevice.executeShellCommand(cmd1);
     26         String out2 = mDevice.executeShellCommand(cmd1);
     27         assertOutputs(out1, out2);
     28     }
     29 
     30     public void testSeed2() throws Exception {
     31         String cmd2 = MONKEY_CMD + " -s 3007 -v -p " + PKGS[0] + " 125";
     32         String out3 = mDevice.executeShellCommand(cmd2);
     33         String out4 = mDevice.executeShellCommand(cmd2);
     34         assertOutputs(out3, out4);
     35     }
     36 
     37     private void assertOutputs(String out1, String out2) {
     38         Scanner s1 = new Scanner(out1);
     39         Scanner s2 = new Scanner(out2);
     40         int numEvents = 0;
     41         while (true) {
     42             String line1 = getNextLine(s1);
     43             String line2 = getNextLine(s2);
     44             if (line1 != null || line2 != null) {
     45                 assertEquals(line1, line2);
     46                 numEvents++;
     47             } else {
     48                 break;
     49             }
     50         }
     51         assertTrue(numEvents > 0);
     52     }
     53 
     54     private String getNextLine(Scanner sc) {
     55         while (sc.hasNextLine()) {
     56             String line = sc.nextLine().trim();
     57             if (line.startsWith(":Sending")) {
     58                 return line;
     59             }
     60         }
     61         return null;
     62     }
     63 }
     64