summaryrefslogtreecommitdiffstats
path: root/ppapi/tests/test_memory.cc
blob: ea612a4fd8496fea8529c665f9ffc3a221ac7573 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ppapi/tests/test_memory.h"

#include "ppapi/c/dev/ppb_testing_dev.h"
#include "ppapi/c/dev/ppb_memory_dev.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/module.h"
#include "ppapi/tests/testing_instance.h"

namespace {

size_t kTestBufferSize = 1000;

}  // namespace

REGISTER_TEST_CASE(Memory);

bool TestMemory::Init() {
  memory_dev_interface_ = static_cast<const PPB_Memory_Dev*>(
      pp::Module::Get()->GetBrowserInterface(PPB_MEMORY_DEV_INTERFACE));
  return memory_dev_interface_ && CheckTestingInterface();
}

void TestMemory::RunTests(const std::string& filter) {
  RUN_TEST(MemAlloc, filter);
  RUN_TEST(NullMemFree, filter);
}

std::string TestMemory::TestMemAlloc() {
  char* buffer = static_cast<char*>(
      memory_dev_interface_->MemAlloc(kTestBufferSize));
  // Touch a couple of locations.  Failure will crash the test.
  buffer[0] = '1';
  buffer[kTestBufferSize - 1] = '1';
  memory_dev_interface_->MemFree(buffer);

  PASS();
}

std::string TestMemory::TestNullMemFree() {
  // Failure crashes the test.
  memory_dev_interface_->MemFree(NULL);

  PASS();
}