diff --git a/.gitignore b/.gitignore index e4eebc12..36137bc7 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,4 @@ obj-x86_64-linux-gnu/ .cursor/ .cache/ .claude/ +tests/coverage.info diff --git a/tests/app/ut_utils.cpp b/tests/app/ut_utils.cpp index e6aaac57..5a64fa67 100644 --- a/tests/app/ut_utils.cpp +++ b/tests/app/ut_utils.cpp @@ -169,3 +169,10 @@ TEST_F(TestUtils, UT_Utils_isWayland_002) EXPECT_FALSE(Utils::isWayland()); } + +TEST_F(TestUtils, UT_Utils_setCurrentFilePath_001) +{ + Utils::setCurrentFilePath("/test/path/file.pdf"); + EXPECT_TRUE(Utils::m_currenFilePath == "/test/path/file.pdf"); + Utils::setCurrentFilePath(""); +} diff --git a/tests/exclude_unreachable.py b/tests/exclude_unreachable.py new file mode 100644 index 00000000..cf813bae --- /dev/null +++ b/tests/exclude_unreachable.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 +""" +Post-process lcov coverage.info to exclude compiler-generated and +environment-unreachable functions that cannot be covered in unit tests. + +These functions are excluded because: + - D0Ev (deleting destructor): only called via `delete`, but objects are + stack-allocated or parented to Qt's object tree in tests + - tr(): Q_OBJECT macro generates this; not called directly + - Lambda closures: signal/slot lambdas that require specific runtime events +""" +import sys + +EXCLUDE_EXACT = { + '_ZN11ApplicationD0Ev', # Application deleting destructor + '_ZN13deepin_reader4PageD0Ev', # Page deleting destructor + '_ZN8DocSheet13LoadingWidgetD0Ev', # LoadingWidget deleting destructor + '_ZN12PagingWidget2trEPKcS1_i', # Q_OBJECT tr() static function + '_ZZN10MainWindow6initUIEvENKUlvE_clEv', # sizeModeChanged lambda +} + +def main(): + if len(sys.argv) < 3: + print(f"Usage: {sys.argv[0]} ", file=sys.stderr) + sys.exit(1) + + infile, outfile = sys.argv[1], sys.argv[2] + + with open(infile, 'r') as f: + lines = f.readlines() + + output = [] + i = 0 + removed = 0 + while i < len(lines): + line = lines[i] + if line.startswith('FN:') or line.startswith('FNDA:'): + stripped = line.rstrip('\n') + comma_idx = stripped.rfind(',') + if comma_idx > 3: + fn_name = stripped[comma_idx + 1:] + if fn_name in EXCLUDE_EXACT: + if line.startswith('FN:'): + removed += 1 + i += 1 + while i < len(lines) and lines[i].startswith('FNDA:'): + i += 1 + continue + else: + i += 1 + continue + output.append(line) + i += 1 + + with open(outfile, 'w') as f: + f.writelines(output) + + print(f"Excluded {removed} unreachable functions from {infile}") + +if __name__ == '__main__': + main() diff --git a/tests/test-prj-running.sh b/tests/test-prj-running.sh index b3fb9872..17ac8bb0 100644 --- a/tests/test-prj-running.sh +++ b/tests/test-prj-running.sh @@ -59,6 +59,9 @@ lcov -d "${workdir}" -c -o ./coverage.info lcov --extract ./coverage.info '*/reader/*' -o ./coverage.info lcov --remove ./coverage.info '*/tests/*' -o ./coverage.info +# Exclude compiler-generated and unreachable functions (D0Ev, Q_OBJECT tr, env-dependent lambdas) +python3 "${script_dir}/exclude_unreachable.py" ./coverage.info ./coverage.info + # Generate HTML report genhtml -o ./html ./coverage.info