Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 68d36a3c authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Remove libbufferhub mocks/" into oc-dev

parents 31d8ab2e deb91680
Loading
Loading
Loading
Loading
+0 −57
Original line number Diff line number Diff line
#ifndef LIB_LIBBUFFERHUB_PRIVATE_DVR_BUFFER_HUB_CLIENT_H_  // NOLINT
#define LIB_LIBBUFFERHUB_PRIVATE_DVR_BUFFER_HUB_CLIENT_H_
#include <gmock/gmock.h>
#include <gtest/gtest.h>

// TODO(jwcai) mock not need for now
class native_handle_t;

namespace android {
namespace dvr {

// TODO(jwcai) mock not need for now
class IonBuffer;

class BufferHubBuffer {
 public:
  MOCK_METHOD1(Poll, int(int timeout_ms));
  MOCK_METHOD6(Lock, bool(int usage, int x, int y, int width, int height,
                          void** addr));
  MOCK_METHOD0(Unlock, int());

  MOCK_METHOD0(native_handle, native_handle_t*());
  MOCK_METHOD0(buffer, IonBuffer*());
  MOCK_METHOD0(event_fd, int());

  MOCK_METHOD0(id, int());
  MOCK_METHOD0(width, int());
  MOCK_METHOD0(height, int());
  MOCK_METHOD0(stride, int());
  MOCK_METHOD0(format, int());
  MOCK_METHOD0(usage, int());
};

class BufferProducer : public BufferHubBuffer {
 public:
  // Note that static method |CreateBuffer| and |Import| are not mocked
  // here, they are just implementation details and thus not needed.
  MOCK_METHOD2(Post, int(int ready_fence, uint64_t sequence));
  MOCK_METHOD1(Gain, int(int* release_fence));

  static BufferProducer* staticObject;
};

class BufferConsumer : public BufferHubBuffer {
 public:
  MOCK_METHOD2(Acquire, int(int* ready_fence, uint64_t* sequence));
  MOCK_METHOD1(Release, int(int release_fence));
  MOCK_METHOD0(Discard, int());
  MOCK_METHOD3(DoAcquire,
               int(int* ready_fence, void* meta, size_t meta_size_bytes));

  static BufferConsumer* staticObject;
};

}  // namespace dvr
}  // namespace android
#endif  // LIB_LIBBUFFERHUB_PRIVATE_DVR_BUFFER_HUB_CLIENT_H_  //NOLINT
+0 −23
Original line number Diff line number Diff line
config("gralloc_config") {
  include_dirs = [ "." ]
}

static_library("gralloc") {
  testonly = true

  sources = [
    "gralloc.cpp",
    "gralloc.h",
  ]

  include_dirs = [
    "//system/core/include",
    "//hardware/libhardware/include",
  ]

  public_deps = [
    "//dreamos/external/gmock",
  ]

  public_configs = [ ":gralloc_config" ]
}
+0 −68
Original line number Diff line number Diff line
#include <gralloc_mock.h>
#include <hardware/gralloc.h>

static alloc_device_t sdevice;

static int local_registerBuffer(struct gralloc_module_t const*,
                                buffer_handle_t handle) {
  return GrallocMock::staticObject->registerBuffer(handle);
}

static int local_unregisterBuffer(struct gralloc_module_t const*,
                                  buffer_handle_t handle) {
  return GrallocMock::staticObject->unregisterBuffer(handle);
}

static int local_unlock(struct gralloc_module_t const*,
                        buffer_handle_t handle) {
  return GrallocMock::staticObject->unlock(handle);
}

static int local_lock(struct gralloc_module_t const*, buffer_handle_t handle,
                      int usage, int l, int t, int w, int h, void** vaddr) {
  return GrallocMock::staticObject->lock(handle, usage, l, t, w, h, vaddr);
}

static int local_alloc(struct alloc_device_t*, int w, int h, int format,
                       int usage, buffer_handle_t* handle, int* stride) {
  return GrallocMock::staticObject->alloc(w, h, format, usage, handle, stride);
}

static int local_free(struct alloc_device_t*, buffer_handle_t handle) {
  return GrallocMock::staticObject->free(handle);
}

static int local_open(const struct hw_module_t*, const char*,
                      struct hw_device_t** device) {
  sdevice.alloc = local_alloc;
  sdevice.free = local_free;
  *device = reinterpret_cast<hw_device_t*>(&sdevice);
  return 0;
}

static hw_module_methods_t smethods;

static gralloc_module_t smodule;

int hw_get_module(const char*, const struct hw_module_t** module) {
  smodule.registerBuffer = local_registerBuffer;
  smodule.unregisterBuffer = local_unregisterBuffer;
  smodule.lock = local_lock;
  smodule.unlock = local_unlock;
  smethods.open = local_open;
  smodule.common.methods = &smethods;
  *module = reinterpret_cast<hw_module_t*>(&smodule);
  return 0;
}

int native_handle_close(const native_handle_t* handle) {
  return GrallocMock::staticObject->native_handle_close(handle);
}

