1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 #include "IDBResult.h"
6
7 #include "gtest/gtest.h"
8
9 using mozilla::ErrorResult;
10 using namespace mozilla::dom::indexedDB;
11
TEST(IDBResultTest,ConstructWithValue)12 TEST(IDBResultTest, ConstructWithValue)
13 {
14 ErrorResult rv;
15 IDBResult<int, IDBSpecialValue::Failure> result(Ok(0));
16 EXPECT_FALSE(result.Is(Failure, rv));
17 EXPECT_TRUE(result.Is(Ok, rv));
18 EXPECT_EQ(result.Unwrap(rv), 0);
19 }
20
TEST(IDBResultTest,Expand)21 TEST(IDBResultTest, Expand)
22 {
23 ErrorResult rv;
24 IDBResult<int, IDBSpecialValue::Failure> narrow{Failure};
25 IDBResult<int, IDBSpecialValue::Failure, IDBSpecialValue::Invalid> wide{
26 narrow};
27 EXPECT_TRUE(wide.Is(Failure, rv));
28 }
29
ThrowException(ErrorResult & aRv)30 IDBResult<int, IDBSpecialValue::Failure> ThrowException(ErrorResult& aRv) {
31 aRv.Throw(NS_ERROR_FAILURE);
32 return Exception;
33 }
34
TEST(IDBResultTest,ThrowException)35 TEST(IDBResultTest, ThrowException)
36 {
37 ErrorResult rv;
38 const auto result = ThrowException(rv);
39 EXPECT_TRUE(result.Is(Exception, rv));
40 rv.SuppressException();
41 }
42