Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit 9ebd246

Browse files
committed
Fix missing exception header
1 parent 8fa297a commit 9ebd246

9 files changed

Lines changed: 229 additions & 227 deletions

test/TestConnection.cpp

Lines changed: 113 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,113 @@
1-
#include "xapi/internals/Connection.hpp"
2-
#include "xapi/internals/Exceptions.hpp"
3-
#include <gtest/gtest.h>
4-
#include <string>
5-
#include <vector>
6-
7-
using namespace xapi;
8-
9-
class ConnectionTest : public testing::Test
10-
{
11-
protected:
12-
void SetUp() override
13-
{
14-
}
15-
16-
void TearDown() override
17-
{
18-
}
19-
20-
public:
21-
boost::asio::io_context &getIoContext()
22-
{
23-
return m_context;
24-
}
25-
26-
template <typename Awaitable> auto runAwaitable(Awaitable &&awaitable)
27-
{
28-
std::exception_ptr eptr;
29-
using result_type = typename Awaitable::value_type;
30-
result_type result;
31-
32-
boost::asio::co_spawn(
33-
m_context,
34-
[&]() -> boost::asio::awaitable<void> {
35-
try
36-
{
37-
result = co_await std::forward<Awaitable>(awaitable);
38-
}
39-
catch (...)
40-
{
41-
eptr = std::current_exception();
42-
}
43-
},
44-
boost::asio::detached);
45-
46-
m_context.run();
47-
48-
if (eptr)
49-
{
50-
std::rethrow_exception(eptr);
51-
}
52-
53-
return result;
54-
}
55-
56-
template <typename Awaitable> auto runAwaitableVoid(Awaitable &&awaitable)
57-
{
58-
std::exception_ptr eptr;
59-
boost::asio::co_spawn(
60-
m_context,
61-
[&]() -> boost::asio::awaitable<void> {
62-
try
63-
{
64-
co_await std::forward<Awaitable>(awaitable);
65-
}
66-
catch (...)
67-
{
68-
eptr = std::current_exception();
69-
}
70-
},
71-
boost::asio::detached);
72-
73-
m_context.run();
74-
75-
if (eptr)
76-
{
77-
std::rethrow_exception(eptr);
78-
}
79-
}
80-
81-
private:
82-
boost::asio::io_context m_context;
83-
};
84-
85-
TEST_F(ConnectionTest, connect_exception)
86-
{
87-
internals::Connection connection(getIoContext());
88-
EXPECT_THROW(runAwaitableVoid(connection.connect(boost::url("wss://localhost:99999"))), exception::ConnectionClosed);
89-
}
90-
91-
TEST_F(ConnectionTest, disconnect_exception)
92-
{
93-
internals::Connection connection(getIoContext());
94-
EXPECT_NO_THROW(runAwaitableVoid(connection.disconnect()));
95-
}
96-
97-
TEST_F(ConnectionTest, makeRequest_exception)
98-
{
99-
internals::Connection connection(getIoContext());
100-
101-
boost::json::object command;
102-
command["command"] = "invalid";
103-
EXPECT_THROW(runAwaitableVoid(connection.makeRequest(command)), exception::ConnectionClosed);
104-
}
105-
106-
TEST_F(ConnectionTest, waitResponse_exception)
107-
{
108-
internals::Connection connection(getIoContext());
109-
110-
boost::json::object result;
111-
EXPECT_THROW(result = runAwaitable(connection.waitResponse()), exception::ConnectionClosed);
112-
EXPECT_TRUE(result.empty());
113-
}
1+
#include "xapi/internals/Connection.hpp"
2+
#include "xapi/internals/Exceptions.hpp"
3+
#include <gtest/gtest.h>
4+
#include <string>
5+
#include <vector>
6+
7+
using namespace xapi;
8+
9+
class ConnectionTest : public testing::Test
10+
{
11+
protected:
12+
void SetUp() override
13+
{
14+
}
15+
16+
void TearDown() override
17+
{
18+
}
19+
20+
public:
21+
boost::asio::io_context &getIoContext()
22+
{
23+
return m_context;
24+
}
25+
26+
template <typename Awaitable> auto runAwaitable(Awaitable &&awaitable)
27+
{
28+
std::exception_ptr eptr;
29+
using result_type = typename Awaitable::value_type;
30+
result_type result;
31+
32+
boost::asio::co_spawn(
33+
m_context,
34+
[&]() -> boost::asio::awaitable<void> {
35+
try
36+
{
37+
result = co_await std::forward<Awaitable>(awaitable);
38+
}
39+
catch (...)
40+
{
41+
eptr = std::current_exception();
42+
}
43+
},
44+
boost::asio::detached);
45+
46+
m_context.run();
47+
48+
if (eptr)
49+
{
50+
std::rethrow_exception(eptr);
51+
}
52+
53+
return result;
54+
}
55+
56+
template <typename Awaitable> auto runAwaitableVoid(Awaitable &&awaitable)
57+
{
58+
std::exception_ptr eptr;
59+
boost::asio::co_spawn(
60+
m_context,
61+
[&]() -> boost::asio::awaitable<void> {
62+
try
63+
{
64+
co_await std::forward<Awaitable>(awaitable);
65+
}
66+
catch (...)
67+
{
68+
eptr = std::current_exception();
69+
}
70+
},
71+
boost::asio::detached);
72+
73+
m_context.run();
74+
75+
if (eptr)
76+
{
77+
std::rethrow_exception(eptr);
78+
}
79+
}
80+
81+
private:
82+
boost::asio::io_context m_context;
83+
};
84+
85+
TEST_F(ConnectionTest, connect_exception)
86+
{
87+
internals::Connection connection(getIoContext());
88+
EXPECT_THROW(runAwaitableVoid(connection.connect(boost::url("wss://localhost:99999"))), exception::ConnectionClosed);
89+
}
90+
91+
TEST_F(ConnectionTest, disconnect_exception)
92+
{
93+
internals::Connection connection(getIoContext());
94+
EXPECT_NO_THROW(runAwaitableVoid(connection.disconnect()));
95+
}
96+
97+
TEST_F(ConnectionTest, makeRequest_exception)
98+
{
99+
internals::Connection connection(getIoContext());
100+
101+
boost::json::object command;
102+
command["command"] = "invalid";
103+
EXPECT_THROW(runAwaitableVoid(connection.makeRequest(command)), exception::ConnectionClosed);
104+
}
105+
106+
TEST_F(ConnectionTest, waitResponse_exception)
107+
{
108+
internals::Connection connection(getIoContext());
109+
110+
boost::json::object result;
111+
EXPECT_THROW(result = runAwaitable(connection.waitResponse()), exception::ConnectionClosed);
112+
EXPECT_TRUE(result.empty());
113+
}

