29package com.jogamp.gluegen.test.junit.generation;
31import com.jogamp.common.os.AndroidVersion;
32import com.jogamp.gluegen.jcpp.JCPP;
33import com.jogamp.gluegen.jcpp.LexerException;
34import com.jogamp.junit.util.SingletonJunitCase;
36import java.io.BufferedReader;
37import java.io.ByteArrayOutputStream;
38import java.io.FileNotFoundException;
39import java.io.FileReader;
40import java.io.IOException;
41import java.util.Collections;
43import org.junit.BeforeClass;
45import static org.junit.Assert.*;
51import org.junit.FixMethodOrder;
52import org.junit.runners.MethodSorters;
54@FixMethodOrder(MethodSorters.NAME_ASCENDING)
58 public static void init() {
61 setTestSupported(
false);
69 testMacroAndInc(
false);
70 }
catch (IOException | LexerException e) {
81 testMacroAndInc(
true);
82 }
catch (IOException | LexerException e) {
89 public void testMacroAndInc(
final boolean pragmaOnce)
throws FileNotFoundException, IOException, LexerException {
90 final String folderpath = BuildEnvironment.gluegenRoot +
"/src/junit/com/jogamp/gluegen/test/junit/generation";
91 final JCPP pp =
new JCPP(Collections.<String>singletonList(folderpath),
false,
false, pragmaOnce);
93 pp.addDefine(
"PRAGMA_ONCE_ENABLED",
"1");
95 final ByteArrayOutputStream output =
new ByteArrayOutputStream();
98 final String filename =
"cpptest_1.h";
99 final String filepath = folderpath +
"/" + filename ;
100 pp.run(
new BufferedReader(
new FileReader(filepath)), filename);
102 final String expected =
103 "#line 1 \"cpptest_1.h\" 1"+
105 "typedef char cl_char;"+
113 " ** STD API file .."+
121 "#line 1 \""+folderpath+
"/cpptest-included.h\" 1"+
124 " const int pragma_once_enabled = 1;"
125 :
" const int pragma_once_enabled = 0;"
128 " // pragma-once or macro-defined test, i.e. should not be included recursively"+
129 "#line 1 \""+folderpath+
"/cpptest-included.h\" 1"+
131 "#line 13 \""+folderpath+
"/cpptest-included.h\" 2"+
133 "const int GOOD_H = 42;"+
135 "#line 136 \"cpptest_1.h\" 2"+
136 "#line 1 \""+folderpath+
"/sub-inc/-cpptest-included2.h\" 1"+
138 "const int GOOD_I = 43;"+
139 "#line 137 \"cpptest_1.h\" 2"+
141 "typedef enum SomeEnum {"+
142 " ConstEnumValue00 = 16,"+
143 " ConstEnumValue01 = (1 << ConstEnumValue00) - 1,"+
144 " ConstEnumValue02 = (10-1),"+
145 " ConstEnumValue03 = (10 - 2),"+
146 " ConstEnumValue04 = ( 10 - 3 ),"+
147 " ConstEnumValue05 = 10-4,"+
148 " ConstEnumValue06 = 10 - 11,"+
149 " ConstEnumValue07 = -2,"+
150 " ConstEnumValue08 = - 2,"+
151 " ConstEnumValueXX = 0"+
154 "const int constInt00 = 16;"+
155 "const int constInt01 = ((1 << 16) - 1);"+
156 "const int constInt02 = (10-1);"+
157 "const int constInt03 = (10 - 2);"+
158 "const int constInt04 = ( 10 - 3 );"+
159 "const int constInt05 = 10-4;"+
160 "const int constInt06 = 10 - 11;"+
161 "const int constInt07 = -2;"+
162 "const int constInt08 = - 2;"+
163 "const int constIntXX = 0;"+
168 final String result = output.toString();
171 System.err.println(
"Expected: ");
172 System.err.println(
"-------------------------------");
173 System.err.println(killWhitespace(expected));
174 System.err.println(
"-------------------------------");
175 System.err.println();
176 System.err.println(
"Result: ");
177 System.err.println(
"-------------------------------");
179 System.err.println(killWhitespace(result));
180 System.err.println(
"-------------------------------");
181 System.err.println();
183 assertEquals(killWhitespace(expected), killWhitespace(result));
186 private String killWhitespace(
final String a) {
187 return a.replaceAll(
"\\p{javaWhitespace}+",
"");
190 public static void main(
final String args[])
throws IOException {
191 final String tstname =
TestJCPP.class.getName();
192 org.junit.runner.JUnitCore.
main(tstname);
static final boolean isAvailable
static void main(final String args[])
void test02MacroAndIncWithPragmaOnce()
void testMacroAndInc(final boolean pragmaOnce)
void test01MacroAndIncWithoutPragmaOnce()