GCC Code Coverage Report


Directory: src/gate/
File: src/gate/cxx_console.cpp
Date: 2025-09-14 13:10:38
Exec Total Coverage
Lines: 59 72 81.9%
Functions: 13 15 86.7%
Branches: 20 54 37.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
29 #include "gate/console.hpp"
30
31 namespace gate
32 {
33
34
35 uint32_t const ConsoleStream::TimeoutNever = GATE_CONSOLE_TIMEOUT_NEVER;
36
37
38 ConsoleStream::ConsoleStream()
39 : Stream((gate_stream_t*)gate_console()),
40 conimpl(NULL)
41 {
42 this->init(gate_console());
43 }
44
45 8 ConsoleStream::ConsoleStream(gate_console_t* strm)
46 : Stream((gate_stream_t*)strm),
47 8 conimpl(NULL)
48 {
49
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 this->init(strm);
50 8 }
51 8 ConsoleStream::~ConsoleStream() noexcept
52 {
53 8 }
54
55 8 void ConsoleStream::init(gate_console_t* strm)
56 {
57
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 Stream stream((gate_stream_t*)strm);
58 8 Stream::operator=(stream);
59 8 this->conimpl = strm;
60 8 }
61
62 3 uintptr_t ConsoleStream::getResource(enumint_t type)
63 {
64 3 uintptr_t ret = 0;
65
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 result_t result = gate_stream_get_resource(this->conimpl, type, &ret);
66
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
3 GATEXX_CHECK_ERROR(result);
67 3 return ret;
68 }
69
70 1 bool ConsoleStream::awaitChar(uint32_t timeout)
71 {
72 1 result_t result = gate_console_await_char(this->conimpl, timeout);
73
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (GATE_RESULT_TIMEOUT == result)
74 {
75 return false;
76 }
77
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_ERROR(result);
78 1 return true;
79 }
80
81 void ConsoleStream::readChar(char_32_t& chr)
82 {
83 result_t result = gate_console_read_char(this->conimpl, &chr);
84 GATEXX_CHECK_ERROR(result);
85 }
86
87 1 bool ConsoleStream::readChar(char_32_t& chr, uint32_t timeoutMS)
88 {
89 1 result_t result = gate_console_timed_read_char(this->conimpl, timeoutMS, &chr);
90
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (GATE_RESULT_TIMEOUT == result)
91 {
92 return false;
93 }
94
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_ERROR(result);
95 1 return true;
96 }
97 1 bool ConsoleStream::readKey(gate_input_keycode_t& keyCode, char_32_t& chr, uint32_t timeoutMS, char* ptrBuffer, size_t& bufferLen)
98 {
99 1 result_t result = gate_console_read_key(this->conimpl, timeoutMS, &keyCode, &chr, ptrBuffer, &bufferLen);
100
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (GATE_RESULT_TIMEOUT == result)
101 {
102 return false;
103 }
104
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_ERROR(result);
105 1 return true;
106 }
107
108
109 2 size_t ConsoleStream::writeErr(char const* buffer, size_t bufferlen)
110 {
111 2 size_t ret = 0;
112
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 result_t result = this->conimpl->vtbl->write_err(this->conimpl, buffer, bufferlen, &ret);
113
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
2 GATEXX_CHECK_ERROR(result);
114 2 return ret;
115 }
116 1 size_t ConsoleStream::writeErr(String const& text)
117 {
118 1 return writeErr(text.c_str(), text.length());
119 }
120
121 1 void ConsoleStream::flushErr()
122 {
123 1 result_t result = this->conimpl->vtbl->flush_err(this->conimpl);
124
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_ERROR(result);
125 1 }
126
127 1 String ConsoleStream::readLine()
128 {
129 1 gate_string_t str_line = GATE_STRING_INIT_EMPTY;
130
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 gate_result_t res = gate_console_readln(this->conimpl, &str_line);
131
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 GATEXX_CHECK_ERROR(res);
132 2 return String::createFrom(str_line);
133 }
134
135 1 bool ConsoleStream::readLineRaw(String& line, uint32_t charTimeout)
136 {
137 1 gate_string_t str_line = GATE_STRING_INIT_EMPTY;
138
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 gate_result_t res = gate_console_readln_raw(this->conimpl, &str_line, charTimeout);
139
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (GATE_RESULT_TIMEOUT == res)
140 {
141 return false;
142 }
143
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 GATEXX_CHECK_ERROR(res);
144 1 line = String::createFrom(str_line);
145
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 gate_string_release(&str_line);
146 1 return true;
147 }
148
149 1 ConsoleStream& ConsoleStream::operator>>(String& line)
150 {
151
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 String tmp = this->readLine();
152 1 line.swap(tmp);
153 2 return *this;
154 }
155
156 ConsoleStream Console((gate_console()));
157 Stream ConError((gate_console_error_stream()));
158
159 } // end of namespace gate
160