test_memory.cc 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright (c) 2011 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ppapi/tests/test_memory.h"
  5. #include <stddef.h>
  6. #include <stdint.h>
  7. #include "ppapi/c/dev/ppb_memory_dev.h"
  8. #include "ppapi/cpp/instance.h"
  9. #include "ppapi/cpp/module.h"
  10. #include "ppapi/tests/testing_instance.h"
  11. namespace {
  12. size_t kTestBufferSize = 1000;
  13. } // namespace
  14. REGISTER_TEST_CASE(Memory);
  15. bool TestMemory::Init() {
  16. memory_dev_interface_ = static_cast<const PPB_Memory_Dev*>(
  17. pp::Module::Get()->GetBrowserInterface(PPB_MEMORY_DEV_INTERFACE));
  18. return memory_dev_interface_ && CheckTestingInterface();
  19. }
  20. void TestMemory::RunTests(const std::string& filter) {
  21. RUN_TEST(MemAlloc, filter);
  22. RUN_TEST(NullMemFree, filter);
  23. }
  24. std::string TestMemory::TestMemAlloc() {
  25. char* buffer = static_cast<char*>(
  26. memory_dev_interface_->MemAlloc(static_cast<uint32_t>(kTestBufferSize)));
  27. // Touch a couple of locations. Failure will crash the test.
  28. buffer[0] = '1';
  29. buffer[kTestBufferSize - 1] = '1';
  30. memory_dev_interface_->MemFree(buffer);
  31. PASS();
  32. }
  33. std::string TestMemory::TestNullMemFree() {
  34. // Failure crashes the test.
  35. memory_dev_interface_->MemFree(NULL);
  36. PASS();
  37. }