|
| 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 | +} |
0 commit comments