Example #1
0
int main(int argc, const char **argv) {
    printf("Running all tests...\n\n");

    int err;
    if ((err = setjmp(G_err))) {
    printf("ERROR: %d\n",err);
    }
    else {
    def_sys();
    //**** core tests
    testDef();
    testTree();
    testMTree();
    testStream();
    testLabel();
    testSemtrex();
    testReceptor();
    testProcess();
    testScape();
    testVMHost();
    testAccumulator();

    //***** examples
    testProfileExample();
    testHTTPExample();

    sys_free();
    report_tests();
    }
    pthread_exit(NULL);
    //    return 0;
}
int main()
{
	std::string TestPath = "/home/mason/gits/lpmc/log-parser-mysql-client/parser/src/test/test.txt";
	std::fstream testStream (TestPath.c_str(), std::ios::app | std::ios::in | std::ios::out);
	std::cout << testStream.good() << std::endl;
	std::string s = "";
	while (!testStream.eof())
	{
		if (testStream.peek() != EOF)
		std::cout << (char)testStream.get();//std::getline(testStream, s);
		else
			std::cout << "eof" << std::endl;
		//std::cout << s << std::endl;
	}
	std::cout << std::endl;
	std::getline(std::cin, s);
	testStream.seekg(0);
	testStream << s << std::endl;
	std::cout << s << std::endl;
	testStream.seekg(0);
	while (!testStream.eof())
	{
		if (testStream.peek() != EOF)
		std::cout << (char)testStream.get();//std::getline(testStream, s);
		else
			std::cout << "eof" << std::endl;
		//std::cout << s << std::endl;
	}
	std::cout << std::endl;
	testStream.close();
	return 0;
}
Example #3
0
bool createTestFiles(const QStringList &fileNames, const QString &dir)
{
    QDir curDir;
    foreach (QString fileName, fileNames) {
        QString filePath = QDir(dir).filePath(fileName);
        QDir testDir = QFileInfo(filePath).dir();
        if (!testDir.exists()) {
            if (!curDir.mkpath(testDir.path())) {
                qWarning("Couldn't mkpath %s",
                        testDir.path().toUtf8().constData());
                return false;
            }
        }
        if (fileName.endsWith('/')) {
            if (!curDir.mkpath(filePath)) {
                qWarning("Couldn't mkpath %s",
				fileName.toUtf8().constData());
                return false;
            }
        } else {
            QFile testFile(filePath);
            if (!testFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
                qWarning("Couldn't create %s",
                        fileName.toUtf8().constData());
                return false;
            }
            QTextStream testStream(&testFile);
            testStream << "This is a test file named " << fileName << endl;
        }
    }
TEST_F(TestBitStreamReadOnly, ZeroSize)
{
    vector<uint8_t> dude;

    BitStreamReadOnly testStream(dude);

    EXPECT_EQ(0, testStream.SizeInBytes());
    EXPECT_EQ(0, testStream.PositionReadBits());
}
void MCMeshLoaderTest::testSimple()
{
    QString testData(TEST_DATA_CUBE);
    QTextStream testStream(&testData);
    m_dut.readStream(testStream);

    QVERIFY(m_dut.vertices().size() == 8);
    QVERIFY(m_dut.textureCoords().size() == 36);
    QVERIFY(m_dut.normals().size() == 36);
}
Example #6
0
bool
mitk::TestDICOMLoading::CompareSpacedValueFields( const std::string& reference, 
                                                  const std::string& test,
                                                  double /*eps*/ )
{
  bool result(true);

  // tokenize string, compare each token, if possible by float comparison
  std::stringstream referenceStream(reduce(reference));
  std::stringstream testStream(reduce(test));

  std::string refToken;
  std::string testToken;
  while ( std::getline( referenceStream,  refToken, ' ' ) && 
          std::getline (     testStream, testToken, ' ' ) )
  {
    float refNumber;
    float testNumber;
    if ( this->StringToNumber(refToken, refNumber) )
    {
      MITK_DEBUG << "Reference Token '" << refToken << "'" << " value " << refNumber
                 << ", test Token '" << refToken << "'" << " value " << refNumber;
      if ( this->StringToNumber(testToken, testNumber) )
      {
        result &= ( fabs(refNumber - testNumber) < mitk::eps );
      }
      else
      {
        MITK_ERROR << refNumber << " cannot be compared to '" << testToken << "'";
      }
    }
    else
    {
      MITK_DEBUG << "Token '" << refToken << "'" << " handled as string";
      result &= refToken == testToken;
    }
  }

  if ( std::getline( referenceStream, refToken, ' ' ) )
  {
    MITK_ERROR << "Reference string still had values when test string was already parsed: ref '" << reference << "', test '" << test << "'";
    result = false;
  }
  else if ( std::getline( testStream, testToken, ' ' ) )
  {
    MITK_ERROR << "Test string still had values when reference string was already parsed: ref '" << reference << "', test '" << test << "'";
    result = false;
  }

  return result;
}
//-----------------------------------------------------------------------
void WSimpleSimulator::Init( WSolver * iSolver, std::istream & iTrainDataStream, std::istream & iTestDataStream ) // TODO make it work with data of arbitrary length
{
	WSimulator::Init( iSolver, iTrainDataStream, iTestDataStream );

	std::string ICoefficients = "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ";
	std::stringstream IStream( ICoefficients );
	for( int i = 0; i < 20; ++i ) // TODO make it not hard-codeed.
		IStream >> m_ICoefficients[ i ];

	std::string UCoefficients = "0 2000000000000 2000000000000 2000000000000 2000000000000 2000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000";
	std::stringstream testStream( UCoefficients );
	for( int i = 0; i < 20; ++i )
		testStream >> m_UCoefficients[ i ];
}
int FilterRuleTable::Main(int argc, char *argv[])
{
  // Process command-line options.
  Options options;
  ProcessOptions(argc, argv, options);

  // Open input file.
  Moses::InputFileStream testStream(options.testSetFile);

  // Read the first test sentence and determine if it is a parse tree or a
  // string.
  std::string line;
  if (!std::getline(testStream, line)) {
    // TODO Error?
    return 0;
  }
  if (line.find_first_of('<') == std::string::npos) {
    // Test sentences are strings.
    std::vector<std::vector<std::string> > sentences;
    do {
      sentences.resize(sentences.size()+1);
      ReadTokens(line, sentences.back());
    } while (std::getline(testStream, line));
    StringBasedFilter filter(sentences);
    filter.Filter(std::cin, std::cout);
  } else {
    // Test sentences are XML parse trees.
    XmlTreeParser parser;
    std::vector<boost::shared_ptr<StringTree> > sentences;
    int lineNum = 1;
    do {
      if (line.size() == 0) {
        std::cerr << "skipping blank test sentence at line " << lineNum
                  << std::endl;
        continue;
      }
      sentences.push_back(boost::shared_ptr<StringTree>(parser.Parse(line)));
      ++lineNum;
    } while (std::getline(testStream, line));
    TreeBasedFilter filter(sentences);
    filter.Filter(std::cin, std::cout);
  }

  return 0;
}
Example #9
0
int main(int argc, const char **argv) {
    printf("Running all tests...\n\n");

    int err;
    if ((err = setjmp(G_err))) {
        printf("ERROR: %d\n",err);
    }
    else {
    G_sem = def_sys();
    load_contexts(G_sem);

    //**** core tests
    testSemTable();
    testDef();
    testTree();
    testMTree();
    testStream();
    testLabel();
    testSemtrex();
    testProcess();
    testReceptor();
    testScape();
    testVMHost();
    testAccumulator();
    testProtocol();

    /**** receptor tests */
    /* /\* testGroup(); *\/ */
    testHTTP();

    /****** examples */
    /* testProfileExample(); */

    sys_free(G_sem);
    report_tests();
    }
    pthread_exit(NULL);
    //    return 0;
}
Example #10
0
static bool isFileBad(const char* fname, int extOffset, const char* upperExt){
  
  ifstream testStream(fname);

  //testing lowercase extension
  if ( testStream.good() ){
    testStream.close();
    return false;
  }
  
  //constructing uppercase extension
  std::string upperExtFname = fname;
  upperExtFname.replace(extOffset, 4, upperExt);
  testStream.open(upperExtFname.c_str());

  //testing uppercase extension
  if ( testStream.good() ){
    testStream.close();
    return false;
  }

  return true;
}
Example #11
0
bool
mitk::TestDICOMLoading::CompareSpacedValueFields( const std::string& reference,
                                                  const std::string& test,
                                                  double /*eps*/ )
{
  bool result(true);

  // tokenize string, compare each token, if possible by float comparison
  std::stringstream referenceStream(reduce(reference));
  std::stringstream testStream(reduce(test));

  std::string refToken;
  std::string testToken;
  while ( std::getline( referenceStream,  refToken, ' ' ) &&
          std::getline (     testStream, testToken, ' ' ) )
  {
    float refNumber;
    float testNumber;
    if ( this->StringToNumber(refToken, refNumber) )
    {
      if ( this->StringToNumber(testToken, testNumber) )
      {
        // print-out compared tokens if DEBUG output allowed
        MITK_DEBUG << "Reference Token '" << refToken << "'" << " value " << refNumber
                   << ", test Token '" << testToken << "'" << " value " << testNumber;

        bool old_result = result;

        result &= ( std::abs(refNumber - testNumber) < 0.0001f /*mitk::eps*/ );
        // log the token/number which causes the test to fail
        if( old_result != result)
        {
          MITK_ERROR << std::setprecision(16) << "Reference Token '" << refToken << "'" << " value " << refNumber
                     << ", test Token '" << testToken << "'" << " value " << testNumber;

          MITK_ERROR << "[FALSE] - difference: " << std::setprecision(16) <<  std::abs(refNumber - testNumber) << " EPS: " << 0.0001f; //mitk::eps;
        }
      }
      else
      {
        MITK_ERROR << refNumber << " cannot be compared to '" << testToken << "'";
      }
    }
    else
    {
      MITK_DEBUG << "Token '" << refToken << "'" << " handled as string";
      result &= refToken == testToken;
    }
  }

  if ( std::getline( referenceStream, refToken, ' ' ) )
  {
    MITK_ERROR << "Reference string still had values when test string was already parsed: ref '" << reference << "', test '" << test << "'";
    result = false;
  }
  else if ( std::getline( testStream, testToken, ' ' ) )
  {
    MITK_ERROR << "Test string still had values when reference string was already parsed: ref '" << reference << "', test '" << test << "'";
    result = false;
  }

  return result;
}
///////////////////////////////////////////////////////////////////////////////
// Parse the command line into its pieces.
///////////////////////////////////////////////////////////////////////////////
void ParseCommandLine::parseLine( int argc, char* argv[] ) {

	// Add the options piece to the usage string, because there always are at
	// least two types of options (help and version information).
	usageString += "[options]";

	// Convert the command line into strings.
	// During this process, transform all flags into lower case.
	vector<string> cmdLine;
	for( int i = 1; i < argc; i++ ) {
		string next( argv[i] );
		if( next[0] == '-' ) {
			transform( next.begin(), next.end(), next.begin(), ::tolower );
		}
		cmdLine.push_back( next );
	}
	//unsigned int length = cmdLine.size();

	// Check if a help flag exists.
	// If one does, print out a usage message, set an error, and return.
	// This isn't a real error, it's just to stop parsing and running later.
	vector<string>::iterator helpIt;
	for( unsigned int i = 1; i <= standardHelpFlags.size(); i++ ) {
		string next = standardHelpFlags[i-1];
		helpIt = find( cmdLine.begin(), cmdLine.end(), next );
		if( helpIt != cmdLine.end() ) {
			usage();
			setError();
			return;
		}
	}

	// Check if a version flag exists.
	// If one does, print out a version message, set an error, and return.
	// This isn't a real error, it's just to stop parsing and running later.
	vector<string>::iterator versionIt;
	for( unsigned int i = 1; i <= standardVersionFlags.size(); i++ ) {
		string next = standardVersionFlags[i-1];
		versionIt = find( cmdLine.begin(), cmdLine.end(), next );
		if( versionIt != cmdLine.end() ) {
			cout << interfaceName << ": Version " << version << "." << endl
			     << "Copyright Mathews Lab, University of Rochester." << endl;
			setError();
			return;
		}
	}

	// Populate the parsed data map.
	unsigned int numParams = 0;
	for( unsigned int i = 1; i <= cmdLine.size(); i++ ) {

		// Get the next command line argument.
		string next = cmdLine[i-1];

		// If the argument doesn't start with "-", call it a parameter.
		if( next[0] != '-' ) {
			numParams++;
			stringstream paramStream( stringstream::in | stringstream::out );
			paramStream << "param" << numParams;
			parsedData[paramStream.str()] = next;
		}

		// Otherwise, process the flag.
		else {
			// Create a variable to track whether the flag exists.
			bool exists = false;

			// Check the flag against the possible flags with no parameters.
			// Set the flag's value if found.
			set<string>::iterator it1;
			set<string> s1 = lowerOptionsNoFlags;
			for( it1 = s1.begin(); it1 != s1.end(); it1++ ) {
				string flag = *it1;
				if( next == flag ) {
					parsedData[next] = "";
					exists = true;
				}
			}

			// Check the flag against the possible options with parameters.
			// Set the flag's value if found.
			// Only do this if a flag wasn't previously found.
			if( exists == false ) {
				set<string>::iterator it2;
				set<string> s2 = lowerOptionsWithFlags;
				for( it2 = s2.begin(); it2 != s2.end(); it2++ ) {
					string flag = *it2;
					if( next == flag ) {
						bool noParam =
							( i == cmdLine.size() ) ||
							( cmdLine[i][0] == '-' );
						if( noParam == true ) {
							double test = 0.0;
							stringstream testStream( cmdLine[i] );
							if( testStream >> test ) { noParam = false; }
						}

						if( noParam ) {
							cerr << "Option missing for flag: " << next << endl;
							setError();
							return;
						} else {
							parsedData[next] = cmdLine[i];
							exists = true;
							i++;
						}
					}
				}
			}
int main(int argc, const char** argv) {
    testStream(argv[1]);
}
Example #14
0
void MCMeshLoaderTest::testFace()
{
    QString testData(TEST_DATA_CUBE);
    QTextStream testStream(&testData);
    m_dut.readStream(testStream);

    QVERIFY(m_dut.faces().size() == 12);

    MCMesh::Face face0 = m_dut.faces().at(0);
    QVERIFY(face0.vertices.size() == 3);
    QVERIFY(qFuzzyCompare(face0.vertices.at(0).x, -0.5f));
    QVERIFY(qFuzzyCompare(face0.vertices.at(0).y, -0.5f));
    QVERIFY(qFuzzyCompare(face0.vertices.at(0).z,  0.5f));
    QVERIFY(qFuzzyCompare(face0.vertices.at(0).u,  1.0f));
    QVERIFY(qFuzzyCompare(face0.vertices.at(0).v,  0.0f));
    QVERIFY(qFuzzyCompare(face0.vertices.at(0).i,  0.0f));
    QVERIFY(qFuzzyCompare(face0.vertices.at(0).j,  0.0f));
    QVERIFY(qFuzzyCompare(face0.vertices.at(0).k,  1.0f));

    QVERIFY(qFuzzyCompare(face0.vertices.at(1).x,  0.5f));
    QVERIFY(qFuzzyCompare(face0.vertices.at(1).y, -0.5f));
    QVERIFY(qFuzzyCompare(face0.vertices.at(1).z,  0.5f));
    QVERIFY(qFuzzyCompare(face0.vertices.at(1).u,  0.0f));
    QVERIFY(qFuzzyCompare(face0.vertices.at(1).v,  0.0f));
    QVERIFY(qFuzzyCompare(face0.vertices.at(1).i,  0.0f));
    QVERIFY(qFuzzyCompare(face0.vertices.at(1).j,  0.0f));
    QVERIFY(qFuzzyCompare(face0.vertices.at(1).k,  1.0f));

    QVERIFY(qFuzzyCompare(face0.vertices.at(2).x, -0.5f));
    QVERIFY(qFuzzyCompare(face0.vertices.at(2).y,  0.5f));
    QVERIFY(qFuzzyCompare(face0.vertices.at(2).z,  0.5f));
    QVERIFY(qFuzzyCompare(face0.vertices.at(2).u,  0.0f));
    QVERIFY(qFuzzyCompare(face0.vertices.at(2).v,  1.0f));
    QVERIFY(qFuzzyCompare(face0.vertices.at(2).i,  0.0f));
    QVERIFY(qFuzzyCompare(face0.vertices.at(2).j,  0.0f));
    QVERIFY(qFuzzyCompare(face0.vertices.at(2).k,  1.0f));

    MCMesh::Face face11 = m_dut.faces().at(11);
    QVERIFY(face11.vertices.size() == 3);
    QVERIFY(qFuzzyCompare(face11.vertices.at(0).x,  0.5f));
    QVERIFY(qFuzzyCompare(face11.vertices.at(0).y, -0.5f));
    QVERIFY(qFuzzyCompare(face11.vertices.at(0).z,  0.5f));
    QVERIFY(qFuzzyCompare(face11.vertices.at(0).u,  0.0f));
    QVERIFY(qFuzzyCompare(face11.vertices.at(0).v,  1.0f));
    QVERIFY(qFuzzyCompare(face11.vertices.at(0).i,  0.0f));
    QVERIFY(qFuzzyCompare(face11.vertices.at(0).j, -1.0f));
    QVERIFY(qFuzzyCompare(face11.vertices.at(0).k,  0.0f));

    QVERIFY(qFuzzyCompare(face11.vertices.at(1).x, -0.5f));
    QVERIFY(qFuzzyCompare(face11.vertices.at(1).y, -0.5f));
    QVERIFY(qFuzzyCompare(face11.vertices.at(1).z,  0.5f));
    QVERIFY(qFuzzyCompare(face11.vertices.at(1).u,  0.0f));
    QVERIFY(qFuzzyCompare(face11.vertices.at(1).v,  0.0f));
    QVERIFY(qFuzzyCompare(face11.vertices.at(1).i,  0.0f));
    QVERIFY(qFuzzyCompare(face11.vertices.at(1).j, -1.0f));
    QVERIFY(qFuzzyCompare(face11.vertices.at(1).k,  0.0f));

    QVERIFY(qFuzzyCompare(face11.vertices.at(2).x, -0.5f));
    QVERIFY(qFuzzyCompare(face11.vertices.at(2).y, -0.5f));
    QVERIFY(qFuzzyCompare(face11.vertices.at(2).z, -0.5f));
    QVERIFY(qFuzzyCompare(face11.vertices.at(2).u,  1.0f));
    QVERIFY(qFuzzyCompare(face11.vertices.at(2).v,  0.0f));
    QVERIFY(qFuzzyCompare(face11.vertices.at(2).i,  0.0f));
    QVERIFY(qFuzzyCompare(face11.vertices.at(2).j, -1.0f));
    QVERIFY(qFuzzyCompare(face11.vertices.at(2).k,  0.0f));
}
Example #15
0
void testIStreamWay() {
	std::stringstream testStream("3%2");
	ASSERT_EQUAL(1, calc(testStream));
}