-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
137 lines (114 loc) · 4.16 KB
/
test.cpp
File metadata and controls
137 lines (114 loc) · 4.16 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
125
126
127
128
129
130
131
132
133
134
135
136
#include "myofstream.hpp"
#include <iostream>
#include <cassert>
#include "testlib.h"
#include <fstream>
DECLARE_OOP_TEST(myofstream_test_create_constructor)//тестируем функцию конца строки
{
try
{
MyOfStream print("I4618462267:\\TestFile.txt", MyOfStream::OpenMode::rewrite);
}
catch (const std::exception& e)
{
assert(!strcmp(e.what(), "Error: Failed to open target file."));
}
}
DECLARE_OOP_TEST(myofstream_test_endline)//тестируем функцию конца строки
{
MyOfStream print("TestFile.txt", MyOfStream::OpenMode::rewrite);
print << endline;
char buf[50];
std::ifstream fin("TestFile.txt");
fin.getline(buf, 50);
assert(!strcmp("", buf));
}
DECLARE_OOP_TEST(myofstream_test_int_flag_oct)//тестируем флаг oct
{
MyOfStream print("TestFile.txt", MyOfStream::OpenMode::rewrite);
int intFlagOct{ 287 }; char resultInOct[] = "437";
print << oct << intFlagOct << endline;
std::ifstream fin("TestFile.txt");
char buf[50];
fin.getline(buf, 50);
assert(!strcmp(resultInOct, buf));
}
DECLARE_OOP_TEST(myofstream_test_int_flag_dec)//тестируем флаг dec
{
MyOfStream print("TestFile.txt", MyOfStream::OpenMode::rewrite);
int intFlagDec{ 287 }; char resultInDec[] = "287";
print << dec << intFlagDec << endline;
std::ifstream fin("TestFile.txt");
char buf[50];
fin.getline(buf, 50);
assert(!strcmp(resultInDec, buf));
}
DECLARE_OOP_TEST(myofstream_test_unsetf)//тестируем функцию установки флага по умолчанию(dec).в начале ставим флаг hex,а затем unsetf. в результате устанавливается hex а потом перекрывается unsetf(по умолчанию dec).
{
MyOfStream print("TestFile.txt", MyOfStream::OpenMode::rewrite);
int intFlagHex{ 287 }; char resultUnflag[] = "287";
print << hex << unsetf << intFlagHex << endline;
std::ifstream fin("TestFile.txt");
char buf[50];
fin.getline(buf, 50);
assert(!strcmp(resultUnflag, buf));
}
DECLARE_OOP_TEST(myofstream_test_int_flag_hex)//тестируем флаг hex
{
MyOfStream print("TestFile.txt", MyOfStream::OpenMode::rewrite);
int intFlagHex{ 287 }; char resultInHex[] = "11f";
print << hex << intFlagHex << endline;
std::ifstream fin("TestFile.txt");
char buf[50];
fin.getline(buf, 50);
assert(!strcmp(resultInHex, buf));
}
DECLARE_OOP_TEST(myofstream_test_int_flag_binary)//тестируем флаг bin
{
MyOfStream print("TestFile.txt", MyOfStream::OpenMode::rewrite);
int intFlagBin{ 287 }; char resultInBin[] = "100011111";
print << bin << intFlagBin << endline;
std::ifstream fin("TestFile.txt");
char buf[50];
fin.getline(buf, 50);
assert(!strcmp(resultInBin, buf));
}
DECLARE_OOP_TEST(myofstream_test_double)//тестируем вывод double
{
MyOfStream print("TestFile.txt", MyOfStream::OpenMode::rewrite);
double testdoublevalue{ 10.123 }; char resultTestDouble[] = "10.123000";
print << testdoublevalue << endline;
std::ifstream fin("TestFile.txt");
char buf[50];
fin.getline(buf, 50);
assert(!strcmp(buf, resultTestDouble));
};
DECLARE_OOP_TEST(myofstream_test_char)//тестируем вывод неконстантной строки (сhar)
{
MyOfStream print("TestFile.txt", MyOfStream::OpenMode::rewrite);
print << "Test string" << endline; char resultstring[] = "Test string";
std::ifstream fin("TestFile.txt");
char buf[50];
fin.getline(buf, 50);
assert(!strcmp(resultstring, buf));
}
DECLARE_OOP_TEST(myofstream_test_const_char)//тестируем вывод константной строки (сhar)
{
MyOfStream print("TestFile.txt", MyOfStream::OpenMode::rewrite);
const char mytestconstchar[] = "This string";
print << mytestconstchar << endline;
std::ifstream fin("TestFile.txt");
char buf[50];
fin.getline(buf, 50);
assert(!strcmp(mytestconstchar, buf));
};
DECLARE_OOP_TEST(myofstream_test_bool)//тестируем вывод булевого значения
{
MyOfStream print("TestFile.txt", MyOfStream::OpenMode::rewrite);
bool testbool{ 1 }; char resultvalue[] = "1";
print << testbool << endline;
std::ifstream fin("TestFile.txt");
char buf[50];
fin >> buf;
assert(!strcmp(resultvalue, buf));
}