Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gershnik committed Jan 15, 2024
1 parent 6fcc58c commit b64a2f1
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
39 changes: 38 additions & 1 deletion test/BlockUtilTest.mm
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <objc-helpers/BlockUtil.h>

#include <Foundation/Foundation.h>

#include "doctest.h"

TEST_SUITE_BEGIN( "BlockUtilTests" );
Expand Down Expand Up @@ -115,12 +117,47 @@ int operator()(int i) const {
}
CHECK(foo::record == "dmm~~o~");

{
foo::record.clear();
auto b = makeBlock(foo{});
decltype(b) b1 = std::move(b);
CHECK(b1(42) == 42);
}
CHECK(foo::record == "dm~mo~~");

{
foo::record.clear();
auto b = makeBlock(fooMoveOnly{});
decltype(b) b1 = std::move(b);
CHECK(b1(42) == 42);
}
CHECK(foo::record == "dm~mo~~");

{
foo::record.clear();
auto b = makeBlock(fooCopyOnly{});
decltype(b) b1 = std::move(b);
CHECK(b1(42) == 42);
}
CHECK(foo::record == "dc~c~~");
CHECK(foo::record == "dc~co~~");
}

@interface MakeStrongCheck : NSObject {
@public int i;
}
@end

@implementation MakeStrongCheck
@end

TEST_CASE( "makeStrong" ) {

auto str = [MakeStrongCheck new];
auto weak = makeWeak(str);
REQUIRE(bool(weak));
auto str1 = makeStrong(weak);
bool equal = str == str1;
CHECK(equal);
}

TEST_SUITE_END();
19 changes: 18 additions & 1 deletion test/BlockUtilTestCpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,29 @@ TEST_CASE( "makeBlock" ) {
}
CHECK(foo::record == "dmm~~o~");

{
foo::record.clear();
auto b = makeBlock(foo{});
decltype(b) b1 = std::move(b);
CHECK(b1(42) == 42);
}
CHECK(foo::record == "dm~mo~~");

{
foo::record.clear();
auto b = makeBlock(fooMoveOnly{});
decltype(b) b1 = std::move(b);
CHECK(b1(42) == 42);
}
CHECK(foo::record == "dm~mo~~");

{
foo::record.clear();
auto b = makeBlock(fooCopyOnly{});
decltype(b) b1 = std::move(b);
CHECK(b1(42) == 42);
}
CHECK(foo::record == "dc~c~~");
CHECK(foo::record == "dc~co~~");
}

TEST_SUITE_END();

0 comments on commit b64a2f1

Please sign in to comment.