1 /* 2 * Copyright (c) 2024 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 <gtest/gtest.h> 17 18 #include "usb_device_id.h" 19 20 using namespace testing::ext; 21 22 namespace OHOS { 23 namespace EDM { 24 namespace TEST { 25 class UsbDeviceIdTest : public testing::Test {}; 26 /** 27 * @tc.name: TestMarshalling 28 * @tc.desc: Test Test Marshalling function. 29 * @tc.type: FUNC 30 */ 31 HWTEST_F(UsbDeviceIdTest, TestMarshalling, TestSize.Level1) 32 { 33 std::shared_ptr<UsbDeviceId> usbDeviceId = std::make_shared<UsbDeviceId>(); 34 MessageParcel parcel; 35 ASSERT_TRUE(usbDeviceId->Marshalling(parcel)); 36 } 37 38 /** 39 * @tc.name: TestUnmarshallingWithDataEmpty 40 * @tc.desc: Test Test Unmarshalling function when input data is empty. 41 * @tc.type: FUNC 42 */ 43 HWTEST_F(UsbDeviceIdTest, TestUnmarshallingWithDataEmpty, TestSize.Level1) 44 { 45 std::shared_ptr<UsbDeviceId> usbDeviceId = std::make_shared<UsbDeviceId>(); 46 MessageParcel parcel; 47 UsbDeviceId usbDeviceId2; 48 ASSERT_TRUE(usbDeviceId->Unmarshalling(parcel, usbDeviceId2)); 49 ASSERT_TRUE(usbDeviceId2.GetVendorId() == 0); 50 ASSERT_TRUE(usbDeviceId2.GetProductId() == 0); 51 } 52 53 /** 54 * @tc.name: TestUnmarshalling 55 * @tc.desc: Test Test Unmarshalling function. 56 * @tc.type: FUNC 57 */ 58 HWTEST_F(UsbDeviceIdTest, TestUnmarshalling, TestSize.Level1) 59 { 60 std::shared_ptr<UsbDeviceId> usbDeviceId = std::make_shared<UsbDeviceId>(); 61 MessageParcel parcel; 62 parcel.WriteInt32(111); 63 parcel.WriteInt32(222); 64 UsbDeviceId usbDeviceId2; 65 ASSERT_TRUE(usbDeviceId->Unmarshalling(parcel, usbDeviceId2)); 66 ASSERT_TRUE(usbDeviceId2.GetVendorId() == 111); 67 ASSERT_TRUE(usbDeviceId2.GetProductId() == 222); 68 } 69 70 } // namespace TEST 71 } // namespace EDM 72 } // namespace OHOS 73