-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathtest.cpp
More file actions
146 lines (138 loc) · 2.72 KB
/
test.cpp
File metadata and controls
146 lines (138 loc) · 2.72 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
137
138
139
140
141
142
143
144
145
146
#include <exception>
#include <fstream>
void test_terminate() {
std::fstream file("file");
std::terminate(); // NON_COMPLIANT
}
void test_closed() {
std::fstream file("file");
if (!file.is_open()) {
return;
}
file.close();
if (file.fail()) {
}
std::terminate(); // COMPLIANT
}
void test_fail() {
{
std::fstream file("file");
if (!file.is_open()) {
return;
}
file.close();
if (file.fail()) {
}
}
std::terminate(); // COMPLIANT
}
void test_scope() {
std::fstream file;
{
file.open("file");
if (!file.is_open()) {
return;
}
file.close();
if (file.fail()) {
}
}
std::terminate(); // COMPLIANT
}
void test_sequence() {
std::fstream file;
{
file.open("file");
if (!file.is_open()) {
return;
}
file.close();
if (file.fail()) {
}
file.open("file");
if (!file.is_open()) {
return;
}
}
std::terminate(); // NON_COMPLIANT
}
// file2 not closed
void test_2files() {
std::fstream file1("file");
std::fstream file2("file1");
file2 << "some data";
if (!file1.is_open()) {
return;
}
file1.close();
if (file2.fail()) {
}
std::terminate(); // NON_COMPLIANT
}
// test istream and ostream inherited functions
void test_stream_functions(int rand) {
std::fstream file("file");
int len = 10;
char buff[len];
file.close();
file.is_open();
if (rand)
std::terminate(); // COMPLIANT
file >> buff;
if (rand)
std::terminate(); // NON_COMPLIANT
file.gcount();
if (rand)
std::terminate(); // NON_COMPLIANT
file.get();
if (rand)
std::terminate(); // NON_COMPLIANT
file.getline(buff, len);
if (rand)
std::terminate(); // NON_COMPLIANT
file.ignore();
if (rand)
std::terminate(); // NON_COMPLIANT
file.peek();
if (rand)
std::terminate(); // NON_COMPLIANT
file.read(buff, len);
if (rand)
std::terminate(); // NON_COMPLIANT
file.readsome(buff, len);
if (rand)
std::terminate(); // NON_COMPLIANT
file.putback('a');
if (rand)
std::terminate(); // NON_COMPLIANT
file.unget();
if (rand)
std::terminate(); // NON_COMPLIANT
file.tellg();
if (rand)
std::terminate(); // NON_COMPLIANT
file.seekg(0);
if (rand)
std::terminate(); // NON_COMPLIANT
file.sync();
if (rand)
std::terminate(); // NON_COMPLIANT
file << "some data";
if (rand)
std::terminate(); // NON_COMPLIANT
file.put('a');
if (rand)
std::terminate(); // NON_COMPLIANT
file.write(buff, len);
if (rand)
std::terminate(); // NON_COMPLIANT
file.tellp();
if (rand)
std::terminate(); // NON_COMPLIANT
file.seekp(0);
if (rand)
std::terminate(); // NON_COMPLIANT
file.flush();
if (rand)
std::terminate(); // NON_COMPLIANT
}