/** * Copyright (C) 2009 STMicroelectronics * * This file is part of "Mind Compiler" is free software: you can redistribute * it and/or modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * 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 GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * Contact: mind@ow2.org * * Authors: Matthieu Leclercq * Contributors: */ package org.ow2.mind.idl; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertSame; import java.util.Collection; import org.ow2.mind.CommonFrontendModule; import org.ow2.mind.idl.ASTChecker.IDLChecker; import org.ow2.mind.idl.ASTChecker.IncludeCheckerIterator; import org.ow2.mind.idl.ASTChecker.TypeCheckerIterator; import org.ow2.mind.idl.ast.IDL; import org.ow2.mind.idl.ast.IDLASTHelper; import org.ow2.mind.idl.ast.InterfaceDefinition; import org.ow2.mind.plugin.PluginLoaderModule; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import com.google.inject.Guice; import com.google.inject.Injector; public class TestIDLLoaderChain { protected IDLLoader idlLoader; protected ASTChecker checker; @BeforeMethod(alwaysRun = true) protected void setUp() throws Exception { final Injector injector = Guice.createInjector(new CommonFrontendModule(), new IDLFrontendModule(), new PluginLoaderModule()); idlLoader = injector.getInstance(IDLLoader.class); checker = new ASTChecker(); } @Test(groups = {"functional"}) public void test1() throws Exception { final IDL idl = idlLoader.load("test1", null); final IDLChecker idlChecker = checker.assertIDL(idl); final TypeCheckerIterator definesType = idlChecker.definesType(); definesType.whereFirst().isTypedefOf("myint").isPrimitiveType("int"); definesType.andNext().isTypedefOf("mypointer").isPointerOf().isArrayOf() .isPrimitiveType("int"); definesType.andNext().isStructDef("s").hasMembers("a", "b"); idlChecker.containsMethods("m1", "m2", "m3", "m4", "m5"); } @Test(groups = {"functional"}) public void test2() throws Exception { final IDL idl = idlLoader.load("/test2.idt", null); final IDLChecker idlChecker = checker.assertIDL(idl); final IncludeCheckerIterator containedIncludes = idlChecker .containsIncludes("\"/test3.idt\"", "\"/foo/bar.idt\""); containedIncludes.whereFirst().includes().definesType().whereFirst() .isStructDef("s"); containedIncludes.andNext().includes().containsIncludes("\"/test3.idt\""); } @Test(groups = {"functional"}) public void test3() throws Exception { final IDL idl = idlLoader.load("/test3.idt", null); checker.assertIDL(idl).definesType().whereFirst().isStructDef("s") .hasMember("fooItf").hasType().isTypedefRefOf("foo.foo"); final Collection<InterfaceDefinition> referencedInterfaces = IDLASTHelper .getReferencedInterfaces(idl, null, null); assertNotNull(referencedInterfaces); assertEquals(referencedInterfaces.size(), 1); final InterfaceDefinition foo_foo = referencedInterfaces.iterator().next(); assertEquals(foo_foo.getName(), "foo.foo"); final IDLChecker foo_foo_checker = checker.assertIDL(foo_foo); final IDLChecker test2_checker = foo_foo_checker.containsInclude( "\"/test2.idt\"").includes(); final IDLChecker foo_bar_checker = foo_foo_checker.containsInclude( "\"/foo/bar.idt\"").includes(); assertSame(foo_bar_checker.idl, test2_checker.containsInclude("\"/foo/bar.idt\"").includes().idl); assertSame(idl, test2_checker.containsInclude("\"/test3.idt\"").includes().idl); } }