Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
io.flutter.plugin.common.StandardMessageCodecTest Class Reference

Public Member Functions

void itEncodesNullLiterals ()
 
void itEncodesNullObjects ()
 
void itEncodesBooleans ()
 
void itEncodesFloatArrays ()
 
void itEncodesCharSequences ()
 
void errorHasType ()
 

Detailed Description

Definition at line 18 of file StandardMessageCodecTest.java.

Member Function Documentation

◆ errorHasType()

void io.flutter.plugin.common.StandardMessageCodecTest.errorHasType ( )
inline

Definition at line 136 of file StandardMessageCodecTest.java.

136 {
137 StandardMessageCodec codec = new StandardMessageCodec();
138 NotEncodable notEncodable = new NotEncodable();
139 Exception exception =
140 assertThrows(
141 IllegalArgumentException.class,
142 () -> {
143 codec.encodeMessage(notEncodable);
144 });
145 assertTrue(exception.getMessage().contains("NotEncodable"));
146 }

◆ itEncodesBooleans()

void io.flutter.plugin.common.StandardMessageCodecTest.itEncodesBooleans ( )
inline

Definition at line 86 of file StandardMessageCodecTest.java.

86 {
87 // Setup message codec
88 StandardMessageCodec codec = new StandardMessageCodec();
89
90 ArrayList<Object> messageContent = new ArrayList();
91 // Test handling of Boolean objects other than the static TRUE and FALSE constants.
92 messageContent.add(new Boolean(true));
93 messageContent.add(new Boolean(false));
94 ByteBuffer message = codec.encodeMessage(messageContent);
95 message.flip();
96 ByteBuffer expected = ByteBuffer.allocateDirect(4);
97 expected.put(new byte[] {LIST, 2, TRUE, FALSE});
98 expected.flip();
99 assertEquals(expected, message);
100 }
Win32Message message

◆ itEncodesCharSequences()

void io.flutter.plugin.common.StandardMessageCodecTest.itEncodesCharSequences ( )
inline

Definition at line 116 of file StandardMessageCodecTest.java.

116 {
117 StandardMessageCodec codec = new StandardMessageCodec();
118
119 CharSequence cs = new SpannableString("hello world");
120
121 ByteBuffer message = codec.encodeMessage(cs);
122 message.flip();
123
124 String value = (String) codec.decodeMessage(message);
125 assertEquals(value, "hello world");
126 }
uint8_t value

◆ itEncodesFloatArrays()

void io.flutter.plugin.common.StandardMessageCodecTest.itEncodesFloatArrays ( )
inline

Definition at line 103 of file StandardMessageCodecTest.java.

103 {
104 StandardMessageCodec codec = new StandardMessageCodec();
105
106 float[] expectedValues = new float[] {1.0f, 2.2f, 5.3f};
107
108 ByteBuffer message = codec.encodeMessage(expectedValues);
109 message.flip();
110
111 float[] values = (float[]) codec.decodeMessage(message);
112 assertArrayEquals(expectedValues, values, 0.01f);
113 }

◆ itEncodesNullLiterals()

void io.flutter.plugin.common.StandardMessageCodecTest.itEncodesNullLiterals ( )
inline

Definition at line 38 of file StandardMessageCodecTest.java.

38 {
39 // Setup message codec
40 StandardMessageCodec codec = new StandardMessageCodec();
41
42 // Attempt to encode message with a null literal inside a list
43 // A list with a null is used instead of just a null literal because if
44 // only null is encoded, then no message is returned; null is returned instead
45 ArrayList<Object> messageContent = new ArrayList();
46 messageContent.add(null);
47 ByteBuffer message = codec.encodeMessage(messageContent);
48 message.flip();
49 ByteBuffer expected = ByteBuffer.allocateDirect(3);
50 expected.put(new byte[] {LIST, 1, NULL});
51 expected.flip();
52 assertEquals(expected, message);
53 }

◆ itEncodesNullObjects()

void io.flutter.plugin.common.StandardMessageCodecTest.itEncodesNullObjects ( )
inline

Definition at line 56 of file StandardMessageCodecTest.java.

56 {
57 // An example class that equals null
58 class ExampleNullObject {
59 @Override
60 public boolean equals(Object other) {
61 return other == null || other == this;
62 }
63
64 @Override
65 public int hashCode() {
66 return 0;
67 }
68 }
69
70 // Setup message codec
71 StandardMessageCodec codec = new StandardMessageCodec();
72
73 // Same as itEncodesNullLiterals but with objects that equal null instead
74 ArrayList<Object> messageContent = new ArrayList();
75 messageContent.add(new ExampleNullObject());
76 ByteBuffer message = codec.encodeMessage(messageContent);
77 message.flip();
78 ByteBuffer expected = ByteBuffer.allocateDirect(3);
79 expected.put(new byte[] {LIST, 1, NULL});
80 expected.flip();
81 assertEquals(expected, message);
82 }
static bool equals(T *a, T *b)

The documentation for this class was generated from the following file: