Skip to content

Commit 2a8d6a1

Browse files
committed
Update tests
1 parent cf12479 commit 2a8d6a1

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

‎tests/unit/out/refcount/init_list.rs‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,31 @@ use std::rc::{Rc, Weak};
99
pub fn f_0(list: Vec<i32>) {
1010
let list: Value<Vec<i32>> = Rc::new(RefCell::new(list));
1111
}
12+
#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)]
13+
#[byte_size(8)]
14+
pub struct Pair {
15+
#[offset(0)]
16+
pub a: i32,
17+
#[offset(4)]
18+
pub b: i32,
19+
}
20+
#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)]
21+
#[byte_size(8)]
22+
pub struct Holder {
23+
#[offset(0)]
24+
#[byte_size(8)]
25+
pub p: Pair,
26+
}
27+
impl Default for Holder {
28+
fn default() -> Self {
29+
Holder {
30+
p: Pair { a: 0, b: 0 },
31+
}
32+
}
33+
}
34+
pub fn sum_1(p: Ptr<Pair>) -> i32 {
35+
return ({ p.with(|__s| __s.a) } + { p.with(|__s| __s.b) });
36+
}
1237
pub fn main() {
1338
__cpp2rust_init_globals();
1439
std::process::exit(main_0());
@@ -21,6 +46,20 @@ fn main_0() -> i32 {
2146
let arr: Value<Vec<i32>> = Rc::new(RefCell::new(vec![1, 2, 3]));
2247
let mut vec_: Vec<i32> = vec![1, 2, 3];
2348
({ f_0(vec![1, 2, 3, 4]) });
49+
let p: Value<Pair> = Rc::new(RefCell::new(Pair { a: 1, b: 2 }));
50+
let h: Value<Holder> = Rc::new(RefCell::new(<Holder>::default()));
51+
({ HolderImpl::operator_assign_1(&h.as_pointer(), p.as_pointer()) });
52+
assert!(({ (*h.borrow()).p.a } == 1) && ({ (*h.borrow()).p.b } == 2));
53+
assert!((({ sum_1(p.as_pointer(),) }) == 3));
2454
return 0;
2555
}
56+
pub trait HolderImpl {
57+
fn operator_assign_1(&self, o: Ptr<Pair>) -> Ptr<Holder>;
58+
}
59+
impl HolderImpl for Ptr<Holder> {
60+
fn operator_assign_1(&self, o: Ptr<Pair>) -> Ptr<Holder> {
61+
field!((*self), p).write({ (*o.upgrade().deref()).clone() });
62+
return (*self).clone();
63+
}
64+
}
2665
pub fn __cpp2rust_init_globals() {}

‎tests/unit/out/unsafe/init_list.rs‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,33 @@ use std::io::{Read, Seek, Write};
77
use std::os::fd::{AsFd, FromRawFd, IntoRawFd};
88
use std::rc::Rc;
99
pub unsafe fn f_0(mut list: Vec<i32>) {}
10+
#[repr(C)]
11+
#[derive(Copy, Clone, VaArg, FnPtrArg, Default)]
12+
pub struct Pair {
13+
pub a: i32,
14+
pub b: i32,
15+
}
16+
#[repr(C)]
17+
#[derive(Copy, Clone, VaArg, FnPtrArg)]
18+
pub struct Holder {
19+
pub p: Pair,
20+
}
21+
impl Holder {
22+
pub unsafe fn operator_assign_1(&mut self, o: *mut Pair) -> *mut Holder {
23+
self.p = (*o);
24+
return &mut (*(self as *mut Holder));
25+
}
26+
}
27+
impl Default for Holder {
28+
fn default() -> Self {
29+
Holder {
30+
p: Pair { a: 0, b: 0 },
31+
}
32+
}
33+
}
34+
pub unsafe fn sum_1(p: *const Pair) -> i32 {
35+
return (((*p).a) + ((*p).b));
36+
}
1037
pub fn main() {
1138
unsafe {
1239
__cpp2rust_init_globals();
@@ -21,6 +48,11 @@ unsafe fn main_0() -> i32 {
2148
let mut arr: Vec<i32> = vec![1, 2, 3];
2249
let mut vec_: Vec<i32> = vec![1, 2, 3];
2350
(unsafe { f_0(vec![1, 2, 3, 4]) });
51+
let mut p: Pair = Pair { a: 1, b: 2 };
52+
let mut h: Holder = <Holder>::default();
53+
(unsafe { Holder::operator_assign_1(&mut h, &mut p) });
54+
assert!(((h.p.a) == (1)) && ((h.p.b) == (2)));
55+
assert!(((unsafe { sum_1(&p,) }) == (3)));
2456
return 0;
2557
}
2658
pub unsafe fn __cpp2rust_init_globals() {}

0 commit comments

Comments
 (0)