Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(292)

Side by Side Diff: base/android/javatests/src/org/chromium/base/CommandLineTest.java

Issue 62333025: [Android] Move CommandLine.java to base (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Split CommandLineTest Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/android/java/src/org/chromium/base/CommandLine.java ('k') | base/base.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.content.browser; 5 package org.chromium.base;
6 6
7 import android.test.InstrumentationTestCase; 7 import android.test.InstrumentationTestCase;
8 import android.test.suitebuilder.annotation.MediumTest; 8 import android.test.suitebuilder.annotation.MediumTest;
9 import android.test.suitebuilder.annotation.SmallTest; 9 import android.test.suitebuilder.annotation.SmallTest;
10 10
11 import org.chromium.base.CommandLine;
11 import org.chromium.base.test.util.Feature; 12 import org.chromium.base.test.util.Feature;
12 import org.chromium.content.app.LibraryLoader;
13 import org.chromium.content.common.CommandLine;
14 import org.chromium.content.common.ProcessInitException;
15 import org.chromium.content_shell_apk.ContentShellActivity;
16 import org.chromium.content_shell_apk.ContentShellApplication;
17 13
18 public class CommandLineTest extends InstrumentationTestCase { 14 public class CommandLineTest extends InstrumentationTestCase {
19 // A reference command line. Note that switch2 is [brea\d], switch3 is [and "butter"], 15 // A reference command line. Note that switch2 is [brea\d], switch3 is [and "butter"],
20 // and switch4 is [a "quoted" 'food'!] 16 // and switch4 is [a "quoted" 'food'!]
21 static final String INIT_SWITCHES[] = { "init_command", "--SWITCH", "Arg", 17 static final String INIT_SWITCHES[] = { "init_command", "--SWITCH", "Arg",
22 "--switch2=brea\\d", "--switch3=and \"butter\"", 18 "--switch2=brea\\d", "--switch3=and \"butter\"",
23 "--switch4=a \"quoted\" 'food'!", 19 "--switch4=a \"quoted\" 'food'!",
24 "--", "--actually_an_arg" }; 20 "--", "--actually_an_arg" };
25 21
26 // The same command line, but in quoted string format. 22 // The same command line, but in quoted string format.
27 static final char INIT_SWITCHES_BUFFER[] = 23 static final char INIT_SWITCHES_BUFFER[] =
28 ("init_command --SWITCH Arg --switch2=brea\\d --switch3=\"and \\\"butt\" er\\\" " 24 ("init_command --SWITCH Arg --switch2=brea\\d --switch3=\"and \\\"butt\" er\\\" "
29 + "--switch4='a \"quoted\" \\'food\\'!' " 25 + "--switch4='a \"quoted\" \\'food\\'!' "
30 + "-- --actually_an_arg").toCharArray(); 26 + "-- --actually_an_arg").toCharArray();
31 27
32 static final String CL_ADDED_SWITCH = "zappo-dappo-doggy-trainer"; 28 static final String CL_ADDED_SWITCH = "zappo-dappo-doggy-trainer";
33 static final String CL_ADDED_SWITCH_2 = "username"; 29 static final String CL_ADDED_SWITCH_2 = "username";
34 static final String CL_ADDED_VALUE_2 = "bozo"; 30 static final String CL_ADDED_VALUE_2 = "bozo";
35 31
32 private static boolean sInitialized = false;
bulach 2013/11/19 12:18:09 nit: looks unused?
jdduke (slow) 2013/11/19 16:32:57 Done, good catch.
33
36 @Override 34 @Override
37 public void setUp() throws Exception { 35 public void setUp() throws Exception {
38 CommandLine.reset(); 36 CommandLine.reset();
39 } 37 }
40 38
41 void loadJni() {
42 assertFalse(CommandLine.getInstance().isNativeImplementation());
43 getInstrumentation().runOnMainSync(new Runnable() {
44 @Override
45 public void run() {
46 ContentShellApplication.initializeApplicationParameters();
47 try {
48 LibraryLoader.ensureInitialized();
49 } catch (ProcessInitException e) {
50 throw new Error(e);
51 }
52 }
53 });
54 assertTrue(CommandLine.getInstance().isNativeImplementation());
55 }
56
57 void checkInitSwitches() { 39 void checkInitSwitches() {
58 CommandLine cl = CommandLine.getInstance(); 40 CommandLine cl = CommandLine.getInstance();
59 assertFalse(cl.hasSwitch("init_command")); 41 assertFalse(cl.hasSwitch("init_command"));
60 assertFalse(cl.hasSwitch("switch")); 42 assertFalse(cl.hasSwitch("switch"));
61 assertTrue(cl.hasSwitch("SWITCH")); 43 assertTrue(cl.hasSwitch("SWITCH"));
62 assertFalse(cl.hasSwitch("--SWITCH")); 44 assertFalse(cl.hasSwitch("--SWITCH"));
63 assertFalse(cl.hasSwitch("Arg")); 45 assertFalse(cl.hasSwitch("Arg"));
64 assertFalse(cl.hasSwitch("actually_an_arg")); 46 assertFalse(cl.hasSwitch("actually_an_arg"));
65 assertEquals("brea\\d", cl.getSwitchValue("switch2")); 47 assertEquals("brea\\d", cl.getSwitchValue("switch2"));
66 assertEquals("and \"butter\"", cl.getSwitchValue("switch3")); 48 assertEquals("and \"butter\"", cl.getSwitchValue("switch3"));
(...skipping 21 matching lines...) Expand all
88 assertFalse(cl.hasSwitch("dummy")); 70 assertFalse(cl.hasSwitch("dummy"));
89 assertFalse(cl.hasSwitch("superfast")); 71 assertFalse(cl.hasSwitch("superfast"));
90 assertNull(cl.getSwitchValue("speed")); 72 assertNull(cl.getSwitchValue("speed"));
91 cl.appendSwitchesAndArguments(switchesAndArgs); 73 cl.appendSwitchesAndArguments(switchesAndArgs);
92 assertFalse(cl.hasSwitch("dummy")); 74 assertFalse(cl.hasSwitch("dummy"));
93 assertFalse(cl.hasSwitch("command")); 75 assertFalse(cl.hasSwitch("command"));
94 assertTrue(cl.hasSwitch("superfast")); 76 assertTrue(cl.hasSwitch("superfast"));
95 assertTrue("turbo".equals(cl.getSwitchValue("speed"))); 77 assertTrue("turbo".equals(cl.getSwitchValue("speed")));
96 } 78 }
97 79
98 void checkAppendedSwitchesPassedThrough() {
99 CommandLine cl = CommandLine.getInstance();
100 assertTrue(cl.hasSwitch(CL_ADDED_SWITCH));
101 assertTrue(cl.hasSwitch(CL_ADDED_SWITCH_2));
102 assertTrue(CL_ADDED_VALUE_2.equals(cl.getSwitchValue(CL_ADDED_SWITCH_2)) );
103 }
104
105 void checkTokenizer(String[] expected, String toParse) { 80 void checkTokenizer(String[] expected, String toParse) {
106 String[] actual = CommandLine.tokenizeQuotedAruments(toParse.toCharArray ()); 81 String[] actual = CommandLine.tokenizeQuotedAruments(toParse.toCharArray ());
107 assertEquals(expected.length, actual.length); 82 assertEquals(expected.length, actual.length);
108 for (int i = 0; i < expected.length; ++i) { 83 for (int i = 0; i < expected.length; ++i) {
109 assertEquals("comparing element " + i, expected[i], actual[i]); 84 assertEquals("comparing element " + i, expected[i], actual[i]);
110 } 85 }
111 } 86 }
112 87
113 @SmallTest 88 @SmallTest
114 @Feature({"Android-AppBase"}) 89 @Feature({"Android-AppBase"})
115 public void testJavaInitialization() { 90 public void testJavaInitialization() {
116 CommandLine.init(INIT_SWITCHES); 91 CommandLine.init(INIT_SWITCHES);
117 checkInitSwitches(); 92 checkInitSwitches();
118 checkSettingThenGetting(); 93 checkSettingThenGetting();
119 } 94 }
120 95
121 @MediumTest
122 @Feature({"Android-AppBase"})
123 public void testJavaNativeTransition() {
124 CommandLine.init(INIT_SWITCHES);
125 checkInitSwitches();
126 loadJni();
127 checkInitSwitches();
128 checkSettingThenGetting();
129 }
130
131 @MediumTest
132 @Feature({"Android-AppBase"})
133 public void testJavaNativeTransitionAfterAppends() {
134 CommandLine.init(INIT_SWITCHES);
135 checkInitSwitches();
136 checkSettingThenGetting();
137 loadJni();
138 checkInitSwitches();
139 checkAppendedSwitchesPassedThrough();
140 }
141
142 @MediumTest
143 @Feature({"Android-AppBase"})
144 public void testNativeInitialization() {
145 CommandLine.init(null);
146 loadJni();
147 // Drop the program name for use with appendSwitchesAndArguments.
148 String[] args = new String[INIT_SWITCHES.length - 1];
149 System.arraycopy(INIT_SWITCHES, 1, args, 0, args.length);
150 CommandLine.getInstance().appendSwitchesAndArguments(args);
151 checkInitSwitches();
152 checkSettingThenGetting();
153 }
154
155 @SmallTest 96 @SmallTest
156 @Feature({"Android-AppBase"}) 97 @Feature({"Android-AppBase"})
157 public void testBufferInitialization() { 98 public void testBufferInitialization() {
158 CommandLine.init(CommandLine.tokenizeQuotedAruments(INIT_SWITCHES_BUFFER )); 99 CommandLine.init(CommandLine.tokenizeQuotedAruments(INIT_SWITCHES_BUFFER ));
159 checkInitSwitches(); 100 checkInitSwitches();
160 checkSettingThenGetting(); 101 checkSettingThenGetting();
161 } 102 }
162 103
163 @SmallTest 104 @SmallTest
164 @Feature({"Android-AppBase"}) 105 @Feature({"Android-AppBase"})
(...skipping 16 matching lines...) Expand all
181 expected = new String[] { "a'b", 122 expected = new String[] { "a'b",
182 "c\"d", 123 "c\"d",
183 "e\"f", 124 "e\"f",
184 "g'h", 125 "g'h",
185 "i\\'j", 126 "i\\'j",
186 "k\\\"l", 127 "k\\\"l",
187 "mn\\'op", 128 "mn\\'op",
188 "qr\\\"st",}; 129 "qr\\\"st",};
189 checkTokenizer(expected, toParse); 130 checkTokenizer(expected, toParse);
190 } 131 }
191
192 @MediumTest
193 @Feature({"Android-AppBase"})
194 public void testFileInitialization() {
195 CommandLine.initFromFile(ContentShellActivity.COMMAND_LINE_FILE);
196 loadJni();
197 checkSettingThenGetting();
198 }
199 } 132 }
OLDNEW
« no previous file with comments | « base/android/java/src/org/chromium/base/CommandLine.java ('k') | base/base.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698