diff options
6 files changed, 110 insertions, 47 deletions
diff --git a/src/components/include/utils/make_shared.h b/src/components/include/utils/make_shared.h index dc817e362d..665344737c 100644 --- a/src/components/include/utils/make_shared.h +++ b/src/components/include/utils/make_shared.h @@ -69,6 +69,43 @@ SharedPtr<T> MakeShared() { } template<typename T, typename Arg1> +SharedPtr<T> MakeShared(Arg1& arg1) { + T* t = new (std::nothrow) T(arg1); + return Initialize(t); +} + +template<typename T, typename Arg1, typename Arg2> +SharedPtr<T> MakeShared(Arg1& arg1, Arg2& arg2) { + T* t = new (std::nothrow) T(arg1, arg2); + return Initialize(t); +} + +template<typename T, typename Arg1, typename Arg2, typename Arg3> +SharedPtr<T> MakeShared(Arg1& arg1, Arg2& arg2, Arg3& arg3) { + T* t = new (std::nothrow) T(arg1, arg2, arg3); + return Initialize(t); +} + +template<typename T, typename Arg1, typename Arg2, typename Arg3, typename Arg4> +SharedPtr<T> MakeShared(Arg1& arg1, Arg2& arg2, Arg3& arg3, Arg4& arg4) { + T* t = new (std::nothrow) T(arg1, arg2, arg3, arg4); + return Initialize(t); +} + +template<typename T, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5> +SharedPtr<T> MakeShared(Arg1& arg1, Arg2& arg2, Arg3& arg3, Arg4& arg4, Arg5& arg5) { + T* t = new (std::nothrow) T(arg1, arg2, arg3, arg4, arg5); + return Initialize(t); +} + +template<typename T, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5, typename Arg6> +SharedPtr<T> MakeShared(Arg1& arg1, Arg2& arg2, Arg3& arg3, Arg4& arg4, Arg5& arg5, Arg6& arg6) { + T* t = new (std::nothrow) T(arg1, arg2, arg3, arg4, arg5, arg6); + return Initialize(t); +} + + +template<typename T, typename Arg1> SharedPtr<T> MakeShared(const Arg1& arg1) { T* t = new (std::nothrow) T(arg1); return Initialize(t); @@ -104,5 +141,6 @@ SharedPtr<T> MakeShared(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3, co return Initialize(t); } + } // namespace utils; #endif // SRC_COMPONENTS_INCLUDE_UTILS_MAKE_SHARED_H_ diff --git a/src/components/include/utils/shared_ptr.h b/src/components/include/utils/shared_ptr.h index d8701eb1f3..a8afd93d19 100644 --- a/src/components/include/utils/shared_ptr.h +++ b/src/components/include/utils/shared_ptr.h @@ -41,6 +41,9 @@ #include "utils/atomic.h" namespace utils { + + + /** * @brief Shared pointer. * @@ -52,9 +55,13 @@ namespace utils { **/ template<typename ObjectType> class SharedPtr { + static void DummyDeleter(ObjectType* t) { + delete t; + } public: //std smart pointer compatibility typedef ObjectType element_type; + typedef void (*Deleter)(ObjectType*) ; /** * @brief Constructor. * @@ -65,6 +72,13 @@ class SharedPtr { **/ SharedPtr(ObjectType* Object); + SharedPtr(ObjectType* Object, Deleter deleter): + mObject(Object), + mReferenceCounter(new uint32_t(1)), + deleter_(deleter) { + + } + SharedPtr(); /** @@ -198,18 +212,21 @@ class SharedPtr { **/ ObjectType* mObject; + /** * @brief Pointer to reference counter. **/ uint32_t* mReferenceCounter; + Deleter deleter_; void release(); }; template<typename ObjectType> inline utils::SharedPtr<ObjectType>::SharedPtr(ObjectType* Object) : mObject(NULL), - mReferenceCounter(new uint32_t(1)) { + mReferenceCounter(new uint32_t(1)), + deleter_(DummyDeleter) { DCHECK(Object != NULL); mObject = Object; } @@ -217,14 +234,16 @@ inline utils::SharedPtr<ObjectType>::SharedPtr(ObjectType* Object) template<typename ObjectType> inline utils::SharedPtr<ObjectType>::SharedPtr() : mObject(0), - mReferenceCounter(0) { + mReferenceCounter(0), + deleter_(DummyDeleter) { } template<typename ObjectType> inline utils::SharedPtr<ObjectType>::SharedPtr( const SharedPtr<ObjectType>& Other) : mObject(0), - mReferenceCounter(0) { + mReferenceCounter(0), + deleter_(DummyDeleter) { *this = Other; } @@ -233,7 +252,8 @@ template<typename OtherObjectType> inline utils::SharedPtr<ObjectType>::SharedPtr( const SharedPtr<OtherObjectType>& Other) : mObject(0), - mReferenceCounter(0) { + mReferenceCounter(0), + deleter_(DummyDeleter) { *this = Other; } @@ -337,8 +357,7 @@ utils::SharedPtr<ObjectType>::reset(ObjectType* other) { template<typename ObjectType> void SharedPtr<ObjectType>::release() { - - delete mObject; + deleter_(mObject); mObject = 0; delete mReferenceCounter; diff --git a/src/components/resumption/test/last_state_test.cc b/src/components/resumption/test/last_state_test.cc index 31bb26567b..1dca8bf57b 100644 --- a/src/components/resumption/test/last_state_test.cc +++ b/src/components/resumption/test/last_state_test.cc @@ -30,75 +30,84 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include "gtest/gtest.h" #include <string> -#include <memory> + +#include "gtest/gtest.h" + #include "resumption/last_state.h" -#include "config_profile/profile.h" #include "utils/file_system.h" -#include "utils/shared_ptr.h" -#include "utils/make_shared.h" namespace test { namespace components { -namespace resumption { +namespace resumption_test { using namespace ::resumption; using namespace ::Json; +const std::string kAppStorageFolder = "app_storage_folder"; +const std::string kAppInfoStorageFile = "app_info_storage"; class LastStateTest : public ::testing::Test { protected: - void SetUp() OVERRIDE { - file_system::DeleteFile("./app_info_storage"); - last_state_ = std::auto_ptr<resumption::LastState>( - new resumption::LastState("app_storage_folder", "app_info_storage")); - ASSERT_TRUE(file_system::CreateFile("./app_info.dat")); - profile::Profile::instance()->UpdateValues(); + LastStateTest() + : empty_dictionary_("null\n") + , app_info_dat_file_("app_info.dat") + , last_state_(kAppStorageFolder, kAppInfoStorageFile){} + + static void SetUpTestCase() { + file_system::DeleteFile(kAppInfoStorageFile); + file_system::RemoveDirectory(kAppStorageFolder); } - void TearDown() OVERRIDE { - EXPECT_TRUE(file_system::DeleteFile("./app_info.dat")); + virtual void SetUp() { + ASSERT_TRUE(file_system::CreateFile(app_info_dat_file_)); } - std::auto_ptr<resumption::LastState> last_state_; + + virtual void TearDown() { + EXPECT_TRUE(file_system::DeleteFile((app_info_dat_file_))); + } + + const std::string empty_dictionary_; + const std::string app_info_dat_file_; + + resumption::LastState last_state_; }; TEST_F(LastStateTest, Basic) { - Value& dictionary = last_state_->dictionary; - const std::string empty_dictionary = "null\n"; - EXPECT_EQ(empty_dictionary, dictionary.toStyledString()); + Value& dictionary = last_state_.dictionary; + EXPECT_EQ(empty_dictionary_, dictionary.toStyledString()); } TEST_F(LastStateTest, SetGetData) { { - Value& dictionary = last_state_->dictionary; - Value bluetooth_info = dictionary["TransportManager"]["BluetoothAdapter"]; - const std::string empty_bluetooth = "null\n"; - EXPECT_EQ(empty_bluetooth, bluetooth_info.toStyledString()); + Value& dictionary = last_state_.dictionary; + Value& bluetooth_info = dictionary["TransportManager"]["BluetoothAdapter"]; + EXPECT_EQ(empty_dictionary_, bluetooth_info.toStyledString()); - Value tcp_adapter_info = + Value& tcp_adapter_info = dictionary["TransportManager"]["TcpAdapter"]["devices"]; - const std::string no_devices = "null\n"; - EXPECT_EQ(no_devices, tcp_adapter_info.toStyledString()); + EXPECT_EQ(empty_dictionary_, tcp_adapter_info.toStyledString()); - Value resumption_time = dictionary["resumption"]["last_ign_off_time"]; + Value& resumption_time = dictionary["resumption"]["last_ign_off_time"]; EXPECT_EQ("null\n", resumption_time.toStyledString()); - Value resumption_list = dictionary["resumption"]["resume_app_list"]; + Value& resumption_list = dictionary["resumption"]["resume_app_list"]; EXPECT_EQ("null\n", resumption_list.toStyledString()); Value test_value; test_value["name"] = "test_device"; last_state_ - ->dictionary["TransportManager"]["TcpAdapter"]["devices"] = test_value; + .dictionary["TransportManager"]["TcpAdapter"]["devices"] = test_value; last_state_ - ->dictionary["TransportManager"]["BluetoothAdapter"]["devices"] = + .dictionary["TransportManager"]["BluetoothAdapter"]["devices"] = "bluetooth_device"; - last_state_->SaveToFileSystem(); + last_state_.SaveToFileSystem(); } - Value& dictionary = last_state_->dictionary; - Value bluetooth_info = dictionary["TransportManager"]["BluetoothAdapter"]; - Value tcp_adapter_info = dictionary["TransportManager"]["TcpAdapter"]; + + Value& dictionary = last_state_.dictionary; + + Value& bluetooth_info = dictionary["TransportManager"]["BluetoothAdapter"]; + Value& tcp_adapter_info = dictionary["TransportManager"]["TcpAdapter"]; EXPECT_EQ("{\n \"devices\" : \"bluetooth_device\"\n}\n", bluetooth_info.toStyledString()); EXPECT_EQ( @@ -106,6 +115,6 @@ TEST_F(LastStateTest, SetGetData) { tcp_adapter_info.toStyledString()); } -} // namespace resumption +} // namespace resumption_test } // namespace components } // namespace test diff --git a/src/components/security_manager/include/security_manager/crypto_manager_settings_impl.h b/src/components/security_manager/include/security_manager/crypto_manager_settings_impl.h index 0e359f201d..727a49dcd4 100644 --- a/src/components/security_manager/include/security_manager/crypto_manager_settings_impl.h +++ b/src/components/security_manager/include/security_manager/crypto_manager_settings_impl.h @@ -35,8 +35,7 @@ class CryptoManagerSettingsImpl : public CryptoManagerSettings { } LOG4CXX_ERROR( logger_, - "Unknown protocol: " << profile::Profile::instance() - ->security_manager_protocol_name()); + "Unknown protocol: " << profile_.security_manager_protocol_name()); return static_cast<security_manager::Protocol>(-1); } bool verify_peer() const OVERRIDE { diff --git a/src/components/utils/src/threads/posix_thread.cc b/src/components/utils/src/threads/posix_thread.cc index 7b76299475..b1ee2f87a1 100644 --- a/src/components/utils/src/threads/posix_thread.cc +++ b/src/components/utils/src/threads/posix_thread.cc @@ -35,7 +35,8 @@ #include <stddef.h> #include <signal.h> #include <pthread.h> -#include <sched.h> +#include <algorithm> +#include <functional> #include "utils/threads/thread.h" #include "utils/atomic.h" diff --git a/src/components/utils/test/auto_trace_test.cc b/src/components/utils/test/auto_trace_test.cc index e131caf7c2..f3aaea490f 100644 --- a/src/components/utils/test/auto_trace_test.cc +++ b/src/components/utils/test/auto_trace_test.cc @@ -36,7 +36,6 @@ #include "gtest/gtest.h" #include "utils/auto_trace.h" #include "utils/logger.h" -#include "config_profile/profile.h" #include "utils/log_message_loop_thread.h" #include "utils/threads/message_loop_thread.h" #include "utils/file_system.h" @@ -63,9 +62,7 @@ void Preconditions() { void InitLogger() { // Set enabled logs - profile::Profile::instance()->config_file_name("smartDeviceLink.ini"); - profile::Profile::instance()->UpdateValues(); - INIT_LOGGER("log4cxx.properties", true); //DEINIT_LOGGER will be called in test_main.cc + INIT_LOGGER("log4cxx.properties", true); // DEINIT_LOGGER will be called in test_main.cc } void CreateDeleteAutoTrace(const std::string & testlog) { |