-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_io.cpp
More file actions
68 lines (46 loc) · 1.84 KB
/
test_io.cpp
File metadata and controls
68 lines (46 loc) · 1.84 KB
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
#include "test_settings.hpp"
#ifdef ENABLE_TESTS
#include "../utils_lib/external/doctest.hpp"
#include "../utils_lib/utils_io.hpp"
#include "../utils_lib/utils_string.hpp"
#include "../utils_lib/utils_random.hpp"
TEST_CASE("Test utils::io::TemporaryFile") {
utils::io::fs::path pp;
SUBCASE("Test utils::io::TemporaryFile deleted after scope") {
{
utils::io::TemporaryFile t;
pp = t.get_path();
REQUIRE(utils::io::fs::exists(pp));
const int rnd = utils::random::Random::get<int>();
const std::string test = utils::string::format("Hello World %d!\n", rnd);
t.printf("Hello World %d!\n", rnd);
t.reopen();
char buffer[40] = { 0 };
t.read(buffer, 40);
CHECK(std::string(buffer) == test);
}
REQUIRE_FALSE(utils::io::fs::exists(pp));
}
SUBCASE("Test utils::io::TemporaryFile deleted after created after ctor") {
{
utils::io::TemporaryFile t(false, "", "", "_test_", ".abc");
pp = t.get_path();
CHECK(utils::string::ends_with(t.get_name(), ".abc"));
CHECK(utils::string::contains(t.get_name(), "_test_"));
REQUIRE_FALSE(utils::io::fs::exists(pp));
std::FILE *fp = std::fopen(t.get_name().data(), "wb+");
const int rnd = utils::random::Random::get<int>();
const std::string test = utils::string::format("Hello World %d!\n", rnd);
std::fprintf(fp, "Hello World %d!\n", rnd);
std::fclose(fp);
REQUIRE(utils::io::fs::exists(pp));
t.reopen();
t.seekstart();
char buffer[40] = { 0 };
t.read(buffer, 40);
CHECK(std::string(buffer) == test);
}
REQUIRE_FALSE(utils::io::fs::exists(pp));
}
}
#endif