mirror of
https://github.com/hyprwm/hyprutils.git
synced 2024-12-22 14:19:49 +01:00
tests: enhance memory + format
This commit is contained in:
parent
db956287d3
commit
3f5293432b
4 changed files with 20 additions and 10 deletions
|
@ -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);
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue