File: cases.cc

package info (click to toggle)
msgpack 0.5.7-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,172 kB
  • sloc: cpp: 18,899; sh: 11,012; ansic: 2,580; makefile: 140
file content (38 lines) | stat: -rw-r--r-- 798 bytes parent folder | download | duplicates (2)
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
#include <msgpack.hpp>
#include <fstream>
#include <gtest/gtest.h>

static void feed_file(msgpack::unpacker& pac, const char* path)
{
	std::ifstream fin(path);
	while(true) {
		pac.reserve_buffer(32*1024);
		fin.read(pac.buffer(), pac.buffer_capacity());
		if(fin.bad()) {
			throw std::runtime_error("read failed");
		}
		pac.buffer_consumed(fin.gcount());
		if(fin.fail()) {
			break;
		}
	}
}

TEST(cases, format)
{
	msgpack::unpacker pac;
	msgpack::unpacker pac_compact;

	feed_file(pac, "cases.mpac");
	feed_file(pac_compact, "cases_compact.mpac");

	msgpack::unpacked result;
	while(pac.next(&result)) {
		msgpack::unpacked result_compact;
		EXPECT_TRUE( pac_compact.next(&result_compact) );
		EXPECT_EQ(result_compact.get(), result.get());
	}

	EXPECT_FALSE( pac_compact.next(&result) );
}