生成代码工程

This commit is contained in:
root 2026-05-25 03:12:55 +00:00
parent d6a568c27c
commit f26aa1c7d1
8 changed files with 9557 additions and 2 deletions

34
CMakeLists.txt Normal file
View File

@ -0,0 +1,34 @@
cmake_minimum_required(VERSION 3.10)
project(odf-manager VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if (MSVC)
add_compile_options(/utf-8)
endif()
# ============================================================
# ODF Core Library
# ============================================================
add_library(odf_core
src/app.cpp
)
target_include_directories(odf_core PUBLIC include)
# ============================================================
# Main Application
# ============================================================
add_executable(odf_manager
src/main.cpp
)
target_link_libraries(odf_manager PRIVATE odf_core)
# ============================================================
# Unit Test (using standard assert only)
# ============================================================
add_executable(basic_test
tests/basic_test.cpp
)
target_link_libraries(basic_test PRIVATE odf_core)

View File

@ -1,3 +1,62 @@
# 27
# ODF 光纤配线单元管理系统
暂无描述
基于需求分析结果生成的 C++17 工程,提供 ODF 光纤配线单元的标准化数据建模、编码生成、兼容性校验、典型配置管理与项目排期跟踪功能。
## 目录结构
```
├── CMakeLists.txt # CMake 构建配置C++17MSVC /utf-8 支持)
├── README.md
├── include/
│ └── app.hpp # 核心头文件数据结构、枚举、ODFManager 类声明
├── src/
│ ├── app.cpp # ODFManager 业务逻辑实现
│ └── main.cpp # 命令行演示入口
└── tests/
└── basic_test.cpp # 单元测试(标准库 assert无外部依赖
```
## 构建与运行
### 前置要求
- CMake >= 3.10
- 支持 C++17 的编译器GCC 8+, Clang 7+, MSVC 2019+
### 编译步骤
```bash
cd codegen-runs/codegen_0aba9d8655fb4800802d9d53d920a8a4
mkdir -p build && cd build
cmake ..
cmake --build .
```
### 运行主程序
```bash
./odf_manager
```
主程序演示:编码生成、典型配置查询、兼容性校验、标签打印、里程碑排期导出。
### 运行单元测试
```bash
./basic_test
```
共 6 个测试用例覆盖:编码生成(含唯一性冲突处理)、适配器兼容性校验、单元注册(含容量约束与重复检测)、典型配置查询、标签与里程碑功能。
## 设计要点
| 需求 | 实现 |
|------|------|
| ODF 单元数据结构 | `ODFUnitInfo` 结构体,包含 ID、型号、位置、制造商、适配器列表 |
| 适配器接口规格 | `AdapterSpec` 结构体含接口类型LC/SC/MPO、等级OM1-OS2、端面UPC/APC、插损/回损 |
| 命名编码规则 | `generate_naming_code()` 格式 `[site]-[cabinet]-[slot]`,长度 ≤ 64 字符,冲突自动去重 |
| 典型配置方案 | `TypicalConfig` 结构 + `register/get_typical_config` 接口 |
| 兼容性校验 | `validate_adapter_compatibility()` 按接口类型匹配,允许 UPC ↔ APC 混合 |
| 项目里程碑 | `Milestone` 结构 + `export_milestone_schedule()` 输出文本表格 |
| 标签打印 | `print_label()` 生成含文本 + 二维码占位符的标签内容 |
| 容量约束 | 注册时校验 `max_capacity_cores ≤ 288` |

8734
events.ndjson Normal file

File diff suppressed because one or more lines are too long

34
generation.json Normal file
View File

@ -0,0 +1,34 @@
{
"projectId": 49,
"generationId": "codegen_0aba9d8655fb4800802d9d53d920a8a4",
"language": "C++",
"status": "completed",
"fileIds": [
784,
785,
786,
787,
788
],
"outputDir": "/app/agents/ai_agents/project-files/codegen-runs/codegen_0aba9d8655fb4800802d9d53d920a8a4",
"relativeOutputDir": "codegen-runs/codegen_0aba9d8655fb4800802d9d53d920a8a4",
"generatedFiles": [
"CMakeLists.txt",
"README.md",
"events.ndjson",
"include/app.hpp",
"src/app.cpp",
"src/main.cpp",
"tests/basic_test.cpp"
],
"analysisSummary": "### 业务目标 \n1. 设计并实现标准化的ODF光纤配线架光纤配线单元支持高效、可靠的光纤连接与管理。 \n2. 统一适配器与连接器接口规范,确保不同设备间的互操作性与物理兼容性。 \n3. 建立清晰的ODF单元编号与命名规则提升现场部署、维护和资产管理效率。 \n4. 提供典型场景下的配置参考方案如数据中心LC单模预端接指导工程实施。 \n5. 明确项目开发与交付的关键时间节点,保障产品按期落地。\n\n---\n\n### 功能清单 \n1. **ODF单元结构设计** \n - 支持模块化安装,适配标准机柜尺寸。 \n - 提供光纤熔接、盘纤、存储一体化空间布局。 \n\n2. **适配器面板集成** \n - 集成LC、SC等类型光纤适配器支持双工/单工模式。 \n - 支持前后面板接入,便于跳纤布线与维护。 \n\n3. **连接器接口管理** \n - 定义光接口类型LC/UPC, LC/APC等、端面角度、插入损耗要求。 \n - 规范连接器插拔寿命、回波损耗等性能指标。 \n\n4. **编号与标识系统** \n - 实现ODF机柜、子框、槽位、端口层级编码。 \n - 支持标签打印与条码/二维码生成,用于资产追踪。 \n\n5. **典型配置方案库** \n - 内置常见应用场景模板如数据中心高密度LC单模预端接。 \n - 提供端口密度、跳纤长度、冗余数量推荐配置。 \n\n6. **项目进度跟踪支持** \n - 输出关键里程碑节点(需求确认、样机测试、批量交付等)。 \n - 支持排期导出与进度状态更新接口。\n\n---\n\n### 数据结构 \n1. **ODF单元信息** \n - 字段单元ID、型号、安装位置机房-机柜-高度U数、制造商、生产日期 \n\n2. **适配器接口规格表** \n - 字段接口类型LC/SC/MPO、连接器等级OM1/OM2/OM3/OS2、端面类型UPC/APC、最大插入损耗dB、最小回波损耗dB、适配器数量、安装方向 \n\n3. **ODF命名编码规则** \n - 结构:`[站点代码]-[机房编号]-[机柜号]-[子架号]-[槽位号]-[端口范围]` \n - 示例:`DC01-RF02-CB03-SU04-SL05-P01-24` \n\n4. **典型配置清单** \n - 字段:场景名称、应用环境(数据中心/园区网/接入网)、光纤类型(单模/多模、连接器类型、预端接长度、端口密度每U、冗余比例、配套附件列表 \n\n5. **项目里程碑计划** \n - 字段:阶段名称、开始时间、结束时间、负责人、交付物、完成状态 \n\n---\n\n### 接口或命令 \n1. **外部系统对接接口** \n - 资产管理系统API同步ODF单元编号与部署位置 \n - 网络设计工具导入导出接口支持典型配置模板导入JSON/CSV格式 \n\n2. **内部操作命令(配置管理)** \n - `generate_naming_code(site, cabinet, slot)`:根据规则生成唯一编码 \n - `get_typical_config(scene_type)`:获取指定场景的推荐配置参数 \n - `validate_adapter_compatibility(connector_a, connector_b)`:检查两端连接器是否可对接 \n\n3. **报告输出命令** \n - `export_milestone_schedule()`:导出项目排期甘特图数据 \n - `print_label(odf_unit_id)`:生成可用于打印的标签内容(含文本与二维码)\n\n---\n\n### 约束 \n1. 所有连接器必须符合IEC 61754系列国际标准。 \n2. ODF单元命名需全局唯一且长度不超过64字符。 \n3. 单个ODF单元最大支持容量为288芯光纤。 \n4. 典型配置方案仅适用于文档中列出的标准场景,非标场景需人工审核。 \n5. 项目关键里程碑不得延迟超过±5个工作日。 \n6. 面板上LC适配器密度不低于48端口/1U。 \n\n---\n\n### 测试建议 \n1. **物理兼容性测试** \n - 验证LC/SC/MPO连接器在对应适配器中的插拔顺畅性与锁定可靠性。 \n - 进行500次插拔循环测试检查磨损与性能衰减。 \n\n2. **光学性能测试** \n - 使用光功率计和光源检测插入损耗与回波损耗是否满足规范值。 \n - 在-20°C至+60°C温变环境下重复测试稳定性。 \n\n3. **命名与编码验证** \n - 输入边界值(如最大编号)测试编码生成逻辑正确性。 \n - 检查重复编码生成的防重机制。 \n\n4. **典型配置匹配测试** \n - 将“数据中心LC单模预端接”方案应用于模拟项目验证物料清单完整性与合理性。 \n\n5. **项目排期一致性审查** \n - 对比各阶段实际进展与计划节点,评估偏差预警机制有效性。 \n\n6. **标签可读性测试** \n - 打印标签并在强光、潮湿环境下观察文字与二维码可识别性。",
"eventLogFile": "/app/agents/ai_agents/project-files/codegen-runs/codegen_0aba9d8655fb4800802d9d53d920a8a4/events.ndjson",
"repoSettings": {
"username": "root",
"password": "pAssW0rd",
"repoUrl": "http://47.108.255.216:3000/root/27.git",
"branch": "main"
},
"repoUrl": "http://47.108.255.216:3000/root/27.git",
"branch": "main"
}

205
include/app.hpp Normal file
View File

@ -0,0 +1,205 @@
#ifndef ODF_MANAGER_APP_HPP
#define ODF_MANAGER_APP_HPP
#include <string>
#include <vector>
#include <map>
#include <cstdint>
#include <sstream>
#include <iomanip>
#include <ctime>
#include <algorithm>
// =========================================================================
// ODF 光纤配线单元管理系统 —— 核心数据类型与接口
// =========================================================================
/// @brief 连接器端面类型UPC / APC
enum class PolishType : uint8_t {
UPC, ///< 超物理接触端面,回波损耗 ≥ 50dB
APC ///< 斜角度物理接触端面,回波损耗 ≥ 60dB
};
/// @brief 连接器等级(按标准光纤分类)
enum class FiberGrade : uint8_t {
OM1, ///< 多模 OM1 (62.5/125μm)
OM2, ///< 多模 OM2 (50/125μm)
OM3, ///< 多模 OM3 (50/125μm, 激光优化)
OM4, ///< 多模 OM4 (50/125μm, 高带宽)
OM5, ///< 多模 OM5 (50/125μm, 宽带)
OS2 ///< 单模 OS2 (9/125μm)
};
/// @brief 光接口类型(连接器形式)
enum class ConnectorType : uint8_t {
LC, ///< LC 连接器1.25mm 插芯)
SC, ///< SC 连接器2.5mm 插芯)
MPO ///< MPO 多芯连接器
};
/// @brief 适配器安装方向
enum class MountDirection : uint8_t {
Front, ///< 前面板接入
Rear, ///< 后面板接入
Both ///< 前后均可接入
};
// =========================================================================
// 数据结构定义
// =========================================================================
/**
* @brief
*
*
*/
struct AdapterSpec {
ConnectorType interface_type; ///< 接口类型LC/SC/MPO
FiberGrade connector_grade; ///< 连接器等级OM1-OS2
PolishType polish_type; ///< 端面类型UPC/APC
double max_insertion_loss_dB; ///< 最大插入损耗 (dB)
double min_return_loss_dB; ///< 最小回波损耗 (dB)
int port_count; ///< 该面板上安装的适配器数量
MountDirection mount_direction; ///< 安装方向
};
/**
* @brief ODF
*
* ODF /
*/
struct ODFUnitInfo {
std::string unit_id; ///< 单元全局唯一标识
std::string model_name; ///< 产品型号
std::string location; ///< 安装位置,格式 "机房-机柜-高度U数"
std::string manufacturer; ///< 制造商
std::string production_date; ///< 生产日期 (YYYY-MM-DD)
int max_capacity_cores; ///< 最大支持光纤芯数(≤ 288
std::vector<AdapterSpec> adapters; ///< 已安装的适配器列表
};
/**
* @brief
*
*
*/
struct TypicalConfig {
std::string scene_name; ///< 场景名称,如 "数据中心LC单模预端接"
std::string environment; ///< 应用环境:数据中心 / 园区网 / 接入网
std::string fiber_type; ///< 光纤类型:单模/多模
std::string connector_type; ///< 连接器类型描述
int preterminated_len_m; ///< 预端接长度 (米)
int port_density_per_u; ///< 每 U 端口密度
double redundancy_ratio; ///< 冗余比例 (如 0.25 表示 25%)
std::vector<std::string> accessories; ///< 配套附件列表
};
/**
* @brief
*/
struct Milestone {
std::string phase_name; ///< 阶段名称
std::string start_date; ///< 开始日期 (YYYY-MM-DD)
std::string end_date; ///< 结束日期 (YYYY-MM-DD)
std::string owner; ///< 负责人
std::string deliverable; ///< 交付物描述
bool is_completed; ///< 完成状态
};
// =========================================================================
// ODF 管理器 —— 核心业务接口
// =========================================================================
/**
* @brief ODF 线
*
* ODF
*/
class ODFManager {
public:
ODFManager() = default;
// ---- 单元管理 ----
/// @brief 注册一个新的 ODF 单元到管理器
void register_unit(const ODFUnitInfo& unit);
/// @brief 按 unit_id 查询已注册的 ODF 单元
/// @return 指向 ODFUnitInfo 的指针,若不存在返回 nullptr
const ODFUnitInfo* find_unit(const std::string& unit_id) const;
/// @brief 返回所有已注册的 ODF 单元列表
const std::vector<ODFUnitInfo>& all_units() const;
// ---- 编码生成 ----
/**
* @brief --
*
* `[site]-[cabinet]-[slot]` 64
*
* @param site DC01
* @param cabinet RF02
* @param slot SL05
* @return
*/
std::string generate_naming_code(const std::string& site,
const std::string& cabinet,
const std::string& slot) const;
// ---- 典型配置 ----
/**
* @brief
* @param scene_type
* @return TypicalConfig
*/
TypicalConfig get_typical_config(const std::string& scene_type) const;
/// @brief 注册一个典型配置方案
void register_typical_config(const TypicalConfig& cfg);
// ---- 兼容性校验 ----
/**
* @brief
*
*
* - LC LCSC SCMPO MPO
* - UPC APC
*
* @param a A
* @param b B
* @return true false
*/
bool validate_adapter_compatibility(const AdapterSpec& a,
const AdapterSpec& b) const;
// ---- 报告与标签 ----
/**
* @brief
* @return
*/
std::string export_milestone_schedule() const;
/// @brief 添加一个里程碑
void add_milestone(const Milestone& ms);
/// @brief 返回所有里程碑
const std::vector<Milestone>& milestones() const;
/**
* @brief
* @param unit_id ODF ID
* @return [QR]
*/
std::string print_label(const std::string& unit_id) const;
private:
std::vector<ODFUnitInfo> units_;
std::vector<TypicalConfig> configs_;
std::vector<Milestone> milestones_;
/// @brief 内部辅助:将 ConnectorType 转为字符串
static std::string connector_type_str(ConnectorType t);
/// @brief 内部辅助:将 PolishType 转为字符串
static std::string polish_type_str(PolishType p);
};
#endif // ODF_MANAGER_APP_HPP

190
src/app.cpp Normal file
View File

@ -0,0 +1,190 @@
#include "app.hpp"
#include <stdexcept>
#include <cassert>
// =========================================================================
// 内部辅助函数
// =========================================================================
std::string ODFManager::connector_type_str(ConnectorType t) {
switch (t) {
case ConnectorType::LC: return "LC";
case ConnectorType::SC: return "SC";
case ConnectorType::MPO: return "MPO";
default: return "UNKNOWN";
}
}
std::string ODFManager::polish_type_str(PolishType p) {
switch (p) {
case PolishType::UPC: return "UPC";
case PolishType::APC: return "APC";
default: return "UNKNOWN";
}
}
// =========================================================================
// 单元管理
// =========================================================================
void ODFManager::register_unit(const ODFUnitInfo& unit) {
if (unit.max_capacity_cores > 288) {
throw std::invalid_argument(
"ODF unit capacity exceeds 288 cores (constraint violated)");
}
if (unit.unit_id.empty()) {
throw std::invalid_argument("unit_id must not be empty");
}
// 检查重复 ID
for (const auto& existing : units_) {
if (existing.unit_id == unit.unit_id) {
throw std::invalid_argument("duplicate unit_id: " + unit.unit_id);
}
}
units_.push_back(unit);
}
const ODFUnitInfo* ODFManager::find_unit(const std::string& unit_id) const {
for (const auto& u : units_) {
if (u.unit_id == unit_id) return &u;
}
return nullptr;
}
const std::vector<ODFUnitInfo>& ODFManager::all_units() const {
return units_;
}
// =========================================================================
// 编码生成
// =========================================================================
std::string ODFManager::generate_naming_code(const std::string& site,
const std::string& cabinet,
const std::string& slot) const {
// 格式: [site]-[cabinet]-[slot]
// 例如: DC01-RF02-SL05
std::ostringstream oss;
oss << site << "-" << cabinet << "-" << slot;
std::string code = oss.str();
// 约束:长度不超过 64 字符
if (code.size() > 64) {
// 截断到 64 字节,并尽可能保留尾部标识
code = code.substr(0, 61) + "...";
}
// 保证全局唯一:检查是否与已注册某单元的 unit_id 重复
// 实际生产可通过数据库约束保证,此处仅做运行时提醒
for (const auto& u : units_) {
if (u.unit_id == code) {
// 若冲突则追加时间戳后缀(简单去重)
std::time_t now = std::time(nullptr);
std::tm* tm = std::localtime(&now);
std::ostringstream suffix;
suffix << std::put_time(tm, "_%H%M%S");
code += suffix.str();
if (code.size() > 64) code = code.substr(0, 64);
break;
}
}
return code;
}
// =========================================================================
// 典型配置
// =========================================================================
TypicalConfig ODFManager::get_typical_config(const std::string& scene_type) const {
for (const auto& cfg : configs_) {
if (cfg.scene_name.find(scene_type) != std::string::npos) {
return cfg;
}
}
// 未找到时返回空配置
return TypicalConfig{};
}
void ODFManager::register_typical_config(const TypicalConfig& cfg) {
configs_.push_back(cfg);
}
// =========================================================================
// 兼容性校验
// =========================================================================
bool ODFManager::validate_adapter_compatibility(const AdapterSpec& a,
const AdapterSpec& b) const {
// 1) 接口类型必须相同
if (a.interface_type != b.interface_type) {
return false;
}
// 2) 端面类型允许混合UPC ↔ APC 可以物理插入)
// 但回波损耗会受短板影响;此处仅校验物理兼容
// 3) 额外检查:连接器等级不同时,物理上仍可插拔
// 不阻塞对接
return true;
}
// =========================================================================
// 报告与标签
// =========================================================================
std::string ODFManager::export_milestone_schedule() const {
if (milestones_.empty()) {
return "[No milestones scheduled]\n";
}
std::ostringstream oss;
oss << "+-----+----------------------+------------+------------+"
<< "----------------------+------+\n";
oss << "| # | Phase | Start | End |"
<< " Deliverable | Done |\n";
oss << "+-----+----------------------+------------+------------+"
<< "----------------------+------+\n";
int idx = 0;
for (const auto& ms : milestones_) {
++idx;
oss << "| " << std::left << std::setw(3) << idx << " "
<< "| " << std::setw(20) << ms.phase_name << " "
<< "| " << std::setw(10) << ms.start_date << " "
<< "| " << std::setw(10) << ms.end_date << " "
<< "| " << std::setw(20) << ms.deliverable << " "
<< "| " << (ms.is_completed ? " Y " : " N ")
<< "|\n";
}
oss << "+-----+----------------------+------------+------------+"
<< "----------------------+------+\n";
return oss.str();
}
void ODFManager::add_milestone(const Milestone& ms) {
milestones_.push_back(ms);
}
const std::vector<Milestone>& ODFManager::milestones() const {
return milestones_;
}
std::string ODFManager::print_label(const std::string& unit_id) const {
const ODFUnitInfo* unit = find_unit(unit_id);
if (!unit) {
return "[ERROR] Unit not found: " + unit_id + "\n";
}
std::ostringstream oss;
oss << "+====================================+\n";
oss << "| ODF Unit Label |\n";
oss << "+====================================+\n";
oss << "| ID: " << std::left << std::setw(27) << unit->unit_id << "|\n";
oss << "| Model: " << std::setw(27) << unit->model_name << "|\n";
oss << "| Location:" << std::setw(27) << unit->location << "|\n";
oss << "| Mfr: " << std::setw(27) << unit->manufacturer << "|\n";
oss << "| Date: " << std::setw(27) << unit->production_date << "|\n";
oss << "| Cores: " << std::setw(27) << unit->max_capacity_cores << "|\n";
oss << "+------------------------------------+\n";
oss << "| [QR CODE] " << unit->unit_id << " |\n";
oss << "+====================================+\n";
return oss.str();
}

137
src/main.cpp Normal file
View File

@ -0,0 +1,137 @@
#include "app.hpp"
#include <iostream>
#include <cstdlib>
/**
* @brief ODF
*
* ODFManager +
*
*/
int main() {
ODFManager mgr;
// =========================================================
// 1. 注册典型配置方案
// =========================================================
TypicalConfig dc_config;
dc_config.scene_name = "数据中心LC单模预端接";
dc_config.environment = "数据中心";
dc_config.fiber_type = "单模 (OS2)";
dc_config.connector_type = "LC/UPC 双工";
dc_config.preterminated_len_m = 15;
dc_config.port_density_per_u = 48;
dc_config.redundancy_ratio = 0.25;
dc_config.accessories = {"尾纤束", "熔接保护管", "标签套", "理线架"};
mgr.register_typical_config(dc_config);
TypicalConfig campus_config;
campus_config.scene_name = "园区网SC多模预端接";
campus_config.environment = "园区网";
campus_config.fiber_type = "多模 (OM4)";
campus_config.connector_type = "SC/UPC 双工";
campus_config.preterminated_len_m = 10;
campus_config.port_density_per_u = 24;
campus_config.redundancy_ratio = 0.33;
campus_config.accessories = {"尾纤束", "适配器面板", "标签套"};
mgr.register_typical_config(campus_config);
// =========================================================
// 2. 注册里程碑
// =========================================================
mgr.add_milestone({"需求确认", "2025-03-01", "2025-03-15", "张工", "需求文档 V1.0", true});
mgr.add_milestone({"样机设计", "2025-03-16", "2025-04-15", "李工", "3D 图纸 & BOM", true});
mgr.add_milestone({"样机试产", "2025-04-16", "2025-05-10", "王工", "10 台样机", false});
mgr.add_milestone({"光学性能测试", "2025-05-11", "2025-05-25", "赵工", "测试报告", false});
mgr.add_milestone({"批量交付", "2025-06-01", "2025-06-30", "钱工", "首批 500 台", false});
// =========================================================
// 3. 注册一个 ODF 单元
// =========================================================
ODFUnitInfo unit;
unit.unit_id = "DC01-RF02-CB03-SU04-SL05-P01-24";
unit.model_name = "ODF-288-4U-SM";
unit.location = "A机房-03号机柜-22U";
unit.manufacturer = "光联科技";
unit.production_date = "2025-02-20";
unit.max_capacity_cores = 288;
AdapterSpec adapter;
adapter.interface_type = ConnectorType::LC;
adapter.connector_grade = FiberGrade::OS2;
adapter.polish_type = PolishType::UPC;
adapter.max_insertion_loss_dB = 0.30;
adapter.min_return_loss_dB = 50.0;
adapter.port_count = 48;
adapter.mount_direction = MountDirection::Front;
unit.adapters.push_back(adapter);
mgr.register_unit(unit);
// =========================================================
// 4. 编码生成演示
// =========================================================
std::cout << "=== ODF 编码生成示例 ===\n";
std::string code = mgr.generate_naming_code("DC01", "RF02", "SL05");
std::cout << "编码结果: " << code << "\n\n";
// =========================================================
// 5. 典型配置查询
// =========================================================
std::cout << "=== 典型配置查询 ===\n";
TypicalConfig cfg = mgr.get_typical_config("数据中心LC单模预端接");
if (!cfg.scene_name.empty()) {
std::cout << "场景: " << cfg.scene_name << "\n"
<< "环境: " << cfg.environment << "\n"
<< "光纤: " << cfg.fiber_type << "\n"
<< "连接器: " << cfg.connector_type << "\n"
<< "密度: " << cfg.port_density_per_u << " 端口/1U\n"
<< "冗余: " << (cfg.redundancy_ratio * 100) << "%\n"
<< "附件:\n";
for (const auto& acc : cfg.accessories) {
std::cout << " - " << acc << "\n";
}
}
std::cout << "\n";
// =========================================================
// 6. 兼容性校验演示
// =========================================================
std::cout << "=== 兼容性校验 ===\n";
AdapterSpec lc_upc_a;
lc_upc_a.interface_type = ConnectorType::LC;
lc_upc_a.polish_type = PolishType::UPC;
lc_upc_a.connector_grade = FiberGrade::OS2;
AdapterSpec lc_upc_b;
lc_upc_b.interface_type = ConnectorType::LC;
lc_upc_b.polish_type = PolishType::UPC;
lc_upc_b.connector_grade = FiberGrade::OS2;
AdapterSpec sc_upc;
sc_upc.interface_type = ConnectorType::SC;
sc_upc.polish_type = PolishType::UPC;
sc_upc.connector_grade = FiberGrade::OS2;
std::cout << "LC/UPC ↔ LC/UPC : "
<< (mgr.validate_adapter_compatibility(lc_upc_a, lc_upc_b) ? "兼容" : "不兼容")
<< "\n";
std::cout << "LC/UPC ↔ SC/UPC : "
<< (mgr.validate_adapter_compatibility(lc_upc_a, sc_upc) ? "兼容" : "不兼容")
<< "\n\n";
// =========================================================
// 7. 标签打印
// =========================================================
std::cout << "=== 标签打印 ===\n";
std::cout << mgr.print_label("DC01-RF02-CB03-SU04-SL05-P01-24") << "\n";
// =========================================================
// 8. 里程碑排期导出
// =========================================================
std::cout << "=== 里程碑排期 ===\n";
std::cout << mgr.export_milestone_schedule() << "\n";
std::cout << "程序运行完毕。\n";
return EXIT_SUCCESS;
}

162
tests/basic_test.cpp Normal file
View File

@ -0,0 +1,162 @@
#include "app.hpp"
#include <cassert>
#include <iostream>
#include <string>
/**
* @brief ODF Manager (使 assert)
*
*
*/
static void test_naming_code_generation() {
ODFManager mgr;
std::string code = mgr.generate_naming_code("DC01", "RF02", "SL05");
// 编码格式应为 "DC01-RF02-SL05"
assert(code == "DC01-RF02-SL05");
assert(code.size() <= 64);
std::cout << "[PASS] test_naming_code_generation\n";
}
static void test_naming_code_uniqueness() {
ODFManager mgr;
ODFUnitInfo u1;
u1.unit_id = "SITE-A-01";
u1.max_capacity_cores = 144;
mgr.register_unit(u1);
// 当编码与已注册 ID 冲突时,应追加后缀避免重复
std::string code = mgr.generate_naming_code("SITE", "A", "01");
// 由于冲突code 会包含时间戳后缀,不应等于 "SITE-A-01"
assert(code != "SITE-A-01");
assert(code.size() <= 64);
std::cout << "[PASS] test_naming_code_uniqueness\n";
}
static void test_adapter_compatibility() {
ODFManager mgr;
AdapterSpec lc_upc;
lc_upc.interface_type = ConnectorType::LC;
lc_upc.polish_type = PolishType::UPC;
AdapterSpec lc_apc;
lc_apc.interface_type = ConnectorType::LC;
lc_apc.polish_type = PolishType::APC;
AdapterSpec sc_upc;
sc_upc.interface_type = ConnectorType::SC;
sc_upc.polish_type = PolishType::UPC;
// 同类型兼容
assert(mgr.validate_adapter_compatibility(lc_upc, lc_upc) == true);
// LC ↔ LCUPC ↔ APC 物理兼容
assert(mgr.validate_adapter_compatibility(lc_upc, lc_apc) == true);
// LC ↔ SC 不兼容
assert(mgr.validate_adapter_compatibility(lc_upc, sc_upc) == false);
std::cout << "[PASS] test_adapter_compatibility\n";
}
static void test_unit_registration() {
ODFManager mgr;
ODFUnitInfo u;
u.unit_id = "TEST-001";
u.model_name = "ODF-TEST";
u.location = "机房A-01-10U";
u.manufacturer = "TestMfr";
u.production_date = "2025-01-01";
u.max_capacity_cores = 144;
mgr.register_unit(u);
const ODFUnitInfo* found = mgr.find_unit("TEST-001");
assert(found != nullptr);
assert(found->model_name == "ODF-TEST");
assert(found->max_capacity_cores == 144);
// 重复注册应抛出异常
bool threw = false;
try {
mgr.register_unit(u);
} catch (const std::invalid_argument&) {
threw = true;
}
assert(threw);
// 超容量约束
ODFUnitInfo over;
over.unit_id = "OVER-001";
over.max_capacity_cores = 300;
bool threw2 = false;
try {
mgr.register_unit(over);
} catch (const std::invalid_argument&) {
threw2 = true;
}
assert(threw2);
std::cout << "[PASS] test_unit_registration\n";
}
static void test_typical_config() {
ODFManager mgr;
TypicalConfig cfg;
cfg.scene_name = "数据中心LC单模预端接";
cfg.environment = "数据中心";
cfg.port_density_per_u = 48;
mgr.register_typical_config(cfg);
TypicalConfig found = mgr.get_typical_config("数据中心LC单模预端接");
assert(!found.scene_name.empty());
assert(found.port_density_per_u == 48);
// 不存在的场景应返回空
TypicalConfig not_found = mgr.get_typical_config("UNKNOWN_SCENE");
assert(not_found.scene_name.empty());
std::cout << "[PASS] test_typical_config\n";
}
static void test_label_and_milestone() {
ODFManager mgr;
// 标签:不存在的单元
std::string label = mgr.print_label("NONEXIST");
assert(label.find("ERROR") != std::string::npos);
// 里程碑排期:空
std::string empty_schedule = mgr.export_milestone_schedule();
assert(empty_schedule.find("No milestones") != std::string::npos);
// 添加里程碑
Milestone ms;
ms.phase_name = "测试阶段";
ms.start_date = "2025-03-01";
ms.end_date = "2025-03-15";
ms.owner = "Tester";
ms.deliverable = "测试报告";
ms.is_completed = false;
mgr.add_milestone(ms);
assert(mgr.milestones().size() == 1);
std::string schedule = mgr.export_milestone_schedule();
assert(schedule.find("测试阶段") != std::string::npos);
assert(schedule.find("N") != std::string::npos); // 未完成标记
std::cout << "[PASS] test_label_and_milestone\n";
}
int main() {
std::cout << "=== ODF Manager Unit Tests ===\n\n";
test_naming_code_generation();
test_naming_code_uniqueness();
test_adapter_compatibility();
test_unit_registration();
test_typical_config();
test_label_and_milestone();
std::cout << "\nAll " << 6 << " tests PASSED.\n";
return 0;
}