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 <gtest/gtest.h> 17 18 #include "pixel_map.h" 19 #include "pixel_map_parcel.h" 20 21 using namespace testing::ext; 22 using namespace OHOS::Media; 23 24 namespace OHOS { 25 namespace Multimedia { 26 class ImagePixelMapParcelTest : public testing::Test { 27 public: ImagePixelMapParcelTest()28 ImagePixelMapParcelTest(){} ~ImagePixelMapParcelTest()29 ~ImagePixelMapParcelTest(){} 30 }; 31 ConstructPixmap()32 std::unique_ptr<PixelMap> ConstructPixmap() 33 { 34 int32_t pixelMapWidth = 4; 35 int32_t pixelMapHeight = 3; 36 std::unique_ptr<PixelMap> pixelMap = std::make_unique<PixelMap>(); 37 ImageInfo info; 38 info.size.width = pixelMapWidth; 39 info.size.height = pixelMapHeight; 40 info.pixelFormat = PixelFormat::RGB_888; 41 info.colorSpace = ColorSpace::SRGB; 42 pixelMap->SetImageInfo(info); 43 44 int32_t rowDataSize = pixelMapWidth; 45 uint32_t bufferSize = rowDataSize * pixelMapHeight; 46 void *buffer = malloc(bufferSize); 47 char *ch = reinterpret_cast<char *>(buffer); 48 for (unsigned int i = 0; i < bufferSize; i++) { 49 *(ch++) = (char)i; 50 } 51 52 pixelMap->SetPixelsAddr(buffer, nullptr, bufferSize, AllocatorType::HEAP_ALLOC, nullptr); 53 54 return pixelMap; 55 } 56 /** 57 * @tc.name: ImagePixelMapParcel001 58 * @tc.desc: test WriteToParcel 59 * @tc.type: FUNC 60 * @tc.require: AR000FTAMO 61 */ 62 HWTEST_F(ImagePixelMapParcelTest, ImagePixelMapParcel001, TestSize.Level3) 63 { 64 GTEST_LOG_(INFO) << "ImagePixelMapParcelTest: ImagePixelMapParcel001 start"; 65 66 MessageParcel data; 67 68 std::unique_ptr<PixelMap> pixelmap = ConstructPixmap(); 69 70 bool ret = PixelMapParcel::WriteToParcel(pixelmap.get(), data); 71 72 EXPECT_EQ(true, ret); 73 74 GTEST_LOG_(INFO) << "ImagePixelMapParcelTest: ImagePixelMapParcel001 end"; 75 } 76 77 /** 78 * @tc.name: ImagePixelMapParcel002 79 * @tc.desc: test CreateFromParcel 80 * @tc.type: FUNC 81 * @tc.require: AR000FTAMO 82 */ 83 HWTEST_F(ImagePixelMapParcelTest, ImagePixelMapParcel002, TestSize.Level3) 84 { 85 GTEST_LOG_(INFO) << "ImagePixelMapParcelTest: ImagePixelMapParcel002 start"; 86 87 MessageParcel data; 88 89 std::unique_ptr<PixelMap> pixelmap1 = ConstructPixmap(); 90 91 bool ret = PixelMapParcel::WriteToParcel(pixelmap1.get(), data); 92 93 EXPECT_EQ(true, ret); 94 95 std::unique_ptr<PixelMap> pixelmap2 = PixelMapParcel::CreateFromParcel(data); 96 97 EXPECT_EQ(pixelmap1->GetHeight(), pixelmap2->GetHeight()); 98 EXPECT_EQ(pixelmap1->GetWidth(), pixelmap2->GetWidth()); 99 EXPECT_EQ(pixelmap1->GetPixelFormat(), pixelmap2->GetPixelFormat()); 100 EXPECT_EQ(pixelmap1->GetColorSpace(), pixelmap2->GetColorSpace()); 101 102 EXPECT_EQ(true, pixelmap1->IsSameImage(*pixelmap2)); 103 104 GTEST_LOG_(INFO) << "ImagePixelMapParcelTest: ImagePixelMapParcel002 end"; 105 } 106 } // namespace Multimedia 107 } // namespace OHOS 108