Skip to content

Commit 4b5bab8

Browse files
committed
Update tests
1 parent eec1a00 commit 4b5bab8

17 files changed

Lines changed: 335 additions & 244 deletions
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <assert.h>
2+
3+
template <typename T> int get(T t) { return t.x; }
4+
5+
namespace ns {
6+
template <typename T> int twice(T t) { return t.x * 2; }
7+
}
8+
9+
int main() {
10+
struct Local {
11+
int x;
12+
};
13+
Local l{7};
14+
assert(get(l) == 7);
15+
assert(ns::twice(l) == 14);
16+
return 0;
17+
}

‎tests/unit/out/refcount/anonymous-struct.rs‎

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -321,36 +321,6 @@ fn main_0() -> i32 {
321321
.borrow())
322322
== 11)
323323
);
324-
#[derive(Default)]
325-
pub struct anon_6 {
326-
pub x: Value<i32>,
327-
pub z: Value<i32>,
328-
}
329-
impl Clone for anon_6 {
330-
fn clone(&self) -> Self {
331-
let __this: Value<anon_6> = Rc::new(RefCell::new(Self {
332-
x: Rc::new(RefCell::new((*self.x.borrow()))),
333-
z: Rc::new(RefCell::new((*self.z.borrow()))),
334-
}));
335-
let this: Ptr<anon_6> = __this.as_pointer();
336-
Rc::try_unwrap(__this).ok().unwrap().into_inner()
337-
}
338-
}
339-
impl ByteRepr for anon_6 {
340-
fn byte_size() -> usize {
341-
8
342-
}
343-
fn to_bytes(&self, buf: &mut [u8]) {
344-
(*self.x.borrow()).to_bytes(&mut buf[0..4]);
345-
(*self.z.borrow()).to_bytes(&mut buf[4..8]);
346-
}
347-
fn from_bytes(buf: &[u8]) -> Self {
348-
Self {
349-
x: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))),
350-
z: Rc::new(RefCell::new(<i32>::from_bytes(&buf[4..8]))),
351-
}
352-
}
353-
};
354324
let s: Value<anon_6> = Rc::new(RefCell::new(<anon_6>::default()));
355325
(*(*s.borrow()).x.borrow_mut()) = 1;
356326
(*(*s.borrow()).z.borrow_mut()) = 2;
@@ -368,3 +338,33 @@ fn main_0() -> i32 {
368338
);
369339
return 0;
370340
}
341+
#[derive(Default)]
342+
pub struct anon_6 {
343+
pub x: Value<i32>,
344+
pub z: Value<i32>,
345+
}
346+
impl Clone for anon_6 {
347+
fn clone(&self) -> Self {
348+
let __this: Value<anon_6> = Rc::new(RefCell::new(Self {
349+
x: Rc::new(RefCell::new((*self.x.borrow()))),
350+
z: Rc::new(RefCell::new((*self.z.borrow()))),
351+
}));
352+
let this: Ptr<anon_6> = __this.as_pointer();
353+
Rc::try_unwrap(__this).ok().unwrap().into_inner()
354+
}
355+
}
356+
impl ByteRepr for anon_6 {
357+
fn byte_size() -> usize {
358+
8
359+
}
360+
fn to_bytes(&self, buf: &mut [u8]) {
361+
(*self.x.borrow()).to_bytes(&mut buf[0..4]);
362+
(*self.z.borrow()).to_bytes(&mut buf[4..8]);
363+
}
364+
fn from_bytes(buf: &[u8]) -> Self {
365+
Self {
366+
x: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))),
367+
z: Rc::new(RefCell::new(<i32>::from_bytes(&buf[4..8]))),
368+
}
369+
}
370+
}

