OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2016 Eyeo GmbH |
| 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. |
| 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ |
| 17 |
| 18 #include <gtest/gtest.h> |
| 19 #include "BaseJsTest.h" |
| 20 |
| 21 #include "JsLatch.h" |
| 22 #include "../src/JsEngineTransition.h" |
| 23 |
| 24 TEST(Latch, InstanceZero) |
| 25 { |
| 26 Latch x(0); |
| 27 ASSERT_TRUE(x.TryWait()); |
| 28 } |
| 29 |
| 30 TEST(Latch, InstanceOne) |
| 31 { |
| 32 Latch x(1); |
| 33 ASSERT_FALSE(x.TryWait()); |
| 34 } |
| 35 |
| 36 /* |
| 37 * Verify that Wait() does not block when the latch is initialized to zero in th
e same thread. |
| 38 */ |
| 39 TEST(Latch, InitialZeroSameThread) |
| 40 { |
| 41 ASSERT_NO_THROW( |
| 42 { |
| 43 Latch x(0); |
| 44 x.Wait(); |
| 45 }); |
| 46 } |
| 47 |
| 48 /* |
| 49 * Verify that Wait() does not block when the latch becomes zero in the same thr
ead. |
| 50 */ |
| 51 TEST(Latch, BecomesZeroSameThread) |
| 52 { |
| 53 ASSERT_NO_THROW( |
| 54 { |
| 55 Latch x(1); |
| 56 x.Arrive(); |
| 57 ASSERT_TRUE(x.TryWait()); |
| 58 x.Wait(); |
| 59 }); |
| 60 } |
| 61 |
| 62 namespace |
| 63 { |
| 64 struct JsTestingLatchTest |
| 65 : public BaseJsTest |
| 66 { |
| 67 JsEngineInternal* engine; |
| 68 |
| 69 void SetUp() |
| 70 { |
| 71 BaseJsTest::SetUp(); |
| 72 engine = ToInternal(jsEngine); |
| 73 } |
| 74 }; |
| 75 } |
| 76 |
| 77 TEST_F(JsTestingLatchTest, Instance) |
| 78 { |
| 79 JsTestingLatch x(engine, "foo"); |
| 80 } |
| 81 |
| 82 TEST_F(JsTestingLatchTest, InstanceInIsolate) |
| 83 { |
| 84 JsTestingLatch x(engine, "foo"); |
| 85 auto y = engine->Evaluate("foo"); |
| 86 ASSERT_FALSE(y->IsUndefined()); |
| 87 y = engine->Evaluate("foo.Arrive()"); |
| 88 ASSERT_TRUE(x.GetLatch().TryWait()); |
| 89 x.Wait(); |
| 90 } |
| 91 |
OLD | NEW |