Source Code Cross Referenced for FriendTestCase.java in  » IDE-Netbeans » cnd » org » netbeans » modules » cnd » modelimpl » csm » container » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » cnd » org.netbeans.modules.cnd.modelimpl.csm.container 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package org.netbeans.modules.cnd.modelimpl.csm.container;
043:
044:        import java.io.File;
045:        import java.util.Collection;
046:        import java.util.HashSet;
047:        import java.util.Set;
048:        import org.netbeans.modules.cnd.api.model.CsmClass;
049:        import org.netbeans.modules.cnd.api.model.CsmFriend;
050:        import org.netbeans.modules.cnd.api.model.CsmFriendClass;
051:        import org.netbeans.modules.cnd.api.model.CsmFriendFunction;
052:        import org.netbeans.modules.cnd.api.model.CsmFunction;
053:        import org.netbeans.modules.cnd.api.model.CsmOffsetableDeclaration;
054:        import org.netbeans.modules.cnd.modelimpl.csm.core.FileImpl;
055:        import org.netbeans.modules.cnd.modelimpl.impl.services.FriendResolverImpl;
056:        import org.netbeans.modules.cnd.modelimpl.csm.core.ProjectBase;
057:        import org.netbeans.modules.cnd.modelimpl.trace.TraceModelTestBase;
058:
059:        /**
060:         * base class for friends tests
061:         *
062:         * @author Alexander Simon
063:         */
064:        public class FriendTestCase extends TraceModelTestBase {
065:
066:            public FriendTestCase(String testName) {
067:                super (testName);
068:            }
069:
070:            @Override
071:            protected void setUp() throws Exception {
072:                super .setUp();
073:                //log("CndFriendTestCase.setUp started.");
074:                //log("Test "+getName()+  " started");
075:            }
076:
077:            @Override
078:            protected void tearDown() throws Exception {
079:                super .tearDown();
080:            }
081:
082:            public void testFriend() throws Exception {
083:                performTest("friend.cc"); // NOI18N
084:            }
085:
086:            @Override
087:            protected void performTest(String source) throws Exception {
088:                File testFile = getDataFile(source);
089:                assertTrue("File not found " + testFile.getAbsolutePath(),
090:                        testFile.exists()); // NOI18N
091:                performModelTest(testFile, System.out, System.err);
092:                checkFriend();
093:                for (FileImpl file : getProject().getAllFileImpls()) {
094:                    file.stateChanged(true);
095:                    file.scheduleParsing(true);
096:                }
097:                checkFriend();
098:                getProject().onFileRemoved(testFile);
099:                checkEmpty();
100:            }
101:
102:            private void checkEmpty() {
103:                ProjectBase project = getProject();
104:                assertNotNull("Project must be valid", project); // NOI18N
105:                assertTrue("Should be 0 declarations in project", project
106:                        .findDeclarationsByPrefix("").size() == 0); // NOI18N
107:                assertTrue(
108:                        "Should be 0 declarations in global namespace",
109:                        project.getGlobalNamespace().getDeclarations().size() == 0); // NOI18N
110:                assertTrue(
111:                        "Should be 0 definitions in global namespace",
112:                        project.getGlobalNamespace().getDefinitions().size() == 0); // NOI18N
113:                assertTrue("Should be 0 namespaces in global namespace",
114:                        project.getGlobalNamespace().getNestedNamespaces()
115:                                .size() == 0); // NOI18N
116:            }
117:
118:            private String getClassName(Class cls) {
119:                String s = cls.getName();
120:                return s.substring(s.lastIndexOf('.') + 1);
121:            }
122:
123:            private void checkFriend() {
124:                ProjectBase project = getProject();
125:                assertNotNull("Project must be valid", project); // NOI18N
126:                CsmClass clsB = (CsmClass) project.findClassifier("B"); // NOI18N
127:                assertNotNull("Class B not found", clsB); // NOI18N
128:                Collection<CsmFriend> friends = clsB.getFriends();
129:                assertTrue("Should be 5 friends in class B",
130:                        friends.size() == 5); // NOI18N
131:                CsmFriendClass friendA2 = null;
132:                CsmFriendFunction friendMoo2 = null;
133:                CsmFriendFunction friendMoo = null;
134:                CsmFriendFunction friendSoo = null;
135:                CsmFriendFunction friendSoo2 = null;
136:                for (CsmFriend friend : friends) {
137:                    if ("A2".equals(friend.getName().toString())) { // NOI18N
138:                        friendA2 = (CsmFriendClass) friend;
139:                    } else if ("moo2".equals(friend.getName().toString())) { // NOI18N
140:                        friendMoo2 = (CsmFriendFunction) friend;
141:                    } else if ("moo".equals(friend.getName().toString())) { // NOI18N
142:                        friendMoo = (CsmFriendFunction) friend;
143:                    } else if ("soo".equals(friend.getName().toString())) { // NOI18N
144:                        friendSoo = (CsmFriendFunction) friend;
145:                    } else if ("soo2".equals(friend.getName().toString())) { // NOI18N
146:                        friendSoo2 = (CsmFriendFunction) friend;
147:                    }
148:                }
149:                assertNotNull("Friend class declaration A2 not found", friendA2); // NOI18N
150:                assertNotNull("Friend method declaration moo2 not found",
151:                        friendMoo2); // NOI18N
152:                assertNotNull("Friend method declaration moo not found",
153:                        friendMoo); // NOI18N
154:                assertNotNull("Friend method declaration soo not found",
155:                        friendSoo); // NOI18N
156:                assertNotNull("Friend method declaration soo2 not found",
157:                        friendSoo2); // NOI18N
158:
159:                CsmClass clsA2 = friendA2.getReferencedClass();
160:                assertNotNull("Referenced class A2 for friend not found", clsA2); // NOI18N
161:                CsmFunction funMoo2 = friendMoo2.getReferencedFunction();
162:                assertNotNull("Referenced function moo2 for friend not found",
163:                        funMoo2); // NOI18N
164:                CsmFunction funMoo = friendMoo.getReferencedFunction();
165:                assertNotNull("Referenced function moo for friend not found",
166:                        funMoo); // NOI18N
167:                CsmFunction funSoo = friendSoo.getReferencedFunction();
168:                assertNotNull("Referenced function soo for friend not found",
169:                        funSoo); // NOI18N
170:                CsmFunction funSoo2 = friendSoo2.getReferencedFunction();
171:                assertNotNull("Referenced function soo2 for friend not found",
172:                        funSoo); // NOI18N
173:
174:                Collection<CsmFriend> list = FriendResolverImpl.getDefault()
175:                        .findFriends(clsA2);
176:                assertTrue("Should be 1 friend declaration for class A2", list
177:                        .size() == 1); // NOI18N
178:                assertTrue(
179:                        "Friend declaration for class A2 has wrong instance",
180:                        list.iterator().next() == friendA2); // NOI18N
181:                list = FriendResolverImpl.getDefault().findFriends(funMoo2);
182:                assertTrue("Should be 1 friend declaration for function moo2",
183:                        list.size() == 1); // NOI18N
184:                assertTrue(
185:                        "Friend declaration for function moo2 has wrong instance",
186:                        list.iterator().next() == friendMoo2); // NOI18N
187:                list = FriendResolverImpl.getDefault().findFriends(funMoo);
188:                assertTrue("Should be 1 friend declaration for function moo",
189:                        list.size() == 1); // NOI18N
190:                assertTrue(
191:                        "Friend declaration for function moo has wrong instance",
192:                        list.iterator().next() == friendMoo); // NOI18N
193:                list = FriendResolverImpl.getDefault().findFriends(funSoo);
194:                assertTrue("Should be 1 friend declaration for function moo",
195:                        list.size() == 1); // NOI18N
196:                assertTrue(
197:                        "Friend declaration for function soo has wrong instance",
198:                        list.iterator().next() == friendSoo);
199:
200:                Collection<CsmOffsetableDeclaration> declarations = project
201:                        .findDeclarationsByPrefix("");
202:                Set<String> set = new HashSet<String>();
203:                for (CsmOffsetableDeclaration decl : declarations) {
204:                    String uName = decl.getUniqueName().toString();
205:                    System.out.println(uName + " \t"
206:                            + getClassName(decl.getClass())); // NOI18N
207:                    if ("F:moo2(int)".equals(uName)) {
208:                        assertTrue("moo2(int) is not friend B",
209:                                FriendResolverImpl.getDefault().isFriend(decl,
210:                                        clsB)); // NOI18N
211:                    } else if ("f:moo(int)".equals(uName)) { // NOI18N
212:                        assertTrue("moo(int) is not friend B",
213:                                FriendResolverImpl.getDefault().isFriend(decl,
214:                                        clsB)); // NOI18N
215:                    } else if ("S:S2".equals(uName)) { // NOI18N
216:                        assertFalse("S2 is friend B", FriendResolverImpl
217:                                .getDefault().isFriend(decl, clsB)); // NOI18N
218:                    } else if ("F:S2::soo()".equals(uName)) { // NOI18N
219:                        assertTrue("S2::soo() is not friend B",
220:                                FriendResolverImpl.getDefault().isFriend(decl,
221:                                        clsB)); // NOI18N
222:                    } else if ("f:S2::soo2()".equals(uName)) { // NOI18N
223:                        assertTrue("S2::soo2() is not friend B",
224:                                FriendResolverImpl.getDefault().isFriend(decl,
225:                                        clsB)); // NOI18N
226:                    } else if ("F:S2::soo3()".equals(uName)) { // NOI18N
227:                        assertTrue("S2::soo3() is not friend B",
228:                                FriendResolverImpl.getDefault().isFriend(decl,
229:                                        clsB)); // NOI18N
230:                    } else if ("C:A2".equals(uName)) { // NOI18N
231:                        assertTrue("A2 is not friend B", FriendResolverImpl
232:                                .getDefault().isFriend(decl, clsB)); // NOI18N
233:                    } else if ("F:A2::foo()".equals(uName)) { // NOI18N
234:                        assertTrue("A2::foo() is not friend B",
235:                                FriendResolverImpl.getDefault().isFriend(decl,
236:                                        clsB)); // NOI18N
237:                    } else if ("f:A2::foo()".equals(uName)) { // NOI18N
238:                        assertTrue("A2::foo() is not friend B",
239:                                FriendResolverImpl.getDefault().isFriend(decl,
240:                                        clsB)); // NOI18N
241:                    } else if ("F:ccStyle()".equals(uName)) { // NOI18N
242:                        assertFalse("ccStyle() is friend B", FriendResolverImpl
243:                                .getDefault().isFriend(decl, clsB)); // NOI18N
244:                    } else if ("C:B".equals(uName)) { // NOI18N
245:                        assertFalse("B is friend B", FriendResolverImpl
246:                                .getDefault().isFriend(decl, clsB)); // NOI18N
247:                    } else if ("t:B::xxx".equals(uName)) { // NOI18N
248:                        assertFalse("B::xxx is friend B", FriendResolverImpl
249:                                .getDefault().isFriend(decl, clsB)); // NOI18N
250:                    } else if ("r:B::A2".equals(uName)) { // NOI18N
251:                        assertFalse("B::A2 is friend B", FriendResolverImpl
252:                                .getDefault().isFriend(decl, clsB)); // NOI18N
253:                    } else if ("F:B::boo()".equals(uName)) { // NOI18N
254:                        assertFalse("B::boo() is friend B", FriendResolverImpl
255:                                .getDefault().isFriend(decl, clsB)); // NOI18N
256:                    } else if ("f:moo2(int)".equals(uName)) { // NOI18N
257:                        assertTrue("moo2(int) is not friend B",
258:                                FriendResolverImpl.getDefault().isFriend(decl,
259:                                        clsB)); // NOI18N
260:                    } else if ("F:moo(int)".equals(uName)) { // NOI18N
261:                        assertTrue("moo(int) is friend B", FriendResolverImpl
262:                                .getDefault().isFriend(decl, clsB)); // NOI18N
263:                    } else if ("f:S2::soo()".equals(uName)) { // NOI18N
264:                        assertTrue("S2::soo() is not friend B",
265:                                FriendResolverImpl.getDefault().isFriend(decl,
266:                                        clsB)); // NOI18N
267:                    } else if ("F:S2::soo2()".equals(uName)) { // NOI18N
268:                        assertTrue("S2::soo2() is not friend B",
269:                                FriendResolverImpl.getDefault().isFriend(decl,
270:                                        clsB)); // NOI18N
271:                    } else if ("f:ccStyle(int)".equals(uName)) { // NOI18N
272:                        assertFalse("ccStyle(int) is friend B",
273:                                FriendResolverImpl.getDefault().isFriend(decl,
274:                                        clsB)); // NOI18N
275:                    } else {
276:                        assertTrue("Inexpected declaration " + uName, false); // NOI18N
277:                    }
278:                    assertFalse("Duplicated declaration ", set.contains(uName)); // NOI18N
279:                    set.add(uName);
280:                }
281:                assertTrue("Not all declaration found in project",
282:                        set.size() == 18); // NOI18N
283:            }
284:            /*
285:             int moo2(int);                          //F:moo2(int)                    FunctionImpl
286:             int moo(int){return 0;}                 //f:moo(int)          FunctionDDImpl
287:             struct S2 {                             //S:S2                             ClassImpl
288:             int soo();                          //F:S2::soo()                    MethodImpl
289:             int soo2(){return 0;} };            //f:S2::soo2() 	MethodDDImpl
290:             class A2{                               //C:A2                              ClassImpl
291:             int foo(); };                       //F:A2::foo()                    MethodImpl
292:             int A2::foo(){ return 0; }              //f:A2::foo() 	FunctionDefinitionImpl
293:             int ccStyle();                          //F:ccStyle()                    FunctionImpl
294:             class B{                                //C:B                               ClassImpl
295:             typedef int xxx;                    //t:B::xxx                        ClassImpl$MemberTypedef
296:             friend class A2;                    //r:B::A2 	FriendClassImpl
297:             int boo();                          //F:B::boo()                     MethodImpl
298:             friend int moo2(int) { return 0; }; //f:moo2(int) 	FriendFunctionDDImpl
299:             friend int moo(int);                //F:moo(int)                     FriendFunctionImpl
300:             friend int S2::soo(){ return 0; }   //f:S2::soo() 	FriendFunctionDefinitionImpl
301:             friend int S2::soo2(); };           //F:S2::soo2()                   FriendFunctionImplEx
302:             int ccStyle(int){ return 0; }           //f:ccStyle(int) 	FunctionDDImpl
303:             */
304:        }
w___w_w.___j__a_va_2__s__.___c__o___m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.