7#import <CoreFoundation/CoreFoundation.h>
9#include "flutter/fml/platform/darwin/scoped_nsobject.h"
11#include "gtest/gtest.h"
13#if !defined(__has_feature) || !__has_feature(objc_arc)
14#error "This file requires ARC support."
19template <
typename NST>
22 return CFGetRetainCount((__bridge CFTypeRef)nst.
get()) - 1;
26#if __has_feature(objc_arc_weak)
27TEST(ScopedNSObjectTestARC, DefaultPolicyIsRetain) {
32 EXPECT_EQ(o,
p.get());
38TEST(ScopedNSObjectTestARC, ScopedNSObject) {
44 EXPECT_EQ(1, GetRetainCount(p1));
45 EXPECT_EQ(1, GetRetainCount(p1));
48 EXPECT_EQ(p1.get(), p2.get());
50 EXPECT_EQ(2, GetRetainCount(p1));
52 EXPECT_EQ(nil, p2.get());
53 EXPECT_EQ(1, GetRetainCount(p1));
57 EXPECT_EQ(p1.get(), p3.
get());
59 EXPECT_EQ(2, GetRetainCount(p1));
62 EXPECT_EQ(p1.get(), p3.
get());
64 EXPECT_EQ(2, GetRetainCount(p1));
66 EXPECT_EQ(1, GetRetainCount(p1));
71 EXPECT_EQ(2, GetRetainCount(p1));
75 EXPECT_FALSE(p1 != p1);
76 EXPECT_FALSE(p1 != p1.get());
82 EXPECT_FALSE(p1 == p5);
83 EXPECT_FALSE(p1 == p5.get());
87 EXPECT_EQ(3, GetRetainCount(p6));
90 EXPECT_EQ(nil, p6.
get());
92 EXPECT_EQ(2, GetRetainCount(p1));
95TEST(ScopedNSObjectTestARC, ScopedNSObjectInContainer) {
100 EXPECT_EQ(1, GetRetainCount(
p));
102 std::vector<fml::scoped_nsobject<id>> objects;
103 objects.push_back(
p);
104 EXPECT_EQ(2, GetRetainCount(
p));
106 EXPECT_EQ(
p.get(), objects[0].get());
112 EXPECT_EQ(1, GetRetainCount(objects[1]));
114 EXPECT_EQ(1, GetRetainCount(
p));
117TEST(ScopedNSObjectTestARC, ScopedNSObjectFreeFunctions) {
121 EXPECT_FALSE(o1 != p1);
124 EXPECT_FALSE(o1 == p2);
127 EXPECT_EQ(o2, p1.get());
128 EXPECT_EQ(o1, p2.get());
#define TEST(S, s, D, expected)
void swap(sk_sp< T > &a, sk_sp< T > &b)
T get() const __attribute((ns_returns_not_retained))
NST autorelease() __attribute((ns_returns_not_retained))
const myers::Point & get(const myers::Segment &)
#define EXPECT_TRUE(handle)