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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
/*
* 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.defsparser;
import java.io.IOException;
import java.io.StringReader;
import java.text.ParseException;
import junit.framework.TestCase;
import com.operationaldynamics.codegen.Thing;
/**
* Evaluate the internal methods in the DefsParser class.
*
* @author Andrew Cowie
*/
public class ValidateDefsParsing extends TestCase
{
private static final String inputDefsData;
static {
final StringBuffer buf;
final String[] raw;
raw = new String[] {
"(define-object Button",
" (in-module \"Gtk\")",
" (parent \"GtkBin\")",
" (c-name \"GtkButton\")",
" (gtype-id \"GTK_TYPE_BUTTON\")",
")",
"",
"(define-function gtk_button_new",
" (is-constructor-of \"GtkButton\")",
" (c-name \"gtk_button_new\")",
" (caller-owns-return #t)",
" (return-type \"GtkWidget*\")",
")",
"",
"(define-method set_label",
" (of-object \"GtkButton\")",
" (c-name \"gtk_button_set_label\")",
" (return-type \"none\")",
" (parameters",
" '(\"const-gchar*\" \"label\")",
" )",
")",
"",
"(define-method leave",
" (of-object \"GtkButton\")",
" (c-name \"gtk_button_leave\")",
" (return-type \"none\")",
" (deprecated)",
")",
"",
"(define-virtual clicked",
" (of-object \"GtkButton\")",
" (return-type \"none\")",
")"
};
buf = new StringBuffer();
for (int i = 0; i < raw.length; i++) {
buf.append(raw[i]);
buf.append("\n");
}
inputDefsData = buf.toString();
}
protected DefsParser parser;
DefsLineNumberReader in;
public void setUp() throws IOException {
in = new DefsLineNumberReader(new StringReader(inputDefsData), "Mock data");
parser = new DefsParser(in);
}
public void tearDown() throws IOException {
in.close();
}
public final void testInputStreamToStanzas() throws ParseException {
int i;
for (i = 0; parser.readNextStanza(); i++) {
;
}
assertEquals(5, i);
}
public final void testObjectBlockCreated() throws ParseException {
Block[] results;
ObjectBlock o;
results = parser.parseData();
assertTrue(results[0] instanceof ObjectBlock);
o = (ObjectBlock) results[0];
assertEquals("Gtk", o.inModule);
assertEquals("GtkBin", o.parent);
assertEquals("GtkButton", o.cName);
assertEquals("Button", o.blockName);
}
public final void testCantCreateThingFromNonTypeBlock() {
Block[] blocks;
Thing t = null;
blocks = parser.parseData();
assertFalse(blocks[1] instanceof TypeBlock);
try {
t = blocks[1].createThing();
fail("Should have thrown UnsupportedOperationException");
} catch (UnsupportedOperationException uoe) {
// good
}
assertNull(t);
}
public final void testMethodReferenceToSelfInsertion() {
Block[] results;
MethodBlock block;
results = parser.parseData();
assertTrue(results[2] instanceof MethodBlock);
block = (MethodBlock) results[2];
assertTrue(block.parameters.length == 2);
assertEquals("GtkButton*", block.parameters[0][0]);
assertEquals("self", block.parameters[0][1]);
assertEquals("const-gchar*", block.parameters[1][0]);
assertEquals("label", block.parameters[1][1]);
}
public final void testIgnoreUnnecessaryBlocks() {
Block[] results;
results = parser.parseData();
assertEquals(4, results.length);
}
}
|