UTIL: added test case for the IncludeUtil

Martin Gerhardy 2020-01-06 21:56:59 +01:00
parent 65b14dc72a
commit 6e24717e46
5 changed files with 37 additions and 0 deletions

2
data/testutil/main.h Normal file
View File

@ -0,0 +1,2 @@
#include "one.h"
#include "two.h"

2
data/testutil/one.h Normal file
View File

@ -0,0 +1,2 @@
#error "one"
#include "two.h"

1
data/testutil/two.h Normal file
View File

@ -0,0 +1 @@
#error "two"

View File

@ -14,12 +14,20 @@ set(TEST_SRCS
tests/KeybindingParserTest.cpp
tests/KeybindingHandlerTest.cpp
tests/EMailValidatorTest.cpp
tests/IncludeUtilTest.cpp
)
set(TEST_FILES
testutil/main.h
testutil/one.h
testutil/two.h
)
gtest_suite_files(tests ${TEST_FILES})
gtest_suite_sources(tests ${TEST_SRCS})
gtest_suite_deps(tests ${LIB})
gtest_suite_begin(tests-${LIB} TEMPLATE ${ROOT_DIR}/src/modules/core/tests/main.cpp.in)
gtest_suite_files(tests-${LIB} ${TEST_FILES})
gtest_suite_sources(tests-${LIB} ${TEST_SRCS} ../core/tests/AbstractTest.cpp)
gtest_suite_deps(tests-${LIB} ${LIB})
gtest_suite_end(tests-${LIB})

View File

@ -0,0 +1,24 @@
/**
* @file
*/
#include "core/tests/AbstractTest.h"
#include "util/IncludeUtil.h"
class IncludeUtilTest : public core::AbstractTest {
};
TEST_F(IncludeUtilTest, testInclude) {
std::vector<std::string> includedFiles;
std::vector<std::string> includeDirs { "." };
const std::string src = io::filesystem()->load("main.h");
EXPECT_EQ(34u, src.size());
std::pair<std::string, bool> retIncludes = util::handleIncludes(src, includeDirs, &includedFiles);
EXPECT_TRUE(retIncludes.second);
EXPECT_EQ(2u, includedFiles.size());
EXPECT_EQ("#error \"one\"\n#include \"two.h\"\n\n#error \"two\"\n\n", retIncludes.first);
retIncludes = util::handleIncludes(retIncludes.first, includeDirs, &includedFiles);
EXPECT_TRUE(retIncludes.second);
EXPECT_EQ(3u, includedFiles.size());
EXPECT_EQ("#error \"one\"\n#error \"two\"\n\n\n#error \"two\"\n\n", retIncludes.first);
}