Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: test/CommunicationTest.cpp

Issue 4806567450902528: Issue 1794 - add handling of std::vector<std::string> by Communication::{Input,Output}Buffer (Closed)
Left Patch Set: Created Dec. 19, 2014, 9:42 a.m.
Right Patch Set: remove WriteStrings and ReadStrings Created Feb. 9, 2015, 2:04 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« src/shared/Utils.h ('K') | « src/shared/Utils.cpp ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 ASSERT_ANY_THROW(response >> int32Value); 106 ASSERT_ANY_THROW(response >> int32Value);
107 ASSERT_ANY_THROW(response >> boolValue); 107 ASSERT_ANY_THROW(response >> boolValue);
108 108
109 ASSERT_EQ("Foo Received", stringValue); 109 ASSERT_EQ("Foo Received", stringValue);
110 ASSERT_EQ(L"Bar \u043f\u0440\u0438\u043d\u044f\u0442\u043e", wstringValue); 110 ASSERT_EQ(L"Bar \u043f\u0440\u0438\u043d\u044f\u0442\u043e", wstringValue);
111 ASSERT_EQ(9876543211L, int64Value); 111 ASSERT_EQ(9876543211L, int64Value);
112 ASSERT_EQ(7, int32Value); 112 ASSERT_EQ(7, int32Value);
113 ASSERT_FALSE(boolValue); 113 ASSERT_FALSE(boolValue);
114 } 114 }
115 115
116 TEST(InputOutputBuffersTests, EmptyVector) 116 void SendReceiveStrings(const std::vector<std::string>& src)
117 { 117 {
118 std::vector<std::string> emptySrcVector;
119 Communication::OutputBuffer outputBuffer; 118 Communication::OutputBuffer outputBuffer;
Eric 2015/01/13 16:20:45 The core of these tests is the same code. It would
120 outputBuffer << emptySrcVector; 119 outputBuffer << src;
121 Communication::InputBuffer inputBuffer(outputBuffer.Get()); 120 Communication::InputBuffer inputBuffer(outputBuffer.Get());
Eric 2015/02/17 17:18:35 I don't like the use of Get() here, but I'll save
122 std::vector<std::string> dstVector; 121 std::vector<std::string> dst;
123 inputBuffer >> dstVector; 122 inputBuffer >> dst;
124 EXPECT_TRUE(dstVector.empty()); 123 auto dstSize = dst.size();
124 ASSERT_EQ(dstSize, src.size());
125 for (auto i = 0; i < dstSize; ++i)
126 {
127 EXPECT_EQ(dst[i], src[i]);
128 }
125 } 129 }
126 130
127 TEST(InputOutputBuffersTests, NonemptyVectors) 131 TEST(InputOutputBuffersTests, EmptyStrings)
Eric 2015/01/13 16:20:45 I'd make this two tests.
128 { 132 {
129 { 133 SendReceiveStrings(std::vector<std::string>());
130 std::vector<std::string> srcVector; 134 }
131 srcVector.emplace_back("string1"); 135
132 Communication::OutputBuffer outputBuffer; 136 TEST(InputOutputBuffersTests, StringsWithOneValue)
133 outputBuffer << srcVector; 137 {
134 Communication::InputBuffer inputBuffer(outputBuffer.Get()); 138 std::vector<std::string> src;
135 std::vector<std::string> dstVector; 139 src.emplace_back("string1");
136 inputBuffer >> dstVector; 140 SendReceiveStrings(src);
137 ASSERT_EQ(1, dstVector.size()); 141 }
138 EXPECT_EQ("string1", dstVector[0]); 142
139 } 143 TEST(InputOutputBuffersTests, MultivalueStrings)
140 { 144 {
141 std::vector<std::string> srcVector; 145 std::vector<std::string> src;
142 srcVector.emplace_back("string1"); 146 src.emplace_back("string1");
143 srcVector.emplace_back("str2"); 147 src.emplace_back("str2");
144 srcVector.emplace_back("value"); 148 src.emplace_back("value");
145 Communication::OutputBuffer outputBuffer; 149 SendReceiveStrings(src);
146 outputBuffer << srcVector;
147 Communication::InputBuffer inputBuffer(outputBuffer.Get());
148 std::vector<std::string> dstVector;
149 inputBuffer >> dstVector;
150 ASSERT_EQ(3, dstVector.size());
151 EXPECT_EQ("string1", dstVector[0]);
152 EXPECT_EQ("str2", dstVector[1]);
153 EXPECT_EQ("value", dstVector[2]);
154 }
155 } 150 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld