1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include <cstdint> 18 19 #include <gtest/gtest.h> 20 21 #include "netdutils/Status.h" 22 #include "netdutils/StatusOr.h" 23 24 namespace android { 25 namespace netdutils { 26 27 TEST(StatusTest, smoke) { 28 // Expect the following lines to compile 29 Status status1(1); 30 Status status2(status1); 31 Status status3 = status1; 32 const Status status4(8); 33 const Status status5(status4); 34 const Status status6 = status4; 35 36 // Default constructor 37 EXPECT_EQ(status::ok, Status()); 38 } 39 40 TEST(StatusOrTest, ostream) { 41 { 42 StatusOr<int> so(11); 43 std::stringstream ss; 44 ss << so; 45 EXPECT_EQ("StatusOr[status: Status[code: 0, msg: ], value: 11]", ss.str()); 46 } 47 { 48 StatusOr<int> err(status::undefined); 49 std::stringstream ss; 50 ss << err; 51 EXPECT_EQ("StatusOr[status: Status[code: 2147483647, msg: undefined]]", ss.str()); 52 } 53 } 54 55 } // namespace netdutils 56 } // namespace android 57