コード例 #1
0
ファイル: http_tests.cpp プロジェクト: abhishekamralkar/mesos
TEST(HTTP, Get)
{
  ASSERT_TRUE(GTEST_IS_THREADSAFE);

  HttpProcess process;

  spawn(process);

  EXPECT_CALL(process, get(_))
    .WillOnce(Invoke(validateGetWithoutQuery));

  Future<http::Response> noQueryFuture = http::get(process.self(), "get");

  AWAIT_READY(noQueryFuture);
  ASSERT_EQ(http::statuses[200], noQueryFuture.get().status);

  EXPECT_CALL(process, get(_))
    .WillOnce(Invoke(validateGetWithQuery));

  Future<http::Response> queryFuture =
    http::get(process.self(), "get", "foo=bar");

  AWAIT_READY(queryFuture);
  ASSERT_EQ(http::statuses[200], queryFuture.get().status);

  terminate(process);
  wait(process);
}
コード例 #2
0
TEST_F(TeleCommandHandlingTest, HandlerShouldBeCalledForKnownTelecommand)
{
    std::uint8_t buffer[40] = "ABCD";
    CommFrame frame(0, 0, 0, buffer);

    EXPECT_CALL(this->deps, Decrypt(_, _)).WillOnce(Invoke([](span<const uint8_t> frame, span<uint8_t> decrypted) {
        auto lastCopied = std::copy(frame.cbegin(), frame.cend(), decrypted.begin());

        auto decryptedDataLength = lastCopied - decrypted.begin();

        return DecryptFrameResult::Success(decrypted.subspan(0, decryptedDataLength));
    }));
    EXPECT_CALL(this->deps, Decode(_)).WillOnce(Invoke([](span<const uint8_t> frame) {
        return DecodeTelecommandResult::Success(frame[0], frame.subspan(1, frame.length() - 1));
    }));

    NiceMock<TeleCommandHandlerMock> someCommand;
    EXPECT_CALL(someCommand, Handle(_, _));
    EXPECT_CALL(someCommand, CommandCode()).WillRepeatedly(Return(static_cast<uint8_t>('A')));

    IHandleTeleCommand* commands[] = {&someCommand};

    IncomingTelecommandHandler handler(deps, deps, span<IHandleTeleCommand*>(commands));

    handler.HandleFrame(this->transmitFrame, frame);
}
コード例 #3
0
ファイル: mesos.cpp プロジェクト: namminammi/mesos
MockSlave::MockSlave(const slave::Flags& flags,
                     MasterDetector* detector,
                     slave::Containerizer* containerizer,
                     const Option<mesos::slave::QoSController*>& _qosController)
  : slave::Slave(
      flags,
      detector,
      containerizer,
      &files,
      &gc,
      statusUpdateManager = new slave::StatusUpdateManager(flags),
      &resourceEstimator,
      _qosController.isSome() ? _qosController.get() : &qosController)
{
  // Set up default behaviors, calling the original methods.
  EXPECT_CALL(*this, runTask(_, _, _, _, _))
    .WillRepeatedly(Invoke(this, &MockSlave::unmocked_runTask));
  EXPECT_CALL(*this, _runTask(_, _, _, _))
    .WillRepeatedly(Invoke(this, &MockSlave::unmocked__runTask));
  EXPECT_CALL(*this, killTask(_, _, _))
    .WillRepeatedly(Invoke(this, &MockSlave::unmocked_killTask));
  EXPECT_CALL(*this, removeFramework(_))
    .WillRepeatedly(Invoke(this, &MockSlave::unmocked_removeFramework));
  EXPECT_CALL(*this, __recover(_))
    .WillRepeatedly(Invoke(this, &MockSlave::unmocked___recover));
}
コード例 #4
0
ファイル: mesos.cpp プロジェクト: dpravat/mesos
MockFetcherProcess::MockFetcherProcess()
{
  // Set up default behaviors, calling the original methods.
  EXPECT_CALL(*this, _fetch(_, _, _, _, _, _))
    .WillRepeatedly(Invoke(this, &MockFetcherProcess::unmocked__fetch));
  EXPECT_CALL(*this, run(_, _, _, _, _))
    .WillRepeatedly(Invoke(this, &MockFetcherProcess::unmocked_run));
}
コード例 #5
0
ファイル: mesos.cpp プロジェクト: sunnyap/mesos
MockDockerContainerizerProcess::MockDockerContainerizerProcess(
    const slave::Flags& flags,
    slave::Fetcher* fetcher,
    const process::Shared<Docker>& docker)
  : slave::DockerContainerizerProcess(flags, fetcher, docker)
{
  EXPECT_CALL(*this, fetch(_, _))
    .WillRepeatedly(Invoke(this, &MockDockerContainerizerProcess::_fetch));

  EXPECT_CALL(*this, pull(_))
    .WillRepeatedly(Invoke(this, &MockDockerContainerizerProcess::_pull));
}
コード例 #6
0
ファイル: http_tests.cpp プロジェクト: Hadoyy/mesos
TEST(HTTP, Post)
{
  ASSERT_TRUE(GTEST_IS_THREADSAFE);

  HttpProcess process;

  spawn(process);

  // Test the case where there is a content type but no body.
  Future<http::Response> future =
    http::post(process.self(), "post", None(), "text/plain");

  AWAIT_EXPECT_FAILED(future);

  EXPECT_CALL(process, post(_))
    .WillOnce(Invoke(validatePost));

  future =
    http::post(process.self(), "post", "This is the payload.", "text/plain");

  AWAIT_READY(future);
  ASSERT_EQ(http::statuses[200], future.get().status);

  terminate(process);
  wait(process);
}
コード例 #7
0
ファイル: store.hpp プロジェクト: 447327642/mesos
  TestStore(const hashmap<std::string, process::Shared<Rootfs>>& _rootfses)
      : rootfses(_rootfses)
  {
    using testing::_;
    using testing::DoDefault;
    using testing::Invoke;

    ON_CALL(*this, recover())
      .WillByDefault(Invoke(this, &TestStore::unmocked_recover));
    EXPECT_CALL(*this, recover())
      .WillRepeatedly(DoDefault());

    ON_CALL(*this, get(_))
      .WillByDefault(Invoke(this, &TestStore::unmocked_get));
    EXPECT_CALL(*this, get(_))
      .WillRepeatedly(DoDefault());
  }
