-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cmp.cpp
More file actions
42 lines (36 loc) · 1.18 KB
/
test_cmp.cpp
File metadata and controls
42 lines (36 loc) · 1.18 KB
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
#include <cfbox/applets.hpp>
#include <cfbox/applet_config.hpp>
#include <gtest/gtest.h>
#include "test_capture.hpp"
#if CFBOX_ENABLE_CMP
using namespace cfbox::test;
TEST(CmpTest, HelpOutput) {
char a0[] = "cmp", a1[] = "--help";
char* argv[] = {a0, a1};
auto out = capture_stdout([&]{ return cmp_main(2, argv); });
EXPECT_FALSE(out.empty());
EXPECT_NE(out.find("compare"), std::string::npos);
}
TEST(CmpTest, IdenticalFiles) {
TempDir tmp;
auto f1 = tmp.write_file("a.bin", "abcdef");
auto f2 = tmp.write_file("b.bin", "abcdef");
char a0[] = "cmp", a1[256], a2[256];
std::snprintf(a1, sizeof(a1), "%s", f1.c_str());
std::snprintf(a2, sizeof(a2), "%s", f2.c_str());
char* argv[] = {a0, a1, a2};
int rc = cmp_main(3, argv);
EXPECT_EQ(rc, 0);
}
TEST(CmpTest, DifferentFiles) {
TempDir tmp;
auto f1 = tmp.write_file("a.bin", "abc");
auto f2 = tmp.write_file("b.bin", "axc");
char a0[] = "cmp", a1[256], a2[256];
std::snprintf(a1, sizeof(a1), "%s", f1.c_str());
std::snprintf(a2, sizeof(a2), "%s", f2.c_str());
char* argv[] = {a0, a1, a2};
int rc = cmp_main(3, argv);
EXPECT_EQ(rc, 1);
}
#endif // CFBOX_ENABLE_CMP