• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "usb_host_serial_loopback.h"
17 #include <cstdio>
18 #include <cstring>
19 #include <gtest/gtest.h>
20 #include <unistd.h>
21 #include "securec.h"
22 #include "usbhost_ddk_test.h"
23 #include "hdf_base.h"
24 
25 using namespace std;
26 using namespace testing::ext;
27 
28 namespace {
29 class UsbHostSerialLoopback : public testing::Test {
30 public:
31     static void SetUpTestCase();
32     static void TearDownTestCase();
33 };
34 
SetUpTestCase()35 void UsbHostSerialLoopback::SetUpTestCase()
36 {
37     const char *apiType = "-SDK";
38     UsbHostDdkTestInit(const_cast<char*>(apiType));
39 }
40 
TearDownTestCase()41 void UsbHostSerialLoopback::TearDownTestCase()
42 {
43     TestExit();
44 }
45 
46 HWTEST_F(UsbHostSerialLoopback, HostSerialLoopback, TestSize.Level1)
47 {
48     printf("------start HostSerialLoopback------\n");
49     char data[512] = {0};
50     int32_t ret = 0;
51     while (true) {
52         ret = UsbHostDdkTestOpen(HOST_ACM_SYNC_READ);
53         EXPECT_EQ(HDF_SUCCESS, ret);
54         UsbHostDdkTestSyncRead(data);
55         ret = UsbHostDdkTestClose(HOST_ACM_SYNC_READ);
56         EXPECT_EQ(HDF_SUCCESS, ret);
57         if (strlen(data) > 0) {
58             if (strcmp(data, "q") == 0) {
59                 break;
60             }
61             ret = UsbHostDdkTestOpen(HOST_ACM_SYNC_WRITE);
62             EXPECT_EQ(HDF_SUCCESS, ret);
63             UsbHostDdkTestSyncWrite(data);
64             ret = UsbHostDdkTestClose(HOST_ACM_SYNC_WRITE);
65             EXPECT_EQ(HDF_SUCCESS, ret);
66             memset_s(data, sizeof(data), 0, sizeof(data));
67         }
68     }
69     printf("------end HostSerialLoopback------\n");
70 }
71 }