集成gtest测试框架
parent
8d8b9839e5
commit
88ce90857a
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* @Author: caiyuzheng
|
* @Author: caiyuzheng
|
||||||
* @Date: 2021-10-06 23:05:26
|
* @Date: 2021-10-06 23:05:26
|
||||||
* @LastEditTime: 2021-11-17 17:24:46
|
* @LastEditTime: 2021-11-18 11:14:20
|
||||||
* @LastEditors: Please set LastEditors
|
* @LastEditors: Please set LastEditors
|
||||||
* @Description: In User Settings Edit
|
* @Description: In User Settings Edit
|
||||||
* @FilePath: \generallib\general\src\threadsafe\thread_safe_list.h
|
* @FilePath: \generallib\general\src\threadsafe\thread_safe_list.h
|
||||||
|
@ -75,20 +75,18 @@ public:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
using vIterator = typename std::list<T>::iterator;
|
using vIterator = typename std::list<T>::iterator;
|
||||||
vIterator PopFront()
|
vIterator Front()
|
||||||
{
|
{
|
||||||
if (!m_data.empty())
|
if (!m_data.empty())
|
||||||
{
|
{
|
||||||
m_mux.lock();
|
m_mux.lock();
|
||||||
auto ret = m_data.begin();
|
auto ret = m_data.begin();
|
||||||
auto ret1 = *ret;
|
|
||||||
m_data.erase(ret);
|
|
||||||
m_mux.unlock();
|
m_mux.unlock();
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
return m_data.end();
|
return m_data.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
T PopFrontAndWait()
|
T PopFrontAndWait()
|
||||||
{
|
{
|
||||||
if (!m_data.empty())
|
if (!m_data.empty())
|
||||||
|
@ -121,18 +119,6 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
T Front()
|
|
||||||
{
|
|
||||||
if (!m_data.empty())
|
|
||||||
{
|
|
||||||
m_mux.lock();
|
|
||||||
auto ret = m_data.front();
|
|
||||||
m_mux.unlock();
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
return T();
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t Length()
|
uint32_t Length()
|
||||||
{
|
{
|
||||||
return m_data.size();
|
return m_data.size();
|
||||||
|
|
|
@ -2,15 +2,26 @@ cmake_minimum_required(VERSION 3.12)
|
||||||
project(cpp11)
|
project(cpp11)
|
||||||
add_definitions(-std=c++11)
|
add_definitions(-std=c++11)
|
||||||
|
|
||||||
|
|
||||||
|
set(CMAKE_BUILD_TYPE DEBUG)
|
||||||
|
set(CMAKE_CXX_FLAGS " /MTd ")
|
||||||
|
set(CMAKE_CXX_FLAGS_DEBUG "/DEBUG")
|
||||||
|
set(CMAKE_CXX_FLAGS_RELEASE "")
|
||||||
|
|
||||||
message("current dir" ${CMAKE_CURRENT_SOURCE_DIR})
|
message("current dir" ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
# set(CMAKE_CXX_FLAGS "-fno-elide-constructors")
|
|
||||||
message(info ${SOURCE})
|
message(info ${SOURCE})
|
||||||
link_directories("./third/jsoncpp/lib/")
|
link_directories("./third/jsoncpp/lib/")
|
||||||
link_directories("../../../obj/")
|
link_directories("../../../obj/")
|
||||||
|
link_directories("./third/gtest/lib")
|
||||||
|
|
||||||
link_libraries(generallib)
|
link_libraries(generallib)
|
||||||
|
link_libraries(gtestd)
|
||||||
|
|
||||||
add_executable(cpp11 cpp11_test.cpp )
|
add_executable(cpp11 cpp11_test.cpp )
|
||||||
|
add_executable(gtest gtest.cpp )
|
||||||
|
|
||||||
include_directories("./third/jsoncpp/include/pkgsrc/include/json")
|
include_directories("./third/jsoncpp/include/pkgsrc/include/json")
|
||||||
include_directories("../../../obj/inc/")
|
include_directories("../../../obj/inc/")
|
||||||
|
include_directories("./third/gtest/include")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* @Author: your name
|
* @Author: your name
|
||||||
* @Date: 2021-03-15 23:07:25
|
* @Date: 2021-03-15 23:07:25
|
||||||
* @LastEditTime: 2021-11-17 17:17:37
|
* @LastEditTime: 2021-11-18 11:14:15
|
||||||
* @LastEditors: Please set LastEditors
|
* @LastEditors: Please set LastEditors
|
||||||
* @Description: In User Settings Edit
|
* @Description: In User Settings Edit
|
||||||
* @FilePath: \cpp11\cpp11_test.cpp
|
* @FilePath: \cpp11\cpp11_test.cpp
|
||||||
|
@ -41,11 +41,11 @@ int main(int argc, char **argv)
|
||||||
((ThreadSafeList<int>*)p)->PushFront(123);
|
((ThreadSafeList<int>*)p)->PushFront(123);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
auto x = ip.Front();
|
||||||
|
std::cout<<*x<<"\r\n";
|
||||||
|
|
||||||
std::cout<<ip.PopFrontAndWait()<<"\r\n";
|
std::cout<<ip.PopFrontAndWait()<<"\r\n";
|
||||||
std::cout<<ip.PopFrontAndWait()<<"\r\n";
|
std::cout<<ip.PopFrontAndWait()<<"\r\n";
|
||||||
std::cout<<ip.PopFrontAndWait()<<"\r\n";
|
|
||||||
|
|
||||||
|
|
||||||
t1.join();
|
t1.join();
|
||||||
// std::cout<<"test start"<<endl;
|
// std::cout<<"test start"<<endl;
|
||||||
|
|
|
@ -27,6 +27,7 @@ void async_cb(uv_async_t* handle)
|
||||||
int id = GetCurrentThreadId();
|
int id = GetCurrentThreadId();
|
||||||
printf("async_cb called!\n");
|
printf("async_cb called!\n");
|
||||||
printf("thread id:%lu.\n", id);
|
printf("thread id:%lu.\n", id);
|
||||||
|
|
||||||
//uv_close((uv_handle_t*)&async, close_cb); //如果async没有关闭,消息队列是会阻塞的
|
//uv_close((uv_handle_t*)&async, close_cb); //如果async没有关闭,消息队列是会阻塞的
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue