Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: mojo/public/cpp/bindings/tests/validation_unittest.cc

Issue 1552983003: Fix a bunch of mojo_public_*_unittests with the new EDK. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/public/cpp/bindings/tests/union_unittest.cc ('k') | mojo/public/cpp/environment/logging.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 #include <stdio.h> 7 #include <stdio.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/run_loop.h"
14 #include "mojo/message_pump/message_pump_mojo.h" 15 #include "mojo/message_pump/message_pump_mojo.h"
15 #include "mojo/public/c/system/macros.h" 16 #include "mojo/public/c/system/macros.h"
16 #include "mojo/public/cpp/bindings/binding.h" 17 #include "mojo/public/cpp/bindings/binding.h"
17 #include "mojo/public/cpp/bindings/interface_ptr.h" 18 #include "mojo/public/cpp/bindings/interface_ptr.h"
18 #include "mojo/public/cpp/bindings/lib/connector.h" 19 #include "mojo/public/cpp/bindings/lib/connector.h"
19 #include "mojo/public/cpp/bindings/lib/filter_chain.h" 20 #include "mojo/public/cpp/bindings/lib/filter_chain.h"
20 #include "mojo/public/cpp/bindings/lib/message_header_validator.h" 21 #include "mojo/public/cpp/bindings/lib/message_header_validator.h"
21 #include "mojo/public/cpp/bindings/lib/router.h" 22 #include "mojo/public/cpp/bindings/lib/router.h"
22 #include "mojo/public/cpp/bindings/lib/validation_errors.h" 23 #include "mojo/public/cpp/bindings/lib/validation_errors.h"
23 #include "mojo/public/cpp/bindings/message.h" 24 #include "mojo/public/cpp/bindings/message.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 std::vector<std::string> names = 165 std::vector<std::string> names =
165 EnumerateSourceRootRelativeDirectory(GetPath("", "")); 166 EnumerateSourceRootRelativeDirectory(GetPath("", ""));
166 std::vector<std::string> tests = GetMatchingTests(names, prefix); 167 std::vector<std::string> tests = GetMatchingTests(names, prefix);
167 168
168 for (size_t i = 0; i < tests.size(); ++i) { 169 for (size_t i = 0; i < tests.size(); ++i) {
169 Message message; 170 Message message;
170 std::string expected; 171 std::string expected;
171 ASSERT_TRUE(ReadTestCase(tests[i], &message, &expected)); 172 ASSERT_TRUE(ReadTestCase(tests[i], &message, &expected));
172 173
173 std::string result; 174 std::string result;
174 mojo::internal::ValidationErrorObserverForTesting observer; 175 base::RunLoop run_loop;
176 mojo::internal::ValidationErrorObserverForTesting observer(
177 run_loop.QuitClosure());
175 mojo_ignore_result(test_message_receiver->Accept(&message)); 178 mojo_ignore_result(test_message_receiver->Accept(&message));
179 if (expected != "PASS") // Observer only gets called on errors.
180 run_loop.Run();
176 if (observer.last_error() == mojo::internal::VALIDATION_ERROR_NONE) 181 if (observer.last_error() == mojo::internal::VALIDATION_ERROR_NONE)
177 result = "PASS"; 182 result = "PASS";
178 else 183 else
179 result = mojo::internal::ValidationErrorToString(observer.last_error()); 184 result = mojo::internal::ValidationErrorToString(observer.last_error());
180 185
181 EXPECT_EQ(expected, result) << "failed test: " << tests[i]; 186 EXPECT_EQ(expected, result) << "failed test: " << tests[i];
182 } 187 }
183 } 188 }
184 189
185 class DummyMessageReceiver : public MessageReceiver { 190 class DummyMessageReceiver : public MessageReceiver {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 TestMessageReceiver(ValidationIntegrationTest* owner, 233 TestMessageReceiver(ValidationIntegrationTest* owner,
229 ScopedMessagePipeHandle handle) 234 ScopedMessagePipeHandle handle)
230 : owner_(owner), 235 : owner_(owner),
231 connector_(std::move(handle), 236 connector_(std::move(handle),
232 mojo::internal::Connector::SINGLE_THREADED_SEND) { 237 mojo::internal::Connector::SINGLE_THREADED_SEND) {
233 connector_.set_enforce_errors_from_incoming_receiver(false); 238 connector_.set_enforce_errors_from_incoming_receiver(false);
234 } 239 }
235 ~TestMessageReceiver() override {} 240 ~TestMessageReceiver() override {}
236 241
237 bool Accept(Message* message) override { 242 bool Accept(Message* message) override {
238 bool rv = connector_.Accept(message); 243 return connector_.Accept(message);
239 owner_->PumpMessages();
240 return rv;
241 } 244 }
242 245
243 public: 246 public:
244 ValidationIntegrationTest* owner_; 247 ValidationIntegrationTest* owner_;
245 mojo::internal::Connector connector_; 248 mojo::internal::Connector connector_;
246 }; 249 };
247 250
248 void PumpMessages() { loop_.RunUntilIdle(); } 251 void PumpMessages() { loop_.RunUntilIdle(); }
249 252
250 base::MessageLoop loop_; 253 base::MessageLoop loop_;
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 static_cast<StructWithEnum::EnumWithin>(2))); 491 static_cast<StructWithEnum::EnumWithin>(2)));
489 EXPECT_TRUE(StructWithEnum::EnumWithin_IsValidValue( 492 EXPECT_TRUE(StructWithEnum::EnumWithin_IsValidValue(
490 static_cast<StructWithEnum::EnumWithin>(3))); 493 static_cast<StructWithEnum::EnumWithin>(3)));
491 EXPECT_FALSE(StructWithEnum::EnumWithin_IsValidValue( 494 EXPECT_FALSE(StructWithEnum::EnumWithin_IsValidValue(
492 static_cast<StructWithEnum::EnumWithin>(4))); 495 static_cast<StructWithEnum::EnumWithin>(4)));
493 } 496 }
494 497
495 } // namespace 498 } // namespace
496 } // namespace test 499 } // namespace test
497 } // namespace mojo 500 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/tests/union_unittest.cc ('k') | mojo/public/cpp/environment/logging.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698