Skip to content

Commit d6c56fc

Browse files
committed
IsNotNull unit tests for QSslEllipticCurve
1 parent 70c07b0 commit d6c56fc

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/ssl/qsslellipticcurve.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,17 @@ impl fmt::Display for QSslEllipticCurve {
9494
}
9595

9696
impl QSslEllipticCurve {
97+
fn into_result(self) -> Result<Self, QSslEllipticCurveError> {
98+
self.nonnull_or(QSslEllipticCurveError(()))
99+
}
100+
97101
/// Returns a `QSslEllipticCurve` instance representing the named curve `name`. The `name` is a long name for the curve, whose exact spelling depends on the SSL implementation.
98102
///
99103
/// Returns an error if the given `name` is not supported.
100104
///
101105
/// **Note:** The OpenSSL implementation of this function treats the name case-sensitively.
102106
pub fn from_long_name(name: &QString) -> Result<Self, QSslEllipticCurveError> {
103-
ffi::qsslellipticcurve_from_long_name(name).nonnull_or(QSslEllipticCurveError(()))
107+
ffi::qsslellipticcurve_from_long_name(name).into_result()
104108
}
105109

106110
/// Returns a `QSslEllipticCurve` instance representing the named curve `name`. The `name` is the conventional short name for the curve, as represented by RFC 4492 (for instance secp521r1), or as NIST short names (for instance P-256). The actual set of recognized names depends on the SSL implementation.
@@ -109,7 +113,7 @@ impl QSslEllipticCurve {
109113
///
110114
/// **Note:** The OpenSSL implementation of this function treats the name case-sensitively.
111115
pub fn from_short_name(name: &QString) -> Result<Self, QSslEllipticCurveError> {
112-
ffi::qsslellipticcurve_from_short_name(name).nonnull_or(QSslEllipticCurveError(()))
116+
ffi::qsslellipticcurve_from_short_name(name).into_result()
113117
}
114118

115119
/// Returns the conventional long name for this curve. If this curve is invalid, returns `None`.
@@ -137,3 +141,15 @@ impl fmt::Display for QSslEllipticCurveError {
137141
f.write_str("the supplied name is not a supported elliptic curve")
138142
}
139143
}
144+
145+
#[cfg(test)]
146+
mod tests {
147+
use super::*;
148+
149+
#[test]
150+
fn nonnull() {
151+
assert!(!crate::util::IsNonNull::is_nonnull(
152+
&QSslEllipticCurve::default()
153+
));
154+
}
155+
}

0 commit comments

Comments
 (0)