Skip to content

Commit 69bed3b

Browse files
committed
add tests
1 parent ab2fcff commit 69bed3b

File tree

7 files changed

+199
-1
lines changed

7 files changed

+199
-1
lines changed

net.lecousin.core/src/test/java/net/lecousin/framework/core/test/util/TestIString.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ public void testTrim() {
200200
@Test(timeout=120000)
201201
public void testToUsAsciiBytes() {
202202
Assert.assertArrayEquals(new byte[] { 'H', 'e', 'l', 'l', 'o' }, createString("Hello").toUsAsciiBytes());
203-
Assert.assertArrayEquals(new byte[] { 'H', 'e', 'l', 'l', 'o' }, createString("He").append("ll").append('o').toUsAsciiBytes());
203+
byte[] bytes = new byte[5];
204+
createString("He").append("ll").append('o').fillUsAsciiBytes(bytes);
205+
Assert.assertArrayEquals(new byte[] { 'H', 'e', 'l', 'l', 'o' }, bytes);
204206
}
205207
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package net.lecousin.framework.core.tests.progress;
2+
3+
import net.lecousin.framework.core.test.LCCoreAbstractTest;
4+
import net.lecousin.framework.progress.MultiTaskProgress;
5+
import net.lecousin.framework.progress.WorkProgress;
6+
7+
import org.junit.Assert;
8+
import org.junit.Test;
9+
10+
public class TestMultiTaskProgress extends LCCoreAbstractTest {
11+
12+
@Test(timeout=30000)
13+
public void test() {
14+
MultiTaskProgress p = new MultiTaskProgress("Test");
15+
WorkProgress t1 = p.createTaskProgress(1000, "Task1");
16+
WorkProgress t2 = p.createTaskProgress(100, "Task2");
17+
WorkProgress t3 = p.createTaskProgress(300, "Task3");
18+
Assert.assertEquals(1400, p.getAmount());
19+
Assert.assertEquals(0, p.getPosition());
20+
Assert.assertEquals(1400, p.getRemainingWork());
21+
t1.progress(150);
22+
Assert.assertEquals(1400, p.getAmount());
23+
Assert.assertEquals(150, p.getPosition());
24+
Assert.assertEquals(1250, p.getRemainingWork());
25+
Assert.assertEquals(1000, t1.getAmount());
26+
Assert.assertEquals(150, t1.getPosition());
27+
Assert.assertEquals(850, t1.getRemainingWork());
28+
t2.done();
29+
Assert.assertEquals(1400, p.getAmount());
30+
Assert.assertEquals(250, p.getPosition());
31+
Assert.assertEquals(1150, p.getRemainingWork());
32+
Assert.assertEquals(100, t2.getAmount());
33+
Assert.assertEquals(100, t2.getPosition());
34+
Assert.assertEquals(0, t2.getRemainingWork());
35+
t3.progress(300);
36+
Assert.assertEquals(1400, p.getAmount());
37+
Assert.assertEquals(550, p.getPosition());
38+
Assert.assertEquals(850, p.getRemainingWork());
39+
Assert.assertEquals(300, t3.getAmount());
40+
Assert.assertEquals(300, t3.getPosition());
41+
Assert.assertEquals(0, t3.getRemainingWork());
42+
}
43+
44+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package net.lecousin.framework.core.tests.progress;
2+
3+
import net.lecousin.framework.concurrent.synch.SynchronizationPoint;
4+
import net.lecousin.framework.core.test.LCCoreAbstractTest;
5+
import net.lecousin.framework.progress.WorkProgressImpl;
6+
7+
import org.junit.Assert;
8+
import org.junit.Test;
9+
10+
public class TestWorkProgressImpl extends LCCoreAbstractTest {
11+
12+
@Test(timeout=30000)
13+
public void test() throws Exception {
14+
WorkProgressImpl p = new WorkProgressImpl(1000);
15+
Assert.assertEquals(1000, p.getAmount());
16+
Assert.assertEquals(1000, p.getRemainingWork());
17+
Assert.assertEquals("", p.getText());
18+
Assert.assertEquals("", p.getSubText());
19+
p = new WorkProgressImpl(1000, "Hello");
20+
Assert.assertEquals(1000, p.getAmount());
21+
Assert.assertEquals(1000, p.getRemainingWork());
22+
Assert.assertEquals("Hello", p.getText());
23+
Assert.assertEquals("", p.getSubText());
24+
p = new WorkProgressImpl(1000, "Hello", "World");
25+
Assert.assertEquals(1000, p.getAmount());
26+
Assert.assertEquals(1000, p.getRemainingWork());
27+
Assert.assertEquals("Hello", p.getText());
28+
Assert.assertEquals("World", p.getSubText());
29+
p.progress(100);
30+
Assert.assertEquals(1000, p.getAmount());
31+
Assert.assertEquals(900, p.getRemainingWork());
32+
Assert.assertEquals(100, p.getPosition());
33+
p.setText("Test");
34+
Assert.assertEquals("Test", p.getText());
35+
p.setSubText("12345");
36+
Assert.assertEquals("12345", p.getSubText());
37+
SynchronizationPoint<Exception> changed = new SynchronizationPoint<>();
38+
Runnable listener = () -> {
39+
changed.unblock();
40+
};
41+
p.listen(listener);
42+
Assert.assertFalse(changed.isUnblocked());
43+
p.progress(200);
44+
Assert.assertEquals(1000, p.getAmount());
45+
Assert.assertEquals(700, p.getRemainingWork());
46+
Assert.assertEquals(300, p.getPosition());
47+
changed.blockThrow(0);
48+
changed.reset();
49+
p.setText("Toto");
50+
Assert.assertEquals("Toto", p.getText());
51+
changed.blockThrow(0);
52+
changed.reset();
53+
p.setSubText("Titi");
54+
Assert.assertEquals("Titi", p.getSubText());
55+
changed.blockThrow(0);
56+
changed.reset();
57+
p.unlisten(listener);
58+
p.progress(1);
59+
Assert.assertEquals(1000, p.getAmount());
60+
Assert.assertEquals(699, p.getRemainingWork());
61+
Assert.assertEquals(301, p.getPosition());
62+
changed.blockThrow(500);
63+
Assert.assertFalse(changed.isUnblocked());
64+
p.done();
65+
}
66+
67+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package net.lecousin.framework.core.tests.util;
2+
3+
import net.lecousin.framework.core.test.LCCoreAbstractTest;
4+
import net.lecousin.framework.locale.FixedLocalizedString;
5+
import net.lecousin.framework.util.CompositeNamedObject;
6+
7+
import org.junit.Assert;
8+
import org.junit.Test;
9+
10+
public class TestCompositeNamedObject extends LCCoreAbstractTest {
11+
12+
@Test(timeout=30000)
13+
public void test() {
14+
CompositeNamedObject c = new CompositeNamedObject();
15+
c.add(new FixedLocalizedString("Test"), Integer.valueOf(51));
16+
Assert.assertEquals(Integer.valueOf(51), c.get(0));
17+
Assert.assertEquals("Test", c.getName(0).appLocalizationSync());
18+
}
19+
20+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package net.lecousin.framework.core.tests.util;
2+
3+
import net.lecousin.framework.core.test.LCCoreAbstractTest;
4+
import net.lecousin.framework.util.Filter;
5+
6+
import org.junit.Assert;
7+
import org.junit.Test;
8+
9+
public class TestFilter extends LCCoreAbstractTest {
10+
11+
@Test(timeout=30000)
12+
public void test() {
13+
Filter.Single<Integer> filter = new Filter.Single<>(Integer.valueOf(51));
14+
Assert.assertTrue(filter.accept(Integer.valueOf(51)));
15+
Assert.assertFalse(filter.accept(Integer.valueOf(50)));
16+
Assert.assertFalse(filter.accept(Integer.valueOf(-51)));
17+
}
18+
19+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package net.lecousin.framework.core.tests.util;
2+
3+
import net.lecousin.framework.core.test.LCCoreAbstractTest;
4+
import net.lecousin.framework.io.encoding.HexaDecimalEncoder;
5+
import net.lecousin.framework.util.IDManagerLong;
6+
7+
import org.junit.Assert;
8+
import org.junit.Test;
9+
10+
public class TestIDManagerLong extends LCCoreAbstractTest {
11+
12+
@Test(timeout=30000)
13+
public void test() {
14+
IDManagerLong idm = new IDManagerLong(new HexaDecimalEncoder());
15+
Assert.assertEquals("0100000000000000", idm.allocate());
16+
Assert.assertEquals("0200000000000000", idm.allocate());
17+
Assert.assertEquals("0300000000000000", idm.allocate());
18+
idm.free("0200000000000000");
19+
Assert.assertEquals("0200000000000000", idm.allocate());
20+
idm.free("0100000000000000");
21+
idm.free("0300000000000000");
22+
Assert.assertEquals("0100000000000000", idm.allocate());
23+
Assert.assertEquals("0300000000000000", idm.allocate());
24+
Assert.assertEquals("0400000000000000", idm.allocate());
25+
}
26+
27+
}

net.lecousin.core/src/test/java/net/lecousin/framework/core/tests/xml/TestDOMModifications.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@ public void test() throws Exception {
267267
Assert.assertEquals("hello", e.getPrefix());
268268
Assert.assertEquals("world", e.getLocalName());
269269

270+
e = doc2.createElement("hello:bonjour");
271+
Assert.assertEquals("hello", e.getPrefix());
272+
Assert.assertEquals("bonjour", e.getLocalName());
273+
270274
e = doc2.createElementNS(null, "empty");
271275
Assert.assertEquals("empty", e.getNodeName());
272276

@@ -276,6 +280,7 @@ public void test() throws Exception {
276280
e.setIdAttribute("myId", true);
277281
root2.appendChild(e);
278282

283+
// getElementById and getElementsByTagName
279284
e = doc2.getElementById("myElement");
280285
Assert.assertNotNull(e);
281286
Assert.assertEquals("empty", e.getNodeName());
@@ -296,6 +301,20 @@ public void test() throws Exception {
296301
Assert.assertEquals("empty", e.getNodeName());
297302
e = doc2.getElementById("myElement");
298303
Assert.assertNull(e);
304+
305+
e = doc2.getElementById("myElement2");
306+
XMLElement e2 = doc2.createElement("test");
307+
e.appendChild(e2);
308+
Assert.assertEquals(e, e2.getParentNode());
309+
Assert.assertTrue(e2.isAncestor(e));
310+
Assert.assertTrue(e2.isAncestor(root2));
311+
Assert.assertFalse(e.isAncestor(e2));
312+
Assert.assertTrue(e.isAncestor(root2));
313+
314+
Assert.assertNull(a.getFirstChild());
315+
Assert.assertNull(a.getLastChild());
316+
Assert.assertFalse(a.hasChildNodes());
317+
Assert.assertFalse(a.hasAttributes());
299318
}
300319

301320
}

0 commit comments

Comments
 (0)