fml: delete scoped_nsobject.h,mm (flutter/engine#56382)
fml::scoped_nsobject and fml::scoped_nsprotocol classes are no longer necessary now that the entire codebase has been migrated to ARC. This also eliminates the fml_arc_unittests target which tests that code. All references to that target in documentation, run_tests.py have been removed. This target was used in various `et` build/query unit tests and has been replaced with the fml_unittests target in those cases. Issue: https://github.com/flutter/flutter/issues/137801
This commit is contained in:
@@ -186,7 +186,6 @@ group("unittests") {
|
||||
"//flutter/display_list:display_list_rendertests",
|
||||
"//flutter/display_list:display_list_unittests",
|
||||
"//flutter/flow:flow_unittests",
|
||||
"//flutter/fml:fml_arc_unittests",
|
||||
"//flutter/fml:fml_unittests",
|
||||
"//flutter/lib/ui:ui_unittests",
|
||||
"//flutter/runtime:dart_plugin_registrant_unittests",
|
||||
|
||||
@@ -256,7 +256,6 @@ $ ./run_tests.py --variant=host_debug_unopt_arm64 --type=engine
|
||||
| felt | n/a | The test runner for flutter web. See //lib/web_ui |
|
||||
| flow_unittests | engine | |
|
||||
| flutter_tester | dart | Launcher for engine dart tests. |
|
||||
| fml_arc_unittests | engine | |
|
||||
| fml_unittests | engine | Unit tests for //fml |
|
||||
| framework_common_unittests | engine(mac) | |
|
||||
| gpu_surface_metal_unittests | engine(mac) | |
|
||||
|
||||
@@ -107,8 +107,6 @@
|
||||
../../../flutter/fml/message_loop_unittests.cc
|
||||
../../../flutter/fml/paths_unittests.cc
|
||||
../../../flutter/fml/platform/darwin/cf_utils_unittests.mm
|
||||
../../../flutter/fml/platform/darwin/scoped_nsobject_arc_unittests.mm
|
||||
../../../flutter/fml/platform/darwin/scoped_nsobject_unittests.mm
|
||||
../../../flutter/fml/platform/darwin/string_range_sanitization_unittests.mm
|
||||
../../../flutter/fml/platform/fuchsia/log_interest_listener_unittests.cc
|
||||
../../../flutter/fml/platform/win/file_win_unittests.cc
|
||||
|
||||
@@ -42733,8 +42733,6 @@ ORIGIN: ../../../flutter/fml/platform/darwin/scoped_block.h + ../../../flutter/L
|
||||
ORIGIN: ../../../flutter/fml/platform/darwin/scoped_block.mm + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/fml/platform/darwin/scoped_nsautorelease_pool.cc + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/fml/platform/darwin/scoped_nsautorelease_pool.h + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/fml/platform/darwin/scoped_nsobject.h + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/fml/platform/darwin/scoped_nsobject.mm + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/fml/platform/darwin/scoped_policy.h + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/fml/platform/darwin/scoped_typeref.h + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/fml/platform/darwin/string_range_sanitization.h + ../../../flutter/LICENSE
|
||||
@@ -45597,8 +45595,6 @@ FILE: ../../../flutter/fml/platform/darwin/scoped_block.h
|
||||
FILE: ../../../flutter/fml/platform/darwin/scoped_block.mm
|
||||
FILE: ../../../flutter/fml/platform/darwin/scoped_nsautorelease_pool.cc
|
||||
FILE: ../../../flutter/fml/platform/darwin/scoped_nsautorelease_pool.h
|
||||
FILE: ../../../flutter/fml/platform/darwin/scoped_nsobject.h
|
||||
FILE: ../../../flutter/fml/platform/darwin/scoped_nsobject.mm
|
||||
FILE: ../../../flutter/fml/platform/darwin/scoped_policy.h
|
||||
FILE: ../../../flutter/fml/platform/darwin/scoped_typeref.h
|
||||
FILE: ../../../flutter/fml/platform/darwin/string_range_sanitization.h
|
||||
|
||||
@@ -156,8 +156,6 @@ source_set("fml") {
|
||||
"platform/darwin/scoped_block.mm",
|
||||
"platform/darwin/scoped_nsautorelease_pool.cc",
|
||||
"platform/darwin/scoped_nsautorelease_pool.h",
|
||||
"platform/darwin/scoped_nsobject.h",
|
||||
"platform/darwin/scoped_nsobject.mm",
|
||||
"platform/darwin/scoped_policy.h",
|
||||
"platform/darwin/scoped_typeref.h",
|
||||
"platform/darwin/string_range_sanitization.h",
|
||||
@@ -374,10 +372,6 @@ if (enable_unittests) {
|
||||
]
|
||||
}
|
||||
|
||||
if (is_mac || is_ios) {
|
||||
sources += [ "platform/darwin/scoped_nsobject_unittests.mm" ]
|
||||
}
|
||||
|
||||
if (is_fuchsia) {
|
||||
sources += [ "platform/fuchsia/log_interest_listener_unittests.cc" ]
|
||||
}
|
||||
@@ -408,18 +402,4 @@ if (enable_unittests) {
|
||||
libs = [ "${fuchsia_arch_root}/sysroot/lib/libzircon.so" ]
|
||||
}
|
||||
}
|
||||
|
||||
executable("fml_arc_unittests") {
|
||||
testonly = true
|
||||
if (is_mac || is_ios) {
|
||||
cflags_objcc = flutter_cflags_objc_arc
|
||||
sources = [ "platform/darwin/scoped_nsobject_arc_unittests.mm" ]
|
||||
}
|
||||
|
||||
deps = [
|
||||
":fml_fixtures",
|
||||
"//flutter/fml",
|
||||
"//flutter/testing",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,248 +0,0 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef FLUTTER_FML_PLATFORM_DARWIN_SCOPED_NSOBJECT_H_
|
||||
#define FLUTTER_FML_PLATFORM_DARWIN_SCOPED_NSOBJECT_H_
|
||||
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
// Include NSObject.h directly because Foundation.h pulls in many dependencies.
|
||||
// (Approx 100k lines of code versus 1.5k for NSObject.h). scoped_nsobject gets
|
||||
// singled out because it is most typically included from other header files.
|
||||
#import <Foundation/NSObject.h>
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/fml/platform/darwin/scoped_typeref.h"
|
||||
|
||||
#if !defined(__has_feature) || !__has_feature(objc_arc)
|
||||
@class NSAutoreleasePool;
|
||||
#endif
|
||||
|
||||
namespace fml {
|
||||
|
||||
// scoped_nsobject<> is patterned after scoped_ptr<>, but maintains ownership
|
||||
// of an NSObject subclass object. Style deviations here are solely for
|
||||
// compatibility with scoped_ptr<>'s interface, with which everyone is already
|
||||
// familiar.
|
||||
//
|
||||
// scoped_nsobject<> takes ownership of an object (in the constructor or in
|
||||
// reset()) by taking over the caller's existing ownership claim. The caller
|
||||
// must own the object it gives to scoped_nsobject<>, and relinquishes an
|
||||
// ownership claim to that object. scoped_nsobject<> does not call -retain,
|
||||
// callers have to call this manually if appropriate.
|
||||
//
|
||||
// scoped_nsprotocol<> has the same behavior as scoped_nsobject, but can be used
|
||||
// with protocols.
|
||||
//
|
||||
// scoped_nsobject<> is not to be used for NSAutoreleasePools. For
|
||||
// NSAutoreleasePools use ScopedNSAutoreleasePool from
|
||||
// scoped_nsautorelease_pool.h instead.
|
||||
// We check for bad uses of scoped_nsobject and NSAutoreleasePool at compile
|
||||
// time with a template specialization (see below).
|
||||
//
|
||||
// If Automatic Reference Counting (aka ARC) is enabled then the ownership
|
||||
// policy is not controllable by the user as ARC make it really difficult to
|
||||
// transfer ownership (the reference passed to scoped_nsobject constructor is
|
||||
// sunk by ARC and __attribute((ns_consumed)) appears to not work correctly
|
||||
// with Objective-C++ see https://llvm.org/bugs/show_bug.cgi?id=27887). Due to
|
||||
// that, the policy is always to |RETAIN| when using ARC.
|
||||
|
||||
namespace internal {
|
||||
|
||||
id ScopedNSProtocolTraitsRetain(__unsafe_unretained id obj)
|
||||
__attribute((ns_returns_not_retained));
|
||||
id ScopedNSProtocolTraitsAutoRelease(__unsafe_unretained id obj)
|
||||
__attribute((ns_returns_not_retained));
|
||||
void ScopedNSProtocolTraitsRelease(__unsafe_unretained id obj);
|
||||
|
||||
// Traits for ScopedTypeRef<>. As this class may be compiled from file with
|
||||
// Automatic Reference Counting enable or not all methods have annotation to
|
||||
// enforce the same code generation in both case (in particular, the Retain
|
||||
// method uses ns_returns_not_retained to prevent ARC to insert a -release
|
||||
// call on the returned value and thus defeating the -retain).
|
||||
template <typename NST>
|
||||
struct ScopedNSProtocolTraits {
|
||||
static NST InvalidValue() __attribute((ns_returns_not_retained)) {
|
||||
return nil;
|
||||
}
|
||||
static NST Retain(__unsafe_unretained NST nst)
|
||||
__attribute((ns_returns_not_retained)) {
|
||||
return ScopedNSProtocolTraitsRetain(nst);
|
||||
}
|
||||
static void Release(__unsafe_unretained NST nst) {
|
||||
ScopedNSProtocolTraitsRelease(nst);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
template <typename NST>
|
||||
class scoped_nsprotocol
|
||||
: public ScopedTypeRef<NST, internal::ScopedNSProtocolTraits<NST>> {
|
||||
public:
|
||||
using Traits = internal::ScopedNSProtocolTraits<NST>;
|
||||
|
||||
#if !defined(__has_feature) || !__has_feature(objc_arc)
|
||||
explicit scoped_nsprotocol(NST object = Traits::InvalidValue(),
|
||||
scoped_policy::OwnershipPolicy policy =
|
||||
scoped_policy::OwnershipPolicy::kAssume)
|
||||
: ScopedTypeRef<NST, Traits>(object, policy) {}
|
||||
#else
|
||||
explicit scoped_nsprotocol(NST object = Traits::InvalidValue())
|
||||
: ScopedTypeRef<NST, Traits>(object,
|
||||
scoped_policy::OwnershipPolicy::kRetain) {}
|
||||
#endif
|
||||
|
||||
// NOLINTNEXTLINE(google-explicit-constructor)
|
||||
scoped_nsprotocol(const scoped_nsprotocol<NST>& that)
|
||||
: ScopedTypeRef<NST, Traits>(that) {}
|
||||
|
||||
template <typename NSR>
|
||||
explicit scoped_nsprotocol(const scoped_nsprotocol<NSR>& that_as_subclass)
|
||||
: ScopedTypeRef<NST, Traits>(that_as_subclass) {}
|
||||
|
||||
// NOLINTNEXTLINE(google-explicit-constructor)
|
||||
scoped_nsprotocol(scoped_nsprotocol<NST>&& that)
|
||||
: ScopedTypeRef<NST, Traits>(std::move(that)) {}
|
||||
|
||||
scoped_nsprotocol& operator=(const scoped_nsprotocol<NST>& that) {
|
||||
ScopedTypeRef<NST, Traits>::operator=(that);
|
||||
return *this;
|
||||
}
|
||||
|
||||
#if !defined(__has_feature) || !__has_feature(objc_arc)
|
||||
void reset(NST object = Traits::InvalidValue(),
|
||||
scoped_policy::OwnershipPolicy policy =
|
||||
scoped_policy::OwnershipPolicy::kAssume) {
|
||||
ScopedTypeRef<NST, Traits>::reset(object, policy);
|
||||
}
|
||||
#else
|
||||
void reset(NST object = Traits::InvalidValue()) {
|
||||
ScopedTypeRef<NST, Traits>::reset(object,
|
||||
scoped_policy::OwnershipPolicy::kRetain);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Shift reference to the autorelease pool to be released later.
|
||||
NST autorelease() __attribute((ns_returns_not_retained)) {
|
||||
return internal::ScopedNSProtocolTraitsAutoRelease(this->release());
|
||||
}
|
||||
};
|
||||
|
||||
// Free functions
|
||||
template <class C>
|
||||
void swap(scoped_nsprotocol<C>& p1, scoped_nsprotocol<C>& p2) {
|
||||
p1.swap(p2);
|
||||
}
|
||||
|
||||
template <class C>
|
||||
bool operator==(C p1, const scoped_nsprotocol<C>& p2) {
|
||||
return p1 == p2.get();
|
||||
}
|
||||
|
||||
template <class C>
|
||||
bool operator!=(C p1, const scoped_nsprotocol<C>& p2) {
|
||||
return p1 != p2.get();
|
||||
}
|
||||
|
||||
template <typename NST>
|
||||
class scoped_nsobject : public scoped_nsprotocol<NST*> {
|
||||
public:
|
||||
using Traits = typename scoped_nsprotocol<NST*>::Traits;
|
||||
|
||||
#if !defined(__has_feature) || !__has_feature(objc_arc)
|
||||
explicit scoped_nsobject(NST* object = Traits::InvalidValue(),
|
||||
scoped_policy::OwnershipPolicy policy =
|
||||
scoped_policy::OwnershipPolicy::kAssume)
|
||||
: scoped_nsprotocol<NST*>(object, policy) {}
|
||||
#else
|
||||
explicit scoped_nsobject(NST* object = Traits::InvalidValue())
|
||||
: scoped_nsprotocol<NST*>(object) {}
|
||||
#endif
|
||||
|
||||
// NOLINTNEXTLINE(google-explicit-constructor)
|
||||
scoped_nsobject(const scoped_nsobject<NST>& that)
|
||||
: scoped_nsprotocol<NST*>(that) {}
|
||||
|
||||
template <typename NSR>
|
||||
explicit scoped_nsobject(const scoped_nsobject<NSR>& that_as_subclass)
|
||||
: scoped_nsprotocol<NST*>(that_as_subclass) {}
|
||||
|
||||
// NOLINTNEXTLINE(google-explicit-constructor)
|
||||
scoped_nsobject(scoped_nsobject<NST>&& that)
|
||||
: scoped_nsprotocol<NST*>(std::move(that)) {}
|
||||
|
||||
scoped_nsobject& operator=(const scoped_nsobject<NST>& that) {
|
||||
scoped_nsprotocol<NST*>::operator=(that);
|
||||
return *this;
|
||||
}
|
||||
|
||||
#if !defined(__has_feature) || !__has_feature(objc_arc)
|
||||
void reset(NST* object = Traits::InvalidValue(),
|
||||
scoped_policy::OwnershipPolicy policy =
|
||||
scoped_policy::OwnershipPolicy::kAssume) {
|
||||
scoped_nsprotocol<NST*>::reset(object, policy);
|
||||
}
|
||||
#else
|
||||
void reset(NST* object = Traits::InvalidValue()) {
|
||||
scoped_nsprotocol<NST*>::reset(object);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(__has_feature) || !__has_feature(objc_arc)
|
||||
static_assert(std::is_same<NST, NSAutoreleasePool>::value == false,
|
||||
"Use ScopedNSAutoreleasePool instead");
|
||||
#endif
|
||||
};
|
||||
|
||||
// Specialization to make scoped_nsobject<id> work.
|
||||
template <>
|
||||
class scoped_nsobject<id> : public scoped_nsprotocol<id> {
|
||||
public:
|
||||
using Traits = typename scoped_nsprotocol<id>::Traits;
|
||||
|
||||
#if !defined(__has_feature) || !__has_feature(objc_arc)
|
||||
explicit scoped_nsobject(id object = Traits::InvalidValue(),
|
||||
scoped_policy::OwnershipPolicy policy =
|
||||
scoped_policy::OwnershipPolicy::kAssume)
|
||||
: scoped_nsprotocol<id>(object, policy) {}
|
||||
#else
|
||||
explicit scoped_nsobject(id object = Traits::InvalidValue())
|
||||
: scoped_nsprotocol<id>(object) {}
|
||||
#endif
|
||||
|
||||
// NOLINTNEXTLINE(google-explicit-constructor)
|
||||
scoped_nsobject(const scoped_nsobject<id>& that)
|
||||
: scoped_nsprotocol<id>(that) {}
|
||||
|
||||
template <typename NSR>
|
||||
explicit scoped_nsobject(const scoped_nsobject<NSR>& that_as_subclass)
|
||||
: scoped_nsprotocol<id>(that_as_subclass) {}
|
||||
|
||||
// NOLINTNEXTLINE(google-explicit-constructor)
|
||||
scoped_nsobject(scoped_nsobject<id>&& that)
|
||||
: scoped_nsprotocol<id>(std::move(that)) {}
|
||||
|
||||
scoped_nsobject& operator=(const scoped_nsobject<id>& that) {
|
||||
scoped_nsprotocol<id>::operator=(that);
|
||||
return *this;
|
||||
}
|
||||
|
||||
#if !defined(__has_feature) || !__has_feature(objc_arc)
|
||||
void reset(id object = Traits::InvalidValue(),
|
||||
scoped_policy::OwnershipPolicy policy =
|
||||
scoped_policy::OwnershipPolicy::kAssume) {
|
||||
scoped_nsprotocol<id>::reset(object, policy);
|
||||
}
|
||||
#else
|
||||
void reset(id object = Traits::InvalidValue()) {
|
||||
scoped_nsprotocol<id>::reset(object);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace fml
|
||||
|
||||
#endif // FLUTTER_FML_PLATFORM_DARWIN_SCOPED_NSOBJECT_H_
|
||||
@@ -1,24 +0,0 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "flutter/fml/platform/darwin/scoped_nsobject.h"
|
||||
|
||||
namespace fml {
|
||||
|
||||
namespace internal {
|
||||
|
||||
id ScopedNSProtocolTraitsRetain(id obj) {
|
||||
return [obj retain];
|
||||
}
|
||||
|
||||
id ScopedNSProtocolTraitsAutoRelease(id obj) {
|
||||
return [obj autorelease];
|
||||
}
|
||||
|
||||
void ScopedNSProtocolTraitsRelease(id obj) {
|
||||
return [obj release];
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
} // namespace fml
|
||||
@@ -1,131 +0,0 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include <vector>
|
||||
|
||||
#import <CoreFoundation/CoreFoundation.h>
|
||||
|
||||
#include "flutter/fml/platform/darwin/scoped_nsobject.h"
|
||||
#include "fml/logging.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#if !defined(__has_feature) || !__has_feature(objc_arc)
|
||||
#error "This file requires ARC support."
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
template <typename NST>
|
||||
CFIndex GetRetainCount(const fml::scoped_nsobject<NST>& nst) {
|
||||
@autoreleasepool {
|
||||
return CFGetRetainCount((__bridge CFTypeRef)nst.get()) - 1;
|
||||
}
|
||||
}
|
||||
|
||||
#if __has_feature(objc_arc_weak)
|
||||
TEST(ScopedNSObjectTestARC, DefaultPolicyIsRetain) {
|
||||
__weak id o;
|
||||
@autoreleasepool {
|
||||
fml::scoped_nsprotocol<id> p([[NSObject alloc] init]);
|
||||
o = p.get();
|
||||
EXPECT_EQ(o, p.get());
|
||||
}
|
||||
EXPECT_EQ(o, nil);
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST(ScopedNSObjectTestARC, ScopedNSObject) {
|
||||
fml::scoped_nsobject<NSObject> p1([[NSObject alloc] init]);
|
||||
@autoreleasepool {
|
||||
EXPECT_TRUE(p1.get());
|
||||
EXPECT_TRUE(p1.get());
|
||||
}
|
||||
EXPECT_EQ(1, GetRetainCount(p1));
|
||||
EXPECT_EQ(1, GetRetainCount(p1));
|
||||
fml::scoped_nsobject<NSObject> p2(p1);
|
||||
@autoreleasepool {
|
||||
EXPECT_EQ(p1.get(), p2.get());
|
||||
}
|
||||
EXPECT_EQ(2, GetRetainCount(p1));
|
||||
p2.reset();
|
||||
EXPECT_EQ(nil, p2.get());
|
||||
EXPECT_EQ(1, GetRetainCount(p1));
|
||||
{
|
||||
fml::scoped_nsobject<NSObject> p3 = p1;
|
||||
@autoreleasepool {
|
||||
EXPECT_EQ(p1.get(), p3.get());
|
||||
}
|
||||
EXPECT_EQ(2, GetRetainCount(p1));
|
||||
p3 = p1;
|
||||
@autoreleasepool {
|
||||
EXPECT_EQ(p1.get(), p3.get());
|
||||
}
|
||||
EXPECT_EQ(2, GetRetainCount(p1));
|
||||
}
|
||||
EXPECT_EQ(1, GetRetainCount(p1));
|
||||
fml::scoped_nsobject<NSObject> p4;
|
||||
@autoreleasepool {
|
||||
p4 = fml::scoped_nsobject<NSObject>(p1.get());
|
||||
}
|
||||
EXPECT_EQ(2, GetRetainCount(p1));
|
||||
@autoreleasepool {
|
||||
EXPECT_TRUE(p1 == p1.get());
|
||||
EXPECT_TRUE(p1 == p1);
|
||||
EXPECT_FALSE(p1 != p1);
|
||||
EXPECT_FALSE(p1 != p1.get());
|
||||
}
|
||||
fml::scoped_nsobject<NSObject> p5([[NSObject alloc] init]);
|
||||
@autoreleasepool {
|
||||
EXPECT_TRUE(p1 != p5);
|
||||
EXPECT_TRUE(p1 != p5.get());
|
||||
EXPECT_FALSE(p1 == p5);
|
||||
EXPECT_FALSE(p1 == p5.get());
|
||||
}
|
||||
|
||||
fml::scoped_nsobject<NSObject> p6 = p1;
|
||||
EXPECT_EQ(3, GetRetainCount(p6));
|
||||
@autoreleasepool {
|
||||
p6.autorelease();
|
||||
EXPECT_EQ(nil, p6.get());
|
||||
}
|
||||
EXPECT_EQ(2, GetRetainCount(p1));
|
||||
}
|
||||
|
||||
TEST(ScopedNSObjectTestARC, ScopedNSObjectInContainer) {
|
||||
fml::scoped_nsobject<id> p([[NSObject alloc] init]);
|
||||
@autoreleasepool {
|
||||
EXPECT_TRUE(p.get());
|
||||
}
|
||||
EXPECT_EQ(1, GetRetainCount(p));
|
||||
@autoreleasepool {
|
||||
std::vector<fml::scoped_nsobject<id>> objects;
|
||||
objects.push_back(p);
|
||||
EXPECT_EQ(2, GetRetainCount(p));
|
||||
@autoreleasepool {
|
||||
EXPECT_EQ(p.get(), objects[0].get());
|
||||
}
|
||||
objects.push_back(fml::scoped_nsobject<id>([[NSObject alloc] init]));
|
||||
@autoreleasepool {
|
||||
EXPECT_TRUE(objects[1].get());
|
||||
}
|
||||
EXPECT_EQ(1, GetRetainCount(objects[1]));
|
||||
}
|
||||
EXPECT_EQ(1, GetRetainCount(p));
|
||||
}
|
||||
|
||||
TEST(ScopedNSObjectTestARC, ScopedNSObjectFreeFunctions) {
|
||||
fml::scoped_nsobject<id> p1([[NSObject alloc] init]);
|
||||
id o1 = p1.get();
|
||||
EXPECT_TRUE(o1 == p1);
|
||||
EXPECT_FALSE(o1 != p1);
|
||||
fml::scoped_nsobject<id> p2([[NSObject alloc] init]);
|
||||
EXPECT_TRUE(o1 != p2);
|
||||
EXPECT_FALSE(o1 == p2);
|
||||
id o2 = p2.get();
|
||||
swap(p1, p2);
|
||||
EXPECT_EQ(o2, p1.get());
|
||||
EXPECT_EQ(o1, p2.get());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -1,106 +0,0 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "flutter/fml/platform/darwin/scoped_nsautorelease_pool.h"
|
||||
#include "flutter/fml/platform/darwin/scoped_nsobject.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace {
|
||||
|
||||
// This is to suppress the bugprone-use-after-move warning.
|
||||
// This strategy is recommanded here:
|
||||
// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/use-after-move.html#silencing-erroneous-warnings
|
||||
template <class T>
|
||||
void IS_INITIALIZED(T&) {}
|
||||
|
||||
TEST(ScopedNSObjectTest, ScopedNSObject) {
|
||||
fml::scoped_nsobject<NSObject> p1([[NSObject alloc] init]);
|
||||
ASSERT_TRUE(p1.get());
|
||||
ASSERT_EQ(1u, [p1 retainCount]);
|
||||
fml::scoped_nsobject<NSObject> p2(p1);
|
||||
ASSERT_EQ(p1.get(), p2.get());
|
||||
ASSERT_EQ(2u, [p1 retainCount]);
|
||||
p2.reset();
|
||||
ASSERT_EQ(nil, p2.get());
|
||||
ASSERT_EQ(1u, [p1 retainCount]);
|
||||
{
|
||||
fml::scoped_nsobject<NSObject> p3 = p1;
|
||||
ASSERT_EQ(p1.get(), p3.get());
|
||||
ASSERT_EQ(2u, [p1 retainCount]);
|
||||
p3 = p1;
|
||||
ASSERT_EQ(p1.get(), p3.get());
|
||||
ASSERT_EQ(2u, [p1 retainCount]);
|
||||
}
|
||||
ASSERT_EQ(1u, [p1 retainCount]);
|
||||
fml::scoped_nsobject<NSObject> p4([p1.get() retain]);
|
||||
ASSERT_EQ(2u, [p1 retainCount]);
|
||||
ASSERT_TRUE(p1 == p1.get());
|
||||
ASSERT_TRUE(p1 == p1);
|
||||
ASSERT_FALSE(p1 != p1);
|
||||
ASSERT_FALSE(p1 != p1.get());
|
||||
fml::scoped_nsobject<NSObject> p5([[NSObject alloc] init]);
|
||||
ASSERT_TRUE(p1 != p5);
|
||||
ASSERT_TRUE(p1 != p5.get());
|
||||
ASSERT_FALSE(p1 == p5);
|
||||
ASSERT_FALSE(p1 == p5.get());
|
||||
|
||||
fml::scoped_nsobject<NSObject> p6 = p1;
|
||||
ASSERT_EQ(3u, [p6 retainCount]);
|
||||
{
|
||||
fml::ScopedNSAutoreleasePool pool;
|
||||
p6.autorelease();
|
||||
ASSERT_EQ(nil, p6.get());
|
||||
ASSERT_EQ(3u, [p1 retainCount]);
|
||||
}
|
||||
ASSERT_EQ(2u, [p1 retainCount]);
|
||||
|
||||
fml::scoped_nsobject<NSObject> p7([[NSObject alloc] init]);
|
||||
fml::scoped_nsobject<NSObject> p8(std::move(p7));
|
||||
ASSERT_TRUE(p8);
|
||||
ASSERT_EQ(1u, [p8 retainCount]);
|
||||
IS_INITIALIZED(p7);
|
||||
ASSERT_FALSE(p7.get());
|
||||
}
|
||||
|
||||
// Instantiating scoped_nsobject<> with T=NSAutoreleasePool should trip a
|
||||
// static_assert.
|
||||
#if 0
|
||||
TEST(ScopedNSObjectTest, FailToCreateScopedNSObjectAutoreleasePool) {
|
||||
fml::scoped_nsobject<NSAutoreleasePool> pool;
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST(ScopedNSObjectTest, ScopedNSObjectInContainer) {
|
||||
fml::scoped_nsobject<id> p([[NSObject alloc] init]);
|
||||
ASSERT_TRUE(p.get());
|
||||
ASSERT_EQ(1u, [p retainCount]);
|
||||
{
|
||||
std::vector<fml::scoped_nsobject<id>> objects;
|
||||
objects.push_back(p);
|
||||
ASSERT_EQ(2u, [p retainCount]);
|
||||
ASSERT_EQ(p.get(), objects[0].get());
|
||||
objects.push_back(fml::scoped_nsobject<id>([[NSObject alloc] init]));
|
||||
ASSERT_TRUE(objects[1].get());
|
||||
ASSERT_EQ(1u, [objects[1] retainCount]);
|
||||
}
|
||||
ASSERT_EQ(1u, [p retainCount]);
|
||||
}
|
||||
|
||||
TEST(ScopedNSObjectTest, ScopedNSObjectFreeFunctions) {
|
||||
fml::scoped_nsobject<id> p1([[NSObject alloc] init]);
|
||||
id o1 = p1.get();
|
||||
ASSERT_TRUE(o1 == p1);
|
||||
ASSERT_FALSE(o1 != p1);
|
||||
fml::scoped_nsobject<id> p2([[NSObject alloc] init]);
|
||||
ASSERT_TRUE(o1 != p2);
|
||||
ASSERT_FALSE(o1 == p2);
|
||||
id o2 = p2.get();
|
||||
swap(p1, p2);
|
||||
ASSERT_EQ(o2, p1.get());
|
||||
ASSERT_EQ(o1, p2.get());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -429,7 +429,6 @@ def run_cc_tests(build_dir, executable_filter, coverage, capture_core_dump):
|
||||
make_test('embedder_proctable_unittests'),
|
||||
make_test('embedder_unittests'),
|
||||
make_test('fml_unittests'),
|
||||
make_test('fml_arc_unittests'),
|
||||
make_test('no_dart_plugin_registrant_unittests'),
|
||||
make_test('runtime_unittests'),
|
||||
make_test('tonic_unittests'),
|
||||
|
||||
@@ -442,9 +442,9 @@ void main() {
|
||||
CannedProcess(
|
||||
(command) => command.contains('desc'),
|
||||
stdout: convert.jsonEncode({
|
||||
'//flutter/fml:fml_arc_unittests': {
|
||||
'//flutter/fml:fml_unittests': {
|
||||
'outputs': [
|
||||
'//out/host_debug/fml_arc_unittests',
|
||||
'//out/host_debug/fml_unittests',
|
||||
],
|
||||
'testonly': true,
|
||||
'type': 'executable',
|
||||
@@ -473,7 +473,7 @@ void main() {
|
||||
'build',
|
||||
'--config',
|
||||
'ci/host_debug',
|
||||
'//flutter/fml:fml_arc_unittests',
|
||||
'//flutter/fml:fml_unittests',
|
||||
]);
|
||||
|
||||
printOnFailure(testEnv.testLogs.map((r) => r.message).join('\n'));
|
||||
@@ -495,7 +495,7 @@ void main() {
|
||||
expect(
|
||||
ninjaCmd.command,
|
||||
contains(
|
||||
contains('flutter/fml:fml_arc_unittests'),
|
||||
contains('flutter/fml:fml_unittests'),
|
||||
),
|
||||
);
|
||||
});
|
||||
@@ -521,9 +521,9 @@ void main() {
|
||||
'testonly': true,
|
||||
'type': 'executable',
|
||||
},
|
||||
'//flutter/fml:fml_arc_unittests': {
|
||||
'//flutter/fml:fml_unittests': {
|
||||
'outputs': [
|
||||
'//out/host_debug/fml_arc_unittests',
|
||||
'//out/host_debug/fml_unittests',
|
||||
],
|
||||
'testonly': true,
|
||||
'type': 'executable',
|
||||
@@ -576,7 +576,7 @@ void main() {
|
||||
containsAll([
|
||||
'flutter/display_list:display_list_unittests',
|
||||
'flutter/flow:flow_unittests',
|
||||
'flutter/fml:fml_arc_unittests',
|
||||
'flutter/fml:fml_unittests',
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -320,9 +320,9 @@ void main() {
|
||||
'testonly': true,
|
||||
'type': 'executable',
|
||||
},
|
||||
'//flutter/fml:fml_arc_unittests': {
|
||||
'//flutter/fml:fml_unittests': {
|
||||
'outputs': [
|
||||
'//out/host_debug/fml_arc_unittests',
|
||||
'//out/host_debug/fml_unittests',
|
||||
],
|
||||
'testonly': true,
|
||||
'type': 'executable',
|
||||
@@ -374,7 +374,7 @@ void main() {
|
||||
final expected = <String>[
|
||||
'//flutter/display_list:display_list_unittests',
|
||||
'//flutter/flow:flow_unittest',
|
||||
'//flutter/fml:fml_arc_unittests',
|
||||
'//flutter/fml:fml_unittests',
|
||||
];
|
||||
|
||||
final testLogs = stringsFromLogs(testEnvironment.testLogs);
|
||||
|
||||
Reference in New Issue
Block a user