diff options
| author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2014-02-25 03:59:23 +0000 |
|---|---|---|
| committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2014-02-25 03:59:23 +0000 |
| commit | 0b9682efa42cbd2c3d4ee5cfd56b22f590aeaa8a (patch) | |
| tree | 77866ecdcefdb675fc2e5559fbe799209b8c3ac6 /clang/unittests/libclang | |
| parent | 09a439d3135d276a1b8b35bc50ff9603cb0f2755 (diff) | |
| download | bcm5719-llvm-0b9682efa42cbd2c3d4ee5cfd56b22f590aeaa8a.tar.gz bcm5719-llvm-0b9682efa42cbd2c3d4ee5cfd56b22f590aeaa8a.zip | |
[libclang] Introduce libclang APIs for creating a buffer with a JSON virtual file overlay description.
The current API only supports adding 'virtual file path' -> 'real file path' mappings.
rdar://15986708
llvm-svn: 202105
Diffstat (limited to 'clang/unittests/libclang')
| -rw-r--r-- | clang/unittests/libclang/LibclangTest.cpp | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/clang/unittests/libclang/LibclangTest.cpp b/clang/unittests/libclang/LibclangTest.cpp index 4278d10a1f8..f855ecdd3c6 100644 --- a/clang/unittests/libclang/LibclangTest.cpp +++ b/clang/unittests/libclang/LibclangTest.cpp @@ -28,3 +28,114 @@ TEST(libclang, clang_createTranslationUnit2_InvalidArgs) { clang_createTranslationUnit2(0, 0, &TU)); EXPECT_EQ(0, TU); } + +namespace { +struct TestVFO { + const char *Contents; + CXVirtualFileOverlay VFO; + + TestVFO(const char *Contents) : Contents(Contents) { + VFO = clang_VirtualFileOverlay_create(0); + } + + void map(const char *VPath, const char *RPath) { + CXErrorCode Err = clang_VirtualFileOverlay_addFileMapping(VFO, VPath, RPath); + EXPECT_EQ(Err, CXError_Success); + } + + void mapError(const char *VPath, const char *RPath, CXErrorCode ExpErr) { + CXErrorCode Err = clang_VirtualFileOverlay_addFileMapping(VFO, VPath, RPath); + EXPECT_EQ(Err, ExpErr); + } + + ~TestVFO() { + if (!Contents) + return; + CXString Buf; + clang_VirtualFileOverlay_writeToBuffer(VFO, 0, &Buf); + EXPECT_STREQ(Contents, clang_getCString(Buf)); + clang_disposeString(Buf); + clang_VirtualFileOverlay_dispose(VFO); + } +}; +} + +TEST(libclang, VirtualFileOverlay) { + { + const char *contents = + "{\n" + " 'version': 0,\n" + " 'roots': [\n" + " {\n" + " 'type': 'directory',\n" + " 'name': \"/path/virtual\",\n" + " 'contents': [\n" + " {\n" + " 'type': 'file',\n" + " 'name': \"foo.h\",\n" + " 'external-contents': \"/real/foo.h\"\n" + " }\n" + " ]\n" + " }\n" + " ]\n" + "}\n"; + TestVFO T(contents); + T.map("/path/virtual/foo.h", "/real/foo.h"); + } + { + TestVFO T(NULL); + T.mapError("/path/./virtual/../foo.h", "/real/foo.h", + CXError_InvalidArguments); + } + { + const char *contents = + "{\n" + " 'version': 0,\n" + " 'roots': [\n" + " {\n" + " 'type': 'directory',\n" + " 'name': \"/another/dir\",\n" + " 'contents': [\n" + " {\n" + " 'type': 'file',\n" + " 'name': \"foo2.h\",\n" + " 'external-contents': \"/real/foo2.h\"\n" + " }\n" + " ]\n" + " },\n" + " {\n" + " 'type': 'directory',\n" + " 'name': \"/path/virtual/dir\",\n" + " 'contents': [\n" + " {\n" + " 'type': 'file',\n" + " 'name': \"foo1.h\",\n" + " 'external-contents': \"/real/foo1.h\"\n" + " },\n" + " {\n" + " 'type': 'file',\n" + " 'name': \"foo3.h\",\n" + " 'external-contents': \"/real/foo3.h\"\n" + " },\n" + " {\n" + " 'type': 'directory',\n" + " 'name': \"in/subdir\",\n" + " 'contents': [\n" + " {\n" + " 'type': 'file',\n" + " 'name': \"foo4.h\",\n" + " 'external-contents': \"/real/foo4.h\"\n" + " }\n" + " ]\n" + " }\n" + " ]\n" + " }\n" + " ]\n" + "}\n"; + TestVFO T(contents); + T.map("/path/virtual/dir/foo1.h", "/real/foo1.h"); + T.map("/another/dir/foo2.h", "/real/foo2.h"); + T.map("/path/virtual/dir/foo3.h", "/real/foo3.h"); + T.map("/path/virtual/dir/in/subdir/foo4.h", "/real/foo4.h"); + } +} |

