Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 493136 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.gef4.dot.tests/src/org/eclipse/gef4/dot/tests/DotImportTests.java (+774 lines)
Lines 15-22 Link Here
15
15
16
import java.io.File;
16
import java.io.File;
17
17
18
import org.eclipse.gef4.dot.internal.DotAttributes;
18
import org.eclipse.gef4.dot.internal.DotImport;
19
import org.eclipse.gef4.dot.internal.DotImport;
20
import org.eclipse.gef4.graph.Edge;
19
import org.eclipse.gef4.graph.Graph;
21
import org.eclipse.gef4.graph.Graph;
22
import org.eclipse.gef4.graph.Node;
20
import org.junit.Assert;
23
import org.junit.Assert;
21
import org.junit.Test;
24
import org.junit.Test;
22
25
Lines 91-94 Link Here
91
		assertEquals(2, graph.getEdges().size());
94
		assertEquals(2, graph.getEdges().size());
92
	}
95
	}
93
96
97
	@Test
98
	public void edge_arrowhead() {
99
		// test global attribute
100
		Graph.Builder graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
101
				DotAttributes._TYPE__G__DIGRAPH);
102
		Node[] nodes = createNodes();
103
		Edge e1 = new Edge.Builder(nodes[0], nodes[1])
104
				.attr(DotAttributes._NAME__GNE, "1->2") //$NON-NLS-1$
105
				.attr(DotAttributes.ARROWHEAD__E, "crow") //$NON-NLS-1$
106
				.buildEdge();
107
		Edge e2 = new Edge.Builder(nodes[2], nodes[3])
108
				.attr(DotAttributes._NAME__GNE, "3->4") //$NON-NLS-1$
109
				.attr(DotAttributes.ARROWHEAD__E, "crow") //$NON-NLS-1$
110
				.buildEdge();
111
		Graph expected = graph.nodes(nodes).edges(e1, e2).build();
112
		testString(expected, DotSampleGraphs.EDGE_ARROWHEAD_GLOBAL);
113
114
		// test local attribute
115
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
116
				DotAttributes._TYPE__G__DIGRAPH);
117
		DotAttributes.setArrowHead(e1, "diamond");
118
		DotAttributes.setArrowHead(e2, "dot");
119
		expected = graph.nodes(nodes).edges(e1, e2).build();
120
		testString(expected, DotSampleGraphs.EDGE_ARROWHEAD_LOCAL);
121
122
		// test override attribute
123
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
124
				DotAttributes._TYPE__G__DIGRAPH);
125
		DotAttributes.setArrowHead(e1, "vee");
126
		DotAttributes.setArrowHead(e2, "tee");
127
		expected = graph.nodes(nodes).edges(e1, e2).build();
128
		testString(expected, DotSampleGraphs.EDGE_ARROWHEAD_OVERRIDE);
129
	}
130
131
	@Test
132
	public void edge_arrowsize() {
133
		// test global attribute
134
		Graph.Builder graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
135
				DotAttributes._TYPE__G__DIGRAPH);
136
		Node[] nodes = createNodes();
137
		Edge e1 = new Edge.Builder(nodes[0], nodes[1])
138
				.attr(DotAttributes._NAME__GNE, "1->2") //$NON-NLS-1$
139
				.attr(DotAttributes.ARROWSIZE__E, "1.5") //$NON-NLS-1$
140
				.buildEdge();
141
		Edge e2 = new Edge.Builder(nodes[2], nodes[3])
142
				.attr(DotAttributes._NAME__GNE, "3->4") //$NON-NLS-1$
143
				.attr(DotAttributes.ARROWSIZE__E, "1.5") //$NON-NLS-1$
144
				.buildEdge();
145
		Graph expected = graph.nodes(nodes).edges(e1, e2).build();
146
		testString(expected, DotSampleGraphs.EDGE_ARROWSIZE_GLOBAL);
147
148
		// test local attribute
149
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
150
				DotAttributes._TYPE__G__DIGRAPH);
151
		DotAttributes.setArrowSize(e1, "2.0");
152
		DotAttributes.setArrowSize(e2, "2.1");
153
		expected = graph.nodes(nodes).edges(e1, e2).build();
154
		testString(expected, DotSampleGraphs.EDGE_ARROWSIZE_LOCAL);
155
156
		// test override attribute
157
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
158
				DotAttributes._TYPE__G__DIGRAPH);
159
		DotAttributes.setArrowSize(e1, "2.3");
160
		DotAttributes.setArrowSize(e2, "2.2");
161
		expected = graph.nodes(nodes).edges(e1, e2).build();
162
		testString(expected, DotSampleGraphs.EDGE_ARROWSIZE_OVERRIDE);
163
	}
164
165
	@Test
166
	public void edge_arrowtail() {
167
		// test global attribute
168
		Graph.Builder graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
169
				DotAttributes._TYPE__G__DIGRAPH);
170
		Node[] nodes = createNodes();
171
		Edge e1 = new Edge.Builder(nodes[0], nodes[1])
172
				.attr(DotAttributes._NAME__GNE, "1->2") //$NON-NLS-1$
173
				.attr(DotAttributes.ARROWTAIL__E, "box") //$NON-NLS-1$
174
				.buildEdge();
175
		Edge e2 = new Edge.Builder(nodes[2], nodes[3])
176
				.attr(DotAttributes._NAME__GNE, "3->4") //$NON-NLS-1$
177
				.attr(DotAttributes.ARROWTAIL__E, "box") //$NON-NLS-1$
178
				.buildEdge();
179
		Graph expected = graph.nodes(nodes).edges(e1, e2).build();
180
		testString(expected, DotSampleGraphs.EDGE_ARROWTAIL_GLOBAL);
