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
|
/*
* java-gnome, a UI library for writing GTK and GNOME programs from Java!
*
* Copyright © 2007-2011 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 com.operationaldynamics.defsparser.ValidateDefsParsing;
import com.operationaldynamics.driver.DefsFile;
import com.operationaldynamics.driver.ImproperDefsFileException;
/**
* While much of the output from the code generator is subjective (ie
* formatting and code style), there are numerous helper methods used to
* transform the .defs data to that needed by the java-gnome bindings. These
* we can test.
*
* @author Andrew Cowie
* @since 4.0.3
*/
public final class ValidateUtilityMethods extends ValidateDefsParsing
{
public final void testEncodeJavaNamesToJni() {
assertEquals("org_gnome_gtk_GtkButton",
Generator.encodeJavaClassName("org.gnome.gtk", "GtkButton"));
assertEquals("gtk_1button_1set_1label", Generator.encodeJavaMethodName("gtk_button_set_label"));
assertEquals("setLabelTheRightWay", Generator.toCamel("set_label_the_right_way"));
}
public final void testFullyQualifiedJavaName() {
Thing button = new ObjectThing("GtkButton*", "org.gnome.gtk", "GtkButton", "Button");
assertEquals("org.gnome.gtk.Button", button.fullyQualifiedJavaClassName());
}
public final void testConstructorNameMunging() {
Thing button = new ObjectThing("GtkButton*", "org.gnome.gtk", "GtkButton", "Button");
Thing.register(button);
String munged1 = ConstructorGenerator.mungeConstructorName("GtkButton*",
"gtk_button_new_with_label");
assertEquals("createButtonWithLabel", munged1);
String munged2 = ConstructorGenerator.mungeConstructorName("GtkButton*", "gtk_button_new");
assertEquals("createButton", munged2);
}
public final void testThingTranslationCode() throws ImproperDefsFileException {
FundamentalThing ft;
ObjectThing ot;
DefsFile context;
context = new DefsFile(parser.parseData());
ft = new FundamentalThing("gboolean", "boolean", "boolean", "jboolean");
assertEquals("a", ft.translationToNative("a"));
assertEquals("a", ft.translationToJava("a", context));
ot = new ObjectThing("GtkWidget*", "org.gnome.gtk", "GtkWidget", "Widget");
assertEquals("pointerOf(b)", ot.translationToNative("b"));
assertEquals("(Widget) objectFor(b)", ot.translationToJava("b", context));
}
public final void testConsantNameMunging() {
assertEquals("REALLY_IMPORTANT", Generator.toAllCaps("really-important"));
}
public final void testSignalNameMunging() {
assertEquals("DeleteEvent", Generator.toPascalCase("delete_event"));
}
public final void testPascalCaseBackToUnderscores() {
assertEquals("gtk_tree_iter", AccessorGenerator.toUnderscores("GtkTreeIter"));
}
}
|