--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+// CLASS HEADER
+#include "file-loader.h"
+
+
+#include <iostream>
+#include <fstream>
+
+namespace Dali
+{
+
+namespace FileLoader
+{
+
+int ReadFile(const std::string& filename, Dali::Vector<char> & memblock, FileLoader::FileType fileType)
+{
+ std::streampos size;
+
+ return ReadFile( filename, size, memblock, fileType);
+}
+
+int ReadFile(const std::string& filename, std::streampos& fileSize, Dali::Vector<char> & memblock, FileLoader::FileType fileType)
+{
+ int errorCode = 0;
+ std::ifstream * file;
+
+
+ if( fileType == BINARY )
+ {
+ file = new std::ifstream (filename.c_str(), std::ios::in|std::ios::binary|std::ios::ate);
+ }
+ else if( fileType == TEXT )
+ {
+ file = new std::ifstream (filename.c_str(), std::ios::in|std::ios::ate);
+ }
+ else
+ {
+ return errorCode;
+ }
+
+ if( file->is_open() )
+ {
+ fileSize = file->tellg();
+
+ memblock.Resize( fileSize );
+
+ file->seekg (0, std::ios::beg);
+ file->read( memblock.Begin(), fileSize );
+ file->close();
+
+ delete file;
+
+ errorCode = 1;
+ }
+
+ return errorCode;
+}
+
+
+std::streampos GetFileSize(const std::string& filename)
+{
+ std::streampos size = 0;
+
+ std::ifstream file (filename.c_str(), std::ios::in|std::ios::binary|std::ios::ate);
+ if( file.is_open() )
+ {
+ size = file.tellg();
+ file.close();
+ }
+ return size;
+}
+
+} //FileLoader
+
+} //Dali
--- /dev/null
+#ifndef __DALI_FILE_LOADER_H__
+#define __DALI_FILE_LOADER_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * 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 <string>
+#include <dali/public-api/common/dali-common.h>
+#include <dali/public-api/object/base-handle.h>
+
+namespace Dali
+{
+
+namespace FileLoader
+{
+/**
+ * @brief File type formats
+ * The default format is binary
+ */
+enum FileType ///< FileType format
+{
+ BINARY, ///< File will be loaded as a binary
+ TEXT ///< File will be loaded as text
+};
+
+/**
+ * @brief Load the file. It will load it either as a binary or as a text
+ *
+ * @param[in] filename Filename of the file to load.
+ * @param[in] memblock Dali::Vector containing the buffer loaded
+ * @param[in] fileType How we want to load the file. Binary or Text. Binary default
+ * @return error code. 0 - Error, 1 - Ok
+ *
+ *
+ */
+DALI_IMPORT_API int ReadFile(const std::string& filename, Dali::Vector<char> & memblock, FileLoader::FileType fileType = BINARY);
+
+/**
+ * @brief Load the file. It will load it either as a binary or as a text
+ *
+ * @param[in] filename Filename of the file to load.
+ * @param[in] fileSize Size of the loaded file
+ * @param[in] memblock Dali::Vector containing the buffer loaded
+ * @param[in] fileType How we want to load the file. Binary or Text. Binary default
+ * @return error code. 0 - Error, 1 - Ok
+ *
+ */
+DALI_IMPORT_API int ReadFile(const std::string& filename, std::streampos& fileSize, Dali::Vector<char> & memblock, FileLoader::FileType fileType = BINARY);
+
+/**
+ * @brief Get the file size of a file
+ *
+ * @param[in] filename Filename of the file to load.
+ * @return the size of the file or 0 if file not found
+ */
+DALI_IMPORT_API std::streampos GetFileSize(const std::string& filename);
+};
+
+} // Dali
+#endif // __DALI_FILE_LOADER_H__
$(adaptor_devel_api_dir)/adaptor-framework/drag-and-drop-detector.cpp \
$(adaptor_devel_api_dir)/adaptor-framework/event-feeder.cpp \
$(adaptor_devel_api_dir)/adaptor-framework/feedback-player.cpp \
+ $(adaptor_devel_api_dir)/adaptor-framework/file-loader.cpp \
$(adaptor_devel_api_dir)/adaptor-framework/imf-manager.cpp \
$(adaptor_devel_api_dir)/adaptor-framework/orientation.cpp \
$(adaptor_devel_api_dir)/adaptor-framework/performance-logger.cpp \
$(adaptor_devel_api_dir)/adaptor-framework/event-feeder.h \
$(adaptor_devel_api_dir)/adaptor-framework/feedback-plugin.h \
$(adaptor_devel_api_dir)/adaptor-framework/feedback-player.h \
+ $(adaptor_devel_api_dir)/adaptor-framework/file-loader.h \
$(adaptor_devel_api_dir)/adaptor-framework/imf-manager.h \
$(adaptor_devel_api_dir)/adaptor-framework/lifecycle-controller.h \
$(adaptor_devel_api_dir)/adaptor-framework/orientation.h \
utc-Dali-Timer.cpp
utc-Dali-TtsPlayer.cpp
utc-Dali-Application.cpp
+ utc-Dali-FileLoader.cpp
)
LIST(APPEND TC_SOURCES
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -ggdb --coverage -Wall -Werror=return-type")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${${CAPI_LIB}_CFLAGS_OTHER}")
+ADD_DEFINITIONS(-DTEST_RESOURCE_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/../../resources\" )
+
FOREACH(directory ${${CAPI_LIB}_LIBRARY_DIRS})
SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -L${directory}")
ENDFOREACH(directory ${CAPI_LIB_LIBRARY_DIRS})
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * 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 <dali/dali.h>
+#include <dali-test-suite-utils.h>
+#include <dali/devel-api/adaptor-framework/file-loader.h>
+
+
+
+using namespace Dali;
+
+
+void utc_dali_file_loader_startup(void)
+{
+ test_return_value = TET_UNDEF;
+}
+
+void utc_dali_file_loader_cleanup(void)
+{
+ test_return_value = TET_PASS;
+}
+
+int UtcDaliReadFileNew1(void)
+{
+ int errorCode;
+ Dali::Vector<char> buffer;
+
+ //negative case
+ errorCode = FileLoader::ReadFile( TEST_RESOURCE_DIR "/not_exist.txt", buffer, FileLoader::TEXT );
+
+ DALI_TEST_CHECK( errorCode == 0 );
+
+ DALI_TEST_CHECK( buffer.Size() == 0 );
+
+ //positive case
+ errorCode = FileLoader::ReadFile( TEST_RESOURCE_DIR "/test.txt", buffer, FileLoader::TEXT );
+
+ DALI_TEST_CHECK( errorCode != 0 );
+
+ DALI_TEST_CHECK( buffer.Size() > 0 );
+
+ END_TEST;
+}
+
+int UtcDaliReadFileNew2(void)
+{
+ int errorCode;
+ Dali::Vector<char> buffer;
+ std::streampos fileSize = 0;
+
+ //negative case
+ errorCode = FileLoader::ReadFile( TEST_RESOURCE_DIR "/not_exist.txt", fileSize, buffer, FileLoader::TEXT );
+
+ DALI_TEST_CHECK( errorCode == 0 );
+
+ DALI_TEST_CHECK( buffer.Size() == 0 );
+
+ DALI_TEST_CHECK( fileSize == 0 );
+
+ //positive case
+ errorCode = FileLoader::ReadFile( TEST_RESOURCE_DIR "/test.txt", fileSize, buffer, FileLoader::TEXT );
+
+ DALI_TEST_CHECK( errorCode != 0 );
+
+ DALI_TEST_CHECK( buffer.Size() > 0 );
+
+ DALI_TEST_CHECK( fileSize != 0 );
+
+ END_TEST;
+}
+
+int UtcDaliReadFileNew3(void)
+{
+ std::streampos fileSize = 0;
+
+ //negative case
+ fileSize = FileLoader::GetFileSize( TEST_RESOURCE_DIR "/not_exist.txt" );
+
+ DALI_TEST_CHECK( fileSize == 0 );
+
+ //positive case
+ fileSize = FileLoader::GetFileSize( TEST_RESOURCE_DIR "/test.txt" );
+
+ DALI_TEST_CHECK( fileSize != 0 );
+
+ END_TEST;
+}