-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_md5sum.cpp
More file actions
31 lines (27 loc) · 995 Bytes
/
Copy pathtest_md5sum.cpp
File metadata and controls
31 lines (27 loc) · 995 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
#include <cfbox/applets.hpp>
#include <cfbox/applet_config.hpp>
#include <gtest/gtest.h>
#include "test_capture.hpp"
#if CFBOX_ENABLE_MD5SUM
using namespace cfbox::test;
TEST(Md5sumTest, OutputFormat) {
TempDir tmp;
auto f = tmp.write_file("data.txt", "hello\n");
char a0[] = "md5sum", a1[256];
std::snprintf(a1, sizeof(a1), "%s", f.c_str());
char* argv[] = {a0, a1};
auto out = capture_stdout([&]{ return md5sum_main(2, argv); });
EXPECT_FALSE(out.empty());
// Output should have 32 hex characters followed by " " and filename
// Find the two-space separator
auto pos = out.find(" ");
ASSERT_NE(pos, std::string::npos);
EXPECT_EQ(pos, 32u);
// Verify all 32 chars are hex
for (std::size_t i = 0; i < 32u; ++i) {
bool hex = (out[i] >= '0' && out[i] <= '9') ||
(out[i] >= 'a' && out[i] <= 'f');
EXPECT_TRUE(hex) << "char at " << i << " is not hex: " << out[i];
}
}
#endif // CFBOX_ENABLE_MD5SUM