TEST(TestMySQL_DatabasePool, TestGetInstance) {
	struct Filename {
		constexpr static const char *str() { return "test.ini"; }
	};
	Core::CLogConsole::SetDisplayOmittable(true);
	EXPECT_NO_FATAL_FAILURE(Core::IDatabasePool &pool = Core::databasePoolFilename<Filename>::getInstance());
	EXPECT_NO_FATAL_FAILURE([] () {
			Core::IDatabasePool &pool = Core::databasePoolFilename<Filename>::getInstance();
			EXPECT_NO_FATAL_FAILURE(Core::IDatabase &database = pool.getDatabase());
		});

	EXPECT_NO_FATAL_FAILURE([] () {
			Core::IDatabasePool &pool = Core::databasePoolFilename<Filename>::getInstance();
			Core::IDatabase &database = pool.getDatabase();
			database.QExecute("DROP TABLE IF EXISTS test_table;");
			database.QExecute("CREATE TABLE test_table(id INT, value INT, str VARCHAR(64), data BLOB);");
			database.QExecute("insert into test_table(id, value, str, data) values(0, 12, 'plop', '\x08\x12\x24');");
			database.QExecute("insert into test_table(id, value, str, data) values(1, NULL, NULL, NULL);");
			auto res = database.QStore("select * from test_table;");
			std::string s;
			res->getString("str", s);
			EXPECT_EQ(s, "plop");
		}());
	Core::CLogConsole::SetDisplayOmittable(true);
}
Exemplo n.º 2
0
// Tests scaling IO for CLI
TEST(CLIRegressionTests, Alpha) {
  // Make sure there is a command interpreter.
  ASSERT_EQ(0,(int)!(std::system(NULL)));

  // Setup the line that calls the command line interface.
  std::string log = "alpha_output.txt";
  std::string output = " > " + data_dir + log + " 2>&1";
  std::string option = " --alpha 0.05 ";
  std::string line = (command + name + path + option + input + output);

  // Make sure there was no error from the command line.
  ASSERT_EQ(0, std::system(line.c_str()));

  // Move the other generated files in the current dir to the test dir.
  for(size_t i = 0; i < num_files; i++) {
    system_execute(MV_CMMD,files[i] + " " + data_dir);
  }

  // Compare all of the related files.
  EXPECT_NO_FATAL_FAILURE(compareNodeFiles(
        data_dir + "alpha/output.node",
        data_dir + "output.node"));
  EXPECT_NO_FATAL_FAILURE(compareEleFiles(
        data_dir + "alpha/output.ele",
        data_dir + "output.ele"));

  // Delete the output files from this test.
  for(size_t i = 0; i < num_files - 4; i++) {
    system_execute(RM_CMMD,data_dir + files[i]);
  }
  system_execute(RM_CMMD,data_dir + "output.info");
  system_execute(RM_CMMD,data_dir + "output.node");
  system_execute(RM_CMMD,data_dir + "output.ele");
  system_execute(RM_CMMD,data_dir + log);
}
TEST(TestMySQL_Database, TestThreaded)
{
	const ::configFile::Database    &dbb = Core::Config::getInstance("test.ini").database();
	std::string host = dbb.host();
	std::string _database = dbb.database();
	std::string user = dbb.user();
	std::string pass = dbb.password();

	Core::CMySQL_Database	database(host.c_str(), _database.c_str(), user.c_str(), pass.c_str());
	database.QExecute("DROP TABLE IF EXISTS test_table;");
	database.QExecute("CREATE TABLE test_table(id INT, value INT, str VARCHAR(64), data BLOB);");
	database.QExecute("insert into test_table(id, value, str, data) values(0, 12, 'plop', '\x08\x12\x24');");
	database.QExecute("insert into test_table(id, value, str, data) values(1, NULL, 'null values', NULL);");
	
	std::thread first([&database] () {
			std::unique_ptr<Core::IResult> res;
			for (int i = 0; i < 20; ++i)
				EXPECT_NO_FATAL_FAILURE(res = std::move(database.QStore("select * from test_table;")));
			});
	std::thread second([&database] () {
			std::unique_ptr<Core::IResult> res;
			for (int i = 0; i < 20; ++i)
				EXPECT_NO_FATAL_FAILURE(res = std::move(database.QStore("select * from test_table;")));
			});
	first.join();
	second.join();
}
TEST_F(VehicleTest, getters_setters) {
	Vehicle car(name, pos);

	EXPECT_EQ(name, car.getName());
	EXPECT_EQ(pos, car.getPosition());
	EXPECT_EQ(pos, car.getDestination());

	EXPECT_NO_FATAL_FAILURE(car.setPosition(destination));
	EXPECT_EQ(destination, car.getPosition());

	EXPECT_NO_FATAL_FAILURE(car.setDestination(destination));
	EXPECT_EQ(destination, car.getDestination());
}
TEST( TestMySQL_Database, TestQExecute )
{
        const ::configFile::Database    &dbb = Core::Config::getInstance("test.ini").database();
        std::string host = dbb.host();
        std::string _database = dbb.database();
        std::string user = dbb.user();
        std::string pass = dbb.password();

	Core::CMySQL_Database database(host.c_str(), _database.c_str(), user.c_str(), pass.c_str());
	EXPECT_NO_FATAL_FAILURE( database.QExecute("DROP TABLE IF EXISTS test_table;"));
	EXPECT_NO_FATAL_FAILURE(database.QExecute("CREATE TABLE test_table(id INT);"));
	EXPECT_NO_FATAL_FAILURE(database.QExecute("DROP TABLE test_table;") );
	EXPECT_THROW(database.QExecute("use table test_table;"), std::exception);
}
TEST(TestMySQL_Database, TestIRowAndIterator)
{
	const ::configFile::Database    &dbb = Core::Config::getInstance("test.ini").database();
	std::string host = dbb.host();
	std::string _database = dbb.database();
	std::string user = dbb.user();
	std::string pass = dbb.password();

	Core::CMySQL_Database	database(host, _database, user, pass);
	database.QExecute("DROP TABLE IF EXISTS test_table;");
	database.QExecute("CREATE TABLE test_table(id INT, value INT, str VARCHAR(64), data BLOB);");
	database.QExecute("insert into test_table(id, value, str, data) values(0, 12, 'plop', '\x08\x12\x24');");
	database.QExecute("insert into test_table(id, value, str, data) values(1, NULL, NULL, NULL);");

	std::unique_ptr<Core::IResult> res = database.QStore("select * from test_table;");
	EXPECT_NO_FATAL_FAILURE([&res] () {
			std::string a;
			for (auto &it : *res) {
				std::string tmp;
				uint32_t t;
				it->getInt("id", t);
				a += std::to_string(t);
				if (it->getString("str", tmp))
					a += tmp;
			}
			EXPECT_EQ(a, "0plop1");
		}());
}
TEST(TestMySQL_Database, TestQStore)
{
        const ::configFile::Database    &dbb = Core::Config::getInstance("test.ini").database();
        std::string host = dbb.host();
        std::string _database = dbb.database();
        std::string user = dbb.user();
        std::string pass = dbb.password();

	Core::CMySQL_Database	database(host.c_str(), _database.c_str(), user.c_str(), pass.c_str());
	database.QExecute("DROP TABLE IF EXISTS test_table;");
	database.QExecute("CREATE TABLE test_table(id INT, value INT, str VARCHAR(64), fl FLOAT, data BLOB);");
	database.QExecute("insert into test_table(id, value, str, fl, data) values(0, 12, 'plop', 3.14, '\x08\x12\x24');");
	database.QExecute("insert into test_table(id, value, str, fl, data) values(1, NULL, 'null values', NULL, NULL);");
	std::unique_ptr<Core::IResult>	res;
	EXPECT_NO_FATAL_FAILURE(res = std::move(database.QStore("select * from test_table;")));
	uint32_t	id;
	EXPECT_EQ(res->getInt("id", id), true);
	EXPECT_EQ(id, 0);
	std::string	str;
	EXPECT_EQ(res->getString("str", str), true);
	EXPECT_EQ(str, "plop");
	float dec;
	EXPECT_EQ(res->getFloat("fl", dec), true);
	EXPECT_FLOAT_EQ(dec, 3.14);
	res->useRow(1);
	EXPECT_EQ(res->getInt("value", id), false);
	EXPECT_EQ(id, 0);
}
Exemplo n.º 8
0
TEST_F(QuotaTest, enforce)
{
    MojObject obj;

    // put quota
    MojAssertNoErr( obj.fromJson(_T("{\"owner\":\"com.foo.bar\",\"size\":1000}")) );
    MojAssertNoErr( db.putQuotas(&obj, &obj + 1) );

    // make kind2 inherit from kind1
    MojAssertNoErr( obj.fromJson(MojTestKind2Str3) );
    MojExpectNoErr( db.putKind(obj) );

    //// end of prerequisites form prev tests

    // set quota size to current usage
    MojInt64 quotaUsage1 = 0;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.bar"), quotaUsage1) );
    MojAssertNoErr( obj.putString(_T("owner"), _T("com.foo.bar")) );
    MojAssertNoErr( obj.putInt(_T("size"), quotaUsage1) );
    MojExpectNoErr( db.putQuotas(&obj, &obj + 1) );

    MojAssertNoErr( obj.fromJson(MojTestKind1Objects[3]) );
    EXPECT_EQ( MojErrDbQuotaExceeded, db.put(obj) );

    // Try to delete the kind
    MojString kindStr;
    MojAssertNoErr( kindStr.assign(_T("Test:1")) );
    bool found = false;
    EXPECT_EQ( MojErrDbKindHasSubKinds, db.delKind(kindStr, found) )
        << "The delete should be failure, because it contain sub kind \"Test2:1\"";
    EXPECT_FALSE( found );
}
TEST( TestMySQL_Database, TestConstructor )
{
	const ::configFile::Database	&dbb = Core::Config::getInstance("test.ini").database();
	std::string host = dbb.host();
	std::string _database = dbb.database();
	std::string user = dbb.user();
	std::string pass = dbb.password();

	EXPECT_NO_FATAL_FAILURE( Core::CMySQL_Database database(host.c_str(), _database.c_str(), user.c_str(), pass.c_str()));
}
Exemplo n.º 10
0
TEST_F(Game_tests, game_create)
{
    std::ifstream checkFile("shader/flush.frag");
    ASSERT_TRUE(checkFile.good());

    ASSERT_TRUE(glfwInit() == GL_TRUE);

    GLFWwindow * window = glfwCreateWindow(1, 1, "elemateTest", NULL, NULL);
    ASSERT_TRUE(window != NULL);

    glfwMakeContextCurrent(window);

    ASSERT_TRUE(glow::init());

    EXPECT_NO_FATAL_FAILURE(m_game = new Game(*window));

    EXPECT_NO_FATAL_FAILURE(delete m_game);
    m_game = nullptr;

    glfwTerminate();
}
Exemplo n.º 11
0
TEST_F(GameLogicTests, CreateStartTable8x8)
{
    Array defaultArray = createArray8x8({{o, B, o, B, o, B, o, B}
                                        ,{B, o, B, o, B, o, B, o}
                                        ,{o, B, o, B, o, B, o, B}
                                        ,{o, o, o, o, o, o, o, o}
                                        ,{o, o, o, o, o, o, o, o}
                                        ,{W, o, W, o, W, o, W, o}
                                        ,{o, W, o, W, o, W, o, W}
                                        ,{W, o, W, o, W, o, W, o}});
    EXPECT_NO_FATAL_FAILURE(createGame(std::move(defaultArray), PieceColor::White));
}
TEST_F(PoliceDepotTest, vehicles) {
	PoliceDepot depot(loc, entr, size, name, health);

	EXPECT_NO_FATAL_FAILURE(depot.addVehicle(ptrCar0));
	EXPECT_EQ(1, depot.getAvailableVehicles());
	EXPECT_EQ(1, depot.getNrVehicles());

	EXPECT_NO_FATAL_FAILURE(depot.addVehicle(ptrCar1));
	EXPECT_EQ(2, depot.getAvailableVehicles());
	EXPECT_EQ(2, depot.getNrVehicles());

	EXPECT_NO_FATAL_FAILURE(ptrCar0->goUp());
	EXPECT_EQ(1, depot.getAvailableVehicles());
	EXPECT_EQ(2, depot.getNrVehicles());

	EXPECT_NO_FATAL_FAILURE(ptrCar1->goUp());
	EXPECT_EQ(0, depot.getAvailableVehicles());
	EXPECT_EQ(2, depot.getNrVehicles());

	EXPECT_NO_FATAL_FAILURE(ptrCar0->goDown());
	EXPECT_EQ(1, depot.getAvailableVehicles());
	EXPECT_EQ(2, depot.getNrVehicles());

	EXPECT_NO_FATAL_FAILURE(ptrCar1->goDown());
	EXPECT_EQ(2, depot.getAvailableVehicles());
	EXPECT_EQ(2, depot.getNrVehicles());
}
Exemplo n.º 13
0
TEST_F(VehicleTest, driving) {
	Vehicle car(name, pos);

	EXPECT_FALSE(car.isOnWay());
	EXPECT_TRUE(car.isArrived());

	EXPECT_NO_FATAL_FAILURE(car.setDestination(destination));
	EXPECT_TRUE(car.isOnWay());
	EXPECT_FALSE(car.isArrived());

	EXPECT_DEATH(car.goLeft(), "");	// oops, just got negative coordinates

	EXPECT_NO_FATAL_FAILURE(car.goRight());
	EXPECT_EQ(Point(pos.getX() + 1, pos.getY()), car.getPosition());
	EXPECT_TRUE(car.isOnWay());
	EXPECT_FALSE(car.isArrived());

	EXPECT_DEATH(car.goDown(), "");	// oops, just got negative coordinates

	EXPECT_NO_FATAL_FAILURE(car.goUp());
	EXPECT_EQ(Point(pos.getX() + 1, pos.getY() + 1), car.getPosition());
	EXPECT_FALSE(car.isOnWay());
	EXPECT_TRUE(car.isArrived());

	// then go back to the original point
	EXPECT_NO_FATAL_FAILURE(car.setDestination(pos));
	EXPECT_EQ(destination, car.getPosition());
	EXPECT_TRUE(car.isOnWay());
	EXPECT_FALSE(car.isArrived());

	EXPECT_NO_FATAL_FAILURE(car.goLeft());
	EXPECT_EQ(Point(pos.getX(), pos.getY() + 1), car.getPosition());
	EXPECT_TRUE(car.isOnWay());
	EXPECT_FALSE(car.isArrived());

	EXPECT_DEATH(car.goLeft(), "");	// oops, just got negative coordinates!

	EXPECT_NO_FATAL_FAILURE(car.goDown());
	EXPECT_EQ(pos, car.getPosition());
	EXPECT_FALSE(car.isOnWay());
	EXPECT_TRUE(car.isArrived());

	EXPECT_DEATH(car.goDown(), "");	// ooops, just got negative coordinates!

	// end of driving
}
Exemplo n.º 14
0
// Test case generated from prender.c printf statements
TEST(PlayerTest, DidNotCrossSegment) {
    Vertex vs1{1, 16};
    Vertex vs2{1, 2};
    Vertex vs3{5, 7};
    Vertex vs4{5, 11};

    float FLOOR = 999;
    float CEILING = 1000;

    std::vector<Sector> sectors;
    Sector s1{FLOOR, CEILING};
    s1.set_number_of_points(4);
    s1.add_vertex(vs1);
    s1.add_vertex(vs2);
    s1.add_vertex(vs3);
    s1.add_vertex(vs4);
    s1.add_neighbor(-1);
    s1.add_neighbor(1);
    s1.add_neighbor(1);
    s1.add_neighbor(11);
    s1.add_neighbor(22);

    sectors.push_back(s1);

    Vector3D<float> location{4.184440, 6, 0};

    float ANGLE = 25;
    Player player{location, ANGLE, s1};
    EXPECT_NO_FATAL_FAILURE(player.move(0, 0, sectors));

    Sector result = player.get_sector();
    EXPECT_EQ(FLOOR, result.get_floor());
    EXPECT_EQ(CEILING, result.get_ceiling());
    EXPECT_EQ(ANGLE, player.get_angle());
    EXPECT_EQ(location.getX(), player.get_location().getX());
    EXPECT_EQ(location.getY(), player.get_location().getY());
}
TEST_F(SimulatorTest, construct) {
	EXPECT_NO_FATAL_FAILURE(Simulator sim(ptrCity, ptrOutput));
}
Exemplo n.º 16
0
TEST_F(QuotaTest, error)
{
	MojErr err;
    MojObject obj;

    // put quota (from testUsage)
	err = obj.fromJson(_T("{\"owner\":\"com.foo.bar\",\"size\":1000}"));
    MojAssertNoErr(err);

	err = db.putQuotas(&obj, &obj + 1);
    MojAssertNoErr(err);

    // quota for com.foo.baz (from multipleQuotas)
	err = obj.fromJson(_T("{\"owner\":\"com.foo.baz\",\"size\":1000}"));
	MojAssertNoErr(err);

	err = db.putQuotas(&obj, &obj + 1);
    MojAssertNoErr(err);

    // make kind2 inherit from kind1 (from multipleQuotas)
	err = obj.fromJson(MojTestKind2Str3);
    MojAssertNoErr(err);

	err = db.putKind(obj);
    MojExpectNoErr(err);

    // kind3 (from multipleQuotas)
	err = obj.fromJson(MojTestKind3Str1);
    MojAssertNoErr(err);

	err = db.putKind(obj);
    MojExpectNoErr(err);

    // wildcard (from multipleQuotas)
	err = obj.fromJson(_T("{\"owner\":\"com.foo.*\",\"size\":1000}"));
    MojAssertNoErr(err);

	err = db.putQuotas(&obj, &obj + 1);
    MojExpectNoErr(err);

	err = db.close();
	MojAssertNoErr(err);

	MojRefCountedPtr<MojDbEnv> testEnv(new MojDbTestStorageEnv(env));

	err = db.open(path.c_str(), testEnv);
	MojAssertNoErr(err);

	MojDbTestStorageEngine* testEngine = dynamic_cast<MojDbTestStorageEngine*> (db.storageEngine());
	ASSERT_TRUE(testEngine);

    // test that failed put does not affect quota
    MojInt64 quotaUsage1 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.*"), quotaUsage1) );
    EXPECT_LE( 0, quotaUsage1 );

	err = testEngine->setNextError(_T("txn.commit"), MojErrDbDeadlock);
    MojAssertNoErr(err);

	err = obj.fromJson(MojTestKind3Objects[1]);
    MojAssertNoErr(err);
    EXPECT_EQ( MojErrDbDeadlock, db.put(obj) );

    MojInt64 quotaUsage2 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.*"), quotaUsage2) );
    EXPECT_LE( 0, quotaUsage2 );
    EXPECT_EQ( quotaUsage1, quotaUsage2 );

    // test that failed putQuota has no effect
	err = testEngine->setNextError(_T("txn.commit"), MojErrDbDeadlock);
    MojAssertNoErr(err);

	err = obj.fromJson(_T("{\"owner\":\"com.foo.boo\",\"size\":1000}"));
    MojAssertNoErr(err);
    EXPECT_EQ( MojErrDbDeadlock, db.putQuotas(&obj, &obj + 1) );

    MojInt64 quotaUsage3 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.*"), quotaUsage3) );
    EXPECT_LE( 0, quotaUsage3 );
    EXPECT_EQ( quotaUsage1, quotaUsage3 );

    // test that failed putKind has no effect
	err = testEngine->setNextError(_T("txn.commit"), MojErrDbDeadlock);
    MojAssertNoErr(err);
	err = obj.fromJson(MojTestKind3Str2);
    MojAssertNoErr(err);
    EXPECT_EQ( MojErrDbDeadlock, db.putKind(obj) );

    MojInt64 quotaUsage4 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.*"), quotaUsage4) );
    EXPECT_LE( 0, quotaUsage4 );
    EXPECT_EQ( quotaUsage1, quotaUsage4 );
}
Exemplo n.º 17
0
TEST_F(HospitalTest, construct) {
	EXPECT_NO_FATAL_FAILURE(Hospital depot(loc, entr, size, name, health));
}
Exemplo n.º 18
0
TEST_F(QuotaTest, multipleQuotas)
{
    MojObject obj;

    // put quota (from testUsage)
    MojAssertNoErr( obj.fromJson(_T("{\"owner\":\"com.foo.bar\",\"size\":1000}")) );
    MojAssertNoErr( db.putQuotas(&obj, &obj + 1) );

    // quota for com.foo.baz
    MojAssertNoErr( obj.fromJson(_T("{\"owner\":\"com.foo.baz\",\"size\":1000}")) );
    MojAssertNoErr( db.putQuotas(&obj, &obj + 1) );

    // register kinds
    MojAssertNoErr( obj.fromJson(MojTestKind1Str1) );
    MojExpectNoErr( db.putKind(obj) );
    MojAssertNoErr( obj.fromJson(MojTestKind2Str1) );
    MojExpectNoErr( db.putKind(obj) );

    // put object of kind1 and kind2
    EXPECT_NO_FATAL_FAILURE( put(db, MojTestKind1Objects[0]) );
    EXPECT_NO_FATAL_FAILURE( put(db, MojTestKind2Objects[0]) );
    MojInt64 quotaUsage1 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.bar"), quotaUsage1) );
    EXPECT_LE( 0, quotaUsage1 );
    MojInt64 quotaUsage2 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.baz"), quotaUsage2) );
    EXPECT_LE( 0, quotaUsage2 );
    EXPECT_LT( 0, quotaUsage1 );
    EXPECT_EQ( 0, quotaUsage2 );

    // change owner of kind2 to com.foo.baz
    MojAssertNoErr( obj.fromJson(MojTestKind2Str2) );
    MojExpectNoErr( db.putKind(obj) );
    MojInt64 quotaUsage3 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.bar"), quotaUsage3) );
    EXPECT_LE( 0, quotaUsage3 );
    MojInt64 quotaUsage4 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.baz"), quotaUsage4) );
    EXPECT_LE( 0, quotaUsage4 );
    EXPECT_LT( 0, quotaUsage3 );
    EXPECT_EQ( quotaUsage3, quotaUsage4);

    // make kind2 inherit from kind1
    MojAssertNoErr( obj.fromJson(MojTestKind2Str3) );
    MojExpectNoErr( db.putKind(obj) );
    MojInt64 quotaUsage5 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.bar"), quotaUsage5) );
    MojInt64 quotaUsage6 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.baz"), quotaUsage6) );
    EXPECT_GT( quotaUsage5, quotaUsage1 );
    EXPECT_EQ( 0, quotaUsage6 );

    // kind3 and object
    MojAssertNoErr( obj.fromJson(MojTestKind3Str1) );
    MojExpectNoErr( db.putKind(obj) );
    EXPECT_NO_FATAL_FAILURE( put(db, MojTestKind3Objects[0]) );
    MojInt64 quotaUsage7 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.bar"), quotaUsage7) );
    EXPECT_EQ( quotaUsage7, quotaUsage5 );

    // wildcard
    MojAssertNoErr( obj.fromJson(_T("{\"owner\":\"com.foo.*\",\"size\":1000}")) );
    MojExpectNoErr( db.putQuotas(&obj, &obj + 1) );
    MojInt64 quotaUsage8 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.bar"), quotaUsage8) );
    MojInt64 quotaUsage9 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.*"), quotaUsage9) );
    EXPECT_EQ( quotaUsage5, quotaUsage8 );
    EXPECT_LT( 0, quotaUsage9 );
}
Exemplo n.º 19
0
TEST_F(QuotaTest, usage)
{
    // put quota
    MojObject obj;
    MojAssertNoErr( obj.fromJson(_T("{\"owner\":\"com.foo.bar\",\"size\":1000}")) );
    MojAssertNoErr( db.putQuotas(&obj, &obj + 1) );

    // empty
    MojInt64 kindUsage = -1;
    EXPECT_NO_FATAL_FAILURE( getKindUsage(db, _T("Test:1"), kindUsage) );
    EXPECT_EQ( 0, kindUsage )
        << "Kind without objects should have zero usage";
    MojInt64 quotaUsage = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.bar"), quotaUsage) );
    EXPECT_EQ( 0, quotaUsage )
        << "Quota without matching objects should have zero usage";

    // new obj
    EXPECT_NO_FATAL_FAILURE( put(db, MojTestKind1Objects[0]) );
    MojInt64 kindUsage1 = -1;
    EXPECT_NO_FATAL_FAILURE( getKindUsage(db, _T("Test:1"), kindUsage1) );
    EXPECT_LT( 0, kindUsage1 )
        << "Adding new object into kind should increase kind usage";
    MojInt64 quotaUsage1 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.bar"), quotaUsage1) );
    EXPECT_LT( 0, quotaUsage1 )
        << "Adding new object matching quota should increase quota usage";

    // add prop to existing obj
    MojAssertNoErr( obj.fromJson(MojTestKind1Objects[0]) );
    MojAssertNoErr( obj.put(_T("bar"), 2) );
    MojAssertNoErr( db.put(obj, MojDb::FlagForce) );
    MojInt64 kindUsage2 = -1;
    EXPECT_NO_FATAL_FAILURE( getKindUsage(db, _T("Test:1"), kindUsage2) );
    EXPECT_LE( 0, kindUsage2 );
    EXPECT_LT( kindUsage1, kindUsage2 )
        << "Adding property to existing object should increase kind usage";
    MojInt64 quotaUsage2 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.bar"), quotaUsage2) );
    EXPECT_LE( 0, quotaUsage2 );
    EXPECT_LT( quotaUsage1, quotaUsage2 )
        << "Adding property to existing object that matches quota should increase usage";

    // add 2nd obj
    EXPECT_NO_FATAL_FAILURE( put(db, MojTestKind1Objects[1]) );
    MojInt64 kindUsage3 = -1;
    EXPECT_NO_FATAL_FAILURE( getKindUsage(db, _T("Test:1"), kindUsage3) );
    EXPECT_LE( 0, kindUsage3 );
    EXPECT_LT( kindUsage2, kindUsage3 )
        << "Adding another object should increase kind usage";
    MojInt64 quotaUsage3 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.bar"), quotaUsage3) );
    EXPECT_LE( 0, quotaUsage3 );
    EXPECT_LT( quotaUsage2, quotaUsage3 )
        << "Adding another object matching to quota should increase usage";

    // del first obj
    bool found = false;
    MojExpectNoErr( db.del(1, found, MojDb::FlagPurge) );
    EXPECT_TRUE( found ) << "Object should be deleted";
    MojInt64 kindUsage4 = -1;
    EXPECT_NO_FATAL_FAILURE( getKindUsage(db, _T("Test:1"), kindUsage4) );
    EXPECT_LE( 0, kindUsage4 );
    EXPECT_EQ( kindUsage3 - kindUsage2, kindUsage4 )
        << "Deletion of object should bring kind usage to expected value";
    MojInt64 quotaUsage4 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.bar"), quotaUsage4) );
    EXPECT_LE( 0, quotaUsage4 );
    EXPECT_EQ( quotaUsage3 - quotaUsage2, quotaUsage4 )
        << "Deletion of object should bring quota usage to expected value";

    // add index
    MojAssertNoErr( obj.fromJson(MojTestKind1Str2) );
    MojExpectNoErr( db.putKind(obj) );
    MojInt64 kindUsage5 = -1;
    EXPECT_NO_FATAL_FAILURE( getKindUsage(db, _T("Test:1"), kindUsage5) );
    EXPECT_LE( 0, kindUsage5 );
    EXPECT_LT( kindUsage4, kindUsage5 )
        << "Adding new index should increase kind usage";
    MojInt64 quotaUsage5 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.bar"), quotaUsage5) );
    EXPECT_LE( 0, quotaUsage5 );
    EXPECT_LT( quotaUsage4, quotaUsage5 )
        << "Adding new index should increase quota usage";

    // update locale
    MojExpectNoErr( db.updateLocale(_T("FR_fr")) );
    MojExpectNoErr( db.updateLocale(_T("EN_us")) );
    MojInt64 kindUsage6 = -1;
    EXPECT_NO_FATAL_FAILURE( getKindUsage(db, _T("Test:1"), kindUsage6) );
    EXPECT_LE( 0, kindUsage6 );
    EXPECT_EQ( kindUsage5, kindUsage6 )
        << "Switching locale forth and back shouldn't affect kind usage";
    MojInt64 quotaUsage6 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.bar"), quotaUsage6) );
    EXPECT_LE( 0, kindUsage6 );
    EXPECT_EQ( quotaUsage5, quotaUsage6 )
        << "Switching locale forth and back shouldn't affect quota usage";

    // drop index
    MojAssertNoErr( obj.fromJson(MojTestKind1Str1) );
    MojExpectNoErr( db.putKind(obj) );
    MojInt64 kindUsage7 = -1;
    EXPECT_NO_FATAL_FAILURE( getKindUsage(db, _T("Test:1"), kindUsage7) );
    EXPECT_LE( 0, kindUsage7 );
    EXPECT_EQ( kindUsage4, kindUsage7 )
        << "Dropping of index should bring kind usage to expected value";
    MojInt64 quotaUsage7 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.bar"), quotaUsage7) );
    EXPECT_LE( 0, quotaUsage7 );
    EXPECT_EQ( quotaUsage4, quotaUsage7 )
        << "Dropping of index should bring quota usage to expected value";

    // drop kind
    MojString kindStr;
    MojAssertNoErr( kindStr.assign(_T("Test:1")) );
    MojExpectNoErr( db.delKind(kindStr, found) );
    EXPECT_TRUE( found ) << "Kind should be deleted";
    MojInt64 kindUsage8 = -1;
    EXPECT_NO_FATAL_FAILURE( getKindUsage(db, _T("Test:1"), kindUsage8) );
    EXPECT_EQ( 0, kindUsage8 )
        << "Dropping of kind should bring its usage to zero";
    MojInt64 quotaUsage8 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.bar"), quotaUsage8) );
    EXPECT_EQ( 0, quotaUsage8 )
        << "Dropping of kind that matches quota should bring quota usage to zero";
    MojExpectNoErr( db.quotaStats(obj) );

    MojString statStr;
    MojExpectNoErr( obj.toJson(statStr) );
    std::cerr << "quotaStats: " << statStr.data() << std::endl;
}
TEST_F(PoliceDepotTest, fire) {
	PoliceDepot depot(loc, entr, size, name, health);

	EXPECT_FALSE(depot.isBurning());

	EXPECT_DEATH(depot.burningDown(), "");	// ooops, depot is not on fire
	EXPECT_DEATH(depot.stopFire(), "");	// oops, depot is not on fire

	EXPECT_FALSE(depot.isDead());
	EXPECT_FALSE(depot.startSpreadingFire());
	EXPECT_FALSE(depot.startRepair());

	EXPECT_DEATH(depot.repair(), "");	// oops, Depot has still it's original health

	EXPECT_FALSE(depot.isFireTruckAssigned());
	EXPECT_DEATH(depot.assignFireTruck(), "");	// oops, the Depot is not on fire
	EXPECT_DEATH(depot.withdrawFireTruckAssignment(), "");	// oops, there is no firetruck assigned

	// okay, start the fire scenario
	EXPECT_NO_FATAL_FAILURE(depot.setFire());
	EXPECT_TRUE(depot.isBurning());
	EXPECT_NO_FATAL_FAILURE(depot.burningDown());
	EXPECT_EQ(health - reducer, depot.getHealth());
	EXPECT_FALSE(depot.isDead());
	EXPECT_FALSE(depot.startSpreadingFire());	// No, it has lost "only" 2 health points
	EXPECT_FALSE(depot.startRepair());

	EXPECT_DEATH(depot.repair(), "");	// oops, Depot is still on fire

	// let's send a firetruck
	EXPECT_NO_FATAL_FAILURE(depot.assignFireTruck());
	EXPECT_TRUE(depot.isFireTruckAssigned());

	// extinguish fire, repair and sendback firetruck
	EXPECT_DEATH(depot.withdrawFireTruckAssignment(), "");	// oops, Depot is still on fire

	EXPECT_NO_FATAL_FAILURE(depot.stopFire());
	EXPECT_FALSE(depot.isBurning());
	EXPECT_TRUE(depot.startRepair());
	EXPECT_NO_FATAL_FAILURE(depot.repair());
	EXPECT_EQ(health - reducer + 0.5, depot.getHealth());
	EXPECT_NO_FATAL_FAILURE(depot.withdrawFireTruckAssignment());
	EXPECT_FALSE(depot.isFireTruckAssigned());
	EXPECT_FALSE(depot.isDead());

	// fire breaks out again
	EXPECT_NO_FATAL_FAILURE(depot.setFire());
	EXPECT_TRUE(depot.isBurning());
	EXPECT_NO_FATAL_FAILURE(depot.burningDown());
	EXPECT_EQ(health - reducer + 0.5 - reducer, depot.getHealth());
	EXPECT_FALSE(depot.isDead());
	EXPECT_TRUE(depot.startSpreadingFire());

	// let them burning down 'till death
	EXPECT_NO_FATAL_FAILURE(depot.burningDown());
	EXPECT_TRUE(depot.isDead());
	EXPECT_EQ(health - reducer + 0.5 - reducer - reducer, depot.getHealth());

	// now, Depot is not on fire anymore
	EXPECT_FALSE(depot.isBurning());
	EXPECT_FALSE(depot.startRepair());	// you cannot repair a dead Depot
	EXPECT_FALSE(depot.startSpreadingFire());
}
TEST_F(PoliceDepotTest, construct) {
	EXPECT_NO_FATAL_FAILURE(PoliceDepot depot(loc, entr, size, name, health));
}
Exemplo n.º 22
0
TEST_F(VehicleTest, construct) {
	EXPECT_NO_FATAL_FAILURE(Vehicle car(name, pos));
}
TEST_F(SimulatorTest, fire) {
	House newHouse(Point(0, 1), 2);
	Street verticalLeft("VerticalLeft", Point(2, 2), Point(2, 1));
	Street horizontal("Horizontal", Point(2, 2), Point(4, 2));
	Street verticalRight("VerticalRight", Point(4, 3), Point(4, 2));
	ASSERT_TRUE(ptrCity->add(newHouse));
	ASSERT_TRUE(ptrCity->add(horizontal));
	ASSERT_TRUE(ptrCity->add(verticalLeft));
	ASSERT_TRUE(ptrCity->add(verticalRight));

	Simulator sim(ptrCity, ptrOutput);
	House* ptrHouse = ptrCity->getHouses()[0];
	ASSERT_TRUE(ptrHouse != NULL);

	EXPECT_NO_FATAL_FAILURE(sim.fireBreaksOut());
	EXPECT_TRUE(ptrHouse->isBurning());
	EXPECT_EQ(2, ptrHouse->getHealth());

	EXPECT_NO_FATAL_FAILURE(sim.burningDown());
	EXPECT_TRUE(ptrHouse->isBurning());
	EXPECT_EQ(1, ptrHouse->getHealth());

	EXPECT_FALSE(sim.sendFireTrucks());	// oh, there isn't even a firedepot

	// now build a firedepot
	FireDepot newDepot(Point(4, 7), Point(4, 3), "Firedepot", 1);
	ASSERT_TRUE(ptrCity->add(newDepot));
	FireDepot* ptrDepot = ptrCity->findFireDepot("Firedepot");
	ASSERT_TRUE(ptrDepot != NULL);

	EXPECT_FALSE(sim.sendFireTrucks());	// oh, there isn't even a firetruck

	// add a firetruck
	FireTruck newTruck("Truck", ptrDepot);
	ASSERT_TRUE(ptrCity->add(newTruck));
	FireTruck* ptrTruck = ptrCity->getFireTrucks()[0];
	ASSERT_TRUE(ptrTruck != NULL);

	EXPECT_TRUE(sim.sendFireTrucks());
	EXPECT_TRUE(ptrTruck->isAtEntranceDepot());
	EXPECT_TRUE(ptrHouse->isFireTruckAssigned());
	EXPECT_EQ(Point(2, 1), ptrTruck->getDestination());

	EXPECT_NO_FATAL_FAILURE(sim.drive());
	EXPECT_EQ(Point(4, 2), ptrTruck->getPosition());

	EXPECT_NO_FATAL_FAILURE(sim.drive());
	EXPECT_EQ(Point(3, 2), ptrTruck->getPosition());

	EXPECT_NO_FATAL_FAILURE(sim.drive());
	EXPECT_EQ(Point(2, 2), ptrTruck->getPosition());

	EXPECT_NO_FATAL_FAILURE(sim.drive());
	EXPECT_EQ(Point(2, 1), ptrTruck->getPosition());
	EXPECT_TRUE(ptrTruck->isArrived());

	EXPECT_NO_FATAL_FAILURE(sim.drive());
	EXPECT_EQ(ptrDepot->getEntrance(), ptrTruck->getDestination());
	EXPECT_FALSE(ptrHouse->isBurning());
	EXPECT_FALSE(ptrHouse->isFireTruckAssigned());

	EXPECT_NO_FATAL_FAILURE(sim.repairBuildings());
	EXPECT_EQ(1.5, ptrHouse->getHealth());

	EXPECT_NO_FATAL_FAILURE(sim.fireBreaksOut());
	EXPECT_NO_FATAL_FAILURE(sim.fireBreaksOut());
	EXPECT_TRUE(ptrHouse->isBurning());
	EXPECT_TRUE(ptrDepot->isBurning());

	EXPECT_NO_FATAL_FAILURE(sim.drive());
	EXPECT_EQ(Point(2, 2), ptrTruck->getPosition());

	EXPECT_NO_FATAL_FAILURE(sim.drive());
	EXPECT_EQ(Point(3, 2), ptrTruck->getPosition());

	EXPECT_NO_FATAL_FAILURE(sim.drive());
	EXPECT_EQ(Point(4, 2), ptrTruck->getPosition());

	EXPECT_NO_FATAL_FAILURE(sim.drive());
	EXPECT_EQ(Point(4, 3), ptrTruck->getPosition());
	EXPECT_TRUE(ptrTruck->isAtEntranceDepot());
	EXPECT_TRUE(ptrTruck->isArrived());

	EXPECT_NO_FATAL_FAILURE(sim.burningDown());
	EXPECT_EQ(0.5, ptrHouse->getHealth());
	EXPECT_EQ(-1, ptrDepot->getHealth());
	EXPECT_TRUE(ptrDepot->isDead());
	EXPECT_FALSE(ptrDepot->isBurning());

	EXPECT_NO_FATAL_FAILURE(sim.drive());
	EXPECT_TRUE(ptrTruck->isAtEntranceDepot());

	EXPECT_NO_FATAL_FAILURE(sim.burningDown());
	EXPECT_EQ(-0.5, ptrHouse->getHealth());
	EXPECT_EQ(-1, ptrDepot->getHealth());

	EXPECT_TRUE(sim.endSimulation());
}
Exemplo n.º 24
0
TEST_F(GameLogicTests, ShouldFinishByDraw)
{
    Array defaultArray = createArray10x10({{o,WQ, o, o, o, o, o, o, o, o}
                                          ,{o, o, o, o, o, o, o, o, o, o}
                                          ,{o, o, o, o, o, o, o, o, o, o}
                                          ,{o, o, o, o, o, o, o, o, o, o}
                                          ,{o, o, o, o, o, o, o, o, o, o}
                                          ,{o, o, o, o, o, o, o, o, o, o}
                                          ,{o, o, o, o, o, o, o, o, o, o}
                                          ,{o, o, o, o, o, o, o, o, o, o}
                                          ,{o, o, o, o, o, o, o, o, o, o}
                                          ,{o, o, o, o, o,BQ, o, o, o, o}});

    auto game = createAndStartGame(defaultArray, Table::TableVersion::Version_100, PieceColor::White);

    Array array2 = createArray10x10({{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o,WQ, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o,BQ, o, o, o, o}});

    EXPECT_NO_FATAL_FAILURE(movePiece(game, Position(0,1), {Position(1,2)}, array2, PieceColor::White, PieceColor::Black));

    Array array3 = createArray10x10({{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, WQ, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, BQ, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}});

    EXPECT_NO_FATAL_FAILURE(movePiece(game, Position(9,5), {Position(8,4)}, array3, PieceColor::Black, PieceColor::White));

    Array array4 = createArray10x10({{o, WQ, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o,BQ, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}});

    EXPECT_NO_FATAL_FAILURE(movePiece(game, Position(1,2), {Position(0,1)}, array4, PieceColor::White, PieceColor::Black));

    Array array5 = createArray10x10({{o, WQ, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o,BQ, o, o, o, o}});

    EXPECT_NO_FATAL_FAILURE(movePiece(game, Position(8,4), {Position(9,5)}, array5, PieceColor::Black, PieceColor::White));

    Array array6 = createArray10x10({{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, WQ, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o,BQ, o, o, o, o}});

    EXPECT_NO_FATAL_FAILURE(movePiece(game, Position(0,1), {Position(1,2)}, array6, PieceColor::White, PieceColor::Black));

    Array array7 = createArray10x10({{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, WQ, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, BQ, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}});

    EXPECT_NO_FATAL_FAILURE(movePiece(game, Position(9,5), {Position(8,4)}, array7, PieceColor::Black, PieceColor::White));

    Array array8 = createArray10x10({{o, WQ, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o,BQ, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}});

    EXPECT_NO_FATAL_FAILURE(movePiece(game, Position(1,2), {Position(0,1)}, array8, PieceColor::White, PieceColor::Black));

    Array array9 = createArray10x10({{o, WQ, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o,BQ, o, o, o, o}});

    EXPECT_NO_FATAL_FAILURE(movePiece(game, Position(8,4), {Position(9,5)}, array9, PieceColor::Black, PieceColor::White));

    Array array10 = createArray10x10({{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, WQ, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o,BQ, o, o, o, o}});

    EXPECT_NO_FATAL_FAILURE(movePiece(game, Position(0,1), {Position(1,2)}, array10, PieceColor::White, PieceColor::Black));

    Array array11 = createArray10x10({{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, WQ, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, BQ, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}});

    EXPECT_NO_FATAL_FAILURE(movePiece(game, Position(9,5), {Position(8,4)}, array11, PieceColor::Black, PieceColor::White));

    Array array12 = createArray10x10({{o, WQ, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o,BQ, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}});

    EXPECT_NO_FATAL_FAILURE(movePiece(game, Position(1,2), {Position(0,1)}, array12, PieceColor::White, PieceColor::Black));

    Array array13 = createArray10x10({{o, WQ, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o,BQ, o, o, o, o}});

    EXPECT_NO_FATAL_FAILURE(movePiece(game, Position(8,4), {Position(9,5)}, array13, PieceColor::Black, PieceColor::White));

    Array array14 = createArray10x10({{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, WQ, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o, o, o, o, o, o}
                                    ,{o, o, o, o, o,BQ, o, o, o, o}});

    EXPECT_NO_FATAL_FAILURE(movePiece(game, Position(0,1), {Position(1,2)}, array14, PieceColor::White, PieceColor::Black));

    Array array15 = createArray10x10({{o, o, o, o, o, o, o, o, o, o}
                                     ,{o, o,WQ, o, o, o, o, o, o, o}
                                     ,{o, o, o, o, o, o, o, o, o, o}
                                     ,{o, o, o, o, o, o, o, o, o, o}
                                     ,{o, o, o, o, o, o, o, o, o, o}
                                     ,{o, o, o, o, o, o, o, o, o, o}
                                     ,{o, o, o, o, o, o, o, o, o, o}
                                     ,{o, o, o, o, o, o, o, o, o, o}
                                     ,{o, o, o, o,BQ, o, o, o, o, o}
                                     ,{o, o, o, o, o, o, o, o, o, o}});


    EXPECT_CALL(*uiMock, onDraw());
    EXPECT_CALL(*uiMock, tableChanged(MatchArray(array15)));

    EXPECT_CALL(*uiMock, movePerformed(Position(9,5), std::vector<Position>{Position(8,4)}));
    game->movePiece(Position(9,5), {Position(8,4)}, PieceColor::Black);
}
TEST_F(SimulatorTest, robbing) {
	Shop appleStore(Point(0, 1), Size(2), 1, 2);
	Street verticalLeft("VerticalLeft", Point(2, 2), Point(2, 1));
	Street horizontal("Horizontal", Point(2, 2), Point(4, 2));
	Street verticalRight("VerticalRight", Point(4, 3), Point(4, 2));
	ASSERT_TRUE(ptrCity->add(appleStore));
	ASSERT_TRUE(ptrCity->add(horizontal));
	ASSERT_TRUE(ptrCity->add(verticalLeft));
	ASSERT_TRUE(ptrCity->add(verticalRight));

	Simulator sim(ptrCity, ptrOutput);
	Shop* ptrShop = ptrCity->getShops()[0];
	ASSERT_TRUE(ptrShop != NULL);

	EXPECT_TRUE(sim.commitRob());
	EXPECT_TRUE(ptrShop->isRobbing());
	EXPECT_EQ(2, ptrShop->getSecurity());

	EXPECT_TRUE(sim.robbing());
	EXPECT_TRUE(ptrShop->isRobbing());
	EXPECT_EQ(1, ptrShop->getSecurity());

	EXPECT_FALSE(sim.sendPoliceTrucks());	// oh, there isn't even a policedepot

	// now build a policedepot
	PoliceDepot newDepot(Point(4, 7), Point(4, 3), Size(4), "Policedepot", 1);
	ASSERT_TRUE(ptrCity->add(newDepot));
	PoliceDepot* ptrDepot = ptrCity->findPoliceDepot("Policedepot");
	ASSERT_TRUE(ptrDepot != NULL);

	EXPECT_FALSE(sim.sendFireTrucks());	// oh, there isn't even a policetruck

	// add a policetruck
	PoliceTruck newTruck("Truck", ptrDepot);
	ASSERT_TRUE(ptrCity->add(newTruck));
	PoliceTruck* ptrTruck = ptrCity->getPoliceTrucks()[0];
	ASSERT_TRUE(ptrTruck != NULL);

	EXPECT_TRUE(sim.sendPoliceTrucks());
	EXPECT_TRUE(ptrTruck->isAtEntranceDepot());
	EXPECT_TRUE(ptrShop->isPoliceTruckAssigned());
	EXPECT_EQ(Point(2, 1), ptrTruck->getDestination());

	EXPECT_TRUE(sim.drive());
	EXPECT_EQ(Point(4, 2), ptrTruck->getPosition());

	EXPECT_TRUE(sim.drive());
	EXPECT_EQ(Point(3, 2), ptrTruck->getPosition());

	EXPECT_TRUE(sim.drive());
	EXPECT_EQ(Point(2, 2), ptrTruck->getPosition());

	EXPECT_TRUE(sim.drive());
	EXPECT_EQ(Point(2, 1), ptrTruck->getPosition());
	EXPECT_TRUE(ptrTruck->isArrived());

	EXPECT_TRUE(sim.drive());
	EXPECT_EQ(ptrDepot->getEntrance(), ptrTruck->getDestination());
	EXPECT_FALSE(ptrShop->isRobbing());
	EXPECT_FALSE(ptrShop->isPoliceTruckAssigned());

	EXPECT_FALSE(sim.robbing());
	EXPECT_FALSE(ptrShop->isRobbing());

	EXPECT_TRUE(sim.commitRob());
	EXPECT_TRUE(ptrShop->isRobbing());
	EXPECT_TRUE(sim.robbing());
	EXPECT_FALSE(ptrShop->isRobbing());

	EXPECT_TRUE(sim.fireBreaksOut());
	EXPECT_TRUE(sim.fireBreaksOut());
	EXPECT_TRUE(ptrDepot->isBurning());
	EXPECT_TRUE(ptrShop->isBurning());

	EXPECT_NO_FATAL_FAILURE(sim.drive());
	EXPECT_EQ(Point(2, 2), ptrTruck->getPosition());

	EXPECT_NO_FATAL_FAILURE(sim.drive());
	EXPECT_EQ(Point(3, 2), ptrTruck->getPosition());

	EXPECT_NO_FATAL_FAILURE(sim.drive());
	EXPECT_EQ(Point(4, 2), ptrTruck->getPosition());

	EXPECT_NO_FATAL_FAILURE(sim.drive());
	EXPECT_EQ(Point(4, 3), ptrTruck->getPosition());
	EXPECT_TRUE(ptrTruck->isAtEntranceDepot());
	EXPECT_TRUE(ptrTruck->isArrived());

	EXPECT_TRUE(sim.drive());
	EXPECT_TRUE(ptrTruck->isAtEntranceDepot());

	EXPECT_TRUE(sim.burningDown());
	EXPECT_EQ(-1, ptrShop->getHealth());
	EXPECT_EQ(-1, ptrDepot->getHealth());
	EXPECT_TRUE(ptrDepot->isDead());
	EXPECT_FALSE(ptrDepot->isBurning());
	EXPECT_TRUE(ptrShop->isDead());

	EXPECT_TRUE(sim.endSimulation());
}
Exemplo n.º 26
0
TEST_F(CheckTest, construct) {
	EXPECT_NO_FATAL_FAILURE(Check checker);
}