libweave: Move testing tools into directory weave/test Also namespace unittests renamed into test. BUG=brillo:1243 TEST=`FEATURES=test emerge-gizmo libweave buffet` CQ-DEPEND=CL:294872 Change-Id: Ib3951cc5781e04632ecf31e1896065d7c6d7f7d8 Reviewed-on: https://chromium-review.googlesource.com/294766 Reviewed-by: Vitaly Buka <vitalybuka@chromium.org> Tested-by: Vitaly Buka <vitalybuka@chromium.org> Reviewed-by: Alex Vakulenko <avakulenko@chromium.org> Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/libweave/include/weave/mock_command.h b/libweave/include/weave/test/mock_command.h similarity index 88% rename from libweave/include/weave/mock_command.h rename to libweave/include/weave/test/mock_command.h index 7d0c938..be1b0c3 100644 --- a/libweave/include/weave/mock_command.h +++ b/libweave/include/weave/test/mock_command.h
@@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef LIBWEAVE_INCLUDE_WEAVE_MOCK_COMMAND_H_ -#define LIBWEAVE_INCLUDE_WEAVE_MOCK_COMMAND_H_ +#ifndef LIBWEAVE_INCLUDE_WEAVE_TEST_MOCK_COMMAND_H_ +#define LIBWEAVE_INCLUDE_WEAVE_TEST_MOCK_COMMAND_H_ #include <weave/command.h> @@ -14,7 +14,7 @@ #include <gmock/gmock.h> namespace weave { -namespace unittests { +namespace test { class MockCommand : public Command { public: @@ -43,7 +43,7 @@ std::unique_ptr<base::DictionaryValue> ToJson() const override; }; -} // namespace unittests +} // namespace test } // namespace weave -#endif // LIBWEAVE_INCLUDE_WEAVE_MOCK_COMMAND_H_ +#endif // LIBWEAVE_INCLUDE_WEAVE_TEST_MOCK_COMMAND_H_
diff --git a/libweave/include/weave/mock_commands.h b/libweave/include/weave/test/mock_commands.h similarity index 77% rename from libweave/include/weave/mock_commands.h rename to libweave/include/weave/test/mock_commands.h index 7e13cd5..575f15b 100644 --- a/libweave/include/weave/mock_commands.h +++ b/libweave/include/weave/test/mock_commands.h
@@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef LIBWEAVE_INCLUDE_WEAVE_MOCK_COMMANDS_H_ -#define LIBWEAVE_INCLUDE_WEAVE_MOCK_COMMANDS_H_ +#ifndef LIBWEAVE_INCLUDE_WEAVE_TEST_MOCK_COMMANDS_H_ +#define LIBWEAVE_INCLUDE_WEAVE_TEST_MOCK_COMMANDS_H_ #include <weave/commands.h> @@ -12,7 +12,7 @@ #include <gmock/gmock.h> namespace weave { -namespace unittests { +namespace test { class MockCommands : public Commands { public: @@ -26,7 +26,7 @@ MOCK_METHOD1(FindCommand, Command*(const std::string&)); }; -} // namespace unittests +} // namespace test } // namespace weave -#endif // LIBWEAVE_INCLUDE_WEAVE_MOCK_COMMANDS_H_ +#endif // LIBWEAVE_INCLUDE_WEAVE_TEST_MOCK_COMMANDS_H_
diff --git a/libweave/include/weave/mock_config_store.h b/libweave/include/weave/test/mock_config_store.h similarity index 85% rename from libweave/include/weave/mock_config_store.h rename to libweave/include/weave/test/mock_config_store.h index e82bc66..357db6e 100644 --- a/libweave/include/weave/mock_config_store.h +++ b/libweave/include/weave/test/mock_config_store.h
@@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef LIBWEAVE_INCLUDE_WEAVE_MOCK_CONFIG_STORE_H_ -#define LIBWEAVE_INCLUDE_WEAVE_MOCK_CONFIG_STORE_H_ +#ifndef LIBWEAVE_INCLUDE_WEAVE_TEST_MOCK_CONFIG_STORE_H_ +#define LIBWEAVE_INCLUDE_WEAVE_TEST_MOCK_CONFIG_STORE_H_ #include <map> #include <string> @@ -13,7 +13,7 @@ #include <weave/config_store.h> namespace weave { -namespace unittests { +namespace test { class MockConfigStore : public ConfigStore { public: @@ -41,7 +41,7 @@ MOCK_METHOD0(LoadStateDefaults, std::vector<std::string>()); }; -} // namespace unittests +} // namespace test } // namespace weave -#endif // LIBWEAVE_INCLUDE_WEAVE_MOCK_CONFIG_STORE_H_ +#endif // LIBWEAVE_INCLUDE_WEAVE_TEST_MOCK_CONFIG_STORE_H_
diff --git a/libweave/include/weave/mock_http_client.h b/libweave/include/weave/test/mock_http_client.h similarity index 87% rename from libweave/include/weave/mock_http_client.h rename to libweave/include/weave/test/mock_http_client.h index 7ea1f26..f5c04ea 100644 --- a/libweave/include/weave/mock_http_client.h +++ b/libweave/include/weave/test/mock_http_client.h
@@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef LIBWEAVE_INCLUDE_WEAVE_MOCK_HTTP_CLIENT_H_ -#define LIBWEAVE_INCLUDE_WEAVE_MOCK_HTTP_CLIENT_H_ +#ifndef LIBWEAVE_INCLUDE_WEAVE_TEST_MOCK_HTTP_CLIENT_H_ +#define LIBWEAVE_INCLUDE_WEAVE_TEST_MOCK_HTTP_CLIENT_H_ #include <weave/http_client.h> @@ -13,7 +13,7 @@ #include <gmock/gmock.h> namespace weave { -namespace unittests { +namespace test { class MockHttpClientResponse : public HttpClient::Response { public: @@ -47,7 +47,7 @@ const ErrorCallback& error_callback) override; }; -} // namespace unittests +} // namespace test } // namespace weave -#endif // LIBWEAVE_INCLUDE_WEAVE_MOCK_HTTP_CLIENT_H_ +#endif // LIBWEAVE_INCLUDE_WEAVE_TEST_MOCK_HTTP_CLIENT_H_
diff --git a/libweave/include/weave/mock_http_server.h b/libweave/include/weave/test/mock_http_server.h similarity index 77% rename from libweave/include/weave/mock_http_server.h rename to libweave/include/weave/test/mock_http_server.h index 7cd8355..9f8bbcc 100644 --- a/libweave/include/weave/mock_http_server.h +++ b/libweave/include/weave/test/mock_http_server.h
@@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef LIBWEAVE_INCLUDE_WEAVE_MOCK_HTTP_SERVER_H_ -#define LIBWEAVE_INCLUDE_WEAVE_MOCK_HTTP_SERVER_H_ +#ifndef LIBWEAVE_INCLUDE_WEAVE_TEST_MOCK_HTTP_SERVER_H_ +#define LIBWEAVE_INCLUDE_WEAVE_TEST_MOCK_HTTP_SERVER_H_ #include <weave/http_server.h> @@ -13,7 +13,7 @@ #include <base/callback.h> namespace weave { -namespace unittests { +namespace test { class MockHttpServer : public HttpServer { public: @@ -26,7 +26,7 @@ MOCK_CONST_METHOD0(GetHttpsCertificateFingerprint, std::vector<uint8_t>&()); }; -} // namespace unittests +} // namespace test } // namespace weave -#endif // LIBWEAVE_INCLUDE_WEAVE_MOCK_HTTP_SERVER_H_ +#endif // LIBWEAVE_INCLUDE_WEAVE_TEST_MOCK_HTTP_SERVER_H_
diff --git a/libweave/include/weave/mock_mdns.h b/libweave/include/weave/test/mock_mdns.h similarity index 76% rename from libweave/include/weave/mock_mdns.h rename to libweave/include/weave/test/mock_mdns.h index c6106c1..1045ce0 100644 --- a/libweave/include/weave/mock_mdns.h +++ b/libweave/include/weave/test/mock_mdns.h
@@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef LIBWEAVE_INCLUDE_WEAVE_MOCK_MDNS_H_ -#define LIBWEAVE_INCLUDE_WEAVE_MOCK_MDNS_H_ +#ifndef LIBWEAVE_INCLUDE_WEAVE_TEST_MOCK_MDNS_H_ +#define LIBWEAVE_INCLUDE_WEAVE_TEST_MOCK_MDNS_H_ #include <weave/mdns.h> @@ -13,7 +13,7 @@ #include <gmock/gmock.h> namespace weave { -namespace unittests { +namespace test { class MockMdns : public Mdns { public: @@ -25,7 +25,7 @@ MOCK_CONST_METHOD0(GetId, std::string()); }; -} // namespace unittests +} // namespace test } // namespace weave -#endif // LIBWEAVE_INCLUDE_WEAVE_MOCK_MDNS_H_ +#endif // LIBWEAVE_INCLUDE_WEAVE_TEST_MOCK_MDNS_H_
diff --git a/libweave/include/weave/mock_network.h b/libweave/include/weave/test/mock_network.h similarity index 88% rename from libweave/include/weave/mock_network.h rename to libweave/include/weave/test/mock_network.h index 2d20395..f09533e 100644 --- a/libweave/include/weave/mock_network.h +++ b/libweave/include/weave/test/mock_network.h
@@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef LIBWEAVE_INCLUDE_WEAVE_MOCK_NETWORK_H_ -#define LIBWEAVE_INCLUDE_WEAVE_MOCK_NETWORK_H_ +#ifndef LIBWEAVE_INCLUDE_WEAVE_TEST_MOCK_NETWORK_H_ +#define LIBWEAVE_INCLUDE_WEAVE_TEST_MOCK_NETWORK_H_ #include <weave/network.h> @@ -12,7 +12,7 @@ #include <gmock/gmock.h> namespace weave { -namespace unittests { +namespace test { class MockNetwork : public Network { public: @@ -48,7 +48,7 @@ } }; -} // namespace unittests +} // namespace test } // namespace weave -#endif // LIBWEAVE_INCLUDE_WEAVE_MOCK_NETWORK_H_ +#endif // LIBWEAVE_INCLUDE_WEAVE_TEST_MOCK_NETWORK_H_
diff --git a/libweave/include/weave/mock_task_runner.h b/libweave/include/weave/test/mock_task_runner.h similarity index 86% rename from libweave/include/weave/mock_task_runner.h rename to libweave/include/weave/test/mock_task_runner.h index 65d9b79..5fee077 100644 --- a/libweave/include/weave/mock_task_runner.h +++ b/libweave/include/weave/test/mock_task_runner.h
@@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef LIBWEAVE_INCLUDE_WEAVE_MOCK_TASK_RUNNER_H_ -#define LIBWEAVE_INCLUDE_WEAVE_MOCK_TASK_RUNNER_H_ +#ifndef LIBWEAVE_INCLUDE_WEAVE_TEST_MOCK_TASK_RUNNER_H_ +#define LIBWEAVE_INCLUDE_WEAVE_TEST_MOCK_TASK_RUNNER_H_ #include <weave/task_runner.h> @@ -16,7 +16,7 @@ #include <gmock/gmock.h> namespace weave { -namespace unittests { +namespace test { class MockTaskRunner : public TaskRunner { public: @@ -55,7 +55,7 @@ MockTaskRunner::Greater> queue_; }; -} // namespace unittests +} // namespace test } // namespace weave -#endif // LIBWEAVE_INCLUDE_WEAVE_MOCK_TASK_RUNNER_H_ +#endif // LIBWEAVE_INCLUDE_WEAVE_TEST_MOCK_TASK_RUNNER_H_
diff --git a/libweave/include/weave/unittest_utils.h b/libweave/include/weave/test/unittest_utils.h similarity index 74% rename from libweave/include/weave/unittest_utils.h rename to libweave/include/weave/test/unittest_utils.h index fe06ab8..95c808f 100644 --- a/libweave/include/weave/unittest_utils.h +++ b/libweave/include/weave/test/unittest_utils.h
@@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef LIBWEAVE_INCLUDE_WEAVE_UNITTEST_UTILS_H_ -#define LIBWEAVE_INCLUDE_WEAVE_UNITTEST_UTILS_H_ +#ifndef LIBWEAVE_INCLUDE_WEAVE_TEST_UNITTEST_UTILS_H_ +#define LIBWEAVE_INCLUDE_WEAVE_TEST_UNITTEST_UTILS_H_ #include <memory> #include <string> @@ -12,7 +12,7 @@ #include <gtest/gtest.h> namespace weave { -namespace unittests { +namespace test { // Helper method to create base::Value from a string as a smart pointer. // For ease of definition in C++ code, double-quotes in the source definition @@ -29,11 +29,11 @@ return val1.Equals(&val2); } -} // namespace unittests +} // namespace test } // namespace weave #define EXPECT_JSON_EQ(expected, actual) \ - EXPECT_PRED2(weave::unittests::IsEqualValue, \ - *weave::unittests::CreateValue(expected), actual) + EXPECT_PRED2(weave::test::IsEqualValue, \ + *weave::test::CreateValue(expected), actual) -#endif // LIBWEAVE_INCLUDE_WEAVE_UNITTEST_UTILS_H_ +#endif // LIBWEAVE_INCLUDE_WEAVE_TEST_UNITTEST_UTILS_H_
diff --git a/libweave/libweave.gypi b/libweave/libweave.gypi index c0e752f..07cf11f 100644 --- a/libweave/libweave.gypi +++ b/libweave/libweave.gypi
@@ -53,10 +53,10 @@ 'third_party/modp_b64/modp_b64.cc', ], 'weave_test_sources': [ - 'src/commands/mock_command.cc', - 'src/commands/unittest_utils.cc', - 'src/mock_http_client.cc', - 'src/mock_task_runner.cc', + 'src/test/mock_command.cc', + 'src/test/mock_http_client.cc', + 'src/test/mock_task_runner.cc', + 'src/test/unittest_utils.cc', ], 'weave_unittest_sources': [ 'external/crypto/p224_spake_unittest.cc', @@ -88,11 +88,11 @@ 'src/states/state_manager_unittest.cc', 'src/states/state_package_unittest.cc', 'src/string_utils_unittest.cc', - 'src/weave_testrunner.cc', + 'src/test/weave_testrunner.cc', ], 'weave_exports_unittest_sources': [ + 'src/test/weave_testrunner.cc', 'src/weave_unittest.cc', - 'src/weave_testrunner.cc', ], 'base_sources': [ 'external/base/bind_helpers.cc',
diff --git a/libweave/src/base_api_handler_unittest.cc b/libweave/src/base_api_handler_unittest.cc index d3b5281..67b4a9f 100644 --- a/libweave/src/base_api_handler_unittest.cc +++ b/libweave/src/base_api_handler_unittest.cc
@@ -7,8 +7,8 @@ #include <base/strings/string_number_conversions.h> #include <base/values.h> #include <gtest/gtest.h> -#include <weave/mock_config_store.h> -#include <weave/mock_http_client.h> +#include <weave/test/mock_config_store.h> +#include <weave/test/mock_http_client.h> #include "libweave/src/commands/command_manager.h" #include "libweave/src/commands/unittest_utils.h" @@ -38,7 +38,7 @@ command_manager_ = std::make_shared<CommandManager>(); state_manager_ = std::make_shared<StateManager>(&mock_state_change_queue_); - auto state_definition = unittests::CreateDictionaryValue(R"({ + auto state_definition = test::CreateDictionaryValue(R"({ 'base': { 'firmwareVersion': 'string', 'localDiscoveryEnabled': 'boolean', @@ -51,7 +51,7 @@ } } })"); - auto state_defaults = unittests::CreateDictionaryValue(R"({ + auto state_defaults = test::CreateDictionaryValue(R"({ 'base': { 'firmwareVersion': '123123', 'localDiscoveryEnabled': false, @@ -72,14 +72,14 @@ } void LoadCommands(const std::string& command_definitions) { - auto json = unittests::CreateDictionaryValue(command_definitions.c_str()); + auto json = test::CreateDictionaryValue(command_definitions.c_str()); EXPECT_TRUE(command_manager_->LoadBaseCommands(*json, nullptr)); EXPECT_TRUE(command_manager_->LoadCommands(*json, "", nullptr)); } void AddCommand(const std::string& command) { auto command_instance = CommandInstance::FromJson( - unittests::CreateDictionaryValue(command.c_str()).get(), + test::CreateDictionaryValue(command.c_str()).get(), CommandOrigin::kLocal, command_manager_->GetCommandDictionary(), nullptr, nullptr); EXPECT_TRUE(!!command_instance); @@ -91,8 +91,8 @@ command_manager_->FindCommand(id)->GetStatus()); } - unittests::MockConfigStore config_store_; - StrictMock<unittests::MockHttpClient> http_client_; + test::MockConfigStore config_store_; + StrictMock<test::MockHttpClient> http_client_; std::unique_ptr<DeviceRegistrationInfo> dev_reg_; std::shared_ptr<CommandManager> command_manager_; testing::StrictMock<MockStateChangeQueueInterface> mock_state_change_queue_;
diff --git a/libweave/src/commands/cloud_command_proxy_unittest.cc b/libweave/src/commands/cloud_command_proxy_unittest.cc index cd3116b..fb881d1 100644 --- a/libweave/src/commands/cloud_command_proxy_unittest.cc +++ b/libweave/src/commands/cloud_command_proxy_unittest.cc
@@ -9,7 +9,7 @@ #include <gmock/gmock.h> #include <gtest/gtest.h> -#include <weave/mock_task_runner.h> +#include <weave/test/mock_task_runner.h> #include "libweave/src/commands/command_dictionary.h" #include "libweave/src/commands/command_instance.h" @@ -24,8 +24,8 @@ namespace weave { -using unittests::CreateDictionaryValue; -using unittests::CreateValue; +using test::CreateDictionaryValue; +using test::CreateValue; namespace { @@ -136,7 +136,7 @@ base::CallbackList<void(StateChangeQueueInterface::UpdateID)> callbacks_; testing::StrictMock<MockCloudCommandUpdateInterface> cloud_updater_; testing::StrictMock<MockStateChangeQueueInterface> state_change_queue_; - testing::StrictMock<unittests::MockTaskRunner> task_runner_; + testing::StrictMock<test::MockTaskRunner> task_runner_; std::queue<base::Closure> task_queue_; CommandDictionary command_dictionary_; std::unique_ptr<CommandInstance> command_instance_;
diff --git a/libweave/src/commands/command_dictionary_unittest.cc b/libweave/src/commands/command_dictionary_unittest.cc index 17c0af2..230da29 100644 --- a/libweave/src/commands/command_dictionary_unittest.cc +++ b/libweave/src/commands/command_dictionary_unittest.cc
@@ -10,8 +10,8 @@ namespace weave { -using unittests::CreateDictionaryValue; -using unittests::IsEqualValue; +using test::CreateDictionaryValue; +using test::IsEqualValue; TEST(CommandDictionary, Empty) { CommandDictionary dict;
diff --git a/libweave/src/commands/command_instance_unittest.cc b/libweave/src/commands/command_instance_unittest.cc index 2c2fe45..49dd1b7 100644 --- a/libweave/src/commands/command_instance_unittest.cc +++ b/libweave/src/commands/command_instance_unittest.cc
@@ -13,8 +13,8 @@ namespace weave { -using unittests::CreateDictionaryValue; -using unittests::CreateValue; +using test::CreateDictionaryValue; +using test::CreateValue; namespace {
diff --git a/libweave/src/commands/command_manager_unittest.cc b/libweave/src/commands/command_manager_unittest.cc index 00ab9c8..2e7ce27 100644 --- a/libweave/src/commands/command_manager_unittest.cc +++ b/libweave/src/commands/command_manager_unittest.cc
@@ -8,7 +8,7 @@ #include <base/json/json_writer.h> #include <gtest/gtest.h> -#include <weave/mock_config_store.h> +#include <weave/test/mock_config_store.h> #include "libweave/src/bind_lambda.h" #include "libweave/src/commands/unittest_utils.h" @@ -17,7 +17,7 @@ namespace weave { -using unittests::CreateDictionaryValue; +using test::CreateDictionaryValue; namespace { @@ -115,7 +115,7 @@ TEST(CommandManager, ShouldLoadStandardAndTestDefinitions) { CommandManager manager; - unittests::MockConfigStore config_store; + test::MockConfigStore config_store; EXPECT_CALL(config_store, LoadBaseCommandDefs()) .WillOnce(Return(kTestBaseCommands)); EXPECT_CALL(config_store, LoadCommandDefs())
diff --git a/libweave/src/commands/object_schema_unittest.cc b/libweave/src/commands/object_schema_unittest.cc index c7c448a..b8a623e 100644 --- a/libweave/src/commands/object_schema_unittest.cc +++ b/libweave/src/commands/object_schema_unittest.cc
@@ -21,8 +21,8 @@ namespace weave { -using unittests::CreateValue; -using unittests::CreateDictionaryValue; +using test::CreateValue; +using test::CreateDictionaryValue; namespace {
diff --git a/libweave/src/commands/schema_utils_unittest.cc b/libweave/src/commands/schema_utils_unittest.cc index 9dfadc3..4ac735f 100644 --- a/libweave/src/commands/schema_utils_unittest.cc +++ b/libweave/src/commands/schema_utils_unittest.cc
@@ -19,8 +19,8 @@ namespace weave { -using unittests::CreateDictionaryValue; -using unittests::CreateValue; +using test::CreateDictionaryValue; +using test::CreateValue; TEST(CommandSchemaUtils, TypedValueToJson_Scalar) { EXPECT_JSON_EQ("true", *TypedValueToJson(true));
diff --git a/libweave/src/commands/unittest_utils.h b/libweave/src/commands/unittest_utils.h index c232f84..78eeefd 100644 --- a/libweave/src/commands/unittest_utils.h +++ b/libweave/src/commands/unittest_utils.h
@@ -10,13 +10,13 @@ #include <base/values.h> #include <gtest/gtest.h> -#include <weave/unittest_utils.h> +#include <weave/test/unittest_utils.h> #include "libweave/src/commands/prop_types.h" #include "libweave/src/commands/prop_values.h" namespace weave { -namespace unittests { +namespace test { template <typename T> std::unique_ptr<const PropValue> make_prop_value(const base::Value& value) { @@ -41,7 +41,7 @@ return make_prop_value<std::string>(base::StringValue{value}); } -} // namespace unittests +} // namespace test } // namespace weave #endif // LIBWEAVE_SRC_COMMANDS_UNITTEST_UTILS_H_
diff --git a/libweave/src/config_unittest.cc b/libweave/src/config_unittest.cc index 7746fbd..9ee16af 100644 --- a/libweave/src/config_unittest.cc +++ b/libweave/src/config_unittest.cc
@@ -9,7 +9,7 @@ #include <base/bind.h> #include <gmock/gmock.h> #include <gtest/gtest.h> -#include <weave/mock_config_store.h> +#include <weave/test/mock_config_store.h> #include "libweave/src/commands/unittest_utils.h" @@ -31,7 +31,7 @@ MOCK_METHOD1(OnConfigChanged, void(const Settings&)); - unittests::MockConfigStore config_store_; + test::MockConfigStore config_store_; std::unique_ptr<Config> config_; const Config default_{nullptr}; }; @@ -203,7 +203,7 @@ 'last_configured_ssid': 'set_last_configured_ssid', 'service_url': 'set_service_url' })"; - EXPECT_JSON_EQ(expected, *unittests::CreateValue(json)); + EXPECT_JSON_EQ(expected, *test::CreateValue(json)); })); EXPECT_CALL(config_store_, OnSettingsChanged(_)).Times(1);
diff --git a/libweave/src/device_registration_info.cc b/libweave/src/device_registration_info.cc index cd62cac..2f058a8 100644 --- a/libweave/src/device_registration_info.cc +++ b/libweave/src/device_registration_info.cc
@@ -283,7 +283,7 @@ const base::TimeDelta& delay) { SetRegistrationStatus(RegistrationStatus::kConnecting); if (!task_runner_) - return; // Assume we're in unittests + return; // Assume we're in test task_runner_->PostDelayedTask( FROM_HERE, base::Bind(&DeviceRegistrationInfo::ConnectToCloud, AsWeakPtr()), @@ -435,7 +435,7 @@ LOG(INFO) << "Starting notification channel"; - // If no TaskRunner assume we're in unittests. + // If no TaskRunner assume we're in test. if (!task_runner_) { LOG(INFO) << "No TaskRunner, not starting notification channel"; return;
diff --git a/libweave/src/device_registration_info_unittest.cc b/libweave/src/device_registration_info_unittest.cc index ec79c5d..8bbf987 100644 --- a/libweave/src/device_registration_info_unittest.cc +++ b/libweave/src/device_registration_info_unittest.cc
@@ -8,8 +8,8 @@ #include <base/json/json_writer.h> #include <base/values.h> #include <gtest/gtest.h> -#include <weave/mock_config_store.h> -#include <weave/mock_http_client.h> +#include <weave/test/mock_config_store.h> +#include <weave/test/mock_http_client.h> #include "libweave/src/bind_lambda.h" #include "libweave/src/commands/command_manager.h" @@ -32,10 +32,10 @@ namespace weave { -using unittests::CreateDictionaryValue; -using unittests::CreateValue; -using unittests::MockHttpClient; -using unittests::MockHttpClientResponse; +using test::CreateDictionaryValue; +using test::CreateValue; +using test::MockHttpClient; +using test::MockHttpClientResponse; namespace { @@ -181,7 +181,7 @@ return dev_reg_->registration_status_; } - unittests::MockConfigStore config_store_; + test::MockConfigStore config_store_; StrictMock<MockHttpClient> http_client_; base::DictionaryValue data_; Config* config_{nullptr}; @@ -375,7 +375,7 @@ MockSendRequest(http::kPatch, ticket_url + "?key=" + test_data::kApiKey, HttpClient::Headers{GetJsonHeader()}, _, _)) .WillOnce(WithArgs<3>(Invoke([](const std::string& data) { - auto json = unittests::CreateDictionaryValue(data); + auto json = test::CreateDictionaryValue(data); EXPECT_NE(nullptr, json.get()); std::string value; EXPECT_TRUE(json->GetString("id", &value));
diff --git a/libweave/src/notification/notification_parser_unittest.cc b/libweave/src/notification/notification_parser_unittest.cc index 8c13460..3572542 100644 --- a/libweave/src/notification/notification_parser_unittest.cc +++ b/libweave/src/notification/notification_parser_unittest.cc
@@ -15,7 +15,7 @@ namespace weave { -using unittests::CreateDictionaryValue; +using test::CreateDictionaryValue; class MockNotificationDelegate : public NotificationDelegate { public:
diff --git a/libweave/src/notification/xmpp_channel_unittest.cc b/libweave/src/notification/xmpp_channel_unittest.cc index eaacf83..574dfa2 100644 --- a/libweave/src/notification/xmpp_channel_unittest.cc +++ b/libweave/src/notification/xmpp_channel_unittest.cc
@@ -8,7 +8,7 @@ #include <queue> #include <gtest/gtest.h> -#include <weave/mock_task_runner.h> +#include <weave/test/mock_task_runner.h> #include "libweave/src/bind_lambda.h" @@ -176,7 +176,7 @@ EXPECT_EQ(st, xmpp_client_.state()); } - StrictMock<unittests::MockTaskRunner> task_runner_; + StrictMock<test::MockTaskRunner> task_runner_; FakeXmppChannel xmpp_client_{&task_runner_}; };
diff --git a/libweave/src/notification/xmpp_iq_stanza_handler_unittest.cc b/libweave/src/notification/xmpp_iq_stanza_handler_unittest.cc index b66fd50..3880f34 100644 --- a/libweave/src/notification/xmpp_iq_stanza_handler_unittest.cc +++ b/libweave/src/notification/xmpp_iq_stanza_handler_unittest.cc
@@ -9,7 +9,7 @@ #include <gmock/gmock.h> #include <gtest/gtest.h> -#include <weave/mock_task_runner.h> +#include <weave/test/mock_task_runner.h> #include "libweave/src/bind_lambda.h" #include "libweave/src/notification/xml_node.h" @@ -76,7 +76,7 @@ class IqStanzaHandlerTest : public testing::Test { public: testing::StrictMock<MockXmppChannelInterface> mock_xmpp_channel_; - unittests::MockTaskRunner task_runner_; + test::MockTaskRunner task_runner_; IqStanzaHandler iq_stanza_handler_{&mock_xmpp_channel_, &task_runner_}; MockResponseReceiver receiver_; };
diff --git a/libweave/src/privet/security_manager_unittest.cc b/libweave/src/privet/security_manager_unittest.cc index 2b7babb..b19b0ee 100644 --- a/libweave/src/privet/security_manager_unittest.cc +++ b/libweave/src/privet/security_manager_unittest.cc
@@ -19,7 +19,7 @@ #include <base/strings/string_util.h> #include <gmock/gmock.h> #include <gtest/gtest.h> -#include <weave/mock_task_runner.h> +#include <weave/test/mock_task_runner.h> #include "libweave/external/crypto/p224_spake.h" #include "libweave/src/data_encoding.h" @@ -100,7 +100,7 @@ } const base::Time time_ = base::Time::FromTimeT(1410000000); - unittests::MockTaskRunner task_runner_; + test::MockTaskRunner task_runner_; SecurityManager security_{{PairingType::kEmbeddedCode}, "1234", false,
diff --git a/libweave/src/states/state_change_queue_unittest.cc b/libweave/src/states/state_change_queue_unittest.cc index 83dcc11..002647e 100644 --- a/libweave/src/states/state_change_queue_unittest.cc +++ b/libweave/src/states/state_change_queue_unittest.cc
@@ -27,9 +27,8 @@ } TEST_F(StateChangeQueueTest, UpdateOne) { - StateChange change{ - base::Time::Now(), - ValueMap{{"prop.name", unittests::make_int_prop_value(23)}}}; + StateChange change{base::Time::Now(), + ValueMap{{"prop.name", test::make_int_prop_value(23)}}}; ASSERT_TRUE(queue_->NotifyPropertiesUpdated(change.timestamp, change.changed_properties)); EXPECT_FALSE(queue_->IsEmpty()); @@ -45,18 +44,16 @@ // TODO(vitalybuka): Fix flakiness. TEST_F(StateChangeQueueTest, DISABLED_UpdateMany) { - StateChange change1{ - base::Time::Now(), - ValueMap{{"prop.name1", unittests::make_int_prop_value(23)}}}; + StateChange change1{base::Time::Now(), + ValueMap{{"prop.name1", test::make_int_prop_value(23)}}}; ASSERT_TRUE(queue_->NotifyPropertiesUpdated(change1.timestamp, change1.changed_properties)); - StateChange change2{ - base::Time::Now(), - ValueMap{ - {"prop.name1", unittests::make_int_prop_value(17)}, - {"prop.name2", unittests::make_double_prop_value(1.0)}, - {"prop.name3", unittests::make_bool_prop_value(false)}, - }}; + StateChange change2{base::Time::Now(), + ValueMap{ + {"prop.name1", test::make_int_prop_value(17)}, + {"prop.name2", test::make_double_prop_value(1.0)}, + {"prop.name3", test::make_bool_prop_value(false)}, + }}; ASSERT_TRUE(queue_->NotifyPropertiesUpdated(change2.timestamp, change2.changed_properties)); EXPECT_EQ(2, queue_->GetLastStateChangeId()); @@ -76,28 +73,28 @@ base::TimeDelta time_delta = base::TimeDelta::FromMinutes(1); ASSERT_TRUE(queue_->NotifyPropertiesUpdated( - timestamp, ValueMap{{"prop.name1", unittests::make_int_prop_value(1)}})); + timestamp, ValueMap{{"prop.name1", test::make_int_prop_value(1)}})); ASSERT_TRUE(queue_->NotifyPropertiesUpdated( - timestamp, ValueMap{{"prop.name2", unittests::make_int_prop_value(2)}})); + timestamp, ValueMap{{"prop.name2", test::make_int_prop_value(2)}})); ASSERT_TRUE(queue_->NotifyPropertiesUpdated( - timestamp, ValueMap{{"prop.name1", unittests::make_int_prop_value(3)}})); + timestamp, ValueMap{{"prop.name1", test::make_int_prop_value(3)}})); ASSERT_TRUE(queue_->NotifyPropertiesUpdated( timestamp + time_delta, - ValueMap{{"prop.name1", unittests::make_int_prop_value(4)}})); + ValueMap{{"prop.name1", test::make_int_prop_value(4)}})); auto changes = queue_->GetAndClearRecordedStateChanges(); EXPECT_EQ(4, queue_->GetLastStateChangeId()); ASSERT_EQ(2, changes.size()); ValueMap expected1{ - {"prop.name1", unittests::make_int_prop_value(3)}, - {"prop.name2", unittests::make_int_prop_value(2)}, + {"prop.name1", test::make_int_prop_value(3)}, + {"prop.name2", test::make_int_prop_value(2)}, }; ValueMap expected2{ - {"prop.name1", unittests::make_int_prop_value(4)}, + {"prop.name1", test::make_int_prop_value(4)}, }; EXPECT_EQ(timestamp, changes[0].timestamp); EXPECT_EQ(expected1, changes[0].changed_properties); @@ -113,22 +110,22 @@ ASSERT_TRUE(queue_->NotifyPropertiesUpdated( start_time, ValueMap{ - {"prop.name1", unittests::make_int_prop_value(1)}, - {"prop.name2", unittests::make_int_prop_value(2)}, + {"prop.name1", test::make_int_prop_value(1)}, + {"prop.name2", test::make_int_prop_value(2)}, })); ASSERT_TRUE(queue_->NotifyPropertiesUpdated( start_time + time_delta1, ValueMap{ - {"prop.name1", unittests::make_int_prop_value(3)}, - {"prop.name3", unittests::make_int_prop_value(4)}, + {"prop.name1", test::make_int_prop_value(3)}, + {"prop.name3", test::make_int_prop_value(4)}, })); ASSERT_TRUE(queue_->NotifyPropertiesUpdated( start_time + time_delta2, ValueMap{ - {"prop.name10", unittests::make_int_prop_value(10)}, - {"prop.name11", unittests::make_int_prop_value(11)}, + {"prop.name10", test::make_int_prop_value(10)}, + {"prop.name11", test::make_int_prop_value(11)}, })); EXPECT_EQ(3, queue_->GetLastStateChangeId()); @@ -136,16 +133,16 @@ ASSERT_EQ(2, changes.size()); ValueMap expected1{ - {"prop.name1", unittests::make_int_prop_value(3)}, - {"prop.name2", unittests::make_int_prop_value(2)}, - {"prop.name3", unittests::make_int_prop_value(4)}, + {"prop.name1", test::make_int_prop_value(3)}, + {"prop.name2", test::make_int_prop_value(2)}, + {"prop.name3", test::make_int_prop_value(4)}, }; EXPECT_EQ(start_time + time_delta1, changes[0].timestamp); EXPECT_EQ(expected1, changes[0].changed_properties); ValueMap expected2{ - {"prop.name10", unittests::make_int_prop_value(10)}, - {"prop.name11", unittests::make_int_prop_value(11)}, + {"prop.name10", test::make_int_prop_value(10)}, + {"prop.name11", test::make_int_prop_value(11)}, }; EXPECT_EQ(start_time + time_delta2, changes[1].timestamp); EXPECT_EQ(expected2, changes[1].changed_properties); @@ -165,8 +162,8 @@ // When queue is not empty, registering a new callback will not trigger it. ASSERT_TRUE(queue_->NotifyPropertiesUpdated( base::Time::Now(), ValueMap{ - {"prop.name1", unittests::make_int_prop_value(1)}, - {"prop.name2", unittests::make_int_prop_value(2)}, + {"prop.name1", test::make_int_prop_value(1)}, + {"prop.name2", test::make_int_prop_value(2)}, })); auto callback = [](StateChangeQueueInterface::UpdateID id) {
diff --git a/libweave/src/states/state_manager_unittest.cc b/libweave/src/states/state_manager_unittest.cc index 98723f7..a7511cc 100644 --- a/libweave/src/states/state_manager_unittest.cc +++ b/libweave/src/states/state_manager_unittest.cc
@@ -11,7 +11,7 @@ #include <base/values.h> #include <gmock/gmock.h> #include <gtest/gtest.h> -#include <weave/mock_config_store.h> +#include <weave/test/mock_config_store.h> #include "libweave/src/commands/schema_constants.h" #include "libweave/src/commands/unittest_utils.h" @@ -22,7 +22,7 @@ using testing::_; using testing::Return; -using unittests::CreateDictionaryValue; +using test::CreateDictionaryValue; namespace { @@ -138,7 +138,7 @@ } TEST_F(StateManagerTest, Startup) { - unittests::MockConfigStore config_store; + test::MockConfigStore config_store; StateManager manager(&mock_state_change_queue_); EXPECT_CALL(config_store, LoadBaseStateDefs()) @@ -173,8 +173,7 @@ TEST_F(StateManagerTest, SetPropertyValue) { ValueMap expected_prop_set{ - {"device.state_property", - unittests::make_string_prop_value("Test Value")}, + {"device.state_property", test::make_string_prop_value("Test Value")}, }; EXPECT_CALL(mock_state_change_queue_, NotifyPropertiesUpdated(timestamp_, expected_prop_set)) @@ -232,7 +231,7 @@ std::vector<StateChange> expected_val; expected_val.emplace_back( timestamp_, ValueMap{{"device.state_property", - unittests::make_string_prop_value("Test Value")}}); + test::make_string_prop_value("Test Value")}}); EXPECT_CALL(mock_state_change_queue_, GetAndClearRecordedStateChanges()) .WillOnce(Return(expected_val)); EXPECT_CALL(mock_state_change_queue_, GetLastStateChangeId()) @@ -246,7 +245,7 @@ TEST_F(StateManagerTest, SetProperties) { ValueMap expected_prop_set{ - {"base.manufacturer", unittests::make_string_prop_value("No Name")}, + {"base.manufacturer", test::make_string_prop_value("No Name")}, }; EXPECT_CALL(mock_state_change_queue_, NotifyPropertiesUpdated(_, expected_prop_set))
diff --git a/libweave/src/states/state_package_unittest.cc b/libweave/src/states/state_package_unittest.cc index 45914bc..8174ac6 100644 --- a/libweave/src/states/state_package_unittest.cc +++ b/libweave/src/states/state_package_unittest.cc
@@ -16,7 +16,7 @@ namespace weave { -using unittests::CreateDictionaryValue; +using test::CreateDictionaryValue; class StatePackageTestHelper { public:
diff --git a/libweave/src/commands/mock_command.cc b/libweave/src/test/mock_command.cc similarity index 90% rename from libweave/src/commands/mock_command.cc rename to libweave/src/test/mock_command.cc index ee36347..91bd9a8 100644 --- a/libweave/src/commands/mock_command.cc +++ b/libweave/src/test/mock_command.cc
@@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <weave/mock_command.h> +#include <weave/test/mock_command.h> #include <memory> #include <string> @@ -12,7 +12,7 @@ #include "libweave/src/commands/unittest_utils.h" namespace weave { -namespace unittests { +namespace test { std::unique_ptr<base::DictionaryValue> MockCommand::GetParameters() const { return CreateDictionaryValue(MockGetParameters()); @@ -30,5 +30,5 @@ return CreateDictionaryValue(MockToJson()); } -} // namespace unittests +} // namespace test } // namespace weave
diff --git a/libweave/src/mock_http_client.cc b/libweave/src/test/mock_http_client.cc similarity index 93% rename from libweave/src/mock_http_client.cc rename to libweave/src/test/mock_http_client.cc index a1d7160..879f213 100644 --- a/libweave/src/mock_http_client.cc +++ b/libweave/src/test/mock_http_client.cc
@@ -2,13 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <weave/mock_http_client.h> +#include <weave/test/mock_http_client.h> #include <memory> #include <string> namespace weave { -namespace unittests { +namespace test { std::unique_ptr<HttpClient::Response> MockHttpClient::SendRequestAndBlock( const std::string& method, @@ -37,5 +37,5 @@ return 0; } -} // namespace unittests +} // namespace test } // namespace weave
diff --git a/libweave/src/mock_task_runner.cc b/libweave/src/test/mock_task_runner.cc similarity index 94% rename from libweave/src/mock_task_runner.cc rename to libweave/src/test/mock_task_runner.cc index 5052b94..da9246a 100644 --- a/libweave/src/mock_task_runner.cc +++ b/libweave/src/test/mock_task_runner.cc
@@ -2,14 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <weave/mock_task_runner.h> +#include <weave/test/mock_task_runner.h> using testing::_; using testing::Invoke; using testing::AnyNumber; namespace weave { -namespace unittests { +namespace test { class MockTaskRunner::TestClock : public base::Clock { public: @@ -54,5 +54,5 @@ queue_.emplace(std::make_pair(test_clock_->Now() + delay, ++counter_), task); } -} // namespace unittests +} // namespace test } // namespace weave
diff --git a/libweave/src/commands/unittest_utils.cc b/libweave/src/test/unittest_utils.cc similarity index 96% rename from libweave/src/commands/unittest_utils.cc rename to libweave/src/test/unittest_utils.cc index 3148ffe..6f55e81 100644 --- a/libweave/src/commands/unittest_utils.cc +++ b/libweave/src/test/unittest_utils.cc
@@ -9,7 +9,7 @@ #include <base/logging.h> namespace weave { -namespace unittests { +namespace test { std::unique_ptr<base::Value> CreateValue(const std::string& json) { std::string json2(json); @@ -42,5 +42,5 @@ return std::unique_ptr<base::DictionaryValue>(dict); } -} // namespace unittests +} // namespace test } // namespace weave
diff --git a/libweave/src/weave_testrunner.cc b/libweave/src/test/weave_testrunner.cc similarity index 100% rename from libweave/src/weave_testrunner.cc rename to libweave/src/test/weave_testrunner.cc
diff --git a/libweave/src/weave_unittest.cc b/libweave/src/weave_unittest.cc index f0bbfa8..fb00b8e 100644 --- a/libweave/src/weave_unittest.cc +++ b/libweave/src/weave_unittest.cc
@@ -6,13 +6,13 @@ #include <gmock/gmock.h> #include <gtest/gtest.h> -#include <weave/mock_config_store.h> -#include <weave/mock_http_client.h> -#include <weave/mock_http_server.h> -#include <weave/mock_mdns.h> -#include <weave/mock_network.h> -#include <weave/mock_task_runner.h> -#include <weave/unittest_utils.h> +#include <weave/test/mock_config_store.h> +#include <weave/test/mock_http_client.h> +#include <weave/test/mock_http_server.h> +#include <weave/test/mock_mdns.h> +#include <weave/test/mock_network.h> +#include <weave/test/mock_task_runner.h> +#include <weave/test/unittest_utils.h> #include "libweave/src/bind_lambda.h" @@ -32,8 +32,8 @@ namespace weave { -using unittests::CreateDictionaryValue; -using unittests::ValueToString; +using test::CreateDictionaryValue; +using test::ValueToString; const char kCategory[] = "powerd"; @@ -162,8 +162,8 @@ const std::string& json_response) { EXPECT_CALL(http_client_, MockSendRequest(method, url, _, _, _)) .WillOnce(InvokeWithoutArgs([json_response]() { - unittests::MockHttpClientResponse* response = - new StrictMock<unittests::MockHttpClientResponse>; + test::MockHttpClientResponse* response = + new StrictMock<test::MockHttpClientResponse>; EXPECT_CALL(*response, GetStatusCode()) .Times(AtLeast(1)) .WillRepeatedly(Return(200)); @@ -295,12 +295,12 @@ std::vector<HttpServer::OnStateChangedCallback> http_server_changed_cb_; std::vector<HttpServer::OnRequestCallback> http_server_request_cb_; - StrictMock<unittests::MockConfigStore> config_store_; - StrictMock<unittests::MockTaskRunner> task_runner_; - StrictMock<unittests::MockHttpClient> http_client_; - StrictMock<unittests::MockNetwork> network_; - StrictMock<unittests::MockMdns> mdns_; - StrictMock<unittests::MockHttpServer> http_server_; + StrictMock<test::MockConfigStore> config_store_; + StrictMock<test::MockTaskRunner> task_runner_; + StrictMock<test::MockHttpClient> http_client_; + StrictMock<test::MockNetwork> network_; + StrictMock<test::MockMdns> mdns_; + StrictMock<test::MockHttpServer> http_server_; weave::Cloud* cloud_{nullptr};