From f60720090c7bd8cdf91d7aebd0c42e01c86b3b83 Mon Sep 17 00:00:00 2001 From: Matt Mastracci Date: Mon, 12 Feb 2024 13:46:50 -0700 Subject: chore: move test_ffi and test_nap to tests/ [WIP] (#22394) Moving some additional NAPI and. FFI tests out of the tree root. --- tests/napi/src/arraybuffer.rs | 52 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 tests/napi/src/arraybuffer.rs (limited to 'tests/napi/src/arraybuffer.rs') diff --git a/tests/napi/src/arraybuffer.rs b/tests/napi/src/arraybuffer.rs new file mode 100644 index 000000000..8402f5d86 --- /dev/null +++ b/tests/napi/src/arraybuffer.rs @@ -0,0 +1,52 @@ +// Copyright 2018-2024 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::*; + +extern "C" fn test_detached( + env: napi_env, + info: napi_callback_info, +) -> napi_value { + let (args, argc, _) = napi_get_callback_info!(env, info, 1); + assert_eq!(argc, 1); + + let mut value = false; + assert_napi_ok!(napi_is_detached_arraybuffer(env, args[0], &mut value)); + assert!(!value); + assert_napi_ok!(napi_detach_arraybuffer(env, args[0])); + assert_napi_ok!(napi_is_detached_arraybuffer(env, args[0], &mut value)); + assert!(value); + args[0] +} + +extern "C" fn is_detached( + env: napi_env, + info: napi_callback_info, +) -> napi_value { + let (args, argc, _) = napi_get_callback_info!(env, info, 1); + assert_eq!(argc, 1); + + let mut value = false; + assert_napi_ok!(napi_is_detached_arraybuffer(env, args[0], &mut value)); + + let mut result = std::ptr::null_mut(); + assert_napi_ok!(napi_get_boolean(env, value, &mut result)); + + result +} + +pub fn init(env: napi_env, exports: napi_value) { + let properties = &[ + napi_new_property!(env, "test_detached", test_detached), + napi_new_property!(env, "is_detached", is_detached), + ]; + + assert_napi_ok!(napi_define_properties( + env, + exports, + properties.len(), + properties.as_ptr() + )); +} -- cgit v1.2.3