CXTranslationUnit clang_createTranslationUnit(CXIndex CIdx,
const char *ast_filename) {
- CXTranslationUnit TU = NULL;
+ CXTranslationUnit TU;
enum CXErrorCode Result =
clang_createTranslationUnit2(CIdx, ast_filename, &TU);
(void)Result;
enum CXErrorCode clang_createTranslationUnit2(CXIndex CIdx,
const char *ast_filename,
CXTranslationUnit *out_TU) {
+ if (out_TU)
+ *out_TU = NULL;
+
if (!CIdx || !ast_filename || !out_TU)
return CXError_InvalidArguments;
#include "clang-c/Index.h"
#include "gtest/gtest.h"
-TEST(libclang, TestInvalidArgs) {
+TEST(libclang, clang_parseTranslationUnit2_InvalidArgs) {
EXPECT_EQ(CXError_InvalidArguments,
clang_parseTranslationUnit2(0, 0, 0, 0, 0, 0, 0, 0));
}
+TEST(libclang, clang_createTranslationUnit_InvalidArgs) {
+ EXPECT_EQ(0, clang_createTranslationUnit(0, 0));
+}
+
+TEST(libclang, clang_createTranslationUnit2_InvalidArgs) {
+ EXPECT_EQ(CXError_InvalidArguments,
+ clang_createTranslationUnit2(0, 0, 0));
+
+ CXTranslationUnit TU = reinterpret_cast<CXTranslationUnit>(1);
+ EXPECT_EQ(CXError_InvalidArguments,
+ clang_createTranslationUnit2(0, 0, &TU));
+ EXPECT_EQ(0, TU);
+}