init
This commit is contained in:
+89
@@ -0,0 +1,89 @@
|
||||
#######################################################################
|
||||
# Software License Agreement (AGPL-3 License)
|
||||
#
|
||||
# OpenViBE SDK Test Software
|
||||
# Based on OpenViBE V1.1.0, Copyright (C) Inria, 2006-2015
|
||||
# Copyright (C) Inria, 2015-2017,V1.0
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License version 3,
|
||||
# as published by the Free Software Foundation.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program.
|
||||
# If not, see <http://www.gnu.org/licenses/>.
|
||||
#######################################################################
|
||||
PROJECT(openvibe-module-fs-test-utf)
|
||||
SET_BUILD_PLATFORM()
|
||||
|
||||
ADD_EXECUTABLE(${PROJECT_NAME} uoFilesTestUTF.cpp)
|
||||
|
||||
INCLUDE("FindOpenViBE")
|
||||
INCLUDE("FindOpenViBECommon")
|
||||
INCLUDE("FindOpenViBEModuleFS")
|
||||
INCLUDE("FindThirdPartyBoost")
|
||||
#INCLUDE("FindThirdPartyBoost_System")
|
||||
INCLUDE("FindThirdPartyBoost_FileSystem")
|
||||
|
||||
SET_PROPERTY(TARGET ${PROJECT_NAME} PROPERTY FOLDER ${TESTS_FOLDER}) # Place project in folder unit-test (for some IDE)
|
||||
|
||||
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${GTEST_BOTH_LIBRARIES})
|
||||
|
||||
ADD_DEFINITIONS("-DDATA_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/data\"")
|
||||
ADD_DEFINITIONS("-DTMP_DIR=\"${OVT_TEST_TEMPORARY_DIR}\"")
|
||||
ADD_TEST(NAME uoFSTestUTF COMMAND ${PROJECT_NAME})
|
||||
|
||||
PROJECT(openvibe-module-fs-test)
|
||||
|
||||
# ---------------------------------
|
||||
# Target macros
|
||||
# Defines target operating system, architecture and compiler
|
||||
# ---------------------------------
|
||||
SET_BUILD_PLATFORM()
|
||||
|
||||
# ----------------------
|
||||
# Configure test target
|
||||
# ----------------------
|
||||
|
||||
# Test that needs to called with parameters
|
||||
SET(TEST_WITH_PARAM
|
||||
uoEntryEnumeratorTest.cpp
|
||||
uoFilesTest.cpp
|
||||
)
|
||||
|
||||
# Test that needs to called without parameters
|
||||
SET(TEST_NO_PARAM
|
||||
)
|
||||
|
||||
# Create test sources list
|
||||
# This macro auto-generate ${PROJECT_NAME}.cpp
|
||||
# in the build tree. ${PROJECT_NAME}.cpp is
|
||||
# the test driver called by ctest to run
|
||||
# the different tests added to this target.
|
||||
CREATE_TEST_SOURCELIST (Tests
|
||||
${PROJECT_NAME}.cpp
|
||||
${TEST_WITH_PARAM}
|
||||
${TEST_NO_PARAM}
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(${PROJECT_NAME} ${Tests})
|
||||
INCLUDE("FindOpenViBE")
|
||||
INCLUDE("FindOpenViBECommon")
|
||||
INCLUDE("FindOpenViBEModuleFS")
|
||||
SET_PROPERTY(TARGET ${PROJECT_NAME} PROPERTY FOLDER ${TESTS_FOLDER})
|
||||
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${OVT_UNIT_TOOLKIT_LIB} ${OV_MODULE_FS})
|
||||
|
||||
# Add test without parameter to driver
|
||||
FOREACH(test ${TEST_NO_PARAM})
|
||||
GET_FILENAME_COMPONENT(TName ${test} NAME_WE)
|
||||
ADD_TEST(NAME ${TName} COMMAND ${PROJECT_NAME} ${TName})
|
||||
ENDFOREACH()
|
||||
|
||||
# Add test with parameter to driver
|
||||
ADD_TEST(NAME uoEntryEnumeratorTest COMMAND ${PROJECT_NAME} uoEntryEnumeratorTest "${CMAKE_CURRENT_SOURCE_DIR}/data/")
|
||||
ADD_TEST(NAME uoFilesTest COMMAND ${PROJECT_NAME} uoFilesTest "${OVT_TEST_TEMPORARY_DIR}")
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
/*********************************************************************
|
||||
* Software License Agreement (AGPL-3 License)
|
||||
*
|
||||
* OpenViBE SDK Test Software
|
||||
* Based on OpenViBE V1.1.0, Copyright (C) Inria, 2006-2015
|
||||
* Copyright (C) Inria, 2015-2017,V1.0
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <fs/IEntryEnumerator.h>
|
||||
|
||||
#include "ovtAssert.h"
|
||||
|
||||
class EntryEnumeratorCallBack final : public FS::IEntryEnumeratorCallBack
|
||||
{
|
||||
public:
|
||||
|
||||
bool callback(FS::IEntryEnumerator::IEntry& rEntry, FS::IEntryEnumerator::IAttributes& rAttributes) override
|
||||
{
|
||||
if (rAttributes.isFile()) { m_files.push_back(rEntry.getName()); }
|
||||
return true;
|
||||
}
|
||||
|
||||
void release() { m_files.clear(); }
|
||||
|
||||
std::vector<std::string> m_files;
|
||||
};
|
||||
|
||||
int uoEntryEnumeratorTest(int /*argc*/, char* argv[])
|
||||
{
|
||||
const std::string dataDirectory = argv[1];
|
||||
|
||||
EntryEnumeratorCallBack cb;
|
||||
FS::IEntryEnumerator* enumerator = createEntryEnumerator(cb);
|
||||
enumerator->enumerate((dataDirectory + "*.txt").c_str());
|
||||
|
||||
OVT_ASSERT(cb.m_files.size() == 2, "Failure to enumerate with wildcard prefix");
|
||||
|
||||
cb.release();
|
||||
|
||||
// test wildcard after
|
||||
enumerator->enumerate((dataDirectory + "test*").c_str());
|
||||
|
||||
OVT_ASSERT(cb.m_files.size() == 2, "Failure to enumerate with wildcard suffix");
|
||||
|
||||
cb.release();
|
||||
|
||||
// test wildcard after
|
||||
enumerator->enumerate((dataDirectory + "t*").c_str());
|
||||
|
||||
OVT_ASSERT(cb.m_files.size() == 3, "Failure to enumerate with single letter");
|
||||
|
||||
cb.release();
|
||||
|
||||
// test wildcard before and after
|
||||
enumerator->enumerate((dataDirectory + "*oto*").c_str());
|
||||
|
||||
OVT_ASSERT(cb.m_files.size() == 1, "Failure to enumerate with englobing wildcards");
|
||||
OVT_ASSERT_STREQ(cb.m_files[0], std::string(dataDirectory + "toto.md"), "Failure to enumerate with englobing wildcards");
|
||||
|
||||
cb.release();
|
||||
|
||||
// test wildcard in middle
|
||||
enumerator->enumerate((dataDirectory + "test1*xt").c_str());
|
||||
|
||||
OVT_ASSERT(cb.m_files.size() == 1, "Failure to enumerate with middle wildcard");
|
||||
OVT_ASSERT_STREQ(cb.m_files[0], std::string(dataDirectory + "test1.txt"), "Failure to enumerate with middle wildcard");
|
||||
|
||||
cb.release();
|
||||
|
||||
// error case: no wildcard
|
||||
enumerator->enumerate((dataDirectory + "t").c_str());
|
||||
|
||||
OVT_ASSERT(cb.m_files.empty(), "Failure to enumerate with no wildcard");
|
||||
|
||||
cb.release();
|
||||
|
||||
enumerator->release();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
/*********************************************************************
|
||||
* Software License Agreement (AGPL-3 License)
|
||||
*
|
||||
* OpenViBE SDK Test Software
|
||||
* Based on OpenViBE V1.1.0, Copyright (C) Inria, 2006-2015
|
||||
* Copyright (C) Inria, 2015-2017,V1.0
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <fs/Files.h>
|
||||
|
||||
#include "ovtAssert.h"
|
||||
#include <iostream>
|
||||
|
||||
int uoFilesTest(int /*argc*/, char* argv[])
|
||||
{
|
||||
std::string outputDirectory = argv[1];
|
||||
|
||||
OVT_ASSERT(FS::Files::directoryExists(outputDirectory.c_str()), "Failure to find test data directory");
|
||||
|
||||
std::string testDir = outputDirectory + "uoFilesTest";
|
||||
std::string testFile = testDir + "/uoFilesTest.txt";
|
||||
|
||||
// test path creation
|
||||
|
||||
FS::Files::createParentPath(testFile.c_str());
|
||||
OVT_ASSERT(FS::Files::directoryExists(testDir.c_str()), "Failure to create directory");
|
||||
OVT_ASSERT(!FS::Files::fileExists(testFile.c_str()), "Failure to create parent path only");
|
||||
|
||||
// test path retrieval methods
|
||||
|
||||
char parentPathFromFile[1024];
|
||||
FS::Files::getParentPath(testFile.c_str(), parentPathFromFile);
|
||||
OVT_ASSERT_STREQ(std::string(parentPathFromFile), testDir, "Failure to retrieve parent path from full path");
|
||||
|
||||
char parentPathFromDir[1024];
|
||||
FS::Files::getParentPath(testDir.c_str(), parentPathFromDir);
|
||||
std::cout << parentPathFromDir << " " << outputDirectory << std::endl;
|
||||
OVT_ASSERT_STREQ((std::string(parentPathFromDir) + "/"), outputDirectory, "Failure to retrieve parent path from path with no slash");
|
||||
|
||||
testDir += "/"; // adding a slash should now give testDir as parent
|
||||
FS::Files::getParentPath(testDir.c_str(), parentPathFromDir);
|
||||
OVT_ASSERT_STREQ((std::string(parentPathFromDir) + "/"), testDir, "Failure to retrieve parent path from path with slash");
|
||||
|
||||
char filename[256];
|
||||
FS::Files::getFilename(testFile.c_str(), filename);
|
||||
OVT_ASSERT_STREQ(std::string(filename), std::string("uoFilesTest.txt"), "Failure to retrieve filename from full path");
|
||||
|
||||
FS::Files::getFilenameWithoutExtension(testFile.c_str(), filename);
|
||||
OVT_ASSERT_STREQ(std::string(filename), std::string("uoFilesTest"), "Failure to retrieve filename with no extension from full path");
|
||||
|
||||
// test file creation and opening
|
||||
|
||||
std::ofstream ostream;
|
||||
FS::Files::openOFStream(ostream, testFile.c_str());
|
||||
OVT_ASSERT(FS::Files::fileExists(testFile.c_str()), "Failure to create file");
|
||||
OVT_ASSERT(ostream.is_open(), "Failure to open file");
|
||||
ostream.close();
|
||||
|
||||
std::string testFileInMissingnDir = testDir + "/newDir/uoFilesTest.txt";
|
||||
FS::Files::openOFStream(ostream, testFileInMissingnDir.c_str());
|
||||
OVT_ASSERT(!FS::Files::fileExists(testFileInMissingnDir.c_str()), "Failure to check for non-existing file");
|
||||
|
||||
std::ifstream istream;
|
||||
FS::Files::openIFStream(istream, testFile.c_str());
|
||||
OVT_ASSERT(istream.is_open(), "Failure to open file in an input stream");
|
||||
istream.close();
|
||||
|
||||
std::fstream fstream;
|
||||
FS::Files::openFStream(fstream, testFile.c_str(), std::ios_base::out);
|
||||
OVT_ASSERT(fstream.is_open(), "Failure to open file in a generic stream");
|
||||
fstream.close();
|
||||
|
||||
auto file = FS::Files::open(testFile.c_str(), "r");
|
||||
OVT_ASSERT(file != nullptr, "Failure to open file in a FILE object");
|
||||
|
||||
file = FS::Files::open(testFileInMissingnDir.c_str(), "r");
|
||||
OVT_ASSERT(file == nullptr, "Failure to return NULL FILE object for non-existing file");
|
||||
|
||||
testDir = outputDirectory + "uoFilesTest2/long spaced/path";
|
||||
FS::Files::createPath(testDir.c_str());
|
||||
OVT_ASSERT(FS::Files::directoryExists(testDir.c_str()), "Failure to create directory with path containing spaces");
|
||||
|
||||
// test equality
|
||||
|
||||
OVT_ASSERT(!FS::Files::equals(testFile.c_str(), testFileInMissingnDir.c_str()), "Failure to compare different files");
|
||||
OVT_ASSERT(FS::Files::equals(testFile.c_str(), testFile.c_str()), "Failure to compare same files");
|
||||
|
||||
|
||||
// test folder copy
|
||||
|
||||
std::string testFile2 = outputDirectory + "uoFilesTest" + "/uoFilesTestChild/uoFilesTest.txt";
|
||||
std::string testTargetDir = outputDirectory + "uoFilesTestCopy";
|
||||
std::string testTargetFile1 = testTargetDir + "/uoFilesTest.txt";
|
||||
std::string testTargetFile2 = testTargetDir + "/uoFilesTestChild/uoFilesTest.txt";
|
||||
// create a subfolder with file
|
||||
FS::Files::createParentPath(testFile2.c_str());
|
||||
std::ofstream ostream2;
|
||||
FS::Files::openOFStream(ostream2, testFile2.c_str());
|
||||
OVT_ASSERT(FS::Files::fileExists(testFile2.c_str()), "Failure to create file in subfolder");
|
||||
OVT_ASSERT(ostream2.is_open(), "Failure to open file");
|
||||
ostream2.close();
|
||||
// copy folder
|
||||
testDir = outputDirectory + "uoFilesTest";
|
||||
FS::Files::copyDirectory(testDir.c_str(), testTargetDir.c_str());
|
||||
OVT_ASSERT(FS::Files::directoryExists(testTargetDir.c_str()), "Failure in copying folder");
|
||||
OVT_ASSERT(FS::Files::fileExists(testTargetFile1.c_str()), "Failure in copying child files of the folder");
|
||||
OVT_ASSERT(FS::Files::fileExists(testTargetFile2.c_str()), "Failure in copying subfolder");
|
||||
// test folder copy on existing folder
|
||||
OVT_ASSERT(!FS::Files::copyDirectory(testDir.c_str(), testTargetDir.c_str()), "Failure: Copy should not have been done if folder exits");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
#include <fs/Files.h>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/version.hpp>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <m_ConverterUtf8.h>
|
||||
|
||||
#define TEMP_OUTPUT_DIR TMP_DIR "/オッペンヴィベ"
|
||||
#define TEMP_OUTPUT_DIR_COPY TMP_DIR "/オッペンヴィベ_Copy"
|
||||
#define TEMP_OUTPUT_ASCII_FILE_PATH TEMP_OUTPUT_DIR "/file.txt"
|
||||
#define TEMP_OUTPUT_UTF_FILE_PATH TEMP_OUTPUT_DIR "/日本語.txt"
|
||||
#define TEMP_OUTPUT_UTF_FILE_PATH_COPY TEMP_OUTPUT_DIR_COPY "/日本語.txt"
|
||||
#define TEMP_OUTPUT_ASCII_FILE_PATH_COPY TEMP_OUTPUT_DIR_COPY "/file.txt"
|
||||
|
||||
|
||||
#define TEST_ASCII_FILE_PATH DATA_DIR "/オッペンヴィベ/file.txt"
|
||||
#define TEST_UTF_FILE_PATH DATA_DIR "/オッペンヴィベ/日本語.txt"
|
||||
#define TEST_ASCII_DIR DATA_DIR "/オッペンヴィベ"
|
||||
|
||||
|
||||
TEST(FS_Files_Test_Directories_UTF, validateFileExists)
|
||||
{
|
||||
ASSERT_TRUE(FS::Files::fileExists(TEST_ASCII_FILE_PATH));
|
||||
ASSERT_TRUE(FS::Files::fileExists(TEST_UTF_FILE_PATH));
|
||||
ASSERT_FALSE(FS::Files::fileExists(DATA_DIR "/オッペンヴィベ/file"));
|
||||
ASSERT_FALSE(FS::Files::fileExists(DATA_DIR "/オッペンヴィベ/日本語"));
|
||||
}
|
||||
|
||||
TEST(FS_Files_Test_Directories_UTF, validateDirectoryExists)
|
||||
{
|
||||
ASSERT_FALSE(FS::Files::directoryExists(DATA_DIR "/inexistent"));
|
||||
ASSERT_TRUE(FS::Files::directoryExists(DATA_DIR "/オッペンヴィベ"));
|
||||
}
|
||||
|
||||
TEST(FS_Files_Test_Directories_UTF, validateGetParentPath)
|
||||
{
|
||||
char parentPath[1024];
|
||||
ASSERT_TRUE(FS::Files::getParentPath(TEST_ASCII_FILE_PATH, parentPath));
|
||||
ASSERT_STREQ(DATA_DIR "/オッペンヴィベ", parentPath);
|
||||
}
|
||||
|
||||
TEST(FS_Files_Test_Directories_UTF, validateGetFileName)
|
||||
{
|
||||
char fileName[1024];
|
||||
FS::Files::getFilename(TEST_ASCII_FILE_PATH, fileName);
|
||||
ASSERT_STREQ("file.txt", fileName);
|
||||
FS::Files::getFilename(TEST_UTF_FILE_PATH, fileName);
|
||||
ASSERT_STREQ("日本語.txt", fileName);
|
||||
}
|
||||
|
||||
TEST(FS_Files_Test_Directories_UTF, validateGetFileNameWithoutExtension)
|
||||
{
|
||||
char fileName[1024];
|
||||
FS::Files::getFilenameWithoutExtension(TEST_ASCII_FILE_PATH, fileName);
|
||||
ASSERT_STREQ("file", fileName);
|
||||
FS::Files::getFilenameWithoutExtension(TEST_UTF_FILE_PATH, fileName);
|
||||
ASSERT_STREQ("日本語", fileName);
|
||||
}
|
||||
|
||||
TEST(FS_Files_Test_Directories_UTF, validateGetFileNameExtension)
|
||||
{
|
||||
char extension[1024];
|
||||
FS::Files::getFilenameExtension(TEST_ASCII_FILE_PATH, extension);
|
||||
ASSERT_STREQ(".txt", extension);
|
||||
FS::Files::getFilenameExtension(TEST_UTF_FILE_PATH, extension);
|
||||
ASSERT_STREQ(".txt", extension);
|
||||
}
|
||||
|
||||
TEST(FS_Files_Test_Directories_UTF, validateCreatePath)
|
||||
{
|
||||
FS::Files::removeAll(TEMP_OUTPUT_DIR);
|
||||
ASSERT_FALSE(FS::Files::directoryExists(TEMP_OUTPUT_DIR));
|
||||
ASSERT_TRUE(FS::Files::createPath(TEMP_OUTPUT_DIR));
|
||||
ASSERT_TRUE(FS::Files::directoryExists(TEMP_OUTPUT_DIR));
|
||||
}
|
||||
|
||||
TEST(FS_Files_Test_Directories_UTF, validateCreateParentPath)
|
||||
{
|
||||
FS::Files::removeAll(TEMP_OUTPUT_DIR);
|
||||
ASSERT_FALSE(FS::Files::directoryExists(TEMP_OUTPUT_DIR));
|
||||
ASSERT_TRUE(FS::Files::createParentPath(TEMP_OUTPUT_DIR "/file.txt"));
|
||||
ASSERT_TRUE(FS::Files::directoryExists(TEMP_OUTPUT_DIR));
|
||||
}
|
||||
|
||||
#if BOOST_VERSION / 100 % 1000 >= 55
|
||||
TEST(FS_Files_Test_Directories_UTF, validateCopyFile)
|
||||
{
|
||||
FS::Files::removeAll(TEMP_OUTPUT_ASCII_FILE_PATH);
|
||||
FS::Files::createParentPath(TEMP_OUTPUT_ASCII_FILE_PATH);
|
||||
|
||||
ASSERT_TRUE(FS::Files::copyFile(TEST_ASCII_FILE_PATH, TEMP_OUTPUT_ASCII_FILE_PATH));
|
||||
ASSERT_TRUE(FS::Files::fileExists(TEMP_OUTPUT_ASCII_FILE_PATH));
|
||||
}
|
||||
|
||||
TEST(FS_Files_Test_Directories_UTF, validateCopyDirectory)
|
||||
{
|
||||
ASSERT_TRUE(FS::Files::copyDirectory(TEST_ASCII_DIR, TEMP_OUTPUT_DIR_COPY));
|
||||
ASSERT_TRUE(FS::Files::fileExists(TEMP_OUTPUT_UTF_FILE_PATH_COPY));
|
||||
ASSERT_TRUE(FS::Files::fileExists(TEMP_OUTPUT_ASCII_FILE_PATH_COPY));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int uoFSFilesTestUTF(int argc, char* argv[])
|
||||
{
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
|
||||
::testing::GTEST_FLAG(filter) = "FS_Files_Test_Directories_UTF.*";
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
Reference in New Issue
Block a user