-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_link.cpp
More file actions
36 lines (27 loc) · 960 Bytes
/
Copy pathtest_link.cpp
File metadata and controls
36 lines (27 loc) · 960 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
#include <cfbox/applets.hpp>
#include <cfbox/applet_config.hpp>
#include <gtest/gtest.h>
#include "test_capture.hpp"
#if CFBOX_ENABLE_LINK
using namespace cfbox::test;
TEST(LinkTest, CreatesHardLink) {
TempDir tmp;
auto file = tmp.write_file("original.txt", "content");
auto link_path = (std::filesystem::path{tmp.path} / "link.txt").string();
char a0[] = "link";
char a1[256], a2[256];
std::snprintf(a1, sizeof(a1), "%s", file.c_str());
std::snprintf(a2, sizeof(a2), "%s", link_path.c_str());
char* argv[] = {a0, a1, a2, nullptr};
EXPECT_EQ(link_main(3, argv), 0);
EXPECT_TRUE(std::filesystem::exists(link_path));
// Same inode (hard link)
auto stat1 = std::filesystem::hard_link_count(file);
EXPECT_GE(stat1, 2u);
}
TEST(LinkTest, MissingOperand) {
char a0[] = "link", a1[] = "onlyone";
char* argv[] = {a0, a1, nullptr};
EXPECT_EQ(link_main(2, argv), 1);
}
#endif // CFBOX_ENABLE_LINK