]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/testcases/org/simantics/databoard/tests/TestPrimitiveSetters.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / testcases / org / simantics / databoard / tests / TestPrimitiveSetters.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2012 Association for Decentralized Information Management in
3  * Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.databoard.tests;
13
14 import java.util.UUID;
15
16 import org.simantics.databoard.Bindings;
17 import org.simantics.databoard.binding.Binding;
18 import org.simantics.databoard.binding.RecordBinding;
19 import org.simantics.databoard.serialization.Serializer;
20
21 public class TestPrimitiveSetters {
22
23     public static class X {
24         
25         public boolean z; // 0
26         public Boolean zz;// 1
27         
28         public byte b;    // 2
29         public Byte bb;   // 3
30         
31         public int i;     // 4
32         public Integer ii;// 5
33         
34         public long l;    // 6        
35         public Long ll;   // 7
36         
37         public float f;   // 8
38         public Float ff;  // 9
39         
40         public double d;  // 10
41         public Double dd; // 11
42
43         private boolean z_; // 12
44         private Boolean zz_;// 13
45         
46         private byte b_;    // 14
47         private Byte bb_;   // 15
48         /*
49         private int i_;     // 16
50         private Integer ii_;// 17
51         
52         private long l_;    // 18       
53         private Long ll_;   // 19
54         
55         private float f_;   // 20
56         private Float ff_;  // 21
57         
58         private double d_;  // 22
59         private Double dd_; // 23
60         */
61         public void setZ_(boolean z) {this.z_ = z;}
62         public boolean getZ_() {return z_;}
63
64         public void setZz_(Boolean z) {this.zz_ = z;}
65         public Boolean getZz_() {return zz_;}
66         
67         public void setB_(byte z) {this.b_ = z;}
68         public byte getB_() {return b_;}
69
70         public void setBb_(Byte z) {this.bb_ = z;}
71         public Byte getBb_() {return bb_;}        
72         
73     }
74     
75     public static void main(String[] args) throws Exception {
76         // DONE Add primitive support for Deserialization
77         // TODO Test UUID
78         // TODO Remove validator from AsmBindingClassLoader
79         // DONE Test Setters
80         
81         RecordBinding b = Bindings.getBinding( X.class );
82         
83         X x = new X();
84         b.setBoolean(x, 0, true);
85         b.setBoolean(x, 1, true);
86         
87         b.setByte(x, 2, (byte)3);
88         b.setByte(x, 3, (byte)3);
89         
90         b.setInt(x, 4, 3);
91         b.setInt(x, 5, 3);
92
93         b.setLong(x, 6, 3L);
94         b.setLong(x, 7, 3L);
95         
96         b.setFloat(x, 8, 3.f);
97         b.setFloat(x, 9, 3.f);
98         
99         b.setDouble(x, 10, 3.2);
100         b.setDouble(x, 11, 3.4);
101
102         b.setBoolean(x, 12, true);
103         b.setBoolean(x, 13, true);
104         
105         b.setByte(x, 14, (byte)3);
106         b.setByte(x, 15, (byte)3);
107         
108         System.out.println( b.getBoolean(x, 0) );
109         System.out.println( b.getBoolean(x, 1) );
110         
111         System.out.println( b.getByte(x, 2) );
112         System.out.println( b.getByte(x, 3) );
113         
114         System.out.println( b.getInt(x, 4) );
115         System.out.println( b.getInt(x, 5) );
116         
117         System.out.println( b.getLong(x, 6) );
118         System.out.println( b.getLong(x, 7) );
119         
120         System.out.println( b.getFloat(x, 8) );
121         System.out.println( b.getFloat(x, 9) );
122         
123         System.out.println( b.getDouble(x, 10) );
124         System.out.println( b.getDouble(x, 11) );
125         
126         System.out.println( b.getBoolean(x, 12) );
127         System.out.println( b.getBoolean(x, 13) );
128         
129         System.out.println( b.getByte(x, 14) );
130         System.out.println( b.getByte(x, 15) );
131         
132         System.out.println(b.toString(x));
133         
134         UUID guid = UUID.randomUUID();
135         Binding binding = Bindings.getBinding(UUID.class);
136         Serializer s = Bindings.getSerializer(binding);
137         byte[] data = s.serialize( guid );
138         
139         guid = (UUID) s.deserialize( data );
140         
141     }
142 }