-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_desc_unit_test.cpp
More file actions
46 lines (38 loc) · 980 Bytes
/
file_desc_unit_test.cpp
File metadata and controls
46 lines (38 loc) · 980 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// SPDX-License-Identifier: MIT
#include "file_desc.h"
#include <gtest/gtest.h>
namespace plac {
namespace {
TEST(FileDescTest, DefaultConstructor) {
FileDesc f{};
EXPECT_FALSE(f.IsValid());
}
TEST(FileDescTest, Constructor) {
FileDesc f{"/dev/null"};
EXPECT_TRUE(f.IsValid());
}
TEST(FileDescTest, MoveConstructor) {
FileDesc f1{"/dev/null"};
EXPECT_TRUE(f1.IsValid());
FileDesc f2{std::move(f1)};
EXPECT_FALSE(f1.IsValid());
EXPECT_TRUE(f2.IsValid());
}
TEST(FileDescTest, MoveAssignment) {
FileDesc f1{"/dev/null"};
EXPECT_TRUE(f1.IsValid());
FileDesc f2{"/dev/zero"};
EXPECT_TRUE(f2.IsValid());
f2 = std::move(f1);
EXPECT_FALSE(f1.IsValid());
EXPECT_TRUE(f2.IsValid());
}
TEST(FileDescTest, SelfMoveAssignment) {
FileDesc f{"/dev/null"};
EXPECT_TRUE(f.IsValid());
FileDesc &alias{f}; // silence warning for intentional self-assign
f = std::move(alias);
EXPECT_TRUE(f.IsValid());
}
} // namespace
} // namespace plac