Adding tests for std::pair and std::map
This commit is contained in:
parent
39b76cb5c5
commit
72912fba19
@ -129,7 +129,6 @@ template <typename T1, typename T2>
|
|||||||
void serialize(Serializer* serializer, const std::pair<T1, T2>& value) {
|
void serialize(Serializer* serializer, const std::pair<T1, T2>& value) {
|
||||||
serializer->write(value.first);
|
serializer->write(value.first);
|
||||||
serializer->write(value.second);
|
serializer->write(value.second);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T1, typename T2>
|
template <typename T1, typename T2>
|
||||||
@ -145,7 +144,7 @@ bool deserialize(Deserializer* deserializer, std::pair<T1, T2>* value) {
|
|||||||
template <typename K, typename V, typename C, typename A>
|
template <typename K, typename V, typename C, typename A>
|
||||||
void serialize(Serializer* serializer, const std::map<K, V, C, A>& value) {
|
void serialize(Serializer* serializer, const std::map<K, V, C, A>& value) {
|
||||||
serializer->write(value.size());
|
serializer->write(value.size());
|
||||||
for (const typename std::map<K, V, C, A>::const_iterator iter = value.begin(); iter != value.end(); ++iter) {
|
for (typename std::map<K, V, C, A>::const_iterator iter = value.begin(); iter != value.end(); ++iter) {
|
||||||
serializer->write(*iter);
|
serializer->write(*iter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
93
testing.cpp
93
testing.cpp
@ -37,6 +37,8 @@ using namespace metacall;
|
|||||||
#define TEST_BASIC_STRING
|
#define TEST_BASIC_STRING
|
||||||
#define TEST_VECTOR
|
#define TEST_VECTOR
|
||||||
#define TEST_LIST
|
#define TEST_LIST
|
||||||
|
#define TEST_PAIR
|
||||||
|
#define TEST_MAP
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -77,12 +79,12 @@ static void testCString(Binding* binding, Protocol* protocol) {
|
|||||||
|
|
||||||
#ifdef TEST_BASIC_STRING
|
#ifdef TEST_BASIC_STRING
|
||||||
|
|
||||||
static void testBasicStringAnsiImp(const std::string& str) {
|
static void testBasicStringAnsiImp(const std::string& string) {
|
||||||
printf("[testBasicStringAnsiImp]: '%s'\n", str.c_str());
|
printf("[testBasicStringAnsiImp]: '%s'\n", string.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
static void testBasicStringUnicodeImp(const std::wstring& str) {
|
static void testBasicStringUnicodeImp(const std::wstring& string) {
|
||||||
wprintf(L"[testBasicStringUnicodeImp]: '%S'\n", str.c_str());
|
wprintf(L"[testBasicStringUnicodeImp]: '%S'\n", string.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
static void testBasicString(Binding* binding, Protocol* protocol) {
|
static void testBasicString(Binding* binding, Protocol* protocol) {
|
||||||
@ -109,10 +111,10 @@ static void testBasicString(Binding* binding, Protocol* protocol) {
|
|||||||
|
|
||||||
#ifdef TEST_VECTOR
|
#ifdef TEST_VECTOR
|
||||||
|
|
||||||
static void testVectorImp(const std::vector<float>& vec) {
|
static void testVectorImp(const std::vector<float>& vector) {
|
||||||
printf("[testVectorImp]: ");
|
printf("[testVectorImp]: ");
|
||||||
|
|
||||||
for (std::vector<float>::const_iterator iter = vec.begin(); iter != vec.end(); ++iter) {
|
for (std::vector<float>::const_iterator iter = vector.begin(); iter != vector.end(); ++iter) {
|
||||||
printf("%f ", *iter);
|
printf("%f ", *iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,12 +124,12 @@ static void testVectorImp(const std::vector<float>& vec) {
|
|||||||
static void testVector(Binding* binding, Protocol* protocol) {
|
static void testVector(Binding* binding, Protocol* protocol) {
|
||||||
binding->bind(FPARAM(testVectorImp));
|
binding->bind(FPARAM(testVectorImp));
|
||||||
|
|
||||||
std::vector<float> vec;
|
std::vector<float> vector;
|
||||||
vec.push_back(3.14159f);
|
vector.push_back(3.14159f);
|
||||||
vec.push_back(2.71828f);
|
vector.push_back(2.71828f);
|
||||||
vec.push_back(1.61803f);
|
vector.push_back(1.61803f);
|
||||||
|
|
||||||
protocol->invoke("testVectorImp", vec);
|
protocol->invoke("testVectorImp", vector);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -139,10 +141,10 @@ static void testVector(Binding* binding, Protocol* protocol) {
|
|||||||
|
|
||||||
#ifdef TEST_LIST
|
#ifdef TEST_LIST
|
||||||
|
|
||||||
static void testListImp(const std::list<float>& lst) {
|
static void testListImp(const std::list<float>& list) {
|
||||||
printf("[testListImp]: ");
|
printf("[testListImp]: ");
|
||||||
|
|
||||||
for (std::list<float>::const_iterator iter = lst.begin(); iter != lst.end(); ++iter) {
|
for (std::list<float>::const_iterator iter = list.begin(); iter != list.end(); ++iter) {
|
||||||
printf("%f ", *iter);
|
printf("%f ", *iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,17 +154,64 @@ static void testListImp(const std::list<float>& lst) {
|
|||||||
static void testList(Binding* binding, Protocol* protocol) {
|
static void testList(Binding* binding, Protocol* protocol) {
|
||||||
binding->bind(FPARAM(testListImp));
|
binding->bind(FPARAM(testListImp));
|
||||||
|
|
||||||
std::list<float> lst;
|
std::list<float> list;
|
||||||
lst.push_back(3.14159f);
|
list.push_back(3.14159f);
|
||||||
lst.push_back(2.71828f);
|
list.push_back(2.71828f);
|
||||||
lst.push_back(1.61803f);
|
list.push_back(1.61803f);
|
||||||
|
|
||||||
protocol->invoke("testListImp", lst);
|
protocol->invoke("testListImp", list);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// std::pair
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifdef TEST_PAIR
|
||||||
|
|
||||||
|
static void testPairImp(const std::pair<float, int>& pair) {
|
||||||
|
printf("[testPairImp]: (%f, %d)\n", pair.first, pair.second);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void testPair(Binding* binding, Protocol* protocol) {
|
||||||
|
binding->bind(FPARAM(testPairImp));
|
||||||
|
protocol->invoke("testPairImp", std::make_pair<float, int>(3.14159f, 123));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// std::map
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifdef TEST_MAP
|
||||||
|
|
||||||
|
static void testMapImp(const std::map<float, int>& map) {
|
||||||
|
printf("[testMapImp]: ");
|
||||||
|
|
||||||
|
for (std::map<float, int>::const_iterator iter = map.begin(); iter != map.end(); ++iter) {
|
||||||
|
printf("(%f, %d) ", iter->first, iter->second);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void testMap(Binding* binding, Protocol* protocol) {
|
||||||
|
binding->bind(FPARAM(testMapImp));
|
||||||
|
|
||||||
|
std::map<float, int> map;
|
||||||
|
map[3.14159f] = 123;
|
||||||
|
map[2.71828f] = 456;
|
||||||
|
map[1.61803f] = 789;
|
||||||
|
|
||||||
|
protocol->invoke("testMapImp", map);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Program entry
|
// Program entry
|
||||||
@ -203,6 +252,14 @@ int main(int, char *[]) {
|
|||||||
testList(&binding, &protocol);
|
testList(&binding, &protocol);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef TEST_PAIR
|
||||||
|
testPair(&binding, &protocol);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef TEST_MAP
|
||||||
|
testMap(&binding, &protocol);
|
||||||
|
#endif
|
||||||
|
|
||||||
server.advance();
|
server.advance();
|
||||||
client.advance();
|
client.advance();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user