#include <stdplus/cancel.hpp>

#include <functional>

#include <gtest/gtest.h>

namespace stdplus
{

struct FakeCancelable : public Cancelable
{
    size_t count = 0;
    void cancel() noexcept override
    {
        count++;
    }
};

TEST(CancelTest, Cancel)
{
    FakeCancelable c;
    EXPECT_EQ(c.count, 0);
    {
        Cancel cancel(&c);
        EXPECT_TRUE(cancel);
        Cancel cancel2(std::move(cancel));
        EXPECT_FALSE(cancel);
        EXPECT_TRUE(cancel2);
        EXPECT_EQ(c.count, 0);
    }
    EXPECT_EQ(c.count, 1);
}

TEST(CancelTest, EmptyCancel)
{
    Cancel cancel, cancel2(std::nullopt);
    EXPECT_FALSE(cancel);
    EXPECT_FALSE(cancel2);
}

TEST(CancelTest, AlwaysCallOnceLambda)
{
    size_t ctr = 0;
    {
        auto i = std::make_unique<size_t>(1);
        auto acb = alwaysCallOnce([&, i = std::move(i)]() { ctr += *i; });
        EXPECT_EQ(ctr, 0);
        acb();
        EXPECT_EQ(ctr, 1);
    }
    EXPECT_EQ(ctr, 1);
    {
        auto acb = alwaysCallOnce([&](size_t i) { ctr += i; }, 3);
        EXPECT_EQ(ctr, 1);
    }
    EXPECT_EQ(ctr, 4);
}

TEST(CanceTest, AlwaysCallOnceFunction)
{
    size_t ctr = 0;
    {
        auto acb = alwaysCallOnce(std::function<void()>(nullptr));
    }
    {
        auto acb = alwaysCallOnce(std::function<void()>([&]() { ctr++; }));
        EXPECT_EQ(ctr, 0);
        acb = alwaysCallOnce(std::function<void()>([&]() { ctr += 2; }));
        EXPECT_EQ(ctr, 1);
    }
    EXPECT_EQ(ctr, 3);
}

} // namespace stdplus
