aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2015-03-24 03:22:05 +0100
committerSven Gothel <[email protected]>2015-03-24 03:22:05 +0100
commita2bf42eafb8d6bc270f832c6bd49793465a593d4 (patch)
treeb7d091648e7da78cfc8675a1206560469d822fd3 /src
parent2ed80887326a12a2b47826c5ea0256f1b0c180d5 (diff)
Complete JogAmp GlueGen merge: Relocate and patch unit test, strip unrelated files, add note in README.md
Diffstat (limited to 'src')
-rw-r--r--src/main/ghpages/index.html6
-rw-r--r--src/main/java/com/jogamp/gluegen/jcpp/BuildMetadata.java72
-rw-r--r--src/main/java/com/jogamp/gluegen/jcpp/Main.java195
-rw-r--r--src/main/velocity/org/anarres/cpp/Version.java83
-rwxr-xr-xsrc/scripts/jcpp32
-rw-r--r--src/scripts/release.sh5
-rw-r--r--src/test/java/com/jogamp/gluegen/jcpp/CppReaderTest.java (renamed from src/test/java/org/anarres/cpp/CppReaderTest.java)30
-rw-r--r--src/test/java/com/jogamp/gluegen/jcpp/ErrorTest.java (renamed from src/test/java/org/anarres/cpp/ErrorTest.java)4
-rw-r--r--src/test/java/com/jogamp/gluegen/jcpp/IncludeAbsoluteTest.java46
-rw-r--r--src/test/java/com/jogamp/gluegen/jcpp/JavaFileSystemTest.java (renamed from src/test/java/org/anarres/cpp/JavaFileSystemTest.java)2
-rw-r--r--src/test/java/com/jogamp/gluegen/jcpp/JoinReaderTest.java (renamed from src/test/java/org/anarres/cpp/JoinReaderTest.java)2
-rw-r--r--src/test/java/com/jogamp/gluegen/jcpp/LexerSourceTest.java (renamed from src/test/java/org/anarres/cpp/LexerSourceTest.java)25
-rw-r--r--src/test/java/com/jogamp/gluegen/jcpp/NumericValueTest.java (renamed from src/test/java/org/anarres/cpp/NumericValueTest.java)4
-rw-r--r--src/test/java/com/jogamp/gluegen/jcpp/PreprocessorTest.java (renamed from src/test/java/org/anarres/cpp/PreprocessorTest.java)177
-rw-r--r--src/test/java/com/jogamp/gluegen/jcpp/TokenPastingWhitespaceTest.java (renamed from src/test/java/org/anarres/cpp/TokenPastingWhitespaceTest.java)30
-rw-r--r--src/test/java/org/anarres/cpp/BuildMetadataTest.java33
-rw-r--r--src/test/java/org/anarres/cpp/IncludeAbsoluteTest.java35
-rw-r--r--src/test/java/org/anarres/cpp/MainTest.java11
18 files changed, 264 insertions, 528 deletions
diff --git a/src/main/ghpages/index.html b/src/main/ghpages/index.html
deleted file mode 100644
index 32292c3..0000000
--- a/src/main/ghpages/index.html
+++ /dev/null
@@ -1,6 +0,0 @@
-<html>
-<body>
-<a href="docs/javadoc/">Javadoc</a>
-<a href="docs/cobertura/">Coverage</a>
-</body>
-</html>
diff --git a/src/main/java/com/jogamp/gluegen/jcpp/BuildMetadata.java b/src/main/java/com/jogamp/gluegen/jcpp/BuildMetadata.java
deleted file mode 100644
index f22d853..0000000
--- a/src/main/java/com/jogamp/gluegen/jcpp/BuildMetadata.java
+++ /dev/null
@@ -1,72 +0,0 @@
-package com.jogamp.gluegen.jcpp;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-import javax.annotation.Nonnull;
-
-/**
- * Returns information about the build.
- *
- * @author shevek
- */
-public class BuildMetadata {
-
- public static final String RESOURCE = "/META-INF/jcpp.properties";
- private static BuildMetadata INSTANCE;
-
- /** @throws RuntimeException if the properties file cannot be found on the classpath. */
- @Nonnull
- public static synchronized BuildMetadata getInstance() {
- try {
- if (INSTANCE == null)
- INSTANCE = new BuildMetadata();
- return INSTANCE;
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- private final Properties properties = new Properties();
-
- private BuildMetadata() throws IOException {
- URL url = BuildMetadata.class.getResource(RESOURCE);
- InputStream in = url.openStream();
- try {
- properties.load(in);
- } finally {
- in.close();
- }
- }
-
- @Nonnull
- public Map<? extends String, ? extends String> asMap() {
- Map<String, String> out = new HashMap<String, String>();
- for (Map.Entry<Object, Object> e : properties.entrySet())
- out.put(String.valueOf(e.getKey()), String.valueOf(e.getValue()));
- return out;
- }
-
- @Nonnull
- public com.github.zafarkhaja.semver.Version getVersion() {
- return com.github.zafarkhaja.semver.Version.valueOf(properties.getProperty("Implementation-Version"));
- }
-
- @Nonnull
- public Date getBuildDate() throws ParseException {
- // Build-Date=2015-01-01_10:09:09
- String text = properties.getProperty("Build-Date");
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss");
- return format.parse(text);
- }
-
- public String getChangeId() {
- return properties.getProperty("Change");
- }
-}
diff --git a/src/main/java/com/jogamp/gluegen/jcpp/Main.java b/src/main/java/com/jogamp/gluegen/jcpp/Main.java
deleted file mode 100644
index 9f06fb0..0000000
--- a/src/main/java/com/jogamp/gluegen/jcpp/Main.java
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * Anarres C Preprocessor
- * Copyright (c) 2007-2008, Shevek
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing
- * permissions and limitations under the License.
- */
-package com.jogamp.gluegen.jcpp;
-
-import java.io.File;
-import java.io.PrintStream;
-import java.util.Arrays;
-import java.util.EnumSet;
-import java.util.List;
-import javax.annotation.Nonnull;
-import joptsimple.OptionParser;
-import joptsimple.OptionSet;
-import joptsimple.OptionSpec;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * (Currently a simple test class).
- */
-public class Main {
-
- private static final Logger LOG = LoggerFactory.getLogger(Main.class);
-
- @Nonnull
- private static CharSequence getWarnings() {
- StringBuilder buf = new StringBuilder();
- for (Warning w : Warning.values()) {
- if (buf.length() > 0)
- buf.append(", ");
- String name = w.name().toLowerCase();
- buf.append(name.replace('_', '-'));
- }
- return buf;
- }
-
- public static void main(String[] args) throws Exception {
- (new Main()).run(args);
- }
-
- public void run(String[] args) throws Exception {
-
- OptionParser parser = new OptionParser();
- OptionSpec<?> helpOption = parser.accepts("help",
- "Displays command-line help.")
- .forHelp();
- OptionSpec<?> versionOption = parser.acceptsAll(Arrays.asList("version"),
- "Displays the product version (" + BuildMetadata.getInstance().getVersion() + ") and exits.")
- .forHelp();
-
- OptionSpec<?> debugOption = parser.acceptsAll(Arrays.asList("debug"),
- "Enables debug output.");
-
- OptionSpec<String> defineOption = parser.acceptsAll(Arrays.asList("define", "D"),
- "Defines the given macro.")
- .withRequiredArg().ofType(String.class).describedAs("name[=definition]");
- OptionSpec<String> undefineOption = parser.acceptsAll(Arrays.asList("undefine", "U"),
- "Undefines the given macro, previously either builtin or defined using -D.")
- .withRequiredArg().describedAs("name");
- OptionSpec<File> includeOption = parser.accepts("include",
- "Process file as if \"#" + "include \"file\"\" appeared as the first line of the primary source file.")
- .withRequiredArg().ofType(File.class).describedAs("file");
- OptionSpec<File> incdirOption = parser.acceptsAll(Arrays.asList("incdir", "I"),
- "Adds the directory dir to the list of directories to be searched for header files.")
- .withRequiredArg().ofType(File.class).describedAs("dir");
- OptionSpec<File> iquoteOption = parser.acceptsAll(Arrays.asList("iquote"),
- "Adds the directory dir to the list of directories to be searched for header files included using \"\".")
- .withRequiredArg().ofType(File.class).describedAs("dir");
- OptionSpec<String> warningOption = parser.acceptsAll(Arrays.asList("warning", "W"),
- "Enables the named warning class (" + getWarnings() + ").")
- .withRequiredArg().ofType(String.class).describedAs("warning");
- OptionSpec<Void> noWarningOption = parser.acceptsAll(Arrays.asList("no-warnings", "w"),
- "Disables ALL warnings.");
- OptionSpec<File> inputsOption = parser.nonOptions()
- .ofType(File.class).describedAs("Files to process.");
-
- OptionSet options = parser.parse(args);
-
- if (options.has(helpOption)) {
- parser.printHelpOn(System.out);
- return;
- }
-
- if (options.has(versionOption)) {
- version(System.out);
- return;
- }
-
- Preprocessor pp = new Preprocessor();
- pp.addFeature(Feature.DIGRAPHS);
- pp.addFeature(Feature.TRIGRAPHS);
- pp.addFeature(Feature.LINEMARKERS);
- pp.addWarning(Warning.IMPORT);
- pp.setListener(new DefaultPreprocessorListener());
- pp.addMacro("__JCPP__");
- pp.getSystemIncludePath().add("/usr/local/include");
- pp.getSystemIncludePath().add("/usr/include");
- pp.getFrameworksPath().add("/System/Library/Frameworks");
- pp.getFrameworksPath().add("/Library/Frameworks");
- pp.getFrameworksPath().add("/Local/Library/Frameworks");
-
- if (options.has(debugOption))
- pp.addFeature(Feature.DEBUG);
-
- if (options.has(noWarningOption))
- pp.getWarnings().clear();
-
- for (String warning : options.valuesOf(warningOption)) {
- warning = warning.toUpperCase();
- warning = warning.replace('-', '_');
- if (warning.equals("ALL"))
- pp.addWarnings(EnumSet.allOf(Warning.class));
- else
- pp.addWarning(Enum.valueOf(Warning.class, warning));
- }
-
- for (String arg : options.valuesOf(defineOption)) {
- int idx = arg.indexOf('=');
- if (idx == -1)
- pp.addMacro(arg);
- else
- pp.addMacro(arg.substring(0, idx), arg.substring(idx + 1));
- }
- for (String arg : options.valuesOf(undefineOption)) {
- pp.getMacros().remove(arg);
- }
-
- for (File dir : options.valuesOf(incdirOption))
- pp.getSystemIncludePath().add(dir.getAbsolutePath());
- for (File dir : options.valuesOf(iquoteOption))
- pp.getQuoteIncludePath().add(dir.getAbsolutePath());
- for (File file : options.valuesOf(includeOption))
- // Comply exactly with spec.
- pp.addInput(new StringLexerSource("#" + "include \"" + file + "\"\n"));
-
- List<File> inputs = options.valuesOf(inputsOption);
- if (inputs.isEmpty()) {
- pp.addInput(new InputLexerSource(System.in));
- } else {
- for (File input : inputs)
- pp.addInput(new FileLexerSource(input));
- }
-
- if (pp.getFeature(Feature.DEBUG)) {
- LOG.info("#" + "include \"...\" search starts here:");
- for (String dir : pp.getQuoteIncludePath())
- LOG.info(" " + dir);
- LOG.info("#" + "include <...> search starts here:");
- for (String dir : pp.getSystemIncludePath())
- LOG.info(" " + dir);
- LOG.info("End of search list.");
- }
-
- try {
- for (;;) {
- Token tok = pp.token();
- if (tok == null)
- break;
- if (tok.getType() == Token.EOF)
- break;
- System.out.print(tok.getText());
- }
- } catch (Exception e) {
- StringBuilder buf = new StringBuilder("Preprocessor failed:\n");
- Source s = pp.getSource();
- while (s != null) {
- buf.append(" -> ").append(s).append("\n");
- s = s.getParent();
- }
- LOG.error(buf.toString(), e);
- }
-
- }
-
- private static void version(@Nonnull PrintStream out) {
- BuildMetadata metadata = BuildMetadata.getInstance();
- out.println("Anarres Java C Preprocessor version " + metadata.getVersion() + " change-id " + metadata.getChangeId());
- out.println("Copyright (C) 2008-2014 Shevek (http://www.anarres.org/).");
- out.println("This is free software; see the source for copying conditions. There is NO");
- out.println("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");
- }
-}
diff --git a/src/main/velocity/org/anarres/cpp/Version.java b/src/main/velocity/org/anarres/cpp/Version.java
deleted file mode 100644
index cedd6bb..0000000
--- a/src/main/velocity/org/anarres/cpp/Version.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Anarres C Preprocessor
- * Copyright (c) 2007-2008, Shevek
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing
- * permissions and limitations under the License.
- */
-
-package org.anarres.cpp;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nonnull;
-
-/**
- * System version metadata for Anarres Java C Preprocessor ${version}.
- *
- * This class contains a main() and may be run to print the version.
- */
-public class Version {
-
- /* Don't instantiate me */
- private Version() {
- }
-
- private static final String VERSION = "${version}";
-
- private static final int major;
- private static final int minor;
- private static final int patch;
- private static final String modifier;
-
- static {
- String[] tmp = VERSION.split("[\\.-]");
- major = Integer.parseInt(tmp[0]);
- minor = Integer.parseInt(tmp[1]);
- patch = Integer.parseInt(tmp[2]);
- modifier = (tmp.length > 3) ? tmp[3] : null;
- }
-
- @Nonnull
- public static String getVersion() {
- return VERSION;
- }
-
- public static int getMajor() {
- return major;
- }
-
- public static int getMinor() {
- return minor;
- }
-
- public static int getPatch() {
- return patch;
- }
-
- @CheckForNull
- public static String getModifier() {
- return modifier;
- }
-
- public static boolean isSnapshot() {
- return "SNAPSHOT".equalsIgnoreCase(getModifier());
- }
-
- public static void main(String[] args) {
- System.out.println("Version " + VERSION);
- System.out.println("getVersion() returns " + getVersion());
- System.out.println("getMajor() returns " + getMajor());
- System.out.println("getMinor() returns " + getMinor());
- System.out.println("getPatch() returns " + getPatch());
- }
-
-}
diff --git a/src/scripts/jcpp b/src/scripts/jcpp
deleted file mode 100755
index ed167c5..0000000
--- a/src/scripts/jcpp
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/bin/sh
-
-CPP_JAR=anarres-cpp.jar
-
-if [ -n "$CPP_ROOT" ] ; then
- CPP_ROOT="$CPP_ROOT"
-elif [ -f lib/$CPP_JAR ] ; then
- CPP_ROOT="."
-elif [ -f ../lib/$CPP_JAR ] ; then
- CPP_ROOT=".."
-elif [ -f $(dirname $0)/lib/$CPP_JAR ] ; then
- CPP_ROOT=$(dirname $0)
-else
- echo "Could not find $CPP_JAR. Please set CPP_ROOT."
- exit 1
-fi
-
-if [ -z "$CPP_LIB" ] ; then
- CPP_LIB=$CPP_ROOT/lib
-fi
-
-if [ -z "$CPP_CLASSPATH" ] ; then
- CPP_CLASSPATH="$(ls $CPP_LIB/*.jar | tr '\n' ':')"
-fi
-
-if [ -z "$CPP_MAINCLASS" ] ; then
- CPP_MAINCLASS=org.anarres.cpp.Main
-fi
-
-CPP_JFLAGS="-Xmx128M"
-
-exec java $CPP_JFLAGS -cp "$CPP_CLASSPATH" $CPP_MAINCLASS "$@"
diff --git a/src/scripts/release.sh b/src/scripts/release.sh
deleted file mode 100644
index cd88d95..0000000
--- a/src/scripts/release.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-rsync -avP build/dist/anarres-cpp-*.tar.gz [email protected]:public_html/projects/jcpp/
-rsync -avP --exclude=.svn --exclude=autohandler build/javadoc [email protected]:public_html/projects/jcpp/
-cp build/tar/lib/anarres-cpp.jar /home/shevek/java/iengine/trunk/lib/runtime/jcpp/
-cp build/tar/lib/anarres-cpp.jar /home/shevek/java/karma/trunk/lib/dp/
-cp build/tar/lib/anarres-cpp.jar /home/shevek/java/dp/trunk/lib/runtime/cpp/
diff --git a/src/test/java/org/anarres/cpp/CppReaderTest.java b/src/test/java/com/jogamp/gluegen/jcpp/CppReaderTest.java
index c901722..e4ef1c5 100644
--- a/src/test/java/org/anarres/cpp/CppReaderTest.java
+++ b/src/test/java/com/jogamp/gluegen/jcpp/CppReaderTest.java
@@ -1,26 +1,33 @@
-package org.anarres.cpp;
+package com.jogamp.gluegen.jcpp;
import java.io.BufferedReader;
+import java.io.IOException;
import java.io.StringReader;
import java.util.Collections;
+
import javax.annotation.Nonnull;
+
import org.junit.Test;
+
+import com.jogamp.gluegen.test.junit.generation.BuildEnvironment;
+
import static org.junit.Assert.assertEquals;
public class CppReaderTest {
- public static String testCppReader(@Nonnull String in, Feature... f)
- throws Exception {
+ public static String testCppReader(@Nonnull final String in, final Feature... f) throws Exception {
+ final String inclpath = BuildEnvironment.gluegenRoot + "/jcpp/src/test/resources" ;
+
System.out.println("Testing " + in);
- StringReader r = new StringReader(in);
- CppReader p = new CppReader(r);
+ final StringReader r = new StringReader(in);
+ final CppReader p = new CppReader(r);
p.getPreprocessor().setSystemIncludePath(
- Collections.singletonList("src/test/resources")
+ Collections.singletonList(inclpath)
);
p.getPreprocessor().addFeatures(f);
- BufferedReader b = new BufferedReader(p);
+ final BufferedReader b = new BufferedReader(p);
- StringBuilder out = new StringBuilder();
+ final StringBuilder out = new StringBuilder();
String line;
while ((line = b.readLine()) != null) {
System.out.println(" >> " + line);
@@ -47,7 +54,7 @@ public class CppReaderTest {
public void testPragmaOnce()
throws Exception {
// The newlines are irrelevant, We want exactly one "foo"
- String out = testCppReader("#include <once.c>\n", Feature.PRAGMA_ONCE);
+ final String out = testCppReader("#include <once.c>\n", Feature.PRAGMA_ONCE);
assertEquals("foo", out.trim());
}
@@ -58,4 +65,9 @@ public class CppReaderTest {
testCppReader("#include <once.c>\n", Feature.PRAGMA_ONCE, Feature.LINEMARKERS);
}
+ public static void main(final String args[]) throws IOException {
+ final String tstname = CppReaderTest.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
}
diff --git a/src/test/java/org/anarres/cpp/ErrorTest.java b/src/test/java/com/jogamp/gluegen/jcpp/ErrorTest.java
index 42240d4..12a5160 100644
--- a/src/test/java/org/anarres/cpp/ErrorTest.java
+++ b/src/test/java/com/jogamp/gluegen/jcpp/ErrorTest.java
@@ -1,8 +1,8 @@
-package org.anarres.cpp;
+package com.jogamp.gluegen.jcpp;
import java.io.IOException;
import org.junit.Test;
-import static org.anarres.cpp.Token.*;
+import static com.jogamp.gluegen.jcpp.Token.*;
import static org.junit.Assert.*;
public class ErrorTest {
diff --git a/src/test/java/com/jogamp/gluegen/jcpp/IncludeAbsoluteTest.java b/src/test/java/com/jogamp/gluegen/jcpp/IncludeAbsoluteTest.java
new file mode 100644
index 0000000..b44b900
--- /dev/null
+++ b/src/test/java/com/jogamp/gluegen/jcpp/IncludeAbsoluteTest.java
@@ -0,0 +1,46 @@
+package com.jogamp.gluegen.jcpp;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Reader;
+
+import org.junit.Test;
+
+import com.jogamp.common.util.IOUtil;
+import com.jogamp.gluegen.Logging;
+import com.jogamp.gluegen.Logging.LoggerIf;
+import com.jogamp.gluegen.test.junit.generation.BuildEnvironment;
+
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author shevek
+ */
+public class IncludeAbsoluteTest {
+
+ private static final LoggerIf LOG = Logging.getLogger(IncludeAbsoluteTest.class);
+
+ @Test
+ public void testAbsoluteInclude() throws Exception {
+ final String filepath = BuildEnvironment.gluegenRoot + "/jcpp/src/test/resources/absolute.h" ;
+ LOG.info("filepath: " + filepath);
+
+ final File file = new File(filepath);
+ assertTrue(file.exists());
+
+ final String input = "#include <" + file.getAbsolutePath() + ">\n";
+ LOG.info("Input: " + input);
+ final Preprocessor pp = new Preprocessor();
+ pp.addInput(new StringLexerSource(input, true));
+ final Reader r = new CppReader(pp);
+ final String output = IOUtil.appendCharStream(new StringBuilder(), r).toString();
+ r.close();
+ LOG.info("Output: " + output);
+ assertTrue(output.contains("absolute-result"));
+ }
+ public static void main(final String args[]) throws IOException {
+ final String tstname = IncludeAbsoluteTest.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+}
diff --git a/src/test/java/org/anarres/cpp/JavaFileSystemTest.java b/src/test/java/com/jogamp/gluegen/jcpp/JavaFileSystemTest.java
index 6e6f834..d867fb8 100644
--- a/src/test/java/org/anarres/cpp/JavaFileSystemTest.java
+++ b/src/test/java/com/jogamp/gluegen/jcpp/JavaFileSystemTest.java
@@ -1,4 +1,4 @@
-package org.anarres.cpp;
+package com.jogamp.gluegen.jcpp;
import java.io.FileNotFoundException;
import org.junit.Test;
diff --git a/src/test/java/org/anarres/cpp/JoinReaderTest.java b/src/test/java/com/jogamp/gluegen/jcpp/JoinReaderTest.java
index bb9cc2d..628a7ec 100644
--- a/src/test/java/org/anarres/cpp/JoinReaderTest.java
+++ b/src/test/java/com/jogamp/gluegen/jcpp/JoinReaderTest.java
@@ -1,4 +1,4 @@
-package org.anarres.cpp;
+package com.jogamp.gluegen.jcpp;
import java.io.StringReader;
import org.junit.Test;
diff --git a/src/test/java/org/anarres/cpp/LexerSourceTest.java b/src/test/java/com/jogamp/gluegen/jcpp/LexerSourceTest.java
index 96ec4a3..43ccbe6 100644
--- a/src/test/java/org/anarres/cpp/LexerSourceTest.java
+++ b/src/test/java/com/jogamp/gluegen/jcpp/LexerSourceTest.java
@@ -1,33 +1,36 @@
-package org.anarres.cpp;
+package com.jogamp.gluegen.jcpp;
import java.util.Arrays;
+
import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import static org.anarres.cpp.PreprocessorTest.assertType;
-import static org.anarres.cpp.Token.*;
+
+import com.jogamp.gluegen.Logging;
+import com.jogamp.gluegen.Logging.LoggerIf;
+
+import static com.jogamp.gluegen.jcpp.PreprocessorTest.assertType;
+import static com.jogamp.gluegen.jcpp.Token.*;
import static org.junit.Assert.*;
public class LexerSourceTest {
- private static final Logger LOG = LoggerFactory.getLogger(LexerSourceTest.class);
+ private static final LoggerIf LOG = Logging.getLogger(LexerSourceTest.class);
- public static void testLexerSource(String in, boolean textmatch, int... out)
+ public static void testLexerSource(final String in, final boolean textmatch, final int... out)
throws Exception {
LOG.info("Testing '" + in + "' => "
+ Arrays.toString(out));
- StringLexerSource s = new StringLexerSource(in);
+ final StringLexerSource s = new StringLexerSource(in);
- StringBuilder buf = new StringBuilder();
+ final StringBuilder buf = new StringBuilder();
for (int i = 0; i < out.length; i++) {
- Token tok = s.token();
+ final Token tok = s.token();
LOG.info("Token is " + tok);
assertType(out[i], tok);
// assertEquals(col, tok.getColumn());
buf.append(tok.getText());
}
- Token tok = s.token();
+ final Token tok = s.token();
LOG.info("Token is " + tok);
assertType(EOF, tok);
diff --git a/src/test/java/org/anarres/cpp/NumericValueTest.java b/src/test/java/com/jogamp/gluegen/jcpp/NumericValueTest.java
index d4ea432..2d612ce 100644
--- a/src/test/java/org/anarres/cpp/NumericValueTest.java
+++ b/src/test/java/com/jogamp/gluegen/jcpp/NumericValueTest.java
@@ -1,8 +1,8 @@
-package org.anarres.cpp;
+package com.jogamp.gluegen.jcpp;
import java.io.IOException;
import org.junit.Test;
-import static org.anarres.cpp.Token.*;
+import static com.jogamp.gluegen.jcpp.Token.*;
import static org.junit.Assert.*;
/**
diff --git a/src/test/java/org/anarres/cpp/PreprocessorTest.java b/src/test/java/com/jogamp/gluegen/jcpp/PreprocessorTest.java
index 13bd944..651af98 100644
--- a/src/test/java/org/anarres/cpp/PreprocessorTest.java
+++ b/src/test/java/com/jogamp/gluegen/jcpp/PreprocessorTest.java
@@ -1,29 +1,38 @@
-package org.anarres.cpp;
+package com.jogamp.gluegen.jcpp;
+import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
+import java.util.List;
+import java.util.logging.Level;
+
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import static org.anarres.cpp.Token.*;
+
+import com.jogamp.gluegen.Logging;
+import com.jogamp.gluegen.Logging.LoggerIf;
+
+import static com.jogamp.gluegen.jcpp.Token.*;
import static org.junit.Assert.*;
public class PreprocessorTest {
- private static final Logger LOG = LoggerFactory.getLogger(PreprocessorTest.class);
+ private static final LoggerIf LOG = Logging.getLogger(PreprocessorTest.class);
private OutputStreamWriter writer;
private Preprocessor p;
@Before
public void setUp() throws Exception {
+ LOG.setLevel(Level.INFO);
final PipedOutputStream po = new PipedOutputStream();
writer = new OutputStreamWriter(po);
p = new Preprocessor();
+ // p.addFeature(Feature.DEBUG);
p.addInput(
new LexerSource(
new InputStreamReader(
@@ -35,10 +44,9 @@ public class PreprocessorTest {
}
private static class I {
-
private final String t;
- public I(String t) {
+ public I(final String t) {
this.t = t;
}
@@ -51,10 +59,28 @@ public class PreprocessorTest {
return getText();
}
}
-
- private static I I(String t) {
+ private static I I(final String t) {
return new I(t);
}
+ private static class N {
+ private final String t;
+
+ public N(final String t) {
+ this.t = t;
+ }
+
+ public String getText() {
+ return t;
+ }
+
+ @Override
+ public String toString() {
+ return getText();
+ }
+ }
+ private static N N(final String t) {
+ return new N(t);
+ }
/*
* When writing tests in this file, remember the preprocessor
@@ -63,7 +89,7 @@ public class PreprocessorTest {
* the following input line.
*/
@Test
- public void testPreprocessor() throws Exception {
+ public void test01Preprocessor() throws Exception {
/* Magic macros */
testInput("line = __LINE__\n",
I("line"), WHITESPACE, '=', WHITESPACE, NUMBER
@@ -75,7 +101,11 @@ public class PreprocessorTest {
/* Simple definitions */
testInput("#define A a /* a defined */\n", NL);
+ testInput("A /* a */\n", NL, I("a"), WHITESPACE, CCOMMENT);
+ testConstMacro("A", true, I("a"));
testInput("#define B b /* b defined */\n", NL);
+ testInput("B /* b */\n", NL, I("b"), WHITESPACE, CCOMMENT);
+ testConstMacro("B", false, I("b"));
testInput("#define C c /* c defined */\n", NL);
/* Expansion of arguments */
@@ -107,20 +137,54 @@ public class PreprocessorTest {
/* Redefinitions, undefinitions. */
testInput("#define two three\n", NL);
+ testInput("two /* three */\n", NL, I("three"), WHITESPACE, CCOMMENT);
testInput("one /* one */\n", NL, I("one"), WHITESPACE, CCOMMENT);
+ testConstMacro("two", false, I("three"));
+ testConstMacro("two", true, I("three"));
+
testInput("#define one two\n", NL);
testInput("one /* three */\n", NL, I("three"), WHITESPACE, CCOMMENT);
+ testConstMacro("one", false, I("two"));
+ testConstMacro("one", true, I("three"));
+
testInput("#undef two\n", NL);
+ testInput("one /* two */\n", NL, I("two"), WHITESPACE, CCOMMENT);
+ testConstMacro("one", false, I("two"));
+ testConstMacro("one", true, I("two"));
+
testInput("#define two five\n", NL);
testInput("one /* five */\n", NL, I("five"), WHITESPACE, CCOMMENT);
+ testConstMacro("one", false, I("two"));
+ testConstMacro("one", true, I("five"));
+
testInput("#undef two\n", NL);
testInput("one /* two */\n", NL, I("two"), WHITESPACE, CCOMMENT);
+ testConstMacro("one", false, I("two"));
+ testConstMacro("one", true, I("two"));
+
testInput("#undef one\n", NL);
testInput("#define one four\n", NL);
testInput("one /* four */\n", NL, I("four"), WHITESPACE, CCOMMENT);
+ testConstMacro("one", false, I("four"));
+ testConstMacro("one", true, I("four"));
+
testInput("#undef one\n", NL);
testInput("#define one one\n", NL);
testInput("one /* one */\n", NL, I("one"), WHITESPACE, CCOMMENT);
+ testConstMacro("one", false, I("one"));
+ testConstMacro("one", true, I("one"));
+
+ testInput("#define NUM1 1\n", NL);
+ testInput("#define NUM4 ( 1 << ( NUM1 + NUM1 ) )\n", NL);
+ testInput("NUM4 /* ( 1 << ( 1 + 1 ) ) */\n", NL,
+ '(', WHITESPACE, N("1"), WHITESPACE, LSH, WHITESPACE,
+ '(', WHITESPACE, N("1"), WHITESPACE, '+', WHITESPACE, N("1"), WHITESPACE, ')', WHITESPACE, ')',
+ WHITESPACE, CCOMMENT);
+ testConstMacro("NUM4", false, '(', WHITESPACE, N("1"), WHITESPACE, LSH, WHITESPACE,
+ '(', WHITESPACE, I("NUM1"), WHITESPACE, '+', WHITESPACE, I("NUM1"), WHITESPACE, ')',
+ WHITESPACE, ')');
+ testConstMacro("NUM4", true, '(', WHITESPACE, N("1"), WHITESPACE, LSH, WHITESPACE,
+ '(', WHITESPACE, N("1"), WHITESPACE, '+', WHITESPACE, N("1"), WHITESPACE, ')', WHITESPACE, ')');
/* Variadic macros. */
testInput("#define var(x...) a x __VA_ARGS__ b\n", NL);
@@ -186,12 +250,12 @@ public class PreprocessorTest {
Token t;
do {
t = p.token();
- LOG.warn("Remaining token " + t);
+ LOG.warning("Remaining token " + t);
} while (t.getType() != EOF);
}
@Test
- public void testPreprocessorUnterminated() throws Exception {
+ public void test02PreprocessorUnterminated() throws Exception {
testInput("#ifndef X\na\n#else\nb\n"); // Bug #16
writer.close();
@@ -199,32 +263,38 @@ public class PreprocessorTest {
Token t;
do {
t = p.token();
- LOG.warn("Remaining token " + t);
+ LOG.warning("Remaining token " + t);
} while (t.getType() != EOF);
}
- public static void assertType(int type, Token t) {
- String typeExpect = TokenType.getTokenName(type);
- String typeActual = TokenType.getTokenName(t.getType());
+ public static void assertType(final int type, final Token t) {
+ final String typeExpect = TokenType.getTokenName(type);
+ final String typeActual = TokenType.getTokenName(t.getType());
assertEquals("Expected " + typeExpect + " but got " + typeActual, type, t.getType());
}
- private void testInput(String in, Object... out)
+ private void testInput(final String in, final Object... out)
throws Exception {
LOG.info("Input: " + in);
writer.write(in);
writer.flush();
- for (Object v : out) {
- Token t = p.token();
- LOG.info(String.valueOf(t));
+ for (final Object v : out) {
+ final Token t = p.token();
+ LOG.info("READ: "+String.valueOf(t));
if (v instanceof String) {
if (t.getType() != STRING)
fail("Expected STRING, but got " + t);
assertEquals(v, t.getValue());
} else if (v instanceof I) {
- if (t.getType() != IDENTIFIER)
+ if (t.getType() != IDENTIFIER) {
fail("Expected IDENTIFIER " + v + ", but got " + t);
+ }
assertEquals(((I) v).getText(), t.getText());
+ } else if (v instanceof N) {
+ if (t.getType() != NUMBER) {
+ fail("Expected NUMBER " + v + ", but got " + t);
+ }
+ assertEquals(((N) v).getText(), t.getText());
} else if (v instanceof Character) {
assertType(((Character) v).charValue(), t);
} else if (v instanceof Integer) {
@@ -234,4 +304,69 @@ public class PreprocessorTest {
}
}
}
+ // slow ..
+ private Macro findMacro(final List<Macro> macros, final String macroName) {
+ final int count = macros.size();
+ for(int i=0; i<count; i++) {
+ final Macro m = macros.get(i);
+ if( m.getName().equals(macroName) ) {
+ return m;
+ }
+ }
+ return null;
+ }
+ private void dumpMacros(final List<Macro> macros) {
+ final int count = macros.size();
+ System.err.println("Macro count: "+count);
+ for(int i=0; i<count; i++) {
+ final Macro m = macros.get(i);
+ System.err.println(" ["+i+"]: "+m);
+ }
+ }
+ private void testConstMacro(final String macroName, final boolean expandMacro, final Object... out)
+ throws Exception {
+ final List<Macro> macros = p.getMacros(expandMacro);
+ final Macro m = findMacro(macros, macroName);
+ if( null == m ) {
+ dumpMacros(macros);
+ }
+ Assert.assertNotNull("Macro <"+macroName+"> is missing!", m);
+ Assert.assertFalse(m.isFunctionLike());
+
+ final Source s = new MacroTokenSource(m, null);
+ try {
+ for (final Object v : out) {
+ final Token t = s.token();
+ LOG.info("READ: "+String.valueOf(t));
+ if (v instanceof String) {
+ if (t.getType() != STRING) {
+ fail("Expected STRING, but got " + t);
+ }
+ assertEquals(v, t.getValue());
+ } else if (v instanceof I) {
+ if (t.getType() != IDENTIFIER) {
+ fail("Expected IDENTIFIER " + v + ", but got " + t);
+ }
+ assertEquals(((I) v).getText(), t.getText());
+ } else if (v instanceof N) {
+ if (t.getType() != NUMBER) {
+ fail("Expected NUMBER " + v + ", but got " + t);
+ }
+ assertEquals(((N) v).getText(), t.getText());
+ } else if (v instanceof Character) {
+ assertType(((Character) v).charValue(), t);
+ } else if (v instanceof Integer) {
+ assertType(((Number) v).intValue(), t);
+ } else {
+ fail("Bad object " + v.getClass());
+ }
+ }
+ } finally {
+ s.close();
+ }
+ }
+ public static void main(final String args[]) throws IOException {
+ final String tstname = PreprocessorTest.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
}
diff --git a/src/test/java/org/anarres/cpp/TokenPastingWhitespaceTest.java b/src/test/java/com/jogamp/gluegen/jcpp/TokenPastingWhitespaceTest.java
index 2e6a2b5..756425b 100644
--- a/src/test/java/org/anarres/cpp/TokenPastingWhitespaceTest.java
+++ b/src/test/java/com/jogamp/gluegen/jcpp/TokenPastingWhitespaceTest.java
@@ -1,11 +1,15 @@
-package org.anarres.cpp;
+package com.jogamp.gluegen.jcpp;
+
+import com.jogamp.common.util.IOUtil;
-import com.google.common.io.CharStreams;
import java.io.IOException;
import java.io.Reader;
+
import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+
+import com.jogamp.gluegen.Logging;
+import com.jogamp.gluegen.Logging.LoggerIf;
+
import static org.junit.Assert.*;
/**
@@ -15,11 +19,14 @@ import static org.junit.Assert.*;
*/
public class TokenPastingWhitespaceTest {
- private static final Logger LOG = LoggerFactory.getLogger(TokenPastingWhitespaceTest.class);
+ private static final LoggerIf LOG = Logging.getLogger(TokenPastingWhitespaceTest.class);
@Test
- public void testWhitespacePasting() throws IOException {
- Preprocessor pp = new Preprocessor();
+ public void test01WhitespacePasting() throws IOException {
+ final Preprocessor pp = new Preprocessor();
+ testWhitespacePastingImpl(pp);
+ }
+ void testWhitespacePastingImpl(final Preprocessor pp) throws IOException {
pp.addInput(new StringLexerSource(
"#define ONE(arg) one_##arg\n"
+ "#define TWO(arg) ONE(two_##arg)\n"
@@ -31,8 +38,8 @@ public class TokenPastingWhitespaceTest {
+ "ONE(good)\n"
+ "ONE( /* evil newline */\n"
+ " bad)\n", true));
- Reader r = new CppReader(pp);
- String text = CharStreams.toString(r).trim();
+ final Reader r = new CppReader(pp);
+ final String text = IOUtil.appendCharStream(new StringBuilder(), r).toString().trim();
LOG.info("Output is:\n" + text);
assertEquals("one_two_good\n"
+ "one_two_bad\n"
@@ -40,4 +47,9 @@ public class TokenPastingWhitespaceTest {
+ "one_good\n"
+ "one_bad", text);
}
+
+ public static void main(final String args[]) throws IOException {
+ final String tstname = TokenPastingWhitespaceTest.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
}
diff --git a/src/test/java/org/anarres/cpp/BuildMetadataTest.java b/src/test/java/org/anarres/cpp/BuildMetadataTest.java
deleted file mode 100644
index 42dc071..0000000
--- a/src/test/java/org/anarres/cpp/BuildMetadataTest.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package org.anarres.cpp;
-
-import com.google.common.base.Charsets;
-import com.google.common.io.Resources;
-import java.net.URL;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- *
- * @author shevek
- */
-public class BuildMetadataTest {
-
- private static final Logger LOG = LoggerFactory.getLogger(BuildMetadataTest.class);
-
- @Test
- public void testProperties() throws Exception {
- URL url = Resources.getResource("META-INF/jcpp.properties");
- String text = Resources.asCharSource(url, Charsets.ISO_8859_1).read();
- LOG.info("Metadata is " + text);
- }
-
- @Test
- public void testMetadata() throws Exception {
- BuildMetadata metadata = BuildMetadata.getInstance();
- LOG.info("Version is " + metadata.getVersion());
- LOG.info("BuildDate is " + metadata.getBuildDate());
- LOG.info("ChangeId is " + metadata.getChangeId());
- }
-
-}
diff --git a/src/test/java/org/anarres/cpp/IncludeAbsoluteTest.java b/src/test/java/org/anarres/cpp/IncludeAbsoluteTest.java
deleted file mode 100644
index df7ffb7..0000000
--- a/src/test/java/org/anarres/cpp/IncludeAbsoluteTest.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package org.anarres.cpp;
-
-import com.google.common.io.CharStreams;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.Reader;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import static org.junit.Assert.*;
-
-/**
- *
- * @author shevek
- */
-public class IncludeAbsoluteTest {
-
- private static final Logger LOG = LoggerFactory.getLogger(IncludeAbsoluteTest.class);
-
- @Test
- public void testAbsoluteInclude() throws Exception {
- File file = new File("build/resources/test/absolute.h");
- assertTrue(file.exists());
-
- String input = "#include <" + file.getAbsolutePath() + ">\n";
- LOG.info("Input: " + input);
- Preprocessor pp = new Preprocessor();
- pp.addInput(new StringLexerSource(input, true));
- Reader r = new CppReader(pp);
- String output = CharStreams.toString(r);
- r.close();
- LOG.info("Output: " + output);
- assertTrue(output.contains("absolute-result"));
- }
-}
diff --git a/src/test/java/org/anarres/cpp/MainTest.java b/src/test/java/org/anarres/cpp/MainTest.java
deleted file mode 100644
index 5ff7350..0000000
--- a/src/test/java/org/anarres/cpp/MainTest.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package org.anarres.cpp;
-
-import org.junit.Test;
-
-public class MainTest {
-
- @Test
- public void testMain() throws Exception {
- Main.main(new String[]{"--version"});
- }
-}