181
182
		// test local attribute
183
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
184
				DotAttributes._TYPE__G__DIGRAPH);
185
		DotAttributes.setArrowTail(e1, "lbox");
186
		DotAttributes.setArrowTail(e2, "rbox");
187
		expected = graph.nodes(nodes).edges(e1, e2).build();
188
		testString(expected, DotSampleGraphs.EDGE_ARROWTAIL_LOCAL);
189
190
		// test override attribute
191
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
192
				DotAttributes._TYPE__G__DIGRAPH);
193
		DotAttributes.setArrowTail(e1, "olbox");
194
		DotAttributes.setArrowTail(e2, "obox");
195
		expected = graph.nodes(nodes).edges(e1, e2).build();
196
		testString(expected, DotSampleGraphs.EDGE_ARROWTAIL_OVERRIDE);
197
	}
198
199
	@Test
200
	public void edge_dir() {
201
		// test global attribute
202
		Graph.Builder graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
203
				DotAttributes._TYPE__G__DIGRAPH);
204
		Node[] nodes = createNodes();
205
		Edge e1 = new Edge.Builder(nodes[0], nodes[1])
206
				.attr(DotAttributes._NAME__GNE, "1->2") //$NON-NLS-1$
207
				.attr(DotAttributes.DIR__E, "forward") //$NON-NLS-1$
208
				.buildEdge();
209
		Edge e2 = new Edge.Builder(nodes[2], nodes[3])
210
				.attr(DotAttributes._NAME__GNE, "3->4") //$NON-NLS-1$
211
				.attr(DotAttributes.DIR__E, "forward") //$NON-NLS-1$
212
				.buildEdge();
213
		Graph expected = graph.nodes(nodes).edges(e1, e2).build();
214
		testString(expected, DotSampleGraphs.EDGE_DIR_GLOBAL);
215
216
		// test local attribute
217
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
218
				DotAttributes._TYPE__G__DIGRAPH);
219
		DotAttributes.setDir(e1, "forward");
220
		DotAttributes.setDir(e2, "back");
221
		expected = graph.nodes(nodes).edges(e1, e2).build();
222
		testString(expected, DotSampleGraphs.EDGE_DIR_LOCAL);
223
224
		// test override attribute
225
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
226
				DotAttributes._TYPE__G__DIGRAPH);
227
		DotAttributes.setDir(e1, "both");
228
		DotAttributes.setDir(e2, "back");
229
		expected = graph.nodes(nodes).edges(e1, e2).build();
230
		testString(expected, DotSampleGraphs.EDGE_DIR_OVERRIDE);
231
	}
232
233
	@Test
234
	public void edge_headlabel() {
235
		// test global attribute
236
		Graph.Builder graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
237
				DotAttributes._TYPE__G__GRAPH);
238
		Node[] nodes = createNodes();
239
		Edge e1 = new Edge.Builder(nodes[0], nodes[1])
240
				.attr(DotAttributes._NAME__GNE, "1--2") //$NON-NLS-1$
241
				.attr(DotAttributes.HEADLABEL__E, "EdgeHeadLabel1") //$NON-NLS-1$
242
				.buildEdge();
243
		Edge e2 = new Edge.Builder(nodes[2], nodes[3])
244
				.attr(DotAttributes._NAME__GNE, "3--4") //$NON-NLS-1$
245
				.attr(DotAttributes.HEADLABEL__E, "EdgeHeadLabel1") //$NON-NLS-1$
246
				.buildEdge();
247
		Graph expected = graph.nodes(nodes).edges(e1, e2).build();
248
		testString(expected, DotSampleGraphs.EDGE_HEADLABEL_GLOBAL);
249
250
		// test local attribute
251
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
252
				DotAttributes._TYPE__G__GRAPH);
253
		DotAttributes.setHeadLabel(e1, "EdgeHeadLabel2");
254
		DotAttributes.setHeadLabel(e2, "EdgeHeadLabel3");
255
		expected = graph.nodes(nodes).edges(e1, e2).build();
256
		testString(expected, DotSampleGraphs.EDGE_HEADLABEL_LOCAL);
257
258
		// test override attribute
259
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
260
				DotAttributes._TYPE__G__GRAPH);
261
		DotAttributes.setHeadLabel(e1, "EdgeHeadLabel5");
262
		DotAttributes.setHeadLabel(e2, "EdgeHeadLabel4");
263
		expected = graph.nodes(nodes).edges(e1, e2).build();
264
		testString(expected, DotSampleGraphs.EDGE_HEADLABEL_OVERRIDE);
265
	}
266
267
	@Test
268
	public void edge_headlp() {
269
		// no global/override attribute tests, since they do not make sense
270
		// test local attribute
271
		Graph.Builder graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
272
				DotAttributes._TYPE__G__GRAPH);
273
		Node[] nodes = createNodes();
274
		Edge e1 = new Edge.Builder(nodes[0], nodes[1])
275
				.attr(DotAttributes._NAME__GNE, "1--2") //$NON-NLS-1$
276
				.attr(DotAttributes.HEAD_LP__E, "2.2,3.3") //$NON-NLS-1$
277
				.buildEdge();
278
		Edge e2 = new Edge.Builder(nodes[2], nodes[3])
279
				.attr(DotAttributes._NAME__GNE, "3--4") //$NON-NLS-1$
280
				.attr(DotAttributes.HEAD_LP__E, "-2.2,-3.3") //$NON-NLS-1$
281
				.buildEdge();
282
		Graph expected = graph.nodes(nodes).edges(e1, e2).build();
283
		testString(expected, DotSampleGraphs.EDGE_HEAD_LP_LOCAL);
284
	}
