| Flutter Linux Embedder |

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
8 TEST(FlMethodResponseTest, Success) {
9 g_autoptr(FlValue) result = fl_value_new_int(42);
10 g_autoptr(FlMethodSuccessResponse) response =
11 fl_method_success_response_new(result);
12 g_autoptr(FlValue) expected = fl_value_new_int(42);
13 ASSERT_TRUE(fl_value_equal(fl_method_success_response_get_result(response),
14 expected));
15 }
16
17 TEST(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
25 TEST(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
33 TEST(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);
40 EXPECT_TRUE(fl_value_equal(fl_method_error_response_get_details(response),
41 expected_details));
42 }
43
44 TEST(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);
51 EXPECT_TRUE(fl_value_equal(fl_method_error_response_get_details(response),
52 expected_details));
53 }
54
55 TEST(FlMethodResponseTest, NotImplemented) {
56 g_autoptr(FlMethodNotImplementedResponse) response =
57 fl_method_not_implemented_response_new();
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
63 TEST(FlMethodResponseTest, SuccessGetResult) {
64 g_autoptr(FlValue) r = fl_value_new_int(42);
65 g_autoptr(FlMethodSuccessResponse) response =
66 fl_method_success_response_new(r);
67 g_autoptr(GError) error = nullptr;
68 FlValue* result =
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
76 TEST(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);
83 EXPECT_TRUE(g_error_matches(error, FL_METHOD_RESPONSE_ERROR,
84 FL_METHOD_RESPONSE_ERROR_REMOTE_ERROR));
85 }
86
87 TEST(FlMethodResponseTest, NotImplementedGetResult) {
88 g_autoptr(FlMethodNotImplementedResponse) response =
89 fl_method_not_implemented_response_new();
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);
94 EXPECT_TRUE(g_error_matches(error, FL_METHOD_RESPONSE_ERROR,
95 FL_METHOD_RESPONSE_ERROR_NOT_IMPLEMENTED));
96 }
fl_method_error_response_new
G_MODULE_EXPORT FlMethodErrorResponse * fl_method_error_response_new(const gchar *code, const gchar *message, FlValue *details)
Definition: fl_method_response.cc:144
fl_method_not_implemented_response_new
G_MODULE_EXPORT FlMethodNotImplementedResponse * fl_method_not_implemented_response_new()
Definition: fl_method_response.cc:179
FL_METHOD_RESPONSE_ERROR_REMOTE_ERROR
@ FL_METHOD_RESPONSE_ERROR_REMOTE_ERROR
Definition: fl_method_response.h:35
FL_METHOD_RESPONSE_ERROR_NOT_IMPLEMENTED
@ FL_METHOD_RESPONSE_ERROR_NOT_IMPLEMENTED
Definition: fl_method_response.h:36
FlValue
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42
fl_method_response_get_result
G_MODULE_EXPORT FlValue * fl_method_response_get_result(FlMethodResponse *self, GError **error)
Definition: fl_method_response.cc:82
fl_value_new_int
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
Definition: fl_value.cc:262
fl_method_error_response_get_message
const G_MODULE_EXPORT gchar * fl_method_error_response_get_message(FlMethodErrorResponse *self)
Definition: fl_method_response.cc:166
fl_method_success_response_new
G_MODULE_EXPORT FlMethodSuccessResponse * fl_method_success_response_new(FlValue *result)
Definition: fl_method_response.cc:126
fl_method_error_response_get_details
G_MODULE_EXPORT FlValue * fl_method_error_response_get_details(FlMethodErrorResponse *self)
Definition: fl_method_response.cc:172
TEST
TEST(FlMethodResponseTest, Success)
Definition: fl_method_response_test.cc:8
FL_METHOD_RESPONSE_ERROR
#define FL_METHOD_RESPONSE_ERROR
Definition: fl_method_response.h:30
fl_method_success_response_get_result
G_MODULE_EXPORT FlValue * fl_method_success_response_get_result(FlMethodSuccessResponse *self)
Definition: fl_method_response.cc:138
fl_method_response.h
fl_value_equal
G_MODULE_EXPORT bool fl_value_equal(FlValue *a, FlValue *b)
Definition: fl_value.cc:471
result
GAsyncResult * result
Definition: fl_text_input_handler.cc:106
fl_method_error_response_get_code
const G_MODULE_EXPORT gchar * fl_method_error_response_get_code(FlMethodErrorResponse *self)
Definition: fl_method_response.cc:160
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40