diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2023-01-11 15:47:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-11 15:47:26 +0100 |
commit | d0a53c3ce509d8a012315d8008a33c03802fc70c (patch) | |
tree | 01dc7aca1d36056c807723bbb78a88d235ab5f9d /test_napi/src/async.rs | |
parent | e26fc195ef97d27dae0ca34b2bf592ae839ca218 (diff) |
refactor(napi): Cleanup tests (#17347)
Diffstat (limited to 'test_napi/src/async.rs')
-rw-r--r-- | test_napi/src/async.rs | 89 |
1 files changed, 43 insertions, 46 deletions
diff --git a/test_napi/src/async.rs b/test_napi/src/async.rs index d825636e1..0df4990ab 100644 --- a/test_napi/src/async.rs +++ b/test_napi/src/async.rs @@ -1,5 +1,8 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +use crate::assert_napi_ok; +use crate::napi_get_callback_info; +use crate::napi_new_property; use napi_sys::Status::napi_ok; use napi_sys::ValueType::napi_function; use napi_sys::*; @@ -31,82 +34,76 @@ unsafe extern "C" fn complete( assert!(!baton.func.is_null()); let mut global: napi_value = ptr::null_mut(); - assert!(napi_get_global(env, &mut global) == napi_ok); + assert_napi_ok!(napi_get_global(env, &mut global)); let mut callback: napi_value = ptr::null_mut(); - assert!(napi_get_reference_value(env, baton.func, &mut callback) == napi_ok); + assert_napi_ok!(napi_get_reference_value(env, baton.func, &mut callback)); let mut _result: napi_value = ptr::null_mut(); - assert!( - napi_call_function(env, global, callback, 0, ptr::null(), &mut _result) - == napi_ok - ); - - assert!(napi_delete_reference(env, baton.func) == napi_ok); - assert!(napi_delete_async_work(env, baton.task) == napi_ok); + assert_napi_ok!(napi_call_function( + env, + global, + callback, + 0, + ptr::null(), + &mut _result + )); + + assert_napi_ok!(napi_delete_reference(env, baton.func)); + assert_napi_ok!(napi_delete_async_work(env, baton.task)); } extern "C" fn test_async_work( env: napi_env, info: napi_callback_info, ) -> napi_value { - let (args, argc, _) = crate::get_callback_info!(env, info, 1); + let (args, argc, _) = napi_get_callback_info!(env, info, 1); assert_eq!(argc, 1); let mut ty = -1; - assert!(unsafe { napi_typeof(env, args[0], &mut ty) } == napi_ok); + assert_napi_ok!(napi_typeof(env, args[0], &mut ty)); assert_eq!(ty, napi_function); let mut resource_name: napi_value = ptr::null_mut(); - assert!( - unsafe { - napi_create_string_utf8( - env, - "test_async_resource\0".as_ptr() as *const c_char, - usize::MAX, - &mut resource_name, - ) - } == napi_ok - ); + assert_napi_ok!(napi_create_string_utf8( + env, + "test_async_resource".as_ptr() as *const c_char, + usize::MAX, + &mut resource_name, + )); let mut async_work: napi_async_work = ptr::null_mut(); let mut func: napi_ref = ptr::null_mut(); - assert!( - unsafe { napi_create_reference(env, args[0], 1, &mut func) } == napi_ok - ); + assert_napi_ok!(napi_create_reference(env, args[0], 1, &mut func)); let baton = Box::new(Baton { called: false, func, task: async_work, }); - assert!( - unsafe { - napi_create_async_work( - env, - ptr::null_mut(), - resource_name, - Some(execute), - Some(complete), - Box::into_raw(baton) as *mut c_void, - &mut async_work, - ) - } == napi_ok - ); - assert!(unsafe { napi_queue_async_work(env, async_work) } == napi_ok); + assert_napi_ok!(napi_create_async_work( + env, + ptr::null_mut(), + resource_name, + Some(execute), + Some(complete), + Box::into_raw(baton) as *mut c_void, + &mut async_work, + )); + assert_napi_ok!(napi_queue_async_work(env, async_work)); ptr::null_mut() } pub fn init(env: napi_env, exports: napi_value) { - let properties = &[crate::new_property!( - env, - "test_async_work\0", - test_async_work - )]; + let properties = + &[napi_new_property!(env, "test_async_work", test_async_work)]; - unsafe { - napi_define_properties(env, exports, properties.len(), properties.as_ptr()) - }; + assert_napi_ok!(napi_define_properties( + env, + exports, + properties.len(), + properties.as_ptr() + )); } |