Skip to content

Commit

Permalink
iox-eclipse-iceoryx#1942 Implement and test FilePath
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Eltzschig <[email protected]>
  • Loading branch information
elfenpiff committed Mar 31, 2023
1 parent 94d410d commit e50fbfa
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 2 deletions.
1 change: 0 additions & 1 deletion iceoryx_hoofs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ iox_add_library(
posix/time/source/adaptive_wait.cpp
posix/time/source/deadline_timer.cpp
posix/vocabulary/source/user_name.cpp
posix/vocabulary/source/group_name.cpp
posix/vocabulary/source/file_name.cpp
posix/vocabulary/source/file_path.cpp
posix/vocabulary/source/path.cpp
Expand Down
63 changes: 63 additions & 0 deletions iceoryx_hoofs/posix/vocabulary/source/file_path.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) 2023 by Apex.AI Inc. 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.
//
// SPDX-License-Identifier: Apache-2.0

#include "iox/file_path.hpp"
#include "iox/filesystem.hpp"

namespace iox
{
namespace details
{
bool file_path_does_contain_invalid_characters(const string<platform::IOX_MAX_PATH_LENGTH>& value) noexcept
{
const auto valueSize = value.size();

for (uint64_t i{0}; i < valueSize; ++i)
{
// AXIVION Next Construct AutosarC++19_03-A3.9.1: Not used as an integer but as actual character
const char c{value[i]};

const bool isSmallLetter{'a' <= c && c <= 'z'};
const bool isCapitalLetter{'A' <= c && c <= 'Z'};
const bool isNumber{'0' <= c && c <= '9'};
const bool isSpecialCharacter{c == '-' || c == '.' || c == ':' || c == '_'};
const bool isPathSeparator{[&] {
for (const auto separator : platform::IOX_PATH_SEPARATORS)
{
if (c == separator)
{
return true;
}
}
return false;
}()};

if ((!isSmallLetter && !isCapitalLetter) && (!isNumber && !isSpecialCharacter) && !isPathSeparator)
{
return true;
}
}

return false;
}

bool file_path_does_contain_invalid_content(const string<platform::IOX_MAX_PATH_LENGTH>& value) noexcept
{
return !isValidPathToFile(value);
}
} // namespace details
} // namespace iox

Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "iceoryx_hoofs/testing/fatal_failure.hpp"
#include "iceoryx_platform/platform_settings.hpp"
#include "iox/file_name.hpp"
#include "iox/file_path.hpp"
#include "iox/group_name.hpp"
#include "iox/semantic_string.hpp"
#include "iox/user_name.hpp"
Expand Down Expand Up @@ -127,6 +128,46 @@ const std::string TestValues<FileName>::MAX_CAPACITY_VALUE{std::string(platform:
// END: FileName
///////////////////

///////////////////
// START: FilePath
///////////////////
template <>
const uint64_t TestValues<FilePath>::CAPACITY = platform::IOX_MAX_PATH_LENGTH;
template <>
const std::vector<std::string> TestValues<FilePath>::VALID_VALUES{{"file"},
{"another_file.bla"},
{"123.456"},
{".hidden_me"},
{"/some/file/path"},
{"./relative/path"},
{"another/../../relative/path"},
{"another/../...bla"},
{"not/yet/another/path/../fuu"}};
template <>
const std::vector<std::string> TestValues<FilePath>::INVALID_CHARACTER_VALUES{{"some-!user"},
{"*kasjd"},
{"$_fuuuas"},
{";'1'fuuuu"},
{"so*me/path/to/."},
{"/some/pa)th/to/."},
{"another/relative/pa]th/at/the/end/.."}};
template <>
const std::vector<std::string> TestValues<FilePath>::INVALID_CONTENT_VALUES{
{""}, {"."}, {".."}, {"stop/with/relative/.."}, "another/relative/part/at/the/end/."};
template <>
const std::vector<std::string> TestValues<FilePath>::TOO_LONG_CONTENT_VALUES{
std::string(platform::IOX_MAX_PATH_LENGTH + 2, 'a')};
template <>
const std::string TestValues<FilePath>::GREATER_VALID_VALUE{"9-i-am-a-file"};
template <>
const std::string TestValues<FilePath>::SMALLER_VALID_VALUE{"0.me.too.be.file"};
template <>
const std::string TestValues<FilePath>::MAX_CAPACITY_VALUE{std::string(platform::IOX_MAX_PATH_LENGTH, 'b')};
///////////////////
// END: FilePath
///////////////////


template <typename T>
class SemanticString_test : public Test
{
Expand Down Expand Up @@ -154,7 +195,7 @@ class SemanticString_test : public Test
SutType smaller_value = SutType::create(smaller_value_str).expect("Failed to create test string.");
};

using Implementations = Types<UserName, FileName, GroupName>;
using Implementations = Types<UserName, FileName, GroupName, FilePath>;

TYPED_TEST_SUITE(SemanticString_test, Implementations, );

Expand Down

0 comments on commit e50fbfa

Please sign in to comment.