diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 06f0a1b..3d7ae88 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,7 @@ jobs: env: PRESET_NAME: ${{ matrix.os == 'ubuntu-latest' && format('linux-{0}', matrix.build_type) || matrix.os == 'windows-latest' && format('windows-{0}', matrix.build_type) || format('macos-{0}', matrix.build_type) }} - VCPKG_TRIPLET: ${{ matrix.os == 'ubuntu-latest' && 'x64-linux' || matrix.os == 'windows-latest' && 'x64-windows' || 'arm64-osx' }} + VCPKG_TRIPLET: ${{ matrix.os == 'ubuntu-latest' && 'x64-linux' || matrix.os == 'windows-latest' && 'x64-windows' || 'x64-osx' }} steps: - name: Checkout repository @@ -78,6 +78,19 @@ jobs: - name: Build project run: cmake --build --preset=${{ env.PRESET_NAME }} + - name: Verify build output + if: success() + shell: bash + run: | + echo "Checking build output directory structure..." + if [ -d "bin/build/${{ env.PRESET_NAME }}" ]; then + echo "✅ Build directory exists" + find bin/build/${{ env.PRESET_NAME }} -type f -name "*.dll" -o -name "*.so" -o -name "*.dylib" -o -name "*.exe" -o -name "*.a" | head -20 || true + else + echo "⚠️ Build directory not found at expected location" + ls -la bin/ || echo "bin/ directory not found" + fi + - name: Test library linkage (Unix) if: runner.os != 'Windows' run: | @@ -93,12 +106,15 @@ jobs: - name: Upload build artifacts uses: actions/upload-artifact@v4 + if: success() || failure() with: name: binancecpp-${{ matrix.os }}-${{ matrix.build_type }} path: | - build/${{ env.PRESET_NAME }}/src/ - build/${{ env.PRESET_NAME }}/example/ + bin/build/${{ env.PRESET_NAME }}/src/ + bin/build/${{ env.PRESET_NAME }}/example/ + bin/build/${{ env.PRESET_NAME }}/tests/ retention-days: 5 + if-no-files-found: warn code-quality: name: Code Quality @@ -118,7 +134,7 @@ jobs: - name: Find C++ source files id: find-files run: | - find src example -name "*.cpp" -o -name "*.h" -o -name "*.hpp" -o -name "*.cc" -o -name "*.cxx" > cpp_files.txt + find src example \( -name "*.cpp" -o -name "*.h" -o -name "*.hpp" -o -name "*.cc" -o -name "*.cxx" \) > cpp_files.txt echo "file-count=$(wc -l < cpp_files.txt)" >> $GITHUB_OUTPUT - name: Check code formatting diff --git a/CMakeLists.txt b/CMakeLists.txt index 623b8d0..a6e4d69 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.20) +cmake_minimum_required(VERSION 3.21) project(binancecpp VERSION 1.0.0 @@ -9,6 +9,11 @@ project(binancecpp set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) +# Windows-specific: Use MultiThreadedDLL runtime library for MSVC +if(MSVC) + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") +endif() + # Configure RPATH set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) if(APPLE) @@ -20,11 +25,13 @@ endif() # Options option(BINANCECPP_BUILD_EXAMPLES "Build examples" ON) +option(BINANCECPP_BUILD_TESTS "Build tests" ON) option(BINANCECPP_DEPLOY_MODE "Enable deployment mode, disables examples" OFF) -# Deployment mode overrides examples setting +# Deployment mode overrides examples and tests settings if(BINANCECPP_DEPLOY_MODE) set(BINANCECPP_BUILD_EXAMPLES OFF CACHE BOOL "Deploy mode disables examples" FORCE) + set(BINANCECPP_BUILD_TESTS OFF CACHE BOOL "Deploy mode disables tests" FORCE) endif() @@ -44,6 +51,11 @@ if(BINANCECPP_BUILD_EXAMPLES) add_subdirectory(example) endif() +# Conditionally build tests +if(BINANCECPP_BUILD_TESTS) + add_subdirectory(tests) +endif() + # Installation include(GNUInstallDirs) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 3c3d67e..dfa389d 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -42,6 +42,24 @@ foreach(EXAMPLE_NAME ${EXAMPLES}) $<$:-fconcepts-ts> ) + # On Windows, copy the DLL and its dependencies to the example executable directory + if(WIN32) + add_custom_command(TARGET ${EXAMPLE_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + $ + $ + COMMENT "Copying binancecpp.dll to example directory" + ) + # Copy runtime DLLs for dependencies (JsonCpp, CURL, websockets) + add_custom_command(TARGET ${EXAMPLE_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + $ + $ + COMMAND_EXPAND_LISTS + COMMENT "Copying dependency DLLs to example directory" + ) + endif() + # Install example binaries install(TARGETS ${EXAMPLE_NAME} RUNTIME DESTINATION bin/examples diff --git a/src/core/binance_api.cpp b/src/core/binance_api.cpp index 5178978..4aef631 100644 --- a/src/core/binance_api.cpp +++ b/src/core/binance_api.cpp @@ -46,6 +46,26 @@ void BinanceAPI::Cleanup() noexcept curl_global_cleanup(); } +void BinanceAPI::SetAPIKey(std::string_view api_key) +{ + api_key_ = std::string(api_key); +} + +void BinanceAPI::SetSecretKey(std::string_view secret_key) +{ + secret_key_ = std::string(secret_key); +} + +const std::string& BinanceAPI::GetAPIKey() noexcept +{ + return api_key_; +} + +const std::string& BinanceAPI::GetSecretKey() noexcept +{ + return secret_key_; +} + size_t BinanceAPI::CurlCallback(void* content, size_t size, size_t nmemb, diff --git a/test_api_structure b/test_api_structure deleted file mode 100755 index acfd9c2..0000000 Binary files a/test_api_structure and /dev/null differ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..1622c5e --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,89 @@ +# CMakeLists.txt for tests directory +cmake_minimum_required(VERSION 3.21) + +# Find required packages for tests +find_package(jsoncpp CONFIG REQUIRED) +find_package(CURL REQUIRED) +find_package(libwebsockets CONFIG REQUIRED) + +# Add src/ as include directory for tests +include_directories(../src) + +# Get all test source files recursively +file(GLOB_RECURSE TEST_SOURCES "test_*.cpp") + +# Create executable for each test file +foreach(TEST_SOURCE ${TEST_SOURCES}) + # Get the filename without extension + get_filename_component(TEST_NAME ${TEST_SOURCE} NAME_WE) + + # Get relative path for unique naming in case of conflicts + file(RELATIVE_PATH REL_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${TEST_SOURCE}) + get_filename_component(REL_DIR ${REL_PATH} DIRECTORY) + + # Create unique test name by including directory path + if(REL_DIR) + string(REPLACE "/" "_" DIR_PREFIX ${REL_DIR}) + string(REPLACE "\\" "_" DIR_PREFIX ${DIR_PREFIX}) + set(UNIQUE_TEST_NAME ${DIR_PREFIX}_${TEST_NAME}) + else() + set(UNIQUE_TEST_NAME ${TEST_NAME}) + endif() + + # Create executable + add_executable(${UNIQUE_TEST_NAME} ${TEST_SOURCE}) + + # Link against the main library and dependencies + target_link_libraries(${UNIQUE_TEST_NAME} + binancecpp + JsonCpp::JsonCpp + CURL::libcurl + $,websockets,websockets_shared> + ) + + # Set C++ standard + set_property(TARGET ${UNIQUE_TEST_NAME} PROPERTY CXX_STANDARD 20) + set_property(TARGET ${UNIQUE_TEST_NAME} PROPERTY CXX_STANDARD_REQUIRED ON) + + # On Windows, copy the DLL and its dependencies to the test executable directory + if(WIN32) + add_custom_command(TARGET ${UNIQUE_TEST_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + $ + $ + COMMENT "Copying binancecpp.dll to test directory" + ) + # Copy runtime DLLs for dependencies (JsonCpp, CURL, websockets) + add_custom_command(TARGET ${UNIQUE_TEST_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + $ + $ + COMMAND_EXPAND_LISTS + COMMENT "Copying dependency DLLs to test directory" + ) + endif() + + # Add to test suite (optional) + # add_test(NAME ${UNIQUE_TEST_NAME} COMMAND ${UNIQUE_TEST_NAME}) +endforeach() + +# Create a convenience target to build all tests +add_custom_target(build_all_tests) +foreach(TEST_SOURCE ${TEST_SOURCES}) + get_filename_component(TEST_NAME ${TEST_SOURCE} NAME_WE) + file(RELATIVE_PATH REL_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${TEST_SOURCE}) + get_filename_component(REL_DIR ${REL_PATH} DIRECTORY) + + if(REL_DIR) + string(REPLACE "/" "_" DIR_PREFIX ${REL_DIR}) + string(REPLACE "\\" "_" DIR_PREFIX ${DIR_PREFIX}) + set(UNIQUE_TEST_NAME ${DIR_PREFIX}_${TEST_NAME}) + else() + set(UNIQUE_TEST_NAME ${TEST_NAME}) + endif() + + add_dependencies(build_all_tests ${UNIQUE_TEST_NAME}) +endforeach() + +message(STATUS "Found ${CMAKE_CURRENT_SOURCE_DIR} test files") +message(STATUS "Test executables will be built for each test_*.cpp file") \ No newline at end of file diff --git a/tests/core/test_binance_api.cpp b/tests/core/test_binance_api.cpp new file mode 100644 index 0000000..dbea7d2 --- /dev/null +++ b/tests/core/test_binance_api.cpp @@ -0,0 +1,143 @@ +/* + Unit test for binance_api.cpp (core) + Tests the BinanceAPI core functionality +*/ + +#include +#include + +#include "binance_api.h" + +int main() +{ + std::cout << "=== Testing BinanceAPI Core ===" << std::endl; + + // Test 1: Basic initialization + std::cout << "\n1. Testing Init..." << std::endl; + try + { + binance_cpp::core::BinanceAPI::Init(); + std::cout << "✅ Init() successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ Init() failed: " << e.what() << std::endl; + return 1; + } + + // Test 2: Initialization with API keys + std::cout << "\n2. Testing Init with API keys..." << std::endl; + try + { + binance_cpp::core::BinanceAPI::Init("test_api_key", "test_secret_key"); + std::cout << "✅ Init(api_key, secret_key) successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ Init(api_key, secret_key) failed: " << e.what() << std::endl; + return 1; + } + + // Test 3: API key management + std::cout << "\n3. Testing API key management..." << std::endl; + try + { + binance_cpp::core::BinanceAPI::SetAPIKey("new_test_api_key"); + const std::string& api_key = binance_cpp::core::BinanceAPI::GetAPIKey(); + + if (api_key == "new_test_api_key") + { + std::cout << "✅ SetAPIKey/GetAPIKey successful" << std::endl; + } + else + { + std::cout << "❌ SetAPIKey/GetAPIKey failed: " << api_key << std::endl; + return 1; + } + } + catch (const std::exception& e) + { + std::cout << "❌ API key management failed: " << e.what() << std::endl; + return 1; + } + + // Test 4: Secret key management + std::cout << "\n4. Testing Secret key management..." << std::endl; + try + { + binance_cpp::core::BinanceAPI::SetSecretKey("new_test_secret_key"); + const std::string& secret_key = binance_cpp::core::BinanceAPI::GetSecretKey(); + + if (secret_key == "new_test_secret_key") + { + std::cout << "✅ SetSecretKey/GetSecretKey successful" << std::endl; + } + else + { + std::cout << "❌ SetSecretKey/GetSecretKey failed: " << secret_key << std::endl; + return 1; + } + } + catch (const std::exception& e) + { + std::cout << "❌ Secret key management failed: " << e.what() << std::endl; + return 1; + } + + // Test 5: CurlCallback function + std::cout << "\n5. Testing CurlCallback..." << std::endl; + try + { + std::string buffer; + const char* test_data = "test response data"; + size_t result = binance_cpp::core::BinanceAPI::CurlCallback( + const_cast(test_data), 1, strlen(test_data), &buffer); + + if (result == strlen(test_data) && buffer == test_data) + { + std::cout << "✅ CurlCallback successful" << std::endl; + } + else + { + std::cout << "❌ CurlCallback failed: " << buffer << std::endl; + return 1; + } + } + catch (const std::exception& e) + { + std::cout << "❌ CurlCallback failed: " << e.what() << std::endl; + return 1; + } + + // Test 6: Cleanup + std::cout << "\n6. Testing Cleanup..." << std::endl; + try + { + binance_cpp::core::BinanceAPI::Cleanup(); + std::cout << "✅ Cleanup() successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ Cleanup() failed: " << e.what() << std::endl; + return 1; + } + + // Test 7: Re-initialization after cleanup + std::cout << "\n7. Testing re-initialization after cleanup..." << std::endl; + try + { + binance_cpp::core::BinanceAPI::Init("test_api", "test_secret"); + std::cout << "✅ Re-initialization successful" << std::endl; + + // Final cleanup + binance_cpp::core::BinanceAPI::Cleanup(); + } + catch (const std::exception& e) + { + std::cout << "❌ Re-initialization failed: " << e.what() << std::endl; + return 1; + } + + std::cout << "\n=== BinanceAPI Core Tests Complete ===" << std::endl; + return 0; +} \ No newline at end of file diff --git a/tests/financial_trading/spot_trading/account_endpoints/test_get_account_information.cpp b/tests/financial_trading/spot_trading/account_endpoints/test_get_account_information.cpp new file mode 100644 index 0000000..994a4b6 --- /dev/null +++ b/tests/financial_trading/spot_trading/account_endpoints/test_get_account_information.cpp @@ -0,0 +1,55 @@ +/* + Unit test for get_account_information.cpp + Auto-generated basic test template +*/ + +#include +#include + +#include "binance_api.h" + +int main() +{ + std::cout << "=== Testing get_account_information ===" << std::endl; + + // Test 1: Basic API initialization (if needed) + std::cout << "\n1. Testing API initialization..." << std::endl; + try + { + binance_cpp::core::BinanceAPI::Init(); + std::cout << "✅ API initialization successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ API initialization failed: " << e.what() << std::endl; + return 1; + } + + // Test 2: Basic functionality test + std::cout << "\n2. Testing basic functionality..." << std::endl; + try + { + // TODO: Add specific tests for get_account_information functions + // This is a placeholder test that verifies the file can be included + std::cout << "✅ Basic functionality test placeholder successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ Basic functionality test failed: " << e.what() << std::endl; + } + + // Cleanup + try + { + binance_cpp::core::BinanceAPI::Cleanup(); + std::cout << "\n✅ API cleanup successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "\n❌ API cleanup failed: " << e.what() << std::endl; + } + + std::cout << "\n=== get_account_information Tests Complete ===" << std::endl; + std::cout << "Note: This is a basic test template. Specific function tests should be added." << std::endl; + return 0; +} diff --git a/tests/financial_trading/spot_trading/account_endpoints/test_get_account_trade_list.cpp b/tests/financial_trading/spot_trading/account_endpoints/test_get_account_trade_list.cpp new file mode 100644 index 0000000..939133b --- /dev/null +++ b/tests/financial_trading/spot_trading/account_endpoints/test_get_account_trade_list.cpp @@ -0,0 +1,55 @@ +/* + Unit test for get_account_trade_list.cpp + Auto-generated basic test template +*/ + +#include +#include + +#include "binance_api.h" + +int main() +{ + std::cout << "=== Testing get_account_trade_list ===" << std::endl; + + // Test 1: Basic API initialization (if needed) + std::cout << "\n1. Testing API initialization..." << std::endl; + try + { + binance_cpp::core::BinanceAPI::Init(); + std::cout << "✅ API initialization successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ API initialization failed: " << e.what() << std::endl; + return 1; + } + + // Test 2: Basic functionality test + std::cout << "\n2. Testing basic functionality..." << std::endl; + try + { + // TODO: Add specific tests for get_account_trade_list functions + // This is a placeholder test that verifies the file can be included + std::cout << "✅ Basic functionality test placeholder successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ Basic functionality test failed: " << e.what() << std::endl; + } + + // Cleanup + try + { + binance_cpp::core::BinanceAPI::Cleanup(); + std::cout << "\n✅ API cleanup successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "\n❌ API cleanup failed: " << e.what() << std::endl; + } + + std::cout << "\n=== get_account_trade_list Tests Complete ===" << std::endl; + std::cout << "Note: This is a basic test template. Specific function tests should be added." << std::endl; + return 0; +} diff --git a/tests/financial_trading/spot_trading/general_endpoints/test_get_exchange_info.cpp b/tests/financial_trading/spot_trading/general_endpoints/test_get_exchange_info.cpp new file mode 100644 index 0000000..382a131 --- /dev/null +++ b/tests/financial_trading/spot_trading/general_endpoints/test_get_exchange_info.cpp @@ -0,0 +1,55 @@ +/* + Unit test for get_exchange_info.cpp + Auto-generated basic test template +*/ + +#include +#include + +#include "binance_api.h" + +int main() +{ + std::cout << "=== Testing get_exchange_info ===" << std::endl; + + // Test 1: Basic API initialization (if needed) + std::cout << "\n1. Testing API initialization..." << std::endl; + try + { + binance_cpp::core::BinanceAPI::Init(); + std::cout << "✅ API initialization successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ API initialization failed: " << e.what() << std::endl; + return 1; + } + + // Test 2: Basic functionality test + std::cout << "\n2. Testing basic functionality..." << std::endl; + try + { + // TODO: Add specific tests for get_exchange_info functions + // This is a placeholder test that verifies the file can be included + std::cout << "✅ Basic functionality test placeholder successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ Basic functionality test failed: " << e.what() << std::endl; + } + + // Cleanup + try + { + binance_cpp::core::BinanceAPI::Cleanup(); + std::cout << "\n✅ API cleanup successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "\n❌ API cleanup failed: " << e.what() << std::endl; + } + + std::cout << "\n=== get_exchange_info Tests Complete ===" << std::endl; + std::cout << "Note: This is a basic test template. Specific function tests should be added." << std::endl; + return 0; +} diff --git a/tests/financial_trading/spot_trading/general_endpoints/test_get_system_status.cpp b/tests/financial_trading/spot_trading/general_endpoints/test_get_system_status.cpp new file mode 100644 index 0000000..151552b --- /dev/null +++ b/tests/financial_trading/spot_trading/general_endpoints/test_get_system_status.cpp @@ -0,0 +1,55 @@ +/* + Unit test for get_system_status.cpp + Auto-generated basic test template +*/ + +#include +#include + +#include "binance_api.h" + +int main() +{ + std::cout << "=== Testing get_system_status ===" << std::endl; + + // Test 1: Basic API initialization (if needed) + std::cout << "\n1. Testing API initialization..." << std::endl; + try + { + binance_cpp::core::BinanceAPI::Init(); + std::cout << "✅ API initialization successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ API initialization failed: " << e.what() << std::endl; + return 1; + } + + // Test 2: Basic functionality test + std::cout << "\n2. Testing basic functionality..." << std::endl; + try + { + // TODO: Add specific tests for get_system_status functions + // This is a placeholder test that verifies the file can be included + std::cout << "✅ Basic functionality test placeholder successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ Basic functionality test failed: " << e.what() << std::endl; + } + + // Cleanup + try + { + binance_cpp::core::BinanceAPI::Cleanup(); + std::cout << "\n✅ API cleanup successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "\n❌ API cleanup failed: " << e.what() << std::endl; + } + + std::cout << "\n=== get_system_status Tests Complete ===" << std::endl; + std::cout << "Note: This is a basic test template. Specific function tests should be added." << std::endl; + return 0; +} diff --git a/tests/financial_trading/spot_trading/general_endpoints/test_server_time.cpp b/tests/financial_trading/spot_trading/general_endpoints/test_server_time.cpp new file mode 100644 index 0000000..db10211 --- /dev/null +++ b/tests/financial_trading/spot_trading/general_endpoints/test_server_time.cpp @@ -0,0 +1,102 @@ +/* + Unit test for server_time.cpp + Tests the ServerTime endpoint functionality +*/ + +#include +#include + +#include "binance_api.h" + +int main() +{ + std::cout << "=== Testing ServerTime Endpoint ===" << std::endl; + + // Initialize the API first + try + { + binance_cpp::core::BinanceAPI::Init(); + std::cout << "✅ API initialization successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ API initialization failed: " << e.what() << std::endl; + return 1; + } + + // Test 1: GetServerTime function exists and can be called + std::cout << "\n1. Testing GetServerTime..." << std::endl; + try + { + Json::Value result; + binance_cpp::financial_trading::spot_trading::general_endpoints:: + ServerTime::GetServerTime(result); + + // For unit testing, we mainly check that the function doesn't crash + // and returns a JSON object (actual network response testing would be integration tests) + std::cout << "✅ GetServerTime call successful (returned Json::Value)" << std::endl; + + // If we got a response with server time, validate it's reasonable + if (!result.empty() && result.isMember("serverTime")) + { + uint64_t serverTime = result["serverTime"].asUInt64(); + // Basic sanity check - should be a recent timestamp (after 2020) + if (serverTime > 1577836800000ULL) // Jan 1, 2020 in milliseconds + { + std::cout << "✅ GetServerTime returned valid timestamp: " << serverTime << std::endl; + } + else + { + std::cout << "⚠️ GetServerTime returned suspicious timestamp: " << serverTime << std::endl; + } + } + else + { + std::cout << "⚠️ GetServerTime returned empty or invalid response (may be expected in test environment)" << std::endl; + } + } + catch (const std::exception& e) + { + std::cout << "❌ GetServerTime failed: " << e.what() << std::endl; + // Don't return 1 here as network failures are expected in some test environments + } + + // Test 2: Verify Json::Value object properties + std::cout << "\n2. Testing Json::Value result object..." << std::endl; + try + { + Json::Value result; + // Call the function again + binance_cpp::financial_trading::spot_trading::general_endpoints:: + ServerTime::GetServerTime(result); + + // Test that result is a valid JSON object + if (result.isObject() || result.isNull()) + { + std::cout << "✅ Result is valid JSON object" << std::endl; + } + else + { + std::cout << "❌ Result is not a valid JSON object" << std::endl; + } + } + catch (const std::exception& e) + { + std::cout << "❌ Json::Value test failed: " << e.what() << std::endl; + } + + // Cleanup + try + { + binance_cpp::core::BinanceAPI::Cleanup(); + std::cout << "\n✅ API cleanup successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "\n❌ API cleanup failed: " << e.what() << std::endl; + } + + std::cout << "\n=== ServerTime Endpoint Tests Complete ===" << std::endl; + std::cout << "Note: Network connectivity dependent tests may show warnings in offline environments" << std::endl; + return 0; +} \ No newline at end of file diff --git a/tests/financial_trading/spot_trading/general_endpoints/test_test_connectivity.cpp b/tests/financial_trading/spot_trading/general_endpoints/test_test_connectivity.cpp new file mode 100644 index 0000000..643d636 --- /dev/null +++ b/tests/financial_trading/spot_trading/general_endpoints/test_test_connectivity.cpp @@ -0,0 +1,127 @@ +/* + Unit test for test_connectivity.cpp + Tests the TestConnectivity endpoint functionality +*/ + +#include +#include + +#include "binance_api.h" + +int main() +{ + std::cout << "=== Testing TestConnectivity Endpoint ===" << std::endl; + + // Initialize the API first + try + { + binance_cpp::core::BinanceAPI::Init(); + std::cout << "✅ API initialization successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ API initialization failed: " << e.what() << std::endl; + return 1; + } + + // Test 1: Ping function exists and can be called + std::cout << "\n1. Testing Ping..." << std::endl; + try + { + Json::Value result; + binance_cpp::financial_trading::spot_trading::general_endpoints:: + TestConnectivity::Ping(result); + + // For unit testing, we mainly check that the function doesn't crash + std::cout << "✅ Ping call successful" << std::endl; + + // If we got a successful ping response, it should be an empty JSON object + if (result.isObject()) + { + std::cout << "✅ Ping returned valid JSON object" << std::endl; + + // Successful ping typically returns an empty object {} + if (result.empty()) + { + std::cout << "✅ Ping returned expected empty response" << std::endl; + } + else + { + std::cout << "⚠️ Ping returned non-empty response (may contain error info)" << std::endl; + } + } + else + { + std::cout << "⚠️ Ping returned non-object response (may be expected in test environment)" << std::endl; + } + } + catch (const std::exception& e) + { + std::cout << "❌ Ping failed: " << e.what() << std::endl; + // Don't return 1 here as network failures are expected in some test environments + } + + // Test 2: Multiple ping calls + std::cout << "\n2. Testing multiple Ping calls..." << std::endl; + try + { + Json::Value result1, result2; + + binance_cpp::financial_trading::spot_trading::general_endpoints:: + TestConnectivity::Ping(result1); + binance_cpp::financial_trading::spot_trading::general_endpoints:: + TestConnectivity::Ping(result2); + + // Both calls should succeed and return similar structure + if (result1.type() == result2.type()) + { + std::cout << "✅ Multiple ping calls returned consistent types" << std::endl; + } + else + { + std::cout << "⚠️ Multiple ping calls returned inconsistent types" << std::endl; + } + } + catch (const std::exception& e) + { + std::cout << "❌ Multiple ping test failed: " << e.what() << std::endl; + } + + // Test 3: Verify Json::Value object properties + std::cout << "\n3. Testing Json::Value result object..." << std::endl; + try + { + Json::Value result; + binance_cpp::financial_trading::spot_trading::general_endpoints:: + TestConnectivity::Ping(result); + + // Test that result is a valid JSON object or null + if (result.isObject() || result.isNull()) + { + std::cout << "✅ Result is valid JSON type" << std::endl; + } + else + { + std::cout << "❌ Result is not a valid JSON type" << std::endl; + } + } + catch (const std::exception& e) + { + std::cout << "❌ Json::Value test failed: " << e.what() << std::endl; + } + + // Cleanup + try + { + binance_cpp::core::BinanceAPI::Cleanup(); + std::cout << "\n✅ API cleanup successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "\n❌ API cleanup failed: " << e.what() << std::endl; + } + + std::cout << "\n=== TestConnectivity Endpoint Tests Complete ===" << std::endl; + std::cout << "Note: Network connectivity dependent tests may show warnings in offline environments" << std::endl; + return 0; +} \ No newline at end of file diff --git a/tests/financial_trading/spot_trading/market_data_endpoints/test_get_24hr_ticker_price_change_statistics_all.cpp b/tests/financial_trading/spot_trading/market_data_endpoints/test_get_24hr_ticker_price_change_statistics_all.cpp new file mode 100644 index 0000000..875a094 --- /dev/null +++ b/tests/financial_trading/spot_trading/market_data_endpoints/test_get_24hr_ticker_price_change_statistics_all.cpp @@ -0,0 +1,55 @@ +/* + Unit test for get_24hr_ticker_price_change_statistics_all.cpp + Auto-generated basic test template +*/ + +#include +#include + +#include "binance_api.h" + +int main() +{ + std::cout << "=== Testing get_24hr_ticker_price_change_statistics_all ===" << std::endl; + + // Test 1: Basic API initialization (if needed) + std::cout << "\n1. Testing API initialization..." << std::endl; + try + { + binance_cpp::core::BinanceAPI::Init(); + std::cout << "✅ API initialization successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ API initialization failed: " << e.what() << std::endl; + return 1; + } + + // Test 2: Basic functionality test + std::cout << "\n2. Testing basic functionality..." << std::endl; + try + { + // TODO: Add specific tests for get_24hr_ticker_price_change_statistics_all functions + // This is a placeholder test that verifies the file can be included + std::cout << "✅ Basic functionality test placeholder successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ Basic functionality test failed: " << e.what() << std::endl; + } + + // Cleanup + try + { + binance_cpp::core::BinanceAPI::Cleanup(); + std::cout << "\n✅ API cleanup successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "\n❌ API cleanup failed: " << e.what() << std::endl; + } + + std::cout << "\n=== get_24hr_ticker_price_change_statistics_all Tests Complete ===" << std::endl; + std::cout << "Note: This is a basic test template. Specific function tests should be added." << std::endl; + return 0; +} diff --git a/tests/financial_trading/spot_trading/market_data_endpoints/test_get_24hr_ticker_price_change_statistics_with_symbol.cpp b/tests/financial_trading/spot_trading/market_data_endpoints/test_get_24hr_ticker_price_change_statistics_with_symbol.cpp new file mode 100644 index 0000000..d3ba924 --- /dev/null +++ b/tests/financial_trading/spot_trading/market_data_endpoints/test_get_24hr_ticker_price_change_statistics_with_symbol.cpp @@ -0,0 +1,55 @@ +/* + Unit test for get_24hr_ticker_price_change_statistics_with_symbol.cpp + Auto-generated basic test template +*/ + +#include +#include + +#include "binance_api.h" + +int main() +{ + std::cout << "=== Testing get_24hr_ticker_price_change_statistics_with_symbol ===" << std::endl; + + // Test 1: Basic API initialization (if needed) + std::cout << "\n1. Testing API initialization..." << std::endl; + try + { + binance_cpp::core::BinanceAPI::Init(); + std::cout << "✅ API initialization successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ API initialization failed: " << e.what() << std::endl; + return 1; + } + + // Test 2: Basic functionality test + std::cout << "\n2. Testing basic functionality..." << std::endl; + try + { + // TODO: Add specific tests for get_24hr_ticker_price_change_statistics_with_symbol functions + // This is a placeholder test that verifies the file can be included + std::cout << "✅ Basic functionality test placeholder successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ Basic functionality test failed: " << e.what() << std::endl; + } + + // Cleanup + try + { + binance_cpp::core::BinanceAPI::Cleanup(); + std::cout << "\n✅ API cleanup successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "\n❌ API cleanup failed: " << e.what() << std::endl; + } + + std::cout << "\n=== get_24hr_ticker_price_change_statistics_with_symbol Tests Complete ===" << std::endl; + std::cout << "Note: This is a basic test template. Specific function tests should be added." << std::endl; + return 0; +} diff --git a/tests/financial_trading/spot_trading/market_data_endpoints/test_get_aggregate_trades_list.cpp b/tests/financial_trading/spot_trading/market_data_endpoints/test_get_aggregate_trades_list.cpp new file mode 100644 index 0000000..394daac --- /dev/null +++ b/tests/financial_trading/spot_trading/market_data_endpoints/test_get_aggregate_trades_list.cpp @@ -0,0 +1,55 @@ +/* + Unit test for get_aggregate_trades_list.cpp + Auto-generated basic test template +*/ + +#include +#include + +#include "binance_api.h" + +int main() +{ + std::cout << "=== Testing get_aggregate_trades_list ===" << std::endl; + + // Test 1: Basic API initialization (if needed) + std::cout << "\n1. Testing API initialization..." << std::endl; + try + { + binance_cpp::core::BinanceAPI::Init(); + std::cout << "✅ API initialization successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ API initialization failed: " << e.what() << std::endl; + return 1; + } + + // Test 2: Basic functionality test + std::cout << "\n2. Testing basic functionality..." << std::endl; + try + { + // TODO: Add specific tests for get_aggregate_trades_list functions + // This is a placeholder test that verifies the file can be included + std::cout << "✅ Basic functionality test placeholder successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ Basic functionality test failed: " << e.what() << std::endl; + } + + // Cleanup + try + { + binance_cpp::core::BinanceAPI::Cleanup(); + std::cout << "\n✅ API cleanup successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "\n❌ API cleanup failed: " << e.what() << std::endl; + } + + std::cout << "\n=== get_aggregate_trades_list Tests Complete ===" << std::endl; + std::cout << "Note: This is a basic test template. Specific function tests should be added." << std::endl; + return 0; +} diff --git a/tests/financial_trading/spot_trading/market_data_endpoints/test_get_klines_candlestick_data.cpp b/tests/financial_trading/spot_trading/market_data_endpoints/test_get_klines_candlestick_data.cpp new file mode 100644 index 0000000..4bb06b6 --- /dev/null +++ b/tests/financial_trading/spot_trading/market_data_endpoints/test_get_klines_candlestick_data.cpp @@ -0,0 +1,55 @@ +/* + Unit test for get_klines_candlestick_data.cpp + Auto-generated basic test template +*/ + +#include +#include + +#include "binance_api.h" + +int main() +{ + std::cout << "=== Testing get_klines_candlestick_data ===" << std::endl; + + // Test 1: Basic API initialization (if needed) + std::cout << "\n1. Testing API initialization..." << std::endl; + try + { + binance_cpp::core::BinanceAPI::Init(); + std::cout << "✅ API initialization successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ API initialization failed: " << e.what() << std::endl; + return 1; + } + + // Test 2: Basic functionality test + std::cout << "\n2. Testing basic functionality..." << std::endl; + try + { + // TODO: Add specific tests for get_klines_candlestick_data functions + // This is a placeholder test that verifies the file can be included + std::cout << "✅ Basic functionality test placeholder successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ Basic functionality test failed: " << e.what() << std::endl; + } + + // Cleanup + try + { + binance_cpp::core::BinanceAPI::Cleanup(); + std::cout << "\n✅ API cleanup successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "\n❌ API cleanup failed: " << e.what() << std::endl; + } + + std::cout << "\n=== get_klines_candlestick_data Tests Complete ===" << std::endl; + std::cout << "Note: This is a basic test template. Specific function tests should be added." << std::endl; + return 0; +} diff --git a/tests/financial_trading/spot_trading/market_data_endpoints/test_get_price.cpp b/tests/financial_trading/spot_trading/market_data_endpoints/test_get_price.cpp new file mode 100644 index 0000000..a726eb1 --- /dev/null +++ b/tests/financial_trading/spot_trading/market_data_endpoints/test_get_price.cpp @@ -0,0 +1,55 @@ +/* + Unit test for get_price.cpp + Auto-generated basic test template +*/ + +#include +#include + +#include "binance_api.h" + +int main() +{ + std::cout << "=== Testing get_price ===" << std::endl; + + // Test 1: Basic API initialization (if needed) + std::cout << "\n1. Testing API initialization..." << std::endl; + try + { + binance_cpp::core::BinanceAPI::Init(); + std::cout << "✅ API initialization successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ API initialization failed: " << e.what() << std::endl; + return 1; + } + + // Test 2: Basic functionality test + std::cout << "\n2. Testing basic functionality..." << std::endl; + try + { + // TODO: Add specific tests for get_price functions + // This is a placeholder test that verifies the file can be included + std::cout << "✅ Basic functionality test placeholder successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ Basic functionality test failed: " << e.what() << std::endl; + } + + // Cleanup + try + { + binance_cpp::core::BinanceAPI::Cleanup(); + std::cout << "\n✅ API cleanup successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "\n❌ API cleanup failed: " << e.what() << std::endl; + } + + std::cout << "\n=== get_price Tests Complete ===" << std::endl; + std::cout << "Note: This is a basic test template. Specific function tests should be added." << std::endl; + return 0; +} diff --git a/tests/financial_trading/spot_trading/market_data_endpoints/test_get_rolling_window_price_change_statistics_all.cpp b/tests/financial_trading/spot_trading/market_data_endpoints/test_get_rolling_window_price_change_statistics_all.cpp new file mode 100644 index 0000000..8a5287d --- /dev/null +++ b/tests/financial_trading/spot_trading/market_data_endpoints/test_get_rolling_window_price_change_statistics_all.cpp @@ -0,0 +1,55 @@ +/* + Unit test for get_rolling_window_price_change_statistics_all.cpp + Auto-generated basic test template +*/ + +#include +#include + +#include "binance_api.h" + +int main() +{ + std::cout << "=== Testing get_rolling_window_price_change_statistics_all ===" << std::endl; + + // Test 1: Basic API initialization (if needed) + std::cout << "\n1. Testing API initialization..." << std::endl; + try + { + binance_cpp::core::BinanceAPI::Init(); + std::cout << "✅ API initialization successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ API initialization failed: " << e.what() << std::endl; + return 1; + } + + // Test 2: Basic functionality test + std::cout << "\n2. Testing basic functionality..." << std::endl; + try + { + // TODO: Add specific tests for get_rolling_window_price_change_statistics_all functions + // This is a placeholder test that verifies the file can be included + std::cout << "✅ Basic functionality test placeholder successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ Basic functionality test failed: " << e.what() << std::endl; + } + + // Cleanup + try + { + binance_cpp::core::BinanceAPI::Cleanup(); + std::cout << "\n✅ API cleanup successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "\n❌ API cleanup failed: " << e.what() << std::endl; + } + + std::cout << "\n=== get_rolling_window_price_change_statistics_all Tests Complete ===" << std::endl; + std::cout << "Note: This is a basic test template. Specific function tests should be added." << std::endl; + return 0; +} diff --git a/tests/financial_trading/spot_trading/market_data_endpoints/test_get_rolling_window_price_change_statistics_with_symbol.cpp b/tests/financial_trading/spot_trading/market_data_endpoints/test_get_rolling_window_price_change_statistics_with_symbol.cpp new file mode 100644 index 0000000..2c103e1 --- /dev/null +++ b/tests/financial_trading/spot_trading/market_data_endpoints/test_get_rolling_window_price_change_statistics_with_symbol.cpp @@ -0,0 +1,55 @@ +/* + Unit test for get_rolling_window_price_change_statistics_with_symbol.cpp + Auto-generated basic test template +*/ + +#include +#include + +#include "binance_api.h" + +int main() +{ + std::cout << "=== Testing get_rolling_window_price_change_statistics_with_symbol ===" << std::endl; + + // Test 1: Basic API initialization (if needed) + std::cout << "\n1. Testing API initialization..." << std::endl; + try + { + binance_cpp::core::BinanceAPI::Init(); + std::cout << "✅ API initialization successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ API initialization failed: " << e.what() << std::endl; + return 1; + } + + // Test 2: Basic functionality test + std::cout << "\n2. Testing basic functionality..." << std::endl; + try + { + // TODO: Add specific tests for get_rolling_window_price_change_statistics_with_symbol functions + // This is a placeholder test that verifies the file can be included + std::cout << "✅ Basic functionality test placeholder successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ Basic functionality test failed: " << e.what() << std::endl; + } + + // Cleanup + try + { + binance_cpp::core::BinanceAPI::Cleanup(); + std::cout << "\n✅ API cleanup successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "\n❌ API cleanup failed: " << e.what() << std::endl; + } + + std::cout << "\n=== get_rolling_window_price_change_statistics_with_symbol Tests Complete ===" << std::endl; + std::cout << "Note: This is a basic test template. Specific function tests should be added." << std::endl; + return 0; +} diff --git a/tests/financial_trading/spot_trading/market_data_endpoints/test_get_symbol_order_book_ticker_all.cpp b/tests/financial_trading/spot_trading/market_data_endpoints/test_get_symbol_order_book_ticker_all.cpp new file mode 100644 index 0000000..7a76e15 --- /dev/null +++ b/tests/financial_trading/spot_trading/market_data_endpoints/test_get_symbol_order_book_ticker_all.cpp @@ -0,0 +1,55 @@ +/* + Unit test for get_symbol_order_book_ticker_all.cpp + Auto-generated basic test template +*/ + +#include +#include + +#include "binance_api.h" + +int main() +{ + std::cout << "=== Testing get_symbol_order_book_ticker_all ===" << std::endl; + + // Test 1: Basic API initialization (if needed) + std::cout << "\n1. Testing API initialization..." << std::endl; + try + { + binance_cpp::core::BinanceAPI::Init(); + std::cout << "✅ API initialization successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ API initialization failed: " << e.what() << std::endl; + return 1; + } + + // Test 2: Basic functionality test + std::cout << "\n2. Testing basic functionality..." << std::endl; + try + { + // TODO: Add specific tests for get_symbol_order_book_ticker_all functions + // This is a placeholder test that verifies the file can be included + std::cout << "✅ Basic functionality test placeholder successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ Basic functionality test failed: " << e.what() << std::endl; + } + + // Cleanup + try + { + binance_cpp::core::BinanceAPI::Cleanup(); + std::cout << "\n✅ API cleanup successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "\n❌ API cleanup failed: " << e.what() << std::endl; + } + + std::cout << "\n=== get_symbol_order_book_ticker_all Tests Complete ===" << std::endl; + std::cout << "Note: This is a basic test template. Specific function tests should be added." << std::endl; + return 0; +} diff --git a/tests/financial_trading/spot_trading/market_data_endpoints/test_get_symbol_order_book_ticker_with_symbol.cpp b/tests/financial_trading/spot_trading/market_data_endpoints/test_get_symbol_order_book_ticker_with_symbol.cpp new file mode 100644 index 0000000..9bbe2b4 --- /dev/null +++ b/tests/financial_trading/spot_trading/market_data_endpoints/test_get_symbol_order_book_ticker_with_symbol.cpp @@ -0,0 +1,55 @@ +/* + Unit test for get_symbol_order_book_ticker_with_symbol.cpp + Auto-generated basic test template +*/ + +#include +#include + +#include "binance_api.h" + +int main() +{ + std::cout << "=== Testing get_symbol_order_book_ticker_with_symbol ===" << std::endl; + + // Test 1: Basic API initialization (if needed) + std::cout << "\n1. Testing API initialization..." << std::endl; + try + { + binance_cpp::core::BinanceAPI::Init(); + std::cout << "✅ API initialization successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ API initialization failed: " << e.what() << std::endl; + return 1; + } + + // Test 2: Basic functionality test + std::cout << "\n2. Testing basic functionality..." << std::endl; + try + { + // TODO: Add specific tests for get_symbol_order_book_ticker_with_symbol functions + // This is a placeholder test that verifies the file can be included + std::cout << "✅ Basic functionality test placeholder successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ Basic functionality test failed: " << e.what() << std::endl; + } + + // Cleanup + try + { + binance_cpp::core::BinanceAPI::Cleanup(); + std::cout << "\n✅ API cleanup successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "\n❌ API cleanup failed: " << e.what() << std::endl; + } + + std::cout << "\n=== get_symbol_order_book_ticker_with_symbol Tests Complete ===" << std::endl; + std::cout << "Note: This is a basic test template. Specific function tests should be added." << std::endl; + return 0; +} diff --git a/tests/financial_trading/spot_trading/market_data_endpoints/test_get_symbol_price_ticker_all.cpp b/tests/financial_trading/spot_trading/market_data_endpoints/test_get_symbol_price_ticker_all.cpp new file mode 100644 index 0000000..cf03a8a --- /dev/null +++ b/tests/financial_trading/spot_trading/market_data_endpoints/test_get_symbol_price_ticker_all.cpp @@ -0,0 +1,55 @@ +/* + Unit test for get_symbol_price_ticker_all.cpp + Auto-generated basic test template +*/ + +#include +#include + +#include "binance_api.h" + +int main() +{ + std::cout << "=== Testing get_symbol_price_ticker_all ===" << std::endl; + + // Test 1: Basic API initialization (if needed) + std::cout << "\n1. Testing API initialization..." << std::endl; + try + { + binance_cpp::core::BinanceAPI::Init(); + std::cout << "✅ API initialization successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ API initialization failed: " << e.what() << std::endl; + return 1; + } + + // Test 2: Basic functionality test + std::cout << "\n2. Testing basic functionality..." << std::endl; + try + { + // TODO: Add specific tests for get_symbol_price_ticker_all functions + // This is a placeholder test that verifies the file can be included + std::cout << "✅ Basic functionality test placeholder successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ Basic functionality test failed: " << e.what() << std::endl; + } + + // Cleanup + try + { + binance_cpp::core::BinanceAPI::Cleanup(); + std::cout << "\n✅ API cleanup successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "\n❌ API cleanup failed: " << e.what() << std::endl; + } + + std::cout << "\n=== get_symbol_price_ticker_all Tests Complete ===" << std::endl; + std::cout << "Note: This is a basic test template. Specific function tests should be added." << std::endl; + return 0; +} diff --git a/tests/financial_trading/spot_trading/market_data_endpoints/test_get_symbol_price_ticker_with_symbol.cpp b/tests/financial_trading/spot_trading/market_data_endpoints/test_get_symbol_price_ticker_with_symbol.cpp new file mode 100644 index 0000000..8d607f3 --- /dev/null +++ b/tests/financial_trading/spot_trading/market_data_endpoints/test_get_symbol_price_ticker_with_symbol.cpp @@ -0,0 +1,55 @@ +/* + Unit test for get_symbol_price_ticker_with_symbol.cpp + Auto-generated basic test template +*/ + +#include +#include + +#include "binance_api.h" + +int main() +{ + std::cout << "=== Testing get_symbol_price_ticker_with_symbol ===" << std::endl; + + // Test 1: Basic API initialization (if needed) + std::cout << "\n1. Testing API initialization..." << std::endl; + try + { + binance_cpp::core::BinanceAPI::Init(); + std::cout << "✅ API initialization successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ API initialization failed: " << e.what() << std::endl; + return 1; + } + + // Test 2: Basic functionality test + std::cout << "\n2. Testing basic functionality..." << std::endl; + try + { + // TODO: Add specific tests for get_symbol_price_ticker_with_symbol functions + // This is a placeholder test that verifies the file can be included + std::cout << "✅ Basic functionality test placeholder successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ Basic functionality test failed: " << e.what() << std::endl; + } + + // Cleanup + try + { + binance_cpp::core::BinanceAPI::Cleanup(); + std::cout << "\n✅ API cleanup successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "\n❌ API cleanup failed: " << e.what() << std::endl; + } + + std::cout << "\n=== get_symbol_price_ticker_with_symbol Tests Complete ===" << std::endl; + std::cout << "Note: This is a basic test template. Specific function tests should be added." << std::endl; + return 0; +} diff --git a/tests/financial_trading/spot_trading/market_data_endpoints/test_order_book.cpp b/tests/financial_trading/spot_trading/market_data_endpoints/test_order_book.cpp new file mode 100644 index 0000000..480ef67 --- /dev/null +++ b/tests/financial_trading/spot_trading/market_data_endpoints/test_order_book.cpp @@ -0,0 +1,55 @@ +/* + Unit test for order_book.cpp + Auto-generated basic test template +*/ + +#include +#include + +#include "binance_api.h" + +int main() +{ + std::cout << "=== Testing order_book ===" << std::endl; + + // Test 1: Basic API initialization (if needed) + std::cout << "\n1. Testing API initialization..." << std::endl; + try + { + binance_cpp::core::BinanceAPI::Init(); + std::cout << "✅ API initialization successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ API initialization failed: " << e.what() << std::endl; + return 1; + } + + // Test 2: Basic functionality test + std::cout << "\n2. Testing basic functionality..." << std::endl; + try + { + // TODO: Add specific tests for order_book functions + // This is a placeholder test that verifies the file can be included + std::cout << "✅ Basic functionality test placeholder successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ Basic functionality test failed: " << e.what() << std::endl; + } + + // Cleanup + try + { + binance_cpp::core::BinanceAPI::Cleanup(); + std::cout << "\n✅ API cleanup successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "\n❌ API cleanup failed: " << e.what() << std::endl; + } + + std::cout << "\n=== order_book Tests Complete ===" << std::endl; + std::cout << "Note: This is a basic test template. Specific function tests should be added." << std::endl; + return 0; +} diff --git a/tests/financial_trading/spot_trading/user_data_stream_endpoints/test_close_listen_key.cpp b/tests/financial_trading/spot_trading/user_data_stream_endpoints/test_close_listen_key.cpp new file mode 100644 index 0000000..cf94fd2 --- /dev/null +++ b/tests/financial_trading/spot_trading/user_data_stream_endpoints/test_close_listen_key.cpp @@ -0,0 +1,55 @@ +/* + Unit test for close_listen_key.cpp + Auto-generated basic test template +*/ + +#include +#include + +#include "binance_api.h" + +int main() +{ + std::cout << "=== Testing close_listen_key ===" << std::endl; + + // Test 1: Basic API initialization (if needed) + std::cout << "\n1. Testing API initialization..." << std::endl; + try + { + binance_cpp::core::BinanceAPI::Init(); + std::cout << "✅ API initialization successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ API initialization failed: " << e.what() << std::endl; + return 1; + } + + // Test 2: Basic functionality test + std::cout << "\n2. Testing basic functionality..." << std::endl; + try + { + // TODO: Add specific tests for close_listen_key functions + // This is a placeholder test that verifies the file can be included + std::cout << "✅ Basic functionality test placeholder successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ Basic functionality test failed: " << e.what() << std::endl; + } + + // Cleanup + try + { + binance_cpp::core::BinanceAPI::Cleanup(); + std::cout << "\n✅ API cleanup successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "\n❌ API cleanup failed: " << e.what() << std::endl; + } + + std::cout << "\n=== close_listen_key Tests Complete ===" << std::endl; + std::cout << "Note: This is a basic test template. Specific function tests should be added." << std::endl; + return 0; +} diff --git a/tests/financial_trading/spot_trading/user_data_stream_endpoints/test_create_listen_key.cpp b/tests/financial_trading/spot_trading/user_data_stream_endpoints/test_create_listen_key.cpp new file mode 100644 index 0000000..de3ee82 --- /dev/null +++ b/tests/financial_trading/spot_trading/user_data_stream_endpoints/test_create_listen_key.cpp @@ -0,0 +1,55 @@ +/* + Unit test for create_listen_key.cpp + Auto-generated basic test template +*/ + +#include +#include + +#include "binance_api.h" + +int main() +{ + std::cout << "=== Testing create_listen_key ===" << std::endl; + + // Test 1: Basic API initialization (if needed) + std::cout << "\n1. Testing API initialization..." << std::endl; + try + { + binance_cpp::core::BinanceAPI::Init(); + std::cout << "✅ API initialization successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ API initialization failed: " << e.what() << std::endl; + return 1; + } + + // Test 2: Basic functionality test + std::cout << "\n2. Testing basic functionality..." << std::endl; + try + { + // TODO: Add specific tests for create_listen_key functions + // This is a placeholder test that verifies the file can be included + std::cout << "✅ Basic functionality test placeholder successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ Basic functionality test failed: " << e.what() << std::endl; + } + + // Cleanup + try + { + binance_cpp::core::BinanceAPI::Cleanup(); + std::cout << "\n✅ API cleanup successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "\n❌ API cleanup failed: " << e.what() << std::endl; + } + + std::cout << "\n=== create_listen_key Tests Complete ===" << std::endl; + std::cout << "Note: This is a basic test template. Specific function tests should be added." << std::endl; + return 0; +} diff --git a/tests/financial_trading/spot_trading/user_data_stream_endpoints/test_ping_extend_listen_key.cpp b/tests/financial_trading/spot_trading/user_data_stream_endpoints/test_ping_extend_listen_key.cpp new file mode 100644 index 0000000..2fb2696 --- /dev/null +++ b/tests/financial_trading/spot_trading/user_data_stream_endpoints/test_ping_extend_listen_key.cpp @@ -0,0 +1,55 @@ +/* + Unit test for ping_extend_listen_key.cpp + Auto-generated basic test template +*/ + +#include +#include + +#include "binance_api.h" + +int main() +{ + std::cout << "=== Testing ping_extend_listen_key ===" << std::endl; + + // Test 1: Basic API initialization (if needed) + std::cout << "\n1. Testing API initialization..." << std::endl; + try + { + binance_cpp::core::BinanceAPI::Init(); + std::cout << "✅ API initialization successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ API initialization failed: " << e.what() << std::endl; + return 1; + } + + // Test 2: Basic functionality test + std::cout << "\n2. Testing basic functionality..." << std::endl; + try + { + // TODO: Add specific tests for ping_extend_listen_key functions + // This is a placeholder test that verifies the file can be included + std::cout << "✅ Basic functionality test placeholder successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ Basic functionality test failed: " << e.what() << std::endl; + } + + // Cleanup + try + { + binance_cpp::core::BinanceAPI::Cleanup(); + std::cout << "\n✅ API cleanup successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "\n❌ API cleanup failed: " << e.what() << std::endl; + } + + std::cout << "\n=== ping_extend_listen_key Tests Complete ===" << std::endl; + std::cout << "Note: This is a basic test template. Specific function tests should be added." << std::endl; + return 0; +} diff --git a/tests/financial_trading/wallet/test_deposit_operations.cpp b/tests/financial_trading/wallet/test_deposit_operations.cpp new file mode 100644 index 0000000..3fee598 --- /dev/null +++ b/tests/financial_trading/wallet/test_deposit_operations.cpp @@ -0,0 +1,55 @@ +/* + Unit test for deposit_operations.cpp + Auto-generated basic test template +*/ + +#include +#include + +#include "binance_api.h" + +int main() +{ + std::cout << "=== Testing deposit_operations ===" << std::endl; + + // Test 1: Basic API initialization (if needed) + std::cout << "\n1. Testing API initialization..." << std::endl; + try + { + binance_cpp::core::BinanceAPI::Init(); + std::cout << "✅ API initialization successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ API initialization failed: " << e.what() << std::endl; + return 1; + } + + // Test 2: Basic functionality test + std::cout << "\n2. Testing basic functionality..." << std::endl; + try + { + // TODO: Add specific tests for deposit_operations functions + // This is a placeholder test that verifies the file can be included + std::cout << "✅ Basic functionality test placeholder successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ Basic functionality test failed: " << e.what() << std::endl; + } + + // Cleanup + try + { + binance_cpp::core::BinanceAPI::Cleanup(); + std::cout << "\n✅ API cleanup successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "\n❌ API cleanup failed: " << e.what() << std::endl; + } + + std::cout << "\n=== deposit_operations Tests Complete ===" << std::endl; + std::cout << "Note: This is a basic test template. Specific function tests should be added." << std::endl; + return 0; +} diff --git a/tests/financial_trading/wallet/test_withdraw_operations.cpp b/tests/financial_trading/wallet/test_withdraw_operations.cpp new file mode 100644 index 0000000..2ab9ff4 --- /dev/null +++ b/tests/financial_trading/wallet/test_withdraw_operations.cpp @@ -0,0 +1,55 @@ +/* + Unit test for withdraw_operations.cpp + Auto-generated basic test template +*/ + +#include +#include + +#include "binance_api.h" + +int main() +{ + std::cout << "=== Testing withdraw_operations ===" << std::endl; + + // Test 1: Basic API initialization (if needed) + std::cout << "\n1. Testing API initialization..." << std::endl; + try + { + binance_cpp::core::BinanceAPI::Init(); + std::cout << "✅ API initialization successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ API initialization failed: " << e.what() << std::endl; + return 1; + } + + // Test 2: Basic functionality test + std::cout << "\n2. Testing basic functionality..." << std::endl; + try + { + // TODO: Add specific tests for withdraw_operations functions + // This is a placeholder test that verifies the file can be included + std::cout << "✅ Basic functionality test placeholder successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ Basic functionality test failed: " << e.what() << std::endl; + } + + // Cleanup + try + { + binance_cpp::core::BinanceAPI::Cleanup(); + std::cout << "\n✅ API cleanup successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "\n❌ API cleanup failed: " << e.what() << std::endl; + } + + std::cout << "\n=== withdraw_operations Tests Complete ===" << std::endl; + std::cout << "Note: This is a basic test template. Specific function tests should be added." << std::endl; + return 0; +} diff --git a/test_api_structure.cpp b/tests/test_api_structure.cpp similarity index 100% rename from test_api_structure.cpp rename to tests/test_api_structure.cpp diff --git a/tests/test_binance_logger.cpp b/tests/test_binance_logger.cpp new file mode 100644 index 0000000..f1bd45e --- /dev/null +++ b/tests/test_binance_logger.cpp @@ -0,0 +1,110 @@ +/* + Unit test for binance_logger.cpp + Tests the BinanceCPP_logger class functionality +*/ + +#include +#include +#include +#include + +#include "binance_logger.h" + +int main() +{ + std::cout << "=== Testing BinanceCPP_logger ===" << std::endl; + + // Test 1: Set debug level + std::cout << "\n1. Testing set_debug_level..." << std::endl; + try + { + BinanceCPP_logger::set_debug_level(1); + std::cout << "✅ set_debug_level(1) successful" << std::endl; + + BinanceCPP_logger::set_debug_level(0); + std::cout << "✅ set_debug_level(0) successful" << std::endl; + + // Reset to enabled for other tests + BinanceCPP_logger::set_debug_level(1); + } + catch (const std::exception& e) + { + std::cout << "❌ set_debug_level failed: " << e.what() << std::endl; + return 1; + } + + // Test 2: Basic logging + std::cout << "\n2. Testing basic write_log..." << std::endl; + try + { + BinanceCPP_logger::write_log("Test log message %d", 123); + std::cout << "✅ write_log with formatted string successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ write_log failed: " << e.what() << std::endl; + return 1; + } + + // Test 3: Clean logging + std::cout << "\n3. Testing write_log_clean..." << std::endl; + try + { + BinanceCPP_logger::write_log_clean("Clean log message"); + std::cout << "✅ write_log_clean successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ write_log_clean failed: " << e.what() << std::endl; + return 1; + } + + // Test 4: Set debug log file + std::cout << "\n4. Testing set_debug_logfile..." << std::endl; + try + { + BinanceCPP_logger::set_debug_logfile("/tmp/test_binance.log"); + std::cout << "✅ set_debug_logfile successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ set_debug_logfile failed: " << e.what() << std::endl; + return 1; + } + + // Test 5: Enable/disable log file + std::cout << "\n5. Testing enable_logfile..." << std::endl; + try + { + BinanceCPP_logger::enable_logfile(1); + BinanceCPP_logger::write_log("Test file log"); + BinanceCPP_logger::enable_logfile(0); + std::cout << "✅ enable_logfile toggle successful" << std::endl; + + // Clean up test log file + std::remove("/tmp/test_binance.log"); + } + catch (const std::exception& e) + { + std::cout << "❌ enable_logfile failed: " << e.what() << std::endl; + return 1; + } + + // Test 6: Disabled logging + std::cout << "\n6. Testing disabled logging..." << std::endl; + try + { + BinanceCPP_logger::set_debug_level(0); + BinanceCPP_logger::write_log("This should not appear"); + BinanceCPP_logger::set_debug_level(1); // Re-enable for final message + std::cout << "✅ Disabled logging test successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ Disabled logging test failed: " << e.what() << std::endl; + return 1; + } + + std::cout << "\n=== BinanceCPP_logger Tests Complete ===" << std::endl; + return 0; +} \ No newline at end of file diff --git a/tests/test_binance_utils.cpp b/tests/test_binance_utils.cpp new file mode 100644 index 0000000..eb3026f --- /dev/null +++ b/tests/test_binance_utils.cpp @@ -0,0 +1,278 @@ +/* + Unit test for binance_utils.cpp + Tests the utility functions +*/ + +#include +#include +#include +#include +#include + +#include "binance_utils.h" + +int main() +{ + std::cout << "=== Testing Binance Utils ===" << std::endl; + + // Test 1: split_string function + std::cout << "\n1. Testing split_string..." << std::endl; + try + { + std::vector result; + split_string("hello,world,test", ',', result); + + if (result.size() == 3 && result[0] == "hello" && result[1] == "world" && result[2] == "test") + { + std::cout << "✅ split_string successful" << std::endl; + } + else + { + std::cout << "❌ split_string failed: incorrect result" << std::endl; + return 1; + } + } + catch (const std::exception& e) + { + std::cout << "❌ split_string failed: " << e.what() << std::endl; + return 1; + } + + // Test 2: replace_string function + std::cout << "\n2. Testing replace_string..." << std::endl; + try + { + std::string test_str = "hello world hello"; + bool result = replace_string(test_str, "hello", "hi"); + + if (result && test_str == "hi world hi") + { + std::cout << "✅ replace_string successful" << std::endl; + } + else + { + std::cout << "❌ replace_string failed: " << test_str << std::endl; + return 1; + } + } + catch (const std::exception& e) + { + std::cout << "❌ replace_string failed: " << e.what() << std::endl; + return 1; + } + + // Test 3: replace_string_once function + std::cout << "\n3. Testing replace_string_once..." << std::endl; + try + { + std::string test_str = "hello world hello"; + int result = replace_string_once(test_str, "hello", "hi", 0); + + if (result > 0 && test_str == "hi world hello") + { + std::cout << "✅ replace_string_once successful" << std::endl; + } + else + { + std::cout << "❌ replace_string_once failed: " << test_str << std::endl; + return 1; + } + } + catch (const std::exception& e) + { + std::cout << "❌ replace_string_once failed: " << e.what() << std::endl; + return 1; + } + + // Test 4: string_toupper function + std::cout << "\n4. Testing string_toupper..." << std::endl; + try + { + std::string test_str = "hello world"; + string_toupper(test_str); + + if (test_str == "HELLO WORLD") + { + std::cout << "✅ string_toupper (in-place) successful" << std::endl; + } + else + { + std::cout << "❌ string_toupper (in-place) failed: " << test_str << std::endl; + return 1; + } + + // Test the overload that returns a new string + std::string result = string_toupper("test string"); + if (result == "TEST STRING") + { + std::cout << "✅ string_toupper (return new) successful" << std::endl; + } + else + { + std::cout << "❌ string_toupper (return new) failed: " << result << std::endl; + return 1; + } + } + catch (const std::exception& e) + { + std::cout << "❌ string_toupper failed: " << e.what() << std::endl; + return 1; + } + + // Test 5: b2a_hex function + std::cout << "\n5. Testing b2a_hex..." << std::endl; + try + { + char data[] = {0x01, 0x23, 0x45, 0x67}; + std::string result = b2a_hex(data, 4); + + if (result == "01234567") + { + std::cout << "✅ b2a_hex successful" << std::endl; + } + else + { + std::cout << "❌ b2a_hex failed: " << result << std::endl; + return 1; + } + } + catch (const std::exception& e) + { + std::cout << "❌ b2a_hex failed: " << e.what() << std::endl; + return 1; + } + + // Test 6: get_current_epoch function + std::cout << "\n6. Testing get_current_epoch..." << std::endl; + try + { + time_t epoch1 = get_current_epoch(); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + time_t epoch2 = get_current_epoch(); + + if (epoch2 >= epoch1 && epoch1 > 1600000000) // Should be a recent timestamp + { + std::cout << "✅ get_current_epoch successful: " << epoch1 << std::endl; + } + else + { + std::cout << "❌ get_current_epoch failed: " << epoch1 << std::endl; + return 1; + } + } + catch (const std::exception& e) + { + std::cout << "❌ get_current_epoch failed: " << e.what() << std::endl; + return 1; + } + + // Test 7: get_current_ms_epoch function + std::cout << "\n7. Testing get_current_ms_epoch..." << std::endl; + try + { + unsigned long ms_epoch1 = get_current_ms_epoch(); + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + unsigned long ms_epoch2 = get_current_ms_epoch(); + + if (ms_epoch2 > ms_epoch1 && ms_epoch1 > 1600000000000UL) // Should be a recent timestamp in ms + { + std::cout << "✅ get_current_ms_epoch successful: " << ms_epoch1 << std::endl; + } + else + { + std::cout << "❌ get_current_ms_epoch failed: " << ms_epoch1 << std::endl; + return 1; + } + } + catch (const std::exception& e) + { + std::cout << "❌ get_current_ms_epoch failed: " << e.what() << std::endl; + return 1; + } + + // Test 8: hmac_sha256 function + std::cout << "\n8. Testing hmac_sha256..." << std::endl; + try + { + std::string result = hmac_sha256("key", "test data"); + + // HMAC-SHA256 should always return a 64-character hex string + if (result.length() == 64) + { + std::cout << "✅ hmac_sha256 successful (length check)" << std::endl; + } + else + { + std::cout << "❌ hmac_sha256 failed: wrong length " << result.length() << std::endl; + return 1; + } + } + catch (const std::exception& e) + { + std::cout << "❌ hmac_sha256 failed: " << e.what() << std::endl; + return 1; + } + + // Test 9: sha256 function + std::cout << "\n9. Testing sha256..." << std::endl; + try + { + std::string result = sha256("test data"); + + // SHA256 should always return a 64-character hex string + if (result.length() == 64) + { + std::cout << "✅ sha256 successful (length check)" << std::endl; + } + else + { + std::cout << "❌ sha256 failed: wrong length " << result.length() << std::endl; + return 1; + } + } + catch (const std::exception& e) + { + std::cout << "❌ sha256 failed: " << e.what() << std::endl; + return 1; + } + + // Test 10: file_exists function + std::cout << "\n10. Testing file_exists..." << std::endl; + try + { + // Test with a file that should not exist + bool result1 = file_exists("/this/file/should/not/exist"); + + // Test with a file that should exist (the test file itself) + bool result2 = file_exists("/tmp"); // /tmp directory should exist on Unix systems + + if (!result1) + { + std::cout << "✅ file_exists (non-existent file) successful" << std::endl; + } + else + { + std::cout << "❌ file_exists (non-existent file) failed" << std::endl; + return 1; + } + +#ifndef _WIN32 + if (result2) + { + std::cout << "✅ file_exists (existing directory) successful" << std::endl; + } + else + { + std::cout << "⚠️ file_exists (existing directory) - /tmp not found (might be Windows)" << std::endl; + } +#endif + } + catch (const std::exception& e) + { + std::cout << "❌ file_exists failed: " << e.what() << std::endl; + return 1; + } + + std::cout << "\n=== Binance Utils Tests Complete ===" << std::endl; + return 0; +} \ No newline at end of file diff --git a/tests/test_binance_websocket.cpp b/tests/test_binance_websocket.cpp new file mode 100644 index 0000000..2bf2290 --- /dev/null +++ b/tests/test_binance_websocket.cpp @@ -0,0 +1,121 @@ +/* + Unit test for binance_websocket.cpp + Tests the BinanceCPP_websocket class functionality +*/ + +#include +#include + +#include "binance_websocket.h" + +int main() +{ + std::cout << "=== Testing BinanceCPP_websocket ===" << std::endl; + + // Test 1: Basic initialization + std::cout << "\n1. Testing init..." << std::endl; + try + { + BinanceCPP_websocket::init(); + std::cout << "✅ init() successful" << std::endl; + } + catch (const std::exception& e) + { + std::cout << "❌ init() failed: " << e.what() << std::endl; + return 1; + } + + // Test 2: Constants and basic setup + std::cout << "\n2. Testing constants..." << std::endl; + try + { + // Test that constants are defined correctly + if (BINANCE_WS_HOST == "stream.binance.com") + { + std::cout << "✅ BINANCE_WS_HOST correct: " << BINANCE_WS_HOST << std::endl; + } + else + { + std::cout << "❌ BINANCE_WS_HOST incorrect: " << BINANCE_WS_HOST << std::endl; + return 1; + } + + if (BINANCE_WS_PORT == 9443) + { + std::cout << "✅ BINANCE_WS_PORT correct: " << BINANCE_WS_PORT << std::endl; + } + else + { + std::cout << "❌ BINANCE_WS_PORT incorrect: " << BINANCE_WS_PORT << std::endl; + return 1; + } + } + catch (const std::exception& e) + { + std::cout << "❌ Constants test failed: " << e.what() << std::endl; + return 1; + } + + // Test 3: Callback function type + std::cout << "\n3. Testing callback function type..." << std::endl; + try + { + // Test that we can create a callback function + CB test_callback = [](Json::Value &json_value) -> int { + // Simple test callback + return 0; + }; + + if (test_callback) + { + std::cout << "✅ Callback function type creation successful" << std::endl; + } + else + { + std::cout << "❌ Callback function type creation failed" << std::endl; + return 1; + } + } + catch (const std::exception& e) + { + std::cout << "❌ Callback function test failed: " << e.what() << std::endl; + return 1; + } + + // Test 4: Test callback execution + std::cout << "\n4. Testing callback execution..." << std::endl; + try + { + bool callback_executed = false; + CB test_callback = [&callback_executed](Json::Value &json_value) -> int { + callback_executed = true; + return 0; + }; + + Json::Value test_json; + test_json["test"] = "value"; + int result = test_callback(test_json); + + if (callback_executed && result == 0) + { + std::cout << "✅ Callback execution successful" << std::endl; + } + else + { + std::cout << "❌ Callback execution failed" << std::endl; + return 1; + } + } + catch (const std::exception& e) + { + std::cout << "❌ Callback execution test failed: " << e.what() << std::endl; + return 1; + } + + // Note: We avoid testing connect_endpoint and enter_event_loop as they require + // an actual network connection and would be integration tests rather than unit tests + + std::cout << "\n=== BinanceCPP_websocket Tests Complete ===" << std::endl; + std::cout << "Note: Network-dependent functions (connect_endpoint, enter_event_loop) not tested in unit tests" << std::endl; + return 0; +} \ No newline at end of file diff --git a/test_new_structure.cpp b/tests/test_new_structure.cpp similarity index 100% rename from test_new_structure.cpp rename to tests/test_new_structure.cpp diff --git a/tests/test_standalone b/tests/test_standalone new file mode 100755 index 0000000..da18cf0 Binary files /dev/null and b/tests/test_standalone differ diff --git a/tests/test_standalone.cpp b/tests/test_standalone.cpp new file mode 100644 index 0000000..f9c9cae --- /dev/null +++ b/tests/test_standalone.cpp @@ -0,0 +1,55 @@ +/* + Simple standalone test that doesn't require the main library + Tests basic functionality to verify our test structure works +*/ + +#include +#include +#include + +// Simple test functions that don't require external dependencies +bool test_basic_string_operations() +{ + std::string test = "hello world"; + return test.length() == 11; +} + +bool test_basic_vector_operations() +{ + std::vector vec = {1, 2, 3, 4, 5}; + return vec.size() == 5; +} + +int main() +{ + std::cout << "=== Standalone Test for Test Structure Validation ===" << std::endl; + + // Test 1: Basic string operations + std::cout << "\n1. Testing basic string operations..." << std::endl; + if (test_basic_string_operations()) + { + std::cout << "✅ Basic string operations successful" << std::endl; + } + else + { + std::cout << "❌ Basic string operations failed" << std::endl; + return 1; + } + + // Test 2: Basic vector operations + std::cout << "\n2. Testing basic vector operations..." << std::endl; + if (test_basic_vector_operations()) + { + std::cout << "✅ Basic vector operations successful" << std::endl; + } + else + { + std::cout << "❌ Basic vector operations failed" << std::endl; + return 1; + } + + std::cout << "\n=== Standalone Test Complete ===" << std::endl; + std::cout << "Test structure validation: SUCCESS" << std::endl; + std::cout << "The tests directory and CMake configuration are working correctly." << std::endl; + return 0; +} \ No newline at end of file