| Flutter macOS Embedder |

method_result_functions_unittests.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "flutter/shell/platform/common/client_wrapper/include/flutter/method_result_functions.h"
6
7 #include <functional>
8 #include <string>
9
10 #include "gtest/gtest.h"
11
12 namespace flutter {
13
14 // Tests that unset handlers don't cause crashes.
15 TEST(MethodChannelTest, NoHandlers) {
16 MethodResultFunctions<int> result(nullptr, nullptr, nullptr);
17 result.Success();
18 result.Error("error");
19 result.NotImplemented();
20 }
21
22 // Tests that Success calls through to handler.
23 TEST(MethodChannelTest, Success) {
24 bool called = false;
25 int value = 1;
26 MethodResultFunctions<int> result(
27 [&called, value](const int* i) {
28 called = true;
29 EXPECT_EQ(*i, value);
30 },
31 nullptr, nullptr);
32 result.Success(value);
33 EXPECT_TRUE(called);
34 }
35
36 // Tests that Error calls through to handler.
37 TEST(MethodChannelTest, Error) {
38 bool called = false;
39 std::string error_code = "a";
40 std::string error_message = "b";
41 int error_details = 1;
42 MethodResultFunctions<int> result(
43 nullptr,
44 [&called, error_code, error_message, error_details](
45 const std::string& code, const std::string& message,
46 const int* details) {
47 called = true;
48 EXPECT_EQ(code, error_code);
49 EXPECT_EQ(message, error_message);
50 EXPECT_EQ(*details, error_details);
51 },
52 nullptr);
53 result.Error(error_code, error_message, error_details);
54 EXPECT_TRUE(called);
55 }
56
57 // Tests that NotImplemented calls through to handler.
58 TEST(MethodChannelTest, NotImplemented) {
59 bool called = false;
60 MethodResultFunctions<int> result(nullptr, nullptr,
61 [&called]() { called = true; });
62 result.NotImplemented();
63 EXPECT_TRUE(called);
64 }
65
66 } // namespace flutter
flutter::TEST
TEST(BasicMessageChannelTest, Registration)
Definition: basic_message_channel_unittests.cc:58
method_result_functions.h
flutter::MethodResult< EncodableValue >::Error
void Error(const std::string &error_code, const std::string &error_message, const EncodableValue &error_details)
Definition: method_result.h:41
flutter
Definition: AccessibilityBridgeMac.h:16
flutter::MethodResult< EncodableValue >::Success
void Success(const EncodableValue &result)
Definition: method_result.h:29
flutter::MethodResultFunctions
Definition: method_result_functions.h:31
flutter::MethodResult< EncodableValue >::NotImplemented
void NotImplemented()
Definition: method_result.h:59