Flutter Engine
The Flutter Engine
StandardMethodCodecTest.java
Go to the documentation of this file.
1package io.flutter.plugin.common;
2
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertNotNull;
5import static org.junit.Assert.assertNull;
6import static org.junit.Assert.assertTrue;
7import static org.junit.Assert.fail;
8
9import androidx.test.ext.junit.runners.AndroidJUnit4;
10import java.nio.ByteBuffer;
11import java.nio.ByteOrder;
12import java.util.HashMap;
13import java.util.Map;
14import org.junit.Test;
15import org.junit.runner.RunWith;
16import org.robolectric.annotation.Config;
17
18@Config(manifest = Config.NONE)
19@RunWith(AndroidJUnit4.class)
21
22 @Test
23 public void encodeMethodTest() {
24 final Map<String, String> args = new HashMap<>();
25 args.put("testArg", "testValue");
26 MethodCall call = new MethodCall("testMethod", args);
28 assertNotNull(buffer);
29 buffer.flip();
31 assertEquals(call.method, result.method);
32 assertEquals(call.arguments, result.arguments);
33 }
34
35 @Test
37 final Map<String, Integer> success = new HashMap<>();
38 success.put("result", 1);
39 final ByteBuffer buffer = StandardMethodCodec.INSTANCE.encodeSuccessEnvelope(success);
40 assertNotNull(buffer);
41 buffer.flip();
43 assertEquals(success, result);
44 }
45
46 @Test
49 try {
51 fail("Should have failed to convert unsupported type.");
52 } catch (IllegalArgumentException e) {
53 // pass.
54 }
55 }
56
57 @Test
59 final ByteBuffer buffer =
61 assertNotNull(buffer);
62 buffer.flip();
63 try {
65 fail("Should have thrown a FlutterException since this is an error envelope.");
66 } catch (FlutterException result) {
67 assertEquals("code", result.code);
68 assertEquals("error", result.getMessage());
69 assertNull(result.details);
70 }
71 }
72
73 @Test
75 final Exception e = new IllegalArgumentException("foo");
76 final ByteBuffer buffer =
77 StandardMethodCodec.INSTANCE.encodeErrorEnvelope("code", e.getMessage(), e);
78 assertNotNull(buffer);
79 buffer.flip();
80 try {
82 fail("Should have thrown a FlutterException since this is an error envelope.");
83 } catch (FlutterException result) {
84 assertEquals("code", result.code);
85 assertEquals("foo", result.getMessage());
86 // Must contain part of a stack.
87 String stack = (String) result.details;
88 assertTrue(
89 stack.contains(
90 "at io.flutter.plugin.common.StandardMethodCodecTest.encodeErrorEnvelopeWithThrowableTest(StandardMethodCodecTest.java:"));
91 }
92 }
93
94 @Test
96 final Exception e = new IllegalArgumentException("foo");
97 final ByteBuffer buffer =
99 "code", e.getMessage(), e, "error stacktrace");
100 assertNotNull(buffer);
101 buffer.flip();
102 buffer.order(ByteOrder.nativeOrder());
103 final byte flag = buffer.get();
106 final Object details = StandardMessageCodec.INSTANCE.readValue(buffer);
107 final Object stacktrace = StandardMessageCodec.INSTANCE.readValue(buffer);
108 assertEquals("code", (String) code);
109 assertEquals("foo", (String) message);
110 String stack = (String) details;
111 assertTrue(
112 stack.contains(
113 "at io.flutter.plugin.common.StandardMethodCodecTest.encodeErrorEnvelopeWithStacktraceTest(StandardMethodCodecTest.java:"));
114 assertEquals("error stacktrace", (String) stacktrace);
115 }
116}
static void fail(const SkString &err)
Definition: DM.cpp:234
final Object readValue(@NonNull ByteBuffer buffer)
ByteBuffer encodeSuccessEnvelope(@NonNull Object result)
ByteBuffer encodeErrorEnvelopeWithStacktrace( @NonNull String errorCode, @NonNull String errorMessage, @NonNull Object errorDetails, @NonNull String errorStacktrace)
ByteBuffer encodeErrorEnvelope( @NonNull String errorCode, @NonNull String errorMessage, @NonNull Object errorDetails)
Object decodeEnvelope(@NonNull ByteBuffer envelope)
ByteBuffer encodeMethodCall(@NonNull MethodCall methodCall)
MethodCall decodeMethodCall(@NonNull ByteBuffer methodCall)
FlutterSemanticsFlag flag
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
static ::testing::Matcher< GBytes * > MethodCall(const std::string &name, ::testing::Matcher< FlValue * > args)
GAsyncResult * result
Win32Message message
def call(args)
Definition: dom.py:159
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126