#include #include // 模拟 Info 类 class Info { public: std::string title_; std::string version_; std::string description_; class Contact { public: std::string name_; std::string email_; Contact& name(const std::string& n) { name_ = n; return *this; } Contact& email(const std::string& e) { email_ = e; return *this; } }; Contact contact_; Info& title(const std::string& t) { title_ = t; return *this; } Info& version(const std::string& v) { version_ = v; return *this; } Info& description(const std::string& d) { description_ = d; return *this; } Info& contact(const Contact& c) { contact_ = c; return *this; } }; // 模拟 OpenAPI 类 class OpenAPI { public: Info info_; OpenAPI& info(const Info& i) { info_ = i; return *this; } }; // 模拟 GroupedOpenApi 类 class GroupedOpenApi { public: std::string group_; std::string pathPattern_; class Builder { public: Builder& group(const std::string& g) { group_name = g; return *this; } Builder& pathsToMatch(const std::string& p) { path = p; return *this; } GroupedOpenApi build() { GroupedOpenApi api; api.group_ = group_name; api.pathPattern_ = path; return api; } private: std::string group_name; std::string path; }; static Builder builder() { return Builder(); } }; // OpenApiConfig 类(模拟) class OpenApiConfig { public: OpenAPI customOpenAPI() { Info info = Info() .title("实验检验过程平台业务管理系统 API") .version("1.0.0") .description("实验检验过程平台业务管理系统 RESTful API 接口文档,提供用户管理、业务流程管理、数据统计等功能。") .contact(Info::Contact() .name("开发团队") .email("dev@example.com")); return OpenAPI().info(info); } GroupedOpenApi businessApi() { return GroupedOpenApi::builder() .group("业务管理") .pathsToMatch("/api/**") .build(); } }; // 测试用例 TEST(OpenApiConfigTest, testCustomOpenAPI_NormalInput) { OpenApiConfig config; OpenAPI api = config.customOpenAPI(); EXPECT_EQ(api.info_.title_, "实验检验过程平台业务管理系统 API"); EXPECT_EQ(api.info_.version_, "1.0.0"); EXPECT_EQ(api.info_.description_, "实验检验过程平台业务管理系统 RESTful API 接口文档,提供用户管理、业务流程管理、数据统计等功能。"); EXPECT_EQ(api.info_.contact_.name_, "开发团队"); EXPECT_EQ(api.info_.contact_.email_, "dev@example.com"); } TEST(OpenApiConfigTest, testBusinessApi_NormalInput) { OpenApiConfig config; GroupedOpenApi group = config.businessApi(); EXPECT_EQ(group.group_, "业务管理"); EXPECT_EQ(group.pathPattern_, "/api/**"); } // 边界值测试:验证字段非空 TEST(OpenApiConfigTest, testCustomOpenAPI_FieldsNotEmpty) { OpenApiConfig config; OpenAPI api = config.customOpenAPI(); EXPECT_FALSE(api.info_.title_.empty()); EXPECT_FALSE(api.info_.version_.empty()); EXPECT_FALSE(api.info_.description_.empty()); EXPECT_FALSE(api.info_.contact_.name_.empty()); EXPECT_FALSE(api.info_.contact_.email_.empty()); } TEST(OpenApiConfigTest, testBusinessApi_FieldsNotEmpty) { OpenApiConfig config; GroupedOpenApi group = config.businessApi(); EXPECT_FALSE(group.group_.empty()); EXPECT_FALSE(group.pathPattern_.empty()); }