Move webrtc/{base => rtc_base}
This refactoring takes a careful approach to avoid rushing the change: * stub headers are left in all the old locations of webrtc/base * existing GN targets are kept and now just forward to the moved ones using public_deps. The only exception to the above is the base_java target and its .java files, which were moved to webrtc/rtc_base right away since it's not possible to use public_deps for android_library. To avoid breaking builds, a temporary Dummy.java file was added to the new intermediate target in webrtc/rtc_base:base_java as well to avoid hitting a GN assert in the android_library template. The above approach should make the transition smooth without breaking downstream. A helper script was created (https://codereview.webrtc.org/2879203002/) and was run like this: stub-headers.py -s webrtc/base -d webrtc/rtc_base -i 7634 stub-headers.py -s webrtc/base/numerics -d webrtc/rtc_base/numerics -i 7634 Fixed invalid header guards in the following files: webrtc/base/base64.h webrtc/base/cryptstring.h webrtc/base/event.h webrtc/base/flags.h webrtc/base/httpbase.h webrtc/base/httpcommon-inl.h webrtc/base/httpcommon.h webrtc/base/httpserver.h webrtc/base/logsinks.h webrtc/base/macutils.h webrtc/base/nattypes.h webrtc/base/openssladapter.h webrtc/base/opensslstreamadapter.h webrtc/base/pathutils.h webrtc/base/physicalsocketserver.h webrtc/base/proxyinfo.h webrtc/base/sigslot.h webrtc/base/sigslotrepeater.h webrtc/base/socket.h webrtc/base/socketaddresspair.h webrtc/base/socketfactory.h webrtc/base/stringutils.h webrtc/base/testbase64.h webrtc/base/testutils.h webrtc/base/transformadapter.h webrtc/base/win32filesystem.h Added new header guards to: sslroots.h testbase64.h BUG=webrtc:7634 NOTRY=True NOPRESUBMIT=True R=kwiberg@webrtc.org Review-Url: https://codereview.webrtc.org/2877023002 . Cr-Commit-Position: refs/heads/master@{#18816}
This commit is contained in:
182
webrtc/rtc_base/optionsfile_unittest.cc
Normal file
182
webrtc/rtc_base/optionsfile_unittest.cc
Normal file
@ -0,0 +1,182 @@
|
||||
/*
|
||||
* Copyright 2008 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 <memory>
|
||||
|
||||
#include "webrtc/base/checks.h"
|
||||
#include "webrtc/base/fileutils.h"
|
||||
#include "webrtc/base/gunit.h"
|
||||
#include "webrtc/base/optionsfile.h"
|
||||
#include "webrtc/base/pathutils.h"
|
||||
|
||||
namespace rtc {
|
||||
|
||||
static const std::string kTestOptionA = "test-option-a";
|
||||
static const std::string kTestOptionB = "test-option-b";
|
||||
static const std::string kTestString1 = "a string";
|
||||
static const std::string kTestString2 = "different string";
|
||||
static const std::string kOptionWithEquals = "foo=bar";
|
||||
static const std::string kOptionWithNewline = "foo\nbar";
|
||||
static const std::string kValueWithEquals = "baz=quux";
|
||||
static const std::string kValueWithNewline = "baz\nquux";
|
||||
static const std::string kEmptyString = "";
|
||||
static const char kOptionWithUtf8[] = {'O', 'p', 't', '\302', '\256', 'i', 'o',
|
||||
'n', '\342', '\204', '\242', '\0'}; // Opt(R)io(TM).
|
||||
static const char kValueWithUtf8[] = {'V', 'a', 'l', '\302', '\256', 'v', 'e',
|
||||
'\342', '\204', '\242', '\0'}; // Val(R)ue(TM).
|
||||
static int kTestInt1 = 12345;
|
||||
static int kTestInt2 = 67890;
|
||||
static int kNegInt = -634;
|
||||
static int kZero = 0;
|
||||
|
||||
#if defined (WEBRTC_ANDROID)
|
||||
// Fails on Android: https://bugs.chromium.org/p/webrtc/issues/detail?id=4364.
|
||||
#define MAYBE_OptionsFileTest DISABLED_OptionsFileTest
|
||||
#else
|
||||
#define MAYBE_OptionsFileTest OptionsFileTest
|
||||
#endif
|
||||
|
||||
class MAYBE_OptionsFileTest : public testing::Test {
|
||||
public:
|
||||
MAYBE_OptionsFileTest() {
|
||||
Pathname dir;
|
||||
RTC_CHECK(Filesystem::GetTemporaryFolder(dir, true, nullptr));
|
||||
test_file_ = Filesystem::TempFilename(dir, ".testfile");
|
||||
OpenStore();
|
||||
}
|
||||
|
||||
~MAYBE_OptionsFileTest() override {
|
||||
remove(test_file_.c_str());
|
||||
}
|
||||
|
||||
protected:
|
||||
void OpenStore() {
|
||||
store_.reset(new OptionsFile(test_file_));
|
||||
}
|
||||
|
||||
std::unique_ptr<OptionsFile> store_;
|
||||
|
||||
private:
|
||||
std::string test_file_;
|
||||
};
|
||||
|
||||
TEST_F(MAYBE_OptionsFileTest, GetSetString) {
|
||||
// Clear contents of the file on disk.
|
||||
EXPECT_TRUE(store_->Save());
|
||||
std::string out1, out2;
|
||||
EXPECT_FALSE(store_->GetStringValue(kTestOptionA, &out1));
|
||||
EXPECT_FALSE(store_->GetStringValue(kTestOptionB, &out2));
|
||||
EXPECT_TRUE(store_->SetStringValue(kTestOptionA, kTestString1));
|
||||
EXPECT_TRUE(store_->Save());
|
||||
EXPECT_TRUE(store_->Load());
|
||||
EXPECT_TRUE(store_->SetStringValue(kTestOptionB, kTestString2));
|
||||
EXPECT_TRUE(store_->Save());
|
||||
EXPECT_TRUE(store_->Load());
|
||||
EXPECT_TRUE(store_->GetStringValue(kTestOptionA, &out1));
|
||||
EXPECT_TRUE(store_->GetStringValue(kTestOptionB, &out2));
|
||||
EXPECT_EQ(kTestString1, out1);
|
||||
EXPECT_EQ(kTestString2, out2);
|
||||
EXPECT_TRUE(store_->RemoveValue(kTestOptionA));
|
||||
EXPECT_TRUE(store_->Save());
|
||||
EXPECT_TRUE(store_->Load());
|
||||
EXPECT_TRUE(store_->RemoveValue(kTestOptionB));
|
||||
EXPECT_TRUE(store_->Save());
|
||||
EXPECT_TRUE(store_->Load());
|
||||
EXPECT_FALSE(store_->GetStringValue(kTestOptionA, &out1));
|
||||
EXPECT_FALSE(store_->GetStringValue(kTestOptionB, &out2));
|
||||
}
|
||||
|
||||
TEST_F(MAYBE_OptionsFileTest, GetSetInt) {
|
||||
// Clear contents of the file on disk.
|
||||
EXPECT_TRUE(store_->Save());
|
||||
int out1, out2;
|
||||
EXPECT_FALSE(store_->GetIntValue(kTestOptionA, &out1));
|
||||
EXPECT_FALSE(store_->GetIntValue(kTestOptionB, &out2));
|
||||
EXPECT_TRUE(store_->SetIntValue(kTestOptionA, kTestInt1));
|
||||
EXPECT_TRUE(store_->Save());
|
||||
EXPECT_TRUE(store_->Load());
|
||||
EXPECT_TRUE(store_->SetIntValue(kTestOptionB, kTestInt2));
|
||||
EXPECT_TRUE(store_->Save());
|
||||
EXPECT_TRUE(store_->Load());
|
||||
EXPECT_TRUE(store_->GetIntValue(kTestOptionA, &out1));
|
||||
EXPECT_TRUE(store_->GetIntValue(kTestOptionB, &out2));
|
||||
EXPECT_EQ(kTestInt1, out1);
|
||||
EXPECT_EQ(kTestInt2, out2);
|
||||
EXPECT_TRUE(store_->RemoveValue(kTestOptionA));
|
||||
EXPECT_TRUE(store_->Save());
|
||||
EXPECT_TRUE(store_->Load());
|
||||
EXPECT_TRUE(store_->RemoveValue(kTestOptionB));
|
||||
EXPECT_TRUE(store_->Save());
|
||||
EXPECT_TRUE(store_->Load());
|
||||
EXPECT_FALSE(store_->GetIntValue(kTestOptionA, &out1));
|
||||
EXPECT_FALSE(store_->GetIntValue(kTestOptionB, &out2));
|
||||
EXPECT_TRUE(store_->SetIntValue(kTestOptionA, kNegInt));
|
||||
EXPECT_TRUE(store_->GetIntValue(kTestOptionA, &out1));
|
||||
EXPECT_EQ(kNegInt, out1);
|
||||
EXPECT_TRUE(store_->SetIntValue(kTestOptionA, kZero));
|
||||
EXPECT_TRUE(store_->GetIntValue(kTestOptionA, &out1));
|
||||
EXPECT_EQ(kZero, out1);
|
||||
}
|
||||
|
||||
TEST_F(MAYBE_OptionsFileTest, Persist) {
|
||||
// Clear contents of the file on disk.
|
||||
EXPECT_TRUE(store_->Save());
|
||||
EXPECT_TRUE(store_->SetStringValue(kTestOptionA, kTestString1));
|
||||
EXPECT_TRUE(store_->SetIntValue(kTestOptionB, kNegInt));
|
||||
EXPECT_TRUE(store_->Save());
|
||||
|
||||
// Load the saved contents from above.
|
||||
OpenStore();
|
||||
EXPECT_TRUE(store_->Load());
|
||||
std::string out1;
|
||||
int out2;
|
||||
EXPECT_TRUE(store_->GetStringValue(kTestOptionA, &out1));
|
||||
EXPECT_TRUE(store_->GetIntValue(kTestOptionB, &out2));
|
||||
EXPECT_EQ(kTestString1, out1);
|
||||
EXPECT_EQ(kNegInt, out2);
|
||||
}
|
||||
|
||||
TEST_F(MAYBE_OptionsFileTest, SpecialCharacters) {
|
||||
// Clear contents of the file on disk.
|
||||
EXPECT_TRUE(store_->Save());
|
||||
std::string out;
|
||||
EXPECT_FALSE(store_->SetStringValue(kOptionWithEquals, kTestString1));
|
||||
EXPECT_FALSE(store_->GetStringValue(kOptionWithEquals, &out));
|
||||
EXPECT_FALSE(store_->SetStringValue(kOptionWithNewline, kTestString1));
|
||||
EXPECT_FALSE(store_->GetStringValue(kOptionWithNewline, &out));
|
||||
EXPECT_TRUE(store_->SetStringValue(kOptionWithUtf8, kValueWithUtf8));
|
||||
EXPECT_TRUE(store_->SetStringValue(kTestOptionA, kTestString1));
|
||||
EXPECT_TRUE(store_->Save());
|
||||
EXPECT_TRUE(store_->Load());
|
||||
EXPECT_TRUE(store_->GetStringValue(kTestOptionA, &out));
|
||||
EXPECT_EQ(kTestString1, out);
|
||||
EXPECT_TRUE(store_->GetStringValue(kOptionWithUtf8, &out));
|
||||
EXPECT_EQ(kValueWithUtf8, out);
|
||||
EXPECT_FALSE(store_->SetStringValue(kTestOptionA, kValueWithNewline));
|
||||
EXPECT_TRUE(store_->GetStringValue(kTestOptionA, &out));
|
||||
EXPECT_EQ(kTestString1, out);
|
||||
EXPECT_TRUE(store_->SetStringValue(kTestOptionA, kValueWithEquals));
|
||||
EXPECT_TRUE(store_->Save());
|
||||
EXPECT_TRUE(store_->Load());
|
||||
EXPECT_TRUE(store_->GetStringValue(kTestOptionA, &out));
|
||||
EXPECT_EQ(kValueWithEquals, out);
|
||||
EXPECT_TRUE(store_->SetStringValue(kEmptyString, kTestString2));
|
||||
EXPECT_TRUE(store_->Save());
|
||||
EXPECT_TRUE(store_->Load());
|
||||
EXPECT_TRUE(store_->GetStringValue(kEmptyString, &out));
|
||||
EXPECT_EQ(kTestString2, out);
|
||||
EXPECT_TRUE(store_->SetStringValue(kTestOptionB, kEmptyString));
|
||||
EXPECT_TRUE(store_->Save());
|
||||
EXPECT_TRUE(store_->Load());
|
||||
EXPECT_TRUE(store_->GetStringValue(kTestOptionB, &out));
|
||||
EXPECT_EQ(kEmptyString, out);
|
||||
}
|
||||
|
||||
} // namespace rtc
|
||||
Reference in New Issue
Block a user