-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
169 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
Source/FiscalPrinterService/test/com/shtrih/fiscalprinter/TLVReaderTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.shtrih.fiscalprinter; | ||
|
||
import org.junit.Test; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.nio.ByteOrder; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
/** | ||
* @author P.Zhirkov | ||
*/ | ||
public class TLVReaderTests { | ||
|
||
@Test | ||
public void Should_decode_vln_tag() throws Exception { | ||
byte[] data = fsWriteTag(1011, 12345); | ||
|
||
TLVReader reader = new TLVReader(); | ||
reader.read(data); | ||
|
||
List<TLVItem> items = reader.getItems(); | ||
assertEquals(1, items.size()); | ||
|
||
TLVItem item = items.get(0); | ||
|
||
assertEquals(12345, item.toInt(item.getData())); | ||
assertEquals("123,45", item.getText()); | ||
} | ||
|
||
private byte[] fsWriteTag(final int tag, final int data) throws Exception { | ||
ByteBuffer buffer = ByteBuffer.allocate(8); | ||
|
||
buffer.order(ByteOrder.LITTLE_ENDIAN); | ||
buffer.putShort((short)(tag)); | ||
buffer.putShort((short)(4)); | ||
buffer.putInt(data); | ||
|
||
return buffer.array(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters