package com.sun.jna;

import java.lang.reflect.Method;

import junit.framework.TestCase;

public class VarArgsCheckerTest extends TestCase {

    public void testCreation() throws Exception {
        final VarArgsChecker sut = VarArgsChecker.create();
        assertNotNull(sut);
    }
    
    public void testNoVarArgs() throws Exception {
        final VarArgsChecker sut = VarArgsChecker.create();
        final Method toCheckForVarArgs = VarArgsCheckerTest.class.getMethod("testNoVarArgs", new Class[0]);
        final boolean res = sut.isVarArgs(toCheckForVarArgs);
        // no matter if JVM 1.4 or 1.5+, the result should always be false
        assertFalse("Method should not be detected as varargs", res);
    }
    
    public void testVarArgsExist() throws Exception {
        final VarArgsChecker sut = VarArgsChecker.create();
        final Method toCheckForVarArgs = VarArgsCheckerTest.class.getMethod("methodWithVarArgs", new Class[]{String[].class});
        final boolean res = sut.isVarArgs(toCheckForVarArgs);
        // this test has to run with Java 1.5+, because this has a method with
        // varargs. So the result has to be true.
        assertTrue("Method should be detected as varargs", res);
    }
    
    public void testFixedArgsOne() throws Exception {
        final VarArgsChecker checker = VarArgsChecker.create();
        final Method method = VarArgsCheckerTest.class.getMethod("methodWithOneFixedArg", new Class[]{String.class, Object[].class});
        final int res = checker.fixedArgs(method);
        // this test has to run with Java 1.5+, because this has a method with
        // varargs. So the result has to be true.
        assertEquals("Wrong number of fixed args", 1, res);
    }
    
    public void testFixedArgsTwo() throws Exception {
        final VarArgsChecker checker = VarArgsChecker.create();
        final Method method = VarArgsCheckerTest.class.getMethod("methodWithTwoFixedArgs", new Class[]{String.class, String.class, Object[].class});
        final int res = checker.fixedArgs(method);
        // this test has to run with Java 1.5+, because this has a method with
        // varargs. So the result has to be true.
        assertEquals("Wrong number of fixed args", 2, res);
    }
    
    public void methodWithVarArgs(String... args) {
        // nothing to do
    }

    public void methodWithOneFixedArg(String fmt, Object... args) {
	// nothing to do
    }

    public void methodWithTwoFixedArgs(String fmt, String fmt2, Object... args) {
	// nothing to do
    }

    public static void main(String[] args) {
        junit.textui.TestRunner.run(VarArgsCheckerTest.class);
    }
}

@@ -206,35 +206,39 @@
  VarArgsChecker 
-sut
+checker
  = VarArgsChecke
@@ -271,19 +271,23 @@
 NotNull(
-sut
+checker
 );%0A    %7D
@@ -364,35 +364,39 @@
  VarArgsChecker 
-sut
+checker
  = VarArgsChecke
@@ -428,33 +428,22 @@
  Method 
-toCheckForVarArgs
+method
  = VarAr
@@ -524,35 +524,39 @@
 l boolean res = 
-sut
+checker
 .isVarArgs(toChe
@@ -550,33 +550,22 @@
 VarArgs(
-toCheckForVarArgs
+method
 );%0A     
@@ -696,36 +696,129 @@
 varargs%22, res);%0A
- 
+%09assertEquals(%22Non-varargs should return fixed args of zero%22, 0, checker.fixedArgs(method));%0A
    
+ 
 %7D%0A    %0A    publi
@@ -891,19 +891,23 @@
 Checker 
-sut
+checker
  = VarAr
@@ -947,33 +947,22 @@
  Method 
-toCheckForVarArgs
+method
  = VarAr
@@ -1074,11 +1074,15 @@
 s = 
-sut
+checker
 .isV
@@ -1092,25 +1092,14 @@
 rgs(
-toCheckForVarArgs
+method
 );%0A 

Add test for fixedArgs value