/src/mozilla-central/dom/media/gtest/TestDataMutex.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
3 | | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
4 | | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | | |
6 | | #include "gtest/gtest.h" |
7 | | #include "mozilla/DataMutex.h" |
8 | | #include "nsTArray.h" |
9 | | |
10 | | using mozilla::DataMutex; |
11 | | |
12 | | struct A |
13 | | { |
14 | 0 | void Set(int a) { mValue = a; } |
15 | | int mValue; |
16 | | }; |
17 | | |
18 | | TEST(DataMutex, Basic) |
19 | 0 | { |
20 | 0 | { |
21 | 0 | DataMutex<uint32_t> i(1, "1"); |
22 | 0 | auto x = i.Lock(); |
23 | 0 | *x = 4; |
24 | 0 | ASSERT_EQ(*x, 4u); |
25 | 0 | } |
26 | 0 | { |
27 | 0 | DataMutex<A> a({ 4 }, "StructA"); |
28 | 0 | auto x = a.Lock(); |
29 | 0 | ASSERT_EQ(x->mValue, 4); |
30 | 0 | x->Set(8); |
31 | 0 | ASSERT_EQ(x->mValue, 8); |
32 | 0 | } |
33 | 0 | { |
34 | 0 | DataMutex<nsTArray<uint32_t>> _a("array"); |
35 | 0 | auto a = _a.Lock(); |
36 | 0 | auto& x = a.ref(); |
37 | 0 | ASSERT_EQ(x.Length(), 0u); |
38 | 0 | x.AppendElement(1u); |
39 | 0 | ASSERT_EQ(x.Length(), 1u); |
40 | 0 | ASSERT_EQ(x[0], 1u); |
41 | 0 | } |
42 | 0 | } |