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

Side by Side Diff: webrtc/base/physicalsocketserver_unittest.cc

Issue 2685783014: Replace NULL with nullptr in all C++ files. (Closed)
Patch Set: Fixing android. Created 3 years, 10 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
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 signals_received_.push_back(signum); 421 signals_received_.push_back(signum);
422 signaled_thread_ = Thread::Current(); 422 signaled_thread_ = Thread::Current();
423 } 423 }
424 424
425 protected: 425 protected:
426 void SetUp() { 426 void SetUp() {
427 ss_.reset(new PhysicalSocketServer()); 427 ss_.reset(new PhysicalSocketServer());
428 } 428 }
429 429
430 void TearDown() { 430 void TearDown() {
431 ss_.reset(NULL); 431 ss_.reset(nullptr);
432 signals_received_.clear(); 432 signals_received_.clear();
433 signaled_thread_ = NULL; 433 signaled_thread_ = nullptr;
434 } 434 }
435 435
436 bool ExpectSignal(int signum) { 436 bool ExpectSignal(int signum) {
437 if (signals_received_.empty()) { 437 if (signals_received_.empty()) {
438 LOG(LS_ERROR) << "ExpectSignal(): No signal received"; 438 LOG(LS_ERROR) << "ExpectSignal(): No signal received";
439 return false; 439 return false;
440 } 440 }
441 if (signals_received_[0] != signum) { 441 if (signals_received_[0] != signum) {
442 LOG(LS_ERROR) << "ExpectSignal(): Received signal " << 442 LOG(LS_ERROR) << "ExpectSignal(): Received signal " <<
443 signals_received_[0] << ", expected " << signum; 443 signals_received_[0] << ", expected " << signum;
(...skipping 12 matching lines...) Expand all
456 return ret; 456 return ret;
457 } 457 }
458 458
459 static std::vector<int> signals_received_; 459 static std::vector<int> signals_received_;
460 static Thread *signaled_thread_; 460 static Thread *signaled_thread_;
461 461
462 std::unique_ptr<PhysicalSocketServer> ss_; 462 std::unique_ptr<PhysicalSocketServer> ss_;
463 }; 463 };
464 464
465 std::vector<int> PosixSignalDeliveryTest::signals_received_; 465 std::vector<int> PosixSignalDeliveryTest::signals_received_;
466 Thread *PosixSignalDeliveryTest::signaled_thread_ = NULL; 466 Thread* PosixSignalDeliveryTest::signaled_thread_ = nullptr;
467 467
468 // Test receiving a synchronous signal while not in Wait() and then entering 468 // Test receiving a synchronous signal while not in Wait() and then entering
469 // Wait() afterwards. 469 // Wait() afterwards.
470 TEST_F(PosixSignalDeliveryTest, RaiseThenWait) { 470 TEST_F(PosixSignalDeliveryTest, RaiseThenWait) {
471 ASSERT_TRUE(ss_->SetPosixSignalHandler(SIGTERM, &RecordSignal)); 471 ASSERT_TRUE(ss_->SetPosixSignalHandler(SIGTERM, &RecordSignal));
472 raise(SIGTERM); 472 raise(SIGTERM);
473 EXPECT_TRUE(ss_->Wait(0, true)); 473 EXPECT_TRUE(ss_->Wait(0, true));
474 EXPECT_TRUE(ExpectSignal(SIGTERM)); 474 EXPECT_TRUE(ExpectSignal(SIGTERM));
475 EXPECT_TRUE(ExpectNone()); 475 EXPECT_TRUE(ExpectNone());
476 } 476 }
(...skipping 24 matching lines...) Expand all
501 } 501 }
502 502
503 class RaiseSigTermRunnable : public Runnable { 503 class RaiseSigTermRunnable : public Runnable {
504 void Run(Thread *thread) { 504 void Run(Thread *thread) {
505 thread->socketserver()->Wait(1000, false); 505 thread->socketserver()->Wait(1000, false);
506 506
507 // Allow SIGTERM. This will be the only thread with it not masked so it will 507 // Allow SIGTERM. This will be the only thread with it not masked so it will
508 // be delivered to us. 508 // be delivered to us.
509 sigset_t mask; 509 sigset_t mask;
510 sigemptyset(&mask); 510 sigemptyset(&mask);
511 pthread_sigmask(SIG_SETMASK, &mask, NULL); 511 pthread_sigmask(SIG_SETMASK, &mask, nullptr);
512 512
513 // Raise it. 513 // Raise it.
514 raise(SIGTERM); 514 raise(SIGTERM);
515 } 515 }
516 }; 516 };
517 517
518 // Test that it works no matter what thread the kernel chooses to give the 518 // Test that it works no matter what thread the kernel chooses to give the
519 // signal to (since it's not guaranteed to be the one that Wait() runs on). 519 // signal to (since it's not guaranteed to be the one that Wait() runs on).
520 TEST_F(PosixSignalDeliveryTest, SignalOnDifferentThread) { 520 TEST_F(PosixSignalDeliveryTest, SignalOnDifferentThread) {
521 ss_->SetPosixSignalHandler(SIGTERM, &RecordSignal); 521 ss_->SetPosixSignalHandler(SIGTERM, &RecordSignal);
522 // Mask out SIGTERM so that it can't be delivered to this thread. 522 // Mask out SIGTERM so that it can't be delivered to this thread.
523 sigset_t mask; 523 sigset_t mask;
524 sigemptyset(&mask); 524 sigemptyset(&mask);
525 sigaddset(&mask, SIGTERM); 525 sigaddset(&mask, SIGTERM);
526 EXPECT_EQ(0, pthread_sigmask(SIG_SETMASK, &mask, NULL)); 526 EXPECT_EQ(0, pthread_sigmask(SIG_SETMASK, &mask, nullptr));
527 // Start a new thread that raises it. It will have to be delivered to that 527 // Start a new thread that raises it. It will have to be delivered to that
528 // thread. Our implementation should safely handle it and dispatch 528 // thread. Our implementation should safely handle it and dispatch
529 // RecordSignal() on this thread. 529 // RecordSignal() on this thread.
530 std::unique_ptr<Thread> thread(new Thread()); 530 std::unique_ptr<Thread> thread(new Thread());
531 std::unique_ptr<RaiseSigTermRunnable> runnable(new RaiseSigTermRunnable()); 531 std::unique_ptr<RaiseSigTermRunnable> runnable(new RaiseSigTermRunnable());
532 thread->Start(runnable.get()); 532 thread->Start(runnable.get());
533 EXPECT_TRUE(ss_->Wait(1500, true)); 533 EXPECT_TRUE(ss_->Wait(1500, true));
534 EXPECT_TRUE(ExpectSignal(SIGTERM)); 534 EXPECT_TRUE(ExpectSignal(SIGTERM));
535 EXPECT_EQ(Thread::Current(), signaled_thread_); 535 EXPECT_EQ(Thread::Current(), signaled_thread_);
536 EXPECT_TRUE(ExpectNone()); 536 EXPECT_TRUE(ExpectNone());
537 } 537 }
538 538
539 #endif 539 #endif
540 540
541 } // namespace rtc 541 } // namespace rtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698