Index: third_party/grpc/test/core/support/alloc_test.c |
diff --git a/third_party/WebKit/Source/modules/quota/StorageQuotaCallbacksImpl.h b/third_party/grpc/test/core/support/alloc_test.c |
similarity index 56% |
copy from third_party/WebKit/Source/modules/quota/StorageQuotaCallbacksImpl.h |
copy to third_party/grpc/test/core/support/alloc_test.c |
index 14300b33e0576462d2062bf8edd4264becbb68fd..6bdba8c3907131d90623f223ee9cc851f3b74dd6 100644 |
--- a/third_party/WebKit/Source/modules/quota/StorageQuotaCallbacksImpl.h |
+++ b/third_party/grpc/test/core/support/alloc_test.c |
@@ -1,5 +1,7 @@ |
/* |
- * Copyright (C) 2011 Google Inc. All rights reserved. |
+ * |
+ * Copyright 2015-2016, Google Inc. |
+ * All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions are |
@@ -26,42 +28,43 @@ |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ * |
*/ |
-#ifndef StorageQuotaCallbacksImpl_h |
-#define StorageQuotaCallbacksImpl_h |
- |
-#include "bindings/core/v8/ScriptPromiseResolver.h" |
-#include "modules/ModulesExport.h" |
-#include "platform/StorageQuotaCallbacks.h" |
-#include "wtf/OwnPtr.h" |
-#include "wtf/PassRefPtr.h" |
-#include "wtf/RefPtr.h" |
- |
-namespace blink { |
+#include <grpc/support/log.h> |
+#include <grpc/support/alloc.h> |
+#include "test/core/util/test_config.h" |
-class MODULES_EXPORT StorageQuotaCallbacksImpl final : public StorageQuotaCallbacks { |
- WTF_MAKE_NONCOPYABLE(StorageQuotaCallbacksImpl); |
-public: |
- static StorageQuotaCallbacksImpl* create(ScriptPromiseResolver* resolver) |
- { |
- return new StorageQuotaCallbacksImpl(resolver); |
- } |
+static void *fake_malloc(size_t size) { return (void *)size; } |
- ~StorageQuotaCallbacksImpl() override; |
+static void *fake_realloc(void *addr, size_t size) { return (void *)size; } |
- void didQueryStorageUsageAndQuota(unsigned long long usageInBytes, unsigned long long quotaInBytes) override; |
- void didGrantStorageQuota(unsigned long long usageInBytes, unsigned long long grantedQuotaInBytes) override; |
- void didFail(WebStorageQuotaError) override; |
+static void fake_free(void *addr) { |
+ *((intptr_t *)addr) = (intptr_t)0xdeadd00d; |
+} |
- DECLARE_VIRTUAL_TRACE(); |
+static void test_custom_allocs() { |
+ const gpr_allocation_functions default_fns = gpr_get_allocation_functions(); |
+ intptr_t addr_to_free = 0; |
+ int *i; |
+ gpr_allocation_functions fns = {fake_malloc, fake_realloc, fake_free}; |
-private: |
- explicit StorageQuotaCallbacksImpl(ScriptPromiseResolver*); |
+ gpr_set_allocation_functions(fns); |
+ GPR_ASSERT((void *)(size_t)0xdeadbeef == gpr_malloc(0xdeadbeef)); |
+ GPR_ASSERT((void *)(size_t)0xcafed00d == gpr_realloc(0, 0xcafed00d)); |
- Member<ScriptPromiseResolver> m_resolver; |
-}; |
+ gpr_free(&addr_to_free); |
+ GPR_ASSERT(addr_to_free == (intptr_t)0xdeadd00d); |
-} // namespace blink |
+ /* Restore and check we don't get funky values and that we don't leak */ |
+ gpr_set_allocation_functions(default_fns); |
+ GPR_ASSERT((void *)1 != (i = gpr_malloc(sizeof(*i)))); |
+ GPR_ASSERT((void *)2 != (i = gpr_realloc(i, 2))); |
+ gpr_free(i); |
+} |
-#endif // StorageQuotaCallbacksImpl_h |
+int main(int argc, char **argv) { |
+ grpc_test_init(argc, argv); |
+ test_custom_allocs(); |
+ return 0; |
+} |