-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileWriteTest.cpp
More file actions
124 lines (98 loc) · 3.85 KB
/
FileWriteTest.cpp
File metadata and controls
124 lines (98 loc) · 3.85 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
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
#include <filesystem>
#include <fstream>
#include <iostream>
#include <vector>
#include "Log.h"
void FileWriteTest()
{
std::cout << "\nFILEWRITE TESTING" << std::endl;
{
// testfiles
std::vector<std::filesystem::path> testfiles;
#ifdef BUILD_WIN
testfiles.emplace_back("test-files\\write-char-1.txt");
testfiles.emplace_back("test-files\\write-char-2.txt");
testfiles.emplace_back("test-files\\write-char-3.txt");
#else
testfiles.emplace_back("test-files/write-char-1.txt");
testfiles.emplace_back("test-files/write-char-2.txt");
testfiles.emplace_back("test-files/write-char-3.txt");
#endif
/*
first test is writing from simple char*
in addition to simple char* also basic string is tested
LINUX:
works
WIN:
works
*/
std::vector<const char*> testlines;
std::vector<std::string> testString;
std::vector<std::streamsize> testlineSizes;
testlines.push_back("Testing standard");
testlineSizes.push_back(16);
testString.emplace_back("Testing standard");
testlines.push_back("Testing advanced - α-ω");
testlineSizes.push_back(24);
testString.emplace_back("Testing advanced - α-ω");
testlines.push_back("Testing next level - ッ");
testlineSizes.push_back(24);
testString.emplace_back("Testing next level - ッ");
int fileIndex = 0;
for (auto& file : testfiles)
{
std::ofstream outFileStream(file, std::ios_base::binary);
outFileStream.write(testlines[fileIndex], testlineSizes[fileIndex]);
outFileStream.write("\n", 1);
outFileStream.write(testString[fileIndex].c_str(), testString[fileIndex].size());
outFileStream.write("\n", 1);
outFileStream.close();
fileIndex++;
}
}
{
// testfiles
std::vector<std::filesystem::path> testfiles;
#ifdef BUILD_WIN
testfiles.emplace_back("test-files\\write-u8Char-1.txt");
testfiles.emplace_back("test-files\\write-u8Char-2.txt");
testfiles.emplace_back("test-files\\write-u8Char-3.txt");
#else
testfiles.emplace_back("test-files/write-u8Char-1.txt");
testfiles.emplace_back("test-files/write-u8Char-2.txt");
testfiles.emplace_back("test-files/write-u8Char-3.txt");
#endif
/*
second test is writing from u8char_t*
in addition also u8string write will be tested
conversion to char* is necessary for write function
LINUX:
works
WIN:
works
*/
std::vector<const char8_t*> testlines;
std::vector<std::u8string> testString;
std::vector<std::streamsize> testlineSizes;
testlines.push_back(u8"Testing standard");
testlineSizes.push_back(16);
testString.emplace_back(u8"Testing standard");
testlines.push_back(u8"Testing advanced - α-ω");
testlineSizes.push_back(24);
testString.emplace_back(u8"Testing advanced - α-ω");
testlines.push_back(u8"Testing next level - ッ");
testlineSizes.push_back(24);
testString.emplace_back(u8"Testing next level - ッ");
int fileIndex = 0;
for (auto& file : testfiles)
{
std::ofstream outFileStream(file, std::ios_base::binary);
outFileStream.write(reinterpret_cast<const char*>(testlines[fileIndex]), testlineSizes[fileIndex]);
outFileStream.write("\n", 1);
outFileStream.write(reinterpret_cast<const char*>(testString[fileIndex].c_str()), testString[fileIndex].size());
outFileStream.write("\n", 1);
outFileStream.close();
fileIndex++;
}
}
}