예제 #1
0
// the common test code
//
void tempStream::DoTest(Action action, bool shouldHaveCommited)
{
    TestFile temp;

    {
        wxTempFileOutputStream out(temp.GetName());
        out.Write("Affer", 5);
        CPPUNIT_ASSERT(out.SeekO(2) == 2);
        out.Write("t", 1);
        CPPUNIT_ASSERT(out.IsSeekable());
        CPPUNIT_ASSERT(out.GetLength() == 5);
        CPPUNIT_ASSERT(out.TellO() == 3);

        switch (action) {
            case DONOTHING: break;
            case COMMIT:    out.Commit(); break;
            case DISCARD:   out.Discard(); break;
            case CLOSE:     out.Close();
        }
    }

    wxFileInputStream in(temp.GetName());
    char buf[32];
    in.Read(buf, sizeof(buf));
    buf[in.LastRead()] = 0;
    CPPUNIT_ASSERT(strcmp(buf, shouldHaveCommited ? "After" : "Before") == 0);
}
예제 #2
0
파일: filetest.cpp 프로젝트: euler0/Helium
void FileTestCase::DoRoundTripTest(const wxMBConv& conv)
{
    TestFile tf;

    const wxString data = "Hello\0UTF";

    {
        wxFile fout(tf.GetName(), wxFile::write);
        CPPUNIT_ASSERT( fout.IsOpened() );

        CPPUNIT_ASSERT( fout.Write(data, conv) );
    }

    {
        wxFile fin(tf.GetName(), wxFile::read);
        CPPUNIT_ASSERT( fin.IsOpened() );

        const ssize_t len = fin.Length();
        wxCharBuffer buf(len);
        CPPUNIT_ASSERT_EQUAL( len, fin.Read(buf.data(), len) );

        wxWCharBuffer wbuf(conv.cMB2WC(buf));
#if wxUSE_UNICODE
        CPPUNIT_ASSERT_EQUAL( data, wbuf );
#else // !wxUSE_UNICODE
        CPPUNIT_ASSERT
        (
            memcmp(wbuf, L"Hello\0UTF", data.length()*sizeof(wchar_t)) == 0
        );
#endif // wxUSE_UNICODE/!wxUSE_UNICODE
    }
}
예제 #3
0
void FileTestCase::DoRoundTripTest(const wxMBConv& conv)
{
    TestFile tf;

    // Explicit length is needed because of the embedded NUL.
    const wxString data("Hello\0UTF!", 10);

    {
        wxFile fout(tf.GetName(), wxFile::write);
        CPPUNIT_ASSERT( fout.IsOpened() );

        CPPUNIT_ASSERT( fout.Write(data, conv) );
    }

    {
        wxFile fin(tf.GetName(), wxFile::read);
        CPPUNIT_ASSERT( fin.IsOpened() );

        const ssize_t len = fin.Length();
        wxCharBuffer buf(len);
        CPPUNIT_ASSERT_EQUAL( len, fin.Read(buf.data(), len) );

        wxString dataReadBack(buf, conv, len);
        CPPUNIT_ASSERT_EQUAL( data, dataReadBack );
    }
}
예제 #4
0
bool test()
{
  bool t1, t2, t3, t4;
  TestFile tf;
  t1 = tf.test();
  TestFileInfo tfi;
  t2 = tfi.test();
  TestPath tp;
  t3 = tp.test();
  TestDirectory td;
  t4 = td.test();
  return t1 && t2 && t3;
}
예제 #5
0
void FileTestCase::ReadAll()
{
    TestFile tf;

    const char* text = "Ream\nde";

    {
        wxFile fout(tf.GetName(), wxFile::write);
        CPPUNIT_ASSERT( fout.IsOpened() );
        fout.Write(text, strlen(text));
        CPPUNIT_ASSERT( fout.Close() );
    }

    {
        wxFile fin(tf.GetName(), wxFile::read);
        CPPUNIT_ASSERT( fin.IsOpened() );

        wxString s;
        CPPUNIT_ASSERT( fin.ReadAll(&s) );
        CPPUNIT_ASSERT_EQUAL( text, s );
    }
}
예제 #6
0
/**
 * @return true if the Validator behaved as expected when validating
 * TestFile, false otherwise.
 */
