#include #include #include #include "shared.hpp" class CFooAttachment : public Aquamarine::IAttachment { public: int counter = 0; }; class CBarAttachment : public Aquamarine::IAttachment { public: int counter = 0; }; int main() { Aquamarine::CAttachmentManager attachments; int ret = 0; EXPECT(attachments.has(), false); EXPECT(attachments.get(), nullptr); EXPECT(attachments.has(), false); EXPECT(attachments.get(), nullptr); auto foo = Hyprutils::Memory::makeShared(); attachments.add(foo); EXPECT(attachments.has(), true); EXPECT(attachments.has(), false); foo->counter++; EXPECT(attachments.get(), foo); EXPECT(attachments.get()->counter, 1); attachments.add(Hyprutils::Memory::makeShared()); EXPECT(attachments.get()->counter, 1); EXPECT(attachments.get()->counter, 0); Hyprutils::Memory::CWeakPointer bar = attachments.get(); EXPECT(bar.valid(), true); bar->counter = 5; // test overriding an attachment attachments.add(Hyprutils::Memory::makeShared()); Hyprutils::Memory::CWeakPointer newBar = attachments.get(); EXPECT(bar == newBar, false); EXPECT(attachments.get()->counter, 0); // should be a noop as this is a different attachment attachments.remove(Hyprutils::Memory::makeShared()); EXPECT(attachments.has(), true); EXPECT(attachments.has(), true); attachments.remove(foo); EXPECT(attachments.has(), false); EXPECT(attachments.has(), true); attachments.removeByType(); EXPECT(attachments.has(), false); EXPECT(attachments.has(), false); EXPECT(foo.strongRef(), 1); EXPECT(bar.valid(), false); EXPECT(newBar.valid(), false); return ret; }