error_code returned from functions might not be of the generic category, but of the system category, which can have different error code values. Use default_error_condition() to remap errors to the generic category where possible, to allow comparing them to the expected values.
Use the ErrorIs() helper instead of a direct comparison against an excpected value.
Can you please use static_cast instead of a C-style cast?