1 /* 2 * Copyright (c) 2022-2023 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 "parcel.h" 17 18 namespace OHOS::FileManagement::Backup { 19 using namespace std; 20 namespace { 21 bool g_mockWriteUint32 = true; 22 bool g_mockWriteString = true; 23 bool g_mockWriteParcelable = true; 24 bool g_mockReadParcelable = true; 25 uint8_t g_mockWriteStringCount = 0; 26 uint8_t g_mockWriteStringMax = 0; 27 } // namespace 28 MockWriteUint32(bool state)29void MockWriteUint32(bool state) 30 { 31 g_mockWriteUint32 = state; 32 } 33 MockWriteString(bool state,uint8_t count)34void MockWriteString(bool state, uint8_t count) 35 { 36 g_mockWriteString = state; 37 g_mockWriteStringMax = count; 38 } 39 MockWriteParcelable(bool state)40void MockWriteParcelable(bool state) 41 { 42 g_mockWriteParcelable = state; 43 } 44 MockReadParcelable(bool state)45void MockReadParcelable(bool state) 46 { 47 g_mockReadParcelable = state; 48 } 49 ResetParcelState()50void ResetParcelState() 51 { 52 g_mockWriteUint32 = true; 53 g_mockWriteString = true; 54 g_mockWriteParcelable = true; 55 g_mockReadParcelable = true; 56 g_mockWriteStringCount = 0; 57 g_mockWriteStringMax = 0; 58 } 59 GetMockReadParcelableState()60bool GetMockReadParcelableState() 61 { 62 return g_mockReadParcelable; 63 } 64 WriteUint32(uint32_t)65bool Parcel::WriteUint32(uint32_t) 66 { 67 return g_mockWriteUint32; 68 } 69 WriteString(const string &)70bool Parcel::WriteString(const string &) 71 { 72 if (g_mockWriteStringCount < g_mockWriteStringMax) { 73 g_mockWriteStringCount++; 74 return !g_mockWriteString; 75 } 76 return g_mockWriteString; 77 } 78 WriteParcelable(const Parcelable *)79bool Parcel::WriteParcelable(const Parcelable *) 80 { 81 return g_mockWriteParcelable; 82 } 83 ReadString(string & value)84bool Parcel::ReadString(string &value) 85 { 86 if (g_mockWriteStringCount < g_mockWriteStringMax) { 87 g_mockWriteStringCount++; 88 return !g_mockWriteString; 89 } 90 return g_mockWriteString; 91 } 92 ReadUint32(uint32_t & value)93bool Parcel::ReadUint32(uint32_t &value) 94 { 95 return g_mockWriteUint32; 96 } 97 } // namespace OHOS::FileManagement::Backup