|
| 1 | +/* |
| 2 | + * Copyright 2013 Google Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 5 | + * use this file except in compliance with the License. You may obtain a copy of |
| 6 | + * 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, WITHOUT |
| 12 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | + * License for the specific language governing permissions and limitations under |
| 14 | + * the License. |
| 15 | + */ |
| 16 | +package com.google.gwt.dev; |
| 17 | + |
| 18 | +import com.google.gwt.dev.util.arg.ArgHandlerDraftCompile; |
| 19 | +import com.google.gwt.dev.util.arg.ArgHandlerOptimize; |
| 20 | +import com.google.gwt.dev.util.arg.OptionAggressivelyOptimize; |
| 21 | +import com.google.gwt.dev.util.arg.OptionOptimize; |
| 22 | + |
| 23 | +/** |
| 24 | + * Test for {@link ArgProcessorBase}. |
| 25 | + */ |
| 26 | +public class ArgProcessorBaseTest extends ArgProcessorTestBase { |
| 27 | + |
| 28 | + private static class OptimizationOptions implements OptionOptimize, OptionAggressivelyOptimize { |
| 29 | + |
| 30 | + private boolean aggressivelyOptimize; |
| 31 | + private int level; |
| 32 | + |
| 33 | + @Override |
| 34 | + public int getOptimizationLevel() { |
| 35 | + return level; |
| 36 | + } |
| 37 | + |
| 38 | + @Override |
| 39 | + public boolean isAggressivelyOptimize() { |
| 40 | + return aggressivelyOptimize; |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + public void setAggressivelyOptimize(boolean aggressivelyOptimize) { |
| 45 | + this.aggressivelyOptimize = aggressivelyOptimize; |
| 46 | + } |
| 47 | + |
| 48 | + @Override |
| 49 | + public void setOptimizationLevel(int level) { |
| 50 | + this.level = level; |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + private static class OptimizeArgProcessor extends ArgProcessorBase { |
| 55 | + public OptimizeArgProcessor(OptimizationOptions option) { |
| 56 | + registerHandler(new ArgHandlerDraftCompile(option)); |
| 57 | + registerHandler(new ArgHandlerOptimize(option)); |
| 58 | + } |
| 59 | + |
| 60 | + @Override |
| 61 | + protected String getName() { |
| 62 | + return this.getClass().getSimpleName(); |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + private final OptimizeArgProcessor argProcessor; |
| 67 | + private final OptimizationOptions options = new OptimizationOptions(); |
| 68 | + |
| 69 | + public ArgProcessorBaseTest() { |
| 70 | + argProcessor = new OptimizeArgProcessor(options); |
| 71 | + } |
| 72 | + |
| 73 | + public void testOptionOrderIsPrecedenceArgs() { |
| 74 | + assertProcessSuccess(argProcessor); |
| 75 | + assertEquals(0, options.getOptimizationLevel()); |
| 76 | + |
| 77 | + assertProcessSuccess(argProcessor, "-optimize", "5"); |
| 78 | + assertEquals(5, options.getOptimizationLevel()); |
| 79 | + |
| 80 | + assertProcessSuccess(argProcessor, "-optimize", "5", "-draftCompile"); |
| 81 | + assertEquals(0, options.getOptimizationLevel()); |
| 82 | + |
| 83 | + assertProcessSuccess(argProcessor, "-optimize", "5", "-draftCompile", "-optimize", "9"); |
| 84 | + assertEquals(9, options.getOptimizationLevel()); |
| 85 | + } |
| 86 | +} |
0 commit comments