Skip to content

Commit 4d8a8a9

Browse files
committed
Update tests
1 parent 18b828e commit 4d8a8a9

2 files changed

Lines changed: 94 additions & 2 deletions

File tree

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

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,85 @@ impl ByteRepr for MyContainer_float_ {
8484
}
8585
}
8686
}
87+
#[derive(Default)]
88+
pub struct Boxed_int_ {
89+
pub value: Value<i32>,
90+
}
91+
impl Boxed_int_ {
92+
pub fn twice(v: i32) -> i32 {
93+
let v: Value<i32> = Rc::new(RefCell::new(v));
94+
return ((*v.borrow()) + (*v.borrow()));
95+
}
96+
}
97+
impl Clone for Boxed_int_ {
98+
fn clone(&self) -> Self {
99+
let __this: Value<Boxed_int_> = Rc::new(RefCell::new(Self {
100+
value: Rc::new(RefCell::new((*self.value.borrow()))),
101+
}));
102+
let this: Ptr<Boxed_int_> = __this.as_pointer();
103+
Rc::try_unwrap(__this).ok().unwrap().into_inner()
104+
}
105+
}
106+
impl ByteRepr for Boxed_int_ {
107+
fn byte_size() -> usize {
108+
4
109+
}
110+
fn to_bytes(&self, buf: &mut [u8]) {
111+
(*self.value.borrow()).to_bytes(&mut buf[0..4]);
112+
}
113+
fn from_bytes(buf: &[u8]) -> Self {
114+
Self {
115+
value: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))),
116+
}
117+
}
118+
}
119+
#[derive(Default)]
120+
pub struct Boxed_long_ {
121+
pub value: Value<i64>,
122+
}
123+
impl Boxed_long_ {
124+
pub fn twice(v: i64) -> i64 {
125+
let v: Value<i64> = Rc::new(RefCell::new(v));
126+
return ((*v.borrow()) + (*v.borrow()));
127+
}
128+
}
129+
impl Clone for Boxed_long_ {
130+
fn clone(&self) -> Self {
131+
let __this: Value<Boxed_long_> = Rc::new(RefCell::new(Self {
132+
value: Rc::new(RefCell::new((*self.value.borrow()))),
133+
}));
134+
let this: Ptr<Boxed_long_> = __this.as_pointer();
135+
Rc::try_unwrap(__this).ok().unwrap().into_inner()
136+
}
137+
}
138+
impl ByteRepr for Boxed_long_ {
139+
fn byte_size() -> usize {
140+
8
141+
}
142+
fn to_bytes(&self, buf: &mut [u8]) {
143+
(*self.value.borrow()).to_bytes(&mut buf[0..8]);
144+
}
145+
fn from_bytes(buf: &[u8]) -> Self {
146+
Self {
147+
value: Rc::new(RefCell::new(<i64>::from_bytes(&buf[0..8]))),
148+
}
149+
}
150+
}
87151
pub fn main() {
88152
__cpp2rust_init_globals();
89153
std::process::exit(main_0());
90154
}
91155
fn main_0() -> i32 {
156+
assert!((({ Boxed_int_::twice(3,) }) == 6));
157+
let bi: Value<Boxed_int_> = Rc::new(RefCell::new(Boxed_int_ {
158+
value: Rc::new(RefCell::new(4)),
159+
}));
160+
assert!((({ Boxed_int_Impl::plus(&bi.as_pointer(), 5,) }) == 9));
161+
assert!((({ Boxed_long_::twice(10_i64,) }) == 20_i64));
162+
let bl: Value<Boxed_long_> = Rc::new(RefCell::new(Boxed_long_ {
163+
value: Rc::new(RefCell::new(7_i64)),
164+
}));
165+
assert!((({ Boxed_long_Impl::plus(&bl.as_pointer(), 1_i64,) }) == 8_i64));
92166
let imc: Value<MyContainer_int_> = Rc::new(RefCell::new(<MyContainer_int_>::default()));
93167
assert!(({ MyContainer_int_Impl::empty(&imc.as_pointer(),) }));
94168
({
@@ -128,6 +202,24 @@ fn main_0() -> i32 {
128202
assert!(({ MyContainer_float_Impl::empty(&fmc.as_pointer(),) }));
129203
return 0;
130204
}
205+
pub trait Boxed_int_Impl {
206+
fn plus(&self, other: i32) -> i32;
207+
}
208+
impl Boxed_int_Impl for Ptr<Boxed_int_> {
209+
fn plus(&self, other: i32) -> i32 {
210+
let other: Value<i32> = Rc::new(RefCell::new(other));
211+
return ((*(*(*self).upgrade().deref()).value.borrow()) + (*other.borrow()));
212+
}
213+
}
214+
pub trait Boxed_long_Impl {
215+
fn plus(&self, other: i64) -> i64;
216+
}
217+
impl Boxed_long_Impl for Ptr<Boxed_long_> {
218+
fn plus(&self, other: i64) -> i64 {
219+
let other: Value<i64> = Rc::new(RefCell::new(other));
220+
return ((*(*(*self).upgrade().deref()).value.borrow()) + (*other.borrow()));
221+
}
222+
}
131223
pub trait MyContainer_char_Impl {
132224
fn empty(&self) -> bool;
133225
fn size(&self) -> usize;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ thread_local!(
8989
);
9090
thread_local!(
9191
pub static str_9: Value<Vec<u8>> = Rc::new(RefCell::new(
92-
Ptr::from_string_literal(b"abc")
92+
Ptr::<u8>::from_string_literal(b"abc")
9393
.to_c_string_iterator()
9494
.chain(std::iter::once(0))
9595
.collect::<Vec<u8>>(),
@@ -177,7 +177,7 @@ fn main_0() -> i32 {
177177
.iter()
178178
.copied()
179179
.take(str_9.with(|rc| rc.borrow().clone()).len().saturating_sub(1))
180-
.eq(Ptr::from_string_literal(b"abc").to_c_string_iterator())
180+
.eq(Ptr::<u8>::from_string_literal(b"abc").to_c_string_iterator())
181181
);
182182
assert!((member_10.with(|rc| *rc.borrow()) == 3));
183183
assert!(((*inline_member_11.with(|rc| rc.borrow().clone()).v.borrow()) == 5));

0 commit comments

Comments
 (0)