Home | History | Annotate | Download | only in common_video
      1 /*
      2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
      3  *
      4  *  Use of this source code is governed by a BSD-style license
      5  *  that can be found in the LICENSE file in the root of the source
      6  *  tree. An additional intellectual property rights grant can be found
      7  *  in the file PATENTS.  All contributing project authors may
      8  *  be found in the AUTHORS file in the root of the source tree.
      9  */
     10 
     11 #include "webrtc/common_video/plane.h"
     12 
     13 #include <math.h>
     14 #include <string.h>
     15 
     16 #include "testing/gtest/include/gtest/gtest.h"
     17 
     18 namespace webrtc {
     19 
     20 TEST(TestPlane, CreateEmptyPlaneValues) {
     21   Plane plane;
     22   int size, stride;
     23   EXPECT_EQ(0, plane.allocated_size());
     24   EXPECT_EQ(0, plane.stride());
     25   EXPECT_TRUE(plane.IsZeroSize());
     26   size = 0;
     27   stride = 20;
     28   EXPECT_EQ(-1, plane.CreateEmptyPlane(size, stride, 1));
     29   EXPECT_EQ(-1, plane.CreateEmptyPlane(10, stride, size));
     30   size  = 20;
     31   stride = 0;
     32   EXPECT_EQ(-1, plane.CreateEmptyPlane(size, stride, size));
     33   stride = 20;
     34   EXPECT_EQ(0, plane.CreateEmptyPlane(size, stride, size));
     35   EXPECT_EQ(size, plane.allocated_size());
     36   EXPECT_EQ(stride, plane.stride());
     37   EXPECT_FALSE(plane.IsZeroSize());
     38 }
     39 
     40 TEST(TestPlane, ResetSize) {
     41   Plane plane;
     42   EXPECT_TRUE(plane.IsZeroSize());
     43   int allocated_size, plane_size, stride;
     44   EXPECT_EQ(0, plane.allocated_size());
     45   allocated_size = 30;
     46   plane_size = 20;
     47   stride = 10;
     48   EXPECT_EQ(0, plane.CreateEmptyPlane(allocated_size, stride, plane_size));
     49   EXPECT_EQ(allocated_size, plane.allocated_size());
     50   EXPECT_FALSE(plane.IsZeroSize());
     51   plane.ResetSize();
     52   EXPECT_TRUE(plane.IsZeroSize());
     53 }
     54 
     55 TEST(TestPlane, PlaneCopy) {
     56   Plane plane1, plane2;
     57   // Copy entire plane.
     58   plane1.CreateEmptyPlane(100, 10, 100);
     59   int size1 = plane1.allocated_size();
     60   int size2 = 30;
     61   plane2.CreateEmptyPlane(50, 15, size2);
     62   int stride1 = plane1.stride();
     63   int stride2 = plane2.stride();
     64   plane1.Copy(plane2);
     65   // Smaller size - keep buffer size as is.
     66   EXPECT_EQ(size1, plane1.allocated_size());
     67   EXPECT_EQ(stride2, plane1.stride());
     68   plane2.Copy(plane1);
     69   // Verify increment of allocated size.
     70   EXPECT_EQ(plane1.allocated_size(), plane2.allocated_size());
     71   EXPECT_EQ(stride2, plane2.stride());
     72   // Copy buffer.
     73   uint8_t buffer1[100];
     74   size1 = 80;
     75   memset(&buffer1, 0, size1);
     76   plane2.Copy(size1, stride1, buffer1);
     77   EXPECT_GE(plane2.allocated_size(), size1);
     78   EXPECT_EQ(0, memcmp(buffer1, plane2.buffer(), size1));
     79 }
     80 
     81 TEST(TestPlane, PlaneSwap) {
     82   Plane plane1, plane2;
     83   int size1, size2, stride1, stride2;
     84   plane1.CreateEmptyPlane(100, 10, 100);
     85   plane2.CreateEmptyPlane(50, 15, 50);
     86   size1 = plane1.allocated_size();
     87   stride1 = plane1.stride();
     88   stride2 = plane2.stride();
     89   size2 = plane2.allocated_size();
     90   plane1.Swap(plane2);
     91   EXPECT_EQ(size1, plane2.allocated_size());
     92   EXPECT_EQ(size2, plane1.allocated_size());
     93   EXPECT_EQ(stride2, plane1.stride());
     94   EXPECT_EQ(stride1, plane2.stride());
     95 }
     96 
     97 }  // namespace webrtc
     98