Skip to content

Commit e185df4

Browse files
committed
tests: test some edge cases of compression detection function
1 parent 5cb2eed commit e185df4

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

tests/components/CompressionDetections.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,49 @@ TEST_CASE("detect_compression")
9090
REQUIRE( fs::remove(path / hash) );
9191
REQUIRE( fs::remove(path) );
9292
}
93+
94+
SECTION("directory without private message")
95+
{
96+
const fs::path path{fs::temp_directory_path() / "pm_no_messages_directory"};
97+
REQUIRE( fs::create_directory(path) );
98+
FileGuard guard{path};
99+
100+
{
101+
std::ofstream stream(path / "not_a_pm.dat", std::ios::out | std::ios::binary);
102+
REQUIRE( stream.good() );
103+
REQUIRE( stream.write("foo", 3).good() );
104+
stream.close();
105+
REQUIRE( stream.good() );
106+
}
107+
108+
const auto detected = detect_compression(path.string());
109+
REQUIRE_FALSE( detected.has_value() );
110+
REQUIRE( fs::remove(path / "not_a_pm.dat") );
111+
REQUIRE( fs::remove(path) );
112+
}
113+
114+
SECTION("directory with corrupted private message file")
115+
{
116+
const fs::path path{fs::temp_directory_path() / "pm_corrupt_messages_directory"};
117+
REQUIRE( fs::create_directory(path) );
118+
FileGuard guard{path};
119+
120+
const auto hash = getExampleMessage().getHash().toHexString();
121+
122+
{
123+
using namespace std::string_view_literals;
124+
125+
std::ofstream stream(path / hash, std::ios::out | std::ios::binary);
126+
REQUIRE( stream.good() );
127+
const std::string_view data = "123\0zxy"sv;
128+
REQUIRE( stream.write(data.data(), data.size()).good() );
129+
stream.close();
130+
REQUIRE( stream.good() );
131+
}
132+
133+
const auto detected = detect_compression(path.string());
134+
REQUIRE_FALSE( detected.has_value() );
135+
REQUIRE( fs::remove(path / hash) );
136+
REQUIRE( fs::remove(path) );
137+
}
93138
}

0 commit comments

Comments
 (0)