Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
flatbuffers
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
flatbuffers
Commits
14e7e826
Commit
14e7e826
authored
Jul 14, 2016
by
Wouter van Oortmerssen
Committed by
GitHub
Jul 14, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3939 from TGIshib/hex-bug
Fixed bug with negative hex constants (2).
parents
7a3f1cf7
0d562761
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
5 deletions
+14
-5
idl_parser.cpp
src/idl_parser.cpp
+6
-0
test.cpp
tests/test.cpp
+8
-5
No files found.
src/idl_parser.cpp
View file @
14e7e826
...
...
@@ -423,6 +423,12 @@ CheckedError Parser::Next() {
return
NoError
();
}
else
if
(
isdigit
(
static_cast
<
unsigned
char
>
(
c
))
||
c
==
'-'
)
{
const
char
*
start
=
cursor_
-
1
;
if
(
c
==
'-'
&&
*
cursor_
==
'0'
&&
(
cursor_
[
1
]
==
'x'
||
cursor_
[
1
]
==
'X'
))
{
++
start
;
++
cursor_
;
attribute_
.
append
(
&
c
,
&
c
+
1
);
c
=
'0'
;
}
if
(
c
==
'0'
&&
(
*
cursor_
==
'x'
||
*
cursor_
==
'X'
))
{
cursor_
++
;
while
(
isxdigit
(
static_cast
<
unsigned
char
>
(
*
cursor_
)))
cursor_
++
;
...
...
tests/test.cpp
View file @
14e7e826
...
...
@@ -814,14 +814,14 @@ void ErrorTest() {
TestError
(
"table X { Y:byte; } root_type X; { Y:1, Y:2 }"
,
"more than once"
);
}
float
TestValue
(
const
char
*
json
)
{
template
<
typename
T
>
T
TestValue
(
const
char
*
json
,
const
char
*
type_name
)
{
flatbuffers
::
Parser
parser
;
// Simple schema.
TEST_EQ
(
parser
.
Parse
(
"table X { Y:float; } root_type X;"
),
true
);
TEST_EQ
(
parser
.
Parse
(
std
::
string
(
"table X { Y:"
+
std
::
string
(
type_name
)
+
"; } root_type X;"
).
c_str
()
),
true
);
TEST_EQ
(
parser
.
Parse
(
json
),
true
);
auto
root
=
flatbuffers
::
GetRoot
<
float
>
(
parser
.
builder_
.
GetBufferPointer
());
auto
root
=
flatbuffers
::
GetRoot
<
T
>
(
parser
.
builder_
.
GetBufferPointer
());
// root will point to the table, which is a 32bit vtable offset followed
// by a float:
TEST_EQ
(
sizeof
(
flatbuffers
::
soffset_t
),
4
);
// Test assumes 32bit offsets
...
...
@@ -833,10 +833,13 @@ bool FloatCompare(float a, float b) { return fabs(a - b) < 0.001; }
// Additional parser testing not covered elsewhere.
void
ValueTest
()
{
// Test scientific notation numbers.
TEST_EQ
(
FloatCompare
(
TestValue
(
"{ Y:0.0314159e+2 }"
),
3.14159
),
true
);
TEST_EQ
(
FloatCompare
(
TestValue
<
float
>
(
"{ Y:0.0314159e+2 }"
,
"float"
),
(
float
)
3.14159
),
true
);
// Test conversion functions.
TEST_EQ
(
FloatCompare
(
TestValue
(
"{ Y:cos(rad(180)) }"
),
-
1
),
true
);
TEST_EQ
(
FloatCompare
(
TestValue
<
float
>
(
"{ Y:cos(rad(180)) }"
,
"float"
),
-
1
),
true
);
// Test negative hex constant.
TEST_EQ
(
TestValue
<
int
>
(
"{ Y:-0x80 }"
,
"int"
)
==
-
128
,
true
);
}
void
EnumStringsTest
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment