GCC Code Coverage Report


Directory: ./
File: src/MessageItem.cpp
Date: 2024-08-07 15:18:03
Exec Total Coverage
Lines: 37 37 100.0%
Branches: 18 24 75.0%

Line Branch Exec Source
1 /*****************************************************************************
2 *
3 * Copyright (C) 2022 Florian Pose <fp@igh.de>
4 *
5 * This file is part of the QtPdCom library.
6 *
7 * The QtPdCom library is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * The QtPdCom library is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 * License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with the QtPdCom Library. If not, see <http://www.gnu.org/licenses/>.
19 *
20 ****************************************************************************/
21
22 #include "MessageItem.h"
23 #include "MessageImpl.h"
24
25 namespace QtPdCom {
26
27 /****************************************************************************/
28
29 12 bool seqNoLessThan(uint32_t a, uint32_t b)
30 {
31 12 return int32_t(a - b) > 0; // greater seqNos shall be on top of the list
32 }
33
34 /****************************************************************************/
35
36 20 MessageModel::Impl::MessageItem::MessageItem(
37 Message *message,
38 MessageModel::Impl *modelImpl,
39 20 quint64 setTime):
40 message{message},
41 modelImpl{modelImpl},
42 seqNo{0},
43 setTime{setTime},
44 20 resetTime{0}
45 {
46 20 }
47
48 /****************************************************************************/
49
50 38 Message::Type MessageModel::Impl::MessageItem::getType() const
51 {
52 38 return message->getType();
53 }
54
55 /****************************************************************************/
56
57 83 QString MessageModel::Impl::MessageItem::getText(
58 const QString &lang) const
59 {
60 83 return message->getText(lang);
61 }
62
63 /****************************************************************************/
64
65 37 QString MessageModel::Impl::MessageItem::getDescription(
66 const QString &lang) const
67 {
68 37 return message->getDescription(lang);
69 }
70
71 /****************************************************************************/
72
73 30 QString MessageModel::Impl::MessageItem::getTimeString() const
74 {
75 30 return message->impl->timeString(setTime);
76 }
77
78 /****************************************************************************/
79
80 12 QString MessageModel::Impl::MessageItem::getResetTimeString() const
81 {
82
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 5 times.
12 if (resetTime) {
83 7 return message->impl->timeString(resetTime);
84 }
85 else {
86 5 return QString();
87 }
88 }
89
90 /****************************************************************************/
91
92 63 bool MessageModel::Impl::MessageItem::isActive() const
93 {
94 63 return resetTime == 0;
95 }
96
97 /****************************************************************************/
98
99 9 bool MessageModel::Impl::MessageItem::seqNoLessThan(const MessageItem *a,
100 const MessageItem *b)
101 {
102 9 return QtPdCom::seqNoLessThan(a->seqNo, b->seqNo);
103 }
104
105 /****************************************************************************/
106
107 1 bool MessageModel::Impl::MessageItem::setTimeLessThan(const MessageItem *a,
108 const MessageItem *b)
109 {
110 1 qint64 diff = a->setTime - b->setTime;
111 return diff > 0
112
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
1 or (!diff and seqNoLessThan(a, b));
113 }
114
115 /****************************************************************************/
116
117 22 bool MessageModel::Impl::MessageItem::levelNoLessThan(
118 const MessageModel::Impl::MessageItem *a, const MessageItem *b)
119 {
120 22 bool aIsReset = a->resetTime;
121 22 bool bIsReset = b->resetTime;
122
123 /* sorting rules:
124 *
125 * - if a message is reset, it should be displayed below all active
126 * messages.
127 * - among reset messages, the sorting should happen just accorting the
128 * time (and sequence number, if time is equal), so ignoring the type
129 * for reset messages.
130 * - for active messages, those with more critical types shall be
131 * displayed on top of the list, thus the set time shall be as ordering
132 * citerion for active messages with the same type.
133 */
134
135
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 6 times.
33 bool ret = (!aIsReset and !bIsReset
136
2/2
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 3 times.
5 and (a->getType() > b->getType() // critical types on top
137
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
2 or (a->getType() == b->getType()
138
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 and setTimeLessThan(a, b))))
139
4/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 3 times.
52 or (bIsReset
140
4/4
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 6 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 7 times.
37 and (!aIsReset or seqNoLessThan(a, b)));
141 22 return ret;
142 }
143
144 /****************************************************************************/
145
146 10 bool MessageModel::Impl::MessageItem::lessThan(const MessageItem *a,
147 const MessageItem *b)
148 {
149 10 return a->modelImpl->lessThan(a, b);
150 }
151
152 /****************************************************************************/
153
154 } // namespace
155
156 /****************************************************************************/
157