コード例 #8
0
ファイル: mesos.cpp プロジェクト: sunnyap/mesos
MockDocker::MockDocker(
    const std::string& path,
    const std::string &socket)
  : Docker(path, socket)
{
  EXPECT_CALL(*this, pull(_, _, _))
    .WillRepeatedly(Invoke(this, &MockDocker::_pull));

  EXPECT_CALL(*this, stop(_, _, _))
    .WillRepeatedly(Invoke(this, &MockDocker::_stop));

  EXPECT_CALL(*this, run(_, _, _, _, _, _, _, _, _))
    .WillRepeatedly(Invoke(this, &MockDocker::_run));

  EXPECT_CALL(*this, inspect(_, _))
    .WillRepeatedly(Invoke(this, &MockDocker::_inspect));
}
コード例 #9
0
ファイル: mesos.cpp プロジェクト: dpravat/mesos
MockDocker::MockDocker(
    const string& path,
    const string& socket,
    const Option<JSON::Object>& config)
  : Docker(path, socket, config)
{
  EXPECT_CALL(*this, ps(_, _))
    .WillRepeatedly(Invoke(this, &MockDocker::_ps));

  EXPECT_CALL(*this, pull(_, _, _))
    .WillRepeatedly(Invoke(this, &MockDocker::_pull));

  EXPECT_CALL(*this, stop(_, _, _))
    .WillRepeatedly(Invoke(this, &MockDocker::_stop));

  EXPECT_CALL(*this, run(_, _, _, _, _, _, _, _, _, _))
    .WillRepeatedly(Invoke(this, &MockDocker::_run));

  EXPECT_CALL(*this, inspect(_, _))
    .WillRepeatedly(Invoke(this, &MockDocker::_inspect));
}
コード例 #10
0
ファイル: http_tests.cpp プロジェクト: ankurcha/mesos
TEST(HTTP, Get)
{
  Http http;

  EXPECT_CALL(*http.process, get(_))
    .WillOnce(Invoke(validateGetWithoutQuery));

  Future<http::Response> noQueryFuture = http::get(http.process->self(), "get");

  AWAIT_READY(noQueryFuture);
  ASSERT_EQ(http::statuses[200], noQueryFuture.get().status);

  EXPECT_CALL(*http.process, get(_))
    .WillOnce(Invoke(validateGetWithQuery));

  Future<http::Response> queryFuture =
    http::get(http.process->self(), "get", "foo=bar");

  AWAIT_READY(queryFuture);
  ASSERT_EQ(http::statuses[200], queryFuture.get().status);
}
コード例 #11
0
ファイル: mesos.cpp プロジェクト: hgschmie/mesos
MockSlave::MockSlave(const slave::Flags& flags,
                     MasterDetector* detector,
                     slave::Containerizer* containerizer)
  : slave::Slave(
      flags,
      detector,
      containerizer,
      &files,
      &gc,
      statusUpdateManager = new slave::StatusUpdateManager(flags))
{
  // Set up default behaviors, calling the original methods.
  EXPECT_CALL(*this, runTask(_, _, _, _, _)).
      WillRepeatedly(Invoke(this, &MockSlave::unmocked_runTask));
  EXPECT_CALL(*this, _runTask(_, _, _, _, _)).
      WillRepeatedly(Invoke(this, &MockSlave::unmocked__runTask));
  EXPECT_CALL(*this, killTask(_, _, _)).
      WillRepeatedly(Invoke(this, &MockSlave::unmocked_killTask));
  EXPECT_CALL(*this, removeFramework(_)).
      WillRepeatedly(Invoke(this, &MockSlave::unmocked_removeFramework));
}
コード例 #12
0
ファイル: miniport.cpp プロジェクト: PW-Sat2/PWSat2OBC
TEST_F(AntennaMiniportTest, TestAntennaActivationTime)
{
    EXPECT_CALL(i2c, WriteRead(ANTENNA_PRIMARY_CHANNEL, ElementsAre(QueryActivationTime1), _))
        .WillOnce(Invoke([=](uint8_t /*address*/, span<const uint8_t> /*inData*/, span<uint8_t> outData) {
            std::fill(outData.begin(), outData.end(), 0);
            outData[0] = 10;
            return I2CResult::OK;
        }));
    TimeSpan response;
    const auto status = miniport.GetAntennaActivationTime(&miniport, &i2c, ANTENNA_PRIMARY_CHANNEL, ANTENNA1_ID, &response);
    ASSERT_THAT(status, Eq(OSResult::Success));
    ASSERT_THAT(response, Eq(TimeSpanFromMilliseconds(128000)));
}
コード例 #13
0
ファイル: provisioner.hpp プロジェクト: CodeTickler/mesos
  TestProvisioner(const process::Shared<Rootfs>& _rootfs)
    : rootfs(_rootfs)
  {
    using testing::_;
    using testing::DoDefault;
    using testing::Invoke;

    ON_CALL(*this, recover(_, _))
      .WillByDefault(Invoke(this, &TestProvisioner::unmocked_recover));
    EXPECT_CALL(*this, recover(_, _))
      .WillRepeatedly(DoDefault());

    ON_CALL(*this, provision(_, _))
      .WillByDefault(Invoke(this, &TestProvisioner::unmocked_provision));
    EXPECT_CALL(*this, provision(_, _))
      .WillRepeatedly(DoDefault());

    ON_CALL(*this, destroy(_))
      .WillByDefault(Invoke(this, &TestProvisioner::unmocked_destroy));
    EXPECT_CALL(*this, destroy(_))
      .WillRepeatedly(DoDefault());
  }
