Exemple #1
0
 /** dynamic execution of all public methods that begin with "test" in all CLASSES */
 protected void test(STClass[] classes) {
   for (int i = 0; i < classes.length; i++) {
     if (jdkOK(classes[i])) {
       System.out.println("  S.O.D.A. testing " + classes[i].getClass().getName());
       currentTestClass = classes[i];
       Method[] methods = classes[i].getClass().getDeclaredMethods();
       for (int j = 0; j < methods.length; j++) {
         Method method = methods[j];
         if (method.getName().startsWith("test")) {
           try {
             method.invoke(classes[i], new Object[0]);
           } catch (Exception e) {
             e.printStackTrace();
           }
         }
       }
     }
   }
 }
  public boolean isEqual(Object a_compare, Object a_with, String a_path, Stack a_stack) {
    if (a_path == null || a_path.length() < 1) {
      if (a_compare != null) {
        a_path = a_compare.getClass().getName() + ":";
      } else {
        if (a_with != null) {
          a_path = a_with.getClass().getName() + ":";
        }
      }
    }

    String path = a_path;

    if (a_compare == null) {
      return a_with == null;
    }
    if (a_with == null) {
      return false;
    }
    Class clazz = a_compare.getClass();
    if (clazz != a_with.getClass()) {
      return false;
    }

    if (isSimple(clazz)) {
      return a_compare.equals(a_with);
    }

    if (a_stack == null) {
      a_stack = new Stack();
    }

    // takes care of repeating calls to the same object
    if (a_stack.contains(a_compare)) {
      return true;
    }
    a_stack.push(a_compare);

    Field fields[] = clazz.getDeclaredFields();
    for (int i = 0; i < fields.length; i++) {
      if (storeableField(clazz, fields[i])) {
        Platform4.setAccessible(fields[i]);
        try {
          path = a_path + fields[i].getName() + ":";
          Object compare = fields[i].get(a_compare);
          Object with = fields[i].get(a_with);
          if (compare == null) {
            if (with != null) {
              return false;
            }
          } else if (with == null) {
            return false;
          } else {
            if (compare.getClass().isArray()) {
              if (!with.getClass().isArray()) {
                return false;
              } else {
                compare = normalizeNArray(compare);
                with = normalizeNArray(with);
                int len = Array.getLength(compare);
                if (len != Array.getLength(with)) {
                  return false;
                } else {
                  for (int j = 0; j < len; j++) {
                    Object elementCompare = Array.get(compare, j);
                    Object elementWith = Array.get(with, j);
                    //										if (l_persistentArray)
                    if (!isEqual(elementCompare, elementWith, path, a_stack)) {
                      return false;
                    } else if (elementCompare == null) {
                      if (elementWith != null) {
                        return false;
                      }
                    } else if (elementWith == null) {
                      return false;
                    } else {
                      Class elementCompareClass = elementCompare.getClass();
                      if (elementCompareClass != elementWith.getClass()) {
                        return false;
                      }
                      if (hasPublicConstructor(elementCompareClass)) {
                        if (!isEqual(elementCompare, elementWith, path, a_stack)) {
                          return false;
                        }
                      } else if (!elementCompare.equals(elementWith)) {
                        return false;
                      }
                    }
                  }
                }
              }
            } else if (hasPublicConstructor(fields[i].getType())) {
              if (!isEqual(compare, with, path, a_stack)) {
                return false;
              }
            } else {
              if (!compare.equals(with)) {
                return false;
              }
            }
          }
        } catch (IllegalAccessException ex) {
          // probably JDK 1
          // never mind this field
          return true;
        } catch (Exception e) {
          System.err.println("STCompare failure executing path:" + path);
          e.printStackTrace();
          return false;
        }
      }
    }
    return true;
  }