Chromium Code Reviews| Index: native_client_sdk/src/tests/nacl_io_test/fake_var_array_interface.cc |
| diff --git a/native_client_sdk/src/tests/nacl_io_test/fake_var_array_interface.cc b/native_client_sdk/src/tests/nacl_io_test/fake_var_array_interface.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..078924ed5f268ef7d13bcf17a9fa5564fe16ec77 |
| --- /dev/null |
| +++ b/native_client_sdk/src/tests/nacl_io_test/fake_var_array_interface.cc |
| @@ -0,0 +1,58 @@ |
| +// Copyright (c) 2014 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 "fake_var_array_interface.h" |
| +#include "fake_var_manager.h" |
| +#include "gtest/gtest.h" |
| + |
| +FakeVarArrayInterface::FakeVarArrayInterface(FakeVarManager* manager) |
| + : manager_(manager) {} |
| + |
| + |
| +PP_Var FakeVarArrayInterface::Create() { |
| + FakeVarData* var_data = manager_->CreateVarData(); |
| + var_data->type = PP_VARTYPE_ARRAY; |
| + |
| + struct PP_Var result = {PP_VARTYPE_ARRAY, 0, {PP_FALSE}}; |
| + result.value.as_id = var_data->id; |
| + return result; |
| +} |
| + |
| +PP_Var FakeVarArrayInterface::Get(PP_Var var, uint32_t index) { |
| + assert(var.type == PP_VARTYPE_ARRAY); |
| + FakeVarData* data = manager_->GetVarData(var); |
|
binji
2014/01/17 01:31:14
NULL check? here and the rest of the file
Sam Clegg
2014/01/17 22:40:11
Done.
|
| + if (index >= data->array_value.size()) |
| + return PP_MakeUndefined(); |
| + |
| + // Return the item at the given index, after first incrementing |
| + // its refcount. It is up the callee to then call Release. |
| + PP_Var result = data->array_value[index]; |
| + manager_->AddRef(result); |
| + return result; |
| +} |
| + |
| +PP_Bool FakeVarArrayInterface::Set(PP_Var var, uint32_t index, PP_Var value) { |
| + assert(var.type == PP_VARTYPE_ARRAY); |
| + FakeVarData* data = manager_->GetVarData(var); |
| + if (index >= data->array_value.size()) |
| + data->array_value.resize(index+1); |
| + else |
| + manager_->Release(data->array_value[index]); |
| + data->array_value[index] = value; |
| + manager_->AddRef(value); |
| + return PP_TRUE; |
| +} |
| + |
| +uint32_t FakeVarArrayInterface::GetLength(PP_Var var) { |
| + assert(var.type == PP_VARTYPE_ARRAY); |
| + FakeVarData* data = manager_->GetVarData(var); |
| + return data->array_value.size(); |
| +} |
| + |
| +PP_Bool FakeVarArrayInterface::SetLength(PP_Var var, uint32_t length) { |
| + assert(var.type == PP_VARTYPE_ARRAY); |
| + FakeVarData* data = manager_->GetVarData(var); |
| + data->array_value.resize(length); |
| + return PP_TRUE; |
| +} |