[DEV] uri provider work correctly
This commit is contained in:
parent
6cd2c7414e
commit
693cd83ce9
@ -40,7 +40,7 @@ etk::archive::Zip::Zip(const etk::Path& _fileName, uint64_t _offset) :
|
||||
if(tmpFileName[strlen(tmpFileName) - 1] == '/' ) {
|
||||
// find directory ...
|
||||
} else {
|
||||
TK_INFO("find file : " << tmpFileName);
|
||||
TK_VERBOSE("find file : " << tmpFileName);
|
||||
m_content.set(etk::Path(tmpFileName), ememory::makeShared<etk::ArchiveContent>(tmpFileInfo.uncompressed_size));
|
||||
}
|
||||
/* Go the the next entry listed in the zip file. */
|
||||
@ -84,7 +84,7 @@ etk::archive::Zip::Zip(const etk::Uri& _uri) :
|
||||
if(tmpFileName[strlen(tmpFileName) - 1] == '/' ) {
|
||||
// find directory ...
|
||||
} else {
|
||||
TK_INFO("find file : " << tmpFileName);
|
||||
TK_VERBOSE("find file : " << tmpFileName);
|
||||
m_content.set(etk::Path(tmpFileName), ememory::makeShared<etk::ArchiveContent>(tmpFileInfo.uncompressed_size));
|
||||
}
|
||||
/* Go the the next entry listed in the zip file. */
|
||||
|
@ -19,7 +19,7 @@ etk::io::ZipFile::ZipFile(const etk::Path& _path, ememory::SharedPtr<etk::Archiv
|
||||
|
||||
bool etk::io::ZipFile::open(etk::io::OpenMode _mode) {
|
||||
if (m_content != null) {
|
||||
TK_CRITICAL("File Already open : " << m_path);
|
||||
TK_CRITICAL("File Already open: " << m_path);
|
||||
return true;
|
||||
}
|
||||
if (m_archive == null) {
|
||||
@ -32,11 +32,11 @@ bool etk::io::ZipFile::open(etk::io::OpenMode _mode) {
|
||||
return false;
|
||||
}
|
||||
m_content = m_archive->getContent(m_path);
|
||||
if (m_content != null) {
|
||||
return true;
|
||||
if (m_content == null) {
|
||||
return false;
|
||||
}
|
||||
m_archive->open(m_path);
|
||||
return false;
|
||||
return true;
|
||||
case etk::io::OpenMode::Write:
|
||||
return false;
|
||||
case etk::io::OpenMode::Append:
|
||||
|
@ -161,6 +161,14 @@ bool etk::uri::Query::operator< (const etk::uri::Query& _obj) const {
|
||||
return getEncoded() < _obj.getEncoded();
|
||||
}
|
||||
|
||||
bool etk::uri::Query::operator<= (const etk::uri::Query& _obj) const {
|
||||
return getEncoded() <= _obj.getEncoded();
|
||||
}
|
||||
|
||||
bool etk::uri::Query::operator> (const etk::uri::Query& _obj) const {
|
||||
return getEncoded() > _obj.getEncoded();
|
||||
}
|
||||
|
||||
bool etk::uri::Query::operator>= (const etk::uri::Query& _obj) const {
|
||||
return getEncoded() >= _obj.getEncoded();
|
||||
}
|
||||
|
@ -91,17 +91,29 @@ namespace etk {
|
||||
*/
|
||||
bool operator!= (const etk::uri::Query& _obj) const;
|
||||
/**
|
||||
* @brief check if this elemnt is greater than the other.
|
||||
* @brief check if this elemnt is lesser than the other.
|
||||
* @param[in] _obj Query to compare.
|
||||
* @return true : less Query, false otherwise.
|
||||
*/
|
||||
bool operator< (const etk::uri::Query& _obj) const;
|
||||
/**
|
||||
* @brief check if this elemnt is lesser or equal than the other.
|
||||
* @param[in] _obj Query to compare.
|
||||
* @return true : less Query, false otherwise.
|
||||
*/
|
||||
bool operator<= (const etk::uri::Query& _obj) const;
|
||||
/**
|
||||
* @brief Check if this elemnt is greater than the other.
|
||||
* @param[in] _obj Query to compare.
|
||||
* @return false : Greater Query, true otherwise.
|
||||
*/
|
||||
bool operator> (const etk::uri::Query& _obj) const;
|
||||
/**
|
||||
* @brief Check if this elemnt is greater or equal than the other.
|
||||
* @param[in] _obj Query to compare.
|
||||
* @return false : Greater Query, true otherwise.
|
||||
*/
|
||||
bool operator>= (const etk::uri::Query& _obj) const;
|
||||
};
|
||||
}
|
||||
//! @not_in_doc
|
||||
|
@ -75,6 +75,16 @@ bool etk::Uri::operator!= (const etk::Uri& _obj) const {
|
||||
|| m_fragment != _obj.m_fragment;
|
||||
}
|
||||
bool etk::Uri::operator< (const etk::Uri& _obj) const {
|
||||
/*
|
||||
TK_WARNING("compare m_scheme =" << m_scheme << " " << ( m_scheme < _obj.m_scheme?"<":">=") << " " << _obj.m_scheme);
|
||||
TK_WARNING("compare m_user =" << m_user << " " << ( m_user < _obj.m_user?"<":">=") << " " << _obj.m_user);
|
||||
TK_WARNING("compare m_password =" << m_password << " " << ( m_password < _obj.m_password?"<":">=") << " " << _obj.m_password);
|
||||
TK_WARNING("compare m_server =" << m_server << " " << ( m_server < _obj.m_server?"<":">=") << " " << _obj.m_server);
|
||||
TK_WARNING("compare m_port =" << m_port << " " << ( m_port < _obj.m_port?"<":">=") << " " << _obj.m_port);
|
||||
TK_WARNING("compare m_path =" << m_path << " " << ( m_path < _obj.m_path?"<":">=") << " " << _obj.m_path);
|
||||
TK_WARNING("compare m_query =" << m_query << " " << ( m_query < _obj.m_query?"<":">=") << " " << _obj.m_query);
|
||||
TK_WARNING("compare m_fragment =" << m_fragment << " " << ( m_fragment < _obj.m_fragment?"<":">=") << " " << _obj.m_fragment);
|
||||
*/
|
||||
return m_scheme < _obj.m_scheme
|
||||
&& m_user < _obj.m_user
|
||||
&& m_password < _obj.m_password
|
||||
@ -84,6 +94,18 @@ bool etk::Uri::operator< (const etk::Uri& _obj) const {
|
||||
&& m_query < _obj.m_query
|
||||
&& m_fragment < _obj.m_fragment;
|
||||
}
|
||||
|
||||
bool etk::Uri::operator<= (const etk::Uri& _obj) const {
|
||||
return m_scheme <= _obj.m_scheme
|
||||
&& m_user <= _obj.m_user
|
||||
&& m_password <= _obj.m_password
|
||||
&& m_server <= _obj.m_server
|
||||
&& m_port <= _obj.m_port
|
||||
&& m_path <= _obj.m_path
|
||||
&& m_query <= _obj.m_query
|
||||
&& m_fragment <= _obj.m_fragment;
|
||||
}
|
||||
|
||||
bool etk::Uri::operator> (const etk::Uri& _obj) const {
|
||||
return m_scheme > _obj.m_scheme
|
||||
&& m_user > _obj.m_user
|
||||
@ -95,6 +117,17 @@ bool etk::Uri::operator> (const etk::Uri& _obj) const {
|
||||
&& m_fragment > _obj.m_fragment;
|
||||
}
|
||||
|
||||
bool etk::Uri::operator>= (const etk::Uri& _obj) const {
|
||||
return m_scheme >= _obj.m_scheme
|
||||
&& m_user >= _obj.m_user
|
||||
&& m_password >= _obj.m_password
|
||||
&& m_server >= _obj.m_server
|
||||
&& m_port >= _obj.m_port
|
||||
&& m_path >= _obj.m_path
|
||||
&& m_query >= _obj.m_query
|
||||
&& m_fragment >= _obj.m_fragment;
|
||||
}
|
||||
|
||||
void etk::Uri::set(etk::String _value) {
|
||||
TK_VERBOSE("parse: '" << _value << "'");
|
||||
size_t pos = _value.find("://");
|
||||
@ -252,3 +285,16 @@ const etk::String& etk::Uri::getFragment() const {
|
||||
void etk::Uri::setFragment(const etk::String& _value) {
|
||||
m_fragment = _value;
|
||||
}
|
||||
|
||||
void etk::Uri::display() const {
|
||||
TK_PRINT("Display of an URI:");
|
||||
TK_PRINT(" m_scheme = '" << m_scheme << "'");
|
||||
TK_PRINT(" m_user = '" << m_user << "'");
|
||||
TK_PRINT(" m_password = '" << m_password << "'");
|
||||
TK_PRINT(" m_server = '" << m_server << "'");
|
||||
TK_PRINT(" m_port = '" << m_port << "'");
|
||||
TK_PRINT(" m_path = '" << m_path << "'");
|
||||
TK_PRINT(" m_query = '" << m_query << "'");
|
||||
TK_PRINT(" m_fragment = '" << m_fragment << "'");
|
||||
}
|
||||
|
||||
|
@ -167,17 +167,33 @@ namespace etk {
|
||||
*/
|
||||
bool operator!= (const etk::Uri& _obj) const;
|
||||
/**
|
||||
* @brief check if this elemnt is greater than the other.
|
||||
* @brief check if this elemnt is lower than the other.
|
||||
* @param[in] _obj Uri to compare.
|
||||
* @return true : less Uri, false otherwise.
|
||||
*/
|
||||
bool operator< (const etk::Uri& _obj) const;
|
||||
/**
|
||||
* @brief check if this elemnt is lower or equal than the other.
|
||||
* @param[in] _obj Uri to compare.
|
||||
* @return true : less Uri, false otherwise.
|
||||
*/
|
||||
bool operator<= (const etk::Uri& _obj) const;
|
||||
/**
|
||||
* @brief Check if this elemnt is greater than the other.
|
||||
* @param[in] _obj Uri to compare.
|
||||
* @return false : Greater Uri, true otherwise.
|
||||
*/
|
||||
bool operator> (const etk::Uri& _obj) const;
|
||||
/**
|
||||
* @brief Check if this elemnt is greater or equal than the other.
|
||||
* @param[in] _obj Uri to compare.
|
||||
* @return false : Greater Uri, true otherwise.
|
||||
*/
|
||||
bool operator>= (const etk::Uri& _obj) const;
|
||||
/**
|
||||
* @brief Detail display of this element
|
||||
*/
|
||||
void display() const;
|
||||
};
|
||||
//! @not_in_doc
|
||||
etk::Stream& operator <<(etk::Stream& _os, const etk::Uri& _obj);
|
||||
|
@ -43,7 +43,7 @@ etk::Vector<etk::Uri> etk::uri::provider::ProviderFile::list(const etk::Uri& _ur
|
||||
}
|
||||
return out;
|
||||
}
|
||||
TK_ERROR("list path: " << m_offset / _uri.getPath());
|
||||
TK_VERBOSE("list path: " << m_offset / _uri.getPath());
|
||||
tmp = etk::fs::list(m_offset / _uri.getPath());
|
||||
int32_t offset = m_offset.getString().size()+1;
|
||||
for (auto& elem: tmp) {
|
||||
|
@ -11,7 +11,6 @@ void etk::uri::provider::ProviderFileZip::loadZipFile(const etk::Uri& _zipFile)
|
||||
m_archive = etk::Archive::load(_zipFile);
|
||||
TK_ASSERT(m_archive != null, "Error loading APK ... '" << _zipFile << "'");
|
||||
#ifdef DEBUG
|
||||
//Just for debug, print APK contents
|
||||
m_archive->display();
|
||||
#endif
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ def configure(target, my_module):
|
||||
])
|
||||
|
||||
my_module.add_header_file([
|
||||
'etk-core/algorithm.hpp',
|
||||
'etk-core/Allocator.hpp',
|
||||
'etk-core/types.hpp',
|
||||
'etk-core/stdTools.hpp',
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <etk/uri/provider/ProviderFile.hpp>
|
||||
#include <etk/uri/provider/ProviderFileZip.hpp>
|
||||
#include <etk/fs/fileSystem.hpp>
|
||||
#include <etk/algorithm.hpp>
|
||||
|
||||
|
||||
|
||||
@ -86,43 +87,15 @@ TEST(TestUriProvider, checkPlouf) {
|
||||
}
|
||||
|
||||
etk::Vector<etk::Uri> listDirect = {
|
||||
"DATA:///filePresent.txt",
|
||||
"DATA:///fileEmpty.txt",
|
||||
"DATA:///data",
|
||||
"DATA:///data_sample.zip",
|
||||
"DATA:///fileEmpty.txt",
|
||||
"DATA:///filePresent.txt",
|
||||
};
|
||||
|
||||
/* This function takes last element as pivot, places
|
||||
the pivot element at its correct position in sorted
|
||||
array, and places all smaller (smaller than pivot)
|
||||
to left of pivot and all greater elements to right
|
||||
of pivot */
|
||||
int_t partition (etk::Vector<etk::Uri>& _data, int _low, int _high) {
|
||||
int_t iii = (_low - 1); // Index of smaller element
|
||||
for (int_t jjj = _low; jjj < _high; ++jjj) {
|
||||
// If current element is smaller than or equal to pivot
|
||||
if (_data[jjj] < _data[_high]) {
|
||||
iii++; // increment index of smaller element
|
||||
etk::swap(_data[iii], _data[jjj]);
|
||||
}
|
||||
}
|
||||
etk::swap(_data[iii + 1], _data[_high]);
|
||||
return (iii + 1);
|
||||
}
|
||||
|
||||
/* The main function that implements QuickSort
|
||||
arr[] --> Array to be sorted,
|
||||
low --> Starting index,
|
||||
high --> Ending index */
|
||||
void quickSort(etk::Vector<etk::Uri>& _data, int _low, int _high) {
|
||||
if (_low >= _high) {
|
||||
return;
|
||||
}
|
||||
// pi is partitioning index, arr[p] is now at right place
|
||||
int_t pi = partition(_data, _low, _high);
|
||||
// Separately sort elements before partition and after partition
|
||||
quickSort(_data, _low, pi - 1);
|
||||
quickSort(_data, pi + 1, _high);
|
||||
bool uriSortCallback(const etk::Uri& _left, const etk::Uri& _right) {
|
||||
TEST_VERBOSE("compare " << _left << " " << (_left <= _right?"<=":">") << " " << _right);
|
||||
return _left <= _right;
|
||||
}
|
||||
|
||||
TEST(TestUriProvider, checkDirectAccess) {
|
||||
@ -134,27 +107,21 @@ TEST(TestUriProvider, checkDirectAccess) {
|
||||
EXPECT_NE(provider, null);
|
||||
etk::Uri searchBase("DATA:///");
|
||||
auto elems = provider->list(searchBase);
|
||||
TEST_WARNING("List DATA path: (A)");
|
||||
TEST_VERBOSE("List DATA path: (A)");
|
||||
for (auto& it: elems) {
|
||||
TEST_WARNING(" " << it);
|
||||
TEST_VERBOSE(" " << it);
|
||||
}
|
||||
elems.sort(0, elems.size(), [] (const etk::Uri& _left, const etk::Uri& _right) {
|
||||
TEST_WARNING("compare " << _left << " " << (_left < _right?"<":">=") << " " << _right);
|
||||
|
||||
return _left < _right;
|
||||
});
|
||||
TEST_WARNING("List DATA path: (B)");
|
||||
etk::algorithm::quickSort(elems, uriSortCallback);
|
||||
TEST_VERBOSE("List DATA path: (C)");
|
||||
for (auto& it: elems) {
|
||||
TEST_WARNING(" " << it);
|
||||
TEST_VERBOSE(" " << it);
|
||||
}
|
||||
quickSort(elems, 0, elems.size()-1);
|
||||
TEST_WARNING("List DATA path: (C)");
|
||||
for (auto& it: elems) {
|
||||
TEST_WARNING(" " << it);
|
||||
TEST_VERBOSE("List corect order:");
|
||||
for (auto& it: listDirect) {
|
||||
TEST_VERBOSE(" " << it);
|
||||
}
|
||||
EXPECT_EQ(elems, listDirect);
|
||||
}
|
||||
|
||||
etk::Vector<etk::Uri> listDirect2 = {
|
||||
"DATA:///data/.file_hidden.txt",
|
||||
"DATA:///data/dir_A",
|
||||
@ -174,20 +141,50 @@ TEST(TestUriProvider, checkDirectAccess2) {
|
||||
etk::Uri searchBase("DATA:///data");
|
||||
|
||||
auto elems = provider->list(searchBase);
|
||||
TEST_WARNING("List DATA path: (A)");
|
||||
TEST_VERBOSE("List DATA path: (A)");
|
||||
for (auto& it: elems) {
|
||||
TEST_WARNING(" " << it);
|
||||
TEST_VERBOSE(" " << it);
|
||||
}
|
||||
elems.sort(0, elems.size(), [] (const etk::Uri& _left, const etk::Uri& _right) {
|
||||
return _left < _right;
|
||||
});
|
||||
TEST_WARNING("List DATA path: (B)");
|
||||
etk::algorithm::quickSort(elems, uriSortCallback);
|
||||
TEST_VERBOSE("List DATA path: (B)");
|
||||
for (auto& it: elems) {
|
||||
TEST_WARNING(" " << it);
|
||||
TEST_VERBOSE(" " << it);
|
||||
}
|
||||
EXPECT_EQ(elems, listDirect2);
|
||||
}
|
||||
|
||||
TEST(TestUriProvider, directExistFile) {
|
||||
etk::uri::provider::clear();
|
||||
TEST_VERBOSE("data path: " << etk::fs::getDataPath());
|
||||
etk::uri::provider::add("DATA", ememory::makeShared<etk::uri::provider::ProviderFile>(etk::fs::getDataPath()));
|
||||
EXPECT_EQ(etk::uri::provider::exist("DATA"), true);
|
||||
ememory::SharedPtr<etk::uri::provider::Interface> provider = etk::uri::provider::getProvider("DATA");
|
||||
EXPECT_NE(provider, null);
|
||||
{
|
||||
etk::Uri element("DATA:///data/dir_B/file_B_1.txt");
|
||||
EXPECT_EQ(provider->exist(element), true);
|
||||
}
|
||||
{
|
||||
etk::Uri element("DATA:///data/dir_B/file_B_1_qsldkjfqlksjd.txt");
|
||||
EXPECT_EQ(provider->exist(element), false);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(TestUriProvider, directReadFile) {
|
||||
etk::uri::provider::clear();
|
||||
TEST_VERBOSE("data path: " << etk::fs::getDataPath());
|
||||
etk::uri::provider::add("DATA", ememory::makeShared<etk::uri::provider::ProviderFile>(etk::fs::getDataPath()));
|
||||
EXPECT_EQ(etk::uri::provider::exist("DATA"), true);
|
||||
etk::Uri element("DATA:///data/dir_B/file_B_1.txt");
|
||||
ememory::SharedPtr<etk::io::Interface> ioElement = etk::uri::provider::get(element);
|
||||
EXPECT_EQ(ioElement->open(etk::io::OpenMode::Read), true);
|
||||
etk::String data = ioElement->readAllString();
|
||||
EXPECT_EQ(ioElement->close(), true);
|
||||
EXPECT_EQ(data, "file_B_1.txt");
|
||||
}
|
||||
|
||||
|
||||
|
||||
etk::Vector<etk::Uri> listZip = {
|
||||
"DATA:///.file_hidden.txt",
|
||||
"DATA:///dir_A",
|
||||
@ -204,11 +201,11 @@ TEST(TestUriProvider, checkZipAccess) {
|
||||
EXPECT_EQ(etk::uri::provider::exist("DATA"), true);
|
||||
ememory::SharedPtr<etk::uri::provider::Interface> provider = etk::uri::provider::getProvider("DATA");
|
||||
EXPECT_NE(provider, null);
|
||||
TEST_WARNING("List DATA path:");
|
||||
TEST_VERBOSE("List DATA path:");
|
||||
etk::Uri searchBase("DATA://");
|
||||
auto elems = provider->list(searchBase);
|
||||
for (auto& it: elems) {
|
||||
TEST_WARNING(" " << it);
|
||||
TEST_VERBOSE(" " << it);
|
||||
}
|
||||
EXPECT_EQ(elems, listZip);
|
||||
}
|
||||
@ -227,12 +224,43 @@ TEST(TestUriProvider, checkZipAccess2) {
|
||||
EXPECT_EQ(etk::uri::provider::exist("DATA"), true);
|
||||
ememory::SharedPtr<etk::uri::provider::Interface> provider = etk::uri::provider::getProvider("DATA");
|
||||
EXPECT_NE(provider, null);
|
||||
TEST_WARNING("List DATA path:");
|
||||
TEST_VERBOSE("List DATA path:");
|
||||
etk::Uri searchBase("DATA:///dir_B");
|
||||
auto elems = provider->list(searchBase);
|
||||
for (auto& it: elems) {
|
||||
TEST_WARNING(" " << it);
|
||||
TEST_VERBOSE(" " << it);
|
||||
}
|
||||
EXPECT_EQ(elems, listZip2);
|
||||
}
|
||||
|
||||
|
||||
TEST(TestUriProvider, zipExistFile) {
|
||||
etk::uri::provider::clear();
|
||||
TEST_VERBOSE("data path: " << etk::fs::getDataPath());
|
||||
etk::uri::provider::add("DATA", ememory::makeShared<etk::uri::provider::ProviderFileZip>(etk::fs::getDataPath() / "data_sample.zip", "data"));
|
||||
EXPECT_EQ(etk::uri::provider::exist("DATA"), true);
|
||||
ememory::SharedPtr<etk::uri::provider::Interface> provider = etk::uri::provider::getProvider("DATA");
|
||||
EXPECT_NE(provider, null);
|
||||
{
|
||||
etk::Uri element("DATA:///dir_B/file_B_1.txt");
|
||||
EXPECT_EQ(provider->exist(element), true);
|
||||
}
|
||||
{
|
||||
etk::Uri element("DATA:///dir_B/file_B_1_qsldkjfqlksjd.txt");
|
||||
EXPECT_EQ(provider->exist(element), false);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(TestUriProvider, zipReadFile) {
|
||||
etk::uri::provider::clear();
|
||||
TEST_VERBOSE("data path: " << etk::fs::getDataPath());
|
||||
etk::uri::provider::add("DATA", ememory::makeShared<etk::uri::provider::ProviderFileZip>(etk::fs::getDataPath() / "data_sample.zip", "data"));
|
||||
EXPECT_EQ(etk::uri::provider::exist("DATA"), true);
|
||||
etk::Uri element("DATA:///dir_B/file_B_1.txt");
|
||||
ememory::SharedPtr<etk::io::Interface> ioElement = etk::uri::provider::get(element);
|
||||
EXPECT_EQ(ioElement->open(etk::io::OpenMode::Read), true);
|
||||
etk::String data = ioElement->readAllString();
|
||||
EXPECT_EQ(ioElement->close(), true);
|
||||
EXPECT_EQ(data, "file_B_1.txt");
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user