Skip to content

Commit

Permalink
Expand tests for move semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
bugdea1er committed Sep 24, 2024
1 parent 2312f2e commit 18d4063
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 29 deletions.
6 changes: 5 additions & 1 deletion src/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,17 @@ entry::entry(fs::path path, native_handle_type handle)

entry::entry(entry&& other) noexcept
: pathobject(other.release()),
handle(other.handle) {}
handle(other.handle) {
//other.handle = -1;
}

entry& entry::operator=(entry&& other) noexcept {
close(*this);
remove(*this);
pathobject = other.release();
handle = other.handle;

//other.handle = -1;
return *this;
}

Expand Down
35 changes: 21 additions & 14 deletions tests/directory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,34 +134,41 @@ TEST(directory, destructor) {
/// Tests directory move constructor
TEST(directory, move_constructor) {
directory fst = directory();
directory snd = std::move(fst);
directory snd = directory(std::move(fst));

EXPECT_TRUE(fst.path().empty());
fst.~directory();

EXPECT_FALSE(snd.path().empty());
EXPECT_TRUE(fs::exists(snd));
EXPECT_TRUE(native_handle_is_valid(snd.native_handle()));
}

/// Tests directory move assignment operator
TEST(directory, move_assignment) {
directory fst = directory();
directory snd = directory();
{
directory snd = directory();

fs::path path1 = fst;
fs::path path2 = snd;
fs::path path1 = fst;
fs::path path2 = snd;

entry::native_handle_type fst_handle = fst.native_handle();
entry::native_handle_type snd_handle = snd.native_handle();
entry::native_handle_type fst_handle = fst.native_handle();
entry::native_handle_type snd_handle = snd.native_handle();

fst = std::move(snd);

fst = std::move(snd);
EXPECT_FALSE(fs::exists(path1));
EXPECT_TRUE(fs::exists(path2));

EXPECT_FALSE(fs::exists(path1));
EXPECT_TRUE(fs::exists(path2));
EXPECT_TRUE(fs::exists(fst));
EXPECT_TRUE(fs::equivalent(fst, path2));

EXPECT_TRUE(fs::exists(fst));
EXPECT_TRUE(fs::equivalent(fst, path2));
EXPECT_FALSE(native_handle_is_valid(fst_handle));
EXPECT_TRUE(native_handle_is_valid(snd_handle));
}

EXPECT_FALSE(native_handle_is_valid(fst_handle));
EXPECT_TRUE(native_handle_is_valid(snd_handle));
EXPECT_FALSE(fst.path().empty());
EXPECT_TRUE(native_handle_is_valid(fst.native_handle()));
}

/// Tests directory moving
Expand Down
35 changes: 21 additions & 14 deletions tests/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,34 +358,41 @@ TEST(file, destructor) {
/// Tests file move constructor
TEST(file, move_constructor) {
file fst = file();
file snd = std::move(fst);
file snd = file(std::move(fst));

EXPECT_TRUE(fst.path().empty());
fst.~file();

EXPECT_FALSE(snd.path().empty());
EXPECT_TRUE(fs::exists(snd));
EXPECT_TRUE(native_handle_is_valid(snd.native_handle()));
}

/// Tests file move assignment operator
TEST(file, move_assignment) {
file fst = file();
file snd = file();
{
file snd = file();

fs::path path1 = fst;
fs::path path2 = snd;
fs::path path1 = fst;
fs::path path2 = snd;

entry::native_handle_type fst_handle = fst.native_handle();
entry::native_handle_type snd_handle = snd.native_handle();
entry::native_handle_type fst_handle = fst.native_handle();
entry::native_handle_type snd_handle = snd.native_handle();

fst = std::move(snd);

fst = std::move(snd);
EXPECT_FALSE(fs::exists(path1));
EXPECT_TRUE(fs::exists(path2));

EXPECT_FALSE(fs::exists(path1));
EXPECT_TRUE(fs::exists(path2));
EXPECT_TRUE(fs::exists(fst));
EXPECT_TRUE(fs::equivalent(fst, path2));

EXPECT_TRUE(fs::exists(fst));
EXPECT_TRUE(fs::equivalent(fst, path2));
EXPECT_FALSE(native_handle_is_valid(fst_handle));
EXPECT_TRUE(native_handle_is_valid(snd_handle));
}

EXPECT_FALSE(native_handle_is_valid(fst_handle));
EXPECT_TRUE(native_handle_is_valid(snd_handle));
EXPECT_FALSE(fst.path().empty());
EXPECT_TRUE(native_handle_is_valid(fst.native_handle()));
}

/// Tests file moving
Expand Down

0 comments on commit 18d4063

Please sign in to comment.