package com.jogamp.gluegen.jcpp;

import java.io.File;
import java.io.IOException;
import java.io.Reader;

import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;

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 com.jogamp.junit.util.SingletonJunitCase;

import static org.junit.Assert.*;

/**
 *
 * @author shevek
 */
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class IncludeAbsoluteTest extends SingletonJunitCase {

    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);
    }
}

@@ -985,17 +985,16 @@
 sts());%0A
-%0A
         
@@ -1010,53 +1010,415 @@
 ing 
-input = %22#include %3C%22 + file.getAbsolut
+slashifiedFilePath = IOUtil.slashify(file.getAbsolutePath(), true, false);%0A        LOG.info(%22slashifiedFilePath: %22 + slashifiedFilePath);%0A%0A        // Expects something like:%0A        //   WINDOWS: %22/C:/projects/jogamp/gluegen/jcpp/src/test/resources/absolute.h%22%0A        //   UNIX:    %22/projects/jogamp/gluegen/jcpp/src/test/resources/absolute.h%22%0A        final String input = %22#include %3C%22 + slashifiedFil
 ePath
-()
  + %22

Fix test on Windows: Use slashified absolut pathname as required by Preprocessor