-
Notifications
You must be signed in to change notification settings - Fork 2
/
DecoderTests.cpp
42 lines (30 loc) · 1.01 KB
/
DecoderTests.cpp
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
39
40
41
42
#include <gmock/gmock.h>
#include "ResourceSystemMock.h"
#include "Decoder.h"
using namespace ::testing;
struct DecoderTestsFixture : Test
{
ResourceSystemMock rs;
using ValueWithError = std::pair < std::string, int > ;
};
TEST_F(DecoderTestsFixture, failed_reserve_resources)
{
EXPECT_CALL(rs, Resource_Reserve(_)).WillRepeatedly(Return(nullptr));
ASSERT_THAT(Decoder::decode("message which needs too much resources"), Eq(ValueWithError("", -1)));
}
TEST_F(DecoderTestsFixture, unsuccessful_decode)
{
const char msg[] = "wrong message";
char out[sizeof(msg)];
EXPECT_CALL(rs, Resource_Reserve(sizeof(msg))).WillOnce(Return(out));
EXPECT_CALL(rs, Resource_Free(out));
ASSERT_THAT(Decoder::decode(msg), Eq(ValueWithError("", 1)));
}
TEST_F(DecoderTestsFixture, successful_decode)
{
const char msg[] = "#abc";
char out[sizeof(msg)];
EXPECT_CALL(rs, Resource_Reserve(sizeof(msg))).WillOnce(Return(out));
EXPECT_CALL(rs, Resource_Free(out));
ASSERT_THAT(Decoder::decode(msg), Eq(ValueWithError("!bcd", 0)));
}