-
Notifications
You must be signed in to change notification settings - Fork 6
/
cpp_test.cpp
57 lines (45 loc) · 1.7 KB
/
cpp_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <flatbuffers/flatbuffers.h>
#include "monster_test_generated.h"
#include <iostream> // C++ header file for printing
#include <fstream> // C++ header file for file access
#define TEST_EQ(src,dst) \
do{\
if ((src) != (dst)){\
std::cerr << "test fail:" << __FUNCTION__ \
<< ":" << __LINE__ << "," << src << " vs " << dst << std::endl;\
return -1;\
}\
} while (0)
#define TEST_STR_EQ(src,dst) \
do{\
if (0 != strcmp((src) , (dst))){\
std::cerr << "test fail:" << __FUNCTION__ \
<< ":" << __LINE__ << "," << src << " vs " << dst << std::endl;\
return -1;\
}\
} while (0)
int main()
{
std::ifstream infile;
infile.open("monsterdata_test.mon", std::ios::binary | std::ios::in);
infile.seekg(0,std::ios::end);
int length = infile.tellg();
infile.seekg(0,std::ios::beg);
char *data = new char[length];
infile.read(data, length);
infile.close();
std::cout << "read " << length << " bytes from file,start verify ..." << std::endl;
flatbuffers::Verifier vfer(reinterpret_cast<const uint8_t*>(data), length);
// VerifyMonsterBuffer need identifier,we don't need it
// TEST_EQ( MyGame::Example::VerifyMonsterBuffer(vfer),true );
TEST_EQ ( vfer.VerifyBuffer<MyGame::Example::Monster>(NULL),true );
auto monster = MyGame::Example::GetMonster(data);
// no need to verify again,already done in VerifyBuffer
// TEST_EQ( monster->Verify(vfer),true );
TEST_EQ( monster->mana() , 1500 );
TEST_EQ( monster->hp() , 800 );
TEST_STR_EQ( monster->name()->c_str(),"testMyMonster" );
delete []data;
std::cout << "OK!" << std::endl;
return 0;
}