From 07c57a0d36c375f55e93f0caf7dd57e7c0afe271 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 8 Aug 2023 22:31:23 +0200 Subject: TestJCPP: Add recursive-include test and include a header file starting with '-' and in a subdir containing a '-' --- .../gluegen/test/junit/generation/TestJCPP.java | 39 ++++++++++++++++++---- .../test/junit/generation/cpptest-included.h | 17 +++++++++- .../jogamp/gluegen/test/junit/generation/cpptest.h | 2 +- .../junit/generation/sub-inc/-cpptest-included2.h | 4 +++ 4 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 src/junit/com/jogamp/gluegen/test/junit/generation/sub-inc/-cpptest-included2.h 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.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 + + #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 -#include +#include #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; -- cgit v1.2.3