Refactored KLocalizedContext
Extracted everything from lib.rs Also extracted all doc tests to integration tests.
This commit is contained in:
parent
0470f05c07
commit
38ebb314b8
6 changed files with 114 additions and 96 deletions
12
tests/common.rs
Normal file
12
tests/common.rs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
use lazy_static::lazy_static;
|
||||
use std::sync::Mutex;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref TEST_MUTEX: Mutex<()> = Mutex::new(());
|
||||
}
|
||||
|
||||
/// There can only be one thread running at the time with a QQuickEngine
|
||||
/// (in principle, everything should be in the same main thread)
|
||||
pub fn lock_for_test() -> std::sync::MutexGuard<'static, ()> {
|
||||
TEST_MUTEX.lock().unwrap_or_else(|e| e.into_inner())
|
||||
}
|
||||
37
tests/klocalizedcontext_tests.rs
Normal file
37
tests/klocalizedcontext_tests.rs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
use ki18n_rs::KLocalizedContext;
|
||||
use qmetaobject::prelude::*;
|
||||
mod common;
|
||||
|
||||
#[test]
|
||||
fn init_engine() {
|
||||
let _lock = common::lock_for_test();
|
||||
|
||||
let engine = QmlEngine::new();
|
||||
KLocalizedContext::init_from_engine(&engine);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cpp_ptr() {
|
||||
let _lock = common::lock_for_test();
|
||||
|
||||
let engine = QmlEngine::new();
|
||||
let context = KLocalizedContext::init_from_engine(&engine);
|
||||
|
||||
let context_ptr = context.cpp_ptr();
|
||||
assert_ne!(std::ptr::null(), context_ptr);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn translation_domain() {
|
||||
let _lock = common::lock_for_test();
|
||||
|
||||
let engine = QmlEngine::new();
|
||||
let mut context = KLocalizedContext::init_from_engine(&engine);
|
||||
|
||||
const TRANSLATION_DOMAIN: &str = "Test Domain";
|
||||
context.set_translation_domain(TRANSLATION_DOMAIN.into());
|
||||
|
||||
let domain = context.translation_domain();
|
||||
|
||||
assert_eq!(domain, QString::from(TRANSLATION_DOMAIN));
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
use ki18n_rs::*;
|
||||
Loading…
Add table
Add a link
Reference in a new issue