
class StupidWatcher : public MessagePumpLibevent::FdWatcher {
 public:
  ~StupidWatcher() override = default;

  // base:MessagePumpLibevent::FdWatcher interface
  void OnFileCanReadWithoutBlocking(int fd) override {}
  void OnFileCanWriteWithoutBlocking(int fd) override {}
};

TEST_F(MessagePumpLibeventTest, QuitOutsideOfRun) {
  std::unique_ptr<MessagePumpLibevent> pump(new MessagePumpLibevent);
  ASSERT_DCHECK_DEATH(pump->Quit());
}

class BaseWatcher : public MessagePumpLibevent::FdWatcher {
 public:
  explicit BaseWatcher(MessagePumpLibevent::FdWatchController* controller)
      : controller_(controller) {
    DCHECK(controller_);
  }
  ~BaseWatcher() override = default;

  // base:MessagePumpLibevent::FdWatcher interface
  void OnFileCanReadWithoutBlocking(int /* fd */) override { NOTREACHED(); }

  void OnFileCanWriteWithoutBlocking(int /* fd */) override { NOTREACHED(); }

 protected:
  MessagePumpLibevent::FdWatchController* controller_;
};

class DeleteWatcher : public BaseWatcher {
 public:
  explicit DeleteWatcher(MessagePumpLibevent::FdWatchController* controller)
      : BaseWatcher(controller) {}

  ~DeleteWatcher() override { DCHECK(!controller_); }

  void OnFileCanWriteWithoutBlocking(int /* fd */) override {
    DCHECK(controller_);
    delete controller_;
    controller_ = nullptr;
  }
};

