<commit_before>package pl.grzeslowski.jsupla.proto.parsers;

import org.junit.Test;
import pl.grzeslowski.jsupla.proto.structs.TSuplaDataPacket;

import static java.lang.Integer.MIN_VALUE;
import static org.assertj.core.api.Assertions.assertThat;

public class TSuplaDataPacketParserTest {
    private final TSuplaDataPacketParser parser = new TSuplaDataPacketParser();

    @Test
    public void shouldParseTSuplaDataPacketFromArrayWithSuplaTag() {

        // given
        byte[] bytes = new byte[]{
                83, 85, 80, 76, 65,
                5,
                1, 0, 0, 0,
                65, 0, 0, 0,
                41, 1, 0, 0,
                -77, 1, 0, 0, 120, 120, 120, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,- 33, 22, - 81, 125, - 64, 116, - 19, 2, 101, 103, - 127, 16, -6 - 66, 96, 60, 90, 65, 77, 69, 76, 32, 82, 79, 87, 45, 48, 49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 50, 46, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 84, 11, 0, 0, 96, 0, 0, 0 - 116, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 83, 85, 80, 76, 65
        };

        // when
        final TSuplaDataPacket packet = parser.parse(bytes);

        // then
        assertThat(packet.version).isEqualTo((byte) 5);
        assertThat(packet.rrId).isEqualTo(MIN_VALUE + 1);
        assertThat(packet.callType).isEqualTo(MIN_VALUE + 65);
        assertThat(packet.dataSize).isEqualTo(MIN_VALUE + 297);
        assertThat(packet.data).isEqualTo(new byte[]{-77, 1, 0, 0, 120, 120, 120, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -33, 22, -81, 125, -64, 116, -19, 2, 101, 103, -127, 16, -6 - 66, 96, 60, 90, 65, 77, 69, 76, 32, 82, 79, 87, 45, 48, 49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 50, 46, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 84, 11, 0, 0, 96, 0, 0, 0 - 116, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 83, 85, 80, 76, 65});
    }
}
<commit_msg>Test was failing because data array was too small<commit_after>package pl.grzeslowski.jsupla.proto.parsers;

import org.junit.Test;
import pl.grzeslowski.jsupla.proto.structs.TSuplaDataPacket;

import static java.lang.Integer.MIN_VALUE;
import static org.assertj.core.api.Assertions.assertThat;
import static pl.grzeslowski.jsupla.consts.JavaConsts.BYTE_SIZE;
import static pl.grzeslowski.jsupla.consts.JavaConsts.INT_SIZE;
import static pl.grzeslowski.jsupla.consts.ProtoConsts.SUPLA_MAX_DATA_SIZE;
import static pl.grzeslowski.jsupla.consts.ProtoConsts.SUPLA_TAG_SIZE;

public class TSuplaDataPacketParserTest {
    private final TSuplaDataPacketParser parser = new TSuplaDataPacketParser();

    @Test
    public void shouldParseTSuplaDataPacketFromArrayWithSuplaTag() {

        // given
        byte[] bytes = new byte[SUPLA_TAG_SIZE + BYTE_SIZE + INT_SIZE * 3 + SUPLA_MAX_DATA_SIZE];
        int i = 0;

        // supla tag
        bytes[i++] = (byte) 83;
        bytes[i++] = (byte) 85;
        bytes[i++] = (byte) 80;
        bytes[i++] = (byte) 76;
        bytes[i++] = (byte) 65;

        // version
        bytes[i++] = (byte) 5;

        // rrId
        bytes[i++] = (byte) 1;
        bytes[i++] = (byte) 0;
        bytes[i++] = (byte) 0;
        bytes[i++] = (byte) 0;

        // callType
        bytes[i++] = (byte) 65;
        bytes[i++] = (byte) 0;
        bytes[i++] = (byte) 0;
        bytes[i++] = (byte) 0;

        // dataSize
        bytes[i++] = (byte) 41;
        bytes[i++] = (byte) 1;
        bytes[i++] = (byte) 0;
        bytes[i++] = (byte) 0;

        // data
        bytes[i++] = (byte) -71;
        bytes[i++] = (byte) 1;
        bytes[i++] = (byte) 0;
        bytes[i++] = (byte) 0;
        bytes[i++] = (byte) 120;
        bytes[i++] = (byte) 120;
        bytes[i++] = (byte) 120;

        for (; i < bytes.length; i++) {
            bytes[i] = 0;
        }

        // when
        final TSuplaDataPacket packet = parser.parse(bytes);

        // then
        assertThat(packet.version).isEqualTo((byte) 5);
        assertThat(packet.rrId).isEqualTo(MIN_VALUE + 1);
        assertThat(packet.callType).isEqualTo(MIN_VALUE + 65);
        assertThat(packet.dataSize).isEqualTo(MIN_VALUE + 297);
        assertThat(packet.data[0]).isEqualTo((byte) -71);
        assertThat(packet.data[1]).isEqualTo((byte) 1);
        assertThat(packet.data[2]).isEqualTo((byte) 0);
        assertThat(packet.data[3]).isEqualTo((byte) 0);
        assertThat(packet.data[4]).isEqualTo((byte) 120);
        assertThat(packet.data[5]).isEqualTo((byte) 120);
        assertThat(packet.data[6]).isEqualTo((byte) 120);
    }
}

{'fraction_non_alphanumeric': 0.20473833097595473, 'fraction_numerical': 0.14285714285714285, 'mean_word_length': 2.3198356807511735, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 11, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6349583', 'n_tokens_mistral': 3253, 'n_tokens_neox': 2481, 'n_words': 840}