Skip to content

Commit 0469990

Browse files
committed
Update tests
1 parent 1f254c6 commit 0469990

28 files changed

Lines changed: 304 additions & 180 deletions
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
project(template_method_late_instantiation LANGUAGES CXX)
3+
add_executable(app a.cpp b.cpp)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <assert.h>
2+
3+
#include "s.h"
4+
5+
int main() {
6+
S<int> p;
7+
p.set(3);
8+
assert(f(&p) == 3);
9+
return 0;
10+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "s.h"
2+
3+
int f(S<int> *p) { return p->get(); }
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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_int_ {
11+
pub x: Value<i32>,
12+
}
13+
impl Clone for S_int_ {
14+
fn clone(&self) -> Self {
15+
let __this: Value<S_int_> = Rc::new(RefCell::new(Self {
16+
x: Rc::new(RefCell::new((*self.x.borrow()))),
17+
}));
18+
let this: Ptr<S_int_> = __this.as_pointer();
19+
Rc::try_unwrap(__this).ok().unwrap().into_inner()
20+
}
21+
}
22+
impl ByteRepr for S_int_ {
23+
fn byte_size() -> usize {
24+
4
25+
}
26+
fn to_bytes(&self, buf: &mut [u8]) {
27+
(*self.x.borrow()).to_bytes(&mut buf[0..4]);
28+
}
29+
fn from_bytes(buf: &[u8]) -> Self {
30+
Self {
31+
x: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))),
32+
}
33+
}
34+
}
35+
pub fn main() {
36+
std::process::exit(main_0());
37+
}
38+
fn main_0() -> i32 {
39+
let p: Value<S_int_> = Rc::new(RefCell::new(<S_int_>::default()));
40+
({ S_int_Impl::set(&p.as_pointer(), 3) });
41+
assert!((({ f_0((p.as_pointer()),) }) == 3));
42+
return 0;
43+
}
44+
pub fn f_0(p: Ptr<S_int_>) -> i32 {
45+
let p: Value<Ptr<S_int_>> = Rc::new(RefCell::new(p));
46+
return ({ S_int_Impl::get(&(*p.borrow())) });
47+
}
48+
impl S_int_Impl for Ptr<S_int_> {
49+
fn set(&self, v: i32) {
50+
let v: Value<i32> = Rc::new(RefCell::new(v));
51+
(*(*(*self).upgrade().deref()).x.borrow_mut()) = (*v.borrow());
52+
}
53+
fn get(&self) -> i32 {
54+
return (*(*(*self).upgrade().deref()).x.borrow());
55+
}
56+
}
57+
pub trait S_int_Impl {
58+
fn set(&self, v: i32);
59+
fn get(&self) -> i32;
60+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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_int_ {
12+
pub x: i32,
13+
}
14+
impl S_int_ {
15+
pub unsafe fn set(&mut self, mut v: i32) {
16+
self.x = v;
17+
}
18+
}
19+
pub fn main() {
20+
unsafe {
21+
std::process::exit(main_0() as i32);
22+
}
23+
}
24+
unsafe fn main_0() -> i32 {
25+
let mut p: S_int_ = <S_int_>::default();
26+
(unsafe { S_int_::set(&mut p, 3) });
27+
assert!(((unsafe { f_0((&mut p as *mut S_int_),) }) == (3)));
28+
return 0;
29+
}
30+
impl S_int_ {
31+
pub unsafe fn get(&mut self) -> i32 {
32+
return self.x;
33+
}
34+
}
35+
pub unsafe fn f_0(mut p: *mut S_int_) -> i32 {
36+
return (unsafe { S_int_::get(&mut (*p)) });
37+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
3+
template <typename T>
4+
struct S {
5+
T x = 0;
6+
7+
void set(T v) { x = v; }
8+
T get() { return x; }
9+
};
10+
11+
int f(S<int> *p);

‎tests/unit/out/refcount/10_struct.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ pub struct Graph {
4141
pub V: Value<u32>,
4242
pub adj: Value<Ptr<Ptr<GraphNode>>>,
4343
}
44-
pub trait GraphImpl {
45-
fn push(&self, src: u32, dst: u32);
46-
}
4744
impl Clone for Graph {
4845
fn clone(&self) -> Self {
4946
let __this: Value<Graph> = Rc::new(RefCell::new(Self {
@@ -109,3 +106,6 @@ impl GraphImpl for Ptr<Graph> {
109106
.write(__rhs);
110107
}
111108
}
109+
pub trait GraphImpl {
110+
fn push(&self, src: u32, dst: u32);
111+
}

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,6 @@ pub struct Pair {
1111
pub first: Value<i32>,
1212
pub second: Value<i32>,
1313
}
14-
pub trait PairImpl {
15-
fn NOP(&self);
16-
fn GetFirst(&self) -> i32;
17-
fn GetSecond(&self) -> i32;
18-
fn Set(&self, field: Ptr<i32>, new_val: i32) -> i32;
19-
fn SetFirst(&self, new_first: i32) -> i32;
20-
fn SetSecond(&self, new_second: i32) -> i32;
21-
}
2214
impl Clone for Pair {
2315
fn clone(&self) -> Self {
2416
let __this: Value<Pair> = Rc::new(RefCell::new(Self {
@@ -49,9 +41,6 @@ pub struct Route {
4941
pub path: Value<Pair>,
5042
pub cost: Value<f64>,
5143
}
52-
pub trait RouteImpl {
53-
fn SetCost(&self, new_cost: f64) -> f64;
54-
}
5544
impl Clone for Route {
5645
fn clone(&self) -> Self {
5746
let __this: Value<Route> = Rc::new(RefCell::new(Self {
@@ -169,3 +158,14 @@ impl RouteImpl for Ptr<Route> {
169158
return (*old_cost.borrow());
170159
}
171160
}
161+
pub trait PairImpl {
162+
fn NOP(&self);
163+
fn GetFirst(&self) -> i32;
164+
fn GetSecond(&self) -> i32;
165+
fn Set(&self, field: Ptr<i32>, new_val: i32) -> i32;
166+
fn SetFirst(&self, new_first: i32) -> i32;
167+
fn SetSecond(&self, new_second: i32) -> i32;
168+
}
169+
pub trait RouteImpl {
170+
fn SetCost(&self, new_cost: f64) -> f64;
171+
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ impl ByteRepr for Point {
3636
pub struct Box_int_ {
3737
pub val: Value<i32>,
3838
}
39-
pub trait Box_int_Impl {
40-
fn twice(&self) -> i32;
41-
}
4239
impl Clone for Box_int_ {
4340
fn clone(&self) -> Self {
4441
let __this: Value<Box_int_> = Rc::new(RefCell::new(Self {
@@ -65,9 +62,6 @@ impl ByteRepr for Box_int_ {
6562
pub struct Box_Point_ {
6663
pub val: Value<Point>,
6764
}
68-
pub trait Box_Point_Impl {
69-
fn get(&self) -> Point;
70-
}
7165
impl Clone for Box_Point_ {
7266
fn clone(&self) -> Self {
7367
let __this: Value<Box_Point_> = Rc::new(RefCell::new(Self {
@@ -117,3 +111,9 @@ impl Box_int_Impl for Ptr<Box_int_> {
117111
+ (*(*(*self).upgrade().deref()).val.borrow()));
118112
}
119113
}
114+
pub trait Box_Point_Impl {
115+
fn get(&self) -> Point;
116+
}
117+
pub trait Box_int_Impl {
118+
fn twice(&self) -> i32;
119+
}

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

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,6 @@ use std::rc::{Rc, Weak};
1010
pub struct MyContainer_int_ {
1111
vec_: Value<Vec<i32>>,
1212
}
13-
pub trait MyContainer_int_Impl {
14-
fn empty(&self) -> bool;
15-
fn size(&self) -> usize;
16-
fn back(&self) -> Ptr<i32>;
17-
fn pop_back(&self);
18-
fn push_back(&self, item: Ptr<i32>);
19-
}
2013
impl Clone for MyContainer_int_ {
2114
fn clone(&self) -> Self {
2215
let __this: Value<MyContainer_int_> = Rc::new(RefCell::new(Self {
@@ -43,13 +36,6 @@ impl ByteRepr for MyContainer_int_ {
4336
pub struct MyContainer_char_ {
4437
vec_: Value<Vec<u8>>,
4538
}
46-
pub trait MyContainer_char_Impl {
47-
fn empty(&self) -> bool;
48-
fn size(&self) -> usize;
49-
fn back(&self) -> Ptr<u8>;
50-
fn pop_back(&self);
51-
fn push_back(&self, item: Ptr<u8>);
52-
}
5339
impl Clone for MyContainer_char_ {
5440
fn clone(&self) -> Self {
5541
let __this: Value<MyContainer_char_> = Rc::new(RefCell::new(Self {
@@ -76,13 +62,6 @@ impl ByteRepr for MyContainer_char_ {
7662
pub struct MyContainer_float_ {
7763
vec_: Value<Vec<f32>>,
7864
}
79-
pub trait MyContainer_float_Impl {
80-
fn empty(&self) -> bool;
81-
fn size(&self) -> usize;
82-
fn back(&self) -> Ptr<f32>;
83-
fn pop_back(&self);
84-
fn push_back(&self, item: Ptr<f32>);
85-
}
8665
impl Clone for MyContainer_float_ {
8766
fn clone(&self) -> Self {
8867
let __this: Value<MyContainer_float_> = Rc::new(RefCell::new(Self {
@@ -211,3 +190,24 @@ impl MyContainer_int_Impl for Ptr<MyContainer_int_> {
211190
};
212191
}
213192
}
193+
pub trait MyContainer_char_Impl {
194+
fn empty(&self) -> bool;
195+
fn size(&self) -> usize;
196+
fn back(&self) -> Ptr<u8>;
197+
fn pop_back(&self);
198+
fn push_back(&self, item: Ptr<u8>);
199+
}
200+
pub trait MyContainer_float_Impl {
201+
fn empty(&self) -> bool;
202+
fn size(&self) -> usize;
203+
fn back(&self) -> Ptr<f32>;
204+
fn pop_back(&self);
205+
fn push_back(&self, item: Ptr<f32>);
206+
}
207+
pub trait MyContainer_int_Impl {
208+
fn empty(&self) -> bool;
209+
fn size(&self) -> usize;
210+
fn back(&self) -> Ptr<i32>;
211+
fn pop_back(&self);
212+
fn push_back(&self, item: Ptr<i32>);
213+
}

0 commit comments

Comments
 (0)