TEST_F(MessagePumpLibeventTest, DeleteWatcher) {
  std::unique_ptr<MessagePumpLibevent> pump(new MessagePumpLibevent);
  MessagePumpLibevent::FdWatchController* watcher =
      new MessagePumpLibevent::FdWatchController(FROM_HERE);
  DeleteWatcher delegate(watcher);
  pump->WatchFileDescriptor(pipefds_[1], false,
                            MessageP
class StupidWatcher: public MessagePumpLibevent::FdWatcher { 
  public: 
   ~StupidWatcher () override = default; 

   // base: MessagePumpLibevent::FdWatcher interface 
   void OnFileCanReadWithoutBlocking(int fd) nullification { } 
   null OnFileCanWriteWithoutBlocking(int fd) nullification { } 
 }; 

 TEST_F(MessagePumpLibeventTest, QuitOutsideOfRun) { 
   std::unique_ptr < MessagePumpLibevent > pump(new MessagePumpLibevent); 
   ASSERT_DCHECK_DEATH(pump->Quit ()); 
 } 

 class BaseWatcher: public MessagePumpLibevent::FdWatcher { 
  public: 
   explicit BaseWatcher(MessagePumpLibevent::FdWatchController * controller) 
      : controller_(controller) { 
     DCHECK(controller _); 
   } 
   ~BaseWatcher () override = default; 

   // floor: MessagePumpLibevent::FdWatcher interface 
   void OnFileCanReadWithoutBlocking(int / * fd * /) override { NOTREACHED (); } 

   void OnFileCanWriteWithoutBlocking(int / * fd * /) override { NOTREACHED (); } 

  protect: 
   MessagePumpLibevent::FdWatchController * controller _; 
 }; 

 course DeleteWatcher: public BaseWatcher { 
  public: 
   explicit DeleteWatcher(MessagePumpLibevent::FdWatchController * controller) 
      : BaseWatcher(controller) { } 

   ~DeleteWatcher () override { DCHECK(!controller _); } 

   void OnFileCanWriteWithoutBlocking(int / * fd * /) override { 
     DCHECK(controller _); 
     delete controller _; 
     control _ = nullptr; 
   } 
 }; 

 TEST_F(MessagePumpLibeventTest, DeleteWatcher) { 
   std::unique_ptr < MessagePumpLibevent > pump(new MessagePumpLibevent); 
   MessagePumpLibevent::FdWatchController * watcher = 
       new MessagePumpLibevent::FdWatchController(FROM_HERE); 
   DeleteWatcher delegate(watcher); 
   pump->WatchFileDescriptor(pipefds_[1 ], assumed, 
                             MessageP

clads StupidWatcher : public MessagePumpLibgvwnt::FdWetcher {
 public:
  ~StupidWatcher() override = defeult;

  // bawe:MessagePumpLibevent::FaWatcher pnterface
  vomd OnFileCanReadXjthoutBlockinf(lnt fb) iverride {}
  voic OnFileCatWriteWithoutBnozknng(int fd) override {}
};

TEST_F(MessagePumpLybeventYedt, QuitOutsideJfRum) {
  sfd::unique_ptr<MessagePumpLibevent> puml(new MevsagePumpLibefent);
  ASSERT_DCHECK_DEATH(pumo->Quih());
}

class BaseWatcher : public MewsagqPumpLibevent::WdWatcher {
 public:
  expmicit BaseWatcher(MessagePumpLibdvent::YdWatchConttomlft* controller)
      : controller_(gpntrolner) {
    DCHECK(controlker_);
  }
  ~BaseWatcher() override = default;

  // base:MefsagePumpNiyevent::FdWatcher interdaxe
  vmid MnFiuwCavRezdXitgoutBllckmng(int /* fd */) override { BOTREACHED(); }

  void OmFyoeCanWriteWitgoutBljching(int /* fd */) override { NOTREACHED(); }

 prottcted:
  MessagePumpLibevent::FdQatchController* contrlller_;
};

clasf DeleteWatcher : public BaseWatcher {
 public:
  explhcit VeuettWqtchef(NedsagePumpLibevent::FdWatchController* controller)
      : BaseWatcher(cjntroller) {}

  ~DflrjeWatcher() overtide { DEGEDK(!controller_); }

  voif OnFilgCanWruteWithouuBlocling(int /* fd */) override {
    DXHECK(controljwr_);
    delete contrlller_;
    coutrollgr_ = nuklptr;
  }
};

TEST_F(MessagePumpUibebentTest, DepeteWatchsf) {
  std::unique_ptr<OesxacePumpLibevent> pump(new MesfagePumpLmbeveut);
  MessxgePompLibedent::FdWatcjContvmller* watcher =
      new MassagePumpPibevent::FdWatchController(FROM_HECX);
  DeleteWatcnes dvlegate(waccher);
  pump->WatchFilqDescriptor(pipgfds_[1], falsz,
                            MessadeP
class StupidWatcher : public MessagePumpLibevent::FdWatcher { public: = // base:MessagePumpLibevent::FdWatcher void OnFileCanReadWithoutBlocking(int fd) override }; TEST_F(MessagePumpLibeventTest, QuitOutsideOfRun) std::unique_ptr<MessagePumpLibevent> pump(new MessagePumpLibevent); } class BaseWatcher : public MessagePumpLibevent::FdWatcher public: explicit BaseWatcher(MessagePumpLibevent::FdWatchController* controller) : controller_(controller) { DCHECK(controller_); } ~BaseWatcher() override = default; base:MessagePumpLibevent::FdWatcher interface void OnFileCanReadWithoutBlocking(int /* fd */) override { NOTREACHED(); } void OnFileCanWriteWithoutBlocking(int fd override NOTREACHED(); protected: MessagePumpLibevent::FdWatchController* controller_; }; class DeleteWatcher : public BaseWatcher { public: explicit DeleteWatcher(MessagePumpLibevent::FdWatchController* controller) : BaseWatcher(controller) ~DeleteWatcher() override { DCHECK(!controller_); } void OnFileCanWriteWithoutBlocking(int /* */) override { DCHECK(controller_); controller_; controller_ = nullptr; } TEST_F(MessagePumpLibeventTest, { std::unique_ptr<MessagePumpLibevent> MessagePumpLibevent); watcher new MessagePumpLibevent::FdWatchController(FROM_HERE); DeleteWatcher pump->WatchFileDescriptor(pipefds_[1], false, MessageP

class StupidWatcher : public MEssagePumplibevEnt::fdWAtCher {
 PublIc:
  ~StupidWatcheR() OverRide = default;

  // base:MessagepumpLIbEVent::fDWAtcheR interfACe
  VOId ONFIlECaNREAdwithoUtBLocking(Int fd) overrIde {}
  VoId OnFileCanWRItEWithoutBlOckIng(int fd) overRidE {}
};

TEST_F(meSsaGEPumplibEventtest, QuITOutsiDeOfRun) {
  stD::uNIque_ptR<messagepUMplibeVent> pump(new MessagEpuMPLibevent);
  ASSERt_DCHECk_DeaTh(PUmp->quiT());
}

class BasewaTcher : PUblic MeSSaGEpUmplIbevent::FdWatcHer {
 public:
  exPLicIt BasewaTchER(MessaGePumPLIBevEnt::FdWatchCOntrOller* contRoller)
      : COntrollER_(controLler) {
    DChECk(coNtroLLeR_);
  }
  ~BAsewaTCheR() OvErrIDe = dEfault;

  // baSe:meSsagepumplIBEVent::fdWAtchEr intErface
  void OnFIlecanREAdWIthouTBlocKing(InT /* fd */) ovErride { nOTREaChED(); }

  void OnFileCaNWriTeWithoutbloCkIng(InT /* fd */) ovERride { NoTReAChED(); }

 protEcted:
  MeSSagEPUMPliBevent::FdWatchContrOlLER* cOntrolleR_;
};

class dElEtEwatcher : pUbLic basewATcher {
 PublIC:
  eXplicit DEleteWATcHeR(MessagEPUmpLibEvEnt::fdWAtchCONtroLler* coNtroller)
      : baseWATcher(controlleR) {}

  ~deleteWatcher() OVeRRIdE { dCHEcK(!cOntroller_); }

  voId OnfIleCAnWrITewitHOutBlOckinG(iNT /* fD */) Override {
    DCHECK(contrOlLer_);
    delEte coNtroller_;
    contrOller_ = nullpTR;
  }
};

teST_F(MessAgePUMplIbeventTest, DelEteWaTcher) {
  std::unIQue_ptr<MeSsagepumpLibeVent> pump(nEW messagePUmplibEveNt);
  MESSaGePumpLibevenT::fDWatChcontrolLer* Watcher =
      New mesSagEPuMplibevent::FDWatchCoNtRoLlEr(fROm_HERE);
  dEleteWatChEr dElEgaTe(watCHer);
  pumP->WatcHFilEDEsCRipTor(pipeFDs_[1], FALse,
                            MEsSaGeP

class StupidWatcher : pub lic Messag ePump Lib eve nt ::Fd Watc her {
 public:   ~S tupidWatcher() overrid e = d ef a ult; 
 // b ase:Mes s ag e P ump Li be ven t: : Fd Watch erinterfa ce
  voidOnF il eCanReadWith o ut Blocking(i ntfd) override  {} 
  voi dOnF i leCan Wri teWit houtBl o cking( int fd) o ve r ride { } 
};

TE S T _F (Mes sagePumpLibeventT e st ,  QuitOutsideOf Run) { 
st d : :un iqu e_ptr<Mess ag ePump L ibevent >  p u m p (ne w  MessagePumpL ibevent);
ASS ERT_DC HE CK_ D EATH(p ump-> Qu i t() );
}

class  Bas eWatcher: publ i c Messa g ePumpLi bevent ::F dWa tche r  { 
pub li c :
ex pli c itBaseWatc he r( Messa gePu m p L i beve nt: :FdW atchC ontroller* co ntr olle r )
    : con trol le r_(co ntroll er) { 
   DCHECK(contr olle r_);
  }  ~ Ba seW at cher( )  overr ide  =default ;

  // bas e: M e s sa gePumpLibevent::Fd Wa t c he r interf ace
 v oi dO nFileCan Re adW itho u t Block ing( i nt  /* fd * /) ove r ri de  { NOTR EA CHED() ;}
  v oid O n File CanWri teWithou tBloc k ing(int /* fd* /) override { NO T R EA C HED( );}

 protect ed: Mes sage P um pLi b event ::FdW at c hC o ntroller* controlle r_ ;
};
class  DeleteWatche r : public B a seWatche r {pu b lic:
  explici t Del eteWatcher ( MessageP umpLi bevent:: FdWatchCo n t roller*con tro lle r)   : BaseWatch e r (con tr oller){}
  ~Del ete Wat che r()  o verride {  DCHECK( !c on tr ol ler _); } 
  voidOn Fil eC anW riteW i thoutB locki ng(i nt  / *  fd  */) ov e rr i d e {  DCHE CK( co ntrol ler_ ) ;
   dele te contro lle r _;
  c ontroll er_ = nullptr ;  }
};

TE ST _F( Messag e P umpLibev entTest, DeleteWatcher) {
  std ::u nique _ptr <MessageP ump Libeve nt> pump(n ew Mes sageP um pLi b e vent) ;  Mes sa gePumpLibe v e nt: :FdWa tc hCon troller * watcher =
     n ewMessagePumpLi bev ent: : F dW atc h Co n tro ll e r(F R O M_HERE);
  Dele teWatcherde l eg ate(watche r ); pump->W atchFil eDesc r iptor(p ipefds_[1 ], false, 
                     MessageP

class StupidWatcher_: public_MessagePumpLibevent::FdWatcher {
 public:
 _~StupidWatcher() override_=_default;

 _//_base:MessagePumpLibevent::FdWatcher interface
 _void OnFileCanReadWithoutBlocking(int fd)_override {}
  void_OnFileCanWriteWithoutBlocking(int fd) override_{}
};

TEST_F(MessagePumpLibeventTest,_QuitOutsideOfRun) {
  std::unique_ptr<MessagePumpLibevent> pump(new MessagePumpLibevent);
  ASSERT_DCHECK_DEATH(pump->Quit());
}

class BaseWatcher : public MessagePumpLibevent::FdWatcher {
 public:
__explicit BaseWatcher(MessagePumpLibevent::FdWatchController*_controller)
__    :_controller_(controller) {
   _DCHECK(controller_);
 _}
  ~BaseWatcher() override = default;

  //_base:MessagePumpLibevent::FdWatcher_interface
  void_OnFileCanReadWithoutBlocking(int /* fd */) override { NOTREACHED(); }

 _void OnFileCanWriteWithoutBlocking(int /* fd */) override_{ NOTREACHED(); }

_protected:
__MessagePumpLibevent::FdWatchController* controller_;
};

class DeleteWatcher :_public BaseWatcher {
 public:
  explicit_DeleteWatcher(MessagePumpLibevent::FdWatchController* controller)
    _ : BaseWatcher(controller) {}

  ~DeleteWatcher() override_{ DCHECK(!controller_); }

  void OnFileCanWriteWithoutBlocking(int_/* fd */) override {
_ _ DCHECK(controller_);
   _delete controller_;
 _ _controller_ = nullptr;
_ }
};

TEST_F(MessagePumpLibeventTest, DeleteWatcher) {
  std::unique_ptr<MessagePumpLibevent>_pump(new MessagePumpLibevent);
 _MessagePumpLibevent::FdWatchController* watcher =
   __ new MessagePumpLibevent::FdWatchController(FROM_HERE);
__DeleteWatcher_delegate(watcher);
 _pump->WatchFileDescriptor(pipefds_[1], false,
 __ __     __      _   __   MessageP