285
286
	@Test
287
	public void edge_id() {
288
		// no global/override attribute tests, since they do not make sense
289
		// test local attribute
290
		Graph.Builder graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
291
				DotAttributes._TYPE__G__GRAPH);
292
		Node[] nodes = createNodes();
293
		Edge e1 = new Edge.Builder(nodes[0], nodes[1])
294
				.attr(DotAttributes._NAME__GNE, "1--2") //$NON-NLS-1$
295
				.attr(DotAttributes.ID__GNE, "edgeID2") //$NON-NLS-1$
296
				.buildEdge();
297
		Edge e2 = new Edge.Builder(nodes[2], nodes[3])
298
				.attr(DotAttributes._NAME__GNE, "3--4") //$NON-NLS-1$
299
				.attr(DotAttributes.ID__GNE, "edgeID3") //$NON-NLS-1$
300
				.buildEdge();
301
		Graph expected = graph.nodes(nodes).edges(e1, e2).build();
302
		testString(expected, DotSampleGraphs.EDGE_ID_LOCAL);
303
	}
304
305
	@Test
306
	public void edge_label() {
307
		// test global attribute
308
		Graph.Builder graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
309
				DotAttributes._TYPE__G__GRAPH);
310
		Node[] nodes = createNodes();
311
		Edge e1 = new Edge.Builder(nodes[0], nodes[1])
312
				.attr(DotAttributes._NAME__GNE, "1--2") //$NON-NLS-1$
313
				.attr(DotAttributes.LABEL__GNE, "Edge1") //$NON-NLS-1$
314
				.buildEdge();
315
		Edge e2 = new Edge.Builder(nodes[2], nodes[3])
316
				.attr(DotAttributes._NAME__GNE, "3--4") //$NON-NLS-1$
317
				.attr(DotAttributes.LABEL__GNE, "Edge1") //$NON-NLS-1$
318
				.buildEdge();
319
		Graph expected = graph.nodes(nodes).edges(e1, e2).build();
320
		testString(expected, DotSampleGraphs.EDGE_LABEL_GLOBAL);
321
322
		// test local attribute
323
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
324
				DotAttributes._TYPE__G__GRAPH);
325
		DotAttributes.setLabel(e1, "Edge1");
326
		DotAttributes.setLabel(e2, "Edge2");
327
		expected = graph.nodes(nodes).edges(e1, e2).build();
328
		testString(expected, DotSampleGraphs.EDGE_LABEL_LOCAL);
329
330
		// test override attribute
331
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
332
				DotAttributes._TYPE__G__GRAPH);
333
		DotAttributes.setLabel(e1, "Edge4");
334
		DotAttributes.setLabel(e2, "Edge3");
335
		expected = graph.nodes(nodes).edges(e1, e2).build();
336
		testString(expected, DotSampleGraphs.EDGE_LABEL_OVERRIDE);
337
	}
338
339
	@Test
340
	public void edge_lp() {
341
		// no global/override attribute tests, since they do not make sense
342
		// test local attribute
343
		Graph.Builder graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
344
				DotAttributes._TYPE__G__GRAPH);
345
		Node[] nodes = createNodes();
346
		Edge e1 = new Edge.Builder(nodes[0], nodes[1])
347
				.attr(DotAttributes._NAME__GNE, "1--2") //$NON-NLS-1$
348
				.attr(DotAttributes.LP__GE, "0.3,0.4") //$NON-NLS-1$
349
				.buildEdge();
350
		Edge e2 = new Edge.Builder(nodes[2], nodes[3])
351
				.attr(DotAttributes._NAME__GNE, "3--4") //$NON-NLS-1$
352
				.attr(DotAttributes.LP__GE, "0.5,0.6") //$NON-NLS-1$
353
				.buildEdge();
354
		Graph expected = graph.nodes(nodes).edges(e1, e2).build();
355
		testString(expected, DotSampleGraphs.EDGE_LP_LOCAL);
356
	}
357
358
	@Test
359
	public void edge_pos() {
360
		// no global/override attribute tests, since they do not make sense
361
		// test local attribute
362
		Graph.Builder graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
363
				DotAttributes._TYPE__G__GRAPH);
364
		Node[] nodes = createNodes();
365
		Edge e1 = new Edge.Builder(nodes[0], nodes[1])
366
				.attr(DotAttributes._NAME__GNE, "1--2") //$NON-NLS-1$
367
				.attr(DotAttributes.POS__NE, "0.0,0.0 1.0,1.0 2.0,2.0 3.0,3.0") //$NON-NLS-1$
368
				.buildEdge();
369
		Edge e2 = new Edge.Builder(nodes[2], nodes[3])
370
				.attr(DotAttributes._NAME__GNE, "3--4") //$NON-NLS-1$
371
				.attr(DotAttributes.POS__NE, "4.0,4.0 5.0,5.0 6.0,6.0 7.0,7.0") //$NON-NLS-1$
372
				.buildEdge();
373
		Graph expected = graph.nodes(nodes).edges(e1, e2).build();
374
		testString(expected, DotSampleGraphs.EDGE_POS_LOCAL);
375
	}
376
377
	@Test
378
	public void edge_style() {
379
		// test global attribute
380
		Graph.Builder graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
381
				DotAttributes._TYPE__G__GRAPH);
382
		Node[] nodes = createNodes();
383
		Edge e1 = new Edge.Builder(nodes[0], nodes[1])
384
				.attr(DotAttributes._NAME__GNE, "1--2") //$NON-NLS-1$
385
				.attr(DotAttributes.STYLE__E, "dashed") //$NON-NLS-1$
386
				.buildEdge();
387
		Edge e2 = new Edge.Builder(nodes[2], nodes[3])
