aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2023-05-15 19:11:30 +0200
committerStefan Boberg <[email protected]>2023-05-15 19:11:30 +0200
commit1f9c5f8ba54a075e22c0b1d3fa153aa7dadac2eb (patch)
tree6980187b4a6642b79cb9928b0c2c6018180adf2b /src
parentdisable warning C5105 in ZEN_THIRD_PARTY_INCLUDES_START (diff)
downloadzen-1f9c5f8ba54a075e22c0b1d3fa153aa7dadac2eb.tar.xz
zen-1f9c5f8ba54a075e22c0b1d3fa153aa7dadac2eb.zip
added IoBuffer.mmap test case
this verifies that attempting to map a range outside the underlying file fails. Posix appears to offer different semantics so it silently accepts it still however.
Diffstat (limited to 'src')
-rw-r--r--src/zencore/iobuffer.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/zencore/iobuffer.cpp b/src/zencore/iobuffer.cpp
index 3aca0cfa7..6a4b56be6 100644
--- a/src/zencore/iobuffer.cpp
+++ b/src/zencore/iobuffer.cpp
@@ -680,6 +680,33 @@ TEST_CASE("IoBuffer")
zen::IoBuffer buffer3(buffer2, 0, buffer2.Size());
}
+TEST_CASE("IoBuffer.mmap")
+{
+ zen::IoBuffer Buffer1{65536};
+ uint8_t* Mutate = Buffer1.MutableData<uint8_t>();
+ memcpy(Mutate, "abc123", 6);
+ zen::WriteFile("test_file.data", Buffer1);
+
+ SUBCASE("in-range")
+ {
+ zen::IoBuffer FileBuffer = IoBufferBuilder::MakeFromFile("test_file.data", 0, 65536);
+ const void* Data = FileBuffer.GetData();
+ CHECK(Data != nullptr);
+ CHECK_EQ(memcmp(Data, "abc123", 6), 0);
+ }
+
+ // Linux/MacOS offers different semantics when calling mmap with out-of-range so
+ // for now let's ignore whether that makes sense or not
+# if ZEN_PLATFORM_WINDOWS
+ SUBCASE("out-of-range")
+ {
+ zen::IoBuffer FileBuffer = IoBufferBuilder::MakeFromFile("test_file.data", 131072, 65536);
+ const void* Data = nullptr;
+ CHECK_THROWS(Data = FileBuffer.GetData());
+ CHECK(Data == nullptr);
+ }
+# endif
+}
#endif
} // namespace zen