#include "PluginCompatibility.hpp" #include #include #include #include #include #include namespace { echoion_string_view_v1 view(const std::string_view value) { return {.data = value.data(), .size = value.size()}; } echoion_status_v1 create(const echoion_module_host_v1*, echoion_module_instance_v1*) { return ECHOION_STATUS_OK_V1; } void destroy(echoion_module_instance_v1) {} echoion_status_v1 activate(echoion_module_instance_v1) { return ECHOION_STATUS_OK_V1; } echoion_status_v1 quiesce(echoion_module_instance_v1, std::int64_t) { return ECHOION_STATUS_OK_V1; } echoion_status_v1 checkpoint(echoion_module_instance_v1, echoion_write_bytes_fn_v1, void*) { return ECHOION_STATUS_OK_V1; } echoion_status_v1 restore(echoion_module_instance_v1, echoion_bytes_view_v1) { return ECHOION_STATUS_OK_V1; } echoion_status_v1 readiness(echoion_module_instance_v1, echoion_module_readiness_v1*) { return ECHOION_STATUS_OK_V1; } echoion_status_v1 deactivate(echoion_module_instance_v1) { return ECHOION_STATUS_OK_V1; } const echoion_module_api_v1 api{ .struct_size = sizeof(echoion_module_api_v1), .abi_version = ECHOION_MODULE_ABI_VERSION, .create = create, .destroy = destroy, .activate = activate, .quiesce = quiesce, .checkpoint = checkpoint, .restore = restore, .readiness = readiness, .deactivate = deactivate, .reserved = {}, }; std::array dependencies(const std::string_view apiHash, const std::string_view coreHash) { return {{ { .struct_size = sizeof(echoion_module_dependency_v1), .component_id = view("EchoionApi"), .version_range = view(">=2.0.0 <3.0.0"), .abi_hash = view(apiHash), .optional = 0, .reserved_bytes = {}, }, { .struct_size = sizeof(echoion_module_dependency_v1), .component_id = view("EchoionCore"), .version_range = view(">=2.0.0 <3.0.0"), .abi_hash = view(coreHash), .optional = 0, .reserved_bytes = {}, }, }}; } echoion_module_descriptor_v1 descriptor(const std::array& values) { return { .struct_size = sizeof(echoion_module_descriptor_v1), .abi_version = ECHOION_MODULE_ABI_VERSION, .component_id = view("EchoionPluginExample"), .version_major = 2, .version_minor = 0, .version_patch = 0, .version_prerelease = {}, .abi_hash = view("sha256:example"), .dependencies = values.data(), .dependency_count = values.size(), .activation_policy = ECHOION_ACTIVATION_RELOADABLE_V1, .api = &api, .reserved = {}, }; } } // namespace Void::Testing::Test compatible_v2_extension_descriptor_is_accepted() { const auto values = dependencies( "sha256:" "d50293d345a97e52f9844088bdd42277f566bc815a21b7636d3e053f06c6c113", "sha256:" "9cb668e2a502dcfe02d145ed63635d63619732d77ff5749685834382705e8d21"); const auto candidate = descriptor(values); const auto result = Echoion::Core::Detail::checkExtensionDescriptor(&candidate); Void::Testing::expect(result.compatible); } Void::Testing::Test legacy_or_mismatched_extension_descriptor_is_rejected() { const auto values = dependencies("sha256:old-api", "sha256:old-core"); auto candidate = descriptor(values); auto result = Echoion::Core::Detail::checkExtensionDescriptor(&candidate); Void::Testing::expect(!result.compatible); candidate.version_major = 1; result = Echoion::Core::Detail::checkExtensionDescriptor(&candidate); Void::Testing::expect(!result.compatible); Void::Testing::expect( !Echoion::Core::Detail::checkExtensionDescriptor(nullptr).compatible); } int main(int argc, char** argv) { return Void::Testing::Runner::instance().main(argc, argv); }