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 "pw_unit_test/framework.h"
18
19 namespace pw::stream {
20 namespace {
21
22 // Path to a non-UART device.
23 constexpr auto kPathNonUart = "/dev/null";
24
TEST(UartStreamLinuxTest,TestOpenNonUartDevice)25 TEST(UartStreamLinuxTest, TestOpenNonUartDevice) {
26 UartStreamLinux uart;
27 Status status = uart.Open(kPathNonUart, 115200);
28 EXPECT_EQ(status, Status::Unknown());
29 }
30
TEST(UartStreamLinuxTest,TestOpenNonUartDeviceWithDefaultConfigStruct)31 TEST(UartStreamLinuxTest, TestOpenNonUartDeviceWithDefaultConfigStruct) {
32 UartStreamLinux uart;
33 // Leave config struct default initialized.
34 UartStreamLinux::Config uart_config = {};
35 Status status = uart.Open(kPathNonUart, uart_config);
36 EXPECT_EQ(status, Status::Unknown());
37 }
38
TEST(UartStreamLinuxTest,TestOpenNonUartDeviceWithPopulatedConfigStruct)39 TEST(UartStreamLinuxTest, TestOpenNonUartDeviceWithPopulatedConfigStruct) {
40 UartStreamLinux uart;
41 UartStreamLinux::Config uart_config = {
42 .baud_rate = 115200,
43 .flow_control = true,
44 };
45 Status status = uart.Open(kPathNonUart, uart_config);
46 EXPECT_EQ(status, Status::Unknown());
47 }
48
TEST(UartStreamLinuxTest,TestOpenInvalidBaudRate)49 TEST(UartStreamLinuxTest, TestOpenInvalidBaudRate) {
50 UartStreamLinux uart;
51 Status status = uart.Open(kPathNonUart, 123456);
52 EXPECT_EQ(status, Status::InvalidArgument());
53 }
54
55 } // namespace
56 } // namespace pw::stream
57