test.cpp: Add (nowadays) misisng header, format fixes
This commit is contained in:
25
test.cpp
25
test.cpp
@@ -1,6 +1,7 @@
|
|||||||
#include "exile.hpp"
|
#include "exile.hpp"
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
std::string sandboxed_reverse(std::string str)
|
std::string sandboxed_reverse(std::string str)
|
||||||
{
|
{
|
||||||
@@ -35,26 +36,34 @@ int test_exile_launch_stdstring()
|
|||||||
|
|
||||||
struct not_trivially_copyable
|
struct not_trivially_copyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::string somecontent;
|
std::string somecontent;
|
||||||
};
|
};
|
||||||
|
|
||||||
int test_exile_launch_serializer()
|
int test_exile_launch_serializer()
|
||||||
{
|
{
|
||||||
static_assert(! std::is_trivially_copyable_v<not_trivially_copyable>);
|
static_assert(!std::is_trivially_copyable_v<not_trivially_copyable>);
|
||||||
|
|
||||||
auto serializer = [](const not_trivially_copyable &obj, char *buf, size_t n){
|
auto serializer = [](const not_trivially_copyable &obj, char *buf, size_t n)
|
||||||
|
{
|
||||||
serialize_stdstring<std::string>(obj.somecontent, buf, n);
|
serialize_stdstring<std::string>(obj.somecontent, buf, n);
|
||||||
return obj.somecontent.size();
|
return obj.somecontent.size();
|
||||||
};
|
};
|
||||||
|
|
||||||
auto deserializer = [](const char *buffer, size_t n) {
|
auto deserializer = [](const char *buffer, size_t n)
|
||||||
|
{
|
||||||
not_trivially_copyable obj;
|
not_trivially_copyable obj;
|
||||||
obj.somecontent = deserialize_stdstring<std::string>(buffer, n);
|
obj.somecontent = deserialize_stdstring<std::string>(buffer, n);
|
||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
not_trivially_copyable result = exile_launch<not_trivially_copyable>(exile_init_policy(), serializer, deserializer, []() {not_trivially_copyable obj; obj.somecontent = "Just something"; return obj;});
|
not_trivially_copyable result = exile_launch<not_trivially_copyable>(exile_init_policy(), serializer, deserializer,
|
||||||
|
[]()
|
||||||
|
{
|
||||||
|
not_trivially_copyable obj;
|
||||||
|
obj.somecontent = "Just something";
|
||||||
|
return obj;
|
||||||
|
});
|
||||||
|
|
||||||
assert(result.somecontent == "Just something");
|
assert(result.somecontent == "Just something");
|
||||||
return 0;
|
return 0;
|
||||||
@@ -68,9 +77,9 @@ int main(int argc, char *argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
std::map<std::string, int (*)()> map = {
|
std::map<std::string, int (*)()> map = {
|
||||||
{ "launch-trivial-cpp", &test_exile_launch_trivial} ,
|
{"launch-trivial-cpp", &test_exile_launch_trivial},
|
||||||
{ "launch-stdstring-cpp", &test_exile_launch_stdstring },
|
{"launch-stdstring-cpp", &test_exile_launch_stdstring},
|
||||||
{ "launch-serializer-cpp", &test_exile_launch_serializer },
|
{"launch-serializer-cpp", &test_exile_launch_serializer},
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string test = argv[1];
|
std::string test = argv[1];
|
||||||
|
|||||||
Reference in New Issue
Block a user