Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#include <filesystem>
 
#include "gtest/gtest.h"
 
#include "core/common/path_utils.h"
#include "test/util/include/temp_dir.h"
 
namespace onnxruntime {
namespace test {
 
TEST(PathUtilsTest, GetDirOrParentPath) {
  TemporaryDirectory temp_dir{ORT_TSTR("path_utils_test")};
  const std::filesystem::path directory{temp_dir.Path()};
 
  EXPECT_TRUE(path_utils::GetDirOrParentPath({}).empty());
  EXPECT_EQ(path_utils::GetDirOrParentPath(directory), directory);
  EXPECT_EQ(path_utils::GetDirOrParentPath(directory / "model.onnx"), directory);
}
 
TEST(PathUtilsTest, GetPathWithStemSuffix) {
  TemporaryDirectory temp_dir{ORT_TSTR("path_utils_test")};
  const std::filesystem::path directory{temp_dir.Path()};
  const std::string directory_string = PathToUTF8String(directory.native());
  const std::filesystem::path explicit_path = directory / "custom_context.onnx";
  const std::string explicit_path_string = PathToUTF8String(explicit_path.native());
 
  EXPECT_EQ(path_utils::GetPathWithStemSuffix("", "model.onnx", "_ctx.onnx"), "model_ctx.onnx");
  EXPECT_EQ(path_utils::GetPathWithStemSuffix("", "model.v1.onnx", "_ctx.onnx"), "model.v1_ctx.onnx");
  EXPECT_EQ(path_utils::GetPathWithStemSuffix(explicit_path_string, "model.onnx", "_ctx.onnx"),
            explicit_path_string);
  EXPECT_EQ(path_utils::GetPathWithStemSuffix(directory_string, "model.onnx", "_ctx.onnx"),
            (directory / "model_ctx.onnx").string());
}
 
TEST(PathUtilsTest, IsAbsolutePath) {
  const std::filesystem::path absolute_path = std::filesystem::absolute("cache");
 
  EXPECT_TRUE(path_utils::IsAbsolutePath(PathToUTF8String(absolute_path.native())));
  EXPECT_FALSE(path_utils::IsAbsolutePath("cache/engine"));
  EXPECT_FALSE(path_utils::IsAbsolutePath(""));
}
 
TEST(PathUtilsTest, IsRelativePathToParentPath) {
  EXPECT_TRUE(path_utils::IsRelativePathToParentPath("../cache"));
#ifdef _WIN32
  EXPECT_FALSE(path_utils::IsRelativePathToParentPath("cache/../engine"));
#else
  EXPECT_TRUE(path_utils::IsRelativePathToParentPath("cache/../engine"));
#endif
  EXPECT_TRUE(path_utils::IsRelativePathToParentPath("cache..engine"));
  EXPECT_FALSE(path_utils::IsRelativePathToParentPath("cache/engine"));
  EXPECT_FALSE(path_utils::IsRelativePathToParentPath(""));
}
 
}  // namespace test
}  // namespace onnxruntime