Ejemplo n.º 1
0
NS_IMETHODIMP
nsFrameUtil::CompareRegressionData(FILE* aFile1, FILE* aFile2,PRInt32 aRegressionOutput)
{
  Node* tree1 = Node::ReadTree(aFile1);
  Node* tree2 = Node::ReadTree(aFile2);

  nsresult rv = NS_OK;
  if (!CompareTrees(tree1, tree2)) {
    // only output this if aRegressionOutput is 0
    if( 0 == aRegressionOutput ){
      printf("Regression data 1:\n");
      DumpTree(tree1, stdout, 0);
      printf("Regression data 2:\n");
      DumpTree(tree2, stdout, 0);
    }
    rv = NS_ERROR_FAILURE;
  }

  Node::Destroy(tree1);
  Node::Destroy(tree2);

  return rv;
}
Ejemplo n.º 2
0
int main(int argc, char** argv)
{
  std::string topDir;
  bool fileOutput = true;
  if (argc == 3) {
    topDir     = std::string(argv[1]);
    fileOutput = atoi(argv[2]);
  }

  std::string errTxt;
  CheckInputFiles(topDir, errTxt);
  if(errTxt == "")
    std::cout << "All files are checked for existence.\n";

  std::ifstream infile;
  NRLib::OpenRead(infile,topDir+"doc/user_manual/4_referencemanual.tex");
  std::string file;
  std::string line;
  while(!infile.eof()) {
    getline(infile, line);
    file = file+"\n"+line;
  }
  infile.close();
  std::vector<std::string> secTab(7);
  secTab[0] = "\\chapter";
  secTab[1] = "\\section";
  secTab[2] = "\\subsection";
  secTab[3] = "\\subsubsection";
  secTab[4] = "\\paragraph";
  secTab[5] = "\\subparagraph";
  secTab[6] = "\\subsubparagraph";
  TiXmlElement * root = ProcessDocLevel(file,0,secTab,0,file.size()+1);
  TiXmlDocument doc;
  doc.LinkEndChild(root);
  if (fileOutput) {
    doc.SaveFile("docgrammar.txt");
  }
  infile.clear();
  NRLib::OpenRead(infile,topDir+"src/xmlmodelfile.cpp");
  file = "";
  while(!infile.eof()) {
    getline(infile, line);
    file = file+"\n"+line;
  }
  infile.close();

  std::vector<std::string> parents;
  root = ProcessCodeLevel(file, "::parseCrava(", errTxt, parents);
  if(errTxt.size() > 0) {
    if (fileOutput) {
      std::ofstream outfile;
      NRLib::OpenWrite(outfile, "legalerrors.txt");
      outfile << errTxt;
      outfile.close();
    }
    std::cout << errTxt;
  }
  else
    std::cout << "Listing of legal commands is consistent with code.\n";

  TiXmlDocument code;
  code.LinkEndChild(root);
  if (fileOutput) {
    code.SaveFile("codegrammar.txt");
  }
  errTxt = "";
  if(CompareTrees(doc, code, errTxt) == false) {
    if (fileOutput) {
      std::ofstream outfile;
      NRLib::OpenWrite(outfile, "Grammarerrors.txt");
      outfile << errTxt;
      outfile.close();
    }
    std::cout << errTxt;
  }
  else
    std::cout << "Code and documentation are consistent.\n";
}
Ejemplo n.º 3
0
void treefriend() {
   CreateParentTree();
   CreateFriendTree();
   CompareTrees();
   DrawFriend();
}
Ejemplo n.º 4
0
PRBool
nsFrameUtil::CompareTrees(Node* tree1, Node* tree2)
{
  PRBool result = PR_TRUE;
  for (;; tree1 = tree1->next, tree2 = tree2->next) {
    // Make sure both nodes are non-null, or at least agree with each other
    if (nsnull == tree1) {
      if (nsnull == tree2) {
        break;
      }
      printf("first tree prematurely ends\n");
      return PR_FALSE;
    }
    else if (nsnull == tree2) {
      printf("second tree prematurely ends\n");
      return PR_FALSE;
    }

    // Check the attributes that we care about
    if (0 != PL_strcmp(tree1->type, tree2->type)) {
      printf("frame type mismatch: %s vs. %s\n", tree1->type, tree2->type);
      printf("Node 1:\n");
      DumpNode(tree1, stdout, 1);
      printf("Node 2:\n");
      DumpNode(tree2, stdout, 1);
      return PR_FALSE;
    }

    // Ignore the XUL scrollbar frames
    static const char kScrollbarFrame[] = "ScrollbarFrame";
    if (0 == PL_strncmp(tree1->type, kScrollbarFrame, sizeof(kScrollbarFrame) - 1))
      continue;

    if (tree1->state != tree2->state) {
      printf("frame state mismatch: 0x%x vs. 0x%x\n",
             tree1->state, tree2->state);
      printf("Node 1:\n");
      DumpNode(tree1, stdout, 1);
      printf("Node 2:\n");
      DumpNode(tree2, stdout, 1);
      result = PR_FALSE; // we have a non-critical failure, so remember that but continue
    }
    if (tree1->bbox != tree2->bbox) {
      printf("frame bbox mismatch: %d,%d,%d,%d vs. %d,%d,%d,%d\n",
             tree1->bbox.x, tree1->bbox.y,
             tree1->bbox.width, tree1->bbox.height,
             tree2->bbox.x, tree2->bbox.y,
             tree2->bbox.width, tree2->bbox.height);
      printf("Node 1:\n");
      DumpNode(tree1, stdout, 1);
      printf("Node 2:\n");
      DumpNode(tree2, stdout, 1);
      result = PR_FALSE; // we have a non-critical failure, so remember that but continue
    }
    if (tree1->styleData != tree2->styleData) {
      printf("frame style data mismatch: %s vs. %s\n",
        tree1->styleData.get(),
        tree2->styleData.get());
    }

    // Check child lists too
    NodeList* list1 = tree1->lists;
    NodeList* list2 = tree2->lists;
    for (;;) {
      if (nsnull == list1) {
        if (nsnull != list2) {
          printf("first tree prematurely ends (no child lists)\n");
          printf("Node 1:\n");
          DumpNode(tree1, stdout, 1);
          printf("Node 2:\n");
          DumpNode(tree2, stdout, 1);
          return PR_FALSE;
        }
        else {
          break;
        }
      }
      if (nsnull == list2) {
        printf("second tree prematurely ends (no child lists)\n");
        printf("Node 1:\n");
        DumpNode(tree1, stdout, 1);
        printf("Node 2:\n");
        DumpNode(tree2, stdout, 1);
        return PR_FALSE;
      }
      if (0 != PL_strcmp(list1->name, list2->name)) {
        printf("child-list name mismatch: %s vs. %s\n",
               list1->name ? list1->name : "(null)",
               list2->name ? list2->name : "(null)");
        result = PR_FALSE; // we have a non-critical failure, so remember that but continue
      }
      else {
        PRBool equiv = CompareTrees(list1->node, list2->node);
        if (!equiv) {
          return equiv;
        }
      }
      list1 = list1->next;
      list2 = list2->next;
    }
  }
  return result;
}