Exemple #1
0
TEST(TestStrand, TypeErasedCall)
{
  boost::shared_ptr<MyActor> obj(new MyActor);
  qi::AnyObject aobj(obj);

  EXPECT_EQ(42, aobj.async<int>("val").value());
  EXPECT_TRUE(aobj.async<int>("thrw").hasError());
  EXPECT_TRUE(aobj.async<int>("fail").hasError());

  EXPECT_EQ(42, aobj.call<int>("val"));
  EXPECT_ANY_THROW(aobj.call<int>("thrw"));
  EXPECT_ANY_THROW(aobj.call<int>("fail"));
}
TEST_F(InstanceTest, String_invalid_constructions) {
    EXPECT_ANY_THROW(StringInstance("42"));
    EXPECT_ANY_THROW(StringInstance("create:", std::vector<std::string>()));
    EXPECT_ANY_THROW(StringInstance("createIfNotExists:", std::vector<std::string>()));
    EXPECT_ANY_THROW(StringInstance("create:withValue:", std::vector<std::string>({"str"})));
    EXPECT_ANY_THROW(StringInstance("create:withValue:", std::vector<std::string>({"str", "42"})));
    EXPECT_ANY_THROW(StringInstance("create:withValue:", std::vector<std::string>({"\"knuckleball\"", "str"})));
    EXPECT_ANY_THROW(StringInstance("createIfNotExists:withValue:", std::vector<std::string>({"str"})));
    EXPECT_ANY_THROW(StringInstance("createIfNotExists:withValue:", std::vector<std::string>({"str", "42"})));
    EXPECT_ANY_THROW(StringInstance("createIfNotExists:withValue:", std::vector<std::string>({"\"knuckleball\"", "str"})));
}
Exemple #3
0
TEST(TStr, InsStr) {
	TStr Str = "abcda";
	TStr Empty = "";

	Str.InsStr(2, "xk");
	EXPECT_EQ(Str, "abxkcda");
	Str.InsStr(2, "");
	EXPECT_EQ(Str, "abxkcda");
	Str.InsStr(0, "f");
	EXPECT_EQ(Str, "fabxkcda");
	Str.InsStr(8, "f");
	EXPECT_EQ(Str, "fabxkcdaf");
	dup2(2, 1); // redirect stdout to stderr (Assert emits a printf to stdout)
	EXPECT_ANY_THROW(Str.InsStr(100, "kek"));
	EXPECT_ANY_THROW(Str.InsStr(-100, "kek"));
}
Exemple #4
0
TEST(TestTimer, Construct) {
    Timer timer;
    timer.Start("a");
    EXPECT_ANY_THROW(timer.End("b"));
    timer.End("a");
    timer.Display();
}
TEST(PathFinder, ThrowsExceptionWhenNotInitialized) {
    // Arrange
    PathFinder p;
    // Act
    // Assert
    EXPECT_ANY_THROW(p.GetDistance(0));
}
TEST(QST, TestConstructWithWrongSpaceDimension) {
    Matrix4cd matr;
    matr(0,0) = matr(3,0) = matr(0,3) = matr(3,3) = 0.5;
    
    HilbertSpace space(5);
    EXPECT_ANY_THROW(QuantumState state(matr, space));
}
TEST(QST, TestConstructWithMatrixThatIsNotDensityMatrix) {
    MatrixXcd matr(3, 3);
    matr.setConstant(std::complex< double >(0.15, 1));
    
    HilbertSpace space(3);
    EXPECT_ANY_THROW(QuantumState state(matr, space));
}
Exemple #8
0
TEST(SharedValueTest, ctorNulls)
{
    EXPECT_NO_THROW(Value v(0));
    EXPECT_NO_THROW(Value v(0.0));
    EXPECT_NO_THROW(Value v(0.0f));
    EXPECT_NO_THROW(Value v('\0'));
    EXPECT_NO_THROW(Value v(false));
    EXPECT_NO_THROW(Value v(NULL));
    EXPECT_NO_THROW(Value v(nullptr));
    EXPECT_NO_THROW(Value v(Value::Null));

    Value v0(0);
    EXPECT_EQ(v0.type(), typeid(int));
    Value v0dot0(0.0);
    EXPECT_EQ(v0dot0.type(), typeid(float));
    Value v0s('\0');
    EXPECT_EQ(v0s.type(), typeid(int));
    Value vfalse(false);
    EXPECT_EQ(vfalse.type(), typeid(bool));
    Value vNULL(NULL);
    EXPECT_EQ(vNULL.type(), typeid(NULL));
    Value vValueNull(Value::Null);
    EXPECT_EQ(vValueNull.type(), typeid(Value::Null));

    EXPECT_NO_THROW(vValueNull = "Hello"); // not locked
    EXPECT_EQ(vValueNull.type(), typeid(const char*)); // now locked
    EXPECT_ANY_THROW(vValueNull = 1);
}
TEST_F( AppTest, SetupTest ) 
{
	// The following tests should all fail
	EXPECT_EQ( mApp->getCounter(), 0 ) << "Not initialized (should cause access violation error)\n";
	EXPECT_ANY_THROW( mApp->setup() ) << "This should be reported because there is no exception thrown\n";
	EXPECT_GT( mApp->getCounter(), 0 ) << "This should be 0\n";
}
TEST(QST, TestConstructWithNonSquareMatrixIsDisallowed) {
    Matrix<std::complex< double >, 2, 3> matr;
    matr.setConstant(0.9);
        
    HilbertSpace space(4);
    EXPECT_ANY_THROW(QuantumState state(matr, space));
}
TEST(QST, TestConstructWithMatrixThatHasNonUnitaryTrace) {
    Matrix2cd matr;
    matr << 1,1,1,1;
    HilbertSpace space(2);
    
    EXPECT_ANY_THROW(QuantumState state(matr, space));
}
TEST(QST, TestConstructWithMatrixThatHasNegativeEigenValues) {
    Matrix2cd matr;
    matr << 0, 1, 1, 0;    
    HilbertSpace space(2);
    
    EXPECT_ANY_THROW(QuantumState state(matr, space));
}
TEST(PathFinder, Throws_Exception_With_Start_Index_Out_Of_Range) {
    // Arrange
    PathFinder pathFinder;
    int** graph = new int*;
    *graph = new int(0);
    // Act & Assert
    EXPECT_ANY_THROW(pathFinder.SetGraph(graph, 1, 5));
}
Exemple #14
0
TEST(TStr, LeftRight) {
	const TStr As = "aaabbbaaa";

	// basic tests
	EXPECT_EQ(As.Left(3), "aaa");
	EXPECT_EQ(As.Right(6), "aaa");

	// negative indexes
	EXPECT_EQ(As.Left(-6), "aaa");
	EXPECT_EQ(As.Right(-3), "aaa");

	// edge cases
	EXPECT_ANY_THROW(As.Left(1000));
	EXPECT_ANY_THROW(As.Right(1000));
	EXPECT_EQ(As.Right(0), "aaabbbaaa");
	EXPECT_EQ(As.Left(0), "");
}
TEST_F(TesteFila, LimpaFilaElementoComplexo){
	for(int i = 0; i < 50; i++){
		Objeto obj(i*4);
		filaobj.inclui(obj);
	}
	filaobj.inicializaFila(); // LimparFila, não sei pq se chama assim
	EXPECT_ANY_THROW(filaobj.getUltimo());
}
TEST(PathFinder, Throws_Exception_Set_Path_To_Self_With_Positive_Distance) {
    // Arrange
    int** graph = new int*;
    *graph = new int(0);
    PathFinder pathFinder(graph, 1, 0);
    // Act & Assert
    EXPECT_ANY_THROW(pathFinder.SetPath(0, 0, 1));
}
TEST(PathFinder, Throws_Exception_When_Set_Path_With_To_Index_Negative) {
    // Arrange
    int** graph = new int*;
    *graph = new int(0);
    PathFinder pathFinder(graph, 1, 0);
    // Act & Assert
    EXPECT_ANY_THROW(pathFinder.SetPath(0, -1, 5));
}
TEST(PathFinder, Throws_Exception_Set_Path_With_From_Index_Out_Of_Bounds) {
    // Arrange
    int** graph = new int*;
    *graph = new int(0);
    PathFinder pathFinder(graph, 1, 0);
    // Act & Assert
    EXPECT_ANY_THROW(pathFinder.SetPath(10, 0, 5));
}
TEST(PathFinder, Throws_Exception_With_Distance_Index_Out_Of_Range) {
    // Arrange
    int** graph = new int*;
    *graph = new int(0);
    PathFinder pathFinder(graph, 1, 0);
    // Act & Assert
    EXPECT_ANY_THROW(pathFinder.GetDistance(2));
}
TEST(PathFinder, Throws_Exception_With_New_Start_Vertex_Out_Of_Range) {
    // Arrange
    int** graph = new int*;
    *graph = new int(0);
    PathFinder pathFinder(graph, 1, 0);
    // Act & Assert
    EXPECT_ANY_THROW(pathFinder.SetStartVertex(5));
}
TEST(PathFinder, Throws_Exception_With_Setting_New_Start_Vertex_Negative) {
    // Arrange
    int** graph = new int*;
    *graph = new int(0);
    PathFinder pathFinder(graph, 1, 0);
    // Act & Assert
    EXPECT_ANY_THROW(pathFinder.SetStartVertex(-1));
}
TEST(PathFinder, Throws_Exception_With_Negative_Start_Index) {
    // Arrange
    PathFinder pathFinder;
    int** graph = new int*;
    *graph = new int(0);
    // Act & Assert
    EXPECT_ANY_THROW(pathFinder.SetGraph(graph, 1, -1));
}
TEST_F(TesteFila, ExcecaoFilaCheiaElementoComplexo) {
	for(int i = 0; i < 100; i++){
		Objeto obj(i*2);
		filaobj.inclui(obj);
	}

	Objeto elementoQueEstouraFila(5);
	EXPECT_ANY_THROW(filaobj.inclui(elementoQueEstouraFila));
}
TEST(PathFinder, ThrowsExceptionWithStartIndexOutOfRange) {
    // Arrange
    PathFinder p;
    int** gr = new int*;
    *gr = new int(0);
    // Act
    // Assert
    EXPECT_ANY_THROW(p.SetGraph(gr, 1, 5));
}
TEST(PathFinder, Throws_Exception_When_Set_Path_With_Negative_Distance) {
    // Arrange
    int** graph = new int*[2];
    for (int i = 0; i < 2; i++)
        graph[i] = new int[2]{ 0, 0 };
    PathFinder pathFinder(graph, 2, 0);
    // Act & Assert
    EXPECT_ANY_THROW(pathFinder.SetPath(0, 1, -1));
}
TEST(PathFinder, ThrowsExceptionWithNegativeStartIndex) {
    // Arrange
    PathFinder p;
    int** gr = new int*;
    *gr = new int(0);
    // Act
    // Assert
    EXPECT_ANY_THROW(p.SetGraph(gr, 1, -1));
}
TEST(PathFinder, Throws_Exception_When_Set_Path_With_Too_Large_Distance) {
    // Arrange
    int** graph = new int*[2];
    for (int i = 0; i < 2; i++)
        graph[i] = new int[2]{ 0, 0 };
    PathFinder pathFinder(graph, 2, 0);
    // Act & Assert
    EXPECT_ANY_THROW(pathFinder.SetPath(0, 0, PathFinder::MAX_DISTANCE));
}
TEST_F(TesteArvoreBinaria, RemoverFilhoDireita) {
	arv->inserir(8, arv);
	arv->inserir(9, arv);
	NoBinario<int>* root = arv->remover(arv, 8);
	EXPECT_ANY_THROW(*(arv->busca(8, arv)));
	arv->emOrdem(arv);
	NoBinario<int>* elemento = arv->getElementos();
	ASSERT_EQ(*(elemento->getDado()), 9);
}
TEST_F(TestApplication, can_parse_command_line_unexpected_empty) {
    // Arrange
    constexpr int argc = 1;
    constexpr const char* argv[argc] = {
        "somepath_to_binary"
    };

    // Act & Assert
    EXPECT_ANY_THROW(parseCommandLine(argc, argv));
}
Exemple #30
0
TEST(QiSession, testClose)
{
  qi::Session session;

  qi::Session sd;

  qi::Future<void> f = sd.listenStandalone("tcp://127.0.0.1:0");
  f.wait(3000);
  ASSERT_TRUE(!f.hasError());

  f = session.connect(sd.endpoints()[0]);
  f.wait(3000);
  ASSERT_TRUE(!f.hasError());

  qi::DynamicObjectBuilder ob;
  ob.advertiseMethod("reply", &reply);
  qi::AnyObject obj(ob.object());

  f = session.listen("tcp://127.0.0.1:0");
  f.wait(3000);
  ASSERT_TRUE(!f.hasError());

  // Wait for service id, otherwise register is asynchronous.
  qi::Future<unsigned int> idx = session.registerService("serviceTest", obj);
  ASSERT_FALSE(idx.hasError());

  qi::AnyObject object = session.service("serviceTest");
  EXPECT_TRUE(object);


  session.close();
  EXPECT_FALSE(session.isConnected());

  EXPECT_ANY_THROW(session.services().value());

  f = session.connect(sd.endpoints()[0]);
  f.wait(3000);
  if (f.hasError())
    qiLogError() << f.error();
  ASSERT_TRUE(!f.hasError());

  EXPECT_ANY_THROW(session.unregisterService(idx.value()));
}