Flutter Engine
The Flutter Engine
fl_method_response_test.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/linux/public/flutter_linux/fl_method_response.h"
6#include "gtest/gtest.h"
7
8TEST(FlMethodResponseTest, Success) {
9 g_autoptr(FlValue) result = fl_value_new_int(42);
10 g_autoptr(FlMethodSuccessResponse) response =
12 g_autoptr(FlValue) expected = fl_value_new_int(42);
14 expected));
15}
16
17TEST(FlMethodResponseTest, Error) {
18 g_autoptr(FlMethodErrorResponse) response =
19 fl_method_error_response_new("code", nullptr, nullptr);
20 EXPECT_STREQ(fl_method_error_response_get_code(response), "code");
21 EXPECT_EQ(fl_method_error_response_get_message(response), nullptr);
22 EXPECT_EQ(fl_method_error_response_get_details(response), nullptr);
23}
24
25TEST(FlMethodResponseTest, ErrorMessage) {
26 g_autoptr(FlMethodErrorResponse) response =
27 fl_method_error_response_new("code", "message", nullptr);
28 EXPECT_STREQ(fl_method_error_response_get_code(response), "code");
29 EXPECT_STREQ(fl_method_error_response_get_message(response), "message");
30 EXPECT_EQ(fl_method_error_response_get_details(response), nullptr);
31}
32
33TEST(FlMethodResponseTest, ErrorDetails) {
34 g_autoptr(FlValue) details = fl_value_new_int(42);
35 g_autoptr(FlMethodErrorResponse) response =
36 fl_method_error_response_new("code", nullptr, details);
37 EXPECT_STREQ(fl_method_error_response_get_code(response), "code");
38 EXPECT_EQ(fl_method_error_response_get_message(response), nullptr);
39 g_autoptr(FlValue) expected_details = fl_value_new_int(42);
41 expected_details));
42}
43
44TEST(FlMethodResponseTest, ErrorMessageAndDetails) {
45 g_autoptr(FlValue) details = fl_value_new_int(42);
46 g_autoptr(FlMethodErrorResponse) response =
47 fl_method_error_response_new("code", "message", details);
48 EXPECT_STREQ(fl_method_error_response_get_code(response), "code");
49 EXPECT_STREQ(fl_method_error_response_get_message(response), "message");
50 g_autoptr(FlValue) expected_details = fl_value_new_int(42);
52 expected_details));
53}
54
55TEST(FlMethodResponseTest, NotImplemented) {
56 g_autoptr(FlMethodNotImplementedResponse) response =
58 // Trivial check to stop the compiler deciding that 'response' is an unused
59 // variable.
60 EXPECT_TRUE(FL_IS_METHOD_NOT_IMPLEMENTED_RESPONSE(response));
61}
62
63TEST(FlMethodResponseTest, SuccessGetResult) {
64 g_autoptr(FlValue) r = fl_value_new_int(42);
65 g_autoptr(FlMethodSuccessResponse) response =
67 g_autoptr(GError) error = nullptr;
69 fl_method_response_get_result(FL_METHOD_RESPONSE(response), &error);
70 ASSERT_NE(result, nullptr);
71 EXPECT_EQ(error, nullptr);
72 g_autoptr(FlValue) expected = fl_value_new_int(42);
73 ASSERT_TRUE(fl_value_equal(result, expected));
74}
75
76TEST(FlMethodResponseTest, ErrorGetResult) {
77 g_autoptr(FlMethodErrorResponse) response =
78 fl_method_error_response_new("code", nullptr, nullptr);
79 g_autoptr(GError) error = nullptr;
80 g_autoptr(FlValue) result =
81 fl_method_response_get_result(FL_METHOD_RESPONSE(response), &error);
82 EXPECT_EQ(result, nullptr);
85}
86
87TEST(FlMethodResponseTest, NotImplementedGetResult) {
88 g_autoptr(FlMethodNotImplementedResponse) response =
90 g_autoptr(GError) error = nullptr;
91 g_autoptr(FlValue) result =
92 fl_method_response_get_result(FL_METHOD_RESPONSE(response), &error);
93 EXPECT_EQ(result, nullptr);
96}
G_MODULE_EXPORT FlValue * fl_method_response_get_result(FlMethodResponse *self, GError **error)
G_MODULE_EXPORT FlValue * fl_method_success_response_get_result(FlMethodSuccessResponse *self)
G_MODULE_EXPORT FlMethodErrorResponse * fl_method_error_response_new(const gchar *code, const gchar *message, FlValue *details)
G_MODULE_EXPORT const gchar * fl_method_error_response_get_message(FlMethodErrorResponse *self)
G_MODULE_EXPORT FlMethodSuccessResponse * fl_method_success_response_new(FlValue *result)
G_MODULE_EXPORT FlValue * fl_method_error_response_get_details(FlMethodErrorResponse *self)
G_MODULE_EXPORT const gchar * fl_method_error_response_get_code(FlMethodErrorResponse *self)
G_MODULE_EXPORT FlMethodNotImplementedResponse * fl_method_not_implemented_response_new()
@ FL_METHOD_RESPONSE_ERROR_NOT_IMPLEMENTED
@ FL_METHOD_RESPONSE_ERROR_REMOTE_ERROR
#define FL_METHOD_RESPONSE_ERROR
TEST(FlMethodResponseTest, Success)
const uint8_t uint32_t uint32_t GError ** error
GAsyncResult * result
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
Definition: fl_value.cc:262
G_MODULE_EXPORT bool fl_value_equal(FlValue *a, FlValue *b)
Definition: fl_value.cc:471
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42
#define EXPECT_TRUE(handle)
Definition: unit_test.h:678