• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "ipc_types.h"
17 #include "assist_test_service.h"
18 
19 namespace OHOS {
AssistTestServiceProxy(const sptr<IRemoteObject> & object)20 AssistTestServiceProxy::AssistTestServiceProxy(const sptr<IRemoteObject>& object)
21     : IRemoteProxy<IAssistTestService>(object)
22 {
23 }
24 
~AssistTestServiceProxy()25 AssistTestServiceProxy::~AssistTestServiceProxy()
26 {
27 }
28 
TestParcelBool(bool value)29 bool AssistTestServiceProxy::TestParcelBool(bool value)
30 {
31     MessageParcel data, reply;
32     MessageOption option;
33     data.WriteBool(value);
34     int res = Remote()->SendRequest(TEST_PARCEL_BOOL, data, reply, option);
35     return (res == ERR_NONE) ? reply.ReadBool() : false;
36 }
37 
TestParcelChar(int16_t value)38 int16_t AssistTestServiceProxy::TestParcelChar(int16_t value)
39 {
40     MessageParcel data, reply;
41     MessageOption option;
42     data.WriteInt16(value);
43     int res = Remote()->SendRequest(TEST_PARCEL_CHAR, data, reply, option);
44     return (res == ERR_NONE) ? reply.ReadInt16() : 0;
45 }
46 
TestParcelInt32(int32_t value)47 int32_t AssistTestServiceProxy::TestParcelInt32(int32_t value)
48 {
49     MessageParcel data, reply;
50     MessageOption option;
51     data.WriteInt32(value);
52     int res = Remote()->SendRequest(TEST_PARCEL_INT32, data, reply, option);
53     return (res == ERR_NONE) ? reply.ReadInt32() : 0;
54 }
55 
TestParcelInt64(int64_t value)56 int64_t AssistTestServiceProxy::TestParcelInt64(int64_t value)
57 {
58     MessageParcel data, reply;
59     MessageOption option;
60     data.WriteInt64(value);
61     int res = Remote()->SendRequest(TEST_PARCEL_INT64, data, reply, option);
62     return (res == ERR_NONE) ? reply.ReadInt64() : 0;
63 }
64 
TestParcelByte(uint8_t value)65 uint8_t AssistTestServiceProxy::TestParcelByte(uint8_t value)
66 {
67     MessageParcel data, reply;
68     MessageOption option;
69     data.WriteUint8(value);
70     int res = Remote()->SendRequest(TEST_PARCEL_BYTE, data, reply, option);
71     return (res == ERR_NONE) ? reply.ReadUint8() : 0;
72 }
73 
TestParcelUint32(uint32_t value)74 uint32_t AssistTestServiceProxy::TestParcelUint32(uint32_t value)
75 {
76     MessageParcel data, reply;
77     MessageOption option;
78     data.WriteUint32(value);
79     int res = Remote()->SendRequest(TEST_PARCEL_UINT32, data, reply, option);
80     return (res == ERR_NONE) ? reply.ReadUint32() : 0;
81 }
82 
TestParcelUint64(uint64_t value)83 uint64_t AssistTestServiceProxy::TestParcelUint64(uint64_t value)
84 {
85     MessageParcel data, reply;
86     MessageOption option;
87     data.WriteUint64(value);
88     int res = Remote()->SendRequest(TEST_PARCEL_UINT64, data, reply, option);
89     return (res == ERR_NONE) ? reply.ReadUint64() : 0;
90 }
91 
TestParcelFloat(float value)92 float AssistTestServiceProxy::TestParcelFloat(float value)
93 {
94     MessageParcel data, reply;
95     MessageOption option;
96     data.WriteFloat(value);
97     int res = Remote()->SendRequest(TEST_PARCEL_FLOAT, data, reply, option);
98     return (res == ERR_NONE) ? reply.ReadFloat() : 0;
99 }
100 
TestParcelDouble(double value)101 double AssistTestServiceProxy::TestParcelDouble(double value)
102 {
103     MessageParcel data, reply;
104     MessageOption option;
105     data.WriteDouble(value);
106     int res = Remote()->SendRequest(TEST_PARCEL_DOUBLE, data, reply, option);
107     return (res == ERR_NONE) ? reply.ReadDouble() : 0;
108 }
109 
TestParcelCString(const char * value)110 const char *AssistTestServiceProxy::TestParcelCString(const char *value)
111 {
112     MessageParcel data, reply;
113     MessageOption option;
114     data.WriteCString(value);
115     int res = Remote()->SendRequest(TEST_PARCEL_CSTRING, data, reply, option);
116     return (res == ERR_NONE) ? reply.ReadCString() : nullptr;
117 }
118 
TestParcelString(const std::string & value)119 const std::string AssistTestServiceProxy::TestParcelString(const std::string& value)
120 {
121     MessageParcel data, reply;
122     MessageOption option;
123     data.WriteString(value);
124     int res = Remote()->SendRequest(TEST_PARCEL_STRING8, data, reply, option);
125     return (res == ERR_NONE) ? reply.ReadString() : std::string();
126 }
127 
TestParcelString16(const std::u16string & value)128 const std::u16string AssistTestServiceProxy::TestParcelString16(const std::u16string& value)
129 {
130     MessageParcel data, reply;
131     MessageOption option;
132     data.WriteString16(value);
133     int res = Remote()->SendRequest(TEST_PARCEL_STRING16, data, reply, option);
134     return (res == ERR_NONE) ? reply.ReadString16() : std::u16string();
135 }
136 
TestParcelBoolVector()137 bool AssistTestServiceProxy::TestParcelBoolVector()
138 {
139     MessageParcel data, reply;
140     MessageOption option;
141     std::vector<bool> readBoolVector;
142     std::vector<bool> writeBoolVector = { false, false, true, false, true };
143     data.WriteBoolVector(writeBoolVector);
144 
145     if (Remote()->SendRequest(TEST_PARCEL_BOOL_VECTOR, data, reply, option) != ERR_NONE) {
146         return false;
147     }
148 
149     if (!reply.ReadBoolVector(&readBoolVector)) {
150         return false;
151     }
152 
153     for (size_t i = 0; i < writeBoolVector.size(); i++) {
154         if (writeBoolVector[i] != readBoolVector[i]) {
155             bool write = writeBoolVector[i];
156             bool read = readBoolVector[i];
157             printf("index:%zu write:%d, read:%d\n", i, write, read);
158             return false;
159         }
160     }
161 
162     return true;
163 }
164 
TestParcelInt8Vector()165 bool AssistTestServiceProxy::TestParcelInt8Vector()
166 {
167     MessageParcel data, reply;
168     MessageOption option;
169     std::vector<int8_t> readInt8Vector;
170     std::vector<int8_t> writeInt8Vector = { 0x01, 0x10, -0x20, 0x30, 0x40 };
171     data.WriteInt8Vector(writeInt8Vector);
172     int res = Remote()->SendRequest(TEST_PARCEL_INT8_VECTOR, data, reply, option);
173     if (res != ERR_NONE) {
174         return false;
175     }
176 
177     if (!reply.ReadInt8Vector(&readInt8Vector)) {
178         return false;
179     }
180 
181     for (size_t i = 0; i < writeInt8Vector.size(); i++) {
182         if (writeInt8Vector[i] != readInt8Vector[i]) {
183             return false;
184         }
185     }
186 
187     return true;
188 }
189 
TestParcelUint8Vector()190 bool AssistTestServiceProxy::TestParcelUint8Vector()
191 {
192     MessageParcel data, reply;
193     MessageOption option;
194     std::vector<uint8_t> readUint8Vector;
195     std::vector<uint8_t> writeUint8Vector = { 0xA1, 0xA1, 0xA2, 0x30, 0x40 };
196     data.WriteUInt8Vector(writeUint8Vector);
197 
198     if (Remote()->SendRequest(TEST_PARCEL_UINT8_VECTOR, data, reply, option) != ERR_NONE) {
199         return false;
200     }
201 
202     if (!reply.ReadUInt8Vector(&readUint8Vector)) {
203         return false;
204     }
205 
206     for (size_t i = 0; i < writeUint8Vector.size(); i++) {
207         if (writeUint8Vector[i] != readUint8Vector[i]) {
208             return false;
209         }
210     }
211 
212     return true;
213 }
214 
TestParcelCharVector()215 bool AssistTestServiceProxy::TestParcelCharVector()
216 {
217     MessageParcel data, reply;
218     MessageOption option;
219     std::vector<int16_t> readInt16Vector;
220     std::vector<int16_t> writeInt16Vector = { 0x1234, -0x2345, 0x3456, -0x4567, 0x5678 };
221     data.WriteInt16Vector(writeInt16Vector);
222 
223     if (Remote()->SendRequest(TEST_PARCEL_CHAR_VECTOR, data, reply, option)  != ERR_NONE) {
224         return false;
225     }
226 
227     if (!reply.ReadInt16Vector(&readInt16Vector)) {
228         return false;
229     }
230 
231     for (size_t i = 0; i < writeInt16Vector.size(); i++) {
232         if (writeInt16Vector[i] != readInt16Vector[i]) {
233             return false;
234         }
235     }
236 
237     return true;
238 }
239 
TestParcelInt64Vector()240 bool AssistTestServiceProxy::TestParcelInt64Vector()
241 {
242     MessageParcel data, reply;
243     MessageOption option;
244     std::vector<int64_t> readInt64Vector;
245     std::vector<int64_t> writeInt64Vector = { 0x1234567887654321, -0x2345678998765432 };
246     data.WriteInt64Vector(writeInt64Vector);
247 
248     if (Remote()->SendRequest(TEST_PARCEL_INT64_VECTOR, data, reply, option) != ERR_NONE) {
249         return false;
250     }
251 
252     if (!reply.ReadInt64Vector(&readInt64Vector)) {
253         return false;
254     }
255 
256     for (size_t i = 0; i < writeInt64Vector.size(); i++) {
257         if (writeInt64Vector[i] != readInt64Vector[i]) {
258             return false;
259         }
260     }
261 
262     return true;
263 }
264 
TestParcelUint64Vector()265 bool AssistTestServiceProxy::TestParcelUint64Vector()
266 {
267     MessageParcel data, reply;
268     MessageOption option;
269     std::vector<uint64_t> readUint64Vector;
270     std::vector<uint64_t> writeUint64Vector = { 0x1234567887654321, 0x2345678998765432 };
271     data.WriteUInt64Vector(writeUint64Vector);
272 
273     if (Remote()->SendRequest(TEST_PARCEL_UINT64_VECTOR, data, reply, option) != ERR_NONE) {
274         return false;
275     }
276 
277     bool result = reply.ReadUInt64Vector(&readUint64Vector);
278     if (result != true) {
279         return false;
280     }
281 
282     for (size_t i = 0; i < writeUint64Vector.size(); i++) {
283         if (writeUint64Vector[i] != readUint64Vector[i]) {
284             return false;
285         }
286     }
287 
288     return true;
289 }
290 
TestParcelInt32Vector()291 bool AssistTestServiceProxy::TestParcelInt32Vector()
292 {
293     MessageParcel data, reply;
294     MessageOption option;
295     std::vector<int32_t> readInt32Vector;
296     std::vector<int32_t> writeInt32Vector = { 0x12345678, -0x23456789, 0x34567890, -0x45678901 };
297     data.WriteInt32Vector(writeInt32Vector);
298 
299     if (Remote()->SendRequest(TEST_PARCEL_INT32_VECTOR, data, reply, option) != ERR_NONE) {
300         return false;
301     }
302 
303     if (!reply.ReadInt32Vector(&readInt32Vector)) {
304         return false;
305     }
306 
307     for (size_t i = 0; i < writeInt32Vector.size(); i++) {
308         if (writeInt32Vector[i] != readInt32Vector[i]) {
309             return false;
310         }
311     }
312 
313     return true;
314 }
315 
TestParcelFloatVector()316 bool AssistTestServiceProxy::TestParcelFloatVector()
317 {
318     MessageParcel data, reply;
319     MessageOption option;
320     std::vector<float> readFloatVector;
321     std::vector<float> writeFloatVector{ 11221.132313, 11221.45678 };
322     data.WriteFloatVector(writeFloatVector);
323 
324     if (Remote()->SendRequest(TEST_PARCEL_FLOAT_VECTOR, data, reply, option) != ERR_NONE) {
325         return false;
326     }
327 
328     if (!reply.ReadFloatVector(&readFloatVector)) {
329         return false;
330     }
331 
332     for (size_t i = 0; i < writeFloatVector.size(); i++) {
333         if (writeFloatVector[i] != readFloatVector[i]) {
334             return false;
335         }
336     }
337 
338     return true;
339 }
340 
TestParcelDoubleVector()341 bool AssistTestServiceProxy::TestParcelDoubleVector()
342 {
343     MessageParcel data, reply;
344     MessageOption option;
345     std::vector<double> readDoubleVector;
346     std::vector<double> writeDoubleVector{ 1122.132313, 1122.45678 };
347     data.WriteDoubleVector(writeDoubleVector);
348 
349     if (Remote()->SendRequest(TEST_PARCEL_DOUBLE_VECTOR, data, reply, option) != ERR_NONE) {
350         return false;
351     }
352 
353     if (!reply.ReadDoubleVector(&readDoubleVector)) {
354         return false;
355     }
356 
357     for (size_t i = 0; i < writeDoubleVector.size(); i++) {
358         if (writeDoubleVector[i] != readDoubleVector[i]) {
359             return false;
360         }
361     }
362 
363     return true;
364 }
365 
TestParcelString16Vector()366 bool AssistTestServiceProxy::TestParcelString16Vector()
367 {
368     MessageParcel data, reply;
369     MessageOption option;
370     std::vector<std::u16string> readString16Vector;
371     std::vector<std::u16string> writeString16Vector{
372         u"test", u"test for", u"test for write", u"test for write vector"
373     };
374     data.WriteString16Vector(writeString16Vector);
375     if (Remote()->SendRequest(TEST_PARCEL_STRING16_VECTOR, data, reply, option) != ERR_NONE) {
376         return false;
377     }
378 
379     if (!reply.ReadString16Vector(&readString16Vector))  {
380         return false;
381     }
382 
383     for (size_t i = 0; i < writeString16Vector.size(); i++) {
384         if (writeString16Vector[i].compare(readString16Vector[i])) {
385             return false;
386         }
387     }
388 
389     return true;
390 }
391 } // namespace OHOS