Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
e9b76b89
Commit
e9b76b89
authored
Nov 08, 2021
by
Sergei Krivonos
Committed by
Sergei Krivonos
Nov 09, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-23766: fix by my_json_writer test
parent
5e988ff8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
21 deletions
+19
-21
sql/my_json_writer.cc
sql/my_json_writer.cc
+11
-15
sql/my_json_writer.h
sql/my_json_writer.h
+6
-4
unittest/sql/my_json_writer-t.cc
unittest/sql/my_json_writer-t.cc
+2
-2
No files found.
sql/my_json_writer.cc
View file @
e9b76b89
...
...
@@ -18,7 +18,7 @@
#include "sql_string.h"
#include "my_json_writer.h"
#if
ndef NDEBUG
#if
!defined(NDEBUG) || defined(JSON_WRITER_UNIT_TEST)
bool
Json_writer
::
named_item_expected
()
const
{
return
named_items_expectation
.
size
()
...
...
@@ -36,7 +36,7 @@ void Json_writer::append_indent()
inline
void
Json_writer
::
on_start_object
()
{
#if
ndef NDEBUG
#if
!defined(NDEBUG) || defined(JSON_WRITER_UNIT_TEST)
if
(
!
fmt_helper
.
is_making_writer_calls
())
{
VALIDITY_ASSERT
(
got_name
==
named_item_expected
());
...
...
@@ -58,20 +58,14 @@ void Json_writer::start_object()
first_child
=
true
;
element_started
=
false
;
document_start
=
false
;
#if
ndef NDEBUG
#if
!defined(NDEBUG) || defined(JSON_WRITER_UNIT_TEST)
got_name
=
false
;
#endif
}
bool
Json_writer
::
on_start_array
()
{
bool
helped
=
fmt_helper
.
on_start_array
();
return
helped
;
}
void
Json_writer
::
start_array
()
{
#if
ndef NDEBUG
#if
!defined(NDEBUG) || defined(JSON_WRITER_UNIT_TEST)
if
(
!
fmt_helper
.
is_making_writer_calls
())
{
VALIDITY_ASSERT
(
got_name
==
named_item_expected
());
...
...
@@ -80,7 +74,7 @@ void Json_writer::start_array()
}
#endif
if
(
on_start_array
())
if
(
fmt_helper
.
on_start_array
())
return
;
if
(
!
element_started
)
...
...
@@ -96,7 +90,8 @@ void Json_writer::start_array()
void
Json_writer
::
end_object
()
{
#ifndef NDEBUG
#if !defined(NDEBUG) || defined(JSON_WRITER_UNIT_TEST)
VALIDITY_ASSERT
(
named_item_expected
());
named_items_expectation
.
pop_back
();
VALIDITY_ASSERT
(
!
got_name
);
got_name
=
false
;
...
...
@@ -111,7 +106,8 @@ void Json_writer::end_object()
void
Json_writer
::
end_array
()
{
#ifndef NDEBUG
#if !defined(NDEBUG) || defined(JSON_WRITER_UNIT_TEST)
VALIDITY_ASSERT
(
!
named_item_expected
());
named_items_expectation
.
pop_back
();
got_name
=
false
;
#endif
...
...
@@ -142,7 +138,7 @@ Json_writer& Json_writer::add_member(const char *name, size_t len)
output
.
append
(
name
,
len
);
output
.
append
(
"
\"
: "
,
3
);
}
#if
ndef NDEBUG
#if
!defined(NDEBUG) || defined(JSON_WRITER_UNIT_TEST)
if
(
!
fmt_helper
.
is_making_writer_calls
())
got_name
=
true
;
#endif
...
...
@@ -260,7 +256,7 @@ void Json_writer::add_unquoted_str(const char* str, size_t len)
inline
bool
Json_writer
::
on_add_str
(
const
char
*
str
,
size_t
num_bytes
)
{
#if
ndef NDEBUG
#if
!defined(NDEBUG) || defined(JSON_WRITER_UNIT_TEST)
got_name
=
false
;
#endif
bool
helped
=
fmt_helper
.
on_add_str
(
str
,
num_bytes
);
...
...
sql/my_json_writer.h
View file @
e9b76b89
...
...
@@ -17,9 +17,12 @@
#define JSON_WRITER_INCLUDED
#include "my_base.h"
#if !defined(NDEBUG) || defined(JSON_WRITER_UNIT_TEST)
#include <vector>
#endif
#ifdef JSON_WRITER_UNIT_TEST
#include "sql_string.h"
#include <vector>
// Also, mock objects are defined in my_json_writer-t.cc
#define VALIDITY_ASSERT(x) if ((!x)) this->invalid_json= true;
#else
...
...
@@ -200,7 +203,7 @@ class String_with_limit
class
Json_writer
{
#if
ndef NDEBUG
#if
!defined(NDEBUG) || defined(JSON_WRITER_UNIT_TEST)
/*
In debug mode, Json_writer will fail and assertion if one attempts to
produce an invalid JSON document (e.g. JSON array having named elements).
...
...
@@ -244,7 +247,6 @@ class Json_writer
void
add_unquoted_str
(
const
char
*
val
,
size_t
len
);
bool
on_add_str
(
const
char
*
str
,
size_t
num_bytes
);
bool
on_start_array
();
void
on_start_object
();
public:
...
...
@@ -264,7 +266,7 @@ class Json_writer
size_t
get_truncated_bytes
()
{
return
output
.
get_truncated_bytes
();
}
Json_writer
()
:
#if
ndef NDEBUG
#if
!defined(NDEBUG) || defined(JSON_WRITER_UNIT_TEST)
got_name
(
false
),
#endif
indent_level
(
0
),
document_start
(
true
),
element_started
(
false
),
...
...
unittest/sql/my_json_writer-t.cc
View file @
e9b76b89
...
...
@@ -110,7 +110,7 @@ int main(int args, char **argv)
Json_writer
w
;
w
.
start_array
();
w
.
end_object
();
ok
(
!
w
.
invalid_json
,
"BAD: not checked!
"
);
ok
(
w
.
invalid_json
,
"JSON object end of array
"
);
}
// BAD:
...
...
@@ -118,7 +118,7 @@ int main(int args, char **argv)
Json_writer
w
;
w
.
start_object
();
w
.
end_array
();
ok
(
!
w
.
invalid_json
,
"BAD: not checked!
"
);
ok
(
w
.
invalid_json
,
"JSON array end of object
"
);
}
...
...
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