public void testOneDimensionPermWithCollapse() { ModuleDef md = new ModuleDef("testOneDimensionPerm"); Properties properties = md.getProperties(); { BindingProperty bindingProperty = properties.createBinding("debug"); bindingProperty.addDefinedValue(bindingProperty.getRootCondition(), "false"); bindingProperty.addDefinedValue(bindingProperty.getRootCondition(), "true"); bindingProperty.addCollapsedValues("true", "false"); } // Permutations and their values are in stable alphabetical order. // PropertyCombinations permutations = new PropertyCombinations(md.getProperties(), md.getActiveLinkerNames()); List<PropertyCombinations> collapsed = permutations.collapseProperties(); assertEquals("size", 1, collapsed.size()); permutations = collapsed.get(0); String[] permutation; Iterator<String[]> it = permutations.iterator(); assertTrue(it.hasNext()); permutation = it.next(); assertEquals("false", permutation[0]); assertTrue(it.hasNext()); permutation = it.next(); assertEquals("true", permutation[0]); }
/** Make sure that a cycle doesn't cause an infinite loop. */ public void testCycle() { // This is what you'd get with a conditional <set-property value="false"> ModuleDef md = new ModuleDef("testCycle"); Properties properties = md.getProperties(); { BindingProperty bindingProperty = properties.createBinding("A"); bindingProperty.addDefinedValue(bindingProperty.getRootCondition(), "a1"); bindingProperty.addDefinedValue(bindingProperty.getRootCondition(), "a2"); bindingProperty.addDefinedValue(new ConditionWhenPropertyIs("B", "b3"), "a3"); } { BindingProperty bindingProperty = properties.createBinding("B"); bindingProperty.addDefinedValue(bindingProperty.getRootCondition(), "b1"); bindingProperty.addDefinedValue(bindingProperty.getRootCondition(), "b2"); bindingProperty.addDefinedValue(new ConditionWhenPropertyIs("A", "a3"), "b3"); } try { new PropertyCombinations(properties, md.getActiveLinkerNames()); fail(); } catch (IllegalStateException e) { // OK } }
public void testTwoDimensionPermWithRestriction() { // This is what you'd get with a conditional <set-property value="false"> ModuleDef md = new ModuleDef("testTwoDimensionsWithRestriction"); Properties properties = md.getProperties(); { BindingProperty bindingProperty = properties.createBinding("user.agent"); bindingProperty.addDefinedValue(bindingProperty.getRootCondition(), "moz"); bindingProperty.addDefinedValue(bindingProperty.getRootCondition(), "ie6"); bindingProperty.addDefinedValue(bindingProperty.getRootCondition(), "ie8"); bindingProperty.addDefinedValue(bindingProperty.getRootCondition(), "opera"); } { BindingProperty bindingProperty = properties.createBinding("stackTraces"); bindingProperty.addDefinedValue(bindingProperty.getRootCondition(), "false"); bindingProperty.addDefinedValue(bindingProperty.getRootCondition(), "true"); ConditionAny cond = new ConditionAny(); cond.getConditions().add(new ConditionWhenPropertyIs("user.agent", "moz")); cond.getConditions().add(new ConditionWhenPropertyIs("user.agent", "opera")); bindingProperty.setValues(cond, "false"); } validateTwoDimensionPerm(properties, md.getActiveLinkerNames()); }
public void testTwoDimensionPermWithExpansion() { ModuleDef md = new ModuleDef("testTwoDimensionsWithExpansion"); Properties properties = md.getProperties(); { BindingProperty bindingProperty = properties.createBinding("user.agent"); bindingProperty.addDefinedValue(bindingProperty.getRootCondition(), "moz"); bindingProperty.addDefinedValue(bindingProperty.getRootCondition(), "ie6"); bindingProperty.addDefinedValue(bindingProperty.getRootCondition(), "ie8"); bindingProperty.addDefinedValue(bindingProperty.getRootCondition(), "opera"); } { BindingProperty bindingProperty = properties.createBinding("stackTraces"); bindingProperty.addDefinedValue(bindingProperty.getRootCondition(), "false"); bindingProperty.addDefinedValue(bindingProperty.getRootCondition(), "true"); // <set-property name="stackTraces" value="false" /> bindingProperty.setValues(bindingProperty.getRootCondition(), "false"); /* * <set-property name="stackTraces" value="true,false"> <when user.agent * is ie6 or ie 8> </set-property> */ ConditionAny cond = new ConditionAny(); cond.getConditions().add(new ConditionWhenPropertyIs("user.agent", "ie6")); cond.getConditions().add(new ConditionWhenPropertyIs("user.agent", "ie8")); bindingProperty.setValues(cond, "true", "false"); } validateTwoDimensionPerm(properties, md.getActiveLinkerNames()); }
public void testTwoDimensionPerm() { ModuleDef md = new ModuleDef("testTwoDimensionPerm"); Properties properties = md.getProperties(); { BindingProperty bindingProperty = properties.createBinding("user.agent"); bindingProperty.addDefinedValue(bindingProperty.getRootCondition(), "moz"); bindingProperty.addDefinedValue(bindingProperty.getRootCondition(), "ie6"); bindingProperty.addDefinedValue(bindingProperty.getRootCondition(), "opera"); } { BindingProperty bindingProperty = properties.createBinding("debug"); bindingProperty.addDefinedValue(bindingProperty.getRootCondition(), "false"); bindingProperty.addDefinedValue(bindingProperty.getRootCondition(), "true"); } // String[]s and their values are in stable alphabetical order. // PropertyCombinations permutations = new PropertyCombinations(md.getProperties(), md.getActiveLinkerNames()); String[] permutation; Iterator<String[]> it = permutations.iterator(); assertTrue(it.hasNext()); permutation = it.next(); assertEquals("false", permutation[0]); assertEquals("ie6", permutation[1]); assertTrue(it.hasNext()); permutation = it.next(); assertEquals("false", permutation[0]); assertEquals("moz", permutation[1]); assertTrue(it.hasNext()); permutation = it.next(); assertEquals("false", permutation[0]); assertEquals("opera", permutation[1]); assertTrue(it.hasNext()); permutation = it.next(); assertEquals("true", permutation[0]); assertEquals("ie6", permutation[1]); assertTrue(it.hasNext()); permutation = it.next(); assertEquals("true", permutation[0]); assertEquals("moz", permutation[1]); assertTrue(it.hasNext()); permutation = it.next(); assertEquals("true", permutation[0]); assertEquals("opera", permutation[1]); }
public void testTwoDimensionPermWithCollapse() { ModuleDef md = new ModuleDef("testTwoDimensionPerm"); Properties properties = md.getProperties(); { BindingProperty bindingProperty = properties.createBinding("user.agent"); bindingProperty.addDefinedValue(bindingProperty.getRootCondition(), "moz"); bindingProperty.addDefinedValue(bindingProperty.getRootCondition(), "ie6"); bindingProperty.addDefinedValue(bindingProperty.getRootCondition(), "opera"); bindingProperty.addCollapsedValues("moz", "ie6", "opera"); } { BindingProperty bindingProperty = properties.createBinding("debug"); bindingProperty.addDefinedValue(bindingProperty.getRootCondition(), "false"); bindingProperty.addDefinedValue(bindingProperty.getRootCondition(), "true"); } // String[]s and their values are in stable alphabetical order. // PropertyCombinations permutations = new PropertyCombinations(md.getProperties(), md.getActiveLinkerNames()); List<PropertyCombinations> collapsed = permutations.collapseProperties(); assertEquals("size", 2, collapsed.size()); Iterator<String[]> it = collapsed.get(0).iterator(); assertEquals(Arrays.asList("false", "ie6"), Arrays.asList(it.next())); assertEquals(Arrays.asList("false", "moz"), Arrays.asList(it.next())); assertEquals(Arrays.asList("false", "opera"), Arrays.asList(it.next())); assertFalse(it.hasNext()); it = collapsed.get(1).iterator(); assertEquals(Arrays.asList("true", "ie6"), Arrays.asList(it.next())); assertEquals(Arrays.asList("true", "moz"), Arrays.asList(it.next())); assertEquals(Arrays.asList("true", "opera"), Arrays.asList(it.next())); assertFalse(it.hasNext()); }