コード例 #14
0
ファイル: http_tests.cpp プロジェクト: ConnorDoyle/mesos
TEST(HTTPTest, Delete)
{
  Http http;

  EXPECT_CALL(*http.process, requestDelete(_))
    .WillOnce(Invoke(validateDelete));

  Future<http::Response> future =
    http::requestDelete(http.process->self(), "delete", None());

  AWAIT_READY(future);
  ASSERT_EQ(http::statuses[200], future.get().status);
}
コード例 #15
0
ファイル: http_tests.cpp プロジェクト: haosdent/mesos
TEST(HTTPTest, Post)
{
  Http http;

  // Test the case where there is a content type but no body.
  Future<http::Response> future =
    http::post(http.process->self(), "post", None(), None(), "text/plain");

  AWAIT_EXPECT_FAILED(future);

  EXPECT_CALL(*http.process, post(_))
    .WillOnce(Invoke(validatePost));

  future = http::post(
      http.process->self(),
      "post",
      None(),
      "This is the payload.",
      "text/plain");

  AWAIT_READY(future);
  ASSERT_EQ(http::Status::OK, future->code);
  ASSERT_EQ(http::Status::string(http::Status::OK), future->status);

  // Now test passing headers instead.
  http::Headers headers;
  headers["Content-Type"] = "text/plain";

  EXPECT_CALL(*http.process, post(_))
    .WillOnce(Invoke(validatePost));

  future =
    http::post(http.process->self(), "post", headers, "This is the payload.");

  AWAIT_READY(future);
  ASSERT_EQ(http::Status::OK, future->code);
  ASSERT_EQ(http::Status::string(http::Status::OK), future->status);
}
コード例 #16
0
ファイル: http_tests.cpp プロジェクト: haosdent/mesos
TEST(HTTPTest, Get)
{
  Http http;

  EXPECT_CALL(*http.process, get(_))
    .WillOnce(Invoke(validateGetWithoutQuery));

  Future<http::Response> noQueryFuture = http::get(http.process->self(), "get");

  AWAIT_READY(noQueryFuture);
  EXPECT_EQ(http::Status::OK, noQueryFuture->code);
  EXPECT_EQ(http::Status::string(http::Status::OK), noQueryFuture->status);

  EXPECT_CALL(*http.process, get(_))
    .WillOnce(Invoke(validateGetWithQuery));

  Future<http::Response> queryFuture =
    http::get(http.process->self(), "get", "foo=bar");

  AWAIT_READY(queryFuture);
  ASSERT_EQ(http::Status::OK, queryFuture->code);
  ASSERT_EQ(http::Status::string(http::Status::OK), queryFuture->status);
}
コード例 #17
0
ファイル: miniport.cpp プロジェクト: PW-Sat2/PWSat2OBC
TEST_F(AntennaMiniportTest, TestAntennaTemperatureOutOfRange)
{
    EXPECT_CALL(i2c, WriteRead(ANTENNA_PRIMARY_CHANNEL, ElementsAre(QueryTemperature), _))
        .WillOnce(Invoke([=](uint8_t /*address*/, span<const uint8_t> /*inData*/, span<uint8_t> outData) {
            std::fill(outData.begin(), outData.end(), 0);
            outData[0] = 0xfc;
            outData[1] = 0;
            return I2CResult::OK;
        }));
    uint16_t response;
    const auto status = miniport.GetTemperature(&miniport, &i2c, ANTENNA_PRIMARY_CHANNEL, &response);
    ASSERT_THAT(status, Eq(OSResult::OutOfRange));
    ASSERT_THAT(response, Eq(0));
}
コード例 #18
0
ファイル: miniport.cpp プロジェクト: PW-Sat2/PWSat2OBC
void AntennaDeploymentStatusTest::MockI2C()
{
    const auto response1 = std::get<0>(GetParam());
    const auto response2 = std::get<1>(GetParam());
    const auto i2cResult = std::get<2>(GetParam());

    EXPECT_CALL(i2c, WriteRead(ANTENNA_PRIMARY_CHANNEL, ElementsAre(QueryDeploymentStatus), _))
        .WillOnce(Invoke([=](uint8_t /*address*/, span<const uint8_t> /*inData*/, span<uint8_t> outData) {
            std::fill(outData.begin(), outData.end(), 0);
            outData[0] = response1;
            outData[1] = response2;
            return i2cResult;
        }));
}
コード例 #19
0
ファイル: http_tests.cpp プロジェクト: haosdent/mesos
TEST(HTTPTest, Request)
{
  Http http;

  EXPECT_CALL(*http.process, request(_))
    .WillOnce(Invoke(validateDeleteHttpRequest));

  Future<http::Response> future =
    http::request(http::createRequest(
        http.process->self(), "DELETE", false, "request"));

  AWAIT_READY(future);
  ASSERT_EQ(http::Status::OK, future->code);
  ASSERT_EQ(http::Status::string(http::Status::OK), future->status);
}
コード例 #20
0
ファイル: antenna.cpp プロジェクト: PW-Sat2/PWSat2OBC
TEST_F(AntennaDriverTest, TestGetTemperature)
{
    EXPECT_CALL(primary, GetTemperature(ANTENNA_PRIMARY_CHANNEL, _))
        .WillOnce(Invoke([](AntennaChannel channel, uint16_t* value) //
            {
                UNREFERENCED_PARAMETER(channel);
                *value = 10;
                return OSResult::Success;
            }));

    uint16_t result;
    const auto status = driver.GetTemperature(&driver, ANTENNA_PRIMARY_CHANNEL, &result);
    ASSERT_THAT(status, Eq(OSResult::Success));
    ASSERT_THAT(result, Eq(10));
}
コード例 #21
0
ファイル: SmartWait.cpp プロジェクト: PW-Sat2/PWSat2OBC
TEST_F(SmartWaitTest, ShouldWaitForPulseAndReturnIfMissionTimeJumpsOverDesiredTime)
{
    timeProvider.CurrentTime = TimePointToTimeSpan(TimePointBuild(0, 0, 0, 0, 0));

    EXPECT_CALL(osMock, PulseWait(_, _))
    .Times(11)
    .WillRepeatedly(Invoke([&](OSPulseHandle handle, const OSTaskTimeSpan timeout) {
        UNUSED(handle, timeout);

        timeProvider.CurrentTime = TimeSpanAdd(timeProvider.CurrentTime, TimeSpanFromMinutes(1));
        return OSResult::Success;
    }));

    auto result = TimeLongDelayUntil(&timeProvider, TimePointBuild(0, 0, 10, 30, 0));

    ASSERT_THAT(result, Eq(true));
}
コード例 #22
0
ファイル: adxrs453Test.cpp プロジェクト: PW-Sat2/PWSat2OBC
TEST_F(adxrs453Test, TestGetRateResponseForNormalValues)
{
    SPIDRV_HandleData_t handleData;
    SPIDRV_Handle_t handle = &handleData;
    GyroInterface_t interface;
    interface.writeProc = TestSPIWrite;
    interface.readProc = TestSPIWriteRead;
    gyro.interface = interface;
    EXPECT_CALL(spimock, SPIWriteRead(_, _, _, _))
        .WillRepeatedly(Invoke([](ADXRS453_PinLocations_t*, SPIDRV_Handle_t, const void* buffer, uint8_t) {
            *((uint8_t*)buffer) = 0x5E;
            *((uint8_t*)buffer + 1) = 0x01;
            *((uint8_t*)buffer + 2) = 0x01;
            *((uint8_t*)buffer + 3) = 0xFF;
            SPI_TransferPairResultCode okresult;
            okresult.resultCodeWrite = ECODE_OK;
            okresult.resultCodeRead = ECODE_OK;
            return okresult;
        }));
    SPI_TransferReturn result = ADXRS453_GetRate(&gyro, handle);
    EXPECT_EQ(result.resultCodes.resultCodeWrite, ECODE_OK);
    EXPECT_EQ(result.resultCodes.resultCodeRead, ECODE_OK);
    EXPECT_EQ(result.result.sensorResult, 25);
}
コード例 #23
0
ファイル: slave_tests.cpp プロジェクト: JianYuan1999/mesos
// This test ensures that a killTask() can happen between runTask()
// and _runTask() and then gets "handled properly". This means that
// the task never gets started, but also does not get lost. The end
// result is status TASK_KILLED. Essentially, killing the task is
// realized while preparing to start it. See MESOS-947.
// Temporarily disabled due to MESOS-1945.
TEST_F(SlaveTest, DISABLED_KillTaskBetweenRunTaskParts)
{
  Try<PID<Master> > master = StartMaster();
  ASSERT_SOME(master);

  MockExecutor exec(DEFAULT_EXECUTOR_ID);

  TestContainerizer containerizer(&exec);

  StandaloneMasterDetector detector(master.get());

  MockSlave slave(CreateSlaveFlags(), &detector, &containerizer);
  process::spawn(slave);

  MockScheduler sched;
  MesosSchedulerDriver driver(
      &sched, DEFAULT_FRAMEWORK_INFO, master.get(), DEFAULT_CREDENTIAL);

  EXPECT_CALL(sched, registered(&driver, _, _))
    .Times(1);

  Future<vector<Offer> > offers;
  EXPECT_CALL(sched, resourceOffers(&driver, _))
    .WillOnce(FutureArg<1>(&offers))
    .WillRepeatedly(Return()); // Ignore subsequent offers.

  driver.start();

  AWAIT_READY(offers);
  EXPECT_NE(0u, offers.get().size());

  TaskInfo task;
  task.set_name("");
  task.mutable_task_id()->set_value("1");
  task.mutable_slave_id()->MergeFrom(offers.get()[0].slave_id());
  task.mutable_resources()->MergeFrom(offers.get()[0].resources());
  task.mutable_executor()->MergeFrom(DEFAULT_EXECUTOR_INFO);

  vector<TaskInfo> tasks;
  tasks.push_back(task);

  EXPECT_CALL(exec, registered(_, _, _, _))
    .Times(0);

  EXPECT_CALL(exec, launchTask(_, _))
    .Times(0);

  EXPECT_CALL(exec, shutdown(_))
    .Times(0);

  Future<TaskStatus> status;
  EXPECT_CALL(sched, statusUpdate(&driver, _))
    .WillRepeatedly(FutureArg<1>(&status));

  EXPECT_CALL(slave, runTask(_, _, _, _, _))
    .WillOnce(Invoke(&slave, &MockSlave::unmocked_runTask));

  // Saved arguments from Slave::_runTask().
  Future<bool> future;
  FrameworkInfo frameworkInfo;
  FrameworkID frameworkId;

  // Skip what Slave::_runTask() normally does, save its arguments for
  // later, tie reaching the critical moment when to kill the task to
  // a future.
  Future<Nothing> _runTask;
  EXPECT_CALL(slave, _runTask(_, _, _, _, _))
    .WillOnce(DoAll(FutureSatisfy(&_runTask),
                    SaveArg<0>(&future),
                    SaveArg<1>(&frameworkInfo),
                    SaveArg<2>(&frameworkId)));

  driver.launchTasks(offers.get()[0].id(), tasks);

  AWAIT_READY(_runTask);

  Future<Nothing> killTask;
  EXPECT_CALL(slave, killTask(_, _, _))
    .WillOnce(DoAll(Invoke(&slave, &MockSlave::unmocked_killTask),
                    FutureSatisfy(&killTask)));
  driver.killTask(task.task_id());

  // Since this is the only task ever for this framework, the
  // framework should get removed in Slave::_runTask().
  // Thus we can observe that this happens before Shutdown().
  Future<Nothing> removeFramework;
  EXPECT_CALL(slave, removeFramework(_))
    .WillOnce(DoAll(Invoke(&slave, &MockSlave::unmocked_removeFramework),
                    FutureSatisfy(&removeFramework)));

  AWAIT_READY(killTask);
  slave.unmocked__runTask(
      future, frameworkInfo, frameworkId, master.get(), task);

  AWAIT_READY(removeFramework);

  AWAIT_READY(status);
  EXPECT_EQ(TASK_KILLED, status.get().state());

  driver.stop();
  driver.join();

  process::terminate(slave);
  process::wait(slave);

  Shutdown(); // Must shutdown before 'containerizer' gets deallocated.
}
コード例 #24
0
 WebClientTest()
   : receiver(GetTestMessage(), mock_endpoint)
 {
   ON_CALL(mock_endpoint, Loop(_)).WillByDefault(Invoke(boost::bind(&ReceiveOneMessage::Loop, &receiver, _1)));
 }
