-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathutil.cpp
More file actions
77 lines (57 loc) · 1.94 KB
/
util.cpp
File metadata and controls
77 lines (57 loc) · 1.94 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "core/util/include/util.hpp"
#include <gtest/gtest.h>
#include <libenvpp/detail/get.hpp>
#include <string_view>
#include "omp.h"
namespace my::nested {
struct Type {};
} // namespace my::nested
TEST(util_tests, extracts_correct_namespace) {
constexpr std::string_view kNs = ppc::util::GetNamespace<my::nested::Type>();
EXPECT_EQ(kNs, "my::nested");
}
TEST(util_tests, threads_control_check_openmp_disabled_valgrind) {
const auto num_threads_env_var = env::get<int>("PPC_NUM_THREADS");
EXPECT_EQ(ppc::util::GetNumThreads(), omp_get_max_threads());
}
namespace test_ns {
struct TypeInNamespace {};
} // namespace test_ns
struct PlainType {};
TEST(GetNamespaceTest, ReturnsExpectedNamespace) {
constexpr auto kNs = ppc::util::GetNamespace<test_ns::TypeInNamespace>();
EXPECT_EQ(kNs, "test_ns");
}
TEST(GetNamespaceTest, ReturnsEmptyIfNoNamespace_PrimitiveType) {
constexpr auto kNs = ppc::util::GetNamespace<int>();
EXPECT_EQ(kNs, "");
}
TEST(GetNamespaceTest, ReturnsEmptyIfNoNamespace_PlainStruct) {
constexpr auto kNs = ppc::util::GetNamespace<PlainType>();
EXPECT_EQ(kNs, "");
}
namespace test_ns {
struct Nested {};
} // namespace test_ns
TEST(GetNamespaceTest, ReturnsNamespaceCorrectly) {
constexpr auto kNs = ppc::util::GetNamespace<test_ns::Nested>();
EXPECT_EQ(kNs, "test_ns");
}
struct NoNamespaceType {};
TEST(GetNamespaceTest, NoNamespaceInType) {
constexpr auto kNs = ppc::util::GetNamespace<NoNamespaceType>();
EXPECT_EQ(kNs, "");
}
template <typename T>
struct NotATemplate {};
TEST(GetNamespaceTest, NoKeyInPrettyFunction) {
constexpr auto kNs = ppc::util::GetNamespace<NotATemplate<void>>();
EXPECT_EQ(kNs, "");
}
namespace crazy {
struct VeryLongTypeNameWithOnlyLettersAndUnderscores {};
} // namespace crazy
TEST(GetNamespaceTest, NoTerminatorCharactersInPrettyFunction) {
constexpr auto kNs = ppc::util::GetNamespace<crazy::VeryLongTypeNameWithOnlyLettersAndUnderscores>();
EXPECT_EQ(kNs, "crazy");
}