Gridarta Editor
ArchetypeTypeTest.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2015 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.model.archetypetype;
21 
22 import java.util.Iterator;
32 import org.junit.Assert;
33 import org.junit.Test;
34 
39 public class ArchetypeTypeTest {
40 
44  @Test
45  public void testAttributes1() {
46  final ResourceIcons resourceIcons = new ResourceIcons();
47  final FaceObjects faceObjects = new TestFaceObjects();
48  final FaceObjectProviders faceObjectProviders = new FaceObjectProviders(0, faceObjects, resourceIcons);
49  final AnimationObjects animationObjects = new TestAnimationObjects();
51  final Attributes archetype = new TestDefaultArchetype("base", faceObjectProviders, animationObjects);
52 
53  final ArchetypeType archetypeType1 = new ArchetypeType("name1", 1, "", true, null, false, "description", "use", typeAttributes);
54  Assert.assertEquals("name1 (1)", archetypeType1.getDisplayName(archetype));
55  }
56 
60  @Test
61  public void testAttributes2() {
62  final ResourceIcons resourceIcons = new ResourceIcons();
63  final FaceObjects faceObjects = new TestFaceObjects();
64  final FaceObjectProviders faceObjectProviders = new FaceObjectProviders(0, faceObjects, resourceIcons);
65  final AnimationObjects animationObjects = new TestAnimationObjects();
67  final BaseObject<?, ?, ?, ?> archetype = new TestDefaultArchetype("base", faceObjectProviders, animationObjects);
68 
69  final ArchetypeType archetypeType2 = new ArchetypeType("name2", 1, "a=${a}${a}", true, null, false, "description", "use", typeAttributes);
70  Assert.assertEquals("name2 (1) [a=]", archetypeType2.getDisplayName(archetype));
71 
72  archetype.setObjectText("a xyz\n");
73  Assert.assertEquals("name2 (1) [a=xyzxyz]", archetypeType2.getDisplayName(archetype));
74 
75  archetype.setObjectText("a ${a}\n");
76  Assert.assertEquals("name2 (1) [a=${a}${a}]", archetypeType2.getDisplayName(archetype));
77 
78  // syntax errors are not fatal
79  final ArchetypeType archetypeType3 = new ArchetypeType("name", 1, "${}", true, null, false, "description", "use", typeAttributes);
80  Assert.assertEquals("name (1) []", archetypeType3.getDisplayName(archetype));
81 
82  final ArchetypeType archetypeType4 = new ArchetypeType("name", 1, "${a", true, null, false, "description", "use", typeAttributes);
83  Assert.assertEquals("name (1) [${a]", archetypeType4.getDisplayName(archetype));
84  }
85 
89  @Test
90  public void testAttributes3() {
91  final ResourceIcons resourceIcons = new ResourceIcons();
92  final FaceObjects faceObjects = new TestFaceObjects();
93  final FaceObjectProviders faceObjectProviders = new FaceObjectProviders(0, faceObjects, resourceIcons);
94  final AnimationObjects animationObjects = new TestAnimationObjects();
96  final BaseObject<?, ?, ?, ?> archetype = new TestDefaultArchetype("base", faceObjectProviders, animationObjects);
97 
98  final ArchetypeType archetypeType2 = new ArchetypeType("name2", 1, "a=${a?True:False}", true, null, false, "description", "use", typeAttributes);
99  Assert.assertEquals("name2 (1) [a=False]", archetypeType2.getDisplayName(archetype));
100 
101  archetype.setObjectText("a xyz\n");
102  Assert.assertEquals("name2 (1) [a=True]", archetypeType2.getDisplayName(archetype));
103 
104  archetype.setObjectText("a 0\n");
105  Assert.assertEquals("name2 (1) [a=False]", archetypeType2.getDisplayName(archetype));
106 
107  // empty replacements are allowed
108  final ArchetypeType archetypeType3 = new ArchetypeType("name", 1, "${a?:}", true, null, false, "description", "use", typeAttributes);
109  archetype.setObjectText("a 0\n");
110  Assert.assertEquals("name (1) []", archetypeType3.getDisplayName(archetype));
111  archetype.setObjectText("a 1\n");
112  Assert.assertEquals("name (1) []", archetypeType3.getDisplayName(archetype));
113 
114  // replacements with multiple colons
115  final ArchetypeType archetypeType4 = new ArchetypeType("name", 1, "${a?b:c:d}", true, null, false, "description", "use", typeAttributes);
116  archetype.setObjectText("a 0\n");
117  Assert.assertEquals("name (1) [c:d]", archetypeType4.getDisplayName(archetype));
118  archetype.setObjectText("a 1\n");
119  Assert.assertEquals("name (1) [b]", archetypeType4.getDisplayName(archetype));
120 
121  // syntax errors are not fatal
122  final ArchetypeType archetypeType5 = new ArchetypeType("name", 1, "${?", true, null, false, "description", "use", typeAttributes);
123  archetype.setObjectText("a 0\n");
124  Assert.assertEquals("name (1) [${?]", archetypeType5.getDisplayName(archetype));
125  archetype.setObjectText("a 1\n");
126  Assert.assertEquals("name (1) [${?]", archetypeType5.getDisplayName(archetype));
127 
128  final ArchetypeType archetypeType6 = new ArchetypeType("name", 1, "${a?", true, null, false, "description", "use", typeAttributes);
129  archetype.setObjectText("a 0\n");
130  Assert.assertEquals("name (1) [${a?]", archetypeType6.getDisplayName(archetype));
131  archetype.setObjectText("a 1\n");
132  Assert.assertEquals("name (1) [${a?]", archetypeType6.getDisplayName(archetype));
133 
134  final ArchetypeType archetypeType7 = new ArchetypeType("name", 1, "${a?:", true, null, false, "description", "use", typeAttributes);
135  archetype.setObjectText("a 0\n");
136  Assert.assertEquals("name (1) [${a?:]", archetypeType7.getDisplayName(archetype));
137  archetype.setObjectText("a 1\n");
138  Assert.assertEquals("name (1) [${a?:]", archetypeType7.getDisplayName(archetype));
139  }
140 
145  @Test(expected = UnsupportedOperationException.class)
146  public void testIteratorReadOnly() {
147  final ArchetypeAttributeSection archetypeAttributeSection = new ArchetypeAttributeSection("section");
148  archetypeAttributeSection.add(new ArchetypeAttributeInt("name", "name", "", 1, 0, 0, 0, 0));
149  final Iterable<?> archetypeType = new ArchetypeType("name", 0, "", false, null, false, null, null, new ArchetypeAttributesDefinition());
150  final Iterator<?> iterator = archetypeType.iterator();
151  Assert.assertTrue(iterator.hasNext());
152  iterator.next();
153  iterator.remove();
154  }
155 
156 }
A FaceObjects for regression tests.
Gridarta can handle frame information of animations and allow the selection of an animation using a t...
An AnimationObjects for regression tests.
String getDisplayName(@NotNull final Attributes baseObject)
Returns a description of this type.
Contains the data of one Gridarta Object-Type.
void testAttributes3()
Checks that ${xxx?true:false} expansions work correctly.
Base package of all Gridarta classes.
void testAttributes2()
Checks that ${xxx} expansions work correctly.
An Archetype implementation for testing purposes.
AnimationObjects is a container for AnimationObjects.
void add(@NotNull final ArchetypeAttribute archetypeAttribute)
Adds an ArchetypeAttribute.
FaceObjects is a container for FaceObjects.
void setObjectText(@NotNull String objectText)
Sets.
void testIteratorReadOnly()
Checks that ArchetypeType#iterator() returns a read-only iterator.
An ArchetypeAttribute for selecting integer values.
Provider for faces of GameObjects and Archetypes.
The face is the appearance of an object.
Creates ImageIcon instances from resources.
void testAttributes1()
Checks that empty expansions work correctly.