1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
/*
* java-gnome, a UI library for writing GTK and GNOME programs from Java!
*
* Copyright © 2007-2010 Operational Dynamics Consulting, Pty Ltd
*
* The code in this file, and the program it is a part of, is made available
* to you by its authors as open source software: you can redistribute it
* and/or modify it under the terms of the GNU General Public License version
* 2 ("GPL") as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GPL for more details.
*
* You should have received a copy of the GPL along with this program. If not,
* see http://www.gnu.org/licenses/. The authors of this program may be
* contacted through http://java-gnome.sourceforge.net/.
*/
package com.operationaldynamics.codegen;
import java.util.ArrayList;
import java.util.List;
import com.operationaldynamics.defsparser.Block;
import com.operationaldynamics.defsparser.ObjectBlock;
import com.operationaldynamics.defsparser.ValidateDefsParsing;
/*
* In the codegen package so we can see the Thing fields.
*/
public final class ValidateThingUsage extends ValidateDefsParsing
{
/**
* This is a somewhat contrived test; the same code is tested again
* {@link com.operationaldynamics.defsparser.ValidateDefsParsing#testObjectBlockCreatesObjectThing()}
* on "real" defs data, but this at least is an isolated an explicit
* check.
*/
public final void testObjectBlockCreatesObjectThing() {
List<String[]> characteristics;
ObjectBlock b;
Thing t;
ObjectThing ot;
characteristics = new ArrayList<String[]>();
characteristics.add(new String[] {
"in-module",
"Gtk"
});
characteristics.add(new String[] {
"parent",
"GtkBin"
});
characteristics.add(new String[] {
"c-name",
"GtkButton"
});
b = new ObjectBlock("Button", characteristics, null);
assertNotNull(b);
t = b.createThing();
assertNotNull(t);
assertTrue(t instanceof ObjectThing);
ot = (ObjectThing) t;
assertEquals("org.gnome.gtk", ot.bindingsPackage);
assertEquals("GtkButton", ot.bindingsClass);
assertEquals("Button", ot.javaType);
assertEquals("long", ot.nativeType);
assertEquals("jlong", ot.jniType);
}
public final void testCreateObjectThing() {
final Block[] blocks;
final ObjectThing ot;
blocks = parser.parseData();
assertTrue(blocks[0] instanceof ObjectBlock);
ot = (ObjectThing) blocks[0].createThing();
assertEquals("GtkButton*", ot.gType);
assertEquals("GtkButton", ot.bindingsClass);
assertEquals("Button", ot.javaType);
Thing.register(ot);
assertSame(ot, Thing.lookup("GtkButton*"));
}
public final void testCreateConstVariant() {
final Thing normal, variant, again;
normal = Thing.lookup("GtkButton*");
assertEquals("GtkButton*", normal.gType);
assertEquals("GtkButton*", normal.cType);
/*
* Ok, let's see it make the constant variant Thing
*/
variant = Thing.lookup("const-GtkButton*");
assertEquals("const-GtkButton*", variant.gType);
assertEquals("const GtkButton*", variant.cType);
/*
* Make sure it doesn't create another one!
*/
again = Thing.lookup("const-GtkButton*");
assertSame(variant, again);
}
public final void testCreateOutVariant() {
final Thing normal, variant, again;
normal = Thing.lookup("GtkButton*");
assertEquals("GtkButton*", normal.gType);
assertEquals("GtkButton*", normal.cType);
/*
* Ok, let's see it make the out-parameter variant Thing
*/
variant = Thing.lookup("GtkButton**");
assertEquals("GtkButton**", variant.gType);
assertEquals("GtkButton**", variant.cType);
/*
* Make sure it doesn't create another one!
*/
again = Thing.lookup("GtkButton**");
assertSame(variant, again);
}
}
|