Skip to main content
summaryrefslogtreecommitdiffstats
blob: ab0f725e0a26db43c8afca9fe387af32e60622b8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.ote.message.elements;

import java.util.Collection;

import org.eclipse.osee.ote.core.MethodFormatter;
import org.eclipse.osee.ote.core.environment.interfaces.ITestEnvironmentAccessor;
import org.eclipse.osee.ote.core.testPoint.CheckPoint;
import org.eclipse.osee.ote.message.Message;
import org.eclipse.osee.ote.message.condition.EmptyStringCondition;
import org.eclipse.osee.ote.message.condition.StringTrimCondition;
import org.eclipse.osee.ote.message.data.MemoryResource;
import org.eclipse.osee.ote.message.data.MessageData;
import org.eclipse.osee.ote.message.elements.nonmapping.NonMappingStringElement;
import org.eclipse.osee.ote.message.interfaces.ITestAccessor;

/**
 * @author Ryan D. Brooks
 * @author Andrew M. Finkbeiner
 */
public class StringElement extends DiscreteElement<String> {

   @Override
   public void visit(IElementVisitor visitor) {
      visitor.asStringElement(this);
   }

   public StringElement(Message<?, ?, ?> message, String elementName, MessageData messageData, int byteOffset, int msb, int lsb) {
      this(message, elementName, messageData, byteOffset, msb, lsb, msb, lsb);
   }

   public StringElement(Message<?, ?, ?> message, String elementName, MessageData messageData, int bitOffset, int bitLength) {
      super(message, elementName, messageData, bitOffset, bitLength);
   }

   public StringElement(Message<?, ?, ?> message, String elementName, MessageData messageData, int byteOffset, int msb, int lsb, int originalLsb, int originalMsb) {
      super(message, elementName, messageData, byteOffset, msb, lsb, originalLsb, originalMsb);
   }

   @Override
   public StringElement switchMessages(Collection<? extends Message<?, ?, ?>> messages) {
      return (StringElement) super.switchMessages(messages);
   }

   @Override
   public String toString(String obj) {
      return obj;
   }

   @Override
   public void setValue(String value) {
      getMsgData().getMem().setASCIIString(value, byteOffset, msb, lsb);
   }

   @Override
   public void parseAndSet(ITestEnvironmentAccessor accessor, String value) throws IllegalArgumentException {
      set(accessor, value);
   }

   @Override
   public String getValue() {
      return getMsgData().getMem().getASCIIString(byteOffset, msb, lsb);
   }

   /**
    * copies this elements chars into the given array. The array must be big enough to contain this elements data or an
    * ArrayIndexOutOfBoundsException will be thrown
    * 
    * @param destination the destination array that will receive the char data
    * @return the actual number of characters copied. The destination array will contain undefined data starting at this
    *         index until the end of the char array.
    * @throws ArrayIndexOutOfBoundsException if the destination array is too small
    */
   public int getChars(char[] destination) throws ArrayIndexOutOfBoundsException {
      return getMsgData().getMem().getASCIIChars(byteOffset, msb, lsb, destination);
   }

   public boolean equals(String other) {
      return getMsgData().getMem().asciiEquals(byteOffset, msb, lsb, other);
   }

   @Override
   public String valueOf(MemoryResource mem) {
      return mem.getASCIIString(byteOffset, msb, lsb);
   }

   public String get(ITestEnvironmentAccessor accessor) {
      return getValue();
   }

   /**
    * Verifies that the element is set to "value" within the number of "milliseconds" passed.
    * 
    * @param accessor
    * @param value Expected value.
    * @param milliseconds Number of milliseconds to wait for the element to equal the "value".
    * @return If the check passed.
    * @throws InterruptedException
    */
   public boolean checkTrimWhiteSpace(ITestAccessor accessor, String value, int milliseconds) throws InterruptedException {
      if (accessor == null) {
         throw new NullPointerException("The parameter accessor is null");
      }

      accessor.getLogger().methodCalledOnObject(accessor, getFullName(),
            (new MethodFormatter()).add(value).add(milliseconds), this.msg);
      final StringTrimCondition c = new StringTrimCondition(this, value);

      MsgWaitResult result = msg.waitForCondition(accessor, c, false, milliseconds);
      CheckPoint passFail =
            new CheckPoint(getFullName(), toString(value), toString(c.getLastCheckValue()), result.isPassed(),
                  result.getElapsedTime());

      accessor.getLogger().testpoint(accessor, accessor.getTestScript(), accessor.getTestCase(), passFail);

      accessor.getLogger().methodEnded(accessor);
      return passFail.isPass();
   }

   /**
    * Sets the element to the "value" passed and immediately sends the message that contains it..
    * 
    * @param accessor
    * @param value The value to set.
    */
   public void setAndSend(ITestEnvironmentAccessor accessor, String value) {
      parseAndSet(accessor, value);
      super.sendMessage();
   }

   @Override
   protected NonMappingStringElement getNonMappingElement() {
      return new NonMappingStringElement(this);
   }

   @Override
   public void zeroize() {
      int sizeInBytes = ((lsb - msb) + 1) / 8;
      getMsgData().getMem().zeroizeFromOffset(byteOffset, sizeInBytes);
   }

   public boolean isEmpty() {
      return (new EmptyStringCondition(this)).check();
   }

   public boolean checkEmpty(ITestAccessor accessor, int milliseconds) throws InterruptedException {
      if (accessor == null) {
         throw new NullPointerException("The parameter accessor is null");
      }

      accessor.getLogger().methodCalledOnObject(accessor, getFullName(), (new MethodFormatter()).add(milliseconds),
            this.msg);
      final EmptyStringCondition c = new EmptyStringCondition(this);

      MsgWaitResult result = msg.waitForCondition(accessor, c, false, milliseconds);
      CheckPoint passFail =
            new CheckPoint(getFullName(), "Empty", result.isPassed() ? "Empty" : "Not Empty", result.isPassed(),
                  result.getElapsedTime());

      accessor.getLogger().testpoint(accessor, accessor.getTestScript(), accessor.getTestCase(), passFail);

      accessor.getLogger().methodEnded(accessor);
      return passFail.isPass();
   }

   public boolean checkMaintainEmpty(ITestAccessor accessor, int milliseconds) throws InterruptedException {
      if (accessor == null) {
         throw new NullPointerException("The parameter accessor is null");
      }

      accessor.getLogger().methodCalledOnObject(accessor, getFullName(), (new MethodFormatter()).add(milliseconds),
            this.msg);
      final EmptyStringCondition c = new EmptyStringCondition(this);

      MsgWaitResult result = msg.waitForCondition(accessor, c, true, milliseconds);
      CheckPoint passFail =
            new CheckPoint(getFullName(), "Empty", result.isPassed() ? "Empty" : "Not Empty", result.isPassed(),
                  result.getElapsedTime());

      accessor.getLogger().testpoint(accessor, accessor.getTestScript(), accessor.getTestCase(), passFail);

      accessor.getLogger().methodEnded(accessor);
      return passFail.isPass();
   }

   @Override
   public String elementMask(String value) {
      return value;
   }

}

Back to the top