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