Flutter Engine
cf_utils_unittests.mm
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/fml/platform/darwin/cf_utils.h"
6 
7 #include "flutter/testing/testing.h"
8 
9 namespace fml {
10 namespace testing {
11 
12 TEST(CFTest, CanCreateRefs) {
13  CFRef<CFMutableStringRef> string(CFStringCreateMutable(kCFAllocatorDefault, 100u));
14  // Cast
15  ASSERT_TRUE(static_cast<bool>(string));
16  ASSERT_TRUE(string);
17 
18  const auto ref_count = CFGetRetainCount(string);
19 
20  // Copy & Reset
21  {
22  CFRef<CFMutableStringRef> string2 = string;
23  ASSERT_TRUE(string2);
24  ASSERT_EQ(ref_count + 1u, CFGetRetainCount(string));
25  ASSERT_EQ(CFGetRetainCount(string2), CFGetRetainCount(string));
26 
27  string2.Reset();
28  ASSERT_FALSE(string2);
29  ASSERT_EQ(ref_count, CFGetRetainCount(string));
30  }
31 
32  // Release
33  {
34  auto string3 = string;
35  ASSERT_TRUE(string3);
36  ASSERT_EQ(ref_count + 1u, CFGetRetainCount(string));
37  auto raw_string3 = string3.Release();
38  ASSERT_FALSE(string3);
39  ASSERT_EQ(ref_count + 1u, CFGetRetainCount(string));
40  CFRelease(raw_string3);
41  ASSERT_EQ(ref_count, CFGetRetainCount(string));
42  }
43 
44  // Move
45  {
46  auto string_source = string;
47  ASSERT_TRUE(string_source);
48  auto string_move = std::move(string_source);
49  ASSERT_FALSE(string_source);
50  ASSERT_EQ(ref_count + 1u, CFGetRetainCount(string));
51  string_move.Reset();
52  ASSERT_EQ(ref_count, CFGetRetainCount(string));
53  }
54 
55  // Move assign.
56  {
57  auto string_move_assign = std::move(string);
58  ASSERT_FALSE(string);
59  ASSERT_EQ(ref_count, CFGetRetainCount(string_move_assign));
60  }
61 }
62 
63 } // namespace testing
64 } // namespace fml
void Reset(T instance=nullptr)
Definition: cf_utils.h:43
Definition: ascii_trie.cc:9
TEST(BacktraceTest, CanGatherBacktrace)