Hoyt's FORK of DemoIccMAX
2.1.17.hoyt
Documentation for Hoyt's FORK of DemoIccMAX
Loading...
Searching...
No Matches
TestParseText.cpp
Go to the documentation of this file.
1
/**
2
* @file TestParseText.cpp
3
* @brief Unit Test for ParseText()
4
* @author @h02332 | David Hoyt | @xsscx
5
* @date 24 MAY 2024
6
* @version 1.0.2
7
*
8
* This program is free software: you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation, either version 3 of the License, or
11
* (at your option) any later version.
12
*
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
17
*
18
* You should have received a copy of the GNU General Public License
19
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20
*
21
* Compile: clang++ -std=c++17 -fsanitize=address -isysroot $(xcrun --show-sdk-path) -I$(xcrun --show-sdk-path)/usr/include/c++/v1 TestParseText.cpp -o TestParseText
22
23
*
24
*
25
*/
26
27
#include <iostream>
28
#include <cstring>
29
#include <cmath>
30
31
// Mock the required environment and dependencies
32
typedef
unsigned
int
icUInt32Number
;
33
enum
icTagTypeSignature
{
icSigUInt16ArrayType
= 1969828150 };
34
35
bool
icIsNumChar
(
char
c) {
36
return
(c >=
'0'
&& c <=
'9'
) || c ==
'.'
|| c ==
'-'
|| c ==
'+'
;
37
}
38
39
float
nanf
(
const
char
* tagp) {
40
return
std::nan(
""
);
41
}
42
43
template
<
class
T, icTagTypeSignature Tsig>
44
class
CIccXmlArrayType
{
45
public
:
46
T*
m_pBuf
;
47
icUInt32Number
m_nSize
;
48
49
CIccXmlArrayType
() :
m_pBuf
(nullptr),
m_nSize
(0) {}
50
~CIccXmlArrayType
() {
delete
[]
m_pBuf
; }
51
52
icUInt32Number
ParseText
(T* pBuf,
icUInt32Number
nSize,
const
char
*szText);
53
};
54
55
template
<
class
T, icTagTypeSignature Tsig>
56
icUInt32Number
CIccXmlArrayType<T, Tsig>::ParseText
(T* pBuf,
icUInt32Number
nSize,
const
char
*szText) {
57
icUInt32Number
n = 0;
58
char
num[256] = {0};
59
int
b = 0;
60
bool
bInNum =
false
;
61
62
while
(*szText && n < nSize) {
63
if
(
icIsNumChar
(*szText)) {
64
if
(!bInNum) {
65
bInNum =
true
;
66
b = 0;
67
}
68
if
(b <
sizeof
(num) - 2) {
69
num[b++] = *szText;
70
}
71
}
else
{
72
if
(bInNum) {
73
num[b] =
'\0'
;
74
pBuf[n++] = (T)atof(num);
75
bInNum =
false
;
76
}
77
}
78
szText++;
79
}
80
81
if
(bInNum && n < nSize) {
82
num[b] =
'\0'
;
83
pBuf[n++] = (T)atof(num);
84
}
85
86
return
n;
87
}
88
89
int
main
() {
90
const
char
testInput[] =
"12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
;
91
unsigned
short
buffer[100];
92
CIccXmlArrayType<unsigned short, icSigUInt16ArrayType>
arrayType;
93
94
arrayType.
ParseText
(buffer, 100, testInput);
95
96
std::cout <<
"Test completed successfully.\n"
;
97
return
0;
98
}
99
icIsNumChar
bool icIsNumChar(char c)
Definition
TestParseText.cpp:35
icTagTypeSignature
icTagTypeSignature
Definition
TestParseText.cpp:33
icSigUInt16ArrayType
@ icSigUInt16ArrayType
Definition
TestParseText.cpp:33
nanf
float nanf(const char *tagp)
Definition
TestParseText.cpp:39
icUInt32Number
unsigned int icUInt32Number
Definition
TestParseText.cpp:32
main
int main()
Definition
TestParseText.cpp:89
CIccXmlArrayType
Definition
TestParseText.cpp:44
CIccXmlArrayType::ParseText
icUInt32Number ParseText(T *pBuf, icUInt32Number nSize, const char *szText)
Definition
TestParseText.cpp:56
CIccXmlArrayType::~CIccXmlArrayType
~CIccXmlArrayType()
Definition
TestParseText.cpp:50
CIccXmlArrayType::CIccXmlArrayType
CIccXmlArrayType()
Definition
TestParseText.cpp:49
CIccXmlArrayType::m_pBuf
T * m_pBuf
Definition
TestParseText.cpp:46
CIccXmlArrayType::m_nSize
icUInt32Number m_nSize
Definition
TestParseText.cpp:47
contrib
UnitTest
TestParseText.cpp
Generated on Sun Jun 2 2024 07:45:58 for Hoyt's FORK of DemoIccMAX by
1.11.0