388
				.attr(DotAttributes._NAME__GNE, "3--4") //$NON-NLS-1$
389
				.attr(DotAttributes.STYLE__E, "dashed") //$NON-NLS-1$
390
				.buildEdge();
391
		Graph expected = graph.nodes(nodes).edges(e1, e2).build();
392
		testString(expected, DotSampleGraphs.EDGE_STYLE_GLOBAL);
393
394
		// test local attribute
395
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
396
				DotAttributes._TYPE__G__GRAPH);
397
		DotAttributes.setStyle(e1, "dashed");
398
		DotAttributes.setStyle(e2, "dotted");
399
		expected = graph.nodes(nodes).edges(e1, e2).build();
400
		testString(expected, DotSampleGraphs.EDGE_STYLE_LOCAL);
401
402
		// test override attribute
403
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
404
				DotAttributes._TYPE__G__GRAPH);
405
		DotAttributes.setStyle(e1, "bold, dotted");
406
		DotAttributes.setStyle(e2, "bold");
407
		expected = graph.nodes(nodes).edges(e1, e2).build();
408
		testString(expected, DotSampleGraphs.EDGE_STYLE_OVERRIDE);
409
	}
410
411
	@Test
412
	public void edge_taillabel() {
413
		// test global attribute
414
		Graph.Builder graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
415
				DotAttributes._TYPE__G__GRAPH);
416
		Node[] nodes = createNodes();
417
		Edge e1 = new Edge.Builder(nodes[0], nodes[1])
418
				.attr(DotAttributes._NAME__GNE, "1--2") //$NON-NLS-1$
419
				.attr(DotAttributes.TAILLABEL__E, "EdgeTailLabel1") //$NON-NLS-1$
420
				.buildEdge();
421
		Edge e2 = new Edge.Builder(nodes[2], nodes[3])
422
				.attr(DotAttributes._NAME__GNE, "3--4") //$NON-NLS-1$
423
				.attr(DotAttributes.TAILLABEL__E, "EdgeTailLabel1") //$NON-NLS-1$
424
				.buildEdge();
425
		Graph expected = graph.nodes(nodes).edges(e1, e2).build();
426
		testString(expected, DotSampleGraphs.EDGE_TAILLABEL_GLOBAL);
427
428
		// test local attribute
429
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
430
				DotAttributes._TYPE__G__GRAPH);
431
		DotAttributes.setTailLabel(e1, "EdgeTailLabel2");
432
		DotAttributes.setTailLabel(e2, "EdgeTailLabel3");
433
		expected = graph.nodes(nodes).edges(e1, e2).build();
434
		testString(expected, DotSampleGraphs.EDGE_TAILLABEL_LOCAL);
435
436
		// test override attribute
437
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
438
				DotAttributes._TYPE__G__GRAPH);
439
		DotAttributes.setTailLabel(e1, "EdgeTailLabel5");
440
		DotAttributes.setTailLabel(e2, "EdgeTailLabel4");
441
		expected = graph.nodes(nodes).edges(e1, e2).build();
442
		testString(expected, DotSampleGraphs.EDGE_TAILLABEL_OVERRIDE);
443
	}
444
445
	@Test
446
	public void edge_taillp() {
447
		// no global/override attribute tests, since they do not make sense
448
		// test local attribute
449
		Graph.Builder graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
450
				DotAttributes._TYPE__G__GRAPH);
451
		Node[] nodes = createNodes();
452
		Edge e1 = new Edge.Builder(nodes[0], nodes[1])
453
				.attr(DotAttributes._NAME__GNE, "1--2") //$NON-NLS-1$
454
				.attr(DotAttributes.TAIL_LP__E, "-4.5,-6.7") //$NON-NLS-1$
455
				.buildEdge();
456
		Edge e2 = new Edge.Builder(nodes[2], nodes[3])
457
				.attr(DotAttributes._NAME__GNE, "3--4") //$NON-NLS-1$
458
				.attr(DotAttributes.TAIL_LP__E, "-8.9,-10.11") //$NON-NLS-1$
459
				.buildEdge();
460
		Graph expected = graph.nodes(nodes).edges(e1, e2).build();
461
		testString(expected, DotSampleGraphs.EDGE_TAIL_LP_LOCAL);
462
	}
463
464
	@Test
465
	public void edge_xlabel() {
466
		// test global attribute
467
		Graph.Builder graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
468
				DotAttributes._TYPE__G__GRAPH);
469
		Node[] nodes = createNodes();
470
		Edge e1 = new Edge.Builder(nodes[0], nodes[1])
471
				.attr(DotAttributes._NAME__GNE, "1--2") //$NON-NLS-1$
472
				.attr(DotAttributes.XLABEL__NE, "EdgeExternalLabel1") //$NON-NLS-1$
473
				.buildEdge();
474
		Edge e2 = new Edge.Builder(nodes[2], nodes[3])
475
				.attr(DotAttributes._NAME__GNE, "3--4") //$NON-NLS-1$
476
				.attr(DotAttributes.XLABEL__NE, "EdgeExternalLabel1") //$NON-NLS-1$
477
				.buildEdge();
478
		Graph expected = graph.nodes(nodes).edges(e1, e2).build();
479
		testString(expected, DotSampleGraphs.EDGE_XLABEL_GLOBAL);
480
481
		// test local attribute
482
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
483
				DotAttributes._TYPE__G__GRAPH);
484
		DotAttributes.setXLabel(e1, "EdgeExternalLabel2");
485
		DotAttributes.setXLabel(e2, "EdgeExternalLabel3");
486
		expected = graph.nodes(nodes).edges(e1, e2).build();
487
		testString(expected, DotSampleGraphs.EDGE_XLABEL_LOCAL);
