package org.codehaus.mojo.natives.c;

import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Properties;

import org.codehaus.mojo.natives.linker.Linker;
import org.codehaus.mojo.natives.linker.LinkerConfiguration;

import junit.framework.TestCase;

public class CLinkerTest
    extends TestCase
{
    LinkerConfiguration config ;
    
    String basedir;
    
    public void setUp()
    {
        this.config = new LinkerConfiguration();
        this.basedir = System.getProperty( "basedir" );
        config.setWorkingDirectory( new File( basedir ) );
        config.setOutputDirectory( new File ( basedir, "target") );
        config.setOutputFileExtension( "exe" );
        config.setOutputFileName( "test" );
    }
    
    
    public void testDefaultLinkerExecutable()
        throws Exception
    {
        Linker linker = new CLinkerSimulator();
        
        linker.link( config, new ArrayList(0) );
        
        Properties properties = new Properties();
        
        properties.load( new FileInputStream( config.getOutputFilePath() ) );
        
        String cli = properties.get( "cli" ).toString();
        assertTrue( cli.startsWith( "gcc") );
        assertEquals( basedir, properties.get( "workingDirectory" ).toString() );
        assertTrue( cli.contains( "-o " + config.getOutputFilePath() ) );
        
    }

    public void testObjectFileList()
        throws Exception
    {           
        ArrayList objectFiles = new ArrayList(2);
        objectFiles.add ( new File( "file1.o" ) );
        objectFiles.add ( new File( "file2.o" ) );
                
        Linker linker = new CLinkerSimulator();
        
        linker.link( config, objectFiles );
        
        Properties properties = new Properties();
        
        properties.load( new FileInputStream( config.getOutputFilePath() ) );
        
        String cli = properties.get( "cli" ).toString();
        
        assertTrue( cli.contains( "file1.o file2.o" ) );
        
    }

}

@@ -1314,24 +1314,23 @@
 ue( cli.
-contains
+indexOf
 ( %22-o %22 
@@ -1351,32 +1351,39 @@
 tputFilePath() )
+ != -1 
  );%0A        %0A   
@@ -1984,49 +1984,516 @@
 cli.
-contains( %22file1.o file2.o%22 ) 
+indexOf( %22file1.o file2.o%22 ) != -1  );%0A        %0A    %7D%0A%0A    public void testOptions()%0A        throws Exception%0A    %7B%0A        String %5B%5D options = %7B%22-o1%22, %22-o2%22, %22-o3%22 %7D;%0A        config.setStartOptions(  options );%0A%0A        Linker linker = new CLinkerSimulator();%0A%0A        linker.link( config, new ArrayList(0) );%0A%0A        Properties properties = new Properties();%0A%0A        properties.load( new FileInputStream( config.getOutputFilePath() ) );%0A%0A        String cli = properties.get( %22cli%22 ).toString(
 );%0A
+%0A
         
 %0A   
@@ -2488,18 +2488,72 @@
         
+assertTrue( cli.indexOf( %22-o1 -o2 -o3%22 ) != -1 );%0A
 %0A    %7D%0A
+    
 %0A%7D%0A

add more CLinker tests