Skip to content

Commit

Permalink
Add Ulbotech unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed Jan 9, 2015
1 parent ab0e4b7 commit 0a12b32
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
17 changes: 1 addition & 16 deletions src/org/traccar/protocol/UlbotechProtocolDecoder.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012 Anton Tananaev ([email protected])
* Copyright 2015 Anton Tananaev ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,7 +16,6 @@
package org.traccar.protocol;

import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
Expand All @@ -26,29 +25,15 @@
import org.traccar.model.ExtendedInfoFormatter;
import org.traccar.model.Position;

import java.util.Calendar;
import java.util.Date;
import java.util.Properties;
import java.util.TimeZone;

public class UlbotechProtocolDecoder extends BaseProtocolDecoder {

public UlbotechProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
super(dataManager, protocol, properties);
}

private String readImei(ChannelBuffer buf) {
int b = buf.readUnsignedByte();
StringBuilder imei = new StringBuilder();
imei.append(b & 0x0F);
for (int i = 0; i < 7; i++) {
b = buf.readUnsignedByte();
imei.append((b & 0xF0) >> 4);
imei.append(b & 0x0F);
}
return imei.toString();
}

private static final short DATA_GPS = 0x01;
private static final short DATA_LBS = 0x02;
private static final short DATA_STATUS = 0x03;
Expand Down
16 changes: 11 additions & 5 deletions test/org/traccar/protocol/UlbotechProtocolDecoderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ public class UlbotechProtocolDecoderTest {
public void testDecode() throws Exception {

UlbotechProtocolDecoder decoder = new UlbotechProtocolDecoder(new TestDataManager(), null, null);

//verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertArray(
// new int[] {0xF8,0x01,0x01,0x08,0x63,0x07,0x00,0x18,0x98,0x72,0x98,0x72,0x96,0x19,0x02,0x27,0x01,0xCC,0x00,0x00,0x28,0x55,0x34,0xBA,0x4F,0x28,0x55,0x3A,0xB1,0x4C,0x28,0x55,0xBC,0x9C,0x57,0x28,0x55,0xBC,0x9D,0x5B,0x28,0x55,0x3A,0xB2,0x5C,0x28,0x55,0x44,0x58,0x61,0x28,0x55,0x44,0x58,0x63,0x03,0x04,0x00,0x00,0x00,0x00,0x04,0x04,0x00,0x00,0x07,0x6F,0x05,0x08,0x03,0x3A,0x18,0xCF,0x22,0x0D,0x3D,0xE6,0xA6,0x38,0xF8}))));

verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertArray(
new int[] {0xF8,0x01,0x01,0x03,0x57,0x85,0x20,0x34,0x57,0x28,0x94,0x95,0xD6,0x02,0x35,0x01,0x0E,0x01,0x61,0x75,0xA5,0x06,0xC2,0xC8,0x38,0x00,0x00,0x00,0x00,0x00,0x64}))));
verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString(
"F80101035785203457289495D60235010E016175A506C2C838000000000064"))));

verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString(
"F8010108621060211481299C4247FA010E015EE1D606BDE797000301370081030402420000040400523CAF050603921743220706080000000000000000071131058E410C0E30310D48312F8E4131046A080402C8F2545445F8"))));

verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString(
"F8010108621060211481299C4249FA010E015EE27506BDE80900020000008F030402420000040400523CAF05060392173F220706080000000000000000071131058E410C0E40310D48312F8E41310884080402CA60E43872F8"))));

//verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString(
// "F801010863070018987298729619022701CC0000285534BA4F28553AB14C2855BC9C572855BC9D5B28553AB25C2855445861285544586303040000000004040000076F0508033A18CF220D3DE6A638F8"))));

}

Expand Down

0 comments on commit 0a12b32

Please sign in to comment.