bool
TestValidator::test (const TestFile& file)
{
    bool error = false;

    unsigned int id       = file.getConstraintId();

    /* change numbers for specific units tests that report same number */
    if (id == 99502 || id == 99503 || id == 99504)
        id = 10501;

    /* change numbers for specific units tests that report same number */
    if (id == 90502 || id == 90503 || id == 90504)
        id = 90501;

    unsigned int expected = file.getNumFailures();
    unsigned int others   = file.getAdditionalFailId();

    unsigned int actual   = mValidator.validate( file.getFullname() );

    list<SBMLError>::const_iterator begin = mValidator.getFailures().begin();
    list<SBMLError>::const_iterator end   = mValidator.getFailures().end();



    if (expected != actual)
    {
        error = true;

        cout << endl;
        cout << "Error: " << file.getFilename() << endl;
        cout << "  - Failures:  Expected: "  << expected << "  Actual: " << actual;
        cout << endl << endl;
    }


    unsigned int same = count_if(begin, end, HasId(id));
    vector<unsigned int> ids;

    if (expected != same && actual != same)
    {
        // need to consider case where the test case has
        // an additional fail
        if (expected - same != 1)
        {
            error = true;
        }
        else
        {
            transform(begin, end, back_inserter(ids), ToId());

            unsigned int match = 0;
            for (unsigned int i = 0; i < ids.size(); i++)
            {
                if (ids.at(i) == others)
                {
                    match = 1;
                }
            }

            if (match == 0)
            {
                error = true;
            }
        }
    }

    if (error)
    {
        cout << endl;
        cout << "Error: " << file.getFilename() << endl;
        cout << "  - Constraints:  Expected: " << id << "  Actual: ";
        cout << endl;
        copy(ids.begin(), ids.end(), ostream_iterator<unsigned int>(cout, " "));
        cout << endl;
    }

    if ( error || isVerbose(id) )
    {
        copy(begin, end, ostream_iterator<SBMLError>(cout, "\n"));
    }

    mValidator.clearFailures();

    return error == false;
}
예제 #7
0
/**
 * @return true if the Validator behaved as expected when validating
 * TestFile, false otherwise.
 */
bool
TestValidator::test (const TestFile& file)
{
  bool error = false;

  unsigned int id       = file.getConstraintId();

  /* change numbers for specific units tests that report same number */
  if (id == 99502 || id == 99503 || id == 99504)
    id = 10501;

  /* change numbers for specific units tests that report same number */
  if (id == 90502 || id == 90503 || id == 90504)
    id = 90501;

  unsigned int expected = file.getNumFailures();
  unsigned int others   = file.getAdditionalFailId();
  unsigned int num = file.getSequenceId();

  /* for 10311 called using just the id validator you will get 99303
     unless it is from units on a cn element (ie case 31*/
  if (id == 10311 && expected == 1 && num != 31)
  {
    expected = 2;
    others = 99303;
  }

  /* for my new compatibility constraints some will only apply to certain levels
   * so adjust these here
   */
  if (id == 98001)
  {
    if (mValidator.getConsistencyLevel() == 3) expected = 0;
  }

  if (id == 98003)
  {
    if (mValidator.getConsistencyLevel() == 1)
    {
      if (num == 12) 
      {
        others = 91001;
        expected = 2;
      }
    }
  }
  if (id == 98004)
  {
    if (mValidator.getConsistencyLevel() == 1) 
    {
      if (num < 12 && num > 7)
      {
        others = 91001;
        expected = 2;
      }
      else if (num == 6)
      {
        others = 91003;
        expected = 2;
      }
      else if (num == 2)
      {
        others = 91004;
        expected = 2;
      }
      else if (num == 1)
      {
        others = 91002;
        expected = 2;
      }
    }
 /*   if (num == 10 && mValidator.getConsistencyLevel() == 2) 
    {
      others = 92011;
      expected = 2;
    }*/
    if (num == 6 && ((mValidator.getConsistencyLevel() == 2 
                   && mValidator.getConsistencyVersion() == 1)))
    {
      others = 92001;
      expected = 2;
    }
    if (num == 2 && ((mValidator.getConsistencyLevel() == 2 
                   && mValidator.getConsistencyVersion() == 1)))
    {
      others = 92002;
      expected = 2;
    }
  }
  if (id == 98005)
  {
    if (mValidator.getConsistencyLevel() == 1) 
    {
        expected = 1;
        id = 91001;
    }
  }
  if (id == 98006)
  {
    if (num > 1 && ((mValidator.getConsistencyLevel() == 2
      && mValidator.getConsistencyVersion() == 1)
      || (mValidator.getConsistencyLevel() == 1)))
    {
      others = 92002;
      if (mValidator.getConsistencyLevel() == 1)
        others = 91004;
      expected = expected + 1;
    }
  }
  if (id == 98007)
  {
    if (num < 3 && ((mValidator.getConsistencyLevel() == 2 
                   && mValidator.getConsistencyVersion() == 1)
                   || (mValidator.getConsistencyLevel() == 1)))
    {
      others = 92001;
      if (mValidator.getConsistencyLevel() == 1)
        others = 91003;
      expected = 2;
    }
  }
  if (id == 98009)
  {
    if (mValidator.getConsistencyLevel() == 1)
    {
      others = 91004;
      expected = 2;
    }
    else if (mValidator.getConsistencyLevel() == 2 && mValidator.getConsistencyVersion() == 1)
    {
      others = 92002;
      expected = 2;
    }
  }
//  cout << file.getFilename() << endl;
/* NOTE: the error 10218 relating to number of child elements to a 
 * piece/otherwise element is very difficult to synchronise 
 *
 * I went with leaving the result of the read unchanged 
 * but actually logging the errors
 */
  if (id == 99219 && num == 32)
  {
    expected = 2;
  }
  if (id == 10218 && num == 12 && expected == 1)
  {
    expected = 2;
    others = 10213;
  }
  if (id == 10218 && num == 10 && expected == 2)
  {
    expected = 1;
  }
  unsigned int actual   = mValidator.validate( file.getFullname() );

  list<SBMLError>::const_iterator begin = mValidator.getFailures().begin();
  list<SBMLError>::const_iterator end   = mValidator.getFailures().end();



  if (expected != actual)
  {
    error = true;

    cout << endl;
    cout << "Error: " << file.getFilename() << endl;
    cout << "  - Failures:  Expected: "  << expected << "  Actual: " << actual;
    cout << endl << endl;
  }


  unsigned int same = (unsigned int)count_if(begin, end, HasId(id));
  vector<unsigned int> ids;

  if (expected != same && actual != same)
  {
    // need to consider case where the test case has
    // an additional fail
    if (expected - same != 1)
    {
      error = true;
    }
    else
    {
      transform(begin, end, back_inserter(ids), ToId());

      unsigned int match = 0;
      for (unsigned int i = 0; i < ids.size(); i++)
      {
        if (others != 0 && ids.at(i) == others)
        {
          match = 1;
        }
      }

      if (match == 0)
      {
        error = true;
      }
    }
  }

  if (error)
  {      
    cout << endl;
    cout << "Error: " << file.getFilename() << endl;
    cout << "  - Constraints:  Expected: " << id << "  Actual: ";
    cout << endl;
    copy(ids.begin(), ids.end(), ostream_iterator<unsigned int>(cout, " "));
    cout << endl;
  }

  if ( error || isVerbose(id) )
  {
    copy(begin, end, ostream_iterator<SBMLError>(cout, "\n"));
  }

  mValidator.clearFailures();

  return error == false;
}
예제 #8
0
/**
 * @return true if the Validator behaved as expected when validating
 * TestFile, false otherwise.
 */
