mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-12-03 20:38:11 +08:00
commit
463491d21a
@ -1,6 +1,8 @@
|
||||
|
||||
clean:
|
||||
@(cd benchmark; make clean)
|
||||
@(cd test; make clean)
|
||||
@(cd test0; make clean)
|
||||
@(cd test1; make clean)
|
||||
@(cd test2; make clean)
|
||||
@(cd test3; make clean)
|
||||
|
5
app/gson/test/test/Makefile
Normal file
5
app/gson/test/test/Makefile
Normal file
@ -0,0 +1,5 @@
|
||||
include ../Makefile.in
|
||||
ifeq ($(findstring FreeBSD, $(UNIXNAME)), FreeBSD)
|
||||
EXTLIBS += -L/usr/local/lib -liconv
|
||||
endif
|
||||
PROG = test
|
58
app/gson/test/test/main.cpp
Normal file
58
app/gson/test/test/main.cpp
Normal file
@ -0,0 +1,58 @@
|
||||
#include "stdafx.h"
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <time.h>
|
||||
#include "struct.h" // 由 gson 工具根据 struct.stub 转换而成
|
||||
#include "gson.h" // 由 gson 工具根据 struct.stub 生成
|
||||
|
||||
// 序列化过程
|
||||
static void serialize(void)
|
||||
{
|
||||
user u;
|
||||
|
||||
u.name = "zsxxsz";
|
||||
u.domain = "263.net";
|
||||
u.age = 11;
|
||||
u.male = true;
|
||||
|
||||
acl::json json;
|
||||
|
||||
// 将 user 对象转换为 json 对象
|
||||
acl::json_node& node = acl::gson(json, u);
|
||||
|
||||
printf("serialize:\r\n");
|
||||
printf("json: %s\r\n", node.to_string().c_str());
|
||||
printf("\r\n");
|
||||
}
|
||||
|
||||
// 反序列化过程
|
||||
static void deserialize(void)
|
||||
{
|
||||
const char *s = "{\"name\": \"zsxxsz\", \"domain\": \"263.net\", \"age\": 11, \"male\": true}";
|
||||
printf("deserialize:\r\n");
|
||||
|
||||
acl::json json;
|
||||
json.update(s);
|
||||
user u;
|
||||
|
||||
// 将 json 对象转换为 user 对象
|
||||
std::pair<bool, std::string> ret = acl::gson(json.get_root(), u);
|
||||
|
||||
// 如果转换失败,则打印转换失败原因
|
||||
if (ret.first == false)
|
||||
printf("error: %s\r\n", ret.second.c_str());
|
||||
else
|
||||
printf("name: %s, domain: %s, age: %d, male: %s\r\n",
|
||||
u.name.c_str(), u.domain.c_str(), u.age,
|
||||
u.male ? "yes" : "no");
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
serialize();
|
||||
deserialize();
|
||||
return 0;
|
||||
}
|
8
app/gson/test/test/stdafx.cpp
Normal file
8
app/gson/test/test/stdafx.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
// stdafx.cpp : 只包括标准包含文件的源文件
|
||||
// wizard.pch 将成为预编译头
|
||||
// stdafx.obj 将包含预编译类型信息
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
// TODO: 在 STDAFX.H 中
|
||||
//引用任何所需的附加头文件,而不是在此文件中引用
|
15
app/gson/test/test/stdafx.h
Normal file
15
app/gson/test/test/stdafx.h
Normal file
@ -0,0 +1,15 @@
|
||||
// stdafx.h : 标准系统包含文件的包含文件,
|
||||
// 或是常用但不常更改的项目特定的包含文件
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
//#include <iostream>
|
||||
//#include <tchar.h>
|
||||
|
||||
// TODO: 在此处引用程序要求的附加头文件
|
||||
|
||||
#include "lib_acl.h"
|
||||
#include "acl_cpp/lib_acl.hpp"
|
||||
#include "lib_protocol.h"
|
10
app/gson/test/test/struct.stub
Normal file
10
app/gson/test/test/struct.stub
Normal file
@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
struct user
|
||||
{
|
||||
std::string name;
|
||||
std::string domain;
|
||||
int age;
|
||||
bool male;
|
||||
};
|
3
app/gson/test/test/valgrind.sh
Executable file
3
app/gson/test/test/valgrind.sh
Executable file
@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
valgrind --tool=memcheck --leak-check=yes -v ./test
|
5
app/gson/test/test3/Makefile
Normal file
5
app/gson/test/test3/Makefile
Normal file
@ -0,0 +1,5 @@
|
||||
include ../Makefile.in
|
||||
ifeq ($(findstring FreeBSD, $(UNIXNAME)), FreeBSD)
|
||||
EXTLIBS += -L/usr/local/lib -liconv
|
||||
endif
|
||||
PROG = test
|
68
app/gson/test/test3/main.cpp
Normal file
68
app/gson/test/test3/main.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
#include "stdafx.h"
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <time.h>
|
||||
#include "struct.h" // 由 gson 工具根据 struct.stub 转换而成
|
||||
#include "gson.h" // 由 gson 工具根据 struct.stub 生成
|
||||
|
||||
// 序列化过程
|
||||
static void serialize(void)
|
||||
{
|
||||
user u;
|
||||
|
||||
u.name = "zsxxsz";
|
||||
u.age = 11;
|
||||
u.male = true;
|
||||
|
||||
u.province_name = "山东省";
|
||||
u.position = "山东省";
|
||||
|
||||
u.shcool = "山东工业大学";
|
||||
u.class_name = "热处理专业";
|
||||
|
||||
acl::json json;
|
||||
|
||||
// 将 user 对象转换为 json 对象
|
||||
acl::json_node& node = acl::gson(json, u);
|
||||
|
||||
printf("serialize:\r\n");
|
||||
printf("json: %s\r\n", node.to_string().c_str());
|
||||
printf("\r\n");
|
||||
}
|
||||
|
||||
// 反序列化过程
|
||||
static void deserialize(void)
|
||||
{
|
||||
const char *s = "{\"shcool\": \"山东工业大学\", \"class_name\": \"热处理专业\", \"province_name\": \"山东省\", \"position\": \"山东省\", \"name\": \"zsxxsz\", \"age\": 11, \"male\": true}";
|
||||
printf("deserialize:\r\n");
|
||||
|
||||
acl::json json;
|
||||
json.update(s);
|
||||
user u;
|
||||
|
||||
// 将 json 对象转换为 user 对象
|
||||
std::pair<bool, std::string> ret = acl::gson(json.get_root(), u);
|
||||
|
||||
// 如果转换失败,则打印转换失败原因
|
||||
if (ret.first == false)
|
||||
printf("error: %s\r\n", ret.second.c_str());
|
||||
else
|
||||
{
|
||||
printf("name: %s, age: %d, male: %s\r\n",
|
||||
u.name.c_str(), u.age, u.male ? "yes" : "no");
|
||||
printf("province_name: %s, position: %s\r\n",
|
||||
u.province_name.c_str(), u.position.c_str());
|
||||
printf("shcool: %s, class_name: %s\r\n",
|
||||
u.shcool.c_str(), u.class_name.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
serialize();
|
||||
deserialize();
|
||||
return 0;
|
||||
}
|
8
app/gson/test/test3/stdafx.cpp
Normal file
8
app/gson/test/test3/stdafx.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
// stdafx.cpp : 只包括标准包含文件的源文件
|
||||
// wizard.pch 将成为预编译头
|
||||
// stdafx.obj 将包含预编译类型信息
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
// TODO: 在 STDAFX.H 中
|
||||
//引用任何所需的附加头文件,而不是在此文件中引用
|
15
app/gson/test/test3/stdafx.h
Normal file
15
app/gson/test/test3/stdafx.h
Normal file
@ -0,0 +1,15 @@
|
||||
// stdafx.h : 标准系统包含文件的包含文件,
|
||||
// 或是常用但不常更改的项目特定的包含文件
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
//#include <iostream>
|
||||
//#include <tchar.h>
|
||||
|
||||
// TODO: 在此处引用程序要求的附加头文件
|
||||
|
||||
#include "lib_acl.h"
|
||||
#include "acl_cpp/lib_acl.hpp"
|
||||
#include "lib_protocol.h"
|
21
app/gson/test/test3/struct.stub
Normal file
21
app/gson/test/test3/struct.stub
Normal file
@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
struct student
|
||||
{
|
||||
std::string shcool;
|
||||
std::string class_name;
|
||||
};
|
||||
|
||||
struct province
|
||||
{
|
||||
std::string province_name;
|
||||
std::string position;
|
||||
};
|
||||
|
||||
struct user : student, province
|
||||
{
|
||||
std::string name;
|
||||
int age;
|
||||
bool male;
|
||||
};
|
3
app/gson/test/test3/valgrind.sh
Executable file
3
app/gson/test/test3/valgrind.sh
Executable file
@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
valgrind --tool=memcheck --leak-check=yes -v ./test
|
Loading…
Reference in New Issue
Block a user