Skip to content

Commit

Permalink
Reland "Enable the clang style plugin in rtc_base/"
Browse files Browse the repository at this point in the history
This is a reland of Id63f0deb7b335690157ab157c35177b7836688da.

Original change's description:
> Enable the clang style plugin in rtc_base/
> 
> Enabled the plugin and cleaned up all issues it found.
> 
> Bug: webrtc:163
> Change-Id: Id63f0deb7b335690157ab157c35177b7836688da
> Reviewed-on: https://webrtc-review.googlesource.com/14660
> Commit-Queue: Steve Anton <[email protected]>
> Reviewed-by: Karl Wiberg <[email protected]>
> Cr-Commit-Position: refs/heads/master@{#20401}

Bug: webrtc:163
Change-Id: I861a5fe741215115b0e7a2be9c0786836ff5376e
Reviewed-on: https://webrtc-review.googlesource.com/15040
Reviewed-by: Karl Wiberg <[email protected]>
Commit-Queue: Steve Anton <[email protected]>
Cr-Commit-Position: refs/heads/master@{#20416}
  • Loading branch information
steveanton authored and Commit Bot committed Oct 24, 2017
1 parent 074dece commit 9de3aac
Show file tree
Hide file tree
Showing 35 changed files with 505 additions and 361 deletions.
34 changes: 3 additions & 31 deletions rtc_base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -716,10 +716,6 @@ rtc_static_library("rtc_base_generic") {
defines += [ "timezone=_timezone" ]
sources -= [ "ifaddrs_converter.cc" ]
}
if (is_win && is_clang) {
# Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
}
}

rtc_source_set("gtest_prod") {
Expand Down Expand Up @@ -752,6 +748,7 @@ rtc_source_set("rtc_base_tests_utils") {
"fakeclock.cc",
"fakeclock.h",
"fakenetwork.h",
"fakesslidentity.cc",
"fakesslidentity.h",
"firewallsocketserver.cc",
"firewallsocketserver.h",
Expand Down Expand Up @@ -782,7 +779,9 @@ rtc_source_set("rtc_base_tests_utils") {
"testbase64.h",
"testclient.cc",
"testclient.h",
"testechoserver.cc",
"testechoserver.h",
"testutils.cc",
"testutils.h",
"timedelta.h",
"virtualsocketserver.cc",
Expand All @@ -799,11 +798,6 @@ rtc_source_set("rtc_base_tests_utils") {
"//testing/gmock",
"//testing/gtest",
]

if (!build_with_chromium && is_clang) {
# Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
}
}

if (rtc_include_tests) {
Expand All @@ -825,11 +819,6 @@ if (rtc_include_tests) {
"//testing/gmock",
"//testing/gtest",
]

if (!build_with_chromium && is_clang) {
# Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
}
}

rtc_source_set("rtc_base_nonparallel_tests") {
Expand Down Expand Up @@ -862,11 +851,6 @@ if (rtc_include_tests) {
if (is_win) {
sources += [ "win32socketserver_unittest.cc" ]
}

if (!build_with_chromium && is_clang) {
# Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
}
}

rtc_source_set("rtc_base_approved_unittests") {
Expand Down Expand Up @@ -931,10 +915,6 @@ if (rtc_include_tests) {
"../system_wrappers:system_wrappers",
"../test:test_support",
]
if (!build_with_chromium && is_clang) {
# Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
}
}

rtc_source_set("rtc_task_queue_unittests") {
Expand All @@ -957,10 +937,6 @@ if (rtc_include_tests) {
":rtc_task_queue",
"../test:test_support",
]
if (!build_with_chromium && is_clang) {
# Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
}
}

rtc_source_set("sequenced_task_checker_unittests") {
Expand Down Expand Up @@ -1096,10 +1072,6 @@ if (rtc_include_tests) {
":rtc_base",
]
configs += [ ":rtc_base_unittests_config" ]
if (!build_with_chromium && is_clang) {
# Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
}
if (build_with_chromium) {
include_dirs = [ "../../boringssl/src/include" ]
}
Expand Down
4 changes: 2 additions & 2 deletions rtc_base/buffer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -359,14 +359,14 @@ TEST(BufferTest, TestBracketWrite) {
TEST(BufferTest, TestBeginEnd) {
const Buffer cbuf(kTestData);
Buffer buf(kTestData);
auto b1 = cbuf.begin();
auto* b1 = cbuf.begin();
for (auto& x : buf) {
EXPECT_EQ(*b1, x);
++b1;
++x;
}
EXPECT_EQ(cbuf.end(), b1);
auto b2 = buf.begin();
auto* b2 = buf.begin();
for (auto& y : cbuf) {
EXPECT_EQ(*b2, y + 1);
++b2;
Expand Down
118 changes: 118 additions & 0 deletions rtc_base/fakesslidentity.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* Copyright 2017 The WebRTC Project Authors. All rights reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/

#include "rtc_base/fakesslidentity.h"

#include <algorithm>
#include <string>
#include <utility>

#include "rtc_base/checks.h"
#include "rtc_base/messagedigest.h"
#include "rtc_base/ptr_util.h"

namespace rtc {

FakeSSLCertificate::FakeSSLCertificate(const std::string& data)
: data_(data), digest_algorithm_(DIGEST_SHA_1), expiration_time_(-1) {}

FakeSSLCertificate::FakeSSLCertificate(const std::vector<std::string>& certs)
: data_(certs.front()),
digest_algorithm_(DIGEST_SHA_1),
expiration_time_(-1) {
std::vector<std::string>::const_iterator it;
// Skip certs[0].
for (it = certs.begin() + 1; it != certs.end(); ++it) {
certs_.push_back(FakeSSLCertificate(*it));
}
}

FakeSSLCertificate::FakeSSLCertificate(const FakeSSLCertificate&) = default;

FakeSSLCertificate::~FakeSSLCertificate() = default;

FakeSSLCertificate* FakeSSLCertificate::GetReference() const {
return new FakeSSLCertificate(*this);
}

std::string FakeSSLCertificate::ToPEMString() const {
return data_;
}

void FakeSSLCertificate::ToDER(Buffer* der_buffer) const {
std::string der_string;
RTC_CHECK(SSLIdentity::PemToDer(kPemTypeCertificate, data_, &der_string));
der_buffer->SetData(der_string.c_str(), der_string.size());
}

int64_t FakeSSLCertificate::CertificateExpirationTime() const {
return expiration_time_;
}

void FakeSSLCertificate::SetCertificateExpirationTime(int64_t expiration_time) {
expiration_time_ = expiration_time;
}

void FakeSSLCertificate::set_digest_algorithm(const std::string& algorithm) {
digest_algorithm_ = algorithm;
}

bool FakeSSLCertificate::GetSignatureDigestAlgorithm(
std::string* algorithm) const {
*algorithm = digest_algorithm_;
return true;
}

bool FakeSSLCertificate::ComputeDigest(const std::string& algorithm,
unsigned char* digest,
size_t size,
size_t* length) const {
*length =
rtc::ComputeDigest(algorithm, data_.c_str(), data_.size(), digest, size);
return (*length != 0);
}

std::unique_ptr<SSLCertChain> FakeSSLCertificate::GetChain() const {
if (certs_.empty())
return nullptr;
std::vector<std::unique_ptr<SSLCertificate>> new_certs(certs_.size());
std::transform(certs_.begin(), certs_.end(), new_certs.begin(), DupCert);
return MakeUnique<SSLCertChain>(std::move(new_certs));
}

FakeSSLIdentity::FakeSSLIdentity(const std::string& data) : cert_(data) {}

FakeSSLIdentity::FakeSSLIdentity(const FakeSSLCertificate& cert)
: cert_(cert) {}

FakeSSLIdentity* FakeSSLIdentity::GetReference() const {
return new FakeSSLIdentity(*this);
}

const FakeSSLCertificate& FakeSSLIdentity::certificate() const {
return cert_;
}

std::string FakeSSLIdentity::PrivateKeyToPEMString() const {
RTC_NOTREACHED(); // Not implemented.
return "";
}

std::string FakeSSLIdentity::PublicKeyToPEMString() const {
RTC_NOTREACHED(); // Not implemented.
return "";
}

bool FakeSSLIdentity::operator==(const SSLIdentity& other) const {
RTC_NOTREACHED(); // Not implemented.
return false;
}

} // namespace rtc
102 changes: 32 additions & 70 deletions rtc_base/fakesslidentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@
#ifndef RTC_BASE_FAKESSLIDENTITY_H_
#define RTC_BASE_FAKESSLIDENTITY_H_

#include <algorithm>
#include <memory>
#include <vector>

#include "rtc_base/checks.h"
#include "rtc_base/messagedigest.h"
#include "rtc_base/ptr_util.h"
#include "rtc_base/sslidentity.h"

namespace rtc {
Expand All @@ -26,57 +22,28 @@ class FakeSSLCertificate : public rtc::SSLCertificate {
public:
// SHA-1 is the default digest algorithm because it is available in all build
// configurations used for unit testing.
explicit FakeSSLCertificate(const std::string& data)
: data_(data), digest_algorithm_(DIGEST_SHA_1), expiration_time_(-1) {}
explicit FakeSSLCertificate(const std::vector<std::string>& certs)
: data_(certs.front()),
digest_algorithm_(DIGEST_SHA_1),
expiration_time_(-1) {
std::vector<std::string>::const_iterator it;
// Skip certs[0].
for (it = certs.begin() + 1; it != certs.end(); ++it) {
certs_.push_back(FakeSSLCertificate(*it));
}
}
FakeSSLCertificate* GetReference() const override {
return new FakeSSLCertificate(*this);
}
std::string ToPEMString() const override {
return data_;
}
void ToDER(Buffer* der_buffer) const override {
std::string der_string;
RTC_CHECK(SSLIdentity::PemToDer(kPemTypeCertificate, data_, &der_string));
der_buffer->SetData(der_string.c_str(), der_string.size());
}
int64_t CertificateExpirationTime() const override {
return expiration_time_;
}
void SetCertificateExpirationTime(int64_t expiration_time) {
expiration_time_ = expiration_time;
}
void set_digest_algorithm(const std::string& algorithm) {
digest_algorithm_ = algorithm;
}
bool GetSignatureDigestAlgorithm(std::string* algorithm) const override {
*algorithm = digest_algorithm_;
return true;
}
explicit FakeSSLCertificate(const std::string& data);

explicit FakeSSLCertificate(const std::vector<std::string>& certs);

FakeSSLCertificate(const FakeSSLCertificate&);
~FakeSSLCertificate() override;

// SSLCertificate implementation.
FakeSSLCertificate* GetReference() const override;
std::string ToPEMString() const override;
void ToDER(Buffer* der_buffer) const override;
int64_t CertificateExpirationTime() const override;
bool GetSignatureDigestAlgorithm(std::string* algorithm) const override;
bool ComputeDigest(const std::string& algorithm,
unsigned char* digest,
size_t size,
size_t* length) const override {
*length = rtc::ComputeDigest(algorithm, data_.c_str(), data_.size(),
digest, size);
return (*length != 0);
}
std::unique_ptr<SSLCertChain> GetChain() const override {
if (certs_.empty())
return nullptr;
std::vector<std::unique_ptr<SSLCertificate>> new_certs(certs_.size());
std::transform(certs_.begin(), certs_.end(), new_certs.begin(), DupCert);
return MakeUnique<SSLCertChain>(std::move(new_certs));
}
size_t* length) const override;
std::unique_ptr<SSLCertChain> GetChain() const override;

void SetCertificateExpirationTime(int64_t expiration_time);

void set_digest_algorithm(const std::string& algorithm);

private:
static std::unique_ptr<SSLCertificate> DupCert(FakeSSLCertificate cert) {
Expand All @@ -92,24 +59,19 @@ class FakeSSLCertificate : public rtc::SSLCertificate {

class FakeSSLIdentity : public rtc::SSLIdentity {
public:
explicit FakeSSLIdentity(const std::string& data) : cert_(data) {}
explicit FakeSSLIdentity(const FakeSSLCertificate& cert) : cert_(cert) {}
virtual FakeSSLIdentity* GetReference() const {
return new FakeSSLIdentity(*this);
}
virtual const FakeSSLCertificate& certificate() const { return cert_; }
virtual std::string PrivateKeyToPEMString() const {
RTC_NOTREACHED(); // Not implemented.
return "";
}
virtual std::string PublicKeyToPEMString() const {
RTC_NOTREACHED(); // Not implemented.
return "";
}
virtual bool operator==(const SSLIdentity& other) const {
RTC_NOTREACHED(); // Not implemented.
return false;
}
explicit FakeSSLIdentity(const std::string& data);
explicit FakeSSLIdentity(const FakeSSLCertificate& cert);

// SSLIdentity implementation.
FakeSSLIdentity* GetReference() const override;
const FakeSSLCertificate& certificate() const override;
// Not implemented.
std::string PrivateKeyToPEMString() const override;
// Not implemented.
std::string PublicKeyToPEMString() const override;
// Not implemented.
virtual bool operator==(const SSLIdentity& other) const;

private:
FakeSSLCertificate cert_;
};
Expand Down
2 changes: 1 addition & 1 deletion rtc_base/filerotatingstream_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class MAYBE_CallSessionFileRotatingStreamTest : public ::testing::Test {
new CallSessionFileRotatingStream(dir_path_, max_total_log_size));
}

virtual void TearDown() {
void TearDown() override {
// On windows, open files can't be removed.
stream_->Close();
CleanupLogDirectory(*stream_);
Expand Down
Loading

0 comments on commit 9de3aac

Please sign in to comment.