488
489
		// test override attribute
490
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
491
				DotAttributes._TYPE__G__GRAPH);
492
		DotAttributes.setXLabel(e1, "EdgeExternalLabel5");
493
		DotAttributes.setXLabel(e2, "EdgeExternalLabel4");
494
		expected = graph.nodes(nodes).edges(e1, e2).build();
495
		testString(expected, DotSampleGraphs.EDGE_XLABEL_OVERRIDE);
496
	}
497
498
	@Test
499
	public void edge_xlp() {
500
		// no global/override attribute tests, since they do not make sense
501
		// test local attribute
502
		Graph.Builder graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
503
				DotAttributes._TYPE__G__GRAPH);
504
		Node[] nodes = createNodes();
505
		Edge e1 = new Edge.Builder(nodes[0], nodes[1])
506
				.attr(DotAttributes._NAME__GNE, "1--2") //$NON-NLS-1$
507
				.attr(DotAttributes.XLP__NE, ".3,.4") //$NON-NLS-1$
508
				.buildEdge();
509
		Edge e2 = new Edge.Builder(nodes[2], nodes[3])
510
				.attr(DotAttributes._NAME__GNE, "3--4") //$NON-NLS-1$
511
				.attr(DotAttributes.XLP__NE, ".5,.6") //$NON-NLS-1$
512
				.buildEdge();
513
		Graph expected = graph.nodes(nodes).edges(e1, e2).build();
514
		testString(expected, DotSampleGraphs.EDGE_XLP_LOCAL);
515
	}
516
517
	@Test
518
	public void node_distortion() {
519
		// test global attribute
520
		Graph.Builder graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
521
				DotAttributes._TYPE__G__GRAPH);
522
		Node n1 = new Node.Builder().attr(DotAttributes._NAME__GNE, "1") //$NON-NLS-1$
523
				.attr(DotAttributes.DISTORTION__N, "1.1").buildNode();
524
		Node n2 = new Node.Builder().attr(DotAttributes._NAME__GNE, "2") //$NON-NLS-1$
525
				.attr(DotAttributes.DISTORTION__N, "1.1").buildNode();
526
		Graph expected = graph.nodes(n1, n2).build();
527
		testString(expected, DotSampleGraphs.NODE_DISTORTION_GLOBAL);
528
529
		// test local attribute
530
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
531
				DotAttributes._TYPE__G__GRAPH);
532
		DotAttributes.setDistortion(n1, "1.2");
533
		DotAttributes.setDistortion(n2, "1.3");
534
		expected = graph.nodes(n1, n2).build();
535
		testString(expected, DotSampleGraphs.NODE_DISTORTION_LOCAL);
536
537
		// test override attribute
538
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
539
				DotAttributes._TYPE__G__GRAPH);
540
		DotAttributes.setDistortion(n1, "1.5");
541
		DotAttributes.setDistortion(n2, "1.4");
542
		expected = graph.nodes(n1, n2).build();
543
		testString(expected, DotSampleGraphs.NODE_DISTORTION_OVERRIDE);
544
	}
545
546
	@Test
547
	public void node_fixedsize() {
548
		// test global attribute
549
		Graph.Builder graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
550
				DotAttributes._TYPE__G__GRAPH);
551
		Node n1 = new Node.Builder().attr(DotAttributes._NAME__GNE, "1") //$NON-NLS-1$
552
				.attr(DotAttributes.FIXEDSIZE__N, "true").buildNode();
553
		Node n2 = new Node.Builder().attr(DotAttributes._NAME__GNE, "2") //$NON-NLS-1$
554
				.attr(DotAttributes.FIXEDSIZE__N, "true").buildNode();
555
		Graph expected = graph.nodes(n1, n2).build();
556
		testString(expected, DotSampleGraphs.NODE_FIXEDSIZE_GLOBAL);
557
558
		// test local attribute
559
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
560
				DotAttributes._TYPE__G__GRAPH);
561
		DotAttributes.setFixedSizeParsed(n1, true);
562
		DotAttributes.setFixedSizeParsed(n2, false);
563
		expected = graph.nodes(n1, n2).build();
564
		testString(expected, DotSampleGraphs.NODE_FIXEDSIZE_LOCAL);
565
566
		// test override attribute
567
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
568
				DotAttributes._TYPE__G__GRAPH);
569
		DotAttributes.setFixedSizeParsed(n1, false);
570
		DotAttributes.setFixedSizeParsed(n2, true);
571
		expected = graph.nodes(n1, n2).build();
572
		testString(expected, DotSampleGraphs.NODE_FIXEDSIZE_OVERRIDE);
573
	}
574
575
	@Test
576
	public void node_height() {
577
		// test global attribute
578
		Graph.Builder graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
579
				DotAttributes._TYPE__G__GRAPH);
580
		Node n1 = new Node.Builder().attr(DotAttributes._NAME__GNE, "1") //$NON-NLS-1$
581
				.attr(DotAttributes.HEIGHT__N, "1.2").buildNode();
582
		Node n2 = new Node.Builder().attr(DotAttributes._NAME__GNE, "2") //$NON-NLS-1$
583
				.attr(DotAttributes.HEIGHT__N, "1.2").buildNode();
584
		Graph expected = graph.nodes(n1, n2).build();
585
		testString(expected, DotSampleGraphs.NODE_HEIGHT_GLOBAL);
586
587
		// test local attribute
588
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
589
				DotAttributes._TYPE__G__GRAPH);
590
		DotAttributes.setHeightParsed(n1, 3.4);
591
		DotAttributes.setHeightParsed(n2, 5.6);
592
		expected = graph.nodes(n1, n2).build();
