Skip to content

Commit 8586ae0

Browse files
committed
Update tests
1 parent aa9721d commit 8586ae0

2 files changed

Lines changed: 226 additions & 0 deletions

File tree

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
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(Default)]
10+
pub struct S {
11+
pub a: Value<i32>,
12+
pub b: Value<i32>,
13+
}
14+
impl Clone for S {
15+
fn clone(&self) -> Self {
16+
let __this: Value<S> = Rc::new(RefCell::new(Self {
17+
a: Rc::new(RefCell::new((*self.a.borrow()))),
18+
b: Rc::new(RefCell::new((*self.b.borrow()))),
19+
}));
20+
let this: Ptr<S> = __this.as_pointer();
21+
Rc::try_unwrap(__this).ok().unwrap().into_inner()
22+
}
23+
}
24+
impl ByteRepr for S {
25+
fn byte_size() -> usize {
26+
8
27+
}
28+
fn to_bytes(&self, buf: &mut [u8]) {
29+
(*self.a.borrow()).to_bytes(&mut buf[0..4]);
30+
(*self.b.borrow()).to_bytes(&mut buf[4..8]);
31+
}
32+
fn from_bytes(buf: &[u8]) -> Self {
33+
Self {
34+
a: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))),
35+
b: Rc::new(RefCell::new(<i32>::from_bytes(&buf[4..8]))),
36+
}
37+
}
38+
}
39+
pub fn main() {
40+
__cpp2rust_init_globals();
41+
std::process::exit(main_0());
42+
}
43+
fn main_0() -> i32 {
44+
let s1: Value<S> = Rc::new(RefCell::new(S {
45+
a: Rc::new(RefCell::new(1)),
46+
b: Rc::new(RefCell::new(2)),
47+
}));
48+
let s2: Value<S> = Rc::new(RefCell::new(S {
49+
a: Rc::new(RefCell::new(1)),
50+
b: Rc::new(RefCell::new(2)),
51+
}));
52+
let s3: Value<S> = Rc::new(RefCell::new(S {
53+
a: Rc::new(RefCell::new(1)),
54+
b: Rc::new(RefCell::new(3)),
55+
}));
56+
assert!(
57+
({
58+
let _x: Ptr<S> = s1.as_pointer();
59+
operator_eq_0(_x, s2.as_pointer())
60+
})
61+
);
62+
assert!(
63+
({
64+
let _x: Ptr<S> = s1.as_pointer();
65+
operator_ne_1(_x, s3.as_pointer())
66+
})
67+
);
68+
assert!(
69+
!({
70+
let _x: Ptr<S> = s1.as_pointer();
71+
operator_eq_0(_x, s3.as_pointer())
72+
})
73+
);
74+
assert!(
75+
({
76+
let _x: Ptr<S> = s1.as_pointer();
77+
operator_lt_2(_x, s3.as_pointer())
78+
})
79+
);
80+
assert!(
81+
!({
82+
let _x: Ptr<S> = s3.as_pointer();
83+
operator_lt_2(_x, s1.as_pointer())
84+
})
85+
);
86+
assert!((({ compare_3(s1.as_pointer(), s3.as_pointer(),) }) == -1_i32));
87+
assert!((({ compare_3(s3.as_pointer(), s1.as_pointer(),) }) == 1));
88+
assert!((({ compare_3(s1.as_pointer(), s2.as_pointer(),) }) == 0));
89+
return 0;
90+
}
91+
pub fn operator_eq_0(x: Ptr<S>, y: Ptr<S>) -> bool {
92+
return ({
93+
let _lhs = (*(*x.upgrade().deref()).a.borrow());
94+
_lhs == (*(*y.upgrade().deref()).a.borrow())
95+
}) && ({
96+
let _lhs = (*(*x.upgrade().deref()).b.borrow());
97+
_lhs == (*(*y.upgrade().deref()).b.borrow())
98+
});
99+
}
100+
pub fn operator_ne_1(x: Ptr<S>, y: Ptr<S>) -> bool {
101+
return !({
102+
let _x: Ptr<S> = (x).clone();
103+
let _y: Ptr<S> = (y).clone();
104+
operator_eq_0(_x, _y)
105+
});
106+
}
107+
pub fn operator_lt_2(x: Ptr<S>, y: Ptr<S>) -> bool {
108+
return ({
109+
let _lhs = (*(*x.upgrade().deref()).a.borrow());
110+
_lhs < (*(*y.upgrade().deref()).a.borrow())
111+
}) || (({
112+
let _lhs = (*(*x.upgrade().deref()).a.borrow());
113+
_lhs == (*(*y.upgrade().deref()).a.borrow())
114+
}) && ({
115+
let _lhs = (*(*x.upgrade().deref()).b.borrow());
116+
_lhs < (*(*y.upgrade().deref()).b.borrow())
117+
}));
118+
}
119+
pub fn compare_3(x: Ptr<S>, y: Ptr<S>) -> i32 {
120+
if ({
121+
let _x: Ptr<S> = (x).clone();
122+
let _y: Ptr<S> = (y).clone();
123+
operator_lt_2(_x, _y)
124+
}) {
125+
return -1_i32;
126+
}
127+
if ({
128+
let _x: Ptr<S> = (y).clone();
129+
let _y: Ptr<S> = (x).clone();
130+
operator_lt_2(_x, _y)
131+
}) {
132+
return 1;
133+
}
134+
return 0;
135+
}
136+
pub fn __cpp2rust_init_globals() {}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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, Default)]
11+
pub struct S {
12+
pub a: i32,
13+
pub b: i32,
14+
}
15+
pub fn main() {
16+
unsafe {
17+
__cpp2rust_init_globals();
18+
std::process::exit(main_0() as i32);
19+
}
20+
}
21+
unsafe fn main_0() -> i32 {
22+
let mut s1: S = S { a: 1, b: 2 };
23+
let mut s2: S = S { a: 1, b: 2 };
24+
let mut s3: S = S { a: 1, b: 3 };
25+
assert!(
26+
(unsafe {
27+
let _x: *const S = &s1;
28+
operator_eq_0(_x, &s2)
29+
})
30+
);
31+
assert!(
32+
(unsafe {
33+
let _x: *const S = &s1;
34+
operator_ne_1(_x, &s3)
35+
})
36+
);
37+
assert!(
38+
!(unsafe {
39+
let _x: *const S = &s1;
40+
operator_eq_0(_x, &s3)
41+
})
42+
);
43+
assert!(
44+
(unsafe {
45+
let _x: *const S = &s1;
46+
operator_lt_2(_x, &s3)
47+
})
48+
);
49+
assert!(
50+
!(unsafe {
51+
let _x: *const S = &s3;
52+
operator_lt_2(_x, &s1)
53+
})
54+
);
55+
assert!(((unsafe { compare_3(&s1, &s3,) }) == (-1_i32)));
56+
assert!(((unsafe { compare_3(&s3, &s1,) }) == (1)));
57+
assert!(((unsafe { compare_3(&s1, &s2,) }) == (0)));
58+
return 0;
59+
}
60+
pub unsafe fn operator_eq_0(x: *const S, y: *const S) -> bool {
61+
return (((*x).a) == ((*y).a)) && (((*x).b) == ((*y).b));
62+
}
63+
pub unsafe fn operator_ne_1(x: *const S, y: *const S) -> bool {
64+
return !(unsafe {
65+
let _x: *const S = x;
66+
let _y: *const S = y;
67+
operator_eq_0(_x, _y)
68+
});
69+
}
70+
pub unsafe fn operator_lt_2(x: *const S, y: *const S) -> bool {
71+
return (((*x).a) < ((*y).a)) || ((((*x).a) == ((*y).a)) && (((*x).b) < ((*y).b)));
72+
}
73+
pub unsafe fn compare_3(x: *const S, y: *const S) -> i32 {
74+
if (unsafe {
75+
let _x: *const S = x;
76+
let _y: *const S = y;
77+
operator_lt_2(_x, _y)
78+
}) {
79+
return -1_i32;
80+
}
81+
if (unsafe {
82+
let _x: *const S = y;
83+
let _y: *const S = x;
84+
operator_lt_2(_x, _y)
85+
}) {
86+
return 1;
87+
}
88+
return 0;
89+
}
90+
pub unsafe fn __cpp2rust_init_globals() {}

0 commit comments

Comments
 (0)