userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
exceptions_test.cpp
1
#
include
<
gmock
/
gmock
.
h
>
2
#
include
<
gtest
/
gtest
.
h
>
3
4
#
include
<
userver
/
protobuf
/
json
/
exceptions
.
hpp
>
5
6
USERVER_NAMESPACE_BEGIN
7
8
namespace
protobuf::json::tests {
9
10
TEST(ExceptionsTest, CtorCorrectlyInitializesObject) {
11
{
12
const
std::vector<std::pair<
ParseErrorCode
, std::string>> errors{
13
{
ParseErrorCode
::
kUnknownField
,
"hello world"
},
14
{
ParseErrorCode
::
kUnknownEnum
,
""
},
15
{
ParseErrorCode
::
kMultipleOneofFields
,
"additional description"
},
16
{
ParseErrorCode
::
kInvalidType
,
""
},
17
{
ParseErrorCode
::
kInvalidValue
,
""
},
18
{
static_cast
<
ParseErrorCode
>(100),
""
}
19
};
20
const
std::string path =
"field.array[0].item[1]"
;
21
22
for
(
const
auto
& e : errors) {
23
ParseError
error
(
e.first
,
path
,
e.second
)
;
24
25
EXPECT_EQ(error
.
GetErrorInfo
(
)
.
GetCode
(
)
, e.first);
26
EXPECT_EQ(error
.
GetErrorInfo
(
)
.
GetPath
(
)
, path);
27
EXPECT_EQ(std::move(error)
.
GetErrorInfo
(
)
.
GetPath
(
)
, path);
28
}
29
}
30
31
{
32
const
std::vector<std::pair<
PrintErrorCode
, std::string>>
33
errors{{
PrintErrorCode
::
kInvalidValue
,
""
}, {
static_cast
<
PrintErrorCode
>(100),
"hello world"
}};
34
const
std::string path =
"field.array[0].item[1].map['key']"
;
35
36
for
(
const
auto
& e : errors) {
37
PrintError
error
(
e.first
,
path
,
e.second
)
;
38
39
EXPECT_EQ(error
.
GetErrorInfo
(
)
.
GetCode
(
)
, e.first);
40
EXPECT_EQ(error
.
GetErrorInfo
(
)
.
GetPath
(
)
, path);
41
EXPECT_EQ(std::move(error)
.
GetErrorInfo
(
)
.
GetPath
(
)
, path);
42
}
43
}
44
}
45
46
TEST(ExceptionsTest, WhatContainsImportantDetails) {
47
{
48
const
std::string path =
"field.array[0].item[1]"
;
49
const
std::string additional_desc =
"hello world"
;
50
const
ParseError
error
(
ParseErrorCode
::
kInvalidType
,
path
,
additional_desc
)
;
51
52
EXPECT_THAT(error.what(), ::
testing
::HasSubstr(path));
53
EXPECT_THAT(error.what(), ::
testing
::HasSubstr(additional_desc));
54
}
55
56
{
57
const
std::string path =
"field.array[0].item[1].map['key']"
;
58
const
std::string additional_desc =
"hello world"
;
59
const
PrintError
error
(
PrintErrorCode
::
kInvalidValue
,
path
,
additional_desc
)
;
60
61
EXPECT_THAT(error.what(), ::
testing
::HasSubstr(path));
62
EXPECT_THAT(error.what(), ::
testing
::HasSubstr(additional_desc));
63
}
64
}
65
66
}
// namespace protobuf::json::tests
67
68
USERVER_NAMESPACE_END
protobuf
tests
json
exceptions_test.cpp
Generated on
for userver by
Doxygen
1.17.0