593
		testString(expected, DotSampleGraphs.NODE_HEIGHT_LOCAL);
594
595
		// test override attribute
596
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
597
				DotAttributes._TYPE__G__GRAPH);
598
		DotAttributes.setHeightParsed(n1, 9.11);
599
		DotAttributes.setHeightParsed(n2, 7.8);
600
		expected = graph.nodes(n1, n2).build();
601
		testString(expected, DotSampleGraphs.NODE_HEIGHT_OVERRIDE);
602
	}
603
604
	@Test
605
	public void node_id() {
606
		// no global/override attribute tests, since they do not make sense
607
		// test local attribute
608
		Graph.Builder graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
609
				DotAttributes._TYPE__G__GRAPH);
610
		Node n1 = new Node.Builder().attr(DotAttributes._NAME__GNE, "1") //$NON-NLS-1$
611
				.attr(DotAttributes.ID__GNE, "NodeID1").buildNode(); //$NON-NLS-1$ .buildNode();
612
		Node n2 = new Node.Builder().attr(DotAttributes._NAME__GNE, "2") //$NON-NLS-1$
613
				.attr(DotAttributes.ID__GNE, "NodeID2").buildNode();
614
		Graph expected = graph.nodes(n1, n2).build();
615
		testString(expected, DotSampleGraphs.NODE_ID_LOCAL);
616
	}
617
618
	@Test
619
	public void node_label() {
620
		// test global attribute
621
		Graph.Builder graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
622
				DotAttributes._TYPE__G__GRAPH);
623
		Node n1 = new Node.Builder().attr(DotAttributes._NAME__GNE, "1") //$NON-NLS-1$
624
				.attr(DotAttributes.LABEL__GNE, "Node1").buildNode();
625
		Node n2 = new Node.Builder().attr(DotAttributes._NAME__GNE, "2") //$NON-NLS-1$
626
				.attr(DotAttributes.LABEL__GNE, "Node1").buildNode();
627
		Graph expected = graph.nodes(n1, n2).build();
628
		testString(expected, DotSampleGraphs.NODE_LABEL_GLOBAL);
629
630
		// test local attribute
631
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
632
				DotAttributes._TYPE__G__GRAPH);
633
		DotAttributes.setLabel(n1, "Node1");
634
		DotAttributes.setLabel(n2, "Node2");
635
		expected = graph.nodes(n1, n2).build();
636
		testString(expected, DotSampleGraphs.NODE_LABEL_LOCAL);
637
638
		// test override attribute
639
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
640
				DotAttributes._TYPE__G__GRAPH);
641
		DotAttributes.setLabel(n1, "Node4");
642
		DotAttributes.setLabel(n2, "Node3");
643
		expected = graph.nodes(n1, n2).build();
644
		testString(expected, DotSampleGraphs.NODE_LABEL_OVERRIDE);
645
	}
646
647
	@Test
648
	public void node_pos() {
649
		// no global/override attribute tests, since they do not make sense
650
		// test local attribute
651
		Graph.Builder graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
652
				DotAttributes._TYPE__G__GRAPH);
653
		Node n1 = new Node.Builder().attr(DotAttributes._NAME__GNE, "1") //$NON-NLS-1$
654
				.attr(DotAttributes.POS__NE, ".1,.2!").buildNode(); //$NON-NLS-1$ .buildNode();
655
		Node n2 = new Node.Builder().attr(DotAttributes._NAME__GNE, "2") //$NON-NLS-1$
656
				.attr(DotAttributes.POS__NE, "-0.1,-2.3!").buildNode();
657
		Graph expected = graph.nodes(n1, n2).build();
658
		testString(expected, DotSampleGraphs.NODE_POS_LOCAL);
659
	}
660
661
	@Test
662
	public void node_shape() {
663
		// test global attribute
664
		Graph.Builder graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
665
				DotAttributes._TYPE__G__GRAPH);
666
		Node n1 = new Node.Builder().attr(DotAttributes._NAME__GNE, "1") //$NON-NLS-1$
667
				.attr(DotAttributes.SHAPE__N, "box").buildNode();
668
		Node n2 = new Node.Builder().attr(DotAttributes._NAME__GNE, "2") //$NON-NLS-1$
669
				.attr(DotAttributes.SHAPE__N, "box").buildNode();
670
		Graph expected = graph.nodes(n1, n2).build();
671
		testString(expected, DotSampleGraphs.NODE_SHAPE_GLOBAL);
672
673
		// test local attribute
674
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
675
				DotAttributes._TYPE__G__GRAPH);
676
		DotAttributes.setShape(n1, "oval");
677
		DotAttributes.setShape(n2, "house");
678
		expected = graph.nodes(n1, n2).build();
679
		testString(expected, DotSampleGraphs.NODE_SHAPE_LOCAL);
680
681
		// test override attribute
682
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
683
				DotAttributes._TYPE__G__GRAPH);
684
		DotAttributes.setShape(n1, "circle");
685
		DotAttributes.setShape(n2, "pentagon");
686
		expected = graph.nodes(n1, n2).build();
687
		testString(expected, DotSampleGraphs.NODE_SHAPE_OVERRIDE);
688
	}
689
690
	@Test
691
	public void node_sides() {
692
		// test global attribute
693
		Graph.Builder graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
694
				DotAttributes._TYPE__G__GRAPH);
695
		Node n1 = new Node.Builder().attr(DotAttributes._NAME__GNE, "1") //$NON-NLS-1$
696
				.attr(DotAttributes.SIDES__N, "3").buildNode();
697
		Node n2 = new Node.Builder().attr(DotAttributes._NAME__GNE, "2") //$NON-NLS-1$
