1 // Copyright 2023 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14
15 #include "pw_stream_uart_linux/stream.h"
16
17 #include "public/pw_stream_uart_linux/stream.h"
18 #include "pw_unit_test/framework.h"
19
20 namespace pw::stream {
21 namespace {
22
23 // Path to a non-UART device.
24 constexpr auto kPathNonUart = "/dev/null";
25
TEST(UartStreamLinuxTest,TestOpenNonUartDevice)26 TEST(UartStreamLinuxTest, TestOpenNonUartDevice) {
27 UartStreamLinux uart;
28 Status status = uart.Open(kPathNonUart, 115200);
29 EXPECT_EQ(status, Status::Unknown());
30 }
31
TEST(UartStreamLinuxTest,TestOpenNonUartDeviceWithDefaultConfigStruct)32 TEST(UartStreamLinuxTest, TestOpenNonUartDeviceWithDefaultConfigStruct) {
33 UartStreamLinux uart;
34 // Leave config struct default initialized.
35 UartStreamLinux::Config uart_config = {};
36 Status status = uart.Open(kPathNonUart, uart_config);
37 EXPECT_EQ(status, Status::Unknown());
38 }
39
TEST(UartStreamLinuxTest,TestOpenNonUartDeviceWithPopulatedConfigStruct)40 TEST(UartStreamLinuxTest, TestOpenNonUartDeviceWithPopulatedConfigStruct) {
41 UartStreamLinux uart;
42 UartStreamLinux::Config uart_config = {
43 .baud_rate = 115200,
44 .flow_control = true,
45 };
46 Status status = uart.Open(kPathNonUart, uart_config);
47 EXPECT_EQ(status, Status::Unknown());
48 }
49
TEST(UartStreamLinuxTest,TestOpenInvalidBaudRate)50 TEST(UartStreamLinuxTest, TestOpenInvalidBaudRate) {
51 UartStreamLinux uart;
52 Status status = uart.Open(kPathNonUart, 123456);
53 EXPECT_EQ(status, Status::InvalidArgument());
54 }
55
56 } // namespace
57 } // namespace pw::stream
58