001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.midp.events;
028:
029: import java.util.Vector;
030:
031: import com.sun.midp.events.NativeEvent;
032: import com.sun.midp.i3test.TestCase;
033:
034: /**
035: * Storage of native event copies for events being posted to evet queue.
036: * It is expected that NamsAPIWrapper uses this class each time it calls
037: * NAMS API method.
038: */
039: public class EventCopyStorage {
040:
041: /** storage for Native Event cpopies */
042: private Vector storage = new Vector(10, 10);
043:
044: public synchronized int putTail(int t, int i1, int i2, int i3,
045: int i4, String s1, String s2, String s3, String s4,
046: String s5, String s6) {
047:
048: NativeEvent e = new NativeEvent(t);
049:
050: e.intParam1 = i1;
051: e.intParam2 = i2;
052: e.intParam3 = i3;
053: e.intParam4 = i4;
054: e.stringParam1 = s1;
055: e.stringParam2 = s2;
056: e.stringParam3 = s3;
057: e.stringParam4 = s4;
058: e.stringParam5 = s5;
059: e.stringParam6 = s6;
060:
061: storage.addElement((Object) e);
062: return storage.size();
063: }
064:
065: private boolean compareEvents(NativeEvent e1, int t, int i1,
066: int i2, int i3, int i4, String s1, String s2, String s3,
067: String s4, String s5, String s6, TestCase test,
068: String message) {
069:
070: test.assertTrue(message + " 'type' field", e1.type == t);
071:
072: test.assertTrue(message + " 'intParam1' field",
073: e1.intParam1 == i1);
074: test.assertTrue(message + " 'intParam2' field",
075: e1.intParam2 == i2);
076: test.assertTrue(message + " 'intParam3' field",
077: e1.intParam3 == i3);
078: test.assertTrue(message + " 'intParam4' field",
079: e1.intParam4 == i4);
080:
081: test.assertEquals(message + " 'stringParam1' field",
082: e1.stringParam1, s1);
083: test.assertEquals(message + " 'stringParam2' field",
084: e1.stringParam2, s2);
085: test.assertEquals(message + " 'stringParam3' field",
086: e1.stringParam3, s3);
087: test.assertEquals(message + " 'stringParam4' field",
088: e1.stringParam4, s4);
089: test.assertEquals(message + " 'stringParam5' field",
090: e1.stringParam5, s5);
091: test.assertEquals(message + " 'stringParam6' field",
092: e1.stringParam6, s6);
093:
094: return (e1.type == t) &&
095:
096: (e1.intParam1 == i1) && (e1.intParam2 == i2)
097: && (e1.intParam3 == i3) && (e1.intParam4 == i4) &&
098:
099: (e1.stringParam1 == s1) && (e1.stringParam2 == s2)
100: && (e1.stringParam3 == s3) && (e1.stringParam4 == s4)
101: && (e1.stringParam5 == s5) && (e1.stringParam6 == s6);
102: }
103:
104: public synchronized NativeEvent getHead() {
105: NativeEvent e = (NativeEvent) storage.elementAt(0);
106: storage.removeElementAt(0);
107: return e;
108: }
109:
110: public synchronized boolean getHead(NativeEvent e, TestCase test,
111: String message) {
112: NativeEvent e1 = (NativeEvent) storage.elementAt(0);
113: storage.removeElementAt(0);
114:
115: return compareEvents(e1, e.type, e.intParam1, e.intParam2,
116: e.intParam3, e.intParam4, e.stringParam1,
117: e.stringParam2, e.stringParam4, e.stringParam4,
118: e.stringParam5, e.stringParam6, test, message);
119: }
120:
121: public synchronized boolean getHead(int t, int i1, int i2, int i3,
122: int i4, String s1, String s2, String s3, String s4,
123: String s5, String s6, TestCase test, String message) {
124:
125: NativeEvent e1 = (NativeEvent) storage.elementAt(0);
126: storage.removeElementAt(0);
127:
128: return compareEvents(e1, t, i1, i2, i3, i4, s1, s2, s3, s4, s5,
129: s6, test, message);
130: }
131:
132: public synchronized NativeEvent checkHead() {
133: return (NativeEvent) storage.elementAt(0);
134: }
135:
136: public synchronized boolean checkHead(NativeEvent e, TestCase test,
137: String message) {
138:
139: NativeEvent e1 = (NativeEvent) storage.elementAt(0);
140:
141: return compareEvents(e1, e.type, e.intParam1, e.intParam2,
142: e.intParam3, e.intParam4, e.stringParam1,
143: e.stringParam2, e.stringParam4, e.stringParam4,
144: e.stringParam5, e.stringParam6, test, message);
145: }
146:
147: public synchronized boolean checkHead(int t, int i1, int i2,
148: int i3, int i4, String s1, String s2, String s3, String s4,
149: String s5, String s6, TestCase test, String message) {
150:
151: NativeEvent e1 = (NativeEvent) storage.elementAt(0);
152:
153: return compareEvents(e1, t, i1, i2, i3, i4, s1, s2, s3, s4, s5,
154: s6, test, message);
155: }
156:
157: public synchronized int checkSize() {
158: return storage.size();
159: }
160:
161: public synchronized void clearAll() {
162: storage.removeAllElements();
163: }
164: }
|