From 5fc98778a92d2515c3389fb0703af1c9c7403ddd Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 21 May 2026 17:49:35 +0100 Subject: [PATCH] Update tests --- tests/unit/out/unsafe/sys_stat.rs | 124 +++++------------------------- 1 file changed, 19 insertions(+), 105 deletions(-) diff --git a/tests/unit/out/unsafe/sys_stat.rs b/tests/unit/out/unsafe/sys_stat.rs index a90489c..4bfa9ef 100644 --- a/tests/unit/out/unsafe/sys_stat.rs +++ b/tests/unit/out/unsafe/sys_stat.rs @@ -8,50 +8,16 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub unsafe fn test_stat_0() { let mut path: *const u8 = (b"/tmp/cpp2rust_stat_test.tmp\0".as_ptr().cast_mut()).cast_const(); - let mut fp: *mut ::std::fs::File = - match std::ffi::CStr::from_ptr((b"wb\0".as_ptr().cast_mut()).cast_const() as *const i8) - .to_str() - .expect("invalid c-string") - { - v if v == "rb" => std::fs::OpenOptions::new() - .read(true) - .open( - std::ffi::CStr::from_ptr(path as *const i8) - .to_str() - .expect("invalid c-string"), - ) - .ok() - .map_or(std::ptr::null_mut(), |f| Box::into_raw(Box::new(f))), - v if v == "wb" => std::fs::OpenOptions::new() - .write(true) - .create(true) - .truncate(true) - .open( - std::ffi::CStr::from_ptr(path as *const i8) - .to_str() - .expect("invalid c-string"), - ) - .ok() - .map_or(std::ptr::null_mut(), |f| Box::into_raw(Box::new(f))), - _ => panic!("unsupported mode"), - }; + let mut fp: *mut ::libc::FILE = libc::fopen( + path as *const i8, + (b"wb\0".as_ptr().cast_mut()).cast_const() as *const i8, + ); assert!((((!((fp).is_null())) as i32) != 0)); - { - let bytes = - std::ffi::CStr::from_ptr((b"hello\0".as_ptr().cast_mut()).cast_const() as *const i8) - .to_bytes(); - match (*fp).write_all(bytes) { - Ok(()) => 0, - Err(_) => -1, - } - }; - assert!( - (((({ - Box::from_raw(fp); - 0 - }) == (0)) as i32) - != 0) + libc::fputs( + (b"hello\0".as_ptr().cast_mut()).cast_const() as *const i8, + fp, ); + assert!(((((libc::fclose(fp)) == (0)) as i32) != 0)); let mut st: stat = std::mem::zeroed::(); assert!(((((libc::stat(path as *const i8, (&mut st as *mut stat))) == (0)) as i32) != 0)); assert!(((((st.st_size) == (5_i64)) as i32) != 0)); @@ -59,73 +25,21 @@ pub unsafe fn test_stat_0() { } pub unsafe fn test_fstat_1() { let mut path: *const u8 = (b"/tmp/cpp2rust_fstat_test.tmp\0".as_ptr().cast_mut()).cast_const(); - let mut fp: *mut ::std::fs::File = - match std::ffi::CStr::from_ptr((b"wb\0".as_ptr().cast_mut()).cast_const() as *const i8) - .to_str() - .expect("invalid c-string") - { - v if v == "rb" => std::fs::OpenOptions::new() - .read(true) - .open( - std::ffi::CStr::from_ptr(path as *const i8) - .to_str() - .expect("invalid c-string"), - ) - .ok() - .map_or(std::ptr::null_mut(), |f| Box::into_raw(Box::new(f))), - v if v == "wb" => std::fs::OpenOptions::new() - .write(true) - .create(true) - .truncate(true) - .open( - std::ffi::CStr::from_ptr(path as *const i8) - .to_str() - .expect("invalid c-string"), - ) - .ok() - .map_or(std::ptr::null_mut(), |f| Box::into_raw(Box::new(f))), - _ => panic!("unsupported mode"), - }; + let mut fp: *mut ::libc::FILE = libc::fopen( + path as *const i8, + (b"wb\0".as_ptr().cast_mut()).cast_const() as *const i8, + ); assert!((((!((fp).is_null())) as i32) != 0)); - { - let bytes = std::ffi::CStr::from_ptr( - (b"hello world\0".as_ptr().cast_mut()).cast_const() as *const i8 - ) - .to_bytes(); - match (*fp).write_all(bytes) { - Ok(()) => 0, - Err(_) => -1, - } - }; - if !(fp).is_null() { - match (*fp).sync_all() { - Ok(_) => 0, - Err(_) => -1, - } - } else { - ::std::io::stdout().flush().unwrap(); - ::std::io::stderr().flush().unwrap(); - 0 - }; - let mut fd: i32 = if fp == libcc2rs::cin_unsafe() { - 0 - } else if fp == libcc2rs::cout_unsafe() { - 1 - } else if fp == libcc2rs::cerr_unsafe() { - 2 - } else { - ::std::os::fd::AsRawFd::as_raw_fd(&*fp) - }; + libc::fputs( + (b"hello world\0".as_ptr().cast_mut()).cast_const() as *const i8, + fp, + ); + libc::fflush(fp); + let mut fd: i32 = libc::fileno(fp); let mut st: stat = std::mem::zeroed::(); assert!(((((libc::fstat(fd, (&mut st as *mut stat))) == (0)) as i32) != 0)); assert!(((((st.st_size) == (11_i64)) as i32) != 0)); - assert!( - (((({ - Box::from_raw(fp); - 0 - }) == (0)) as i32) - != 0) - ); + assert!(((((libc::fclose(fp)) == (0)) as i32) != 0)); libc::unlink(path as *const i8); } pub fn main() {