Skip to content

Commit

Permalink
tests: enhance memory + format
Browse files Browse the repository at this point in the history
  • Loading branch information
vaxerski committed Sep 25, 2024
1 parent db95628 commit 3f52934
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion tests/math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ int main(int argc, char** argv, char** envp) {

// Test matrices
{
Mat3x3 jeremy = Mat3x3::outputProjection({1920, 1080}, HYPRUTILS_TRANSFORM_FLIPPED_90);
Mat3x3 jeremy = Mat3x3::outputProjection({1920, 1080}, HYPRUTILS_TRANSFORM_FLIPPED_90);
Mat3x3 matrixBox = jeremy.projectBox(CBox{10, 10, 200, 200}, HYPRUTILS_TRANSFORM_NORMAL).translate({100, 100}).scale({1.25F, 1.5F}).transpose();

Mat3x3 expected = std::array<float, 9>{0, 0.46296296, 0, 0.3125, 0, 0, 19.84375, 36.055557, 1};
Expand Down
18 changes: 15 additions & 3 deletions tests/memory.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#include <hyprutils/memory/WeakPtr.hpp>
#include "shared.hpp"
#include <vector>

using namespace Hyprutils::Memory;

#define SP CSharedPointer
#define WP CWeakPointer

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;

EXPECT(*intPtr, 10);
EXPECT(intPtr.strongRef(), 1);
Expand All @@ -21,7 +23,17 @@ int main(int argc, char** argv, char** envp) {
EXPECT(*weak.get(), 10);
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);

Expand Down
2 changes: 1 addition & 1 deletion tests/shared.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Colors {

#define EXPECT(expr, val) \
if (const auto RESULT = expr; RESULT != (val)) { \
std::cout << Colors::RED << "Failed: " << Colors::RESET << #expr << ", expected " << val << " but got " << RESULT << "\n"; \
std::cout << Colors::RED << "Failed: " << Colors::RESET << #expr << ", expected " << val << " but got " << RESULT << "\n"; \
ret = 1; \
} else { \
std::cout << Colors::GREEN << "Passed " << Colors::RESET << #expr << ". Got " << val << "\n"; \
Expand Down
8 changes: 3 additions & 5 deletions tests/signal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ using namespace Hyprutils::Signal;
using namespace Hyprutils::Memory;

int main(int argc, char** argv, char** envp) {
int ret = 0;
int ret = 0;

CSignal signal;
int data = 0;
auto listener = signal.registerListener([&] (std::any d) {
data = 1;
});
int data = 0;
auto listener = signal.registerListener([&](std::any d) { data = 1; });

signal.emit();

Expand Down

0 comments on commit 3f52934

Please sign in to comment.