int native_handle_delete(native_handle_t* handle) {
  return GrallocMock::staticObject->native_handle_delete(handle);
}

native_handle_t* native_handle_create(int numFds, int numInts) {
  return GrallocMock::staticObject->native_handle_create(numFds, numInts);
}
+0 −23
Original line number Diff line number Diff line
#ifndef LIB_LIBBUFFERHUB_MOCKS_GRALLOC_GRALLOC_MOCK_H_
#define LIB_LIBBUFFERHUB_MOCKS_GRALLOC_GRALLOC_MOCK_H_
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <hardware/gralloc.h>

// IonBuffer is an abstraction of Ion/Gralloc buffers.
class GrallocMock {
 public:
  // Add methods here.
  MOCK_METHOD1(native_handle_close, int(const native_handle_t*));
  MOCK_METHOD1(native_handle_delete, int(native_handle_t*));
  MOCK_METHOD2(native_handle_create, native_handle_t*(int, int));
  MOCK_METHOD1(registerBuffer, int(buffer_handle_t));
  MOCK_METHOD1(unregisterBuffer, int(buffer_handle_t));
  MOCK_METHOD7(lock, int(buffer_handle_t, int, int, int, int, int, void**));
  MOCK_METHOD1(unlock, int(buffer_handle_t));
  MOCK_METHOD6(alloc, int(int, int, int, int, buffer_handle_t*, int*));
  MOCK_METHOD1(free, int(buffer_handle_t));
  static GrallocMock* staticObject;
};

#endif  // LIB_LIBBUFFERHUB_MOCKS_GRALLOC_GRALLOC_MOCK_H_
+0 −78
Original line number Diff line number Diff line
// This file has a big hack, it "mocks" the actual IonBuffer by redefining
// it with mock methods and using the same header guard to prevent the original
// definition from being included in the same context.
#ifndef LIB_LIBBUFFERHUB_PRIVATE_DVR_ION_BUFFER_H_  // NOLINT
#define LIB_LIBBUFFERHUB_PRIVATE_DVR_ION_BUFFER_H_
#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include <hardware/gralloc.h>

namespace android {
namespace dvr {

// IonBuffer is an abstraction of Ion/Gralloc buffers.
class IonBufferMock {
 public:
  IonBufferMock() {}
  MOCK_METHOD0(GetGrallocModuleImpl, gralloc_module_t const*());
  MOCK_METHOD6(Import, int(buffer_handle_t handle, int width, int height,
                           int layer_count, int stride, int format, int usage));
  MOCK_METHOD9(Import,
               int(const int* fd_array, int fd_count, const int* int_array,
                   int int_count, int width, int height, int layer_count,
                   int stride, int format, int usage));
  MOCK_METHOD6(Lock, int(int usage, int x, int y, int width, int height,
                         void** address));
  MOCK_METHOD0(Unlock, int());
  MOCK_CONST_METHOD0(handle, buffer_handle_t());
  MOCK_CONST_METHOD0(width, int());
  MOCK_CONST_METHOD0(height, int());
  MOCK_CONST_METHOD0(layer_count, int());
  MOCK_CONST_METHOD0(stride, int());
  MOCK_CONST_METHOD0(format, int());
  MOCK_CONST_METHOD0(usage, int());
};

// IonBuffer is an abstraction of Ion/Gralloc buffers.
class IonBuffer {
 public:
  IonBuffer() : mock_(new IonBufferMock) {
    if (initializer) {
      initializer(mock_.get());
    }
  }
  IonBuffer(IonBuffer&& other) = default;
  static gralloc_module_t const* GetGrallocModule() {
    return staticObject->GetGrallocModuleImpl();
  }
  int Import(buffer_handle_t handle, int width, int height, int layer_count,
             int stride, int format, int usage) {
    return mock_->Import(handle, width, height, layer_count, stride, format,
                         usage);
  }
  int Import(const int* fd_array, int fd_count, const int* int_array,
             int int_count, int width, int height, int layer_count, int stride,
             int format, int usage) {
    return mock_->Import(fd_array, fd_count, int_array, int_count, width,
                         height, layer_count, stride, format, usage);
  }
  int Lock(int usage, int x, int y, int width, int height, void** address) {
    return mock_->Lock(usage, x, y, width, height, address);
  }
  int Unlock() { return mock_->Unlock(); }
  buffer_handle_t handle() const { return mock_->handle(); }
  int width() const { return mock_->width(); }
  int height() const { return mock_->height(); }
  int layer_count() const { return mock_->layer_count(); }
  int stride() const { return mock_->stride(); }
  int format() const { return mock_->format(); }
  int usage() const { return mock_->usage(); }
  std::unique_ptr<IonBufferMock> mock_;
  static IonBufferMock* staticObject;
  static void (*initializer)(IonBufferMock* target);
};

}  // namespace dvr
}  // namespace android
#endif  // LIB_LIBBUFFERHUB_PRIVATE_DVR_ION_BUFFER_H_ - NOLINT