698
				.attr(DotAttributes.SIDES__N, "3").buildNode();
699
		Graph expected = graph.nodes(n1, n2).build();
700
		testString(expected, DotSampleGraphs.NODE_SIDES_GLOBAL);
701
702
		// test local attribute
703
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
704
				DotAttributes._TYPE__G__GRAPH);
705
		DotAttributes.setSidesParsed(n1, 4);
706
		DotAttributes.setSidesParsed(n2, 5);
707
		expected = graph.nodes(n1, n2).build();
708
		testString(expected, DotSampleGraphs.NODE_SIDES_LOCAL);
709
710
		// test override attribute
711
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
712
				DotAttributes._TYPE__G__GRAPH);
713
		DotAttributes.setSidesParsed(n1, 7);
714
		DotAttributes.setSidesParsed(n2, 6);
715
		expected = graph.nodes(n1, n2).build();
716
		testString(expected, DotSampleGraphs.NODE_SIDES_OVERRIDE);
717
	}
718
719
	@Test
720
	public void node_skew() {
721
		// test global attribute
722
		Graph.Builder graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
723
				DotAttributes._TYPE__G__GRAPH);
724
		Node n1 = new Node.Builder().attr(DotAttributes._NAME__GNE, "1") //$NON-NLS-1$
725
				.attr(DotAttributes.SKEW__N, "1.2").buildNode();
726
		Node n2 = new Node.Builder().attr(DotAttributes._NAME__GNE, "2") //$NON-NLS-1$
727
				.attr(DotAttributes.SKEW__N, "1.2").buildNode();
728
		Graph expected = graph.nodes(n1, n2).build();
729
		testString(expected, DotSampleGraphs.NODE_SKEW_GLOBAL);
730
731
		// test local attribute
732
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
733
				DotAttributes._TYPE__G__GRAPH);
734
		DotAttributes.setSkewParsed(n1, 3.4);
735
		DotAttributes.setSkewParsed(n2, 5.6);
736
		expected = graph.nodes(n1, n2).build();
737
		testString(expected, DotSampleGraphs.NODE_SKEW_LOCAL);
738
739
		// test override attribute
740
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
741
				DotAttributes._TYPE__G__GRAPH);
742
		DotAttributes.setSkewParsed(n1, -7.8);
743
		DotAttributes.setSkewParsed(n2, 7.8);
744
		expected = graph.nodes(n1, n2).build();
745
		testString(expected, DotSampleGraphs.NODE_SKEW_OVERRIDE);
746
	}
747
748
	@Test
749
	public void node_style() {
750
		// test global attribute
751
		Graph.Builder graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
752
				DotAttributes._TYPE__G__GRAPH);
753
		Node n1 = new Node.Builder().attr(DotAttributes._NAME__GNE, "1") //$NON-NLS-1$
754
				.attr(DotAttributes.STYLE__E, "solid, dashed").buildNode();
755
		Node n2 = new Node.Builder().attr(DotAttributes._NAME__GNE, "2") //$NON-NLS-1$
756
				.attr(DotAttributes.STYLE__E, "solid, dashed").buildNode();
757
		Graph expected = graph.nodes(n1, n2).build();
758
		testString(expected, DotSampleGraphs.NODE_STYLE_GLOBAL);
759
760
		// test local attribute
761
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
762
				DotAttributes._TYPE__G__GRAPH);
763
		DotAttributes.setStyle(n1, "bold");
764
		DotAttributes.setStyle(n2, "dotted");
765
		expected = graph.nodes(n1, n2).build();
766
		testString(expected, DotSampleGraphs.NODE_STYLE_LOCAL);
767
768
		// test override attribute
769
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
770
				DotAttributes._TYPE__G__GRAPH);
771
		DotAttributes.setStyle(n1, "rounded");
772
		DotAttributes.setStyle(n2, "bold, filled");
773
		expected = graph.nodes(n1, n2).build();
774
		testString(expected, DotSampleGraphs.NODE_STYLE_OVERRIDE);
775
	}
776
777
	@Test
778
	public void node_width() {
779
		// test global attribute
780
		Graph.Builder graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
781
				DotAttributes._TYPE__G__GRAPH);
782
		Node n1 = new Node.Builder().attr(DotAttributes._NAME__GNE, "1") //$NON-NLS-1$
783
				.attr(DotAttributes.WIDTH__N, "1.2").buildNode();
784
		Node n2 = new Node.Builder().attr(DotAttributes._NAME__GNE, "2") //$NON-NLS-1$
785
				.attr(DotAttributes.WIDTH__N, "1.2").buildNode();
786
		Graph expected = graph.nodes(n1, n2).build();
787
		testString(expected, DotSampleGraphs.NODE_WIDTH_GLOBAL);
788
789
		// test local attribute
790
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
791
				DotAttributes._TYPE__G__GRAPH);
792
		DotAttributes.setWidthParsed(n1, 3.4);
793
		DotAttributes.setWidthParsed(n2, 5.6);
794
		expected = graph.nodes(n1, n2).build();
795
		testString(expected, DotSampleGraphs.NODE_WIDTH_LOCAL);
796
797
		// test override attribute
798
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
799
				DotAttributes._TYPE__G__GRAPH);
800
		DotAttributes.setWidthParsed(n1, 9.11);
801
		DotAttributes.setWidthParsed(n2, 7.8);
802
		expected = graph.nodes(n1, n2).build();
803
		testString(expected, DotSampleGraphs.NODE_WIDTH_OVERRIDE);
804
	}
805
806
	@Test
807
	public void node_xlabel() {
808
		// test global attribute
809
		Graph.Builder graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
810
				DotAttributes._TYPE__G__GRAPH);
