diff options
author | Sven Gothel <[email protected]> | 2023-08-08 22:31:23 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-08-08 22:31:23 +0200 |
commit | 07c57a0d36c375f55e93f0caf7dd57e7c0afe271 (patch) | |
tree | a77b3b17b4960e45b26ae8754d8027d596b773d3 | |
parent | 33ffd1240a8d4f2cb4032ca2d111142e0f87beac (diff) |
TestJCPP: Add recursive-include test and include a header file starting with '-' and in a subdir containing a '-'
4 files changed, 53 insertions, 9 deletions
diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/TestJCPP.java b/src/junit/com/jogamp/gluegen/test/junit/generation/TestJCPP.java index 61cb01a..d197592 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/TestJCPP.java +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/TestJCPP.java @@ -30,6 +30,7 @@ package com.jogamp.gluegen.test.junit.generation; import com.jogamp.common.os.AndroidVersion; import com.jogamp.gluegen.jcpp.JCPP; +import com.jogamp.gluegen.jcpp.LexerException; import com.jogamp.junit.util.SingletonJunitCase; import java.io.BufferedReader; @@ -62,18 +63,21 @@ public class TestJCPP extends SingletonJunitCase { } @Test - public void pcppMacroDefinitionTestWithoutPragmaOnce() throws FileNotFoundException, IOException { - pcppMacroDefinitionTest(false); + public void test01MacroAndIncWithoutPragmaOnce() throws FileNotFoundException, IOException, LexerException { + testMacroAndInc(false); } @Test - public void pcppMacroDefinitionTestWithPragmaOnce() throws FileNotFoundException, IOException { - pcppMacroDefinitionTest(true); + public void test02MacroAndIncWithPragmaOnce() throws FileNotFoundException, IOException, LexerException { + testMacroAndInc(true); } - public void pcppMacroDefinitionTest(final boolean pragmaOnce) throws FileNotFoundException, IOException { + public void testMacroAndInc(final boolean pragmaOnce) throws FileNotFoundException, IOException, LexerException { final String folderpath = BuildEnvironment.gluegenRoot + "/src/junit/com/jogamp/gluegen/test/junit/generation"; final JCPP pp = new JCPP(Collections.<String>singletonList(folderpath), false, false, pragmaOnce); + if( pragmaOnce ) { + pp.addDefine("PRAGMA_ONCE_ENABLED", "1"); + } final ByteArrayOutputStream output = new ByteArrayOutputStream(); pp.setOut(output); @@ -81,7 +85,8 @@ public class TestJCPP extends SingletonJunitCase { final String filepath = folderpath + "/" + filename ; pp.run(new BufferedReader(new FileReader(filepath)), filename); - final String expected = "#line 1 \"cpptest.h\" 1"+ + final String expected = + "#line 1 \"cpptest.h\" 1"+ ""+ "cl_char GOOD_A;"+ "int GOOD_B;"+ @@ -97,7 +102,26 @@ public class TestJCPP extends SingletonJunitCase { "int GOOD_F_2;"+ ""+ "int GOOD_G;"+ - "#line 1\""+folderpath+"/cpptest-included.h\" 1"+ + ""+ + "#line 1 \""+folderpath+"/cpptest-included.h\" 1"+ + ""+ + ( pragmaOnce ? + " const int pragma_once_enabled = 1;" + : " const int pragma_once_enabled = 0;" + )+ + ""+ + " // pragma-once or macro-defined test, i.e. should not be included recursively"+ + "#line 1 \""+folderpath+"/cpptest-included.h\" 1"+ + ""+ + "#line 13 \""+folderpath+"/cpptest-included.h\" 2"+ + ""+ + "const int GOOD_H = 42;"+ + ""+ + "#line 135 \"cpptest.h\" 2"+ + "#line 1 \""+folderpath+"/sub-inc/-cpptest-included2.h\" 1"+ + ""+ + "const int GOOD_I = 43;"+ + "#line 136 \"cpptest.h\" 2"+ "" ; @@ -113,6 +137,7 @@ public class TestJCPP extends SingletonJunitCase { System.err.println(); System.err.println("Result: "); System.err.println("-------------------------------"); + // System.err.println(result); System.err.println(killWhitespace(result)); System.err.println("-------------------------------"); System.err.println(); diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/cpptest-included.h b/src/junit/com/jogamp/gluegen/test/junit/generation/cpptest-included.h index 8dbe022..2e6db9c 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/cpptest-included.h +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/cpptest-included.h @@ -1,2 +1,17 @@ #pragma once -#define EXAMPLE 42
\ No newline at end of file + +#ifndef CPPTEST_INCLUDED_H + #ifdef PRAGMA_ONCE_ENABLED + const int pragma_once_enabled = 1; + #else + #define CPPTEST_INCLUDED_H + const int pragma_once_enabled = 0; + #endif + + // pragma-once or macro-defined test, i.e. should not be included recursively + #include <cpptest-included.h> + + #define EXAMPLE 42 + + const int GOOD_H = EXAMPLE; +#endif diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/cpptest.h b/src/junit/com/jogamp/gluegen/test/junit/generation/cpptest.h index 5cda9a5..376442a 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/cpptest.h +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/cpptest.h @@ -132,7 +132,7 @@ int TEST_G_VAL; #endif #include <cpptest-included.h> -#include <cpptest-included.h> +#include <sub-inc/-cpptest-included2.h> #endif /* __test_h_ */ diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/sub-inc/-cpptest-included2.h b/src/junit/com/jogamp/gluegen/test/junit/generation/sub-inc/-cpptest-included2.h new file mode 100644 index 0000000..887ed6e --- /dev/null +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/sub-inc/-cpptest-included2.h @@ -0,0 +1,4 @@ +#pragma once +#define EXAMPLE_2 43 + +const int GOOD_I = EXAMPLE_2; |