1 | // Licensed to the Apache Software Foundation (ASF) under one |
2 | // or more contributor license agreements. See the NOTICE file |
3 | // distributed with this work for additional information |
4 | // regarding copyright ownership. The ASF licenses this file |
5 | // to you under the Apache License, Version 2.0 (the |
6 | // "License"); you may not use this file except in compliance |
7 | // with the License. You may obtain a copy of the License at |
8 | // |
9 | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | // |
11 | // Unless required by applicable law or agreed to in writing, |
12 | // software distributed under the License is distributed on an |
13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | // KIND, either express or implied. See the License for the |
15 | // specific language governing permissions and limitations |
16 | // under the License. |
17 | |
18 | #include <sstream> |
19 | |
20 | #include <gtest/gtest.h> |
21 | |
22 | #include "arrow/status.h" |
23 | |
24 | namespace arrow { |
25 | |
26 | TEST(StatusTest, TestCodeAndMessage) { |
27 | Status ok = Status::OK(); |
28 | ASSERT_EQ(StatusCode::OK, ok.code()); |
29 | Status file_error = Status::IOError("file error" ); |
30 | ASSERT_EQ(StatusCode::IOError, file_error.code()); |
31 | ASSERT_EQ("file error" , file_error.message()); |
32 | } |
33 | |
34 | TEST(StatusTest, TestToString) { |
35 | Status file_error = Status::IOError("file error" ); |
36 | ASSERT_EQ("IOError: file error" , file_error.ToString()); |
37 | |
38 | std::stringstream ss; |
39 | ss << file_error; |
40 | ASSERT_EQ(file_error.ToString(), ss.str()); |
41 | } |
42 | |
43 | TEST(StatusTest, AndStatus) { |
44 | Status a = Status::OK(); |
45 | Status b = Status::OK(); |
46 | Status c = Status::Invalid("invalid value" ); |
47 | Status d = Status::IOError("file error" ); |
48 | |
49 | Status res; |
50 | res = a & b; |
51 | ASSERT_TRUE(res.ok()); |
52 | res = a & c; |
53 | ASSERT_TRUE(res.IsInvalid()); |
54 | res = d & c; |
55 | ASSERT_TRUE(res.IsIOError()); |
56 | |
57 | res = Status::OK(); |
58 | res &= c; |
59 | ASSERT_TRUE(res.IsInvalid()); |
60 | res &= d; |
61 | ASSERT_TRUE(res.IsInvalid()); |
62 | |
63 | // With rvalues |
64 | res = Status::OK() & Status::Invalid("foo" ); |
65 | ASSERT_TRUE(res.IsInvalid()); |
66 | res = Status::Invalid("foo" ) & Status::OK(); |
67 | ASSERT_TRUE(res.IsInvalid()); |
68 | res = Status::Invalid("foo" ) & Status::IOError("bar" ); |
69 | ASSERT_TRUE(res.IsInvalid()); |
70 | |
71 | res = Status::OK(); |
72 | res &= Status::OK(); |
73 | ASSERT_TRUE(res.ok()); |
74 | res &= Status::Invalid("foo" ); |
75 | ASSERT_TRUE(res.IsInvalid()); |
76 | res &= Status::IOError("bar" ); |
77 | ASSERT_TRUE(res.IsInvalid()); |
78 | } |
79 | |
80 | } // namespace arrow |
81 | |