811
		Node n1 = new Node.Builder().attr(DotAttributes._NAME__GNE, "1") //$NON-NLS-1$
812
				.attr(DotAttributes.XLABEL__NE, "NodeExternalLabel1")
813
				.buildNode();
814
		Node n2 = new Node.Builder().attr(DotAttributes._NAME__GNE, "2") //$NON-NLS-1$
815
				.attr(DotAttributes.XLABEL__NE, "NodeExternalLabel1")
816
				.buildNode();
817
		Graph expected = graph.nodes(n1, n2).build();
818
		testString(expected, DotSampleGraphs.NODE_XLABEL_GLOBAL);
819
820
		// test local attribute
821
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
822
				DotAttributes._TYPE__G__GRAPH);
823
		DotAttributes.setXLabel(n1, "NodeExternalLabel2");
824
		DotAttributes.setXLabel(n2, "NodeExternalLabel3");
825
		expected = graph.nodes(n1, n2).build();
826
		testString(expected, DotSampleGraphs.NODE_XLABEL_LOCAL);
827
828
		// test override attribute
829
		graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
830
				DotAttributes._TYPE__G__GRAPH);
831
		DotAttributes.setXLabel(n1, "NodeExternalLabel5");
832
		DotAttributes.setXLabel(n2, "NodeExternalLabel4");
833
		expected = graph.nodes(n1, n2).build();
834
		testString(expected, DotSampleGraphs.NODE_XLABEL_OVERRIDE);
835
	}
836
837
	@Test
838
	public void node_xlp() {
839
		// no global/override attribute tests, since they do not make sense
840
		// test local attribute
841
		Graph.Builder graph = new Graph.Builder().attr(DotAttributes._TYPE__G,
842
				DotAttributes._TYPE__G__GRAPH);
843
		Node n1 = new Node.Builder().attr(DotAttributes._NAME__GNE, "1") //$NON-NLS-1$
844
				.attr(DotAttributes.XLP__NE, "-0.3,-0.4").buildNode(); //$NON-NLS-1$ .buildNode();
845
		Node n2 = new Node.Builder().attr(DotAttributes._NAME__GNE, "2") //$NON-NLS-1$
846
				.attr(DotAttributes.XLP__NE, "-1.5,-1.6").buildNode();
847
		Graph expected = graph.nodes(n1, n2).build();
848
		testString(expected, DotSampleGraphs.NODE_XLP_LOCAL);
849
	}
850
851
	private Node[] createNodes() {
852
		Node n1 = new Node.Builder().attr(DotAttributes._NAME__GNE, "1") //$NON-NLS-1$
853
				.buildNode();
854
		Node n2 = new Node.Builder().attr(DotAttributes._NAME__GNE, "2") //$NON-NLS-1$
855
				.buildNode();
856
		Node n3 = new Node.Builder().attr(DotAttributes._NAME__GNE, "3") //$NON-NLS-1$
857
				.buildNode();
858
		Node n4 = new Node.Builder().attr(DotAttributes._NAME__GNE, "4") //$NON-NLS-1$
859
				.buildNode();
860
		return new Node[] { n1, n2, n3, n4 };
861
	}
862
863
	private void testString(Graph expected, String dot) {
864
		Graph graph = new DotImport().importDot(dot);
865
		Assert.assertNotNull("Resulting graph must not be null", graph); //$NON-NLS-1$
866
		Assert.assertEquals(expected.toString(), graph.toString());
867
	}
94
}
868
}
(-)a/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/DotInterpreter.java (+26 lines)
Lines 290-295 Link Here
290
		if (skew != null) {
290
		if (skew != null) {
291
			DotAttributes.setSkew(node, skew);
291
			DotAttributes.setSkew(node, skew);
292
		}
292
		}
293
294
		// style
295
		String style = getAttributeValue(nodeStmt, DotAttributes.STYLE__E);
296
		if (style != null) {
297
			DotAttributes.setStyle(node, style);
298
		}
293
		return super.caseNodeStmt(nodeStmt);
299
		return super.caseNodeStmt(nodeStmt);
294
	}
300
	}
295
301
Lines 486-491 Link Here
486
				DotAttributes.setFixedSize(node,
492
				DotAttributes.setFixedSize(node,
487
						globalNodeAttributes.get(DotAttributes.FIXEDSIZE__N));
493
						globalNodeAttributes.get(DotAttributes.FIXEDSIZE__N));
488
			}
494
			}
495
			if (globalNodeAttributes.containsKey(DotAttributes.DISTORTION__N)) {
496
				DotAttributes.setDistortion(node,
497
						globalNodeAttributes.get(DotAttributes.DISTORTION__N));
498
			}
499
			if (globalNodeAttributes.containsKey(DotAttributes.SHAPE__N)) {
500
				DotAttributes.setShape(node,
501
						globalNodeAttributes.get(DotAttributes.SHAPE__N));
502
			}
503
			if (globalNodeAttributes.containsKey(DotAttributes.SIDES__N)) {
504
				DotAttributes.setSides(node,
505
						globalNodeAttributes.get(DotAttributes.SIDES__N));
506
			}
507
			if (globalNodeAttributes.containsKey(DotAttributes.SKEW__N)) {
508
				DotAttributes.setSkew(node,
509
						globalNodeAttributes.get(DotAttributes.SKEW__N));
510
			}
511
			if (globalNodeAttributes.containsKey(DotAttributes.STYLE__E)) {
512
				DotAttributes.setStyle(node,
513
						globalNodeAttributes.get(DotAttributes.STYLE__E));
514
			}
489
		}
515
		}
490
		return nodesByName.get(nodeName);
516
		return nodesByName.get(nodeName);
491
	}
517
	}

Return to bug 493136