• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 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.tradefed.command;
18 
19 import com.android.tradefed.config.ArgsOptionParser;
20 import com.android.tradefed.config.ConfigurationException;
21 
22 import junit.framework.TestCase;
23 
24 /**
25  * Unit tests for {@link CommandOptions}
26  */
27 public class CommandOptionsTest extends TestCase {
28 
29     /**
30      * Test that {@link CommandOptions#getLoopTime()} returns min-loop-time when
31      * max-random-loop-time is not set.
32      */
testGetLoopTime_minset()33     public void testGetLoopTime_minset() throws ConfigurationException {
34         CommandOptions co = new CommandOptions();
35         ArgsOptionParser p = new ArgsOptionParser(co);
36         p.parse("--min-loop-time", "10");
37         assertEquals(10, co.getLoopTime());
38     }
39 
40     /**
41      * Test that {@link CommandOptions#getLoopTime()} returns a random time between min loop time
42      * and max-random-loop-time.
43      */
testGetLoopTime_maxrandomset()44     public void testGetLoopTime_maxrandomset() throws ConfigurationException {
45         CommandOptions co = new CommandOptions();
46         ArgsOptionParser p = new ArgsOptionParser(co);
47         p.parse("--max-random-loop-time", "10", "--min-loop-time", "5");
48 
49         long loop = co.getLoopTime();
50         assertTrue("Loop time less than min loop time " + loop, loop >= 5);
51         assertTrue("Loop time too high: " + loop, loop <= 10);
52     }
53 
54     /**
55      * Test that setting multiple --min-loop-time values results in the latest value provided
56      */
testGetLoopTime_least()57     public void testGetLoopTime_least() throws ConfigurationException {
58         CommandOptions co = new CommandOptions();
59         ArgsOptionParser p = new ArgsOptionParser(co);
60         p.parse("--min-loop-time", "5", "--min-loop-time", "0");
61         assertEquals(0, co.getLoopTime());
62     }
63 }
64