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         String cmd2 = MONKEY_CMD + " -s 3007 -v -p " + PKGS[0] + " 125";
     30         String out3 = mDevice.executeShellCommand(cmd2);
     31         String out4 = mDevice.executeShellCommand(cmd2);
     32         assertOutputs(out3, out4);
     33     }
     34 
     35     private void assertOutputs(String out1, String out2) {
     36         Scanner s1 = new Scanner(out1);
     37         Scanner s2 = new Scanner(out2);
     38         int numEvents = 0;
     39         while (true) {
     40             String line1 = getNextLine(s1);
     41             String line2 = getNextLine(s2);
     42             if (line1 != null || line2 != null) {
     43                 assertEquals(line1, line2);
     44                 numEvents++;
     45             } else {
     46                 break;
     47             }
     48         }
     49         assertTrue(numEvents > 0);
     50     }
     51 
     52     private String getNextLine(Scanner sc) {
     53         while (sc.hasNextLine()) {
     54             String line = sc.nextLine().trim();
     55             if (line.startsWith(":Sending")) {
     56                 return line;
     57             }
     58         }
     59         return null;
     60     }
     61 }
     62