Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
12namespace flutter {
13
14// Tests that unset handlers don't cause crashes.
15TEST(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.
23TEST(MethodChannelTest, Success) {
24 bool called = false;
25 int value = 1;
27 [&called, value](const int* i) {
28 called = true;
29 EXPECT_EQ(*i, value);
30 },
31 nullptr, nullptr);
33 EXPECT_TRUE(called);
34}
35
36// Tests that Error calls through to handler.
37TEST(MethodChannelTest, Error) {
38 bool called = false;
39 std::string error_code = "a";
40 std::string error_message = "b";
41 int error_details = 1;
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.
58TEST(MethodChannelTest, NotImplemented) {
59 bool called = false;
60 MethodResultFunctions<int> result(nullptr, nullptr,
61 [&called]() { called = true; });
63 EXPECT_TRUE(called);
64}
65
66} // namespace flutter
#define TEST(S, s, D, expected)
void Error(const std::string &error_code, const std::string &error_message, const T &error_details)
void Success(const T &result)
uint8_t value
GAsyncResult * result
Win32Message message
#define EXPECT_TRUE(handle)
Definition unit_test.h:685