summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/appMain/CMakeLists.txt1
-rw-r--r--src/components/application_manager/include/application_manager/request_controller.h16
-rw-r--r--src/components/application_manager/src/application_manager_impl.cc10
-rw-r--r--src/components/application_manager/src/commands/hmi/navi_audio_start_stream_request.cc15
-rw-r--r--src/components/application_manager/src/commands/hmi/navi_start_stream_request.cc16
-rwxr-xr-x[-rw-r--r--]src/components/application_manager/src/commands/mobile/on_button_press_notification.cc0
-rw-r--r--src/components/application_manager/src/policies/policy_handler.cc2
-rw-r--r--src/components/application_manager/src/request_controller.cc86
-rw-r--r--src/components/interfaces/HMI_API.xml8
-rw-r--r--src/components/interfaces/MOBILE_API.xml8
-rw-r--r--src/components/media_manager/CMakeLists.txt4
-rw-r--r--src/components/media_manager/src/media_manager_impl.cc10
-rw-r--r--src/components/policy/src/sql_pt_representation.cc4
-rw-r--r--src/components/policy/test/sql_pt_representation_test.cc74
-rw-r--r--src/components/utils/include/utils/sqlite_wrapper/sql_database.h5
-rw-r--r--src/components/utils/src/sqlite_wrapper/sql_database.cc6
16 files changed, 145 insertions, 120 deletions
diff --git a/src/appMain/CMakeLists.txt b/src/appMain/CMakeLists.txt
index debcfe66c2..84b2c847bd 100644
--- a/src/appMain/CMakeLists.txt
+++ b/src/appMain/CMakeLists.txt
@@ -45,6 +45,7 @@ cmake_policy(POP)
if (EXTENDED_MEDIA_MODE)
set(default_media_inc
${GSTREAMER_gst_INCLUDE_DIR}
+${GSTREAMER_gstconfig_INCLUDE_DIR}
)
else(EXTENDED_MEDIA_MODE)
set(default_media_inc
diff --git a/src/components/application_manager/include/application_manager/request_controller.h b/src/components/application_manager/include/application_manager/request_controller.h
index 49fa2a7608..479ebb217e 100644
--- a/src/components/application_manager/include/application_manager/request_controller.h
+++ b/src/components/application_manager/include/application_manager/request_controller.h
@@ -216,15 +216,14 @@ class RequestController {
protected:
/**
- * @brief Timer Callback
+ * @brief Timer callback which handles all request timeouts
*/
- void onTimer();
+ void TimeoutThread();
/**
- * @brief Update timout for next OnTimer
- * Not thread safe
+ * @brief Signal timer condition variable
*/
- void UpdateTimer();
+ void NotifyTimer();
void terminateWaitingForExecutionAppRequests(const uint32_t& app_id);
void terminateWaitingForResponseAppRequests(const uint32_t& app_id);
@@ -284,6 +283,13 @@ class RequestController {
*/
timer::Timer timer_;
+ /*
+ * Timer for lock
+ */
+ bool timer_stop_flag_;
+ sync_primitives::Lock timer_lock;
+ sync_primitives::ConditionalVariable timer_condition_;
+
bool is_low_voltage_;
const RequestControlerSettings& settings_;
DISALLOW_COPY_AND_ASSIGN(RequestController);
diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc
index 004841d12e..46c952d8aa 100644
--- a/src/components/application_manager/src/application_manager_impl.cc
+++ b/src/components/application_manager/src/application_manager_impl.cc
@@ -1418,16 +1418,6 @@ void ApplicationManagerImpl::SendMessageToMobile(
<< ") not allowed by policy");
return;
}
-
- if (function_id == mobile_apis::FunctionID::OnSystemRequestID) {
- mobile_apis::RequestType::eType request_type =
- static_cast<mobile_apis::RequestType::eType>(
- (*message)[strings::msg_params][strings::request_type].asUInt());
- if (mobile_apis::RequestType::PROPRIETARY == request_type ||
- mobile_apis::RequestType::HTTP == request_type) {
- GetPolicyHandler().OnUpdateRequestSentToMobile();
- }
- }
}
if (message_to_send->binary_data()) {
diff --git a/src/components/application_manager/src/commands/hmi/navi_audio_start_stream_request.cc b/src/components/application_manager/src/commands/hmi/navi_audio_start_stream_request.cc
index db7477aae2..1e46eab52e 100644
--- a/src/components/application_manager/src/commands/hmi/navi_audio_start_stream_request.cc
+++ b/src/components/application_manager/src/commands/hmi/navi_audio_start_stream_request.cc
@@ -63,20 +63,19 @@ void AudioStartStreamRequest::Run() {
LOG4CXX_INFO(logger_, "Interface Navi is not supported by system");
return;
}
- SetAllowedToTerminate(false);
- subscribe_on_event(hmi_apis::FunctionID::Navigation_StartAudioStream,
- correlation_id());
-
ApplicationSharedPtr app =
application_manager_.application_by_hmi_app(application_id());
- if (app) {
- app->set_audio_streaming_allowed(true);
- SendRequest();
- } else {
+ if (!app) {
LOG4CXX_ERROR(logger_,
"Applcation with hmi_app_id " << application_id()
<< " does not exist");
+ return;
}
+ SetAllowedToTerminate(false);
+ subscribe_on_event(hmi_apis::FunctionID::Navigation_StartAudioStream,
+ correlation_id());
+ app->set_audio_streaming_allowed(true);
+ SendRequest();
}
void AudioStartStreamRequest::on_event(const event_engine::Event& event) {
diff --git a/src/components/application_manager/src/commands/hmi/navi_start_stream_request.cc b/src/components/application_manager/src/commands/hmi/navi_start_stream_request.cc
index 38a38e9329..9f1c4b7902 100644
--- a/src/components/application_manager/src/commands/hmi/navi_start_stream_request.cc
+++ b/src/components/application_manager/src/commands/hmi/navi_start_stream_request.cc
@@ -63,21 +63,19 @@ void NaviStartStreamRequest::Run() {
LOG4CXX_INFO(logger_, "Interface Navi is not supported by system");
return;
}
-
- SetAllowedToTerminate(false);
- subscribe_on_event(hmi_apis::FunctionID::Navigation_StartStream,
- correlation_id());
-
ApplicationSharedPtr app =
application_manager_.application_by_hmi_app(application_id());
- if (app) {
- app->set_video_streaming_allowed(true);
- SendRequest();
- } else {
+ if (!app) {
LOG4CXX_ERROR(logger_,
"Applcation with hmi_app_id " << application_id()
<< "does not exist");
+ return;
}
+ SetAllowedToTerminate(false);
+ subscribe_on_event(hmi_apis::FunctionID::Navigation_StartStream,
+ correlation_id());
+ app->set_video_streaming_allowed(true);
+ SendRequest();
}
void NaviStartStreamRequest::on_event(const event_engine::Event& event) {
diff --git a/src/components/application_manager/src/commands/mobile/on_button_press_notification.cc b/src/components/application_manager/src/commands/mobile/on_button_press_notification.cc
index fdf8b559bc..fdf8b559bc 100644..100755
--- a/src/components/application_manager/src/commands/mobile/on_button_press_notification.cc
+++ b/src/components/application_manager/src/commands/mobile/on_button_press_notification.cc
diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc
index cf312acc6d..23f5227667 100644
--- a/src/components/application_manager/src/policies/policy_handler.cc
+++ b/src/components/application_manager/src/policies/policy_handler.cc
@@ -1130,6 +1130,8 @@ void PolicyHandler::OnSnapshotCreated(const BinaryMessage& pt_string) {
}
SendMessageToSDK(pt_string, urls.front().url.front());
#endif
+ // reset update required false
+ OnUpdateRequestSentToMobile();
}
bool PolicyHandler::GetPriority(const std::string& policy_app_id,
diff --git a/src/components/application_manager/src/request_controller.cc b/src/components/application_manager/src/request_controller.cc
index cdf1616e42..aa2a3d7c5d 100644
--- a/src/components/application_manager/src/request_controller.cc
+++ b/src/components/application_manager/src/request_controller.cc
@@ -51,15 +51,20 @@ RequestController::RequestController(const RequestControlerSettings& settings)
, pool_size_(settings.thread_pool_size())
, timer_("AM RequestCtrlTimer",
new timer::TimerTaskImpl<RequestController>(
- this, &RequestController::onTimer))
+ this, &RequestController::TimeoutThread))
+ , timer_stop_flag_(false)
, is_low_voltage_(false)
, settings_(settings) {
LOG4CXX_AUTO_TRACE(logger_);
InitializeThreadpool();
+ timer_.Start(0, timer::kSingleShot);
}
RequestController::~RequestController() {
LOG4CXX_AUTO_TRACE(logger_);
+ timer_stop_flag_ = true;
+ timer_condition_.Broadcast();
+ timer_.Stop();
if (pool_state_ != TPoolState::STOPPED) {
DestroyThreadpool();
}
@@ -202,7 +207,7 @@ RequestController::TResult RequestController::addHMIRequest(
LOG4CXX_DEBUG(logger_,
"Waiting for response count:" << waiting_for_response_.Size());
- UpdateTimer();
+ NotifyTimer();
return RequestController::SUCCESS;
}
@@ -252,7 +257,7 @@ void RequestController::TerminateRequest(const uint32_t correlation_id,
} else {
LOG4CXX_WARN(logger_, "Request was not terminated");
}
- UpdateTimer();
+ NotifyTimer();
}
void RequestController::OnMobileResponse(const uint32_t mobile_correlation_id,
@@ -307,7 +312,7 @@ void RequestController::terminateAppRequests(const uint32_t& app_id) {
terminateWaitingForExecutionAppRequests(app_id);
terminateWaitingForResponseAppRequests(app_id);
- UpdateTimer();
+ NotifyTimer();
}
void RequestController::terminateAllHMIRequests() {
@@ -322,7 +327,7 @@ void RequestController::terminateAllMobileRequests() {
AutoLock waiting_execution_auto_lock(mobile_request_list_lock_);
mobile_request_list_.clear();
LOG4CXX_DEBUG(logger_, "Mobile Requests waiting for execution cleared");
- UpdateTimer();
+ NotifyTimer();
}
void RequestController::updateRequestTimeout(const uint32_t& app_id,
@@ -344,7 +349,7 @@ void RequestController::updateRequestTimeout(const uint32_t& app_id,
waiting_for_response_.RemoveRequest(request_info);
request_info->updateTimeOut(new_timeout);
waiting_for_response_.Add(request_info);
- UpdateTimer();
+ NotifyTimer();
LOG4CXX_INFO(logger_,
"Timeout updated for "
<< " app_id: " << app_id << " correlation_id: "
@@ -375,14 +380,40 @@ bool RequestController::IsLowVoltage() {
return is_low_voltage_;
}
-void RequestController::onTimer() {
+void RequestController::TimeoutThread() {
LOG4CXX_AUTO_TRACE(logger_);
LOG4CXX_DEBUG(
logger_,
"ENTER Waiting fore response count: " << waiting_for_response_.Size());
- RequestInfoPtr probably_expired =
- waiting_for_response_.FrontWithNotNullTimeout();
- while (probably_expired && probably_expired->isExpired()) {
+ while (!timer_stop_flag_) {
+ RequestInfoPtr probably_expired =
+ waiting_for_response_.FrontWithNotNullTimeout();
+ if (!probably_expired) {
+ sync_primitives::AutoLock auto_lock(timer_lock);
+ timer_condition_.Wait(auto_lock);
+ continue;
+ }
+ if (!probably_expired->isExpired()) {
+ LOG4CXX_DEBUG(logger_,
+ "Timeout for "
+ << (RequestInfo::HMIRequest ==
+ probably_expired->requst_type()
+ ? "HMI"
+ : "Mobile")
+ << " request id: " << probably_expired->requestId()
+ << " connection_key: " << probably_expired->app_id()
+ << " NOT expired");
+ sync_primitives::AutoLock auto_lock(timer_lock);
+ const TimevalStruct current_time = date_time::DateTime::getCurrentTime();
+ const TimevalStruct end_time = probably_expired->end_time();
+ if (current_time < end_time) {
+ const uint32_t msecs = static_cast<uint32_t>(
+ date_time::DateTime::getmSecs(end_time - current_time));
+ LOG4CXX_DEBUG(logger_, "Sleep for " << msecs << " millisecs");
+ timer_condition_.WaitFor(auto_lock, msecs);
+ }
+ continue;
+ }
LOG4CXX_INFO(logger_,
"Timeout for "
<< (RequestInfo::HMIRequest ==
@@ -410,7 +441,6 @@ void RequestController::onTimer() {
}
}
}
- UpdateTimer();
LOG4CXX_DEBUG(
logger_,
"EXIT Waiting for response count : " << waiting_for_response_.Size());
@@ -461,7 +491,7 @@ void RequestController::Worker::threadMain() {
LOG4CXX_DEBUG(logger_, "timeout_in_mseconds " << timeout_in_mseconds);
if (0 != timeout_in_mseconds) {
- request_controller_->UpdateTimer();
+ request_controller_->NotifyTimer();
} else {
LOG4CXX_DEBUG(logger_,
"Default timeout was set to 0. "
@@ -489,37 +519,9 @@ void RequestController::Worker::exitThreadMain() {
// FIXME (dchmerev@luxoft.com): There is no waiting
}
-void RequestController::UpdateTimer() {
+void RequestController::NotifyTimer() {
LOG4CXX_AUTO_TRACE(logger_);
- RequestInfoPtr front = waiting_for_response_.FrontWithNotNullTimeout();
- // Buffer for sending request
- const uint32_t delay_time = 100u;
- if (front) {
- const TimevalStruct current_time = date_time::DateTime::getCurrentTime();
- TimevalStruct end_time = front->end_time();
- date_time::DateTime::AddMilliseconds(end_time, delay_time);
- if (current_time < end_time) {
- const uint32_t msecs = static_cast<uint32_t>(
- date_time::DateTime::getmSecs(end_time - current_time));
- LOG4CXX_DEBUG(logger_, "Sleep for " << msecs << " millisecs");
- // Timeout for bigger than 5 minutes is a mistake
- timer_.Start(msecs, timer::kSingleShot);
- } else {
- LOG4CXX_WARN(
- logger_,
- "Request app_id: "
- << front->app_id() << " correlation_id: " << front->requestId()
- << " is expired. "
- << "End time (ms): " << date_time::DateTime::getmSecs(end_time)
- << " Current time (ms): "
- << date_time::DateTime::getmSecs(current_time)
- << " Diff (current - end) (ms): "
- << date_time::DateTime::getmSecs(current_time - end_time)
- << " Request timeout (sec): "
- << front->timeout_msec() /
- date_time::DateTime::MILLISECONDS_IN_SECOND);
- }
- }
+ timer_condition_.NotifyOne();
}
} // namespace request_controller
diff --git a/src/components/interfaces/HMI_API.xml b/src/components/interfaces/HMI_API.xml
index f24c8812b4..022053f96a 100644
--- a/src/components/interfaces/HMI_API.xml
+++ b/src/components/interfaces/HMI_API.xml
@@ -243,10 +243,10 @@
</enum>
<struct name="Coordinate">
- <param name="latitudeDegrees" minvalue="-90" maxvalue="90" type="Double" mandatory="true">
+ <param name="latitudeDegrees" minvalue="-90" maxvalue="90" type="Float" mandatory="true">
<description>Latitude of the location.</description>
</param>
- <param name="longitudeDegrees" minvalue="-180" maxvalue="180" type="Double" mandatory="true">
+ <param name="longitudeDegrees" minvalue="-180" maxvalue="180" type="Float" mandatory="true">
<description>Longitude of the location.</description>
</param>
</struct>
@@ -1680,9 +1680,9 @@
<!--IVI part-->
<struct name="GPSData">
<description>Struct with the GPS data.</description>
- <param name="longitudeDegrees" type="Double" minvalue="-180" maxvalue="180" mandatory="false">
+ <param name="longitudeDegrees" type="Float" minvalue="-180" maxvalue="180" mandatory="false">
</param>
- <param name="latitudeDegrees" type="Double" minvalue="-90" maxvalue="90" mandatory="false">
+ <param name="latitudeDegrees" type="Float" minvalue="-90" maxvalue="90" mandatory="false">
</param>
<param name="utcYear" type="Integer" minvalue="2010" maxvalue="2100" mandatory="false">
<description>The current UTC year.</description>
diff --git a/src/components/interfaces/MOBILE_API.xml b/src/components/interfaces/MOBILE_API.xml
index bc47d1e6d7..d0326ce647 100644
--- a/src/components/interfaces/MOBILE_API.xml
+++ b/src/components/interfaces/MOBILE_API.xml
@@ -2311,10 +2311,10 @@
</enum>
<struct name="Coordinate">
- <param name="latitudeDegrees" minvalue="-90" maxvalue="90" type="Double" mandatory="true">
+ <param name="latitudeDegrees" minvalue="-90" maxvalue="90" type="Float" mandatory="true">
<description>Latitude of the location.</description>
</param>
- <param name="longitudeDegrees" minvalue="-180" maxvalue="180" type="Double" mandatory="true">
+ <param name="longitudeDegrees" minvalue="-180" maxvalue="180" type="Float" mandatory="true">
<description>Longitude of the location.</description>
</param>
</struct>
@@ -4815,9 +4815,9 @@
</function>
<function name="SendLocation" functionID="SendLocationID" messagetype="request">
- <param name="longitudeDegrees" type="Double" minvalue="-180" maxvalue="180" mandatory="false">
+ <param name="longitudeDegrees" type="Float" minvalue="-180" maxvalue="180" mandatory="false">
</param>
- <param name="latitudeDegrees" type="Double" minvalue="-90" maxvalue="90" mandatory="false">
+ <param name="latitudeDegrees" type="Float" minvalue="-90" maxvalue="90" mandatory="false">
</param>
<param name="locationName" type="String" maxlength="500" mandatory="false">
<description>
diff --git a/src/components/media_manager/CMakeLists.txt b/src/components/media_manager/CMakeLists.txt
index 69af6e7841..3ca02357ab 100644
--- a/src/components/media_manager/CMakeLists.txt
+++ b/src/components/media_manager/CMakeLists.txt
@@ -37,6 +37,7 @@ pkg_check_modules(GLIB2 REQUIRED glib-2.0)
add_definitions(${GLIB2_CFLAGS})
set(default_includes
${GSTREAMER_gst_INCLUDE_DIR}
+ ${GSTREAMER_gstconfig_INCLUDE_DIR}
${GLIB_glib_2_INCLUDE_DIR}
)
set(default_sources
@@ -63,6 +64,8 @@ set(LIBRARIES
glib-2.0
)
else(EXTENDED_MEDIA_MODE)
+set(default_includes
+)
set(default_sources
${COMPONENTS_DIR}/media_manager/src/audio/socket_audio_streamer_adapter.cc
@@ -96,6 +99,7 @@ include_directories (
${JSONCPP_INCLUDE_DIRECTORY}
${CMAKE_BINARY_DIR}/src/components/
${COMPONENTS_DIR}/policy/include/
+ ${default_includes}
${LOG4CXX_INCLUDE_DIRECTORY}
)
diff --git a/src/components/media_manager/src/media_manager_impl.cc b/src/components/media_manager/src/media_manager_impl.cc
index e531894b27..b89fc4c71f 100644
--- a/src/components/media_manager/src/media_manager_impl.cc
+++ b/src/components/media_manager/src/media_manager_impl.cc
@@ -114,8 +114,6 @@ void MediaManagerImpl::Init() {
#if defined(EXTENDED_MEDIA_MODE)
LOG4CXX_INFO(logger_, "Called Init with default configuration.");
- a2dp_player_ =
- new A2DPSourcePlayerAdapter(protocol_handler_->get_session_observer());
from_mic_recorder_ = new FromMicRecorderAdapter();
#endif
@@ -157,6 +155,14 @@ void MediaManagerImpl::Init() {
void MediaManagerImpl::PlayA2DPSource(int32_t application_key) {
LOG4CXX_AUTO_TRACE(logger_);
+
+#if defined(EXTENDED_MEDIA_MODE)
+ if (!a2dp_player_ && protocol_handler_) {
+ a2dp_player_ =
+ new A2DPSourcePlayerAdapter(protocol_handler_->get_session_observer());
+ }
+#endif
+
if (a2dp_player_) {
a2dp_player_->StartActivity(application_key);
}
diff --git a/src/components/policy/src/sql_pt_representation.cc b/src/components/policy/src/sql_pt_representation.cc
index 03fd88b717..ff301cf568 100644
--- a/src/components/policy/src/sql_pt_representation.cc
+++ b/src/components/policy/src/sql_pt_representation.cc
@@ -320,6 +320,10 @@ InitResult SQLPTRepresentation::Init(const PolicySettings* settings) {
#ifdef BUILD_TESTS
open_counter_ = 0;
#endif // BUILD_TESTS
+ std::string path = get_settings().app_storage_folder();
+ if (!path.empty()) {
+ db_->set_path(path + "/");
+ }
if (!db_->Open()) {
LOG4CXX_ERROR(logger_, "Failed opening database.");
LOG4CXX_INFO(logger_, "Starting opening retries.");
diff --git a/src/components/policy/test/sql_pt_representation_test.cc b/src/components/policy/test/sql_pt_representation_test.cc
index 1f4df5d15d..42f7a9cc33 100644
--- a/src/components/policy/test/sql_pt_representation_test.cc
+++ b/src/components/policy/test/sql_pt_representation_test.cc
@@ -76,21 +76,20 @@ class SQLPTRepresentationTest : public SQLPTRepresentation,
static DBMS* dbms;
static SQLPTRepresentation* reps;
static const std::string kDatabaseName;
+ static const std::string kAppStorageFolder;
// Gtest can show message that this object doesn't destroyed
static std::auto_ptr<policy_handler_test::MockPolicySettings>
policy_settings_;
static void SetUpTestCase() {
- const std::string kAppStorageFolder = "storage1";
- file_system::RemoveDirectory(kAppStorageFolder);
- file_system::DeleteFile("policy.sqlite");
+ file_system::DeleteFile(kAppStorageFolder + "/policy.sqlite");
reps = new SQLPTRepresentation;
- dbms = new DBMS(kDatabaseName);
policy_settings_ = std::auto_ptr<policy_handler_test::MockPolicySettings>(
new policy_handler_test::MockPolicySettings());
ON_CALL(*policy_settings_, app_storage_folder())
.WillByDefault(ReturnRef(kAppStorageFolder));
EXPECT_EQ(::policy::SUCCESS, reps->Init(policy_settings_.get()));
+ dbms = new DBMS(kAppStorageFolder + "/" + kDatabaseName);
EXPECT_TRUE(dbms->Open());
}
@@ -104,6 +103,7 @@ class SQLPTRepresentationTest : public SQLPTRepresentation,
reps->RemoveDB();
delete reps;
dbms->Close();
+ file_system::RemoveDirectory(kAppStorageFolder);
policy_settings_.reset();
}
@@ -351,6 +351,7 @@ class SQLPTRepresentationTest : public SQLPTRepresentation,
DBMS* SQLPTRepresentationTest::dbms = 0;
SQLPTRepresentation* SQLPTRepresentationTest::reps = 0;
const std::string SQLPTRepresentationTest::kDatabaseName = "policy.sqlite";
+const std::string SQLPTRepresentationTest::kAppStorageFolder = "storage1";
std::auto_ptr<policy_handler_test::MockPolicySettings>
SQLPTRepresentationTest::policy_settings_;
@@ -385,6 +386,25 @@ class SQLPTRepresentationTest2 : public ::testing::Test {
const uint16_t kAttemptsToOpenPolicyDB;
};
+class SQLPTRepresentationTest3 : public ::testing::Test {
+ protected:
+ SQLPTRepresentationTest3() : kAppStorageFolder("storage") {}
+
+ void SetUp() OVERRIDE {
+ file_system::CreateDirectory(kAppStorageFolder);
+ reps = new SQLPTRepresentation;
+ }
+
+ void TearDown() OVERRIDE {
+ file_system::RemoveDirectory(kAppStorageFolder, true);
+ delete reps;
+ }
+
+ SQLPTRepresentation* reps;
+ NiceMock<policy_handler_test::MockPolicySettings> policy_settings_;
+ const std::string kAppStorageFolder;
+};
+
// {AKozoriz} : Unknown behavior (must try 8 times, tried 2 and opened)
TEST_F(SQLPTRepresentationTest2,
DISABLED_OpenAttemptTimeOut_ExpectCorrectNumber) {
@@ -991,49 +1011,38 @@ TEST_F(SQLPTRepresentationTest,
EXPECT_EQ("EMERGENCY", priority);
}
-namespace {
-const std::string kAppStorageFolder = "storage";
-}
-
-TEST(SQLPTRepresentationTest3, Init_InitNewDataBase_ExpectResultSuccess) {
+TEST_F(SQLPTRepresentationTest3, Init_InitNewDataBase_ExpectResultSuccess) {
// Arrange
- NiceMock<policy_handler_test::MockPolicySettings> policy_settings_;
- SQLPTRepresentation* reps;
- reps = new SQLPTRepresentation;
- // Checks
ON_CALL(policy_settings_, app_storage_folder())
.WillByDefault(ReturnRef(kAppStorageFolder));
+ // Checks
EXPECT_EQ(::policy::SUCCESS, reps->Init(&policy_settings_));
EXPECT_EQ(::policy::EXISTS, reps->Init(&policy_settings_));
reps->RemoveDB();
- delete reps;
}
-TEST(SQLPTRepresentationTest3,
- Init_TryInitNotExistingDataBase_ExpectResultFail) {
+TEST_F(SQLPTRepresentationTest3,
+ Init_TryInitNotExistingDataBase_ExpectResultFail) {
+ const std::string kEmptyDirectory = "";
// Arrange
- NiceMock<policy_handler_test::MockPolicySettings> policy_settings_;
ON_CALL(policy_settings_, app_storage_folder())
- .WillByDefault(ReturnRef(kAppStorageFolder));
- SQLPTRepresentation reps;
- (reps.db())->set_path("/home/");
+ .WillByDefault(ReturnRef(kEmptyDirectory));
+ (reps->db())->set_path("/home/");
// Check
- EXPECT_EQ(::policy::FAIL, reps.Init(&policy_settings_));
+ EXPECT_EQ(::policy::FAIL, reps->Init(&policy_settings_));
}
-TEST(SQLPTRepresentationTest3,
- Close_InitNewDataBaseThenClose_ExpectResultSuccess) {
+TEST_F(SQLPTRepresentationTest3,
+ Close_InitNewDataBaseThenClose_ExpectResultSuccess) {
// Arrange
- NiceMock<policy_handler_test::MockPolicySettings> policy_settings_;
ON_CALL(policy_settings_, app_storage_folder())
.WillByDefault(ReturnRef(kAppStorageFolder));
- SQLPTRepresentation reps;
- EXPECT_EQ(::policy::SUCCESS, reps.Init(&policy_settings_));
- EXPECT_TRUE(reps.Close());
+ EXPECT_EQ(::policy::SUCCESS, reps->Init(&policy_settings_));
+ EXPECT_TRUE(reps->Close());
utils::dbms::SQLError error(utils::dbms::Error::OK);
// Checks
- EXPECT_EQ(error.number(), (reps.db()->LastError().number()));
- reps.RemoveDB();
+ EXPECT_EQ(error.number(), (reps->db()->LastError().number()));
+ reps->RemoveDB();
}
TEST_F(SQLPTRepresentationTest,
@@ -1476,10 +1485,10 @@ TEST_F(SQLPTRepresentationTest,
EXPECT_EQ(0, dbms->FetchOneInt(query_select));
}
-TEST(SQLPTRepresentationTest3, RemoveDB_RemoveDB_ExpectFileDeleted) {
+TEST_F(SQLPTRepresentationTest3, RemoveDB_RemoveDB_ExpectFileDeleted) {
// Arrange
- policy_handler_test::MockPolicySettings policy_settings_;
- SQLPTRepresentation* reps = new SQLPTRepresentation;
+ ON_CALL(policy_settings_, app_storage_folder())
+ .WillByDefault(ReturnRef(kAppStorageFolder));
EXPECT_EQ(::policy::SUCCESS, reps->Init(&policy_settings_));
EXPECT_EQ(::policy::EXISTS, reps->Init(&policy_settings_));
std::string path = (reps->db())->get_path();
@@ -1487,7 +1496,6 @@ TEST(SQLPTRepresentationTest3, RemoveDB_RemoveDB_ExpectFileDeleted) {
reps->RemoveDB();
// Check
EXPECT_FALSE(file_system::FileExists(path));
- delete reps;
}
// TODO {AKozoriz} : Snapshot must have module meta section, but test
diff --git a/src/components/utils/include/utils/sqlite_wrapper/sql_database.h b/src/components/utils/include/utils/sqlite_wrapper/sql_database.h
index 720628ef3c..8b78881473 100644
--- a/src/components/utils/include/utils/sqlite_wrapper/sql_database.h
+++ b/src/components/utils/include/utils/sqlite_wrapper/sql_database.h
@@ -131,6 +131,11 @@ class SQLDatabase {
sync_primitives::Lock conn_lock_;
/**
+ * The file path of database
+ */
+ std::string path_;
+
+ /**
* The filename of database
*/
std::string databasename_;
diff --git a/src/components/utils/src/sqlite_wrapper/sql_database.cc b/src/components/utils/src/sqlite_wrapper/sql_database.cc
index bf19275bac..8c9563ca71 100644
--- a/src/components/utils/src/sqlite_wrapper/sql_database.cc
+++ b/src/components/utils/src/sqlite_wrapper/sql_database.cc
@@ -53,7 +53,7 @@ bool SQLDatabase::Open() {
sync_primitives::AutoLock auto_lock(conn_lock_);
if (conn_)
return true;
- error_ = sqlite3_open(databasename_.c_str(), &conn_);
+ error_ = sqlite3_open(get_path().c_str(), &conn_);
return error_ == SQLITE_OK;
}
@@ -101,11 +101,11 @@ sqlite3* SQLDatabase::conn() const {
}
void SQLDatabase::set_path(const std::string& path) {
- databasename_ = path + databasename_;
+ path_ = path;
}
std::string SQLDatabase::get_path() const {
- return databasename_;
+ return path_ + databasename_;
}
bool SQLDatabase::Backup() {