Skip to content

Commit

Permalink
test(CSerialPortHotPlugTest): add CSerialPortHotPlugTest
Browse files Browse the repository at this point in the history
  • Loading branch information
itas109 committed Dec 17, 2024
1 parent 544990e commit 73834a3
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ target_link_libraries( ${PROJECT_NAME} gtest)

if (WIN32)
# for function availableFriendlyPorts
target_link_libraries( ${PROJECT_NAME} setupapi)
target_link_libraries( ${PROJECT_NAME} user32 advapi32 setupapi)
elseif(APPLE)
find_library(IOKIT_LIBRARY IOKit)
find_library(FOUNDATION_LIBRARY Foundation)
Expand Down
2 changes: 1 addition & 1 deletion test/benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ endif ()
add_executable( ${PROJECT_NAME} CSerialPortBenchmark.cpp ${CSerialPortSourceFiles})

if (WIN32)
target_link_libraries( ${PROJECT_NAME} setupapi)
target_link_libraries( ${PROJECT_NAME} user32 advapi32 setupapi)
elseif(APPLE)
find_library(IOKIT_LIBRARY IOKit)
find_library(FOUNDATION_LIBRARY Foundation)
Expand Down
31 changes: 31 additions & 0 deletions test/hotPlugTest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#***************************************************************************
# @file CMakeLists.txt
# @author itas109 (itas109@qq.com) \n\n
# Blog : https://blog.csdn.net/itas109 \n
# Github : https://github.com/itas109 \n
# Gitee : https://gitee.com/itas109 \n
# QQ Group : 129518033
# @brief Lightweight cross-platform serial port library based on C++
# @copyright The CSerialPort is Copyright (C) 2014 itas109 <itas109@qq.com>.
# You may use, copy, modify, and distribute the CSerialPort, under the terms
# of the LICENSE file.
############################################################################

cmake_minimum_required(VERSION 2.8.12)

project(CSerialPortHotPlug)

set(CSerialPortRootPath "${CMAKE_CURRENT_SOURCE_DIR}/../..")
include_directories(${CSerialPortRootPath}/include)

add_executable( ${PROJECT_NAME} CSerialPortHotPlugTest.cpp )

if (WIN32)
target_link_libraries( ${PROJECT_NAME} user32)
elseif(APPLE)
find_library(IOKIT_LIBRARY IOKit)
find_library(FOUNDATION_LIBRARY Foundation)
target_link_libraries( ${PROJECT_NAME} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY})
elseif(UNIX)
target_link_libraries( ${PROJECT_NAME} pthread)
endif ()
27 changes: 27 additions & 0 deletions test/hotPlugTest/CSerialPortHotPlugTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <stdio.h>

#include "CSerialPort/SerialPortHotPlug.hpp"

class MyListener : public itas109::CSerialPortHotPlugListener
{
public:
MyListener(){}

void onHotPlugEvent(const char *portName, int isAdd)
{
printf("portName: %s, isAdded: %d\n", portName, isAdd);
}
};

int main(int argc, char *argv[])
{
MyListener listener;

itas109::CSerialPortHotPlug m_serialPortHotPlug;
m_serialPortHotPlug.connectHotPlugEvent(&listener);
printf("CSerialPortHotPlug...\n");

while (true);

return 0;
}

0 comments on commit 73834a3

Please sign in to comment.