Exemple #1
0
 public List<CompilationError> failCompile() {
   try {
     strategy.compile();
     throw AbstractTestCase.failure("Was expecting compilation to fail");
   } catch (CompilationException e) {
     return e.getErrors();
   } catch (Exception e) {
     throw AbstractTestCase.failure(e);
   }
 }
Exemple #2
0
 public void assertRemove(String... names) {
   try {
     I path = strategy.sourcePath.getPath(names);
     if (path == null) {
       throw AbstractTestCase.failure("Cannot remove path " + Tools.join('/', names));
     }
     strategy.sourcePath.removePath(path);
   } catch (Exception e) {
     throw AbstractTestCase.failure(e);
   }
 }
Exemple #3
0
 public JavaFile<I> assertJavaFile(String... names) {
   I path;
   try {
     path = strategy.sourcePath.getPath(names);
   } catch (IOException e) {
     throw AbstractTestCase.failure(e);
   }
   if (path == null) {
     throw AbstractTestCase.failure(
         "Was not expecting " + Arrays.asList(names) + " to be null file");
   }
   return new JavaFile<I>(strategy.sourcePath, path);
 }
 @Deployment
 public static WebArchive getDeployment() {
   return AbstractTestCase.getDeployment()
       .addClasses(LoggingParticipant.class, AbstractTestCase.class)
       .addAsWebInfResource(new File("../test-classes", "web.xml"), "web.xml")
       .addAsManifestResource(new StringAsset(DEPENDENCIES), "MANIFEST.MF");
 }
Exemple #5
0
  public CompilerAssert(
      boolean incremental,
      ReadWriteFileSystem<I> sourcePath,
      ReadWriteFileSystem<O> sourceOutput,
      ReadWriteFileSystem<O> classOutput) {
    ClassLoader baseClassLoader = Thread.currentThread().getContextClassLoader();

    //
    ClassLoaderFileSystem classPath = classPathCache.get(baseClassLoader);
    if (classPath == null) {
      try {
        classPathCache.put(baseClassLoader, classPath = new ClassLoaderFileSystem(baseClassLoader));
      } catch (IOException e) {
        throw AbstractTestCase.failure(e);
      }
    }

    //
    this.strategy =
        incremental
            ? new CompileStrategy.Incremental<I, O>(
                classPath, sourcePath, sourceOutput, classOutput, META_MODEL_PROCESSOR_FACTORY)
            : new CompileStrategy.Batch<I, O>(
                classPath, sourcePath, sourceOutput, classOutput, META_MODEL_PROCESSOR_FACTORY);

    //
    this.baseClassLoader = baseClassLoader;
  }
Exemple #6
0
 public Class<?> assertClass(String className) {
   try {
     return classLoader.loadClass(className);
   } catch (ClassNotFoundException e) {
     throw AbstractTestCase.failure(e);
   }
 }
Exemple #7
0
 public MockApplication<?> application(InjectImplementation injectImplementation, QN name) {
   try {
     return new MockApplication<O>(getClassOutput(), classLoader, injectImplementation, name);
   } catch (Exception e) {
     throw AbstractTestCase.failure(e);
   }
 }
