1 /*******************************************************************************
2 * Copyright (c) 2010- Association for Decentralized Information Management in
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.databoard.tests;
14 import junit.framework.TestCase;
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;
21 public class TestStringVariantBinding extends TestCase {
23 public void testAll() throws Exception
25 RandomValue rv = new RandomValue();
26 VariantBinding vb = Bindings.STR_VARIANT;
27 VariantBinding gen = (VariantBinding) Bindings.getMutableBinding( Datatypes.VARIANT );
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) );
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=") );
40 for (int i=0; i<10000; i++) {
43 rv.getRandom().setSeed(seed);
44 rv.getRandom().nextLong();
46 Object value = gen.accept(rv);
48 String str = (String) Bindings.adaptUnchecked(value, gen, vb);
49 Object value2 = Bindings.adaptUnchecked(str, vb, gen);
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("");
58 assertTrue( gen.equals(value, value2) );