‎tests/unit/out/refcount/anonymous-struct_c.rs‎

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -290,34 +290,6 @@ fn main_0() -> i32 {
290290
== 11) as i32)
291291
!= 0)
292292
);
293-
#[derive(Default)]
294-
pub struct anon_6 {
295-
pub x: Value<i32>,
296-
pub z: Value<i32>,
297-
}
298-
impl Clone for anon_6 {
299-
fn clone(&self) -> Self {
300-
Self {
301-
x: Rc::new(RefCell::new((*self.x.borrow()).clone())),
302-
z: Rc::new(RefCell::new((*self.z.borrow()).clone())),
303-
}
304-
}
305-
}
306-
impl ByteRepr for anon_6 {
307-
fn byte_size() -> usize {
308-
8
309-
}
310-
fn to_bytes(&self, buf: &mut [u8]) {
311-
(*self.x.borrow()).to_bytes(&mut buf[0..4]);
312-
(*self.z.borrow()).to_bytes(&mut buf[4..8]);
313-
}
314-
fn from_bytes(buf: &[u8]) -> Self {
315-
Self {
316-
x: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))),
317-
z: Rc::new(RefCell::new(<i32>::from_bytes(&buf[4..8]))),
318-
}
319-
}
320-
};
321293
let s: Value<anon_6> = <Value<anon_6>>::default();
322294
(*(*s.borrow()).x.borrow_mut()) = 1;
323295
(*(*s.borrow()).z.borrow_mut()) = 2;
@@ -335,3 +307,31 @@ fn main_0() -> i32 {
335307
);
336308
return 0;
337309
}
310+
#[derive(Default)]
311+
pub struct anon_6 {
312+
pub x: Value<i32>,
313+
pub z: Value<i32>,
314+
}
315+
impl Clone for anon_6 {
316+
fn clone(&self) -> Self {
317+
Self {
318+
x: Rc::new(RefCell::new((*self.x.borrow()).clone())),
319+
z: Rc::new(RefCell::new((*self.z.borrow()).clone())),
320+
}
321+
}
322+
}
323+
impl ByteRepr for anon_6 {
324+
fn byte_size() -> usize {
325+
8
326+
}
327+
fn to_bytes(&self, buf: &mut [u8]) {
328+
(*self.x.borrow()).to_bytes(&mut buf[0..4]);
329+
(*self.z.borrow()).to_bytes(&mut buf[4..8]);
330+
}
331+
fn from_bytes(buf: &[u8]) -> Self {
332+
Self {
333+
x: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))),
334+
z: Rc::new(RefCell::new(<i32>::from_bytes(&buf[4..8]))),
335+
}
336+
}
337+
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ pub fn main() {
7878
std::process::exit(main_0());
7979
}
8080
fn main_0() -> i32 {
81-
pub type anon_3 = u32;
82-
pub const anon_3_THIRD_A: anon_3 = 0;
83-
pub const anon_3_THIRD_B: anon_3 = 1;;
8481
assert!(((anon_0_FIRST_A as i32) != (anon_0_FIRST_B as i32)));
8582
assert!(((anon_1_SECOND_A as i32) != (anon_1_SECOND_B as i32)));
8683
assert!(((anon_3_THIRD_A as i32) != (anon_3_THIRD_B as i32)));
@@ -95,3 +92,6 @@ fn main_0() -> i32 {
9592
assert!((((*(*w.borrow()).field.borrow()) as i32) == (anon_2_FIELD_B as i32)));
9693
return 0;
9794
}
95+
pub type anon_3 = u32;
96+
pub const anon_3_THIRD_A: anon_3 = 0;
97+
pub const anon_3_THIRD_B: anon_3 = 1;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@ pub fn main() {
7474
std::process::exit(main_0());
7575
}
7676
fn main_0() -> i32 {
77-
pub type anon_3 = u32;
78-
pub const anon_3_THIRD_A: anon_3 = 0;
79-
pub const anon_3_THIRD_B: anon_3 = 1;;
8077
assert!(((((anon_0_FIRST_A as i32) != (anon_0_FIRST_B as i32)) as i32) != 0));
8178
assert!(((((anon_1_SECOND_A as i32) != (anon_1_SECOND_B as i32)) as i32) != 0));
8279
assert!(((((anon_3_THIRD_A as i32) != (anon_3_THIRD_B as i32)) as i32) != 0));
@@ -97,3 +94,6 @@ fn main_0() -> i32 {
9794
);
9895
return 0;
9996
}
97+
pub type anon_3 = u32;
98+
pub const anon_3_THIRD_A: anon_3 = 0;
99+
pub const anon_3_THIRD_B: anon_3 = 1;

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

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -7,73 +7,73 @@ use std::io::{Read, Seek, Write};
77
use std::os::fd::AsFd;
88
use std::rc::{Rc, Weak};
99
pub fn first_0() -> i32 {
10-
#[derive(Default)]
11-
pub struct anon_1 {
12-
pub x: Value<i32>,
13-
pub y: Value<i32>,
14-
}
15-
impl Clone for anon_1 {
16-
fn clone(&self) -> Self {
17-
Self {
18-
x: Rc::new(RefCell::new((*self.x.borrow()).clone())),
19-
y: Rc::new(RefCell::new((*self.y.borrow()).clone())),
20-
}
21-
}
22-
}
23-
impl ByteRepr for anon_1 {
24-
fn byte_size() -> usize {
25-
8
26-
}
27-
fn to_bytes(&self, buf: &mut [u8]) {
28-
(*self.x.borrow()).to_bytes(&mut buf[0..4]);
29-
(*self.y.borrow()).to_bytes(&mut buf[4..8]);
30-
}
31-
fn from_bytes(buf: &[u8]) -> Self {
32-
Self {
33-
x: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))),
34-
y: Rc::new(RefCell::new(<i32>::from_bytes(&buf[4..8]))),
35-
}
36-
}
37-
};
3810
let p: Value<anon_1> = <Value<anon_1>>::default();
3911
(*(*p.borrow()).x.borrow_mut()) = 1;
4012
(*(*p.borrow()).y.borrow_mut()) = 2;
4113
return ((*(*p.borrow()).x.borrow()) + (*(*p.borrow()).y.borrow()));
4214
}
43-
pub fn second_2() -> i32 {
44-
#[derive(Default)]
45-
pub struct anon_3 {
46-
pub a: Value<i64>,
47-
pub b: Value<i64>,
48-
}
49-
impl Clone for anon_3 {
50-
fn clone(&self) -> Self {
51-
Self {
52-
a: Rc::new(RefCell::new((*self.a.borrow()).clone())),
53-
b: Rc::new(RefCell::new((*self.b.borrow()).clone())),
54-
}
15+
#[derive(Default)]
16+
pub struct anon_1 {
17+
pub x: Value<i32>,
18+
pub y: Value<i32>,
19+
}
20+
impl Clone for anon_1 {
21+
fn clone(&self) -> Self {
22+
Self {
23+
x: Rc::new(RefCell::new((*self.x.borrow()).clone())),
24+
y: Rc::new(RefCell::new((*self.y.borrow()).clone())),
5525
}
5626
}
57-
impl ByteRepr for anon_3 {
58-
fn byte_size() -> usize {
59-
16
60-
}
61-
fn to_bytes(&self, buf: &mut [u8]) {
62-
(*self.a.borrow()).to_bytes(&mut buf[0..8]);
63-
(*self.b.borrow()).to_bytes(&mut buf[8..16]);
64-
}
65-
fn from_bytes(buf: &[u8]) -> Self {
66-
Self {
67-
a: Rc::new(RefCell::new(<i64>::from_bytes(&buf[0..8]))),
68-
b: Rc::new(RefCell::new(<i64>::from_bytes(&buf[8..16]))),
69-
}
27+
}
28+
impl ByteRepr for anon_1 {
29+
fn byte_size() -> usize {
30+
8
31+
}
32+
fn to_bytes(&self, buf: &mut [u8]) {
33+
(*self.x.borrow()).to_bytes(&mut buf[0..4]);
34+
(*self.y.borrow()).to_bytes(&mut buf[4..8]);
35+
}
36+
fn from_bytes(buf: &[u8]) -> Self {
37+
Self {
38+
x: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))),
39+
y: Rc::new(RefCell::new(<i32>::from_bytes(&buf[4..8]))),
7040
}
71-
};
41+
}
42+
}
43+
pub fn second_2() -> i32 {
7244
let q: Value<anon_3> = <Value<anon_3>>::default();
7345
(*(*q.borrow()).a.borrow_mut()) = 10_i64;
7446
(*(*q.borrow()).b.borrow_mut()) = 20_i64;
7547
return (((*(*q.borrow()).a.borrow()) + (*(*q.borrow()).b.borrow())) as i32);
7648
}
49+
#[derive(Default)]
50+
pub struct anon_3 {
51+
pub a: Value<i64>,
52+
pub b: Value<i64>,
53+
}
54+
impl Clone for anon_3 {
55+
fn clone(&self) -> Self {
56+
Self {
57+
a: Rc::new(RefCell::new((*self.a.borrow()).clone())),
58+
b: Rc::new(RefCell::new((*self.b.borrow()).clone())),
59+
}
60+
}
61+
}
62+
impl ByteRepr for anon_3 {
63+
fn byte_size() -> usize {
64+
16
65+
}
66+
fn to_bytes(&self, buf: &mut [u8]) {
67+
(*self.a.borrow()).to_bytes(&mut buf[0..8]);
68+
(*self.b.borrow()).to_bytes(&mut buf[8..16]);
69+
}
70+
fn from_bytes(buf: &[u8]) -> Self {
71+
Self {
72+
a: Rc::new(RefCell::new(<i64>::from_bytes(&buf[0..8]))),
73+
b: Rc::new(RefCell::new(<i64>::from_bytes(&buf[8..16]))),
74+
}
75+
}
76+
}
7777
pub fn main() {
7878
std::process::exit(main_0());
7979
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
pub fn get_0(t: Local) -> i32 {
10+
let t: Value<Local> = Rc::new(RefCell::new(t));
11+
return (*(*t.borrow()).x.borrow());
12+
}
13+
pub fn main() {
14+
std::process::exit(main_0());
15+
}
16+
fn main_0() -> i32 {
17+
let l: Value<Local> = Rc::new(RefCell::new(Local {
18+
x: Rc::new(RefCell::new(7)),
19+
}));
20+
assert!((({ get_0((*l.borrow()).clone(),) }) == 7));
21+
return 0;
22+
}
23+
#[derive(Default)]
24+
pub struct Local {
25+
pub x: Value<i32>,
26+
}
27+
impl Clone for Local {
28+
fn clone(&self) -> Self {
29+
let __this: Value<Local> = Rc::new(RefCell::new(Self {
30+
x: Rc::new(RefCell::new((*self.x.borrow()))),
31+
}));
32+
let this: Ptr<Local> = __this.as_pointer();
33+
Rc::try_unwrap(__this).ok().unwrap().into_inner()
34+
}
35+
}
36+
impl ByteRepr for Local {
37+
fn byte_size() -> usize {
38+
4
39+
}
40+
fn to_bytes(&self, buf: &mut [u8]) {
41+
(*self.x.borrow()).to_bytes(&mut buf[0..4]);
42+
}
43+
fn from_bytes(buf: &[u8]) -> Self {
44+
Self {
45+
x: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))),
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)