| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 { | 63 { |
| 64 return passed(response.copyData()); | 64 return passed(response.copyData()); |
| 65 } | 65 } |
| 66 | 66 |
| 67 // Test CrossThreadCopier using static_assert. | 67 // Test CrossThreadCopier using static_assert. |
| 68 | 68 |
| 69 // Verify that ThreadSafeRefCounted objects get handled correctly. | 69 // Verify that ThreadSafeRefCounted objects get handled correctly. |
| 70 class CopierThreadSafeRefCountedTest : public ThreadSafeRefCounted<CopierThreadS
afeRefCountedTest> { | 70 class CopierThreadSafeRefCountedTest : public ThreadSafeRefCounted<CopierThreadS
afeRefCountedTest> { |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 // Add a generic specialization which will let's us verify that no other templat
e matches. |
| 74 template<typename T> struct CrossThreadCopierBase<T, false> { |
| 75 typedef int Type; |
| 76 }; |
| 77 |
| 73 static_assert((std::is_same< | 78 static_assert((std::is_same< |
| 74 PassRefPtr<CopierThreadSafeRefCountedTest>, | 79 PassRefPtr<CopierThreadSafeRefCountedTest>, |
| 75 CrossThreadCopier<PassRefPtr<CopierThreadSafeRefCountedTest>>::Type | 80 CrossThreadCopier<PassRefPtr<CopierThreadSafeRefCountedTest>>::Type |
| 76 >::value), | 81 >::value), |
| 77 "PassRefPtr test"); | 82 "PassRefPtr + ThreadSafeRefCounted should pass CrossThreadCopier"); |
| 78 static_assert((std::is_same< | 83 static_assert((std::is_same< |
| 79 PassRefPtr<CopierThreadSafeRefCountedTest>, | 84 RefPtr<CopierThreadSafeRefCountedTest>, |
| 80 CrossThreadCopier<RefPtr<CopierThreadSafeRefCountedTest>>::Type | 85 CrossThreadCopier<RefPtr<CopierThreadSafeRefCountedTest>>::Type |
| 81 >::value), | 86 >::value), |
| 82 "RefPtr test"); | 87 "RefPtr + ThreadSafeRefCounted should pass CrossThreadCopier"); |
| 83 static_assert((std::is_same< | 88 static_assert((std::is_same< |
| 84 PassRefPtr<CopierThreadSafeRefCountedTest>, | 89 int, |
| 85 CrossThreadCopier<CopierThreadSafeRefCountedTest*>::Type | 90 CrossThreadCopier<CopierThreadSafeRefCountedTest*>::Type |
| 86 >::value), | 91 >::value), |
| 87 "RawPointer test"); | 92 "Raw pointer + ThreadSafeRefCounted should NOT pass CrossThreadCopier"); |
| 88 | |
| 89 | |
| 90 // Add a generic specialization which will let's us verify that no other templat
e matches. | |
| 91 template<typename T> struct CrossThreadCopierBase<T, false, false> { | |
| 92 typedef int Type; | |
| 93 }; | |
| 94 | 93 |
| 95 // Verify that RefCounted objects only match our generic template which exposes
Type as int. | 94 // Verify that RefCounted objects only match our generic template which exposes
Type as int. |
| 96 class CopierRefCountedTest : public RefCounted<CopierRefCountedTest> { | 95 class CopierRefCountedTest : public RefCounted<CopierRefCountedTest> { |
| 97 }; | 96 }; |
| 98 | 97 |
| 99 static_assert((std::is_same< | 98 static_assert((std::is_same< |
| 100 int, | 99 int, |
| 101 CrossThreadCopier<PassRefPtr<CopierRefCountedTest>>::Type | |
| 102 >::value), | |
| 103 "PassRefPtr<RefCountedTest> test"); | |
| 104 | |
| 105 static_assert((std::is_same< | |
| 106 int, | |
| 107 CrossThreadCopier<RefPtr<CopierRefCountedTest>>::Type | |
| 108 >::value), | |
| 109 "RefPtr<RefCounted> test"); | |
| 110 | |
| 111 static_assert((std::is_same< | |
| 112 int, | |
| 113 CrossThreadCopier<CopierRefCountedTest*>::Type | 100 CrossThreadCopier<CopierRefCountedTest*>::Type |
| 114 >::value), | 101 >::value), |
| 115 "Raw pointer RefCounted test"); | 102 "Raw pointer + RefCounted should NOT pass CrossThreadCopier"); |
| 116 | 103 |
| 117 // Verify that std::unique_ptr gets passed through. | 104 // Verify that std::unique_ptr gets passed through. |
| 118 static_assert((std::is_same< | 105 static_assert((std::is_same< |
| 119 std::unique_ptr<float>, | 106 std::unique_ptr<float>, |
| 120 CrossThreadCopier<std::unique_ptr<float>>::Type | 107 CrossThreadCopier<std::unique_ptr<float>>::Type |
| 121 >::value), | 108 >::value), |
| 122 "std::unique_ptr test"); | 109 "std::unique_ptr test"); |
| 123 | 110 |
| 124 } // namespace blink | 111 } // namespace blink |
| OLD | NEW |