summaryrefslogtreecommitdiff
path: root/jessie-tests/gnu/javax/net/ssl/provider/testRecord.java
blob: a14417f3efdaebbf469ccdfa7b6579fbd93615aa (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64


package gnu.javax.net.ssl.provider;

import java.nio.ByteBuffer;
import java.util.Arrays;

class testRecord
{
  public static void main (final String[] argv)
  {
    try
      {
        check ();
      }
    catch (Exception x)
      {
        System.out.println ("FAIL: caught exception " + x);
        x.printStackTrace ();
      }
  }

  static void check () throws Exception
  {
    ByteBuffer buf = ByteBuffer.allocate (42 + 5);
    Record record = new Record (buf);
    byte[] fragment = new byte[42];
    new java.util.Random (31337).nextBytes (fragment);

    record.setVersion (ProtocolVersion.TLS_1);
    System.out.println ("PASS: setVersion");
    record.setContentType (ContentType.APPLICATION_DATA);
    System.out.println ("PASS: setContentType");
    record.setLength (42);
    System.out.println ("PASS: setLength");

    record.fragment ().put (fragment);
    System.out.println ("PASS: fragment ().put ()");

    if (ProtocolVersion.TLS_1.equals (record.version ()))
      System.out.println ("PASS: version()");
    else
      System.out.println ("FAIL: version()");

    if (ContentType.APPLICATION_DATA.equals (record.contentType ()))
      System.out.println ("PASS: contentType()");
    else
      System.out.println ("FAIL: contentType()");

    if (record.length () == 42)
      System.out.println ("PASS: length()");
    else
      System.out.println ("FAIL: length()");

    byte[] fragment2 = new byte[42];
    record.fragment ().get (fragment2);
    if (Arrays.equals (fragment, fragment2))
      System.out.println ("PASS: fragment ().get ()");
    else
      System.out.println ("FAIL: fragment ().get ()");

    System.err.println (record);
  }
}