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
23 using namespace std;
24 using namespace testing::ext;
25
26 namespace {
27 class UsbDeviceSerialLoopback : public testing::Test {
28 public:
29 static void SetUpTestCase();
30 static void TearDownTestCase();
31 };
32
SetUpTestCase()33 void UsbDeviceSerialLoopback::SetUpTestCase()
34 {
35 AcmOpen();
36 }
37
TearDownTestCase()38 void UsbDeviceSerialLoopback::TearDownTestCase()
39 {
40 AcmClose();
41 }
42
43 HWTEST_F(UsbDeviceSerialLoopback, DeviceSerialLoopback, TestSize.Level1)
44 {
45 printf("------start DeviceSerialLoopback------\n");
46 char data[256] = {0};
47 while (1) {
48 AcmRead(data);
49 if (strlen(data) > 0) {
50 if (strcmp(data, "q") == 0) {
51 break;
52 }
53 AcmWrite(data);
54 memset_s(data, sizeof(data), 0, sizeof(data));
55 }
56 }
57 printf("------end DeviceSerialLoopback------\n");
58 }
59 }
60