]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/testcases/org/simantics/databoard/tests/TestStringVariantBinding.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / testcases / org / simantics / databoard / tests / TestStringVariantBinding.java
1 /*******************************************************************************
2  * Copyright (c) 2010- 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 junit.framework.TestCase;
15
16 import org.simantics.databoard.Bindings;
17 import org.simantics.databoard.Datatypes;
18 import org.simantics.databoard.binding.VariantBinding;
19 import org.simantics.databoard.binding.util.RandomValue;
20
21 public class TestStringVariantBinding extends TestCase {
22
23         public void testAll() throws Exception 
24         {               
25                 RandomValue rv = new RandomValue();
26                 VariantBinding vb = Bindings.STR_VARIANT;
27                 VariantBinding gen = (VariantBinding) Bindings.getMutableBinding( Datatypes.VARIANT );
28                 
29                 System.out.println( vb.create(Bindings.INTEGER, 5) );
30                 System.out.println( vb.create(Bindings.LONG, 5L) );
31                 System.out.println( vb.create(Bindings.STRING, "PA11_Valve/Pressure") );
32                 System.out.println( vb.create(Bindings.BOOLEAN, true) );
33                 System.out.println( vb.create(Bindings.BOOLEAN, false) );
34                 
35                 System.out.println( vb.getContent("I5") );
36                 System.out.println( vb.getContent("L5") );
37                 System.out.println( vb.getContent("SMoi") );
38                 System.out.println( vb.getContent("BAAE=") );
39                 
40                 for (int i=0; i<10000; i++) {
41                         
42                         int seed = i;
43                         rv.getRandom().setSeed(seed);
44                         rv.getRandom().nextLong();
45                         
46                         Object value = gen.accept(rv);
47                         
48                         String str = (String) Bindings.adaptUnchecked(value, gen, vb);
49                         Object value2 = Bindings.adaptUnchecked(str, vb, gen);
50                                                 
51                         System.out.println("Testcase: "+i);
52                         System.out.println("String: "+str);
53                         System.out.println("Value1: "+gen.printValueDefinition(value, true));
54                         System.out.println("Value2: "+gen.printValueDefinition(value2, true));
55                         System.out.println("Value3: "+vb.printValueDefinition(str, true));
56                         System.out.println("");
57                         
58                         assertTrue( gen.equals(value, value2) );
59                 }
60         }
61         
62 }
63