Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c20952bdfb86cebdc8c0d6d507527e68a836a11b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*******************************************************************************
 * Copyright (c) 2008, 2012 Wind River Systems, Inc. and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     Anton Leherbauer (Wind River Systems) - initial API and implementation
 *******************************************************************************/

package org.eclipse.cdt.core.settings.model;

import org.eclipse.cdt.core.settings.model.util.PathSettingsContainer;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;

import junit.framework.TestSuite;

/**
 */
public class PathSettingsContainerTests extends BaseTestCase {

	public static TestSuite suite() {
		return suite(PathSettingsContainerTests.class, "_");
	}

	@Override
	protected void setUp() throws Exception {
	}

	@Override
	protected void tearDown() throws Exception {
	}

	public void testPathSettingsContainerCreate() {
		final PathSettingsContainer root = PathSettingsContainer.createRootContainer();
		assertNull(root.getValue());
		assertNull(root.getParentContainer());
		assertTrue(root.isRoot());
		assertTrue(root.isValid());
		assertEquals(0, root.getChildren(false).length);
		assertEquals(1, root.getChildren(true).length);

		final IPath level1 = new Path("level1");
		final PathSettingsContainer child1 = root.getChildContainer(level1, true, true);
		assertNotNull(child1);
		assertNull(child1.getValue());
		assertSame(root, child1.getParentContainer());
		assertFalse(child1.isRoot());
		assertTrue(child1.isValid());
		assertEquals(1, root.getChildren(false).length);
		assertEquals(0, child1.getChildren(false).length);
		assertEquals(1, child1.getChildren(true).length);
		final String value1 = "child1";
		child1.setValue(value1);
		assertSame(value1, child1.getValue());

		final IPath level2 = level1.append("level2");
		final PathSettingsContainer child2 = root.getChildContainer(level2, true, true);
		assertNotNull(child2);
		assertNull(child2.getValue());
		assertSame(child1, child2.getParentContainer());
		assertFalse(child2.isRoot());
		assertTrue(child2.isValid());
		assertEquals(1, child1.getChildren(false).length);
		assertEquals(0, child2.getChildren(false).length);
		assertEquals(1, child2.getChildren(true).length);
		final String value2 = "child2";
		child2.setValue(value2);
		assertSame(value2, child2.getValue());

		final IPath level3 = level2.append("level3");
		final PathSettingsContainer child3 = root.getChildContainer(level3, true, true);
		assertNotNull(child3);
		assertNull(child3.getValue());
		assertSame(child2, child3.getParentContainer());
		assertFalse(child3.isRoot());
		assertTrue(child3.isValid());
		assertEquals(1, child2.getChildren(false).length);
		assertEquals(0, child3.getChildren(false).length);
		assertEquals(1, child3.getChildren(true).length);
		final String value3 = "child3";
		child3.setValue(value3);
		assertSame(value3, child3.getValue());

		assertSame(child1, root.getChildContainer(level1, true, true));
		assertSame(child2, root.getChildContainer(level2, true, true));
		assertSame(child3, root.getChildContainer(level3, true, true));
	}

	public void testPathSettingsContainerRemove() {
		final PathSettingsContainer root = PathSettingsContainer.createRootContainer();
		final IPath level1 = new Path("level1");
		final PathSettingsContainer child1 = root.getChildContainer(level1, true, true);
		final IPath level2 = level1.append("level2");
		final PathSettingsContainer child2 = root.getChildContainer(level2, true, true);
		final IPath level3 = level2.append("level3");
		final PathSettingsContainer child3 = root.getChildContainer(level3, true, true);
		final IPath level31 = level2.append("level31");
		final PathSettingsContainer child31 = root.getChildContainer(level31, true, true);

		child3.remove();
		assertEquals(1, child2.getChildren(false).length);
		assertFalse(child3.isValid());

		child2.remove();
		assertFalse(child2.isValid());

		child31.remove();
		assertEquals(0, child2.getChildren(false).length);
		assertFalse(child31.isValid());

	}

	public void testPathSettingsContainer_Bug208765() {
		final PathSettingsContainer root = PathSettingsContainer.createRootContainer();
		try {
			root.removeChildContainer(new Path(""));
		} catch (NullPointerException npe) {
			fail(npe.getMessage());
		}
	}

}

Back to the top