grpc
third_party
boringssl-with-bazel
src
crypto
test
file_test_gtest.cc
Go to the documentation of this file.
1
/* Copyright (c) 2017, Google Inc.
2
*
3
* Permission to use, copy, modify, and/or distribute this software for any
4
* purpose with or without fee is hereby granted, provided that the above
5
* copyright notice and this permission notice appear in all copies.
6
*
7
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14
15
#include "
file_test.h
"
16
17
#include <assert.h>
18
#include <
string.h
>
19
20
#include <memory>
21
#include <string>
22
#include <utility>
23
24
#include <gtest/gtest.h>
25
26
#include <
openssl/err.h
>
27
28
29
std::string
GetTestData
(
const
char
*
path
);
30
31
class
StringLineReader
:
public
FileTest::LineReader
{
32
public
:
33
explicit
StringLineReader
(
const
std::string
&
data
)
34
:
data_
(
data
),
offset_
(0) {}
35
36
FileTest::ReadResult
ReadLine
(
char
*
out
,
size_t
len
)
override
{
37
assert(
len
> 0);
38
if
(
offset_
==
data_
.size()) {
39
return
FileTest::kReadEOF
;
40
}
41
42
size_t
idx
=
data_
.find(
'\n'
,
offset_
);
43
if
(
idx
== std::string::npos) {
44
idx
=
data_
.size();
45
}
else
{
46
idx
++;
// Include the newline.
47
}
48
49
if
(
idx
-
offset_
>
len
- 1) {
50
ADD_FAILURE
() <<
"Line too long."
;
51
return
FileTest::kReadError
;
52
}
53
54
memcpy
(
out
,
data_
.data() +
offset_
,
idx
-
offset_
);
55
out
[
idx
-
offset_
] =
'\0'
;
56
offset_
=
idx
;
57
return
FileTest::kReadSuccess
;
58
}
59
60
private
:
61
std::string
data_
;
62
size_t
offset_
;
63
64
StringLineReader
(
const
StringLineReader
&) =
delete
;
65
StringLineReader
&
operator=
(
const
StringLineReader
&) =
delete
;
66
};
67
68
void
FileTestGTest
(
const
char
*
path
,
std::function
<
void
(
FileTest
*)>
run_test
) {
69
std::unique_ptr<StringLineReader>
reader
(
70
new
StringLineReader
(
GetTestData
(
path
)));
71
FileTest
t(
std::move
(
reader
),
nullptr
,
false
);
72
73
while
(
true
) {
74
switch
(t.ReadNext()) {
75
case
FileTest::kReadError
:
76
ADD_FAILURE
() <<
"Error reading test."
;
77
return
;
78
case
FileTest::kReadEOF
:
79
return
;
80
case
FileTest::kReadSuccess
:
81
break
;
82
}
83
84
const
testing::TestResult
*
test_result
=
85
testing::UnitTest::GetInstance
()->
current_test_info
()->
result
();
86
int
before_part_count =
test_result
->total_part_count();
87
88
SCOPED_TRACE
(
testing::Message
() <<
path
<<
", line "
<< t.start_line());
89
run_test
(&t);
90
91
// Check for failures from the most recent test.
92
bool
failed =
false
;
93
for
(
int
i
= before_part_count;
i
<
test_result
->total_part_count();
i
++) {
94
if
(
test_result
->GetTestPartResult(
i
).failed()) {
95
failed =
true
;
96
break
;
97
}
98
}
99
100
// Clean up the error queue for the next test, reporting it on failure.
101
if
(failed) {
102
ERR_print_errors_fp
(
stdout
);
103
}
else
{
104
ERR_clear_error
();
105
}
106
}
107
}
gen_build_yaml.out
dictionary out
Definition:
src/benchmark/gen_build_yaml.py:24
StringLineReader::StringLineReader
StringLineReader(const std::string &data)
Definition:
file_test_gtest.cc:33
testing::UnitTest::current_test_info
const TestInfo * current_test_info() const GTEST_LOCK_EXCLUDED_(mutex_)
Definition:
bloaty/third_party/googletest/googletest/src/gtest.cc:4961
demumble_test.stdout
stdout
Definition:
demumble_test.py:38
StringLineReader::operator=
StringLineReader & operator=(const StringLineReader &)=delete
testing::TestResult
Definition:
bloaty/third_party/googletest/googletest/include/gtest/gtest.h:562
string.h
testing::internal::string
::std::string string
Definition:
bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
ERR_print_errors_fp
#define ERR_print_errors_fp
Definition:
boringssl_prefix_symbols.h:1437
check_documentation.path
path
Definition:
check_documentation.py:57
StringLineReader::data_
std::string data_
Definition:
file_test_gtest.cc:61
grpc::testing::test_result
test_result
Definition:
h2_ssl_cert_test.cc:201
testing::Message
Definition:
bloaty/third_party/googletest/googletest/include/gtest/gtest-message.h:90
FileTest::ReadResult
ReadResult
Definition:
file_test.h:92
StringLineReader::ReadLine
FileTest::ReadResult ReadLine(char *out, size_t len) override
Definition:
file_test_gtest.cc:36
StringLineReader
Definition:
file_test_gtest.cc:31
memcpy
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
SCOPED_TRACE
#define SCOPED_TRACE(message)
Definition:
bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2264
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition:
abseil-cpp/absl/utility/utility.h:221
FileTest::kReadSuccess
@ kReadSuccess
Definition:
file_test.h:93
FileTestGTest
void FileTestGTest(const char *path, std::function< void(FileTest *)> run_test)
Definition:
file_test_gtest.cc:68
FileTest::LineReader
Definition:
file_test.h:98
FileTest
Definition:
file_test.h:90
err.h
data
char data[kBufferLength]
Definition:
abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1006
ADD_FAILURE
#define ADD_FAILURE()
Definition:
bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1911
testing::TestInfo::result
const TestResult * result() const
Definition:
bloaty/third_party/googletest/googletest/include/gtest/gtest.h:761
GetTestData
std::string GetTestData(const char *path)
Definition:
crypto_test_data.cc:4454
setup.idx
idx
Definition:
third_party/bloaty/third_party/capstone/bindings/python/setup.py:197
StringLineReader::offset_
size_t offset_
Definition:
file_test_gtest.cc:62
ERR_clear_error
#define ERR_clear_error
Definition:
boringssl_prefix_symbols.h:1413
testing::UnitTest::GetInstance
static UnitTest * GetInstance()
Definition:
bloaty/third_party/googletest/googletest/src/gtest.cc:4616
tests.stress.client.run_test
def run_test(args)
Definition:
src/python/grpcio_tests/tests/stress/client.py:116
len
int len
Definition:
abseil-cpp/absl/base/internal/low_level_alloc_test.cc:46
function
std::function< bool(GrpcTool *, int, const char **, const CliCredentials &, GrpcToolOutputCallback)> function
Definition:
grpc_tool.cc:250
file_test.h
FileTest::kReadEOF
@ kReadEOF
Definition:
file_test.h:94
reader
void reader(void *n)
Definition:
libuv/docs/code/locks/main.c:8
i
uint64_t i
Definition:
abseil-cpp/absl/container/btree_benchmark.cc:230
FileTest::kReadError
@ kReadError
Definition:
file_test.h:95
grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:23