10a7ce71fSopenharmony_ci/*
20a7ce71fSopenharmony_ci * Copyright (C) 2022 HiHope Open Source Organization .
30a7ce71fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
40a7ce71fSopenharmony_ci * you may not use this file except in compliance with the License.
50a7ce71fSopenharmony_ci * You may obtain a copy of the License at
60a7ce71fSopenharmony_ci *
70a7ce71fSopenharmony_ci *     http:// www.apache.org/licenses/LICENSE-2.0
80a7ce71fSopenharmony_ci *
90a7ce71fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
100a7ce71fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
110a7ce71fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
120a7ce71fSopenharmony_ci * See the License for the specific language governing permissions and
130a7ce71fSopenharmony_ci *
140a7ce71fSopenharmony_ci * limitations under the License.
150a7ce71fSopenharmony_ci */
160a7ce71fSopenharmony_ci
170a7ce71fSopenharmony_ci#ifndef NET_DEMO_COMMON_H
180a7ce71fSopenharmony_ci#define NET_DEMO_COMMON_H
190a7ce71fSopenharmony_ci
200a7ce71fSopenharmony_civoid NetDemoTest(unsigned short port, const char* host);
210a7ce71fSopenharmony_ci
220a7ce71fSopenharmony_ciconst char* GetNetDemoName(void);
230a7ce71fSopenharmony_ci
240a7ce71fSopenharmony_ciIMPL_GET_NET_DEMO_NAME(testFunc) { \
250a7ce71fSopenharmony_ci    const char* GetNetDemoName() { \
260a7ce71fSopenharmony_ci        static const char* demoName = #testFunc; \
270a7ce71fSopenharmony_ci        return demoName; \
280a7ce71fSopenharmony_ci    }
290a7ce71fSopenharmony_ci}
300a7ce71fSopenharmony_ci
310a7ce71fSopenharmony_ciCLIENT_TEST_DEMO(testFunc) { \
320a7ce71fSopenharmony_ci    void NetDemoTest(unsigned short port, const char* host) { \
330a7ce71fSopenharmony_ci        (void) host; \
340a7ce71fSopenharmony_ci        printf("%s start\r\n", #testFunc); \
350a7ce71fSopenharmony_ci        printf("I will connect to %s:%d\r\n", host, port); \
360a7ce71fSopenharmony_ci        testFunc(host, port); \
370a7ce71fSopenharmony_ci        printf("%s done!\r\n", #testFunc); \
380a7ce71fSopenharmony_ci    } \
390a7ce71fSopenharmony_ci}
400a7ce71fSopenharmony_ci    IMPL_GET_NET_DEMO_NAME(testFunc)
410a7ce71fSopenharmony_ci
420a7ce71fSopenharmony_ciSERVER_TEST_DEMO(testFunc) { \
430a7ce71fSopenharmony_ci    void NetDemoTest(unsigned short port, const char* host) { \
440a7ce71fSopenharmony_ci        (void) host; \
450a7ce71fSopenharmony_ci        printf("%s start\r\n", #testFunc); \
460a7ce71fSopenharmony_ci        printf("I will listen on :%d\r\n", port); \
470a7ce71fSopenharmony_ci        testFunc(port); \
480a7ce71fSopenharmony_ci        printf("%s done!\r\n", #testFunc); \
490a7ce71fSopenharmony_ci    } \
500a7ce71fSopenharmony_ci}
510a7ce71fSopenharmony_ci    IMPL_GET_NET_DEMO_NAME(testFunc)
520a7ce71fSopenharmony_ci
530a7ce71fSopenharmony_ci#endif // NET_DEMO_COMMON_H
54