summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/unittests/clang-rename/USRLocFindingTest.cpp
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2014-08-17 18:00:59 +0000
committerManuel Klimek <klimek@google.com>2014-08-17 18:00:59 +0000
commitccf0d797242da0656896bc38e1f6b7303e7ab91a (patch)
treebfe41e056b7dcf363c2ae5aacaf435f0403c903d /clang-tools-extra/unittests/clang-rename/USRLocFindingTest.cpp
parentab73774c4771a7e310d403934d0c961eb0ad213b (diff)
downloadbcm5719-llvm-ccf0d797242da0656896bc38e1f6b7303e7ab91a.tar.gz
bcm5719-llvm-ccf0d797242da0656896bc38e1f6b7303e7ab91a.zip
First version of a clang-rename tool.
Summary: Note that this code is still grossly under-tested - the next steps will be to add significantly better test coverage. Patch by Matthew Plant. Test Plan: Reviewers: Subscribers: llvm-svn: 215839
Diffstat (limited to 'clang-tools-extra/unittests/clang-rename/USRLocFindingTest.cpp')
-rw-r--r--clang-tools-extra/unittests/clang-rename/USRLocFindingTest.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/clang-tools-extra/unittests/clang-rename/USRLocFindingTest.cpp b/clang-tools-extra/unittests/clang-rename/USRLocFindingTest.cpp
new file mode 100644
index 00000000000..81627eec836
--- /dev/null
+++ b/clang-tools-extra/unittests/clang-rename/USRLocFindingTest.cpp
@@ -0,0 +1,77 @@
+#include "USRFindingAction.h"
+#include "gtest/gtest.h"
+#include "clang/Tooling/Tooling.h"
+#include <stdio.h>
+#include <set>
+#include <map>
+#include <vector>
+
+namespace clang {
+namespace rename {
+namespace test {
+
+// Determines if the symbol group invariants hold. To recap, those invariants
+// are:
+// (1) All symbols in the same symbol group share the same USR.
+// (2) Two symbols from two different groups do not share the same USR.
+static void testOffsetGroups(const char *Code,
+ const std::vector<std::vector<unsigned>> Groups) {
+ std::set<std::string> AllUSRs, CurrUSR;
+
+ for (const auto &Group : Groups) {
+ // Groups the invariants do not hold then the value of USR is also invalid,
+ // but at that point the test has already failed and USR ceases to be
+ // useful.
+ std::string USR;
+ for (const auto &Offset : Group) {
+ USRFindingAction Action(Offset);
+ auto Factory = tooling::newFrontendActionFactory(&Action);
+ EXPECT_TRUE(tooling::runToolOnCode(Factory->create(), Code));
+ const auto &USRs = Action.getUSRs();
+ EXPECT_EQ(1u, USRs.size());
+ USR = USRs[0];
+ CurrUSR.insert(USR);
+ }
+ EXPECT_EQ(1u, CurrUSR.size());
+ CurrUSR.clear();
+ AllUSRs.insert(USR);
+ }
+
+ EXPECT_EQ(Groups.size(), AllUSRs.size());
+}
+
+
+TEST(USRLocFinding, FindsVarUSR) {
+ const char VarTest[] = "\n\
+namespace A {\n\
+int foo;\n\
+}\n\
+int foo;\n\
+int bar = foo;\n\
+int baz = A::foo;\n\
+void fun1() {\n\
+ struct {\n\
+ int foo;\n\
+ } b = { 100 };\n\
+ int foo = 100;\n\
+ baz = foo;\n\
+ {\n\
+ extern int foo;\n\
+ baz = foo;\n\
+ foo = A::foo + baz;\n\
+ A::foo = b.foo;\n\
+ }\n\
+ foo = b.foo;\n\
+}\n";
+ std::vector<std::vector<unsigned>> VarTestOffsets = {
+ { 19, 63, 205, 223 },
+ { 30, 45, 172, 187 },
+ { 129, 148, 242 },
+ };
+
+ testOffsetGroups(VarTest, VarTestOffsets);
+}
+
+}
+}
+}
OpenPOWER on IntegriCloud