• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 package org.chromium.mojo;
6 
7 import org.chromium.mojo.system.Core;
8 import org.chromium.mojo.system.Core.HandleSignalsState;
9 import org.chromium.mojo.system.DataPipe;
10 import org.chromium.mojo.system.DataPipe.ConsumerHandle;
11 import org.chromium.mojo.system.DataPipe.ProducerHandle;
12 import org.chromium.mojo.system.Handle;
13 import org.chromium.mojo.system.MessagePipeHandle;
14 import org.chromium.mojo.system.MojoResult;
15 import org.chromium.mojo.system.ResultAnd;
16 import org.chromium.mojo.system.SharedBufferHandle;
17 import org.chromium.mojo.system.UntypedHandle;
18 import org.chromium.mojo.system.impl.CoreImpl;
19 
20 import java.nio.ByteBuffer;
21 import java.util.List;
22 
23 /**
24  * A mock handle, that does nothing.
25  */
26 public class HandleMock implements UntypedHandle, MessagePipeHandle, ProducerHandle, ConsumerHandle,
27                                    SharedBufferHandle {
28     /**
29      * @see Handle#close()
30      */
31     @Override
close()32     public void close() {
33         // Do nothing.
34     }
35 
36     /**
37      * @see Handle#querySignalsState()
38      */
39     @Override
querySignalsState()40     public HandleSignalsState querySignalsState() {
41         return null;
42     }
43 
44     /**
45      * @see Handle#isValid()
46      */
47     @Override
isValid()48     public boolean isValid() {
49         return true;
50     }
51 
52     /**
53      * @see Handle#toUntypedHandle()
54      */
55     @Override
toUntypedHandle()56     public UntypedHandle toUntypedHandle() {
57         return this;
58     }
59 
60     /**
61      * @see org.chromium.mojo.system.Handle#getCore()
62      */
63     @Override
getCore()64     public Core getCore() {
65         return CoreImpl.getInstance();
66     }
67 
68     /**
69      * @see org.chromium.mojo.system.UntypedHandle#pass()
70      */
71     @Override
pass()72     public HandleMock pass() {
73         return this;
74     }
75 
76     /**
77      * @see Handle#releaseNativeHandle()
78      */
79     @Override
releaseNativeHandle()80     public int releaseNativeHandle() {
81         return 0;
82     }
83 
84     /**
85      * @see ConsumerHandle#discardData(int, DataPipe.ReadFlags)
86      */
87     @Override
discardData(int numBytes, DataPipe.ReadFlags flags)88     public int discardData(int numBytes, DataPipe.ReadFlags flags) {
89         // Do nothing.
90         return 0;
91     }
92 
93     /**
94      * @see ConsumerHandle#readData(java.nio.ByteBuffer, DataPipe.ReadFlags)
95      */
96     @Override
readData(ByteBuffer elements, DataPipe.ReadFlags flags)97     public ResultAnd<Integer> readData(ByteBuffer elements, DataPipe.ReadFlags flags) {
98         // Do nothing.
99         return new ResultAnd<Integer>(MojoResult.OK, 0);
100     }
101 
102     /**
103      * @see ConsumerHandle#beginReadData(int, DataPipe.ReadFlags)
104      */
105     @Override
beginReadData(int numBytes, DataPipe.ReadFlags flags)106     public ByteBuffer beginReadData(int numBytes, DataPipe.ReadFlags flags) {
107         // Do nothing.
108         return null;
109     }
110 
111     /**
112      * @see ConsumerHandle#endReadData(int)
113      */
114     @Override
endReadData(int numBytesRead)115     public void endReadData(int numBytesRead) {
116         // Do nothing.
117     }
118 
119     /**
120      * @see ProducerHandle#writeData(java.nio.ByteBuffer, DataPipe.WriteFlags)
121      */
122     @Override
writeData(ByteBuffer elements, DataPipe.WriteFlags flags)123     public ResultAnd<Integer> writeData(ByteBuffer elements, DataPipe.WriteFlags flags) {
124         // Do nothing.
125         return new ResultAnd<Integer>(MojoResult.OK, 0);
126     }
127 
128     /**
129      * @see ProducerHandle#beginWriteData(int, DataPipe.WriteFlags)
130      */
131     @Override
beginWriteData(int numBytes, DataPipe.WriteFlags flags)132     public ByteBuffer beginWriteData(int numBytes, DataPipe.WriteFlags flags) {
133         // Do nothing.
134         return null;
135     }
136 
137     /**
138      * @see ProducerHandle#endWriteData(int)
139      */
140     @Override
endWriteData(int numBytesWritten)141     public void endWriteData(int numBytesWritten) {
142         // Do nothing.
143     }
144 
145     /**
146      * @see MessagePipeHandle#writeMessage(java.nio.ByteBuffer, java.util.List,
147      *      MessagePipeHandle.WriteFlags)
148      */
149     @Override
writeMessage(ByteBuffer bytes, List<? extends Handle> handles, WriteFlags flags)150     public void writeMessage(ByteBuffer bytes, List<? extends Handle> handles, WriteFlags flags) {
151         // Do nothing.
152     }
153 
154     /**
155      * @see MessagePipeHandle#readMessage(MessagePipeHandle.ReadFlags)
156      */
157     @Override
readMessage(ReadFlags flags)158     public ResultAnd<ReadMessageResult> readMessage(ReadFlags flags) {
159         // Do nothing.
160         return new ResultAnd<ReadMessageResult>(MojoResult.OK, new ReadMessageResult());
161     }
162 
163     /**
164      * @see UntypedHandle#toMessagePipeHandle()
165      */
166     @Override
toMessagePipeHandle()167     public MessagePipeHandle toMessagePipeHandle() {
168         return this;
169     }
170 
171     /**
172      * @see UntypedHandle#toDataPipeConsumerHandle()
173      */
174     @Override
toDataPipeConsumerHandle()175     public ConsumerHandle toDataPipeConsumerHandle() {
176         return this;
177     }
178 
179     /**
180      * @see UntypedHandle#toDataPipeProducerHandle()
181      */
182     @Override
toDataPipeProducerHandle()183     public ProducerHandle toDataPipeProducerHandle() {
184         return this;
185     }
186 
187     /**
188      * @see UntypedHandle#toSharedBufferHandle()
189      */
190     @Override
toSharedBufferHandle()191     public SharedBufferHandle toSharedBufferHandle() {
192         return this;
193     }
194 
195     /**
196      * @see SharedBufferHandle#duplicate(SharedBufferHandle.DuplicateOptions)
197      */
198     @Override
duplicate(DuplicateOptions options)199     public SharedBufferHandle duplicate(DuplicateOptions options) {
200         // Do nothing.
201         return null;
202     }
203 
204     /**
205      * @see SharedBufferHandle#map(long, long, SharedBufferHandle.MapFlags)
206      */
207     @Override
map(long offset, long numBytes, MapFlags flags)208     public ByteBuffer map(long offset, long numBytes, MapFlags flags) {
209         // Do nothing.
210         return null;
211     }
212 
213     /**
214      * @see SharedBufferHandle#unmap(java.nio.ByteBuffer)
215      */
216     @Override
unmap(ByteBuffer buffer)217     public void unmap(ByteBuffer buffer) {
218         // Do nothing.
219     }
220 }
221