Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ obj-x86_64-linux-gnu/
.cursor/
.cache/
.claude/
tests/coverage.info
7 changes: 7 additions & 0 deletions tests/app/ut_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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("");
}
61 changes: 61 additions & 0 deletions tests/exclude_unreachable.py
Original file line number Diff line number Diff line change
@@ -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]} <input.info> <output.info>", 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()
3 changes: 3 additions & 0 deletions tests/test-prj-running.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading