1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://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,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <cstdio>
17 #include <cstring>
18 #include <gtest/gtest.h>
19 #include <unistd.h>
20 #include "securec.h"
21 #include "lib_acm_test.h"
22 #include "hdf_base.h"
23
24 using namespace std;
25 using namespace testing::ext;
26
27 namespace {
28 class UsbDeviceSerialLoopback : public testing::Test {
29 public:
30 static void SetUpTestCase();
31 static void TearDownTestCase();
32 };
33
SetUpTestCase()34 void UsbDeviceSerialLoopback::SetUpTestCase()
35 {
36 AcmOpen();
37 }
38
TearDownTestCase()39 void UsbDeviceSerialLoopback::TearDownTestCase()
40 {
41 AcmClose();
42 }
43
44 HWTEST_F(UsbDeviceSerialLoopback, DeviceSerialLoopback, TestSize.Level1)
45 {
46 printf("------start DeviceSerialLoopback------\n");
47 char data[256] = {0};
48 int32_t ret = 0;
49 while (1) {
50 AcmRead(data);
51 if (strlen(data) > 0) {
52 if (strcmp(data, "q") == 0) {
53 break;
54 }
55 AcmWrite(data);
56 ret = memset_s(data, sizeof(data), 0, sizeof(data));
57 EXPECT_EQ(HDF_SUCCESS, ret);
58 }
59 }
60 printf("------end DeviceSerialLoopback------\n");
61 }
62 }
63