bool
TestValidator::test (const TestFile& file)
{
  bool error = false;

  unsigned int id       = file.getConstraintId();
  unsigned int expected = file.getNumFailures();
  unsigned int others   = file.getAdditionalFailId();

  unsigned int actual   = mValidator.validate( file.getFullname() );


  list<SBMLError>::const_iterator begin = mValidator.getFailures().begin();
  list<SBMLError>::const_iterator end   = mValidator.getFailures().end();



  if (expected != actual)
  {
    error = true;

    cout << endl;
    cout << "Error: " << file.getFilename() << endl;
    cout << "  - Failures:  Expected: "  << expected << "  Actual: " << actual;
    cout << endl << endl;
  }


  vector<unsigned int> ids;
  transform(begin, end, back_inserter(ids), ToId());

  if (id == 1021204 && ids.at(0) == 99108)
  {
    id = 99108;
  }

  unsigned int same = (unsigned int)count_if(begin, end, HasId(id));

  if (expected != same && actual != same)
  {
    // need to change report if we needed a package to be implemented
    //but this version of libsbml does not have the package
    if (id == 1021204)
    {

    }
    // need to consider case where the test case has
    // an additional fail
    if (expected - same != 1)
    {
      error = true;
    }
    else
    {
      unsigned int match = 0;
      for (unsigned int i = 0; i < ids.size(); i++)
      {
        if (others != 0 && ids.at(i) == others)
        {
          match = 1;
        }
      }

      if (match == 0)
      {
        error = true;
      }
    }
  }

  if (error)
  {      
    cout << endl;
    cout << "Error: " << file.getFilename() << endl;
    cout << "  - Constraints:  Expected: " << id << "  Actual: ";
    cout << endl;
    copy(ids.begin(), ids.end(), ostream_iterator<unsigned int>(cout, " "));
    cout << endl;
  }

  if ( error || isVerbose(id) )
  {
    copy(begin, end, ostream_iterator<SBMLError>(cout, "\n"));
  }

  mValidator.clearFailures();

  return error == false;
}