1 /*
2  * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 package com.sun.hotspot.igv.data;
27 
28 import static org.junit.Assert.*;
29 
30 /**
31  *
32  * @author Thomas Wuerthinger
33  */
34 public class Util {
35 
assertGraphDocumentNotEquals(GraphDocument a, GraphDocument b)36     public static void assertGraphDocumentNotEquals(GraphDocument a, GraphDocument b) {
37         try {
38             assertGraphDocumentEquals(a, b);
39         } catch(AssertionError e) {
40             return;
41         }
42 
43         fail("Graphs documents are equal!");
44     }
45 
assertGraphDocumentEquals(GraphDocument a, GraphDocument b)46     public static void assertGraphDocumentEquals(GraphDocument a, GraphDocument b) {
47 
48         if (a.getElements().size() != b.getElements().size()) {
49             fail();
50         }
51 
52         int z = 0;
53         for (FolderElement e : b.getElements()) {
54 
55             if (e instanceof Group) {
56                 Group g = (Group) e;
57                 Group thisG = (Group) a.getElements().get(z);
58                 assertGroupEquals(thisG, g);
59             z++;
60             }
61         }
62     }
63 
assertGroupNotEquals(Group a, Group b)64     public static void assertGroupNotEquals(Group a, Group b) {
65         try {
66             assertGroupEquals(a, b);
67         } catch(AssertionError e) {
68             return;
69         }
70 
71         fail("Groups are equal!");
72     }
73 
assertGroupEquals(Group a, Group b)74     public static void assertGroupEquals(Group a, Group b) {
75 
76         if (a.getGraphsCount() != b.getGraphsCount()) {
77             fail();
78         }
79 
80         int z = 0;
81         for (InputGraph graph : a.getGraphs()) {
82             InputGraph otherGraph = b.getGraphs().get(z);
83             assertGraphEquals(graph, otherGraph);
84             z++;
85         }
86 
87         if (a.getMethod() == null || b.getMethod() == null) {
88             if (a.getMethod() != b.getMethod()) {
89                 fail();
90             }
91         } else {
92             if (!a.getMethod().equals(b.getMethod())) {
93                 fail();
94             }
95         }
96     }
97 
assertGraphNotEquals(InputGraph a, InputGraph b)98     public static void assertGraphNotEquals(InputGraph a, InputGraph b) {
99         try {
100             assertGraphEquals(a, b);
101         } catch(AssertionError e) {
102             return;
103         }
104 
105         fail("Graphs are equal!");
106     }
107 
assertGraphEquals(InputGraph a, InputGraph b)108     public static void assertGraphEquals(InputGraph a, InputGraph b) {
109 
110         if(!a.getNodesAsSet().equals(b.getNodesAsSet())) {
111             fail();
112         }
113 
114         if (!a.getEdges().equals(b.getEdges())) {
115             fail();
116         }
117 
118         if (a.getBlocks().equals(b.getBlocks())) {
119             fail();
120         }
121 
122         for (InputNode n : a.getNodes()) {
123             assertEquals(a.getBlock(n), b.getBlock(n));
124         }
125     }
126 }
127