]>
Commit | Line | Data |
---|---|---|
1a4d82fc | 1 | // Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT |
970d7e83 LB |
2 | // file at the top-level directory of this distribution and at |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
8 | // option. This file may not be copied, modified, or distributed | |
9 | // except according to those terms. | |
10 | ||
11 | // This actually tests a lot more than just encodable/decodable, but it gets the | |
12 | // job done at least | |
13 | ||
1a4d82fc | 14 | // ignore-test FIXME(#5121) |
970d7e83 | 15 | |
1a4d82fc JJ |
16 | extern crate rand; |
17 | extern crate rbml; | |
18 | extern crate serialize; | |
970d7e83 | 19 | |
1a4d82fc JJ |
20 | use rand::{random, Rand}; |
21 | use rbml; | |
22 | use rbml::Doc; | |
23 | use rbml::writer::Encoder; | |
24 | use rbml::reader::Decoder; | |
25 | use serialize::{Encodable, Decodable}; | |
970d7e83 | 26 | |
1a4d82fc | 27 | #[derive(Encodable, Decodable, Eq, Rand)] |
970d7e83 | 28 | struct A; |
1a4d82fc | 29 | #[derive(Encodable, Decodable, Eq, Rand)] |
c34b1796 | 30 | struct B(isize); |
1a4d82fc | 31 | #[derive(Encodable, Decodable, Eq, Rand)] |
c34b1796 | 32 | struct C(isize, isize, usize); |
970d7e83 | 33 | |
1a4d82fc | 34 | #[derive(Encodable, Decodable, Eq, Rand)] |
970d7e83 | 35 | struct D { |
c34b1796 AL |
36 | a: isize, |
37 | b: usize, | |
970d7e83 LB |
38 | } |
39 | ||
1a4d82fc | 40 | #[derive(Encodable, Decodable, Eq, Rand)] |
970d7e83 LB |
41 | enum E { |
42 | E1, | |
c34b1796 | 43 | E2(usize), |
970d7e83 | 44 | E3(D), |
c34b1796 | 45 | E4{ x: usize }, |
970d7e83 LB |
46 | } |
47 | ||
1a4d82fc | 48 | #[derive(Encodable, Decodable, Eq, Rand)] |
970d7e83 LB |
49 | enum F { F1 } |
50 | ||
1a4d82fc | 51 | #[derive(Encodable, Decodable, Eq, Rand)] |
970d7e83 LB |
52 | struct G<T> { |
53 | t: T | |
54 | } | |
55 | ||
1a4d82fc JJ |
56 | fn roundtrip<'a, T: Rand + Eq + Encodable<Encoder<'a>> + |
57 | Decodable<Decoder<'a>>>() { | |
970d7e83 | 58 | let obj: T = random(); |
1a4d82fc JJ |
59 | let mut w = Vec::new(); |
60 | let mut e = Encoder::new(&mut w); | |
61 | obj.encode(&mut e); | |
85aaf69f | 62 | let doc = rbml::Doc::new(&w); |
1a4d82fc | 63 | let mut dec = Decoder::new(doc); |
970d7e83 LB |
64 | let obj2 = Decodable::decode(&mut dec); |
65 | assert!(obj == obj2); | |
66 | } | |
67 | ||
68 | pub fn main() { | |
69 | roundtrip::<A>(); | |
70 | roundtrip::<B>(); | |
71 | roundtrip::<C>(); | |
72 | roundtrip::<D>(); | |
73 | ||
85aaf69f | 74 | for _ in 0..20 { |
970d7e83 LB |
75 | roundtrip::<E>(); |
76 | roundtrip::<F>(); | |
c34b1796 | 77 | roundtrip::<G<isize>>(); |
970d7e83 LB |
78 | } |
79 | } |