diff options
author | sbc@chromium.org <sbc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-18 17:44:50 +0000 |
---|---|---|
committer | sbc@chromium.org <sbc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-18 17:44:50 +0000 |
commit | c9a49064b71a15c9b38308b5741c99368d42fb71 (patch) | |
tree | e9a5fcea46eac8f88f1247e6842adf33aa23d991 /native_client_sdk | |
parent | 0a921d9a6187359568d1cdc9a7e9658364fe3258 (diff) | |
download | chromium_src-c9a49064b71a15c9b38308b5741c99368d42fb71.zip chromium_src-c9a49064b71a15c9b38308b5741c99368d42fb71.tar.gz chromium_src-c9a49064b71a15c9b38308b5741c99368d42fb71.tar.bz2 |
[NaCl SDK] nacl_io: add fakes for PP_Var dictionary type.
Currently nothing uses these but I created them as part
of a separate CL which is due to land soon and it made
sense to split them off.
R=binji@chromium.org
Review URL: https://codereview.chromium.org/242403002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@264812 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'native_client_sdk')
12 files changed, 183 insertions, 18 deletions
diff --git a/native_client_sdk/src/libraries/nacl_io/pepper/all_interfaces.h b/native_client_sdk/src/libraries/nacl_io/pepper/all_interfaces.h index a22e127..a889ecd 100644 --- a/native_client_sdk/src/libraries/nacl_io/pepper/all_interfaces.h +++ b/native_client_sdk/src/libraries/nacl_io/pepper/all_interfaces.h @@ -112,6 +112,14 @@ BEGIN_INTERFACE(VarArrayBufferInterface, PPB_VarArrayBuffer_1_0, METHOD1(VarArrayBufferInterface, void, Unmap, PP_Var) END_INTERFACE(VarArrayBufferInterface, PPB_VarArrayBuffer_1_0) +BEGIN_INTERFACE(VarDictionaryInterface, PPB_VarDictionary_1_0, + PPB_VAR_DICTIONARY_INTERFACE_1_0) + METHOD0(VarDictionaryInterface, PP_Var, Create) + METHOD3(VarDictionaryInterface, PP_Bool, Set, PP_Var, PP_Var, PP_Var) + METHOD2(VarDictionaryInterface, PP_Var, Get, PP_Var, PP_Var) + METHOD1(VarDictionaryInterface, PP_Var, GetKeys, PP_Var) +END_INTERFACE(VarDictionaryInterface, PPB_VarDictionary_1_0) + /* Chrome M18 required */ BEGIN_INTERFACE(VarInterface, PPB_Var_1_1, PPB_VAR_INTERFACE_1_1) METHOD1(VarInterface, void, AddRef, PP_Var) diff --git a/native_client_sdk/src/libraries/nacl_io/pepper_interface.h b/native_client_sdk/src/libraries/nacl_io/pepper_interface.h index 6b25c92..c896431 100644 --- a/native_client_sdk/src/libraries/nacl_io/pepper_interface.h +++ b/native_client_sdk/src/libraries/nacl_io/pepper_interface.h @@ -29,6 +29,7 @@ #include <ppapi/c/ppb_var.h> #include <ppapi/c/ppb_var_array.h> #include <ppapi/c/ppb_var_array_buffer.h> +#include <ppapi/c/ppb_var_dictionary.h> #include <sdk_util/macros.h> diff --git a/native_client_sdk/src/tests/nacl_io_test/example.dsc b/native_client_sdk/src/tests/nacl_io_test/example.dsc index 1a0c565..15c0f47 100644 --- a/native_client_sdk/src/tests/nacl_io_test/example.dsc +++ b/native_client_sdk/src/tests/nacl_io_test/example.dsc @@ -29,6 +29,8 @@ 'fake_ppapi/fake_var_array_buffer_interface.h', 'fake_ppapi/fake_var_array_interface.cc', 'fake_ppapi/fake_var_array_interface.h', + 'fake_ppapi/fake_var_dictionary_interface.cc', + 'fake_ppapi/fake_var_dictionary_interface.h', 'fake_ppapi/fake_var_interface.cc', 'fake_ppapi/fake_var_interface.h', 'fake_ppapi/fake_var_manager.cc', diff --git a/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface.cc b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface.cc index f070c03..21f49f5 100644 --- a/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface.cc +++ b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface.cc @@ -24,6 +24,9 @@ FakePepperInterface::FakePepperInterface() var_array_interface_(&var_manager_), var_array_buffer_interface_(&var_manager_), var_interface_(&var_manager_), + var_dictionary_interface_(&var_manager_, + &var_interface_, + &var_array_interface_), resolver_interface_(this), net_address_interface_(this) { FakeInstanceResource* instance_resource = new FakeInstanceResource; @@ -48,6 +51,10 @@ VarArrayBufferInterface* FakePepperInterface::GetVarArrayBufferInterface() { return &var_array_buffer_interface_; } +VarDictionaryInterface* FakePepperInterface::GetVarDictionaryInterface() { + return &var_dictionary_interface_; +} + VarInterface* FakePepperInterface::GetVarInterface() { return &var_interface_; } diff --git a/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface.h b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface.h index a1a5ebc..1e6786c 100644 --- a/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface.h +++ b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface.h @@ -12,6 +12,7 @@ #include "fake_ppapi/fake_resource_manager.h" #include "fake_ppapi/fake_var_array_buffer_interface.h" #include "fake_ppapi/fake_var_array_interface.h" +#include "fake_ppapi/fake_var_dictionary_interface.h" #include "fake_ppapi/fake_var_interface.h" #include "fake_ppapi/fake_var_manager.h" #include "nacl_io/pepper_interface_dummy.h" @@ -25,6 +26,7 @@ class FakePepperInterface : public nacl_io::PepperInterfaceDummy { virtual nacl_io::MessagingInterface* GetMessagingInterface(); virtual nacl_io::VarArrayInterface* GetVarArrayInterface(); virtual nacl_io::VarArrayBufferInterface* GetVarArrayBufferInterface(); + virtual nacl_io::VarDictionaryInterface* GetVarDictionaryInterface(); virtual nacl_io::VarInterface* GetVarInterface(); virtual nacl_io::HostResolverInterface* GetHostResolverInterface(); virtual nacl_io::NetAddressInterface* GetNetAddressInterface(); @@ -43,6 +45,7 @@ class FakePepperInterface : public nacl_io::PepperInterfaceDummy { FakeVarArrayInterface var_array_interface_; FakeVarArrayBufferInterface var_array_buffer_interface_; FakeVarInterface var_interface_; + FakeVarDictionaryInterface var_dictionary_interface_; FakeHostResolverInterface resolver_interface_; FakeNetAddressInterface net_address_interface_; diff --git a/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_var_array_buffer_interface.h b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_var_array_buffer_interface.h index fb48371..8f0d23e 100644 --- a/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_var_array_buffer_interface.h +++ b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_var_array_buffer_interface.h @@ -5,11 +5,6 @@ #ifndef TESTS_NACL_IO_TEST_FAKE_VAR_ARRAY_BUFFER_INTERFACE_H_ #define TESTS_NACL_IO_TEST_FAKE_VAR_ARRAY_BUFFER_INTERFACE_H_ -#include <map> -#include <string> - -#include <ppapi/c/pp_var.h> - #include "nacl_io/pepper_interface.h" #include "sdk_util/macros.h" diff --git a/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_var_array_interface.h b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_var_array_interface.h index 8b70174..1c81583 100644 --- a/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_var_array_interface.h +++ b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_var_array_interface.h @@ -5,11 +5,6 @@ #ifndef TESTS_NACL_IO_TEST_FAKE_VAR_ARRAY_INTERFACE_H_ #define TESTS_NACL_IO_TEST_FAKE_VAR_ARRAY_INTERFACE_H_ -#include <map> -#include <string> - -#include <ppapi/c/pp_var.h> - #include "nacl_io/pepper_interface.h" #include "sdk_util/macros.h" diff --git a/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_var_dictionary_interface.cc b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_var_dictionary_interface.cc new file mode 100644 index 0000000..8ae97e8 --- /dev/null +++ b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_var_dictionary_interface.cc @@ -0,0 +1,104 @@ +// Copyright 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_ppapi/fake_var_dictionary_interface.h" + +#include "fake_ppapi/fake_var_manager.h" +#include "gtest/gtest.h" + +FakeVarDictionaryInterface::FakeVarDictionaryInterface(FakeVarManager* manager, + nacl_io::VarInterface* var_interface, + nacl_io::VarArrayInterface* array_interface) : + manager_(manager), + var_interface_(var_interface), + array_interface_(array_interface) {} + + +PP_Var FakeVarDictionaryInterface::Create() { + FakeVarData* var_data = manager_->CreateVarData(); + var_data->type = PP_VARTYPE_DICTIONARY; + + struct PP_Var result = {PP_VARTYPE_DICTIONARY, 0, {PP_FALSE}}; + result.value.as_id = var_data->id; + return result; +} + +PP_Bool FakeVarDictionaryInterface::Set(PP_Var var, PP_Var key, PP_Var value) { + EXPECT_EQ(PP_VARTYPE_DICTIONARY, var.type); + EXPECT_EQ(PP_VARTYPE_STRING, key.type); + FakeVarData* data = manager_->GetVarData(var); + FakeVarData* key_data = manager_->GetVarData(key); + EXPECT_NE(static_cast<FakeVarData*>(NULL), data); + EXPECT_NE(static_cast<FakeVarData*>(NULL), key_data); + const std::string& key_string = key_data->string_value; + FakeDictType& dict = data->dict_value; + manager_->AddRef(value); + // Release any existing value + if (dict.count(key_string) > 0) { + manager_->Release(dict[key_string]); + } + dict[key_string] = value; + return PP_TRUE; +} + +PP_Var FakeVarDictionaryInterface::Get(PP_Var var, PP_Var key) { + EXPECT_EQ(PP_VARTYPE_DICTIONARY, var.type); + EXPECT_EQ(PP_VARTYPE_STRING, key.type); + FakeVarData* data = manager_->GetVarData(var); + FakeVarData* key_data = manager_->GetVarData(key); + EXPECT_NE(static_cast<FakeVarData*>(NULL), data); + EXPECT_NE(static_cast<FakeVarData*>(NULL), key_data); + FakeDictType& dict = data->dict_value; + const std::string& key_string = key_data->string_value; + PP_Var rtn = dict[key_string]; + manager_->AddRef(rtn); + return rtn; +} + +void FakeVarDictionaryInterface::Delete(PP_Var var, PP_Var key) { + EXPECT_EQ(PP_VARTYPE_DICTIONARY, var.type); + EXPECT_EQ(PP_VARTYPE_STRING, key.type); + FakeVarData* data = manager_->GetVarData(var); + FakeVarData* key_data = manager_->GetVarData(key); + EXPECT_NE(static_cast<FakeVarData*>(NULL), data); + EXPECT_NE(static_cast<FakeVarData*>(NULL), key_data); + FakeDictType& dict = data->dict_value; + const std::string& key_string = key_data->string_value; + if (dict.count(key_string) > 0) { + manager_->Release(dict[key_string]); + } + dict.erase(key_string); +} + +PP_Bool FakeVarDictionaryInterface::HasKey(PP_Var var, PP_Var key) { + EXPECT_EQ(PP_VARTYPE_DICTIONARY, var.type); + EXPECT_EQ(PP_VARTYPE_STRING, key.type); + FakeVarData* data = manager_->GetVarData(var); + FakeVarData* key_data = manager_->GetVarData(key); + EXPECT_NE(static_cast<FakeVarData*>(NULL), data); + EXPECT_NE(static_cast<FakeVarData*>(NULL), key_data); + FakeDictType& dict = data->dict_value; + const std::string& key_string = key_data->string_value; + if (dict.count(key_string) > 0) + return PP_FALSE; + return PP_TRUE; +} + +PP_Var FakeVarDictionaryInterface::GetKeys(PP_Var var) { + EXPECT_EQ(PP_VARTYPE_DICTIONARY, var.type); + FakeVarData* data = manager_->GetVarData(var); + EXPECT_NE(static_cast<FakeVarData*>(NULL), data); + FakeDictType& dict = data->dict_value; + PP_Var rtn = array_interface_->Create(); + array_interface_->SetLength(rtn, dict.size()); + int index = 0; + for (FakeDictType::iterator it = dict.begin(); it != dict.end(); it++) { + PP_Var key = var_interface_->VarFromUtf8(it->first.c_str(), + it->first.size()); + array_interface_->Set(rtn, index, key); + manager_->Release(key); + index++; + } + return rtn; +} diff --git a/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_var_dictionary_interface.h b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_var_dictionary_interface.h new file mode 100644 index 0000000..5199863 --- /dev/null +++ b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_var_dictionary_interface.h @@ -0,0 +1,34 @@ +// Copyright 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. + +#ifndef TESTS_NACL_IO_TEST_FAKE_VAR_DICTIONARY_INTERFACE_H_ +#define TESTS_NACL_IO_TEST_FAKE_VAR_DICTIONARY_INTERFACE_H_ + +#include "nacl_io/pepper_interface.h" +#include "sdk_util/macros.h" + +class FakeVarManager; + +class FakeVarDictionaryInterface : public nacl_io::VarDictionaryInterface { + public: + explicit FakeVarDictionaryInterface(FakeVarManager* manager, + nacl_io::VarInterface* var_interface, + nacl_io::VarArrayInterface* array_interface); + + virtual PP_Var Create(); + virtual PP_Var Get(PP_Var dict, PP_Var key); + virtual PP_Bool Set(PP_Var dict, PP_Var key, PP_Var value); + virtual void Delete(PP_Var dict, PP_Var key); + virtual PP_Bool HasKey(PP_Var dict, PP_Var key); + virtual PP_Var GetKeys(PP_Var dict); + + private: + FakeVarManager* manager_; + nacl_io::VarInterface* var_interface_; + nacl_io::VarArrayInterface* array_interface_; + + DISALLOW_COPY_AND_ASSIGN(FakeVarDictionaryInterface); +}; + +#endif // TESTS_NACL_IO_TEST_FAKE_VAR_DICTIONARY_INTERFACE_H_ diff --git a/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_var_interface.h b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_var_interface.h index 451553b..c6dd4ea 100644 --- a/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_var_interface.h +++ b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_var_interface.h @@ -5,8 +5,6 @@ #ifndef TESTS_NACL_IO_TEST_FAKE_VAR_INTERFACE_H_ #define TESTS_NACL_IO_TEST_FAKE_VAR_INTERFACE_H_ -#include <ppapi/c/pp_var.h> - #include "nacl_io/pepper_interface.h" #include "sdk_util/macros.h" diff --git a/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_var_manager.cc b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_var_manager.cc index eb1809e..e6c16bc 100644 --- a/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_var_manager.cc +++ b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_var_manager.cc @@ -74,18 +74,29 @@ void FakeVarManager::DestroyVarData(FakeVarData* var_data) { switch (var_data->type) { case PP_VARTYPE_ARRAY: { - std::vector<PP_Var>& vector = var_data->array_value; - for (std::vector<PP_Var>::iterator it = vector.begin(); - it != vector.end(); ++it) { + FakeArrayType& vector = var_data->array_value; + for (FakeArrayType::iterator it = vector.begin(); + it != vector.end(); ++it) { Release(*it); } vector.clear(); break; } - case PP_VARTYPE_ARRAY_BUFFER: + case PP_VARTYPE_ARRAY_BUFFER: { free(var_data->buffer_value.ptr); var_data->buffer_value.ptr = NULL; var_data->buffer_value.length = 0; + break; + } + case PP_VARTYPE_DICTIONARY: { + FakeDictType& dict = var_data->dict_value; + for (FakeDictType::iterator it = dict.begin(); + it != dict.end(); it++) { + Release(it->second); + } + dict.clear(); + break; + } default: break; } @@ -95,7 +106,10 @@ FakeVarData* FakeVarManager::GetVarData(PP_Var var) { VarMap::iterator iter = var_map_.find(var.value.as_id); if (iter == var_map_.end()) return NULL; - return &iter->second; + FakeVarData* var_data = &iter->second; + EXPECT_GT(var_data->ref_count, 0) + << "Accessing freed " << Describe(*var_data); + return var_data; } void FakeVarManager::Release(PP_Var var) { diff --git a/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_var_manager.h b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_var_manager.h index c8d1309..8f02bb5 100644 --- a/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_var_manager.h +++ b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_var_manager.h @@ -12,12 +12,16 @@ #include "sdk_util/macros.h" +typedef std::vector<PP_Var> FakeArrayType; +typedef std::map<std::string, PP_Var> FakeDictType; + struct FakeVarData { uint64_t id; uint64_t type; int32_t ref_count; std::string string_value; - std::vector<PP_Var> array_value; + FakeArrayType array_value; + FakeDictType dict_value; struct { void* ptr; uint32_t length; |