GCC Code Coverage Report


Directory: Svc/FileDownlink/
File: File.cpp
Date: 2026-09-03 21:17:43
Exec Total Coverage
Lines: 26 33 78.8%
Functions: 2 2 100.0%
Branches: 18 25 72.0%

Line Branch Exec Source
1 // ======================================================================
2 // \title File.cpp
3 // \author bocchino
4 // \brief cpp file for FileDownlink::File
5 //
6 // \copyright
7 // Copyright 2009-2015, by the California Institute of Technology.
8 // ALL RIGHTS RESERVED. United States Government Sponsorship
9 // acknowledged.
10 //
11 // ======================================================================
12
13 #include <Fw/FPrimeBasicTypes.hpp>
14 #include <Fw/Types/Assert.hpp>
15 #include <Svc/FileDownlink/FileDownlink.hpp>
16
17 namespace Svc {
18
19 8 Os::File::Status FileDownlink::File ::open(const Fw::FileNameString& sourceFileName,
20 const Fw::FileNameString& destFileName) {
21 // Set source name
22
1/1
✓ Branch 5 taken 8 times.
8 Fw::LogStringArg sourceLogStringArg(sourceFileName);
23
1/1
✓ Branch 5 taken 8 times.
8 this->m_sourceName = sourceLogStringArg;
24
25 // Set dest name
26
1/1
✓ Branch 5 taken 8 times.
8 Fw::LogStringArg destLogStringArg(destFileName);
27
1/1
✓ Branch 6 taken 8 times.
8 this->m_destName = destLogStringArg;
28
29 // Initialize checksum
30
1/1
✓ Branch 2 taken 8 times.
8 CFDP::Checksum checksum;
31
1/1
✓ Branch 4 taken 8 times.
8 this->m_checksum = checksum;
32
33 // Open osFile for reading (sandbox path validation happens here)
34
1/1
✓ Branch 8 taken 8 times.
8 Os::File::Status status = this->m_osFile.open(sourceFileName.toChar(), Os::File::OPEN_READ);
35
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
8 if (status != Os::File::OP_OK) {
36 2 return status;
37 }
38
39 // Query size only after the path passes sandbox checks
40 6 FwSizeType file_size;
41
1/1
✓ Branch 4 taken 6 times.
6 status = this->m_osFile.size(file_size);
42
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (status != Os::File::OP_OK) {
43 this->m_osFile.close();
44 return Os::File::BAD_SIZE;
45 }
46 // If the size does not cast cleanly to the desired U32 type, return size error
47
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (static_cast<FwSizeType>(static_cast<U32>(file_size)) != file_size) {
48 this->m_osFile.close();
49 return Os::File::BAD_SIZE;
50 }
51 6 this->m_size = static_cast<U32>(file_size);
52 6 return Os::File::OP_OK;
53 8 }
54
55 4 Os::File::Status FileDownlink::File ::read(U8* const data, const U32 byteOffset, const U32 size) {
56 Os::File::Status status;
57
1/1
✓ Branch 4 taken 4 times.
4 status = this->m_osFile.seek(byteOffset, Os::File::SeekType::ABSOLUTE);
58
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (status != Os::File::OP_OK) {
59 return status;
60 }
61
62 4 FwSizeType intSize = size;
63
1/1
✓ Branch 4 taken 4 times.
4 status = this->m_osFile.read(data, intSize);
64
65
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (status != Os::File::OP_OK) {
66 return status;
67 }
68 // Force a bad size error when the U32 carrying size is bad
69
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (static_cast<U32>(intSize) != size) {
70 return Os::File::BAD_SIZE;
71 }
72
1/1
✓ Branch 4 taken 4 times.
4 this->m_checksum.update(data, byteOffset, size);
73
74 4 return Os::File::OP_OK;
75 }
76 } // namespace Svc
77