1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2012 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.databoard.tests;
\r
14 import java.util.UUID;
\r
16 import org.simantics.databoard.Bindings;
\r
17 import org.simantics.databoard.binding.Binding;
\r
18 import org.simantics.databoard.binding.RecordBinding;
\r
19 import org.simantics.databoard.serialization.Serializer;
\r
21 public class TestPrimitiveSetters {
\r
23 public static class X {
\r
25 public boolean z; // 0
\r
26 public Boolean zz;// 1
\r
29 public Byte bb; // 3
\r
32 public Integer ii;// 5
\r
34 public long l; // 6
\r
35 public Long ll; // 7
\r
37 public float f; // 8
\r
38 public Float ff; // 9
\r
40 public double d; // 10
\r
41 public Double dd; // 11
\r
43 private boolean z_; // 12
\r
44 private Boolean zz_;// 13
\r
46 private byte b_; // 14
\r
47 private Byte bb_; // 15
\r
49 private int i_; // 16
\r
50 private Integer ii_;// 17
\r
52 private long l_; // 18
\r
53 private Long ll_; // 19
\r
55 private float f_; // 20
\r
56 private Float ff_; // 21
\r
58 private double d_; // 22
\r
59 private Double dd_; // 23
\r
61 public void setZ_(boolean z) {this.z_ = z;}
\r
62 public boolean getZ_() {return z_;}
\r
64 public void setZz_(Boolean z) {this.zz_ = z;}
\r
65 public Boolean getZz_() {return zz_;}
\r
67 public void setB_(byte z) {this.b_ = z;}
\r
68 public byte getB_() {return b_;}
\r
70 public void setBb_(Byte z) {this.bb_ = z;}
\r
71 public Byte getBb_() {return bb_;}
\r
75 public static void main(String[] args) throws Exception {
\r
76 // DONE Add primitive support for Deserialization
\r
78 // TODO Remove validator from AsmBindingClassLoader
\r
79 // DONE Test Setters
\r
81 RecordBinding b = Bindings.getBinding( X.class );
\r
84 b.setBoolean(x, 0, true);
\r
85 b.setBoolean(x, 1, true);
\r
87 b.setByte(x, 2, (byte)3);
\r
88 b.setByte(x, 3, (byte)3);
\r
93 b.setLong(x, 6, 3L);
\r
94 b.setLong(x, 7, 3L);
\r
96 b.setFloat(x, 8, 3.f);
\r
97 b.setFloat(x, 9, 3.f);
\r
99 b.setDouble(x, 10, 3.2);
\r
100 b.setDouble(x, 11, 3.4);
\r
102 b.setBoolean(x, 12, true);
\r
103 b.setBoolean(x, 13, true);
\r
105 b.setByte(x, 14, (byte)3);
\r
106 b.setByte(x, 15, (byte)3);
\r
108 System.out.println( b.getBoolean(x, 0) );
\r
109 System.out.println( b.getBoolean(x, 1) );
\r
111 System.out.println( b.getByte(x, 2) );
\r
112 System.out.println( b.getByte(x, 3) );
\r
114 System.out.println( b.getInt(x, 4) );
\r
115 System.out.println( b.getInt(x, 5) );
\r
117 System.out.println( b.getLong(x, 6) );
\r
118 System.out.println( b.getLong(x, 7) );
\r
120 System.out.println( b.getFloat(x, 8) );
\r
121 System.out.println( b.getFloat(x, 9) );
\r
123 System.out.println( b.getDouble(x, 10) );
\r
124 System.out.println( b.getDouble(x, 11) );
\r
126 System.out.println( b.getBoolean(x, 12) );
\r
127 System.out.println( b.getBoolean(x, 13) );
\r
129 System.out.println( b.getByte(x, 14) );
\r
130 System.out.println( b.getByte(x, 15) );
\r
132 System.out.println(b.toString(x));
\r
134 UUID guid = UUID.randomUUID();
\r
135 Binding binding = Bindings.getBinding(UUID.class);
\r
136 Serializer s = Bindings.getSerializer(binding);
\r
137 byte[] data = s.serialize( guid );
\r
139 guid = (UUID) s.deserialize( data );
\r