Flutter Engine
 
Loading...
Searching...
No Matches
fl_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 "gtest/gtest.h"
6
8
11
12namespace {
13class ImModuleEnv : public ::testing::Environment {
14 public:
15 void SetUp() override {
16 setenv("GTK_IM_MODULE", "gtk-im-context-simple", true);
17 }
18};
19
20testing::Environment* const kEnv =
21 testing::AddGlobalTestEnvironment(new ImModuleEnv);
22} // namespace
23
24static uint8_t hex_digit_to_int(char value) {
25 if (value >= '0' && value <= '9') {
26 return value - '0';
27 } else if (value >= 'a' && value <= 'f') {
28 return value - 'a' + 10;
29 } else if (value >= 'F' && value <= 'F') {
30 return value - 'A' + 10;
31 } else {
32 return 0;
33 }
34}
35
36static uint8_t parse_hex8(const gchar* hex_string) {
37 if (hex_string[0] == '\0') {
38 return 0x00;
39 }
40 return hex_digit_to_int(hex_string[0]) << 4 | hex_digit_to_int(hex_string[1]);
41}
42
43GBytes* hex_string_to_bytes(const gchar* hex_string) {
44 GByteArray* buffer = g_byte_array_new();
45 for (int i = 0; hex_string[i] != '\0' && hex_string[i + 1] != '\0'; i += 2) {
46 uint8_t value = parse_hex8(hex_string + i);
47 g_byte_array_append(buffer, &value, 1);
48 }
49 return g_byte_array_free_to_bytes(buffer);
50}
51
52gchar* bytes_to_hex_string(GBytes* bytes) {
53 GString* hex_string = g_string_new("");
54 size_t data_length;
55 const uint8_t* data =
56 static_cast<const uint8_t*>(g_bytes_get_data(bytes, &data_length));
57 for (size_t i = 0; i < data_length; i++) {
58 g_string_append_printf(hex_string, "%02x", data[i]);
59 }
60 return g_string_free(hex_string, FALSE);
61}
62
63void PrintTo(FlValue* v, std::ostream* os) {
64 g_autofree gchar* s = fl_value_to_string(v);
65 *os << s;
66}
int32_t value
g_byte_array_append(buffer, &type, sizeof(uint8_t))
static uint8_t hex_digit_to_int(char value)
Definition fl_test.cc:24
void PrintTo(FlValue *v, std::ostream *os)
Definition fl_test.cc:63
static uint8_t parse_hex8(const gchar *hex_string)
Definition fl_test.cc:36
GBytes * hex_string_to_bytes(const gchar *hex_string)
Definition fl_test.cc:43
gchar * bytes_to_hex_string(GBytes *bytes)
Definition fl_test.cc:52
G_MODULE_EXPORT gchar * fl_value_to_string(FlValue *value)
Definition fl_value.cc:846
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition fl_value.h:42
std::shared_ptr< const fml::Mapping > data