blob: fdf211bfafeb178c6fd7c3dc6e48fbbfcbf112e0 [file] [log] [blame]
Zhenkai Zhu7c1cd8d2013-01-31 12:27:17 -08001#include "ccnx-common.h"
2#include "sync-core.h"
3#include <boost/make_shared.hpp>
4#include <boost/test/unit_test.hpp>
5#include <boost/iostreams/filter/gzip.hpp>
6#include <boost/iostreams/filtering_stream.hpp>
7#include <boost/iostreams/device/back_inserter.hpp>
8#include <boost/range/iterator_range.hpp>
9#include <boost/make_shared.hpp>
10
11using namespace Ccnx;
12using namespace std;
13using namespace boost;
14
15BOOST_AUTO_TEST_SUITE(ProtobufTests)
16
17
18BOOST_AUTO_TEST_CASE (TestGzipProtobuf)
19{
20 SyncStateMsgPtr msg = make_shared<SyncStateMsg>();
21
22 SyncState *state = msg->add_state();
23 state->set_type(SyncState::UPDATE);
24 state->set_seq(100);
25 char x[100] = {'a'};
26 state->set_locator(&x[0], sizeof(x));
27 state->set_name(&x[0], sizeof(x));
28
29 BytesPtr bb = serializeMsg<SyncStateMsg>(*msg);
30
31 BytesPtr cb = serializeGZipMsg<SyncStateMsg>(*msg);
32 BOOST_CHECK(cb->size() < bb->size());
33 cout << cb->size() <<", " << bb->size() << endl;
34
35 SyncStateMsgPtr msg1 = deserializeGZipMsg<SyncStateMsg>(*cb);
36
37 BOOST_REQUIRE(msg1->state_size() == 1);
38
39 SyncState state1 = msg1->state(0);
40 BOOST_CHECK_EQUAL(state->seq(), state1.seq());
41 BOOST_CHECK_EQUAL(state->type(), state1.type());
42 string sx(x, 100);
43 BOOST_CHECK_EQUAL(sx, state1.name());
44 BOOST_CHECK_EQUAL(sx, state1.locator());
45}
46
47BOOST_AUTO_TEST_SUITE_END()