test/TestXStationClient.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "MockConnection.hpp"
2-
#include "xapi/Exceptions.hpp"
2+
#include "xapi/internals/Exceptions.hpp"
33
#include "xapi/XStationClient.hpp"
44
#include <gtest/gtest.h>
55
#include <iostream>

test/TestXStationClientStream.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "MockConnection.hpp"
2-
#include "xapi/Exceptions.hpp"
2+
#include "xapi/internals/Exceptions.hpp"
33
#include "xapi/XStationClientStream.hpp"
44
#include <gtest/gtest.h>
55
#include <string>

xapi/CMakeLists.txt

Lines changed: 74 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,74 @@
1-
# TARGET COMPILE OPTIONS ========================================
2-
set(COMMON_FLAGS
3-
-Wall
4-
-Werror
5-
-Wpedantic
6-
-Wextra
7-
-march=native
8-
)
9-
10-
if(CMAKE_BUILD_TYPE STREQUAL "Release")
11-
list(APPEND COMMON_FLAGS -O3)
12-
else()
13-
list(APPEND COMMON_FLAGS -O0 -g)
14-
endif()
15-
16-
# XAPI SETUP ================================================
17-
18-
set(XAPI_PUBLIC_H
19-
Enums.hpp
20-
XStationClient.hpp
21-
XStationClientStream.hpp
22-
Xapi.hpp
23-
)
24-
25-
set(XAPI_SOURCES
26-
${XAPI_PUBLIC_H}
27-
XStationClient.cpp
28-
XStationClientStream.cpp
29-
)
30-
31-
add_subdirectory(internals)
32-
33-
add_library(Xapi SHARED ${XAPI_SOURCES})
34-
target_compile_options(Xapi PRIVATE ${COMMON_FLAGS})
35-
target_link_libraries(Xapi PRIVATE XapiConnection)
36-
37-
# LIBRARY SETUP OPTIONS ========================================
38-
include(GNUInstallDirs)
39-
40-
target_include_directories(Xapi
41-
PUBLIC
42-
"$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>"
43-
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
44-
)
45-
46-
install(TARGETS Xapi
47-
EXPORT XapiTargets
48-
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
49-
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
50-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
51-
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
52-
)
53-
54-
install(FILES ${XAPI_PUBLIC_H} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/xapi)
55-
56-
install(EXPORT XapiTargets
57-
FILE XapiTargets.cmake
58-
NAMESPACE Xapi::
59-
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Xapi
60-
)
61-
62-
# FIND PACKAGE ORCHESTRATION ====================================
63-
include(CMakePackageConfigHelpers)
64-
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
65-
"${CMAKE_CURRENT_BINARY_DIR}/XapiConfig.cmake"
66-
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Xapi
67-
)
68-
69-
install(FILES
70-
"${CMAKE_CURRENT_BINARY_DIR}/XapiConfig.cmake"
71-
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Xapi
72-
)
73-
1+
# TARGET COMPILE OPTIONS ========================================
2+
set(COMMON_FLAGS
3+
-Wall
4+
-Werror
5+
-Wpedantic
6+
-Wextra
7+
-march=native
8+
)
9+
10+
if(CMAKE_BUILD_TYPE STREQUAL "Release")
11+
list(APPEND COMMON_FLAGS -O3)
12+
else()
13+
list(APPEND COMMON_FLAGS -O0 -g)
14+
endif()
15+
16+
# XAPI SETUP ================================================
17+
18+
set(XAPI_PUBLIC_H
19+
Enums.hpp
20+
XStationClient.hpp
21+
XStationClientStream.hpp
22+
Xapi.hpp
23+
)
24+
25+
set(XAPI_SOURCES
26+
${XAPI_PUBLIC_H}
27+
XStationClient.cpp
28+
XStationClientStream.cpp
29+
)
30+
31+
add_subdirectory(internals)
32+
33+
add_library(Xapi SHARED ${XAPI_SOURCES})
34+
target_compile_options(Xapi PRIVATE ${COMMON_FLAGS})
35+
target_link_libraries(Xapi PRIVATE XapiConnection)
36+
target_include_directories(Xapi PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/internals)
37+
38+
# LIBRARY SETUP OPTIONS ========================================
39+
include(GNUInstallDirs)
40+
41+
target_include_directories(Xapi
42+
PUBLIC
43+
"$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>"
44+
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
45+
)
46+
47+
install(TARGETS Xapi
48+
EXPORT XapiTargets
49+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
50+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
51+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
52+
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
53+
)
54+
55+
install(FILES ${XAPI_PUBLIC_H} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/xapi)
56+
57+
install(EXPORT XapiTargets
58+
FILE XapiTargets.cmake
59+
NAMESPACE Xapi::
60+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Xapi
61+
)
62+
63+
# FIND PACKAGE ORCHESTRATION ====================================
64+
include(CMakePackageConfigHelpers)
65+
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
66+
"${CMAKE_CURRENT_BINARY_DIR}/XapiConfig.cmake"
67+
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Xapi
68+
)
69+
70+
install(FILES
71+
"${CMAKE_CURRENT_BINARY_DIR}/XapiConfig.cmake"
72+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Xapi
73+
)
74+

xapi/Enums.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,4 @@ enum class PeriodCode
7070
};
7171

7272
} // namespace xapi
73+

0 commit comments

Comments
 (0)