Skip to content

Commit 2822921

Browse files
authored
Merge pull request #394 from Superhepper/wrapper-error-kind-display-tests
Adds tests for WrapperErrorKind.
2 parents d7baa84 + 7d92964 commit 2822921

File tree

3 files changed

+61
-9
lines changed

3 files changed

+61
-9
lines changed

tss-esapi/src/error/wrapper.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,27 @@ impl std::fmt::Display for WrapperErrorKind {
3131
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3232
match self {
3333
WrapperErrorKind::WrongParamSize => {
34-
write!(f, "parameter provided is of the wrong size")
34+
write!(f, "Parameter provided is of the wrong size.")
3535
}
3636
WrapperErrorKind::ParamsMissing => {
37-
write!(f, "some of the required parameters were not provided")
37+
write!(f, "Some of the required parameters were not provided.")
3838
}
3939
WrapperErrorKind::InconsistentParams => write!(
4040
f,
41-
"the provided parameters have inconsistent values or variants"
41+
"The provided parameters have inconsistent values or variants."
4242
),
4343
WrapperErrorKind::UnsupportedParam => write!(
4444
f,
45-
"the provided parameter is not yet supported by the library"
45+
"The provided parameter is not yet supported by the library."
4646
),
4747
WrapperErrorKind::InvalidParam => {
48-
write!(f, "the provided parameter is invalid for that type.")
48+
write!(f, "The provided parameter is invalid for that type.")
4949
}
50-
WrapperErrorKind::WrongValueFromTpm => write!(f, "the TPM returned an invalid value."),
51-
WrapperErrorKind::MissingAuthSession => write!(f, "Missing authorization session"),
52-
WrapperErrorKind::InvalidHandleState => write!(f, "Invalid handle state"),
50+
WrapperErrorKind::WrongValueFromTpm => write!(f, "The TPM returned an invalid value."),
51+
WrapperErrorKind::MissingAuthSession => write!(f, "Missing authorization session."),
52+
WrapperErrorKind::InvalidHandleState => write!(f, "Invalid handle state."),
5353
WrapperErrorKind::InternalError => {
54-
write!(f, "an unexpected error occurred within the crate")
54+
write!(f, "An unexpected error occurred within the crate.")
5555
}
5656
}
5757
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
// Copyright 2022 Contributors to the Parsec project.
22
// SPDX-License-Identifier: Apache-2.0
33
mod return_code_tests;
4+
mod wrapper_error_kind_tests;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2023 Contributors to the Parsec project.
2+
// SPDX-License-Identifier: Apache-2.0
3+
use tss_esapi::error::WrapperErrorKind;
4+
5+
#[test]
6+
fn test_display() {
7+
assert_eq!(
8+
"Parameter provided is of the wrong size.",
9+
format!("{}", WrapperErrorKind::WrongParamSize)
10+
);
11+
12+
assert_eq!(
13+
"Some of the required parameters were not provided.",
14+
format!("{}", WrapperErrorKind::ParamsMissing)
15+
);
16+
17+
assert_eq!(
18+
"The provided parameters have inconsistent values or variants.",
19+
format!("{}", WrapperErrorKind::InconsistentParams)
20+
);
21+
22+
assert_eq!(
23+
"The provided parameter is not yet supported by the library.",
24+
format!("{}", WrapperErrorKind::UnsupportedParam)
25+
);
26+
27+
assert_eq!(
28+
"The provided parameter is invalid for that type.",
29+
format!("{}", WrapperErrorKind::InvalidParam)
30+
);
31+
32+
assert_eq!(
33+
"The TPM returned an invalid value.",
34+
format!("{}", WrapperErrorKind::WrongValueFromTpm)
35+
);
36+
37+
assert_eq!(
38+
"Missing authorization session.",
39+
format!("{}", WrapperErrorKind::MissingAuthSession)
40+
);
41+
42+
assert_eq!(
43+
"Invalid handle state.",
44+
format!("{}", WrapperErrorKind::InvalidHandleState)
45+
);
46+
47+
assert_eq!(
48+
"An unexpected error occurred within the crate.",
49+
format!("{}", WrapperErrorKind::InternalError)
50+
);
51+
}

0 commit comments

Comments
 (0)