modules/widget_dao/database_checksum.h
modules/security_origin_dao/database_checksum_security_origin.h
modules/custom_handler_dao/database_checksum_custom_handler.h
-
+modules/certificate_dao/database_checksum_certificage.h
ENDIF(DPL_LOG AND NOT CMAKE_BUILD_TYPE MATCHES "profiling")
OPTION(WITH_TESTS "Build tests" OFF)
+ ADD_DEFINITIONS("-DDPL_LOGS_ENABLED") #@@@@@@@@@@@@@
# Compiler flags
SET(CMAKE_C_FLAGS_PROFILING "-O2")
SET(TARGET_CUSTOM_HANDLER_DAO_RW_LIB "wrt-commons-custom-handler-dao-rw")
SET(TARGET_CUSTOM_HANDLER_DAO_RO_LIB "wrt-commons-custom-handler-dao-ro")
SET(TARGET_SECURITY_ORIGIN_DAO_LIB "wrt-commons-security-origin-dao")
+SET(TARGET_CERTIFICATE_DAO_LIB "wrt-commons-certificate-dao")
SET(TARGET_DPL_UTILS_EFL "lib${PROJECT_NAME}-utils-efl")
SET(TARGET_DPL_ENCRYPTION "lib${PROJECT_NAME}-encryption")
ADD_SUBDIRECTORY(utils)
ADD_SUBDIRECTORY(support)
ADD_SUBDIRECTORY(encryption)
+ADD_SUBDIRECTORY(certificate_dao)
--- /dev/null
+# Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# @file CMakeLists.txt
+# @author Leerang Song (leerang.song@samsung.com)
+# @brief
+#
+
+configure_and_install_pkg(wrt-commons-certificate-dao.pc)
+
--- /dev/null
+prefix=/usr
+exec_prefix=${prefix}
+
+libdir=${prefix}/lib
+includedir=${prefix}/include
+Name: wrt-commons-certificate-dao
+Description: wrt-commons-certificate-dao
+
+Version: @VERSION@
+Requires: dpl-efl
+Libs: -lwrt-commons-certificate-dao -L${libdir}
+Cflags: -I${includedir}/dpl-efl
PKG_CHECK_MODULES(SYS_ENCRYPTION
dlog
openssl
+ osp-appfw
REQUIRED
)
TARGET_LINK_LIBRARIES(${TARGET_DPL_ENCRYPTION} "-ldukgenerator" )
TARGET_LINK_LIBRARIES(${TARGET_DPL_ENCRYPTION} "-lcryptsvc" )
+TARGET_LINK_LIBRARIES(${TARGET_DPL_ENCRYPTION} -L/usr/lib/osp -losp-appfw )
# Target library properties
SET_TARGET_PROPERTIES(${TARGET_DPL_ENCRYPTION} PROPERTIES
+wrt-commons (0.2.103) unstable; urgency=low
+
+ * Update tizen version to 2.1
+ * Replaced VARCHAR with TEXT in databases
+ * Path class for DPL + tests
+ * Implement certificate confirm popup
+ * Add encrypt/decrypt API from trust zone
+
+ -- Jihoon Chung <jihoon.chung@samsung.com> Fri, 08 Mar 2013 17:17:26 +0900
+
wrt-commons (0.2.102) unstable; urgency=low
* DPL path join for class Path to be introduced
ADD_SUBDIRECTORY(auto_save_dao)
ADD_SUBDIRECTORY(security_origin_dao)
ADD_SUBDIRECTORY(custom_handler_dao)
+ADD_SUBDIRECTORY(certificate_dao)
include(utils/config.cmake)
include(localization/config.cmake)
include(support/config.cmake)
--- /dev/null
+SET(TARGET_CERTIFICATE_DAO_DB "Sqlite3DbCertificate")
+
+ADD_CUSTOM_COMMAND( OUTPUT .certificate.db
+ COMMAND rm -f ${CMAKE_CURRENT_BINARY_DIR}/.certificate.db
+ COMMAND gcc -Wall -I${PROJECT_SOURCE_DIR}/modules/db/include -I${PROJECT_SOURCE_DIR}/modules/certificate_dao/orm -E ${PROJECT_SOURCE_DIR}/modules/certificate_dao/orm/certificate_db_sql_generator.h | grep --invert-match "^#" > ${CMAKE_CURRENT_BINARY_DIR}/certificate_db.sql
+ COMMAND sqlite3 ${CMAKE_CURRENT_BINARY_DIR}/.certificate.db ".read ${CMAKE_CURRENT_BINARY_DIR}/certificate_db.sql" || rm -f ${CMAKE_CURRENT_BINARY_DIR}/.certificate.db
+ DEPENDS ${PROJECT_SOURCE_DIR}/modules/certificate_dao/orm/certificate_db_sql_generator.h ${PROJECT_SOURCE_DIR}/modules/certificate_dao/orm/certificate_db
+ )
+
+ADD_CUSTOM_COMMAND( OUTPUT .certificate.db-journal
+ COMMAND touch
+ ARGS ${CMAKE_CURRENT_BINARY_DIR}/.certificate.db-journal
+ )
+
+ADD_CUSTOM_TARGET(${TARGET_CERTIFICATE_DAO_DB} ALL DEPENDS .certificate.db .certificate.db-journal)
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/certificate_db.sql DESTINATION share/wrt-engine/)
+
+###############################################################################
+
+INCLUDE(FindPkgConfig)
+
+PKG_CHECK_MODULES(CERTIFICATE_DAO_DEPS
+ glib-2.0
+ REQUIRED)
+
+SET(CERTIFICATE_DAO_INCLUDE_DIRS
+ ${PROJECT_SOURCE_DIR}/modules/certificate_dao/include
+ ${PROJECT_SOURCE_DIR}/modules/certificate_dao/orm
+ ${PROJECT_SOURCE_DIR}/modules/core/include
+ ${PROJECT_SOURCE_DIR}/modules/db/include
+ ${PROJECT_SOURCE_DIR}/modules/log/include
+ ${PROJECT_SOURCE_DIR}/modules/widget_dao/include
+)
+
+SET(CERTIFICATE_DAO_SOURCES
+ dao/certificate_dao_types.cpp
+ dao/certificate_dao.cpp
+ dao/certificate_database.cpp
+)
+
+INCLUDE_DIRECTORIES(SYSTEM ${CERTIFICATE_DAO_DEPS_INCLUDE_DIRS} )
+INCLUDE_DIRECTORIES(${CERTIFICATE_DAO_INCLUDE_DIRS})
+
+ADD_LIBRARY(${TARGET_CERTIFICATE_DAO_LIB} SHARED ${CERTIFICATE_DAO_SOURCES})
+SET_TARGET_PROPERTIES(${TARGET_CERTIFICATE_DAO_LIB} PROPERTIES SOVERSION ${API_VERSION} VERSION ${VERSION})
+TARGET_LINK_LIBRARIES(${TARGET_CERTIFICATE_DAO_LIB} ${TARGET_DPL_EFL} ${TARGET_DPL_DB_EFL} ${TARGET_WRT_DAP_RO_LIB} ${CERTIFICATE_DAO_DEPS_LIBRARIES})
+ADD_DEPENDENCIES(${TARGET_CERTIFICATE_DAO_LIB} ${TARGET_CERTIFICATE_DAO_DB})
+
+INSTALL(TARGETS ${TARGET_CERTIFICATE_DAO_LIB} DESTINATION lib)
+
+INSTALL(FILES
+ include/wrt-commons/certificate-dao/certificate_dao_types.h
+ include/wrt-commons/certificate-dao/certificate_database.h
+ include/wrt-commons/certificate-dao/certificate_dao.h
+ DESTINATION include/dpl-efl/wrt-commons/certificate-dao
+)
+
--- /dev/null
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * @file certificate_dao.cpp
+ * @author Leerang Song (leerang.song@samsung.com)
+ * @version 1.0
+ * @brief This file contains the definition of certificate dao class.
+ */
+
+#include <wrt-commons/certificate-dao/certificate_dao.h>
+#include <wrt-commons/certificate-dao/certificate_database.h>
+#include <wrt-commons/certificate-dao/certificate_dao_types.h>
+#include <orm_generator_certificate.h>
+#include <dpl/foreach.h>
+#include <dpl/wrt-dao-ro/widget_dao_read_only.h>
+#include <dpl/wrt-dao-ro/WrtDatabase.h>
+#include <dpl/wrt-dao-ro/widget_config.h>
+#include <dpl/wrt-dao-ro/global_config.h>
+#include <dpl/wrt-dao-ro/common_dao_types.h>
+#include <sys/stat.h>
+#include <fstream>
+
+using namespace DPL::DB::ORM;
+using namespace DPL::DB::ORM::certificate;
+
+namespace CertificateDB {
+#define SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN Try
+
+#define SQL_CONNECTION_EXCEPTION_HANDLER_END(message) \
+ Catch(DPL::DB::SqlConnection::Exception::Base) { \
+ LogError(message); \
+ ReThrowMsg(CertificateDAO::Exception::DatabaseError, \
+ message); \
+ }
+
+namespace {
+DPL::DB::SqlConnection::Flag::Option CERTIFICATE_DB_OPTION =
+ DPL::DB::SqlConnection::Flag::RW;
+DPL::DB::SqlConnection::Flag::Type CERTIFICATE_DB_TYPE =
+ DPL::DB::SqlConnection::Flag::UseLucene;
+const char* const CERTIFICATE_DB_NAME = ".certificate.db";
+const char* const CERTIFICATE_DB_SQL_PATH =
+ "/usr/share/wrt-engine/certificate_db.sql";
+const char* const CERTIFICATE_DATABASE_JOURNAL_FILENAME = "-journal";
+
+const int WEB_APPLICATION_UID = 5000;
+const int WEB_APPLICATION_GUID = 5000;
+
+std::string createDatabasePath(const WrtDB::WidgetPkgName &pkgName)
+{
+ std::stringstream filename;
+
+ filename << WrtDB::WidgetConfig::GetWidgetPersistentStoragePath(pkgName)
+ << "/"
+ << CERTIFICATE_DB_NAME;
+ return filename.str();
+}
+
+std::string createDatabasePath(int widgetHandle)
+{
+ using namespace DPL::DB::ORM;
+ using namespace WrtDB::WidgetConfig;
+ using namespace WrtDB::GlobalConfig;
+
+ WrtDB::TizenAppId appid;
+
+ Try
+ {
+ appid = WrtDB::WidgetDAOReadOnly::getTzAppId(widgetHandle);
+ }
+ Catch(DPL::DB::SqlConnection::Exception::Base) {
+ LogError("Failed to get database Path");
+ }
+ return createDatabasePath(appid);
+}
+
+void checkDatabase(std::string databasePath)
+{
+ SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+ {
+ if (databasePath.empty()) {
+ ThrowMsg(CertificateDAO::Exception::DatabaseError,
+ "Wrong database Path is passed");
+ }
+
+ struct stat buffer;
+ if (stat(databasePath.c_str(), &buffer) != 0) {
+ //Create fresh database
+ LogInfo("Creating database " << databasePath);
+
+ std::fstream file;
+ file.open(CERTIFICATE_DB_SQL_PATH, std::ios_base::in);
+ if (!file) {
+ ThrowMsg(CertificateDAO::Exception::DatabaseError,
+ "Fail to get database Path");
+ }
+
+ std::stringstream ssBuffer;
+ ssBuffer << file.rdbuf();
+
+ file.close();
+
+ DPL::DB::SqlConnection con(databasePath,
+ CERTIFICATE_DB_TYPE,
+ CERTIFICATE_DB_OPTION);
+ con.ExecCommand(ssBuffer.str().c_str());
+ }
+
+ if(chown(databasePath.c_str(),
+ WEB_APPLICATION_UID,
+ WEB_APPLICATION_GUID) != 0)
+ {
+ ThrowMsg(CertificateDAO::Exception::DatabaseError,
+ "Fail to change uid/guid");
+ }
+ std::string databaseJournal =
+ databasePath + CERTIFICATE_DATABASE_JOURNAL_FILENAME;
+ if(chown(databaseJournal.c_str(),
+ WEB_APPLICATION_UID,
+ WEB_APPLICATION_GUID) != 0)
+ {
+ ThrowMsg(CertificateDAO::Exception::DatabaseError,
+ "Fail to change uid/guid");
+ }
+ }
+ SQL_CONNECTION_EXCEPTION_HANDLER_END("Fail to get database Path")
+}
+}
+
+CertificateDAO::CertificateDAO(const WrtDB::WidgetPkgName &pkgName) :
+ m_certificateDBPath(createDatabasePath(pkgName)),
+ m_certificateDBInterface(m_certificateDBPath, CERTIFICATE_DB_TYPE)
+{
+ checkDatabase(m_certificateDBPath);
+ m_certificateDBInterface.AttachToThread(CERTIFICATE_DB_OPTION);
+}
+
+CertificateDAO::~CertificateDAO()
+{
+ m_certificateDBInterface.DetachFromThread();
+}
+
+CertificateDataList CertificateDAO::getCertificateDataList(void)
+{
+ SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+ {
+ CertificateDataList list;
+ CERTIFICATE_DB_SELECT(select,
+ CertificateInfo,
+ &m_certificateDBInterface);
+ typedef std::list<CertificateInfo::Row> RowList;
+ RowList rowList = select->GetRowList();
+
+ FOREACH(it, rowList) {
+ list.push_back(
+ CertificateDataPtr(
+ new CertificateData(it->Get_certificate())));
+ }
+ return list;
+ }
+ SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get data list")
+}
+
+Result CertificateDAO::getResult(
+ const CertificateData &certificateData)
+{
+ SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+ {
+ CERTIFICATE_DB_SELECT(select,
+ CertificateInfo,
+ &m_certificateDBInterface);
+ select->Where(
+ Equals<CertificateInfo::certificate>(certificateData.certificate));
+ CertificateInfo::Select::RowList rows = select->GetRowList();
+
+ if (rows.empty()) {
+ return RESULT_UNKNOWN;
+ }
+ CertificateInfo::Row row = rows.front();
+ return static_cast<Result>(row.Get_result());
+ }
+ SQL_CONNECTION_EXCEPTION_HANDLER_END(
+ "Failed to get result for security certiInfo")
+}
+
+void CertificateDAO::setCertificateData(const CertificateData &certificateData,
+ const Result result)
+{
+ SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+ {
+ ScopedTransaction transaction(&m_certificateDBInterface);
+ CertificateInfo::Row row;
+ row.Set_certificate(certificateData.certificate);
+ row.Set_result(result);
+
+ if (true == hasResult(certificateData)) {
+ CERTIFICATE_DB_UPDATE(update,
+ CertificateInfo,
+ &m_certificateDBInterface);
+ update->Values(row);
+ update->Execute();
+ } else {
+ CERTIFICATE_DB_INSERT(insert,
+ CertificateInfo,
+ &m_certificateDBInterface);
+ insert->Values(row);
+ insert->Execute();
+ }
+ transaction.Commit();
+ }
+ SQL_CONNECTION_EXCEPTION_HANDLER_END("Fail to set security certiInfo data")
+}
+
+void CertificateDAO::removeCertificateData(
+ const CertificateData &certificateData)
+{
+ SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+ {
+ ScopedTransaction transaction(&m_certificateDBInterface);
+
+ if (true == hasResult(certificateData)) {
+ CERTIFICATE_DB_DELETE(del,
+ CertificateInfo,
+ &m_certificateDBInterface)
+ del->Where(
+ Equals<CertificateInfo::certificate>(certificateData.certificate));
+ del->Execute();
+ transaction.Commit();
+ }
+ }
+ SQL_CONNECTION_EXCEPTION_HANDLER_END("Fail to set certiInfo data")
+}
+
+void CertificateDAO::removeCertificateData(const Result result)
+{
+ SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+ {
+ ScopedTransaction transaction(&m_certificateDBInterface);
+ CERTIFICATE_DB_DELETE(del,
+ CertificateInfo,
+ &m_certificateDBInterface)
+ del->Where(Equals<CertificateInfo::result>(result));
+ del->Execute();
+ transaction.Commit();
+ }
+ SQL_CONNECTION_EXCEPTION_HANDLER_END("Fail to remove data by result")
+}
+
+bool CertificateDAO::hasResult(const CertificateData &certificateData)
+{
+ Result res = getResult(certificateData);
+ return (res != RESULT_UNKNOWN);
+}
+
+#undef SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+#undef SQL_CONNECTION_EXCEPTION_HANDLER_END
+} // namespace CertificateDB
--- /dev/null
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ *
+ * @file certificate_dao_types.cpp
+ * @author Leerang Song (leerang.song@samsung.com)
+ * @version 1.0
+ * @brief This file contains the implementation of
+ * common data types for certificate.db
+ */
+
+#include <wrt-commons/certificate-dao/certificate_dao_types.h>
+#include <dpl/log/log.h>
+
+namespace CertificateDB {
+
+} // namespace CertificateDB
--- /dev/null
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <wrt-commons/certificate-dao/certificate_database.h>
+
+DPL::Mutex g_certificateDBQueriesMutex;
--- /dev/null
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file certificate_dao.h
+ * @author Leerang Song (leerang.song@samsung.com)
+ * @version 1.0
+ * @brief This file contains the declaration of certificate dao
+ */
+#ifndef _CERTIFICATE_DAO_H_
+#define _CERTIFICATE_DAO_H_
+
+#include <dpl/db/thread_database_support.h>
+#include <wrt-commons/certificate-dao/certificate_dao_types.h>
+#include <dpl/wrt-dao-ro/common_dao_types.h>
+
+namespace CertificateDB {
+class CertificateDAO
+{
+ public:
+ class Exception
+ {
+ public:
+ DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
+ DECLARE_EXCEPTION_TYPE(Base, DatabaseError)
+ DECLARE_EXCEPTION_TYPE(Base, DataNotExist)
+ };
+
+ explicit CertificateDAO(const WrtDB::WidgetPkgName &pkgName);
+ virtual ~CertificateDAO();
+ CertificateDataList getCertificateDataList();
+ Result getResult(const CertificateData &certificateData);
+ void setCertificateData(const CertificateData &certificateData,
+ const Result result);
+ void removeCertificateData(const CertificateData &certificateData);
+ void removeCertificateData(const Result result);
+
+ private:
+ std::string m_certificateDBPath;
+ DPL::DB::ThreadDatabaseSupport m_certificateDBInterface;
+ bool hasResult(const CertificateData &certificateData);
+};
+
+typedef std::shared_ptr<CertificateDAO> CertificateDAOPtr;
+} // namespace CertificateDB
+
+#endif // _CERTIFICATE_DAO_H_
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ *
+ * @file certificate_dao_types.h
+ * @author Leerang Song (leerang.song@samsung.com)
+ * @version 1.0
+ * @brief This file contains the declaration of
+ * common data types for certificate database.
+ */
+#ifndef _CERTIFICATE_DAO_TYPES_H_
+#define _CERTIFICATE_DAO_TYPES_H_
+
+#include <list>
+#include <memory>
+#include <dpl/string.h>
+
+namespace CertificateDB {
+
+enum Result
+{
+ RESULT_UNKNOWN = 0,
+ RESULT_ALLOW_ONCE,
+ RESULT_DENY_ONCE,
+ RESULT_ALLOW_ALWAYS,
+ RESULT_DENY_ALWAYS
+};
+
+struct CertificateData
+{
+ DPL::String certificate;
+
+ CertificateData(const DPL::String& certi) :
+ certificate(certi)
+ {}
+
+ bool operator== (const CertificateData& other) const
+ {
+ return !(certificate == other.certificate);
+ }
+
+ bool operator!= (const CertificateData& other) const
+ {
+ return !(*this == other);
+ }
+};
+
+typedef std::shared_ptr<CertificateData> CertificateDataPtr;
+typedef std::list<CertificateDataPtr> CertificateDataList;
+} // namespace CertificateDB
+
+#endif // _CERTIFICATE_DAO_TYPES_H_
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _CERTIFICATE_DATABASE_H_
+#define _CERTIFICATE_DATABASE_H_
+
+#include <dpl/thread.h>
+#include <dpl/mutex.h>
+
+extern DPL::Mutex g_certificateDBQueriesMutex;
+
+#define CERTIFICATE_DB_INTERNAL(tlsCommand, InternalType, interface) \
+ static DPL::ThreadLocalVariable<InternalType> *tlsCommand##Ptr = NULL; \
+ { \
+ DPL::Mutex::ScopedLock lock(&g_certificateDBQueriesMutex); \
+ if (!tlsCommand##Ptr) { \
+ static DPL::ThreadLocalVariable<InternalType> tmp; \
+ tlsCommand##Ptr = &tmp; \
+ } \
+ } \
+ DPL::ThreadLocalVariable<InternalType> &tlsCommand = *tlsCommand##Ptr; \
+ if (tlsCommand.IsNull()) { tlsCommand = InternalType(interface); }
+
+#define CERTIFICATE_DB_SELECT(name, type, interface) \
+ CERTIFICATE_DB_INTERNAL(name, type::Select, interface)
+
+#define CERTIFICATE_DB_INSERT(name, type, interface) \
+ CERTIFICATE_DB_INTERNAL(name, type::Insert, interface)
+
+#define CERTIFICATE_DB_UPDATE(name, type, interface) \
+ CERTIFICATE_DB_INTERNAL(name, type::Update, interface)
+
+#define CERTIFICATE_DB_DELETE(name, type, interface) \
+ CERTIFICATE_DB_INTERNAL(name, type::Delete, interface)
+
+#endif // _CERTIFICATE_DATABASE_H_
+
--- /dev/null
+SQL(BEGIN TRANSACTION;)
+
+CREATE_TABLE(CertificateInfo)
+ COLUMN_NOT_NULL(certificate, TEXT,DEFAULT '')
+ COLUMN_NOT_NULL(result, INT, DEFAULT 0)
+ TABLE_CONSTRAINTS(PRIMARY KEY(certificate))
+CREATE_TABLE_END()
+
+SQL(COMMIT;)
--- /dev/null
+DATABASE_START(certificate)
+
+#include "certificate_db"
+
+DATABASE_END()
--- /dev/null
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * @file certificate_db_sql_generator.h
+ * @author Leerang Song (leerang.song@samsung.com)
+ * @version 1.0
+ * @brief Macro definitions for generating the SQL
+ * input file from database definition.
+ */
+
+//Do not include this file directly! It is used only for SQL code generation.
+#include <dpl/db/orm_macros.h>
+
+#include "certificate_db_definitions"
--- /dev/null
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _ORM_GENERATOR_CERTIFICATE_H_
+#define _ORM_GENERATOR_CERTIFICATE_H_
+
+#define ORM_GENERATOR_DATABASE_NAME certificate_db_definitions
+#include <dpl/db/orm_generator.h>
+#undef ORM_GENERATOR_DATABASE_NAME
+
+#endif // _ORM_GENERATOR_CERTIFICATE_H_
\ No newline at end of file
#include <openssl/sha.h>
#include <dpl/exception.h>
-extern char** calculate(char*pappId, int idLen, int keyLen);
-
namespace WRTDecryptor {
class ResourceDecryptor
{
unsigned char* decBuf,
size_t chunkSize);
+ /* TrustZone */
+ int DecryptChunkByTrustZone(
+ std::string pkgid,
+ const unsigned char *inBuffer,
+ int inBufSize);
+ void getDecryptStringByTrustZone(unsigned char *decBuffer);
+
private:
AES_KEY* GetDecryptionKey();
AES_KEY m_decKey;
+ void *m_getBuffer;
};
} //namespace WRTDecryptor
#include <openssl/sha.h>
#include <dpl/exception.h>
-extern char** calculate(char*pappId, int idLen, int keyLen);
-
namespace WRTEncryptor {
class ResourceEncryptor
{
void EncryptChunk(unsigned char* inputBuf, unsigned char* encBuf, size_t
chunkSize);
+ /* TrustZone */
+ int EncryptChunkByTrustZone(
+ std::string pkgid,
+ const unsigned char *plainBuffer,
+ int pBufSize);
+ void getEncStringByTrustZone(unsigned char *encBuffer);
+
private:
AES_KEY GetEncryptionkey();
AES_KEY m_encKey;
+ void *m_getBuffer;
};
} //namespace WRTEncryptor
#include <dpl/log/log.h>
#include <dpl/exception.h>
#include <dukgen.h>
+#include <FBaseByteBuffer.h>
+#include <security/FSecCrypto_TrustZoneService.h>
namespace {
#define BITS_SIZE 128
#define KEY_SIZE 16
}
namespace WRTDecryptor {
-ResourceDecryptor::ResourceDecryptor()
+ResourceDecryptor::ResourceDecryptor() :
+ m_getBuffer(NULL)
{
LogDebug("Started Decryption");
}
AES_cbc_encrypt(inBuf, decBuf, inBufSize, &m_decKey, ivec, AES_DECRYPT);
LogDebug("Success decryption");
}
+
+int ResourceDecryptor::DecryptChunkByTrustZone(
+ std::string pkgid, const unsigned char* inBuffer,
+ int inBufSize)
+{
+ using namespace Tizen::Base;
+
+ const byte *b_pkgid = reinterpret_cast<const byte*>(pkgid.c_str());
+ ByteBuffer appInfo;
+ appInfo.Construct(pkgid.length());
+ appInfo.SetArray(b_pkgid, 0, pkgid.length());
+ appInfo.Flip();
+
+ Tizen::Security::Crypto::_TrustZoneService* pInstance;
+ pInstance = Tizen::Security::Crypto::_TrustZoneService::GetInstance();
+
+ ByteBuffer pBuf;
+ pBuf.Construct(inBufSize);
+ const byte *pByte = reinterpret_cast<const byte*>(inBuffer);
+ pBuf.SetArray(pByte, 0, inBufSize);
+ pBuf.Flip();
+
+ ByteBuffer *getBuffer = pInstance->_TrustZoneService::DecryptN(appInfo, pBuf);
+
+ m_getBuffer = reinterpret_cast<void*>(getBuffer);
+ return getBuffer->GetRemaining();
+}
+
+void ResourceDecryptor::getDecryptStringByTrustZone(unsigned char *decBuffer)
+{
+ using namespace Tizen::Base;
+ LogDebug("Get decrypted string");
+ ByteBuffer *buffer = reinterpret_cast<ByteBuffer*>(m_getBuffer);
+ memcpy(decBuffer, buffer->GetPointer(), buffer->GetRemaining());
+ buffer->Reset();
+}
+
} //namespace WRTDecryptor
#include <fcntl.h>
#include <dpl/log/log.h>
#include <dukgen.h>
+#include <FBaseByteBuffer.h>
+#include <security/FSecCrypto_TrustZoneService.h>
namespace {
#define BITS_SIZE 128
#define KEY_SIZE 16
}
namespace WRTEncryptor {
-ResourceEncryptor::ResourceEncryptor()
+ResourceEncryptor::ResourceEncryptor() :
+ m_getBuffer(NULL)
{
LogDebug("Started Encrytion");
}
AES_cbc_encrypt(inputBuf, encBuf, chunkSize, &m_encKey, ivec, AES_ENCRYPT);
}
+
+int ResourceEncryptor::EncryptChunkByTrustZone(
+ std::string pkgid,
+ const unsigned char *plainBuffer,
+ int pBufSize)
+{
+ using namespace Tizen::Base;
+
+ const byte *b_pkgid = reinterpret_cast<const byte*>(pkgid.c_str());
+ ByteBuffer appInfo;
+ appInfo.Construct(pkgid.length());
+ appInfo.SetArray(b_pkgid, 0, pkgid.length());
+ appInfo.Flip();
+
+ Tizen::Security::Crypto::_TrustZoneService* pInstance;
+ pInstance = Tizen::Security::Crypto::_TrustZoneService::GetInstance();
+
+ ByteBuffer pBuf;
+ pBuf.Construct(pBufSize);
+ const byte *pByte = reinterpret_cast<const byte*>(plainBuffer);
+ pBuf.SetArray(pByte, 0, pBufSize);
+ pBuf.Flip();
+
+ ByteBuffer *getBuffer =
+ pInstance->_TrustZoneService::EncryptN(appInfo, pBuf);
+ m_getBuffer = reinterpret_cast<void*>(getBuffer);
+
+ return getBuffer->GetRemaining();
+}
+
+void ResourceEncryptor::getEncStringByTrustZone(unsigned char *encBuffer)
+{
+ using namespace Tizen::Base;
+ LogDebug("Get encrypted String");
+ ByteBuffer *buffer = reinterpret_cast<ByteBuffer*>(m_getBuffer);
+ memcpy(encBuffer, buffer->GetPointer(), buffer->GetRemaining());
+ buffer->Reset();
+}
} //namespace ResourceEnc
${PROJECT_SOURCE_DIR}/modules/utils/src/widget_version.cpp
${PROJECT_SOURCE_DIR}/modules/utils/src/wrt_global_settings.cpp
${PROJECT_SOURCE_DIR}/modules/utils/src/wrt_utility.cpp
+ ${PROJECT_SOURCE_DIR}/modules/utils/src/path.cpp
PARENT_SCOPE
)
${PROJECT_SOURCE_DIR}/modules/utils/include/dpl/utils/widget_version.h
${PROJECT_SOURCE_DIR}/modules/utils/include/dpl/utils/wrt_global_settings.h
${PROJECT_SOURCE_DIR}/modules/utils/include/dpl/utils/wrt_utility.h
+ ${PROJECT_SOURCE_DIR}/modules/utils/include/dpl/utils/path.h
PARENT_SCOPE
)
--- /dev/null
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file path.h
+ * @author Tomasz Iwanek (t.iwanek@samsung.com)
+ * @version 1.0
+ */
+#ifndef PATH_H
+#define PATH_H
+
+#include <dirent.h>
+#include <sys/stat.h>
+
+#include <string>
+#include <sstream>
+#include <iterator>
+#include <memory>
+#include <vector>
+
+#include <dpl/exception.h>
+#include <dpl/string.h>
+
+namespace DPL {
+namespace Utils {
+class Path;
+}
+}
+
+std::ostream & operator<<(std::ostream & str, const DPL::Utils::Path & path);
+
+namespace DPL {
+namespace Utils {
+/**
+ * @brief The Path class path abstraction
+ *
+ * Class for expressing paths not limited not existing ones.
+ * It's possible to check if path exists, remove it or iterate it if it's directory
+ */
+class Path
+{
+public:
+ DECLARE_EXCEPTION_TYPE(DPL::Exception, BaseException)
+ DECLARE_EXCEPTION_TYPE(BaseException, AlreadyExists)
+ DECLARE_EXCEPTION_TYPE(BaseException, NotExists)
+ DECLARE_EXCEPTION_TYPE(BaseException, NotDirectory)
+ DECLARE_EXCEPTION_TYPE(BaseException, OperationFailed)
+ DECLARE_EXCEPTION_TYPE(BaseException, EmptyPath)
+ DECLARE_EXCEPTION_TYPE(BaseException, InternalError)
+
+ class Iterator : public std::iterator<std::input_iterator_tag, Path>
+ {
+ public:
+ Iterator();
+ Iterator(const char *);
+ Iterator& operator++();
+ Iterator operator++(int);
+ bool operator==(const Iterator& rhs) const;
+ bool operator!=(const Iterator& rhs) const;
+ const Path & operator*();
+ const Path * operator->();
+ private:
+ void ReadNext();
+
+ std::shared_ptr<DIR> m_dir;
+ std::shared_ptr<Path> m_path;
+ std::shared_ptr<Path> m_root;
+ };
+
+ explicit Path(const DPL::String & str);
+ explicit Path(const std::string & str);
+ explicit Path(const char * str);
+
+ /**
+ * @brief DirectoryName shell's dirname equivalent
+ * @return directory name of given path
+ */
+ std::string DirectoryName() const;
+ /**
+ * @brief Basename shell's basename equivalent
+ * @return base name of given path
+ */
+ std::string Basename() const;
+ /**
+ * @brief Fullpath fullpath based on current working diretory
+ * @return full path
+ */
+ std::string Fullpath() const;
+
+ bool Exists() const;
+ bool IsDir() const;
+ bool IsFile() const;
+ bool IsSymlink() const;
+
+ bool operator==(const Path & other) const;
+ bool operator!=(const Path & other) const;
+
+ //appending to path
+ Path operator/(const DPL::String& part) const;
+ Path operator/(const std::string& part) const;
+ Path operator/(const char * part) const;
+
+ Path & operator/=(const DPL::String& part);
+ Path & operator/=(const std::string& part);
+ Path & operator/=(const char * part);
+
+ //foreach
+ Iterator begin() const;
+ Iterator end() const;
+
+private:
+ Path();
+
+ void Append(const std::string& part);
+ void Construct(const std::string & src);
+
+ std::vector<std::string> m_parts;
+
+ friend std::ostream & ::operator<<(std::ostream & str, const DPL::Utils::Path & path);
+};
+
+/**
+ * @brief MkDir creates 'current path' as directory
+ * @param path path
+ * @param mode mode
+ */
+void MakeDir(const Path & path, mode_t mode = 0755);
+
+/**
+ * @brief MkFile creates 'current path' as empty file
+ * @param path path
+ */
+void MakeEmptyFile(const Path & path);
+
+/**
+ * @brief Remove removes 'current path'
+ * @param path path to remove
+ */
+void Remove(const Path & path);
+
+/**
+ * @brief Rename renames(moves) current path
+ *
+ * If you uses this method string to path is internally change
+ * and this object will store new path not only anymore
+ * @param from source path
+ * @param to target path
+ */
+void Rename(const Path & from, const Path & to);
+
+/**
+ * @brief Exists Checks if given path exists
+ * @param path path
+ * @return true if path exists
+ */
+bool Exists(const Path & path);
+
+}
+
+}
+
+//TODO: uncomment when user defiend literals are supported
+///Path operator"" p(const char * str);
+
+#endif // PATH_H
--- /dev/null
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file path.h
+ * @author Tomasz Iwanek (t.iwanek@samsung.com)
+ * @version 1.0
+ */
+
+#include "dpl/utils/path.h"
+
+#include <dpl/utils/wrt_utility.h>
+
+#include <dpl/scoped_free.h>
+#include <dpl/errno_string.h>
+#include <dpl/file_input.h>
+#include <dpl/file_output.h>
+#include <dpl/copy.h>
+
+#include <sys/stat.h>
+
+namespace DPL {
+
+namespace Utils {
+
+Path::Iterator::Iterator() //end iterator by default
+{
+}
+
+Path::Iterator::Iterator(const char * str)
+{
+ m_root = std::shared_ptr<Path>(new Path(str));
+ m_dir = std::shared_ptr<DIR>(opendir(str), [](DIR * d){ if(d)closedir(d); }); //custom delete
+ if(m_dir.get() == NULL)
+ {
+ ThrowMsg(NotDirectory, "Not directory");
+ }
+ ReadNext();
+}
+
+Path::Iterator& Path::Iterator::operator++()
+{
+ ReadNext();
+ return *this;
+}
+
+Path::Iterator Path::Iterator::operator++(int)
+{
+ Path::Iterator copy(*this);
+ ReadNext();
+ return copy;
+}
+
+void Path::Iterator::ReadNext()
+{
+ struct dirent * entry = readdir(m_dir.get());
+ while(entry && (strcmp(entry->d_name, ".") == 0 ||
+ strcmp(entry->d_name, "..") == 0))
+ {
+ entry = readdir(m_dir.get());
+ }
+ if(entry)
+ {
+ m_path = std::shared_ptr<Path>(new Path(*m_root));
+ m_path->Append(entry->d_name);
+ }
+ else //transform into end iterator
+ {
+ m_path.reset();
+ m_dir.reset();
+ }
+}
+
+bool Path::Iterator::operator==(const Path::Iterator& rhs) const
+{
+ if(m_dir.get() == NULL)
+ {
+ if(rhs.m_dir.get() == NULL) return true;
+ else return false;
+ }
+ else
+ {
+ if(rhs.m_dir.get() == NULL) return false;
+ }
+ return *m_path == *rhs.m_path;
+}
+
+bool Path::Iterator::operator!=(const Path::Iterator& rhs) const
+{
+ return !this->operator==(rhs);
+}
+
+const Path & Path::Iterator::operator*()
+{
+ return *m_path;
+}
+
+const Path * Path::Iterator::operator->()
+{
+ return m_path.get();
+}
+
+Path::Path(const DPL::String & str)
+{
+ Construct(ToUTF8String(str));
+}
+
+Path::Path(const std::string & str)
+{
+ Construct(str);
+}
+
+Path::Path(const char * str)
+{
+ Construct(std::string(str));
+}
+
+void Path::Construct(const std::string & src)
+{
+ if(src.empty()) ThrowMsg(EmptyPath, "Path cannot be empty");
+ if(src[0] != '/')
+ {
+ DPL::ScopedFree<char> root(getcwd(NULL,0));
+ Tokenize(std::string(root.Get()), "\\/", std::inserter(m_parts, m_parts.begin()), true);
+ }
+ Tokenize(src, "\\/", std::inserter(m_parts, m_parts.end()), true);
+}
+
+Path::Path() //for private usage
+{
+}
+
+std::string Path::DirectoryName() const
+{
+ if(m_parts.empty()) ThrowMsg(InternalError, "Asking DirectoryName for root directory");
+ std::string ret = Join(m_parts.begin(), --m_parts.end(), "/");
+ return std::string("/") + ret;
+}
+
+std::string Path::Basename() const
+{
+ if(m_parts.empty()) return "";
+ else return m_parts.back();
+}
+
+std::string Path::Fullpath() const
+{
+ std::string ret = Join(m_parts.begin(), m_parts.end(), "/");
+ return std::string ("/") + ret;
+}
+
+//foreach
+Path::Iterator Path::begin() const
+{
+ if(IsDir())
+ {
+ return Iterator(Fullpath().c_str());
+ }
+ else
+ {
+ ThrowMsg(NotDirectory, "Cannot iterate not a directory");
+ }
+}
+
+Path::Iterator Path::end() const
+{
+ return Iterator();
+}
+
+
+bool Path::Exists() const
+{
+ struct stat tmp;
+ return (0 == lstat(Fullpath().c_str(), &tmp));
+}
+
+bool Path::IsDir() const
+{
+ struct stat tmp;
+ if (-1 == lstat(Fullpath().c_str(), &tmp))
+ {
+ ThrowMsg(NotExists, DPL::GetErrnoString());
+ }
+ return S_ISDIR(tmp.st_mode);
+}
+
+bool Path::IsFile() const
+{
+ struct stat tmp;
+ if (-1 == lstat(Fullpath().c_str(), &tmp))
+ {
+ ThrowMsg(NotExists, DPL::GetErrnoString());
+ }
+ return S_ISREG(tmp.st_mode);
+}
+
+bool Path::IsSymlink() const
+{
+ struct stat tmp;
+ if (-1 == lstat(Fullpath().c_str(), &tmp))
+ {
+ ThrowMsg(NotExists, DPL::GetErrnoString());
+ }
+ return S_ISLNK(tmp.st_mode);
+}
+
+bool Path::operator==(const Path & other) const
+{
+ return m_parts == other.m_parts;
+}
+
+bool Path::operator!=(const Path & other) const
+{
+ return m_parts != other.m_parts;
+}
+
+Path Path::operator/(const DPL::String& part) const
+{
+ Path newOne;
+ newOne.Append(ToUTF8String(part));
+ return newOne;
+}
+
+Path Path::operator/(const std::string& part) const
+{
+ Path newOne;
+ newOne.Append(part);
+ return newOne;
+}
+
+Path Path::operator/(const char * part) const
+{
+ Path newOne(*this);
+ newOne.Append(std::string(part));
+ return newOne;
+}
+
+Path & Path::operator/=(const DPL::String& part)
+{
+ Append(ToUTF8String(part));
+}
+
+Path & Path::operator/=(const std::string& part)
+{
+ Append(part);
+}
+
+Path & Path::operator/=(const char * part)
+{
+ Append(std::string(part));
+}
+
+void Path::Append(const std::string& part)
+{
+ std::vector<std::string> tokens;
+ Tokenize(part, "\\/", std::inserter(tokens, tokens.end()), true);
+ std::copy(tokens.begin(), tokens.end(), std::inserter(m_parts, m_parts.end()));
+}
+
+void MakeDir(const Path & path, mode_t mode)
+{
+ if(!WrtUtilMakeDir(path.Fullpath(), mode)) ThrowMsg(Path::OperationFailed, "Cannot make directory");
+}
+
+void MakeEmptyFile(const Path & path)
+{
+ std::string fp = path.Fullpath();
+ FILE* fd = fopen(fp.c_str(), "wx");
+ if(!fd)
+ {
+ struct stat st;
+ if(lstat(fp.c_str(), &st) == 0)
+ {
+ ThrowMsg(Path::AlreadyExists, "File already exists");
+ }
+ else
+ {
+ ThrowMsg(Path::OperationFailed, "Operation failed");
+ }
+ }
+ fclose(fd);
+}
+
+void Remove(const Path & path)
+{
+ if(!WrtUtilRemove(path.Fullpath())) ThrowMsg(Path::OperationFailed, "Cannot remove path");
+}
+
+void Rename(const Path & from, const Path & to)
+{
+ if(from == to)
+ {
+ return;
+ }
+ int code = 0;
+ if( (code = rename(from.Fullpath().c_str(), to.Fullpath().c_str())) )
+ {
+ if(code == EXDEV)
+ {
+ Try
+ {
+ DPL::FileInput in(from.Fullpath());
+ DPL::FileOutput out(to.Fullpath());
+ DPL::Copy(&in, &out);
+ }
+ Catch(DPL::FileInput::Exception::Base)
+ {
+ ThrowMsg(Path::OperationFailed, "Cannot open input file " << from.Fullpath());
+ }
+ Catch(DPL::FileOutput::Exception::Base)
+ {
+ ThrowMsg(Path::OperationFailed, "Cannot open output file " << to.Fullpath());
+ }
+ }
+ else
+ {
+ ThrowMsg(Path::OperationFailed, DPL::GetErrnoString());
+ }
+ }
+}
+
+bool Exists(const Path & path)
+{
+ return path.Exists();
+}
+
+}
+
+}
+
+std::ostream & operator<<(std::ostream & str, const DPL::Utils::Path & path)
+{
+ str << path.Fullpath();
+ return str;
+}
+
+//TODO: uncomment when used defiend literals are supported
+///DPL::Utils::Path operator""p(const char * str, size_t)
+//{
+// return DPL::Utils::Path(str);
+//}
#include <orm_generator_wrt.h>
#include <dpl/wrt-dao-ro/WrtDatabase.h>
-namespace {
- unsigned int seed = time(NULL);
-}
-
namespace WrtDB {
//TODO in current solution in each getter there exists a check
//"IsWidgetInstalled". Maybe it should be verified, if it could be done
struct timeval tv;
gettimeofday(&tv, NULL);
DbWidgetHandle widgetHandle;
+ unsigned int seed = time(NULL);
do {
widgetHandle = rand_r(&seed);
} while (isWidgetInstalled(widgetHandle));
inline const char* GetTizenVersion()
{
- return "1.0";
+ return "2.1";
}
inline const char* GetShareDirectoryPath()
CREATE_TABLE(WidgetInfo)
COLUMN_NOT_NULL(app_id, INTEGER, PRIMARY KEY AUTOINCREMENT)
- COLUMN(widget_type, INT, DEFAULT 1)
- COLUMN(widget_id, VARCHAR(256), DEFAULT '')
- COLUMN(widget_version, VARCHAR(256), DEFAULT '')
+ COLUMN(widget_type, INT, DEFAULT 1)
+ COLUMN(widget_id, TEXT, DEFAULT '')
+ COLUMN(widget_version, TEXT, DEFAULT '')
COLUMN(widget_width, INT, DEFAULT 0)
COLUMN(widget_height, INT, DEFAULT 0)
- COLUMN(author_name, VARCHAR(256), DEFAULT '')
- COLUMN(author_email, VARCHAR(256), DEFAULT '')
- COLUMN(author_href, VARCHAR(256), DEFAULT '')
- COLUMN(base_folder, VARCHAR(256), DEFAULT '')
+ COLUMN(author_name, TEXT, DEFAULT '')
+ COLUMN(author_email, TEXT, DEFAULT '')
+ COLUMN(author_href, TEXT, DEFAULT '')
+ COLUMN(base_folder, TEXT, DEFAULT '')
COLUMN(webkit_plugins_required, TINYINT, DEFAULT 0)
COLUMN(security_domain, INT, DEFAULT 0)
COLUMN(csp_policy, TEXT, DEFAULT '')
COLUMN(recognized, INT, DEFAULT 0)
COLUMN(wac_signed, INT, DEFAULT 0)
COLUMN(distributor_signed, INT, DEFAULT 0)
- COLUMN(min_version, VARCHAR(16), DEFAULT '1.0')
+ COLUMN(min_version, TEXT, DEFAULT '1.0')
COLUMN_NOT_NULL(back_supported, TINYINT, DEFAULT 0)
COLUMN(access_network, TINYINT, DEFAULT 0)
- COLUMN(defaultlocale, VARCHAR(256), DEFAULT 0)
- COLUMN_NOT_NULL(tizen_pkgid, VARCHAR(256), DEFAULT '')
- COLUMN_NOT_NULL(tizen_appid, VARCHAR(256), DEFAULT 0 UNIQUE)
+ COLUMN(defaultlocale, TEXT, DEFAULT 0)
+ COLUMN_NOT_NULL(tizen_pkgid, TEXT, DEFAULT '')
+ COLUMN_NOT_NULL(tizen_appid, TEXT, DEFAULT 0 UNIQUE)
COLUMN(pkg_type, INT, DEFAULT 0)
CREATE_TABLE_END()
COLUMN(last_update_time, BIGINT, DEFAULT 0)
COLUMN(install_time, BIGINT, DEFAULT 0)
COLUMN(option_state, INT, DEFAULT 0)
- COLUMN(share_href, VARCHAR(256), DEFAULT '')
+ COLUMN(share_href, TEXT, DEFAULT '')
COLUMN(signature_type, INT, DEFAULT 0)
COLUMN(updated, INT, DEFAULT 0)
COLUMN(update_policy, INT, DEFAULT 0)
COLUMN_NOT_NULL(test_widget, INT, CHECK(test_widget between 0 and 1) DEFAULT 0)
- COLUMN(splash_img_src, VARCHAR(256), DEFAULT '')
- COLUMN(background_page, VARCHAR(256), DEFAULT '')
- COLUMN(installed_path, VARCHAR(512), DEFAULT '')
+ COLUMN(splash_img_src, TEXT, DEFAULT '')
+ COLUMN(background_page, TEXT, DEFAULT '')
+ COLUMN(installed_path, TEXT, DEFAULT '')
TABLE_CONSTRAINTS(
FOREIGN KEY(app_id) REFERENCES WidgetInfo (app_id) ON DELETE CASCADE
)
CREATE_TABLE_END()
CREATE_TABLE(WidgetPreference)
- COLUMN_NOT_NULL(tizen_appid, VARCHAR(256), DEFAULT 0)
- COLUMN_NOT_NULL(key_name, VARCHAR(256),)
- COLUMN(key_value, VARCHAR(8000), DEFAULT '')
- COLUMN(readonly, INT, DEFAULT 0)
+ COLUMN_NOT_NULL(tizen_appid, TEXT, DEFAULT 0)
+ COLUMN_NOT_NULL(key_name, TEXT,)
+ COLUMN(key_value, TEXT, DEFAULT '')
+ COLUMN(readonly, INT, DEFAULT 0)
TABLE_CONSTRAINTS(
PRIMARY KEY(tizen_appid, key_name),
CREATE_TABLE(WidgetFeature)
COLUMN_NOT_NULL(widget_feature_id, INTEGER, primary key autoincrement)
COLUMN_NOT_NULL(app_id, INT,)
- COLUMN_NOT_NULL(name, VARCHAR(256),)
+ COLUMN_NOT_NULL(name, TEXT,)
COLUMN_NOT_NULL(required, INT,)
COLUMN_NOT_NULL(rejected, INT,)
TABLE_CONSTRAINTS(
CREATE_TABLE(WidgetPrivilege)
COLUMN_NOT_NULL(widget_privilege_id, INTEGER, primary key autoincrement)
COLUMN_NOT_NULL(app_id, INT,)
- COLUMN_NOT_NULL(name, VARCHAR(256),)
+ COLUMN_NOT_NULL(name, TEXT,)
TABLE_CONSTRAINTS(
FOREIGN KEY (app_id) REFERENCES WidgetInfo (app_id) ON DELETE CASCADE
)
CREATE_TABLE(WidgetIcon)
COLUMN_NOT_NULL(icon_id, INTEGER, primary key autoincrement)
COLUMN_NOT_NULL(app_id, INT,)
- COLUMN_NOT_NULL(icon_src, VARCHAR(256),)
+ COLUMN_NOT_NULL(icon_src, TEXT,)
COLUMN(icon_width, INT, DEFAULT 0)
COLUMN(icon_height, INT, DEFAULT 0)
TABLE_CONSTRAINTS(
CREATE_TABLE(WidgetStartFile)
COLUMN_NOT_NULL(start_file_id, INTEGER, primary key autoincrement)
COLUMN_NOT_NULL(app_id, INT,)
- COLUMN_NOT_NULL(src, VARCHAR(256),)
+ COLUMN_NOT_NULL(src, TEXT,)
TABLE_CONSTRAINTS(
FOREIGN KEY(app_id) REFERENCES WidgetInfo (app_id) ON DELETE CASCADE
)
CREATE_TABLE(WidgetAccessHost)
COLUMN_NOT_NULL(app_id, INT,)
- COLUMN_NOT_NULL(host, VARCHAR(256),)
+ COLUMN_NOT_NULL(host, TEXT,)
TABLE_CONSTRAINTS(
PRIMARY KEY(app_id, host)
COLUMN_NOT_NULL(owner, INT,)
COLUMN_NOT_NULL(chainid, INT,)
COLUMN_NOT_NULL(type, INT,)
- COLUMN(md5_fingerprint, VARCHAR(64),)
- COLUMN(sha1_fingerprint, VARCHAR(64),)
+ COLUMN(md5_fingerprint, TEXT,)
+ COLUMN(sha1_fingerprint, TEXT,)
COLUMN(common_name, VARCHAR(64),)
TABLE_CONSTRAINTS(
CREATE_TABLE(WidgetWARPInfo)
COLUMN_NOT_NULL(app_id, INT,)
- COLUMN_NOT_NULL(iri, VARCHAR(65536),)
+ COLUMN_NOT_NULL(iri, TEXT,)
COLUMN(subdomain_access, INT, CHECK(subdomain_access between 0 and 1))
TABLE_CONSTRAINTS(
/*TODO: It will be removed when user agent is fixed. User agent MUST be configurable in development...*/
CREATE_TABLE(UserAgents)
- COLUMN_NOT_NULL(key_name, VARCHAR(256),)
- COLUMN(key_value, VARCHAR(8000), DEFAULT '')
+ COLUMN_NOT_NULL(key_name, TEXT,)
+ COLUMN(key_value, TEXT, DEFAULT '')
TABLE_CONSTRAINTS(PRIMARY KEY(key_name))
CREATE_TABLE_END()
-#git:framework/web/wrt-commons wrt-commons 0.2.102
+#git:framework/web/wrt-commons wrt-commons 0.2.103
Name: wrt-commons
Summary: Wrt common library
-Version: 0.2.102
+Version: 0.2.103
Release: 1
Group: Development/Libraries
License: Apache License, Version 2.0
BuildRequires: pkgconfig(openssl)
BuildRequires: pkgconfig(libiri)
BuildRequires: pkgconfig(libidn)
+BuildRequires: pkgconfig(osp-appfw)
BuildRequires: libcryptsvc-devel
BuildRequires: dukgenerator-devel
+BuildRequires: osp-appfw-internal-devel
Requires: libcryptsvc
+Requires: osp-appfw
%description
Wrt common library
${TESTS_DIR}/utils/widget_version.cpp
${TESTS_DIR}/utils/bash_utils.cpp
${TESTS_DIR}/utils/wrt_utility.cpp
+ ${TESTS_DIR}/utils/path_tests.cpp
)
#WRT_TEST_ADD_INTERNAL_DEPENDENCIES(${TARGET_NAME} ${TARGET_DPL_UTILS_EFL})
--- /dev/null
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file path.h
+ * @author Tomasz Iwanek (t.iwanek@samsung.com)
+ * @version 1.0
+ */
+
+#include <set>
+#include <memory>
+
+#include <dpl/test/test_runner.h>
+#include <dpl/scoped_dir.h>
+#include <dpl/scoped_free.h>
+#include <dpl/utils/path.h>
+#include <dpl/foreach.h>
+#include <dpl/log/log.h>
+
+#include <sys/stat.h>
+#include <unistd.h>
+
+using namespace DPL::Utils;
+
+namespace {
+//do not used path here we test it
+std::string rootTest = "/tmp/wrttest/";
+}
+
+RUNNER_TEST_GROUP_INIT(DPL_Path)
+
+/*
+Name: path_touch
+Description: constructs paths in many ways
+Expected: success full constrution
+*/
+RUNNER_TEST(path_mkfile)
+{
+ DPL::ScopedDir sd(rootTest);
+
+ struct stat st;
+ Path path = Path(rootTest) / "touch.txt";
+ RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) != 0, "File should not be created");
+ RUNNER_ASSERT(!path.Exists());
+ MakeEmptyFile(path);
+ RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) == 0, "File should be created");
+ RUNNER_ASSERT(path.Exists());
+ RUNNER_ASSERT(path.IsFile());
+ RUNNER_ASSERT(!path.IsDir());
+ RUNNER_ASSERT(!path.IsSymlink());
+}
+
+/*
+Name: path_touch
+Description: tries to craete file when it exists
+Expected: failure
+*/
+RUNNER_TEST(path_mkfile_exists)
+{
+ DPL::ScopedDir sd(rootTest);
+
+ Path path = Path(rootTest) / "touch.txt";
+ MakeEmptyFile(path);
+ RUNNER_ASSERT(path.Exists());
+ bool cannotCreate2ndTime = false;
+ Try
+ {
+ MakeEmptyFile(path);
+ }
+ Catch(Path::AlreadyExists)
+ {
+ cannotCreate2ndTime = true;
+ }
+ RUNNER_ASSERT_MSG(cannotCreate2ndTime, "File created should not be able to be created second time");
+}
+
+/*
+Name: path_mkfile_invalid_path
+Description: tries to create file in not exisitng directory
+Expected: failure at creation
+*/
+RUNNER_TEST(path_mkfile_invalid_path)
+{
+ DPL::ScopedDir sd(rootTest);
+
+ Path path = Path(rootTest) / "not_existing" / "touch.txt";
+ bool cannotCreate = false;
+ Try
+ {
+ MakeEmptyFile(path);
+ }
+ Catch(Path::OperationFailed)
+ {
+ cannotCreate = true;
+ }
+ RUNNER_ASSERT_MSG(cannotCreate, "File created should not be able to be created");
+}
+
+/*
+Name: path_mkdir
+Description: creates valid directory
+Expected: success direcotry creation
+*/
+RUNNER_TEST(path_mkdir)
+{
+ DPL::ScopedDir sd(rootTest);
+
+ struct stat st;
+ Path path = Path(rootTest) / "touchDir";
+ RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) != 0, "Directory should not be created");
+ RUNNER_ASSERT(!path.Exists());
+ MakeDir(path);
+ RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) == 0, "Directory should be created");
+ RUNNER_ASSERT(path.Exists());
+ RUNNER_ASSERT(!path.IsFile());
+ RUNNER_ASSERT(path.IsDir());
+ RUNNER_ASSERT(!path.IsSymlink());
+}
+
+/*
+Name: path_symlink
+Description: chekc if symlink is correctly recognized
+Expected: method isSymlink returns true
+*/
+RUNNER_TEST(path_symlink)
+{
+ DPL::ScopedDir sd(rootTest);
+
+ struct stat st;
+ Path path = Path(rootTest) / "symlink";
+ RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) != 0, "Symlink should not be created");
+ RUNNER_ASSERT(!path.Exists());
+ (void)symlink("/nonexistisfile/file/file/file ", path.Fullpath().c_str());
+ RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) == 0, "Symlink should be created");
+ RUNNER_ASSERT(path.Exists());
+ RUNNER_ASSERT(!path.IsFile());
+ RUNNER_ASSERT(!path.IsDir());
+ RUNNER_ASSERT(path.IsSymlink());
+}
+
+/*
+Name: path_construction_empty
+Description: tries to construct empty path
+Expected: failure
+*/
+RUNNER_TEST(path_construction_empty)
+{
+ bool passed = false;
+ Try
+ {
+ Path path1(std::string(""));
+ }
+ Catch(Path::EmptyPath)
+ {
+ passed = true;
+ }
+ RUNNER_ASSERT_MSG(passed, "Construction with empty path do not fails");
+}
+
+/*
+Name: path_construction_root
+Description: tries to construct root path
+Expected: success
+*/
+RUNNER_TEST(path_construction_root)
+{
+ Path path1(std::string("/"));
+ RUNNER_ASSERT(path1.Fullpath() == "/");
+ RUNNER_ASSERT(path1.Basename() == "");
+ bool passed = false;
+ Try
+ {
+ RUNNER_ASSERT(path1.DirectoryName() == "/");
+ }
+ Catch(Path::InternalError)
+ {
+ passed = true;
+ }
+ RUNNER_ASSERT_MSG(passed, "Directory name for root should be an error");
+}
+
+/*
+Name: path_construction_1
+Description: constructs paths in many ways
+Expected: success full constrution
+*/
+RUNNER_TEST(path_construction_1)
+{
+ DPL::ScopedFree<char> sf(getcwd(NULL, 0));
+
+ Path path1(std::string("/test/bin/file"));
+ RUNNER_ASSERT(path1.Fullpath() == "/test/bin/file");
+ RUNNER_ASSERT(path1.Basename() == "file");
+ RUNNER_ASSERT(path1.DirectoryName() == "/test/bin");
+}
+
+/*
+Name: path_construction_2
+Description: constructs paths in many ways
+Expected: success full constrution
+*/
+RUNNER_TEST(path_construction_2)
+{
+ DPL::ScopedFree<char> sf(getcwd(NULL, 0));
+ std::string cwd(sf.Get());
+
+ Path path2(std::string("test/bin/file.eas"));
+ RUNNER_ASSERT(path2.Fullpath() == cwd + "/test/bin/file.eas");
+ RUNNER_ASSERT(path2.Basename() == "file.eas");
+ RUNNER_ASSERT(path2.DirectoryName() == cwd + "/test/bin");
+}
+
+/*
+Name: path_construction_3
+Description: constructs paths in many ways
+Expected: success full constrution
+*/
+RUNNER_TEST(path_construction_3)
+{
+ DPL::ScopedFree<char> sf(getcwd(NULL, 0));
+ std::string cwd(sf.Get());
+
+ Path path3("test/23/abc");
+ RUNNER_ASSERT(path3.Fullpath() == cwd + "/test/23/abc");
+ RUNNER_ASSERT(path3.Basename() == "abc");
+ RUNNER_ASSERT(path3.DirectoryName() == cwd + "/test/23");
+}
+
+/*
+Name: path_construction_4
+Description: constructs paths in many ways
+Expected: success full constrution
+*/
+RUNNER_TEST(path_construction_4)
+{
+ DPL::ScopedFree<char> sf(getcwd(NULL, 0));
+
+ Path path4("/test/bin/abc");
+ RUNNER_ASSERT(path4.Fullpath() == "/test/bin/abc");
+ RUNNER_ASSERT(path4.Basename() == "abc");
+ RUNNER_ASSERT(path4.DirectoryName() == "/test/bin");
+}
+
+/*
+Name: path_construction_5
+Description: constructs paths in many ways
+Expected: success full constrution
+*/
+RUNNER_TEST(path_construction_5)
+{
+ DPL::ScopedFree<char> sf(getcwd(NULL, 0));
+ std::string cwd(sf.Get());
+
+ Path path5(DPL::String(L"test/bin/file.st.exe"));
+ RUNNER_ASSERT(path5.Fullpath() == cwd + "/test/bin/file.st.exe");
+ RUNNER_ASSERT(path5.Basename() == "file.st.exe");
+ RUNNER_ASSERT(path5.DirectoryName() == cwd + "/test/bin");
+}
+
+/*
+Name: path_construction_6
+Description: constructs paths in many ways
+Expected: success full constrution
+*/
+RUNNER_TEST(path_construction_6)
+{
+ DPL::ScopedFree<char> sf(getcwd(NULL, 0));
+
+ Path path6(DPL::String(L"/test/bin/file"));
+ RUNNER_ASSERT(path6.Fullpath() == "/test/bin/file");
+ RUNNER_ASSERT(path6.Basename() == "file");
+ RUNNER_ASSERT(path6.DirectoryName() == "/test/bin");
+}
+
+/*
+Name: path_construction_7
+Description: constructs paths in many ways
+Expected: success full constrution
+*/
+RUNNER_TEST(path_construction_7)
+{
+ DPL::ScopedFree<char> sf(getcwd(NULL, 0));
+ std::string cwd(sf.Get());
+
+ Path path7 = Path("test") / "a///23/lol";
+ RUNNER_ASSERT(path7.Fullpath() == cwd + "/test/a/23/lol");
+ RUNNER_ASSERT(path7.Basename() == "lol");
+ RUNNER_ASSERT(path7.DirectoryName() == cwd + "/test/a/23");
+}
+
+/*
+Name: path_construction_8
+Description: constructs paths in many ways
+Expected: success full constrution
+*/
+RUNNER_TEST(path_construction_8)
+{
+ DPL::ScopedFree<char> sf(getcwd(NULL, 0));
+
+ Path path8 = Path("/test/bin/") / "123" / "dir1.dll";
+ RUNNER_ASSERT(path8.Fullpath() == "/test/bin/123/dir1.dll");
+ RUNNER_ASSERT(path8.Basename() == "dir1.dll");
+ RUNNER_ASSERT(path8.DirectoryName() == "/test/bin/123");
+}
+
+/*
+Name: path_construction_9
+Description: constructs paths in many ways
+Expected: success full constrution
+*/
+RUNNER_TEST(path_construction_9)
+{
+ DPL::ScopedFree<char> sf(getcwd(NULL, 0));
+
+ Path path9 = Path("/test/bin/file.txt//");
+ RUNNER_ASSERT(path9.Fullpath() == "/test/bin/file.txt");
+ RUNNER_ASSERT(path9.Basename() == "file.txt");
+ RUNNER_ASSERT(path9.DirectoryName() == "/test/bin");
+}
+
+/*
+Name: path_construction_10
+Description: constructs paths by appending
+Expected: success full constrution
+*/
+RUNNER_TEST(path_construction_10)
+{
+ Path path10 = Path("/test/");
+ path10 /= "one";
+ path10 /= std::string("two");
+ path10 /= DPL::String(L"three");
+ RUNNER_ASSERT(path10.Fullpath() == "/test/one/two/three");
+ RUNNER_ASSERT(path10.Basename() == "three");
+ RUNNER_ASSERT(path10.DirectoryName() == "/test/one/two");
+}
+
+/*
+Name: path_remove
+Description: tests removing paths
+Expected: successfull path remove
+*/
+RUNNER_TEST(path_remove_valid)
+{
+ DPL::ScopedDir sd(rootTest);
+
+ struct stat st;
+ Path path = Path(rootTest) / "touchDir";
+ RUNNER_ASSERT(!path.Exists());
+
+ MakeDir(path);
+ RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) == 0, "Directory should be created");
+ RUNNER_ASSERT(path.Exists());
+
+ Remove(path);
+ RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) != 0, "Directory should not be created");
+ RUNNER_ASSERT(!path.Exists());
+
+ MakeEmptyFile(path);
+ RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) == 0, "File should be created");
+ RUNNER_ASSERT(path.Exists());
+
+ Remove(path);
+ RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) != 0, "File should not be created");
+ RUNNER_ASSERT(!path.Exists());
+}
+
+/*
+Name: path_remove_invalid
+Description: tests removing invalid paths
+Expected: failure at path remove
+*/
+RUNNER_TEST(path_remove_invalid)
+{
+ DPL::ScopedDir sd(rootTest);
+
+ Path path = Path(rootTest) / "touchDir";
+
+ bool removedNotExisting = true;
+ Try
+ {
+ Remove(path);
+ }
+ Catch(Path::OperationFailed)
+ {
+ removedNotExisting = false;
+ }
+ RUNNER_ASSERT_MSG(!removedNotExisting, "Removing not existing file");
+}
+
+/*
+Name: path_rename
+Description: tests path renaming
+Expected: path is successfully renamed
+*/
+RUNNER_TEST(path_rename)
+{
+ DPL::ScopedDir sd(rootTest);
+
+ struct stat st;
+ Path path = Path(rootTest) / "touchDir";
+ Path dirpath = Path(rootTest) / "directory";
+ Path path2 = dirpath / "touchDir2";
+
+ MakeDir(dirpath);
+
+ MakeEmptyFile(path);
+ RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) == 0, "File should be created");
+ RUNNER_ASSERT(path.Exists());
+ RUNNER_ASSERT(!path2.Exists());
+
+ Rename(path, path2);
+ RUNNER_ASSERT(!path.Exists());
+ RUNNER_ASSERT(path2.Exists());
+
+ Rename(path2, path);
+ RUNNER_ASSERT(path.Exists());
+ RUNNER_ASSERT(!path2.Exists());
+
+ //TODO: test for different devices
+}
+
+/*
+Name: path_rename_same
+Description: tests if renam does not brokens file if target location is equal to source location
+Expected: path is avaliable
+*/
+RUNNER_TEST(path_rename_same)
+{
+ DPL::ScopedDir sd(rootTest);
+
+ struct stat st;
+ Path path = Path(rootTest) / "touchDir";
+
+ MakeDir(path);
+ Rename(path, path);
+ RUNNER_ASSERT(path.Exists());
+}
+
+/*
+Name: path_iterate_not_directory
+Description: iterates not a directory
+Expected: success full constrution
+*/
+RUNNER_TEST(path_iterate_not_directory)
+{
+ DPL::ScopedDir sd(rootTest);
+
+ Path fileTest = Path(rootTest) / "file.txt";
+ MakeEmptyFile(fileTest);
+
+ bool passed = false;
+ Try
+ {
+ FOREACH(file, fileTest)
+ {
+
+ }
+ }
+ Catch(Path::NotDirectory)
+ {
+ passed = true;
+ }
+ RUNNER_ASSERT(passed);
+}
+
+/*
+Name: path_construction
+Description: constructs paths in many ways
+Expected: success full constrution
+*/
+RUNNER_TEST(path_iterate_empty_directory)
+{
+ DPL::ScopedDir sd(rootTest);
+
+ Path dirTest = Path(rootTest) / "directory";
+ MakeDir(dirTest);
+
+ bool passed = true;
+ Try
+ {
+ FOREACH(file, dirTest)
+ {
+ passed = false;
+ LogError("Directory should be empty");
+ }
+ }
+ Catch(Path::NotDirectory)
+ {
+ passed = false;
+ LogError("Directory should exists");
+ }
+ RUNNER_ASSERT(passed);
+}
+
+/*
+Name: path_construction
+Description: constructs paths in many ways
+Expected: success full constrution
+*/
+RUNNER_TEST(path_iterate_notempty_directory)
+{
+ DPL::ScopedDir sd(rootTest);
+
+ Path dirTest = Path(rootTest) / "directory";
+
+ Path path1 = Path(rootTest) / "directory" / "file1";
+ Path path2 = Path(rootTest) / "directory" / "file2";
+ Path path3 = Path(rootTest) / "directory" / "file3";
+
+ std::set<std::string> resultSet;
+ std::set<std::string> testSet;
+ testSet.insert(path1.Fullpath());
+ testSet.insert(path2.Fullpath());
+ testSet.insert(path3.Fullpath());
+
+ MakeDir(dirTest);
+ MakeEmptyFile(path1);
+ MakeEmptyFile(path2);
+ MakeEmptyFile(path3);
+
+ FOREACH(file, dirTest)
+ {
+ resultSet.insert(file->Fullpath());
+ }
+
+ RUNNER_ASSERT_MSG(testSet == resultSet, "Testing");
+}
+
+/*
+Name: path_construction
+Description: constructs paths in many ways
+Expected: success full constrution
+*/
+RUNNER_TEST(path_iterator_copy_constructor)
+{
+ DPL::ScopedDir sd(rootTest);
+
+ Path dirTest = Path(rootTest) / "directory";
+
+ Path path1 = Path(rootTest) / "directory" / "file1";
+ Path path2 = Path(rootTest) / "directory" / "file2";
+ Path path3 = Path(rootTest) / "directory" / "file3";
+
+ MakeDir(dirTest);
+ MakeEmptyFile(path1);
+ MakeEmptyFile(path2);
+ MakeEmptyFile(path3);
+
+ std::shared_ptr<Path::Iterator> iter1(new Path::Iterator((Path(rootTest) / "directory").Fullpath().c_str()));
+
+ //as it's input iterator it's guaranteed for one element to be iterate only once
+ (*iter1)++;
+ std::shared_ptr<Path::Iterator> iter2(new Path::Iterator( (*iter1)));
+ iter1.reset();
+ (*iter2)++;
+ ++(*iter2);
+ RUNNER_ASSERT_MSG(*iter2 == dirTest.end(), "Iterator is in broken state");
+ iter2.reset();
+}