1//===-- TestTypeSystem.cpp -------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "TestingSupport/SubsystemRAII.h"
10#include "lldb/Core/Module.h"
11#include "lldb/Host/FileSystem.h"
12#include "lldb/Host/HostInfo.h"
13#include "lldb/Symbol/TypeSystem.h"
14#include "gtest/gtest.h"
15
16using namespace lldb;
17using namespace lldb_private;
18
19class TestTypeSystemMap : public testing::Test {
20public:
21 SubsystemRAII<FileSystem, HostInfo> subsystems;
22};
23
24TEST_F(TestTypeSystemMap, GetTypeSystemForLanguageWithInvalidModule) {
25 // GetTypeSystemForLanguage called with an invalid Module.
26 TypeSystemMap map;
27 Module module{ModuleSpec()};
28 EXPECT_THAT_EXPECTED(
29 map.GetTypeSystemForLanguage(eLanguageTypeUnknown, &module,
30 /*can_create=*/true),
31 llvm::FailedWithMessage("TypeSystem for language unknown doesn't exist"));
32
33 EXPECT_THAT_EXPECTED(
34 map.GetTypeSystemForLanguage(eLanguageTypeUnknown, &module,
35 /*can_create=*/false),
36 llvm::FailedWithMessage("TypeSystem for language unknown doesn't exist"));
37
38 EXPECT_THAT_EXPECTED(
39 map.GetTypeSystemForLanguage(eLanguageTypeC, &module,
40 /*can_create=*/true),
41 llvm::FailedWithMessage("TypeSystem for language c doesn't exist"));
42 EXPECT_THAT_EXPECTED(
43 map.GetTypeSystemForLanguage(eLanguageTypeC, &module,
44 /*can_create=*/false),
45 llvm::FailedWithMessage("TypeSystem for language c doesn't exist"));
46}
47
48TEST_F(TestTypeSystemMap, GetTypeSystemForLanguageWithNoModule) {
49 // GetTypeSystemForLanguage called with no Module.
50 TypeSystemMap map;
51 Module *module = nullptr;
52 EXPECT_THAT_EXPECTED(
53 map.GetTypeSystemForLanguage(eLanguageTypeUnknown, module,
54 /*can_create=*/true),
55 llvm::FailedWithMessage("TypeSystem for language unknown doesn't exist"));
56
57 EXPECT_THAT_EXPECTED(
58 map.GetTypeSystemForLanguage(eLanguageTypeUnknown, module,
59 /*can_create=*/false),
60 llvm::FailedWithMessage("TypeSystem for language unknown doesn't exist"));
61
62 EXPECT_THAT_EXPECTED(
63 map.GetTypeSystemForLanguage(eLanguageTypeC, module, /*can_create=*/true),
64 llvm::FailedWithMessage("TypeSystem for language c doesn't exist"));
65 EXPECT_THAT_EXPECTED(
66 map.GetTypeSystemForLanguage(eLanguageTypeC, module,
67 /*can_create=*/false),
68 llvm::FailedWithMessage("TypeSystem for language c doesn't exist"));
69}
70
71TEST_F(TestTypeSystemMap, GetTypeSystemForLanguageWithNoTarget) {
72 // GetTypeSystemForLanguage called with no Target.
73 TypeSystemMap map;
74 Target *target = nullptr;
75 EXPECT_THAT_EXPECTED(
76 map.GetTypeSystemForLanguage(eLanguageTypeUnknown, target,
77 /*can_create=*/true),
78 llvm::FailedWithMessage("TypeSystem for language unknown doesn't exist"));
79
80 EXPECT_THAT_EXPECTED(
81 map.GetTypeSystemForLanguage(eLanguageTypeUnknown, target,
82 /*can_create=*/false),
83 llvm::FailedWithMessage("TypeSystem for language unknown doesn't exist"));
84
85 EXPECT_THAT_EXPECTED(
86 map.GetTypeSystemForLanguage(eLanguageTypeC, target, /*can_create=*/true),
87 llvm::FailedWithMessage("TypeSystem for language c doesn't exist"));
88 EXPECT_THAT_EXPECTED(
89 map.GetTypeSystemForLanguage(eLanguageTypeC, target,
90 /*can_create=*/false),
91 llvm::FailedWithMessage("TypeSystem for language c doesn't exist"));
92}
93

source code of lldb/unittests/Symbol/TestTypeSystem.cpp