Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mtxclient
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nheko Reborn
mtxclient
Commits
5f8c9ab6
Commit
5f8c9ab6
authored
6 years ago
by
Konstantinos Sideris
Browse files
Options
Downloads
Patches
Plain Diff
Verify that JSON output is in the canonical format
parent
52c2feb2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/utils.cpp
+38
-0
38 additions, 0 deletions
tests/utils.cpp
with
38 additions
and
0 deletions
tests/utils.cpp
+
38
−
0
View file @
5f8c9ab6
...
...
@@ -11,6 +11,44 @@ using json = nlohmann::json;
using
namespace
mtx
::
client
::
crypto
;
using
namespace
std
;
TEST
(
Utilities
,
CanonicalJSON
)
{
// Examples taken from
// https://matrix.org/docs/spec/appendices.html#canonical-json
json
data
=
R"({
"auth": {
"success": true,
"mxid": "@john.doe:example.com",
"profile": {
"display_name": "John Doe",
"three_pids": [{
"medium": "email",
"address": "john.doe@example.org"
}, {
"medium": "msisdn",
"address": "123456789"
}]
}}})"
_json
;
EXPECT_EQ
(
data
.
dump
(),
"{
\"
auth
\"
:{
\"
mxid
\"
:
\"
@john.doe:example.com
\"
,
\"
profile
\"
:{
\"
display_name
\"
:
\"
John "
"Doe
\"
,
\"
three_pids
\"
:[{
\"
address
\"
:
\"
john.doe@example.org
\"
,
\"
medium
\"
:
\"
email
\"
},{"
"
\"
address
\"
:
\"
123456789
\"
,
\"
medium
\"
:
\"
msisdn
\"
}]},
\"
success
\"
:true}}"
);
json
data0
=
R"({"b":"2","a":"1"})"
_json
;
EXPECT_EQ
(
data0
.
dump
(),
"{
\"
a
\"
:
\"
1
\"
,
\"
b
\"
:
\"
2
\"
}"
);
json
data1
=
R"({ "本": 2, "日": 1 })"
_json
;
EXPECT_EQ
(
data1
.
dump
(),
"{
\"
日
\"
:1,
\"
本
\"
:2}"
);
json
data2
=
R"({"a": "\u65E5"})"
_json
;
EXPECT_EQ
(
data2
.
dump
(),
"{
\"
a
\"
:
\"
日
\"
}"
);
json
data3
=
R"({ "a": null })"
_json
;
EXPECT_EQ
(
data3
.
dump
(),
"{
\"
a
\"
:null}"
);
}
TEST
(
Utilities
,
JsonToBuffer
)
{
auto
msg
=
json
({{
"key"
,
"text"
}});
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment