mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
add json BJSON_TYPE_BYTES support
This commit is contained in:
parent
6f4a7db910
commit
f8fadf8b74
7 changed files with 72 additions and 8 deletions
41
test/coders/json.cpp
Normal file
41
test/coders/json.cpp
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
#include <gtest/gtest.h>
|
||||
|
||||
#include "coders/json.hpp"
|
||||
#include "util/stringutil.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
TEST(JSON, EncodeDecode) {
|
||||
const std::string name = "JSON-encoder";
|
||||
const int bytesSize = 20;
|
||||
const int year = 2019;
|
||||
const float score = 3.141592;
|
||||
dynamic::ByteBuffer srcBytes(bytesSize);
|
||||
for (int i = 0; i < bytesSize; i ++) {
|
||||
srcBytes[i] = rand();
|
||||
}
|
||||
|
||||
std::string text;
|
||||
{
|
||||
dynamic::Map map;
|
||||
map.put("name", name);
|
||||
map.put("year", year);
|
||||
map.put("score", score);
|
||||
map.put("data", &srcBytes);
|
||||
|
||||
text = json::stringify(&map, false, "");
|
||||
}
|
||||
{
|
||||
auto map = json::parse(text);
|
||||
EXPECT_EQ(map->get<std::string>("name"), name);
|
||||
EXPECT_EQ(map->get<integer_t>("year"), year);
|
||||
EXPECT_FLOAT_EQ(map->get<number_t>("score"), score);
|
||||
auto b64string = map->get<std::string>("data");
|
||||
|
||||
auto bytes = util::base64_decode(b64string);
|
||||
EXPECT_EQ(bytes.size(), bytesSize);
|
||||
for (int i = 0; i < bytesSize; i++) {
|
||||
EXPECT_EQ(bytes[i], srcBytes[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue