tests: enhance memory + format

This commit is contained in:
Vaxry 2024-09-25 22:44:05 +01:00
parent db956287d3
commit 3f5293432b
4 changed files with 20 additions and 10 deletions

View file

@ -1,5 +1,6 @@
#include <hyprutils/memory/WeakPtr.hpp> #include <hyprutils/memory/WeakPtr.hpp>
#include "shared.hpp" #include "shared.hpp"
#include <vector>
using namespace Hyprutils::Memory; using namespace Hyprutils::Memory;
@ -8,6 +9,7 @@ using namespace Hyprutils::Memory;
int main(int argc, char** argv, char** envp) { int main(int argc, char** argv, char** envp) {
SP<int> intPtr = makeShared<int>(10); SP<int> intPtr = makeShared<int>(10);
SP<int> intPtr2 = makeShared<int>(1337);
int ret = 0; int ret = 0;
@ -21,7 +23,17 @@ int main(int argc, char** argv, char** envp) {
EXPECT(*weak.get(), 10); EXPECT(*weak.get(), 10);
EXPECT(weak.expired(), false); EXPECT(weak.expired(), false);
intPtr = {}; std::vector<SP<int>> sps;
sps.push_back(intPtr);
sps.emplace_back(intPtr);
sps.push_back(intPtr2);
sps.emplace_back(intPtr2);
std::erase_if(sps, [intPtr](const auto& e) { return e == intPtr; });
intPtr.reset();
EXPECT(weak.impl_->ref(), 0);
EXPECT(intPtr2.strongRef(), 3);
EXPECT(weak.expired(), true); EXPECT(weak.expired(), true);

View file

@ -10,9 +10,7 @@ int main(int argc, char** argv, char** envp) {
CSignal signal; CSignal signal;
int data = 0; int data = 0;
auto listener = signal.registerListener([&] (std::any d) { auto listener = signal.registerListener([&](std::any d) { data = 1; });
data = 1;
});
signal.emit(); signal.emit();