Exemple #8
0
 public Compiler assertCompile() {
   try {
     strategy.compile();
     classLoader = new URLClassLoader(new URL[] {strategy.classOutput.getURL()}, baseClassLoader);
     return strategy.compiler;
   } catch (Exception e) {
     throw AbstractTestCase.failure(e);
   }
 }
  public void setUp() {
    super.setUp();

    lista =
        new List<Integer>() {

          @Override
          public boolean add(Integer e) {
            // TODO Auto-generated method stub
            return false;
          }

          @Override
          public void add(int index, Integer element) {
            // TODO Auto-generated method stub

          }

          @Override
          public boolean addAll(Collection<? extends Integer> c) {
            // TODO Auto-generated method stub
            return false;
          }

          @Override
          public boolean addAll(int index, Collection<? extends Integer> c) {
            // TODO Auto-generated method stub
            return false;
          }

          @Override
          public void clear() {
            // TODO Auto-generated method stub

          }

          @Override
          public boolean contains(Object o) {
            // TODO Auto-generated method stub
            return false;
          }

          @Override
          public boolean containsAll(Collection<?> c) {
            // TODO Auto-generated method stub
            return false;
          }

          @Override
          public Integer get(int index) {
            // TODO Auto-generated method stub
            return null;
          }

          @Override
          public int indexOf(Object o) {
            // TODO Auto-generated method stub
            return 0;
          }

          @Override
          public boolean isEmpty() {
            // TODO Auto-generated method stub
            return false;
          }

          @Override
          public Iterator<Integer> iterator() {
            // TODO Auto-generated method stub
            return null;
          }

          @Override
          public int lastIndexOf(Object o) {
            // TODO Auto-generated method stub
            return 0;
          }

          @Override
          public ListIterator<Integer> listIterator() {
            // TODO Auto-generated method stub
            return null;
          }

          @Override
          public ListIterator<Integer> listIterator(int index) {
            // TODO Auto-generated method stub
            return null;
          }

          @Override
          public boolean remove(Object o) {
            // TODO Auto-generated method stub
            return false;
          }

          @Override
          public Integer remove(int index) {
            // TODO Auto-generated method stub
            return null;
          }

          @Override
          public boolean removeAll(Collection<?> c) {
            // TODO Auto-generated method stub
            return false;
          }

          @Override
          public boolean retainAll(Collection<?> c) {
            // TODO Auto-generated method stub
            return false;
          }

          @Override
          public Integer set(int index, Integer element) {
            // TODO Auto-generated method stub
            return null;
          }

          @Override
          public int size() {
            // TODO Auto-generated method stub
            return 0;
          }

          @Override
          public List<Integer> subList(int fromIndex, int toIndex) {
            // TODO Auto-generated method stub
            return null;
          }

          @Override
          public Object[] toArray() {
            // TODO Auto-generated method stub
            return null;
          }

          @Override
          public <T> T[] toArray(T[] a) {
            // TODO Auto-generated method stub
            return null;
          }
        };
    lista.clear();
    lista.add(1);
    lista.add(3);
    lista.add(5);
    lista.add(8);
  }
Exemple #10
0
  public static void main(String[] args) {

    if (args.length != 0) {

      if (args[0].equals("-h") || args[0].equals("--help")) {

        System.err.println(
            "To use this main, you can either run the program with no "
                + "command line arguments to run all test cases or you can specify one or more classes to test");
        System.err.println("For example:");
        System.err.println(
            "java testcasesupport.Main testcases.CWE690_Unchecked_Return_Value_to_NULL_Pointer_Dereference.custom_function.CWE690_Unchecked_Return_Value_to_NULL_Pointer_Dereference__custom_function_01 testcases.CWE481_Assigning_instead_of_Comparing.bool.CWE481_Assigning_instead_of_Comparing__bool_01");
        System.exit(1);
      }

      /* User supplied some class names on the command line, just use those with introspection
       *
       * String classNames[] = { "CWE481_Assigning_instead_of_Comparing__boolean_01",
       *		"CWE476_Null_Pointer_Dereference__getProperty_01" };
       * could read class names from command line or use
       * http://sadun-util.sourceforge.net/api/org/sadun/util/
       * ClassPackageExplorer.html
       */

      for (String className : args) {

        try {

          /* String classNameWithPackage = "testcases." + className; */

          /* IO.writeLine("classNameWithPackage = " + classNameWithPackage); */

          Class<?> myClass = Class.forName(className);

          AbstractTestCase myObject = (AbstractTestCase) myClass.newInstance();

          myObject.runTest(className);

        } catch (Exception ex) {

          IO.writeLine("Could not run test for class " + className);
          ex.printStackTrace();
        }

        IO.writeLine(""); /* leave a blank line between classes */
      }

    } else {

      /* No command line args were used, we want to run every testcase */

      /* needed to separate these calls into other methods because
      we were running into the size limit Java has for a single method */
      runTestCWE1();
      runTestCWE2();
      runTestCWE3();
      runTestCWE4();
      runTestCWE5();
      runTestCWE6();
      runTestCWE7();
      runTestCWE8();
      runTestCWE9();
    }
  }
 @Override
 @Inject
 public void setConvertedField(@Named("classpathResource") URL convertedField) {
   super.setConvertedField(convertedField);
 }