From a30130bbb8a5291c8dff3bd6d847f991662fd193 Mon Sep 17 00:00:00 2001 From: qwerty2501 <939468+qwerty2501@users.noreply.github.com> Date: Sun, 15 May 2022 12:53:43 +0900 Subject: [PATCH] =?UTF-8?q?=E7=B0=A1=E5=8D=98=E3=81=AA=E3=83=86=E3=82=B9?= =?UTF-8?q?=E3=83=88=E3=82=B3=E3=83=BC=E3=83=89=E3=81=A8testing=E3=83=A9?= =?UTF-8?q?=E3=82=A4=E3=83=96=E3=83=A9=E3=83=AA=E3=81=AE=E5=B0=8E=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 参考になりそうな簡単なテストコードと独断ですがtestingライブラリを導入しました --- crates/voicevox_core/Cargo.toml | 4 ++++ crates/voicevox_core/src/c_export.rs | 18 ++++++++++++++++++ crates/voicevox_core/src/lib.rs | 3 +++ 3 files changed, 25 insertions(+) diff --git a/crates/voicevox_core/Cargo.toml b/crates/voicevox_core/Cargo.toml index 2b8a6f181..7f63d504a 100644 --- a/crates/voicevox_core/Cargo.toml +++ b/crates/voicevox_core/Cargo.toml @@ -13,5 +13,9 @@ derive-new = "0.5.9" once_cell = "1.10.0" thiserror = "1.0.31" +[dev-dependencies] +rstest = "0.12.0" +pretty_assertions = "1.2.1" + [build-dependencies] cbindgen = "0.23.0" diff --git a/crates/voicevox_core/src/c_export.rs b/crates/voicevox_core/src/c_export.rs index 58a96ef7d..dd213da57 100644 --- a/crates/voicevox_core/src/c_export.rs +++ b/crates/voicevox_core/src/c_export.rs @@ -11,6 +11,7 @@ use std::sync::Mutex; */ #[repr(C)] +#[derive(Debug, PartialEq)] #[allow(non_camel_case_types)] pub enum VoicevoxResultCode { // C でのenum定義に合わせて大文字で定義している @@ -214,3 +215,20 @@ pub extern "C" fn voicevox_error_result_to_message( ) -> *const c_char { internal::voicevox_error_result_to_message(result_code).as_ptr() as *const c_char } + +#[cfg(test)] +mod tests { + use super::*; + use pretty_assertions::assert_eq; + + #[rstest] + #[case(Ok(()), VoicevoxResultCode::VOICEVOX_RESULT_SUCCEED)] + #[case( + Err(Error::NotLoadedOpenjtalkDict), + VoicevoxResultCode::VOICEVOX_RESULT_NOT_LOADED_OPENJTALK_DICT + )] + fn convert_result_works(#[case] result: Result<()>, #[case] expected: VoicevoxResultCode) { + let (_, actual) = convert_result(result); + assert_eq!(expected, actual); + } +} diff --git a/crates/voicevox_core/src/lib.rs b/crates/voicevox_core/src/lib.rs index 748ff9e01..7ec79b138 100644 --- a/crates/voicevox_core/src/lib.rs +++ b/crates/voicevox_core/src/lib.rs @@ -5,3 +5,6 @@ mod result; use error::*; use result::*; + +#[cfg(test)] +use rstest::*;