<commit_before>/*
 * libjingle
 * Copyright 2011, Google Inc.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *  1. Redistributions of source code must retain the above copyright notice,
 *     this list of conditions and the following disclaimer.
 *  2. Redistributions in binary form must reproduce the above copyright notice,
 *     this list of conditions and the following disclaimer in the documentation
 *     and/or other materials provided with the distribution.
 *  3. The name of the author may not be used to endorse or promote products
 *     derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include <string>

#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "talk/app/webrtc_dev/mediastreamproxy.h"
#include "talk/app/webrtc_dev/mediastreamtrackproxy.h"
#include "talk/app/webrtc_dev/ref_count.h"
#include "talk/base/scoped_ptr.h"
#include "talk/base/thread.h"

static const char kStreamLabel1[] = "local_stream_1";
static const char kVideoTrackLabel[] = "dummy_video_cam_1";
static const char kAudioTrackLabel[] = "dummy_microphone_1";

using talk_base::scoped_refptr;
using ::testing::Exactly;

namespace {

class ReadyStateMessageData : public talk_base::MessageData {
 public:
  ReadyStateMessageData(
      webrtc::MediaStreamInterface* stream,
      webrtc::MediaStreamInterface::ReadyState new_state)
      : stream_(stream),
        ready_state_(new_state) {
  }

  scoped_refptr<webrtc::MediaStreamInterface> stream_;
  webrtc::MediaStreamInterface::ReadyState ready_state_;
};

class SsrcMessageData : public talk_base::MessageData {
 public:
  SsrcMessageData(
      webrtc::MediaStreamTrackInterface* track,
      uint32 ssrc)
      : track_(track),
        ssrc_(ssrc) {
  }

  scoped_refptr<webrtc::MediaStreamTrackInterface> track_;
  uint32 ssrc_;
};

class TrackStateMessageData : public talk_base::MessageData {
 public:
  TrackStateMessageData(
      webrtc::MediaStreamTrackInterface* track,
      webrtc::MediaStreamTrackInterface::TrackState state)
      : track_(track),
        state_(state) {
  }

  scoped_refptr<webrtc::MediaStreamTrackInterface> track_;
  webrtc::MediaStreamTrackInterface::TrackState state_;
};

}  // namespace anonymous

namespace webrtc {

// Helper class to test Observer.
class MockObserver : public ObserverInterface {
 public:
  explicit MockObserver(talk_base::Thread* signaling_thread)
      : signaling_thread_(signaling_thread) {
  }

  MOCK_METHOD0(DoOnChanged, void());
  virtual void OnChanged() {
    ASSERT_TRUE(talk_base::Thread::Current() == signaling_thread_);
    DoOnChanged();
  }
 private:
  talk_base::Thread* signaling_thread_;
};

class MockMediaStream: public LocalMediaStreamInterface {
 public:
  MockMediaStream(const std::string& label, talk_base::Thread* signaling_thread)
      : stream_impl_(MediaStream::Create(label)),
        signaling_thread_(signaling_thread) {
  }
  virtual void RegisterObserver(webrtc::ObserverInterface* observer) {
    EXPECT_EQ(talk_base::Thread::Current(), signaling_thread_);
    stream_impl_->RegisterObserver(observer);
  }
  virtual void UnregisterObserver(webrtc::ObserverInterface* observer) {
    EXPECT_EQ(talk_base::Thread::Current(), signaling_thread_);
    stream_impl_->UnregisterObserver(observer);
  }
  virtual std::string label() const {
    EXPECT_EQ(talk_base::Thread::Current(), signaling_thread_);
    return stream_impl_->label();
  }
  virtual AudioTracks* audio_tracks() {
    EXPECT_EQ(talk_base::Thread::Current(), signaling_thread_);
    return stream_impl_->audio_tracks();
  }
  virtual VideoTracks* video_tracks() {
    EXPECT_EQ(talk_base::Thread::Current(), signaling_thread_);
    return stream_impl_->video_tracks();
  }
  virtual ReadyState ready_state() {
    EXPECT_EQ(talk_base::Thread::Current(), signaling_thread_);
    return stream_impl_->ready_state();
  }
  virtual void set_ready_state(ReadyState state) {
    EXPECT_EQ(talk_base::Thread::Current(), signaling_thread_);
    return stream_impl_->set_ready_state(state);
  }
  virtual bool AddTrack(AudioTrackInterface* audio_track) {
    EXPECT_EQ(talk_base::Thread::Current(), signaling_thread_);
    return stream_impl_->AddTrack(audio_track);
  }
  virtual bool AddTrack(VideoTrackInterface* video_track) {
    EXPECT_EQ(talk_base::Thread::Current(), signaling_thread_);
    return stream_impl_->AddTrack(video_track);
  }

 private:
  scoped_refptr<MediaStream> stream_impl_;
  talk_base::Thread* signaling_thread_;
};

template <class T>
class MockMediaStreamTrack: public T {
 public:
  MockMediaStreamTrack(T* implementation,
                       talk_base::Thread* signaling_thread)
      : track_impl_(implementation),
        signaling_thread_(signaling_thread) {
  }
  virtual void RegisterObserver(webrtc::ObserverInterface* observer) {
    EXPECT_EQ(talk_base::Thread::Current(), signaling_thread_);
    track_impl_->RegisterObserver(observer);
  }
  virtual void UnregisterObserver(webrtc::ObserverInterface* observer) {
    EXPECT_EQ(talk_base::Thread::Current(), signaling_thread_);
    track_impl_->UnregisterObserver(observer);
  }
  virtual const char* kind() const {
    EXPECT_EQ(talk_base::Thread::Current(), signaling_thread_);
    return track_impl_->kind();
  }<commit_msg>Fixes broken build in peerconnection unit tests Review URL: http://webrtc-codereview.appspot.com/244006<commit_after>/*
 * libjingle
 * Copyright 2011, Google Inc.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *  1. Redistributions of source code must retain the above copyright notice,
 *     this list of conditions and the following disclaimer.
 *  2. Redistributions in binary form must reproduce the above copyright notice,
 *     this list of conditions and the following disclaimer in the documentation
 *     and/or other materials provided with the distribution.
 *  3. The name of the author may not be used to endorse or promote products
 *     derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include <string>

#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "talk/app/webrtc_dev/mediastreamproxy.h"
#include "talk/app/webrtc_dev/mediastreamtrackproxy.h"
#include "talk/app/webrtc_dev/refcount.h"
#include "talk/base/scoped_ptr.h"
#include "talk/base/thread.h"

static const char kStreamLabel1[] = "local_stream_1";
static const char kVideoTrackLabel[] = "dummy_video_cam_1";
static const char kAudioTrackLabel[] = "dummy_microphone_1";

using talk_base::scoped_refptr;
using ::testing::Exactly;

namespace {

class ReadyStateMessageData : public talk_base::MessageData {
 public:
  ReadyStateMessageData(
      webrtc::MediaStreamInterface* stream,
      webrtc::MediaStreamInterface::ReadyState new_state)
      : stream_(stream),
        ready_state_(new_state) {
  }

  scoped_refptr<webrtc::MediaStreamInterface> stream_;
  webrtc::MediaStreamInterface::ReadyState ready_state_;
};

class SsrcMessageData : public talk_base::MessageData {
 public:
  SsrcMessageData(
      webrtc::MediaStreamTrackInterface* track,
      uint32 ssrc)
      : track_(track),
        ssrc_(ssrc) {
  }

  scoped_refptr<webrtc::MediaStreamTrackInterface> track_;
  uint32 ssrc_;
};

class TrackStateMessageData : public talk_base::MessageData {
 public:
  TrackStateMessageData(
      webrtc::MediaStreamTrackInterface* track,
      webrtc::MediaStreamTrackInterface::TrackState state)
      : track_(track),
        state_(state) {
  }

  scoped_refptr<webrtc::MediaStreamTrackInterface> track_;
  webrtc::MediaStreamTrackInterface::TrackState state_;
};

}  // namespace anonymous

namespace webrtc {

// Helper class to test Observer.
class MockObserver : public ObserverInterface {
 public:
  explicit MockObserver(talk_base::Thread* signaling_thread)
      : signaling_thread_(signaling_thread) {
  }

  MOCK_METHOD0(DoOnChanged, void());
  virtual void OnChanged() {
    ASSERT_TRUE(talk_base::Thread::Current() == signaling_thread_);
    DoOnChanged();
  }
 private:
  talk_base::Thread* signaling_thread_;
};

class MockMediaStream: public LocalMediaStreamInterface {
 public:
  MockMediaStream(const std::string& label, talk_base::Thread* signaling_thread)
      : stream_impl_(MediaStream::Create(label)),
        signaling_thread_(signaling_thread) {
  }
  virtual void RegisterObserver(webrtc::ObserverInterface* observer) {
    EXPECT_EQ(talk_base::Thread::Current(), signaling_thread_);
    stream_impl_->RegisterObserver(observer);
  }
  virtual void UnregisterObserver(webrtc::ObserverInterface* observer) {
    EXPECT_EQ(talk_base::Thread::Current(), signaling_thread_);
    stream_impl_->UnregisterObserver(observer);
  }
  virtual std::string label() const {
    EXPECT_EQ(talk_base::Thread::Current(), signaling_thread_);
    return stream_impl_->label();
  }
  virtual AudioTracks* audio_tracks() {
    EXPECT_EQ(talk_base::Thread::Current(), signaling_thread_);
    return stream_impl_->audio_tracks();
  }
  virtual VideoTracks* video_tracks() {
    EXPECT_EQ(talk_base::Thread::Current(), signaling_thread_);
    return stream_impl_->video_tracks();
  }
  virtual ReadyState ready_state() {
    EXPECT_EQ(talk_base::Thread::Current(), signaling_thread_);
    return stream_impl_->ready_state();
  }
  virtual void set_ready_state(ReadyState state) {
    EXPECT_EQ(talk_base::Thread::Current(), signaling_thread_);
    return stream_impl_->set_ready_state(state);
  }
  virtual bool AddTrack(AudioTrackInterface* audio_track) {
    EXPECT_EQ(talk_base::Thread::Current(), signaling_thread_);
    return stream_impl_->AddTrack(audio_track);
  }
  virtual bool AddTrack(VideoTrackInterface* video_track) {
    EXPECT_EQ(talk_base::Thread::Current(), signaling_thread_);
    return stream_impl_->AddTrack(video_track);
  }

 private:
  scoped_refptr<MediaStream> stream_impl_;
  talk_base::Thread* signaling_thread_;
};

template <class T>
class MockMediaStreamTrack: public T {
 public:
  MockMediaStreamTrack(T* implementation,
                       talk_base::Thread* signaling_thread)
      : track_impl_(implementation),
        signaling_thread_(signaling_thread) {
  }
  virtual void RegisterObserver(webrtc::ObserverInterface* observer) {
    EXPECT_EQ(talk_base::Thread::Current(), signaling_thread_);
    track_impl_->RegisterObserver(observer);
  }
  virtual void UnregisterObserver(webrtc::ObserverInterface* observer) {
    EXPECT_EQ(talk_base::Thread::Current(), signaling_thread_);
    track_impl_->UnregisterObserver(observer);
  }
  virtual std::string kind() const {
    EXPECT_EQ(talk_base::Thread::Current(), signaling_thread_);
    return track_impl_->kind();
  }
{'fraction_non_alphanumeric': 0.0975986975986976, 'fraction_numerical': 0.0030932030932030933, 'mean_word_length': 5.146073036518259, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5046778', 'n_tokens_mistral': 3632, 'n_tokens_neox': 3469, 'n_words': 894}