summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authoralokp@chromium.org <alokp@chromium.org@736b8ea6-26fd-11df-bfd4-992fa37f6226>2012-06-19 18:39:48 +0000
committeralokp@chromium.org <alokp@chromium.org@736b8ea6-26fd-11df-bfd4-992fa37f6226>2012-06-19 18:39:48 +0000
commitf3cdb460d1dde723815eecd006274a3da5d81099 (patch)
treebb33d982576aa4d54b5b7d5650e65cca2203181c /tests
parent4f677306af281e039c26cd18ba1064d66d89787a (diff)
downloadangle_dx11-f3cdb460d1dde723815eecd006274a3da5d81099.tar.gz
Added support for pre-defined macros.
Review URL: https://codereview.appspot.com/6301084 git-svn-id: https://angleproject.googlecode.com/svn/trunk@1157 736b8ea6-26fd-11df-bfd4-992fa37f6226
Diffstat (limited to 'tests')
-rw-r--r--tests/preprocessor_tests/define_test.cpp138
-rw-r--r--tests/preprocessor_tests/location_test.cpp23
2 files changed, 160 insertions, 1 deletions
diff --git a/tests/preprocessor_tests/define_test.cpp b/tests/preprocessor_tests/define_test.cpp
index f7ed448f..71c33b8d 100644
--- a/tests/preprocessor_tests/define_test.cpp
+++ b/tests/preprocessor_tests/define_test.cpp
@@ -26,6 +26,45 @@ TEST_F(DefineTest, NonIdentifier)
preprocess(input, expected);
};
+TEST_F(DefineTest, RedefinePredefined)
+{
+ const char* input = "#define __LINE__ 10\n"
+ "__LINE__\n"
+ "#define __FILE__ 20\n"
+ "__FILE__\n"
+ "#define __VERSION__ 200\n"
+ "__VERSION__\n"
+ "#define GL_ES 0\n"
+ "GL_ES\n";
+ const char* expected = "\n"
+ "2\n"
+ "\n"
+ "0\n"
+ "\n"
+ "100\n"
+ "\n"
+ "1\n";
+
+ EXPECT_CALL(mDiagnostics,
+ print(pp::Diagnostics::MACRO_PREDEFINED_REDEFINED,
+ pp::SourceLocation(0, 1),
+ "__LINE__"));
+ EXPECT_CALL(mDiagnostics,
+ print(pp::Diagnostics::MACRO_PREDEFINED_REDEFINED,
+ pp::SourceLocation(0, 3),
+ "__FILE__"));
+ EXPECT_CALL(mDiagnostics,
+ print(pp::Diagnostics::MACRO_PREDEFINED_REDEFINED,
+ pp::SourceLocation(0, 5),
+ "__VERSION__"));
+ EXPECT_CALL(mDiagnostics,
+ print(pp::Diagnostics::MACRO_PREDEFINED_REDEFINED,
+ pp::SourceLocation(0, 7),
+ "GL_ES"));
+
+ preprocess(input, expected);
+}
+
TEST_F(DefineTest, ReservedUnderScore1)
{
const char* input = "#define __foo bar\n"
@@ -693,6 +732,45 @@ TEST_F(DefineTest, Undef)
preprocess(input, expected);
}
+TEST_F(DefineTest, UndefPredefined)
+{
+ const char* input = "#undef __LINE__\n"
+ "__LINE__\n"
+ "#undef __FILE__\n"
+ "__FILE__\n"
+ "#undef __VERSION__\n"
+ "__VERSION__\n"
+ "#undef GL_ES\n"
+ "GL_ES\n";
+ const char* expected = "\n"
+ "2\n"
+ "\n"
+ "0\n"
+ "\n"
+ "100\n"
+ "\n"
+ "1\n";
+
+ EXPECT_CALL(mDiagnostics,
+ print(pp::Diagnostics::MACRO_PREDEFINED_UNDEFINED,
+ pp::SourceLocation(0, 1),
+ "__LINE__"));
+ EXPECT_CALL(mDiagnostics,
+ print(pp::Diagnostics::MACRO_PREDEFINED_UNDEFINED,
+ pp::SourceLocation(0, 3),
+ "__FILE__"));
+ EXPECT_CALL(mDiagnostics,
+ print(pp::Diagnostics::MACRO_PREDEFINED_UNDEFINED,
+ pp::SourceLocation(0, 5),
+ "__VERSION__"));
+ EXPECT_CALL(mDiagnostics,
+ print(pp::Diagnostics::MACRO_PREDEFINED_UNDEFINED,
+ pp::SourceLocation(0, 7),
+ "GL_ES"));
+
+ preprocess(input, expected);
+}
+
TEST_F(DefineTest, UndefRedefine)
{
const char* input = "#define foo 1\n"
@@ -753,3 +831,63 @@ TEST_F(DefineTest, C99Example)
preprocess(input, expected);
}
+TEST_F(DefineTest, Predefined_GL_ES)
+{
+ const char* input = "GL_ES\n";
+ const char* expected = "1\n";
+
+ preprocess(input, expected);
+}
+
+TEST_F(DefineTest, Predefined_VERSION)
+{
+ const char* input = "__VERSION__\n";
+ const char* expected = "100\n";
+
+ preprocess(input, expected);
+}
+
+TEST_F(DefineTest, Predefined_LINE1)
+{
+ const char* str = "\n\n__LINE__";
+ ASSERT_TRUE(mPreprocessor.init(1, &str, NULL));
+
+ pp::Token token;
+ mPreprocessor.lex(&token);
+ EXPECT_EQ(pp::Token::CONST_INT, token.type);
+ EXPECT_EQ("3", token.value);
+}
+
+TEST_F(DefineTest, Predefined_LINE2)
+{
+ const char* str = "#line 10\n"
+ "__LINE__\n";
+ ASSERT_TRUE(mPreprocessor.init(1, &str, NULL));
+
+ pp::Token token;
+ mPreprocessor.lex(&token);
+ EXPECT_EQ(pp::Token::CONST_INT, token.type);
+ EXPECT_EQ("10", token.value);
+}
+
+TEST_F(DefineTest, Predefined_FILE1)
+{
+ const char* const str[] = {"", "", "__FILE__"};
+ ASSERT_TRUE(mPreprocessor.init(3, str, NULL));
+
+ pp::Token token;
+ mPreprocessor.lex(&token);
+ EXPECT_EQ(pp::Token::CONST_INT, token.type);
+ EXPECT_EQ("2", token.value);
+}
+
+TEST_F(DefineTest, Predefined_FILE2)
+{
+ const char* const str[] = {"#line 10 20\n", "__FILE__"};
+ ASSERT_TRUE(mPreprocessor.init(2, str, NULL));
+
+ pp::Token token;
+ mPreprocessor.lex(&token);
+ EXPECT_EQ(pp::Token::CONST_INT, token.type);
+ EXPECT_EQ("21", token.value);
+}
diff --git a/tests/preprocessor_tests/location_test.cpp b/tests/preprocessor_tests/location_test.cpp
index 9532f71f..29897e36 100644
--- a/tests/preprocessor_tests/location_test.cpp
+++ b/tests/preprocessor_tests/location_test.cpp
@@ -200,7 +200,7 @@ TEST_F(LocationTest, LineDirectiveCommentsIgnored)
expectLocation(1, &str, NULL, loc);
}
-TEST_F(LocationTest, LineDirectiveWithMacro)
+TEST_F(LocationTest, LineDirectiveWithMacro1)
{
const char* str = "#define L 10\n"
"#define F(x) x\n"
@@ -208,6 +208,27 @@ TEST_F(LocationTest, LineDirectiveWithMacro)
"foo";
pp::SourceLocation loc(20, 10);
+ SCOPED_TRACE("LineDirectiveWithMacro1");
+ expectLocation(1, &str, NULL, loc);
+}
+
+TEST_F(LocationTest, LineDirectiveWithMacro2)
+{
+ const char* str = "#define LOC 10 20\n"
+ "#line LOC\n"
+ "foo";
+ pp::SourceLocation loc(20, 10);
+
+ SCOPED_TRACE("LineDirectiveWithMacro2");
+ expectLocation(1, &str, NULL, loc);
+}
+
+TEST_F(LocationTest, LineDirectiveWithPredefinedMacro)
+{
+ const char* str = "#line __LINE__ __FILE__\n"
+ "foo";
+ pp::SourceLocation loc(0, 1);
+
SCOPED_TRACE("LineDirectiveWithMacro");
expectLocation(1, &str, NULL, loc);
}