コード例 #25
0
ファイル: IRCSockTest.cpp プロジェクト: DarthGandalf/znc
TEST_F(IRCSockTest, OnActionMessage) {
    // 2 callbacks are called in row: OnCTCP, OnAction.
    // If OnCTCP returns HALT, OnAction isn't called.
    struct ActionModule : TestModule {
        ActionModule() { Reset(); }
        void Reset() {
            Mock::VerifyAndClear(this);
            EXPECT_CALL(*this, OnPrivCTCPMessage(_)).Times(0);
            EXPECT_CALL(*this, OnChanCTCPMessage(_)).Times(0);
            EXPECT_CALL(*this, OnPrivActionMessage(_)).Times(0);
            EXPECT_CALL(*this, OnChanActionMessage(_)).Times(0);
            TestModule::Reset();
        }
        MOCK_METHOD1(OnPrivCTCPMessage, EModRet(CCTCPMessage&));
        MOCK_METHOD1(OnChanCTCPMessage, EModRet(CCTCPMessage&));
        MOCK_METHOD1(OnPrivActionMessage, EModRet(CActionMessage&));
        MOCK_METHOD1(OnChanActionMessage, EModRet(CActionMessage&));
    };
    ActionModule testModule;
    CZNC::Get().GetModules().push_back(&testModule);
    CChan* pExpectedChan = m_pTestChan;

    CMessage msg(":nick PRIVMSG #chan :\001ACTION hello\001");
    auto CON = Invoke([&](CMessage& m) {
        EXPECT_EQ(m.ToString(), msg.ToString());
        EXPECT_EQ(m.GetNetwork(), m_pTestNetwork);
        EXPECT_EQ(m.GetChan(), pExpectedChan);
        return CModule::CONTINUE;
    });
    auto HAL = Invoke([&](CMessage& m) {
        EXPECT_EQ(m.ToString(), msg.ToString());
        EXPECT_EQ(m.GetNetwork(), m_pTestNetwork);
        EXPECT_EQ(m.GetChan(), pExpectedChan);
        return CModule::HALT;
    });
    auto Reset = [&]() {
        testModule.Reset();
        m_pTestClient->Reset();
    };

    Reset();
    {
        InSequence seq;
        EXPECT_CALL(testModule, OnChanCTCPMessage(_)).WillOnce(CON);
        EXPECT_CALL(testModule, OnChanActionMessage(_)).WillOnce(CON);
    }
    m_pTestSock->ReadLine(msg.ToString());
    EXPECT_THAT(m_pTestClient->vsLines, ElementsAre(msg.ToString()));

    Reset();
    {
        InSequence seq;
        EXPECT_CALL(testModule, OnChanCTCPMessage(_)).WillOnce(CON);
        EXPECT_CALL(testModule, OnChanActionMessage(_)).WillOnce(HAL);
    }
    m_pTestSock->ReadLine(msg.ToString());
    EXPECT_THAT(m_pTestClient->vsLines, IsEmpty());

    Reset();
    EXPECT_CALL(testModule, OnChanCTCPMessage(_)).WillOnce(HAL);
    m_pTestSock->ReadLine(msg.ToString());
    EXPECT_THAT(m_pTestClient->vsLines, IsEmpty());

    msg.Parse(":nick PRIVMSG me :\001ACTION hello\001");
    pExpectedChan = nullptr;

    Reset();
    {
        InSequence seq;
        EXPECT_CALL(testModule, OnPrivCTCPMessage(_)).WillOnce(CON);
        EXPECT_CALL(testModule, OnPrivActionMessage(_)).WillOnce(CON);
    }
    m_pTestSock->ReadLine(msg.ToString());
    EXPECT_THAT(m_pTestClient->vsLines, ElementsAre(msg.ToString()));

    Reset();
    {
        InSequence seq;
        EXPECT_CALL(testModule, OnPrivCTCPMessage(_)).WillOnce(CON);
        EXPECT_CALL(testModule, OnPrivActionMessage(_)).WillOnce(HAL);
    }
    m_pTestSock->ReadLine(msg.ToString());
    EXPECT_THAT(m_pTestClient->vsLines, IsEmpty());

    Reset();
    EXPECT_CALL(testModule, OnPrivCTCPMessage(_)).WillOnce(HAL);
    m_pTestSock->ReadLine(msg.ToString());
    EXPECT_THAT(m_pTestClient->vsLines, IsEmpty());
}
コード例 #26
0
 MockLibNice() {
   ON_CALL(*this, NiceAgentNew(_)).WillByDefault(Invoke(&real_impl_, &erizo::LibNiceInterfaceImpl::NiceAgentNew));
 }