• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2022 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "base/files/file_error_or.h"
6 
7 #include "base/types/expected.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 
10 namespace base {
11 namespace {
12 
TEST(FileErrorOrDeathTest,Error)13 TEST(FileErrorOrDeathTest, Error) {
14   FileErrorOr<int> error;
15   error = unexpected(File::Error::FILE_ERROR_FAILED);
16   EXPECT_FALSE(error.has_value());
17   EXPECT_EQ(error.error(), File::Error::FILE_ERROR_FAILED);
18   EXPECT_DEATH_IF_SUPPORTED(error.value(), "");
19 }
20 
TEST(FileErrorOrDeathTest,Value)21 TEST(FileErrorOrDeathTest, Value) {
22   FileErrorOr<int> value(42);
23   EXPECT_TRUE(value.has_value());
24   EXPECT_EQ(value.value(), 42);
25   EXPECT_DEATH_IF_SUPPORTED(value.error(), "");
26 }
27 
TEST(FileErrorOrDeathTest,ConstValue)28 TEST(FileErrorOrDeathTest, ConstValue) {
29   const FileErrorOr<int> const_value(1234);
30   EXPECT_TRUE(const_value.has_value());
31   EXPECT_EQ(const_value.value(), 1234);
32   EXPECT_DEATH_IF_SUPPORTED(const_value.error(), "");
33 }
34 
35 }  // namespace
36 }  // namespace base
37