Skip to content

Commit e791f2d

Browse files
authored
Merge pull request #3 from js-labs/datablock-wr-order
Both DataBlock.rd and DataBlock.wr inherits byte order from the source byte buffer.
2 parents 6ceb6b4 + 604c211 commit e791f2d

File tree

4 files changed

+81
-2
lines changed

4 files changed

+81
-2
lines changed

build.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<sequential>
3737
<property name="testName" value=""/>
3838
<get-test-name propertyName="testName"/>
39-
<java classname="org.jsl.tests.${testName}.Main" fork="true">
39+
<java classname="org.jsl.tests.${testName}.Main" fork="true" failonerror="true">
4040
<classpath>
4141
<pathelement location="${build}/classes"/>
4242
<pathelement location="${build}/tests"/>
@@ -191,6 +191,10 @@
191191
<run-test/>
192192
</target>
193193

194+
<target name="test.unit" depends="compile_tests">
195+
<run-test/>
196+
</target>
197+
194198
<target name="tests"
195199
depends="test.buffer_overlap_copy,
196200
test.byte_buffer_pool,
@@ -209,5 +213,6 @@
209213
test.sched_latency,
210214
test.thread_pool,
211215
test.thread_pool_throughput,
212-
test.timer_queue"/>
216+
test.timer_queue,
217+
test.unit"/>
213218
</project>

src/main/java/org/jsl/collider/DataBlock.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public DataBlock(ByteBuffer buf)
3131
{
3232
wr = buf;
3333
rd = buf.duplicate();
34+
rd.order(buf.order());
3435
}
3536

3637
public final DataBlock reset()
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (C) 2013 Sergey Zubarev, info@js-labs.org
3+
*
4+
* This file is a part of JS-Collider test.
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as
8+
* published by the Free Software Foundation, either version 3 of the
9+
* License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Affero General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
package org.jsl.tests.unit;
20+
21+
import java.nio.ByteBuffer;
22+
import java.nio.ByteOrder;
23+
import org.jsl.collider.DataBlock;
24+
25+
interface TestFunc {
26+
void run() throws Exception;
27+
}
28+
29+
public class Main {
30+
private static void dataBlockInheritsByteOrder() throws Exception {
31+
final ByteOrder [] orders = {ByteOrder.LITTLE_ENDIAN, ByteOrder.BIG_ENDIAN};
32+
for (ByteOrder byteOrder: orders) {
33+
final ByteBuffer byteBuffer = ByteBuffer.allocateDirect(32);
34+
byteBuffer.order(byteOrder);
35+
final DataBlock dataBlock = new DataBlock(byteBuffer);
36+
if (dataBlock.rd.order() != byteOrder) {
37+
throw new Exception("wrong dataBlock.rd.order()");
38+
}
39+
if (dataBlock.wr.order() != byteOrder) {
40+
throw new Exception("wrong dataBlock.wr.order()");
41+
}
42+
}
43+
}
44+
45+
private static int runTest(TestFunc testFunc) {
46+
try {
47+
testFunc.run();
48+
return 0;
49+
} catch (final Exception ex) {
50+
System.out.println(ex.getMessage());
51+
return 1;
52+
}
53+
}
54+
55+
public static void main(String [] args) {
56+
int failedTests = 0;
57+
failedTests += runTest(Main::dataBlockInheritsByteOrder);
58+
System.out.println(failedTests + " tests failed");
59+
System.exit((failedTests == 0) ? 0 : -1);
60+
}
61+
}

tests/tests.iml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="true" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
<orderEntry type="module" module-name="js-collider" />
11+
</component>
12+
</module>

0 commit comments

Comments
 (0)