Created
January 9, 2014 18:22
-
-
Save berkus/8339233 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define BOOST_TEST_MODULE Test1 | |
#include <boost/test/unit_test.hpp> | |
#include <string> | |
char IfaceData[] | |
= { 23, 0, 0, 0, | |
5, 0, 0, 0, 'H', 'e', 'l', 'l', 'o', | |
5, 0, 0, 0, 'W', 'o', 'r', 'l', 'd', | |
1, 0, 0, 0, '!' }; | |
int32_t * MTEGetString(int32_t * pointer, std::string & result) | |
{ | |
int32_t datalen = *pointer; | |
char *data = (char *) (pointer + 1); | |
result = std::string(data, datalen); | |
pointer = (int32_t *)(data + datalen); | |
return pointer; | |
} | |
// Example buf: | |
// [5]Hello[5]World[1]! | |
int32_t* ReadFromBuf(int32_t * pointer) | |
{ | |
std::string name, caption, description; | |
pointer = MTEGetString(pointer, name); | |
pointer = MTEGetString(pointer, caption); | |
pointer = MTEGetString(pointer, description); | |
// etc | |
std::cout << name << std::endl << caption << std::endl << description << std::endl; | |
BOOST_CHECK(name == "Hello"); | |
BOOST_CHECK(caption == "World"); | |
BOOST_CHECK(description == "!"); | |
return pointer; | |
} | |
typedef struct { | |
int32_t DataLen; | |
char Data[1]; // Allocated inline | |
} MTEMSG; | |
BOOST_AUTO_TEST_CASE(read_from_buf) | |
{ | |
// MTEMSG *IfaceData; | |
// int Interface = MTEStructure2(ConnectionHandle, &IfaceData); // Allocates sizeof(MTEMSG)+DataLen bytes | |
// int32_t * pointer = (int32_t *)IfaceData->Data; | |
ReadFromBuf((int32_t*)&((MTEMSG*)IfaceData)->Data); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment