Skip to content

Commit 7e8b369

Browse files
committed
Update tests
1 parent 07b1793 commit 7e8b369

2 files changed

Lines changed: 126 additions & 0 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
extern crate libcc2rs;
2+
use libcc2rs::*;
3+
use std::cell::RefCell;
4+
use std::collections::BTreeMap;
5+
use std::io::prelude::*;
6+
use std::io::{Read, Seek, Write};
7+
use std::os::fd::AsFd;
8+
use std::rc::{Rc, Weak};
9+
#[derive(DeepClone, Record, ByteRepr, VaArg, FnPtrArg)]
10+
#[byte_size(4)]
11+
pub struct F {
12+
#[offset(0)]
13+
pub n: i32,
14+
#[offset(4)]
15+
#[byte_size(0)]
16+
pub tail: Value<Box<[i8]>>,
17+
}
18+
impl Default for F {
19+
fn default() -> Self {
20+
F {
21+
n: 0_i32,
22+
tail: Rc::new(RefCell::new(Box::<[i8]>::default())),
23+
}
24+
}
25+
}
26+
pub fn main() {
27+
__cpp2rust_init_globals();
28+
std::process::exit(main_0());
29+
}
30+
fn main_0() -> i32 {
31+
assert!((((4usize == ::std::mem::size_of::<i32>()) as i32) != 0));
32+
let mut f: Ptr<F> =
33+
libcc2rs::malloc_refcount((4usize as usize).wrapping_add(4_usize)).reinterpret_cast::<F>();
34+
assert!((((!((f).is_null())) as i32) != 0));
35+
field!(f, n).write(4);
36+
{
37+
((array_field_ptr!(f, tail) as Ptr<i8>) as Ptr<i8>)
38+
.to_any()
39+
.memcpy(
40+
&Ptr::<i8>::from_string_literal(b"xyz").to_any(),
41+
4_usize as usize,
42+
);
43+
((array_field_ptr!(f, tail) as Ptr<i8>) as Ptr<i8>).to_any()
44+
};
45+
assert!((((f.with(|__s| __s.n) == 4) as i32) != 0));
46+
assert!(
47+
((({
48+
let mut __it1 = (array_field_ptr!(f, tail) as Ptr<i8>).to_c_string_iterator();
49+
let mut __it2 = Ptr::<i8>::from_string_literal(b"xyz").to_c_string_iterator();
50+
loop {
51+
let __c1 = __it1.next();
52+
let __c2 = __it2.next();
53+
if __c1 != __c2 {
54+
break (__c1.unwrap_or(0) as u8 as i32) - (__c2.unwrap_or(0) as u8 as i32);
55+
}
56+
if __c1.is_none() {
57+
break 0;
58+
}
59+
}
60+
} == 0) as i32)
61+
!= 0)
62+
);
63+
assert!(
64+
(((((elem!((array_field_ptr!(f, tail) as Ptr::<i8>), 1).read()) as i32) == ('y' as i32))
65+
as i32)
66+
!= 0)
67+
);
68+
libcc2rs::free_refcount((f).to_any());
69+
return 0;
70+
}
71+
pub fn __cpp2rust_init_globals() {}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
extern crate libc;
2+
use libc::*;
3+
extern crate libcc2rs;
4+
use libcc2rs::*;
5+
use std::collections::BTreeMap;
6+
use std::io::{Read, Seek, Write};
7+
use std::os::fd::{AsFd, FromRawFd, IntoRawFd};
8+
use std::rc::Rc;
9+
#[repr(C)]
10+
#[derive(Copy, Clone, VaArg, FnPtrArg)]
11+
pub struct F {
12+
pub n: i32,
13+
pub tail: [libc::c_char; 0],
14+
}
15+
impl Default for F {
16+
fn default() -> Self {
17+
F { n: 0_i32, tail: [] }
18+
}
19+
}
20+
pub fn main() {
21+
unsafe {
22+
__cpp2rust_init_globals();
23+
std::process::exit(main_0() as i32);
24+
}
25+
}
26+
unsafe fn main_0() -> i32 {
27+
assert!(((((::std::mem::size_of::<F>()) == (::std::mem::size_of::<i32>())) as i32) != 0));
28+
let mut f: *mut F =
29+
(libcc2rs::malloc_unsafe((::std::mem::size_of::<F>() as usize).wrapping_add(4_usize))
30+
as *mut F);
31+
assert!((((!((f).is_null())) as i32) != 0));
32+
(*f).n = 4;
33+
{
34+
if 4_usize != 0 {
35+
::std::ptr::copy_nonoverlapping(
36+
(c"xyz".as_ptr().cast_mut() as *const ::libc::c_void),
37+
((*f).tail.as_mut_ptr() as *mut ::libc::c_void),
38+
4_usize as usize,
39+
)
40+
}
41+
((*f).tail.as_mut_ptr() as *mut ::libc::c_void)
42+
};
43+
assert!((((((*f).n) == (4)) as i32) != 0));
44+
assert!(
45+
((((libc::strcmp(
46+
((*f).tail.as_mut_ptr()).cast_const(),
47+
(c"xyz".as_ptr().cast_mut()).cast_const()
48+
)) == (0)) as i32)
49+
!= 0)
50+
);
51+
assert!((((((*(*f).tail.as_mut_ptr().add((1) as usize)) as i32) == ('y' as i32)) as i32) != 0));
52+
libcc2rs::free_unsafe((f as *mut ::libc::c_void));
53+
return 0;
54+
}
55+
pub unsafe fn __cpp2rust_init_globals() {}

0 commit comments

Comments
 (0)