@@ -62,7 +62,7 @@ impl QMessageLogContext {
62
62
63
63
/// Wrap Qt's QtMsgType enum
64
64
#[ repr( C ) ]
65
- #[ derive( Copy , Clone , Debug ) ]
65
+ #[ derive( Copy , Clone , Debug , Eq , PartialEq ) ]
66
66
pub enum QtMsgType {
67
67
QtDebugMsg ,
68
68
QtWarningMsg ,
@@ -180,14 +180,15 @@ extern "C" fn log_capture(msg_type: QtMsgType,
180
180
}
181
181
}
182
182
183
- /// Installs into Qt logging system a function which forwards messages to the
183
+ /// Installs into [ Qt logging system][qt-log] a function which forwards messages to the
184
184
/// [Rust logging facade][log].
185
185
///
186
186
/// Most metadata from Qt logging context is retained and passed to [`log::Record`][].
187
187
/// Logging levels are mapped with the [default][map_level] algorithm.
188
188
///
189
189
/// This function may be called more than once.
190
190
///
191
+ /// [qt-log]: https://doc.qt.io/qt-5/qtglobal.html#qInstallMessageHandler
191
192
/// [log]: https://docs.rs/log
192
193
/// [`log::Record`]: https://docs.rs/log/0.4.10/log/struct.Record.html
193
194
/// [map_level]: ./fn.map_level.html
@@ -197,3 +198,21 @@ pub fn init_qt_to_rust() {
197
198
// would want to implement the opposite forwarding logger?
198
199
install_message_handler ( log_capture) ;
199
200
}
201
+
202
+ #[ cfg( test) ]
203
+ mod tests {
204
+ use super :: * ;
205
+
206
+ #[ test]
207
+ fn test_double_init ( ) {
208
+ // must not crash
209
+ init_qt_to_rust ( ) ;
210
+ init_qt_to_rust ( ) ;
211
+ }
212
+
213
+ #[ test]
214
+ fn test_convert ( ) {
215
+ assert_eq ! ( Level :: from( QtInfoMsg ) , Level :: Info ) ;
216
+ assert_eq ! ( QtCriticalMsg , QtMsgType :: from( Level :: Error ) )
217
+ }
218
+ }
0 commit comments