-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest-filesystemIO.cpp
204 lines (165 loc) · 5.88 KB
/
test-filesystemIO.cpp
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
//
// test-myfs.cpp
// testing
//
// Created by Oliver Waldhorst on 15.12.17.
// Copyright © 2017 Oliver Waldhorst. All rights reserved.
//
#include "catch.hpp"
#include <string.h>
#include <iostream>
#include "helper.hpp"
#include "constants.h"
#include "myfs-structs.h"
#include "filesystemIO.h"
#define BD_PATH "Test_Blockdevice.bin"
typedef struct {
uint64_t one;
uint64_t two;
uint64_t three;
uint64_t four;
uint64_t five;
uint64_t six;
uint64_t seven;
uint64_t eight;
uint64_t nine;
uint64_t ten;
uint64_t eleven;
} testNumbers;
typedef struct {
testNumbers before;
testNumbers first;
testNumbers second;
testNumbers third;
testNumbers fourth;
testNumbers fifth;
testNumbers after;
} testData;
TEST_CASE( "filsystemIO.Read/Write struct, on stack", "[filsystemIO]" ) {
remove(BD_PATH);
BlockDevice* blockdevice = new BlockDevice();
blockdevice->create(BD_PATH);
FilesystemIO fsIO = FilesystemIO(blockdevice);
SECTION("struct < BLOCK_SIZE") {
fileStats input;
fileStats output;
input.size = 1024;
output.size = 2345;
fsIO.writeDevice(15, &input, sizeof(input));
fsIO.readDevice(15, &output, sizeof(output));
REQUIRE(memcmp(&input, &output, sizeof(fileStats)) == 0);
}
SECTION("struct > BLOCK_SIZE") {
testData input;
input.before = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
input.first = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
input.second = {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2};
input.third = {3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3};
input.fourth = {4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4};
input.fifth = {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5};
input.after = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
testData output;
output.before = {333, 444, 555, 666, 777, 888, 999, 0, 1111, 2222, 3333};
fsIO.writeDevice(2, &input, sizeof(input));
fsIO.readDevice(2, &output, sizeof(output));
REQUIRE(memcmp(&input, &output, sizeof(testData)) == 0);
}
blockdevice->close();
remove(BD_PATH);
}
TEST_CASE( "filsystemIO.Read/Write array, on stack", "[filsystemIO]" ) {
remove(BD_PATH);
BlockDevice* blockdevice = new BlockDevice();
blockdevice->create(BD_PATH);
FilesystemIO fsIO = FilesystemIO(blockdevice);
SECTION("array < BLOCK_SIZE") {
uint16_t input[10];
uint16_t output[10];
for(int i = 0; i < 10; i++) {
input[i] = (uint16_t)(i * i);
}
fsIO.writeDevice(21, input, sizeof(input));
fsIO.readDevice(21, output, sizeof(output));
REQUIRE(memcmp(input, output, sizeof(input)) == 0);
}
SECTION("array > BLOCK_SIZE") {
uint64_t input[201];
uint64_t output[201];
for(int i = 0; i < 201; i++) {
input[i] = (uint16_t)(i + 1);
}
fsIO.writeDevice(5, input, sizeof(input));
fsIO.readDevice(5, output, sizeof(output));
REQUIRE(memcmp(input, output, sizeof(input)) == 0);
}
blockdevice->close();
remove(BD_PATH);
}
TEST_CASE( "filsystemIO.Read/Write struct, on heap", "[filsystemIO]" ) {
remove(BD_PATH);
BlockDevice* blockdevice = new BlockDevice();
blockdevice->create(BD_PATH);
FilesystemIO fsIO = FilesystemIO(blockdevice);
SECTION("struct < BLOCK_SIZE") {
fileStats* input = new fileStats;
fileStats* output = new fileStats;
input->size = 1024;
fsIO.writeDevice(15, input, sizeof(*input));
fsIO.readDevice(15, output, sizeof(*output));
REQUIRE(memcmp(input, output, sizeof(fileStats)) == 0);
delete input;
delete output;
}
SECTION("struct > BLOCK_SIZE") {
testData* putput = new testData;
testData* output = new testData;
putput->before = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
putput->first = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
putput->second = {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2};
putput->third = {3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3};
putput->fourth = {4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4};
putput->fifth = {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5};
putput->after = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
fsIO.writeDevice(2, putput, sizeof(*putput));
fsIO.readDevice(2, output, sizeof(*output));
REQUIRE(memcmp(putput, output, sizeof(testData)) == 0);
delete putput;
delete output;
}
blockdevice->close();
remove(BD_PATH);
}
TEST_CASE( "filsystemIO.Read/Write array, on heap", "[filsystemIO]" ) {
remove(BD_PATH);
BlockDevice* blockdevice = new BlockDevice();
blockdevice->create(BD_PATH);
FilesystemIO fsIO = FilesystemIO(blockdevice);
SECTION("array < BLOCK_SIZE") {
uint16_t arraySize = 10;
uint16_t* input = new uint16_t[arraySize];
uint16_t* output = new uint16_t[arraySize];
for(int i = 0; i < arraySize; i++) {
input[i] = i * i;
}
fsIO.writeDevice(21, input, sizeof(*input) * arraySize);
fsIO.readDevice(21, output, sizeof(*output) * arraySize);
REQUIRE(memcmp(input, output, sizeof(*input) * arraySize) == 0);
delete[] input;
delete[] output;
}
SECTION("array > BLOCK_SIZE") {
uint16_t arraySize = 201;
uint16_t* input = new uint16_t[arraySize];
uint16_t* output = new uint16_t[arraySize];
for(int i = 0; i < arraySize; i++) {
input[i] = i + 1;
}
fsIO.writeDevice(5, input, sizeof(*input) * arraySize);
fsIO.readDevice(5, output, sizeof(*output) * arraySize);
REQUIRE(memcmp(input, output, sizeof(*input) * arraySize) == 0);
delete[] input;
delete[] output;
}
blockdevice->close();
remove(BD_PATH);
}