-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathBlockStreamTest.cpp
33 lines (26 loc) · 1017 Bytes
/
BlockStreamTest.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
/* BlockStreamTest.cpp
2015-11-09 - 2018-06-30
Esp. Ing. José María Sola
Profesor
UTN FRBA */
#include "BlockStream.h"
#include <cassert>
int main(){
using Byte = unsigned char; // std::byte C++17 #include<cstddef>
struct Color{Byte red, green, blue;}; // A sample block.
constexpr auto filename{"color.bin"};
// Write
std::ofstream out{filename, std::ios::binary}; // Create and connect to write.
WriteBlock(out, Color{70,130,180}); // Write to out.
out.close(); // Disconnect.
// Read
std::ifstream in{filename, std::ios::binary}; // Connect to read.
Color steelBlue; // Object to store read data.
ReadBlock(in, steelBlue); // Read from in.
in.close(); // Disconcect.
remove(filename); // C++17 // std::filesystem::remove(filename);
// Test
assert( 70 == steelBlue.red );
assert( 130 == steelBlue.green );
assert( 180 == steelBlue.blue );
}