blob: f0450947cdff1c052e842982290c1a80e4833182 (
plain)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
#include "kernel/filesystem/open_file_description.hpp"
#include "kernel/test_support/filesystem/inode.hpp"
#include <kstd/memory>
#include <kstd/print>
#include <kstd/vector>
#include <catch2/catch_test_macros.hpp>
SCENARIO("Open file description construction", "[filesystem][open_file_description]")
{
GIVEN("an inode and an open file description for that inode")
{
auto inode = kstd::make_shared<kernel::tests::filesystem::inode>();
auto file_description = kernel::filesystem::open_file_description{inode};
THEN("the initial offset is zero")
{
REQUIRE(file_description.offset() == 0);
}
}
}
SCENARIO("Open file description read/write offset management", "[filesystem][open_file_description]")
{
GIVEN("an inode that tracks read/write calls and an open file description for that inode")
{
auto inode = kstd::make_shared<kernel::tests::filesystem::inode>();
auto file_description = kernel::filesystem::open_file_description{inode};
THEN("the offset is updated correctly after reads")
{
REQUIRE(file_description.read(nullptr, 100) == 100);
REQUIRE(file_description.offset() == 100);
REQUIRE(file_description.read(nullptr, 50) == 50);
REQUIRE(file_description.offset() == 150);
}
THEN("the offset is updated correctly after writes")
{
REQUIRE(file_description.write(nullptr, 200) == 200);
REQUIRE(file_description.offset() == 200);
REQUIRE(file_description.write(nullptr, 25) == 25);
REQUIRE(file_description.offset() == 225);
}
THEN("reads and writes both update the same offset")
{
REQUIRE(file_description.read(nullptr, 10) == 10);
REQUIRE(file_description.offset() == 10);
REQUIRE(file_description.write(nullptr, 20) == 20);
REQUIRE(file_description.offset() == 30);
REQUIRE(file_description.read(nullptr, 5) == 5);
REQUIRE(file_description.offset() == 35);
REQUIRE(file_description.write(nullptr, 15) == 15);
REQUIRE(file_description.offset() == 50);
}
}
}
|