use chdb_rust::arrow_stream::{ArrowArray, ArrowSchema, ArrowStream};
use chdb_rust::connection::Connection;
use chdb_rust::error::Error;
#[test]
fn test_arrow_stream_wrapper() {
let null_ptr = std::ptr::null_mut();
let stream = unsafe { ArrowStream::from_raw(null_ptr) };
assert!(stream.as_raw().is_null());
let stream2 = stream;
assert_eq!(stream.as_raw(), stream2.as_raw());
}
#[test]
fn test_arrow_schema_wrapper() {
let null_ptr = std::ptr::null_mut();
let schema = unsafe { ArrowSchema::from_raw(null_ptr) };
assert!(schema.as_raw().is_null());
let schema2 = schema;
assert_eq!(schema.as_raw(), schema2.as_raw());
}
#[test]
fn test_arrow_array_wrapper() {
let null_ptr = std::ptr::null_mut();
let array = unsafe { ArrowArray::from_raw(null_ptr) };
assert!(array.as_raw().is_null());
let array2 = array;
assert_eq!(array.as_raw(), array2.as_raw());
}
#[test]
fn test_register_arrow_stream_invalid_table_name() {
let conn = Connection::open_in_memory().expect("Failed to create connection");
let null_stream = unsafe { ArrowStream::from_raw(std::ptr::null_mut()) };
let result = conn.register_arrow_stream("table\0name", &null_stream);
assert!(result.is_err());
match result {
Err(Error::Nul(_)) => {}
Err(e) => panic!("Expected Nul error, got {:?}", e),
Ok(_) => panic!("Expected error for null byte in table name"),
}
}
#[test]
fn test_register_arrow_stream_with_null_handle() {
let conn = Connection::open_in_memory().expect("Failed to create connection");
let null_stream = unsafe { ArrowStream::from_raw(std::ptr::null_mut()) };
let result = conn.register_arrow_stream("test_table", &null_stream);
let _ = result;
}
#[test]
fn test_register_arrow_array_invalid_table_name() {
let conn = Connection::open_in_memory().expect("Failed to create connection");
let null_schema = unsafe { ArrowSchema::from_raw(std::ptr::null_mut()) };
let null_array = unsafe { ArrowArray::from_raw(std::ptr::null_mut()) };
let result = conn.register_arrow_array("table\0name", &null_schema, &null_array);
assert!(result.is_err());
match result {
Err(Error::Nul(_)) => {}
Err(e) => panic!("Expected Nul error, got {:?}", e),
Ok(_) => panic!("Expected error for null byte in table name"),
}
}
#[test]
fn test_register_arrow_array_with_null_handles() {
let conn = Connection::open_in_memory().expect("Failed to create connection");
let null_schema = unsafe { ArrowSchema::from_raw(std::ptr::null_mut()) };
let null_array = unsafe { ArrowArray::from_raw(std::ptr::null_mut()) };
let result = conn.register_arrow_array("test_table", &null_schema, &null_array);
let _ = result;
}
#[test]
fn test_unregister_arrow_table_invalid_table_name() {
let conn = Connection::open_in_memory().expect("Failed to create connection");
let result = conn.unregister_arrow_table("table\0name");
assert!(result.is_err());
match result {
Err(Error::Nul(_)) => {}
Err(e) => panic!("Expected Nul error, got {:?}", e),
Ok(_) => panic!("Expected error for null byte in table name"),
}
}
#[test]
fn test_unregister_nonexistent_table() {
let conn = Connection::open_in_memory().expect("Failed to create connection");
let result = conn.unregister_arrow_table("nonexistent_table_12345");
match result {
Ok(_) => {
}
Err(Error::QueryError(_)) => {
}
Err(e) => panic!("Unexpected error type: {:?}", e),
}
}
#[test]
fn test_arrow_stream_send() {
use std::thread;
let null_ptr = std::ptr::null_mut();
let stream = unsafe { ArrowStream::from_raw(null_ptr) };
thread::spawn(move || {
let _ = stream;
})
.join()
.expect("Thread should complete");
}
#[test]
fn test_arrow_schema_send() {
use std::thread;
let null_ptr = std::ptr::null_mut();
let schema = unsafe { ArrowSchema::from_raw(null_ptr) };
thread::spawn(move || {
let _ = schema;
})
.join()
.expect("Thread should complete");
}
#[test]
fn test_arrow_array_send() {
use std::thread;
let null_ptr = std::ptr::null_mut();
let array = unsafe { ArrowArray::from_raw(null_ptr) };
thread::spawn(move || {
let _ = array;
})
.join()
.expect("Thread should complete");
}
#[test]
fn test_arrow_stream_valid_table_names() {
let conn = Connection::open_in_memory().expect("Failed to create connection");
let null_stream = unsafe { ArrowStream::from_raw(std::ptr::null_mut()) };
let valid_names = [
"simple_table",
"table_with_underscores",
"TableWithCamelCase",
"table123",
"a",
"very_long_table_name_with_many_characters_that_should_still_be_valid",
];
for name in &valid_names {
let result = conn.register_arrow_stream(name, &null_stream);
let _ = result;
}
}
#[test]
fn test_arrow_array_valid_table_names() {
let conn = Connection::open_in_memory().expect("Failed to create connection");
let null_schema = unsafe { ArrowSchema::from_raw(std::ptr::null_mut()) };
let null_array = unsafe { ArrowArray::from_raw(std::ptr::null_mut()) };
let valid_names = [
"simple_table",
"table_with_underscores",
"TableWithCamelCase",
"table123",
];
for name in &valid_names {
let result = conn.register_arrow_array(name, &null_schema, &null_array);
let _ = result;
}
}
#[test]
fn test_connection_methods_consistency() {
let conn = Connection::open_in_memory().expect("Failed to create connection");
let null_stream = unsafe { ArrowStream::from_raw(std::ptr::null_mut()) };
let null_schema = unsafe { ArrowSchema::from_raw(std::ptr::null_mut()) };
let null_array = unsafe { ArrowArray::from_raw(std::ptr::null_mut()) };
let result1 = conn.register_arrow_stream("test\0", &null_stream);
let result2 = conn.register_arrow_array("test\0", &null_schema, &null_array);
let result3 = conn.unregister_arrow_table("test\0");
assert!(result1.is_err());
assert!(result2.is_err());
assert!(result3.is_err());
match (result1, result2, result3) {
(Err(Error::Nul(_)), Err(Error::Nul(_)), Err(Error::Nul(_))) => {}
_ => panic!("All should return Nul errors for null bytes"),
}
}