001 /*
002 * Copyright (c) 2005 Jens Schou, Staffan Gustafsson, Björn Lanneskog,
003 * Einar Pehrson and Sebastian Kekkonen
004 *
005 * This file is part of
006 * CleanSheets Extension for Test Cases
007 *
008 * CleanSheets Extension for Test Cases is free software; you can
009 * redistribute it and/or modify it under the terms of the GNU General Public
010 * License as published by the Free Software Foundation; either version 2 of
011 * the License, or (at your option) any later version.
012 *
013 * CleanSheets Extension for Test Cases is distributed in the hope that
014 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
015 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016 * See the GNU General Public License for more details.
017 *
018 * You should have received a copy of the GNU General Public License
019 * along with CleanSheets Extension for Test Cases; if not, write to the
020 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
021 * Boston, MA 02111-1307 USA
022 */
023 package csheets.ext.test;
024
025 import java.io.Serializable;
026
027 import csheets.core.Value;
028 import csheets.core.formula.Literal;
029
030 /**
031 * A class holding information about a Test Case Parameter.
032 * It contains the value of the parameter.
033 * @author Staffan Gustafsson
034 * @author Jens Schou
035 */
036 public class TestCaseParam extends Literal implements Serializable {
037
038 /** The unique version identifier used for serialization */
039 private static final long serialVersionUID = -6821036933997460416L;
040
041 private TestableCell cell;
042 private int userEntered = 0;
043 private int systemGenerated = 0;
044 private int derived = 0;
045
046 /** The test case parameters origin can be either user entered,
047 * system generated within the cells assertion or derived from
048 * the values of its test cases
049 */
050 public enum Type {
051
052 /** Entered manually by the user. */
053 USER_ENTERED,
054
055 /** Auto-generated by the system based on the cell's assertion. */
056 SYSTEM_GENERATED,
057
058 /** Derived from the cell's test case value. */
059 DERIVED
060 };
061
062 /**
063 * Creates the Test Case Parameter.
064 * @param cell the cell to which the parameter belongs
065 * @param value the value of the parameter.
066 * @param type the origin of the test case parameter
067 */
068 public TestCaseParam(TestableCell cell, Value value, Type type) {
069 super(value);
070 this.cell = cell;
071
072 switch(type){
073 case USER_ENTERED:
074 userEntered++;
075 break;
076 case SYSTEM_GENERATED:
077 systemGenerated++;
078 break;
079 case DERIVED:
080 derived++;
081 break;
082 }
083 }
084
085 /**
086 * Returns the Test Case Parameters cells address.
087 * @return The Test Case Parameters cells address.
088 */
089 public TestableCell getCell(){
090 return cell;
091 }
092
093 public boolean hasType(Type type) {
094 switch(type){
095 case USER_ENTERED:
096 return userEntered > 0;
097 case SYSTEM_GENERATED:
098 return systemGenerated > 0;
099 case DERIVED:
100 return derived > 0;
101 default:
102 return false;
103 }
104 }
105
106 public void setType(Type type, boolean toggle) {
107 // TO DO fulhack för att hinna klart i tid
108 switch(type){
109 case USER_ENTERED:
110 if(toggle)
111 userEntered++;
112 else
113 userEntered--;
114 break;
115 case SYSTEM_GENERATED:
116 if(toggle)
117 systemGenerated++;
118 else
119 systemGenerated--;
120 break;
121 case DERIVED:
122 if(toggle)
123 derived++;
124 else
125 derived--;
126 break;
127 }
128 }
129
130 public boolean hasNoType(){
131 return !(userEntered > 0 || systemGenerated > 0 || derived > 0);
132 }
133
134 public boolean isUserEntered() {
135 return userEntered > 0;
136 }
137 public boolean isSystemGenerated() {
138 return systemGenerated > 0;
139 }
140 public boolean isDerived() {
141 return derived > 0;
142 }
143
144 public String toString2() {
145 String temp = toString();
146
147 if(userEntered > 0) temp += " user entered";
148 if(systemGenerated > 0) temp += " system generated";
149 if(derived > 0) temp += " derived";
150
151 return temp;
152 }
153
154 /**
155 * Returns whether the other object has the same value
156 * and type as this has. Could also check against address
157 * but that seems unecessary since TCPs are stored on
158 * the cell they belong to, and this way you can compare
159 * TCP's from different cells if you want.
160 * @param other the object to check for equality
161 * @return true if the objects are equal
162 */
163 public boolean equals(Object other) {
164 if (!(other instanceof TestCaseParam) || other == null)
165 return false;
166 TestCaseParam otherTCP = (TestCaseParam)other;
167 return getValue().equals(otherTCP.getValue());
168 }
169
170 /**
171 * Returns the hash code of the test case parameter.
172 * @return the hash code of the test case parameter.
173 */
174 public int hashCode() {
175 return cell.hashCode() + getValue().hashCode();
176 }
177 }