GCC Code Coverage Report


Directory: src/gate/
File: src/gate/cxx_objects.cpp
Date: 2025-12-12 23:40:09
Exec Total Coverage
Lines: 96 105 91.4%
Functions: 28 29 96.6%
Branches: 16 32 50.0%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright(c) 2018-2025, Stefan Meislinger <sm@opengate.at> |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met:|
8 | |
9 | 1. Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | THE POSSIBILITY OF SUCH DAMAGE. |
26 +----------------------------------------------------------------------------+
27 */
28 #include "gate/objects.hpp"
29
30 #include "gate/exceptions.hpp"
31 #include "gate/results.hpp"
32
33 namespace gate
34 {
35
36 231 Object::Object(gate_object_ptr_t obj_ptr) noexcept
37 231 : object_ref_ptr(obj_ptr)
38 {
39
40 231 }
41 30 Object::Object(Object const& obj) noexcept
42 30 : object_ref_ptr(obj.object_ref_ptr)
43 {
44
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if (this->object_ref_ptr != NULL)
45 {
46 30 gate_object_retain(this->object_ref_ptr);
47 }
48 30 }
49 29 Object& Object::operator=(Object const& that) noexcept
50 {
51
1/2
✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
29 if (this != &that)
52 {
53
1/2
✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
29 if (that.object_ref_ptr != NULL)
54 {
55 29 gate_object_retain(that.object_ref_ptr);
56 }
57
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 2 times.
29 if (this->object_ref_ptr != NULL)
58 {
59 27 gate_object_release(this->object_ref_ptr);
60 }
61 29 this->object_ref_ptr = that.object_ref_ptr;
62 }
63 29 return *this;
64 }
65 522 Object::~Object() noexcept
66 {
67
2/2
✓ Branch 0 taken 260 times.
✓ Branch 1 taken 1 times.
261 if (this->object_ref_ptr != NULL)
68 {
69 260 gate_object_release(this->object_ref_ptr);
70 }
71 261 }
72
73 14 String Object::getInterfaceName()
74 {
75 14 char const* name = NULL;
76
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if (this->object_ref_ptr == NULL)
77 {
78 GATEXX_RAISE_ERROR(results::NullPointer);
79 }
80 else
81 {
82 14 name = gate_object_get_interface_name(this->object_ref_ptr);
83 }
84 14 return String::createStatic(name);
85 }
86
87 3 bool_t Object::implementsInterface(char const* ifaceName)
88 {
89 3 return gate_object_implements_interface(this->object_ref_ptr, ifaceName);
90 }
91
92
93 gate_object_t* Object::c_impl() noexcept
94 {
95 return this->object_ref_ptr;
96 }
97
98 1 bool_t Object::operator!() const noexcept
99 {
100 1 return this->empty();
101 }
102 11 bool_t Object::empty() const noexcept
103 {
104 11 return this->object_ref_ptr == NULL;
105 }
106
107
108
109 5 void Object::swap(Object& that) noexcept
110 {
111 5 gate::swapRefs(this->object_ref_ptr, that.object_ref_ptr);
112 5 }
113
114
115
116
117 24 IObject::~IObject()
118 {
119 24 }
120
121
122
123
124 3 Startable::Startable(gate_startable_t* obj)
125 3 : object_impl_t(obj)
126 {
127 3 }
128 1 Startable::Startable(Startable const& src)
129 1 : object_impl_t(src)
130 {
131 1 }
132
133 1 Startable& Startable::operator=(Startable const& src)
134 {
135 1 object_impl_t::operator=(src);
136 1 return *this;
137 }
138
139 2 void Startable::start()
140 {
141 2 result_t result = gate_startable_start(this->impl_ptr);
142
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATEXX_CHECK_EXCEPTION(result);
143 2 }
144 2 void Startable::stop()
145 {
146 2 result_t result = gate_startable_stop(this->impl_ptr);
147
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATEXX_CHECK_EXCEPTION(result);
148 2 }
149 3 enumint_t Startable::getStatus()
150 {
151 3 gate_enumint_t status = gate_startable_get_status(this->impl_ptr);
152 3 return status;
153 }
154
155
156
157
158
159 1 MemoryBlock::MemoryBlock(size_t blockLength)
160 1 : object_impl_t(gate_memoryblock_create(blockLength))
161 {
162
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (!this->c_impl())
163 {
164 GATEXX_RAISE_ERROR(results::OutOfMemory);
165 }
166 1 }
167
168 3 MemoryBlock::MemoryBlock(void const* sourceBlockBytes, size_t blockLength)
169 3 : object_impl_t(gate_memoryblock_create(blockLength))
170 {
171
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
3 if (!this->c_impl())
172 {
173 GATEXX_RAISE_ERROR(results::OutOfMemory);
174 }
175
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 void* ptrContent = this->getContent();
176 3 Mem::copy(ptrContent, sourceBlockBytes, blockLength);
177 3 }
178
179 1 MemoryBlock::MemoryBlock(gate_memoryblock_t* obj)
180 1 : object_impl_t(obj)
181 {
182 1 }
183 4 MemoryBlock::MemoryBlock(MemoryBlock const& src)
184 4 : object_impl_t(src)
185 {
186 4 }
187 1 MemoryBlock& MemoryBlock::operator=(MemoryBlock const& src)
188 {
189 1 object_impl_t::operator=(src);
190 1 return *this;
191 }
192
193 6 size_t MemoryBlock::getSize() const
194 {
195 6 return gate_memoryblock_get_size(this->c_impl());
196 }
197 4 void* MemoryBlock::getContent()
198 {
199 4 return gate_memoryblock_get_content(this->c_impl());
200 }
201 5 void const* MemoryBlock::getContent() const
202 {
203 5 return gate_memoryblock_get_content(this->c_impl());
204 }
205 4 intptr_t MemoryBlock::compare(void const* block, size_t blockLength) const
206 {
207 4 void const* thisContent = this->getContent();
208 4 size_t size = this->getSize();
209 4 intptr_t ret = 0;
210
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (size < blockLength)
211 {
212 ret = -1;
213 }
214
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 else if (size > blockLength)
215 {
216 size = blockLength;
217 ret = 1;
218 }
219 4 intptr_t compareResult = Mem::compare(thisContent, block, size);
220
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (compareResult != 0)
221 {
222 ret = compareResult;
223 }
224 4 return ret;
225 }
226 1 intptr_t MemoryBlock::compare(MemoryBlock const& block) const
227 {
228 1 return this->compare(block.getContent(), block.getSize());
229 }
230
231 1 bool MemoryBlock::equals(MemoryBlock const& block) const
232 {
233 1 return this->compare(block) == 0;
234 }
235 3 bool MemoryBlock::equals(void const* block, size_t blockLength) const
236 {
237 3 return this->compare(block, blockLength) == 0;
238 }
239
240 } // end of namespace gate
241