blob: cf821f5e408402e86662115a16099f596ce6e15a (
plain)
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
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sync/engine/traffic_recorder.h"
#include "sync/protocol/sync.pb.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace syncer {
const unsigned int kMaxMessages = 10;
const unsigned int kMaxMessageSize = 5 * 1024;
// Ensure the number of records don't exceed |kMaxMessages|.
TEST(TrafficRecorderTest, MaxRecordsTest) {
TrafficRecorder recorder(kMaxMessages, kMaxMessageSize);
sync_pb::ClientToServerResponse response;
for (unsigned int i = 0; i < 2*kMaxMessages; ++i)
recorder.RecordClientToServerResponse(response);
EXPECT_EQ(recorder.records().size(), kMaxMessages);
}
// Ensure records with size greater than |kMaxMessageSize| are truncated.
TEST(TrafficRecorderTest, MaxMessageSizeTest) {
sync_pb::ClientToServerResponse response;
sync_pb::ClientToServerResponse::Error* error = response.mutable_error();
std::string error_description(kMaxMessageSize * 2, 'a');
error->set_error_description(error_description);
TrafficRecorder recorder(kMaxMessages, kMaxMessageSize);
recorder.RecordClientToServerResponse(response);
TrafficRecorder::TrafficRecord record = recorder.records().front();
EXPECT_TRUE(record.truncated);
EXPECT_TRUE(record.message.empty());
}
} // namespace syncer
|