/** * Check if definition methods: isVisible, isHidden, isPrivate and isStorable works as expected by * defining some of them. */ @Test public void testDefinitionsMethods() { RPClass b = new RPClass("RPClassTest::F"); assertEquals(b, RPClass.getRPClass("RPClassTest::F")); b.add(DefinitionClass.ATTRIBUTE, "a", Type.INT, Definition.STANDARD); b.add(DefinitionClass.ATTRIBUTE, "b", Type.FLAG, Definition.HIDDEN); b.add( DefinitionClass.ATTRIBUTE, "c", Type.STRING, (byte) (Definition.PRIVATE | Definition.VOLATILE)); Definition def = b.getDefinition(DefinitionClass.ATTRIBUTE, "a"); assertEquals(Type.INT, def.getType()); assertTrue(def.isVisible()); assertFalse(def.isHidden()); assertFalse(def.isPrivate()); assertTrue(def.isStorable()); def = b.getDefinition(DefinitionClass.ATTRIBUTE, "b"); assertEquals(Type.FLAG, def.getType()); assertFalse(def.isVisible()); assertTrue(def.isHidden()); assertFalse(def.isPrivate()); assertTrue(def.isStorable()); def = b.getDefinition(DefinitionClass.ATTRIBUTE, "c"); assertEquals(Type.STRING, def.getType()); assertFalse(def.isVisible()); assertFalse(def.isHidden()); assertTrue(def.isPrivate()); assertFalse(def.isStorable()); }
/** * Test the hierachy process. This test verify bug, that caused codes to be badly resolve, is * fixed. */ @Test public void testHierachyBug() { RPClass b = new RPClass("RPClassTest::K"); b.add(DefinitionClass.ATTRIBUTE, "a", Type.INT, Definition.STANDARD); b.add(DefinitionClass.ATTRIBUTE, "b", Type.FLAG, Definition.STANDARD); b.add(DefinitionClass.STATIC, "c", "test", Definition.STANDARD); RPClass c = new RPClass("RPClassTest::M"); c.isA(b); c.add(DefinitionClass.ATTRIBUTE, "a", Type.STRING, Definition.STANDARD); c.add(DefinitionClass.STATIC, "c", "subclass", Definition.STANDARD); Attributes attr = new Attributes(c); attr.put("a", 10); assertTrue(attr.has("a")); assertFalse(attr.has("b")); assertTrue(attr.has("c")); assertEquals("subclass", attr.get("c")); Definition def = c.getDefinition(DefinitionClass.ATTRIBUTE, "a"); assertEquals(Type.STRING, def.getType()); short code = def.getCode(); assertEquals("a", c.getName(DefinitionClass.ATTRIBUTE, code)); }
/** * This test case shows a bug fix for a Marauroa 1.3x bug where two attributes definition even in * diferent classes where created as the same one ( ignoring the second definition ). * * <p>For example A ( id string ) B ( id int ) * * <p>They are different attributes and of different type. Check that it is true. */ @Test public void testGlobalDefinitionBug() { RPClass b = new RPClass("RPClassTest::G"); b.add(DefinitionClass.ATTRIBUTE, "a", Type.INT, Definition.STANDARD); b.add(DefinitionClass.ATTRIBUTE, "b", Type.FLAG, Definition.STANDARD); RPClass c = new RPClass("H"); c.add(DefinitionClass.ATTRIBUTE, "a", Type.STRING, Definition.STANDARD); c.add(DefinitionClass.ATTRIBUTE, "b", Type.FLOAT, Definition.HIDDEN); Definition defb = b.getDefinition(DefinitionClass.ATTRIBUTE, "a"); Definition defc = c.getDefinition(DefinitionClass.ATTRIBUTE, "a"); assertFalse(defb.getType() == defc.getType()); }
public void readFile() { String log = "updated : "; boolean notempty = false; for (String fileName : filesToRead) { try { notempty = true; log = log.concat(fileName + ", "); XMLInputFactory inputFactory = XMLInputFactory.newInstance(); InputStream in = null; if (GoldMonkeyAppState.external) in = new FileInputStream(fileName); else in = this.getClass().getResourceAsStream(fileName); XMLEventReader eventReader = inputFactory.createXMLEventReader(in); Definition def = null; // read the XML document while (eventReader.hasNext()) { XMLEvent event = eventReader.nextEvent(); if (event.isStartElement()) { def = parseEvent(event, def); } else if (event.isEndElement()) { String elementName = event.asEndElement().getName().getLocalPart(); if (def != null && elementName.equals(def.getType())) { BuilderManager.submit(def); def = null; } // else // throw new // RuntimeException("("+fileName+") At line "+event.getLocation().getLineNumber()+", // find a closing element that is not closing a definition"+elementName); } } } catch (FileNotFoundException | XMLStreamException e) { e.printStackTrace(); } } if (notempty) { BuilderManager.buildLinks(); } }
/** @see jaskell.compiler.JaskellVisitor#visit(Definition) */ public Object visit(Definition a) { return a.getType(); }