A52 (IGES face orientation closure, importer/exporter symmetric): - importer: apply_shell_orientation derives face.reversed = (514 ORIENTATION==0) XOR (186 SHELLFLAG==0); token_is_pure_int guards legacy "0HNAME"; convert_face reads 510 OUTERLOOPFLAG, convert_loop reads 508 ORIENTATION (diagnostics only); empty/void shells use their own SHELLFLAG - exporter: 514 writes per-face ORIENTATION (0 when reversed), 510 OUTERLOOPFLAG=1, 508 ORIENTATION from edge.reversed; 144 counts reversed trimmed faces only (no orientation field); 186 keeps "1,0" - test_iges_export 34 -> 43 tests (T1-T8, real corpus round-trips): occ__bug25415 vol_rel 0.9697 -> 8.30e-12, occ__bug22821_test 2.0 -> 0, PWB/31000/28366 stay ~0 A53 (IGES import zero-copy caches): - curve_cache_/surface_cache_ become unordered_map<int, shared_ptr<const NurbsCurve/NurbsSurface>>; hits share pointers, misses make_shared<const T>(std::move(...)); composite curves return pointers - split_params/params_of return std::string_view (zero-copy token slicing; tokens are substrings) - import_iges reads the file in one sized binary read (chunked fallback for >16GB or tellg failure) - V8 Motor_1.igs 3.40 -> 1.346 s, moteur_v8_asm.igs 9.27 -> 3.284 s; topology/model hashes unchanged A54/A55 (UTF-8 path leftovers): - A54: 13 foundation files, 17 open sites -> open_ifstream_utf8/open_ofstream_utf8; 9 UTF-8 cases - A55: 13 infra/plugin/capi/core files, 24+ sites (11 user-path sites in plugin_manager); 12 UTF-8 cases - Linux-only fixed paths (/sys,/proc,/etc/machine-id) and platform.cpp fopen wrapper intentionally kept Verification: 23 suites 918 passed / 0 failed; PR gate 1067/1067 (81.44 s); four KPI windows bit-identical (fixed 196/36, auto 196/36, band 8/0 and 8/0); 35 extra suites green; redline identical.
143 lines
5.2 KiB
C++
143 lines
5.2 KiB
C++
#include <gtest/gtest.h>
|
||
#include "vde/foundation/vde_log.h"
|
||
#include "vde/foundation/utf8_path.h"
|
||
|
||
#include <filesystem>
|
||
#include <fstream>
|
||
#include <iterator>
|
||
#include <sstream>
|
||
#include <string>
|
||
|
||
using namespace vde::foundation;
|
||
|
||
// ═══════════════════════════════════════════════════════════
|
||
// D10: vde_log — 结构化日志模块测试
|
||
// ═══════════════════════════════════════════════════════════
|
||
|
||
TEST(VdeLogTest, LevelLabels) {
|
||
EXPECT_STREQ(log_level_label(LogLevel::Trace), "T");
|
||
EXPECT_STREQ(log_level_label(LogLevel::Info), "I");
|
||
EXPECT_STREQ(log_level_label(LogLevel::Error), "E");
|
||
EXPECT_STREQ(log_level_name(LogLevel::Critical), "CRITICAL");
|
||
}
|
||
|
||
TEST(VdeLogTest, LevelFromString) {
|
||
EXPECT_EQ(log_level_from_string("INFO"), LogLevel::Info);
|
||
EXPECT_EQ(log_level_from_string("warning"), LogLevel::Warn);
|
||
EXPECT_EQ(log_level_from_string("ERROR"), LogLevel::Error);
|
||
EXPECT_EQ(log_level_from_string("nonsense"), LogLevel::Info);
|
||
}
|
||
|
||
TEST(VdeLogTest, LevelFiltering) {
|
||
std::ostringstream oss;
|
||
vde_log::set_output(&oss);
|
||
vde_log::set_level(LogLevel::Warn);
|
||
|
||
vde_log::info("test", "evt", "should be filtered");
|
||
EXPECT_TRUE(oss.str().empty()) << "Info 级别在 Warn 过滤下不应输出";
|
||
|
||
vde_log::warn("test", "evt", "visible warning");
|
||
EXPECT_FALSE(oss.str().empty());
|
||
|
||
// 恢复默认
|
||
vde_log::set_output(nullptr);
|
||
vde_log::set_level(LogLevel::Info);
|
||
}
|
||
|
||
TEST(VdeLogTest, StructuredFields) {
|
||
std::ostringstream oss;
|
||
vde_log::set_output(&oss);
|
||
vde_log::set_level(LogLevel::Trace);
|
||
|
||
vde_log::info("brep", "boolean_union",
|
||
"union completed",
|
||
vde_log::field("faces_a", 12),
|
||
vde_log::field("faces_b", 8),
|
||
vde_log::field("time_ms", 3.5),
|
||
vde_log::field("ok", true));
|
||
|
||
std::string out = oss.str();
|
||
EXPECT_NE(out.find("boolean_union"), std::string::npos);
|
||
EXPECT_NE(out.find("faces_a=12"), std::string::npos);
|
||
EXPECT_NE(out.find("faces_b=8"), std::string::npos);
|
||
EXPECT_NE(out.find("ok=true"), std::string::npos);
|
||
|
||
vde_log::set_output(nullptr);
|
||
vde_log::set_level(LogLevel::Info);
|
||
}
|
||
|
||
TEST(VdeLogTest, SinkCallback) {
|
||
int count = 0;
|
||
std::string last_module;
|
||
vde_log::set_sink([&](const LogMessage& m) {
|
||
++count;
|
||
last_module = m.module;
|
||
});
|
||
|
||
vde_log::error("step", "import", "failed", vde_log::field("code", 1301));
|
||
EXPECT_EQ(count, 1);
|
||
EXPECT_EQ(last_module, "step");
|
||
|
||
vde_log::set_sink(nullptr);
|
||
}
|
||
|
||
TEST(VdeLogTest, MessageFormat) {
|
||
LogMessage msg;
|
||
msg.level = LogLevel::Error;
|
||
msg.module = "curves";
|
||
msg.event = "eval";
|
||
msg.message = "boom";
|
||
msg.timestamp_us = 1000000; // 1970-01-01 00:00:01 UTC
|
||
msg.fields = {{"t", "0.5"}};
|
||
|
||
std::string s = msg.to_string();
|
||
EXPECT_NE(s.find("E"), std::string::npos);
|
||
EXPECT_NE(s.find("curves"), std::string::npos);
|
||
EXPECT_NE(s.find("eval"), std::string::npos);
|
||
EXPECT_NE(s.find("boom"), std::string::npos);
|
||
EXPECT_NE(s.find("t=0.5"), std::string::npos);
|
||
}
|
||
|
||
TEST(VdeLogTest, LevelOffDisablesAll) {
|
||
std::ostringstream oss;
|
||
vde_log::set_output(&oss);
|
||
vde_log::set_level(LogLevel::Off);
|
||
|
||
vde_log::critical("x", "y", "should be silent");
|
||
EXPECT_TRUE(oss.str().empty());
|
||
|
||
vde_log::set_output(nullptr);
|
||
vde_log::set_level(LogLevel::Info);
|
||
}
|
||
|
||
// ═══════════════════════════════════════════════════════════
|
||
// Wave21 A54:UTF-8(中文/非 ASCII)日志文件路径
|
||
// ═══════════════════════════════════════════════════════════
|
||
TEST(VdeLogUtf8Path, SetOutputFileUtf8Path) {
|
||
const std::string path = std::string(VDE_TEST_TEMP_DIR) + "test_vde_log_日志_①.log";
|
||
std::error_code ec;
|
||
std::filesystem::remove(path_from_utf8(path), ec);
|
||
|
||
vde_log::set_output(nullptr);
|
||
vde_log::set_level(LogLevel::Info);
|
||
ASSERT_TRUE(vde_log::set_output_file(path));
|
||
EXPECT_TRUE(std::filesystem::exists(path_from_utf8(path)));
|
||
|
||
// Error 级别会立即 flush(vde_log.cpp:155),随后即可从磁盘读回。
|
||
vde_log::error("utf8", "path", "UTF8_MARKER 中文日志");
|
||
{
|
||
std::ifstream in = open_ifstream_utf8(path);
|
||
ASSERT_TRUE(static_cast<bool>(in));
|
||
const std::string text((std::istreambuf_iterator<char>(in)),
|
||
std::istreambuf_iterator<char>());
|
||
EXPECT_NE(text.find("UTF8_MARKER"), std::string::npos) << text;
|
||
EXPECT_NE(text.find("中文日志"), std::string::npos) << text;
|
||
}
|
||
|
||
// 无公开 close API:用 NUL 设备替换输出以关闭旧句柄,再恢复默认。
|
||
vde_log::set_output_file("NUL");
|
||
vde_log::set_output(nullptr);
|
||
vde_log::set_level(LogLevel::Info);
|
||
std::filesystem::remove(path_from_utf8(path), ec);
|
||
}
|