1.9 KiB
1.9 KiB
Task 4 Fix Brief: make list_devices test compatible with libusb-enabled builds
Finding to fix
Task 4 reviewer found an Important issue:
- tests/cpp/test_c_api.cpp unconditionally expects mag160c_list_devices to return MAG160C_ERR_UNSUPPORTED.
- That is correct only when MAG160C_HAS_LIBUSB=0.
- When CMake finds libusb and builds with MAG160C_HAS_LIBUSB=1, the Task 4 spec requires no matching device to return MAG160C_OK with an empty list, and matching devices may return MAG160C_OK with a non-empty list.
- The test target currently does not receive MAG160C_HAS_LIBUSB from CMake, so it cannot conditionalize correctly.
Required fix
- In tests/cpp/test_c_api.cpp, make the list_devices expectation conditional on MAG160C_HAS_LIBUSB.
- In no-libusb builds, continue to assert MAG160C_ERR_UNSUPPORTED, null devices, count 0, and last_error contains libusb.
- In libusb-enabled builds, assert MAG160C_OK, and always call mag160c_free_device_list(devices). Do not require count to be zero because hardware may be attached.
- In CMakeLists.txt, propagate MAG160C_HAS_LIBUSB=1 or 0 to test targets that need it, at least test_c_api.
Verification
Run direct no-libusb verification:
g++ -std=c++17 -DMAG160C_STATIC -DMAG160C_HAS_LIBUSB=0 -Iinclude -Isrc src\core\error.cpp src\core\context.cpp src\core\tcm_frame.cpp src\core\tcm_device.cpp src\core\device.cpp src\c_api.cpp tests\cpp\test_c_api.cpp -o build_task4_c_api_test.exe
.\build_task4_c_api_test.exe
g++ -std=c++17 -DMAG160C_STATIC -DMAG160C_HAS_LIBUSB=0 -Iinclude -Isrc src\core\error.cpp src\core\context.cpp src\core\tcm_frame.cpp src\core\tcm_device.cpp src\core\device.cpp src\c_api.cpp tests\cpp\test_device_model.cpp -o build_task4_device_model_test.exe
.\build_task4_device_model_test.exe
Report contract
Append a fix report section to .superpowers/sdd/task-4-report.md and return status plus one-line test summary.