DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
DALI_TEST_CHECK(!object.GetBaseHandle()); // object moved
+ object.Reset(); /// No effect to moved object
+
END_TEST;
}
DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
DALI_TEST_CHECK(!object.GetBaseHandle()); // object moved
+ object.Reset(); /// No effect to moved object
+
END_TEST;
}
END_TEST;
}
+int UtcDaliWeakHandleBaseEqualityOperatorVariousCases(void)
+{
+ TestApplication application;
+ tet_infoline("Positive Test Dali::WeakHandleBase::operator== with various cases");
+
+ WeakHandleBase object;
+ WeakHandleBase theSameObject;
+ DALI_TEST_CHECK(object == theSameObject);
+
+ Actor actor = Actor::New();
+
+ object = WeakHandleBase(actor);
+ DALI_TEST_CHECK(object.GetBaseHandle() == actor);
+
+ theSameObject = WeakHandleBase(actor);
+ DALI_TEST_CHECK(theSameObject.GetBaseHandle() == actor);
+ DALI_TEST_CHECK(object == theSameObject);
+
+ // Compare with empty object
+ tet_printf("Compare with empty object\n");
+ WeakHandleBase emptyObject;
+ DALI_TEST_CHECK(object != emptyObject);
+
+ tet_printf("Compare with moved object\n");
+ WeakHandleBase movedObject = std::move(theSameObject);
+
+ DALI_TEST_CHECK(movedObject.GetBaseHandle() == actor);
+ DALI_TEST_CHECK(object == movedObject);
+
+ DALI_TEST_CHECK(!theSameObject.GetBaseHandle());
+ DALI_TEST_CHECK(emptyObject == theSameObject);
+
+ tet_printf("Compare after Reset called\n");
+
+ object.Reset();
+
+ DALI_TEST_CHECK(emptyObject == object);
+ DALI_TEST_CHECK(theSameObject == object);
+ DALI_TEST_CHECK(object != movedObject);
+
+ tet_printf("Compare between moved objects\n");
+
+ movedObject = std::move(object);
+ DALI_TEST_CHECK(emptyObject == object);
+ DALI_TEST_CHECK(theSameObject == object);
+ DALI_TEST_CHECK(object == movedObject);
+ DALI_TEST_CHECK(emptyObject == movedObject);
+ DALI_TEST_CHECK(theSameObject == movedObject);
+
+ END_TEST;
+}
+
int UtcDaliWeakHandleBaseGetBaseHandle(void)
{
TestApplication application;
DALI_TEST_CHECK(object == WeakHandleBase());
DALI_TEST_CHECK(object.GetBaseHandle() == Handle());
+ // Call Reset one more time.
+ object.Reset();
+
+ DALI_TEST_CHECK(object == WeakHandleBase());
+ DALI_TEST_CHECK(object.GetBaseHandle() == Handle());
+
END_TEST;
}
public:
static SelfDestructHandle New();
- SelfDestructHandle() = default;
+ SelfDestructHandle() = default;
~SelfDestructHandle() = default;
+
private:
explicit SelfDestructHandle(SelfDestructObject* object);
};
SelfDestructHandle SelfDestructHandle::New()
{
IntrusivePtr<SelfDestructObject> object = new SelfDestructObject();
- auto handle = SelfDestructHandle(object.Get());
- object->mWeakHandle = handle;
+ auto handle = SelfDestructHandle(object.Get());
+ object->mWeakHandle = handle;
return handle;
}
END_TEST;
}
-
/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
WeakHandleBase::~WeakHandleBase()
{
- delete mImpl;
- mImpl = nullptr;
}
WeakHandleBase::WeakHandleBase(const WeakHandleBase& handle)
: mImpl(nullptr)
{
BaseHandle object = handle.GetBaseHandle();
- mImpl = new Impl(object);
+ mImpl = std::make_unique<Impl>(object);
}
WeakHandleBase& WeakHandleBase::operator=(const WeakHandleBase& rhs)
{
if(this != &rhs)
{
- delete mImpl;
+ mImpl.reset();
BaseHandle handle = rhs.GetBaseHandle();
- mImpl = new Impl(handle);
+ mImpl = std::make_unique<Impl>(handle);
}
return *this;
}
WeakHandleBase::WeakHandleBase(WeakHandleBase&& rhs) noexcept
-: mImpl(rhs.mImpl)
+: mImpl(std::move(rhs.mImpl))
{
- rhs.mImpl = nullptr;
}
WeakHandleBase& WeakHandleBase::operator=(WeakHandleBase&& rhs) noexcept
{
if(this != &rhs)
{
- delete mImpl;
-
- mImpl = rhs.mImpl;
- rhs.mImpl = nullptr;
+ mImpl = std::move(rhs.mImpl);
}
return *this;
bool WeakHandleBase::operator==(const WeakHandleBase& rhs) const
{
- return this->mImpl->mObject == rhs.mImpl->mObject;
+ if(DALI_LIKELY(this->mImpl))
+ {
+ if(DALI_LIKELY(rhs.mImpl))
+ {
+ return this->mImpl->mObject == rhs.mImpl->mObject;
+ }
+ else
+ {
+ return this->mImpl->mObject == nullptr;
+ }
+ }
+ else
+ {
+ if(DALI_LIKELY(rhs.mImpl))
+ {
+ return rhs.mImpl->mObject == nullptr;
+ }
+ }
+ return true; /// Both are empty handle.
}
bool WeakHandleBase::operator!=(const WeakHandleBase& rhs) const
void WeakHandleBase::Reset()
{
- mImpl->Reset();
+ if(DALI_LIKELY(mImpl))
+ {
+ mImpl->Reset();
+ }
}
} // namespace Dali