aboutsummaryrefslogtreecommitdiff
path: root/src/test/model/asn1/BoolTest.java
blob: fed31525ca46f29f99f499c9d07b0e9b99951a63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package model.asn1;

import model.asn1.exceptions.ParseException;
import model.asn1.parsing.BytesReader;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

public class BoolTest {
    @Test
    void testConstructor() {
        assertTrue(new Bool(Bool.TAG, null, true).getValue());
        assertFalse(new Bool(Bool.TAG, null, false).getValue());
    }

    @Test
    void testParse() throws ParseException {
        assertFalse(new Bool(new BytesReader(new Byte[]{ 0x1, 1, 0 }), false)
                        .getValue());
        assertTrue(new Bool(new BytesReader(new Byte[]{ 0x1, 1, -1 }), false)
                .getValue());
    }

    @Test
    void testParseFail() throws ParseException {
        assertThrows(ParseException.class, () ->
                new Bool(new BytesReader(new Byte[]{ 0x1, 0 }), false));
        assertThrows(ParseException.class, () ->
                new Bool(new BytesReader(new Byte[]{ 0x1, 1 }), false));
        assertThrows(ParseException.class, () ->
                new Bool(new BytesReader(new Byte[]{ 0x1, 1, 1 }), false));
        assertThrows(ParseException.class, () ->
                new Bool(new BytesReader(new Byte[]{ 0x1, 1, -2 }), false));
        assertThrows(ParseException.class, () ->
                new Bool(new BytesReader(new Byte[]{ 0x1, 2, -1, 2 }), false));
    }

    @Test
    void testEncode() {
        assertArrayEquals(new Byte[]{ 0 },
                new Bool(Bool.TAG, null, false).encodeValueDER());
        assertArrayEquals(new Byte[]{ -1 },
                new Bool(Bool.TAG, null, true).encodeValueDER());
    }
}