Example #1
0
TEST( Machine, MachineDirectionalDiscovery )
{
    Machine machines[GAME_MAP_WIDTH*GAME_MAP_HEIGHT];
    int i=0;
    for( int y =0; y<GAME_MAP_HEIGHT; y++ )
    {
        for( int x = 0; x<GAME_MAP_WIDTH; x++, i++ )
        {
            p2 gridPoint = { x,y };
            CreateMachine( &machines[i], gridPoint );
        }
    }
    machines[0].alive = true;
    
    // test with gridpoint
    p2 gridPoint = { 1, 0 };
    int direction = MACHINE_ADJ_LEFT;
    Machine* adj = 0;
    
    ASSERT_TRUE( GetAdjacentMachine( machines, gridPoint, &adj, direction ) );
    EXPECT_NE( nullptr, adj );

    direction = MACHINE_ADJ_RIGHT;
    ASSERT_FALSE( GetAdjacentMachine( machines, gridPoint, &adj, direction ) );
    EXPECT_EQ( nullptr, adj ); // should clear the pointer

    direction = MACHINE_ADJ_TOP;
    ASSERT_FALSE( GetAdjacentMachine( machines, gridPoint, &adj, direction ) );
    EXPECT_EQ( nullptr, adj );

    direction = MACHINE_ADJ_BOTTOM;
    ASSERT_FALSE( GetAdjacentMachine( machines, gridPoint, &adj, direction ) );
}
Example #2
0
TEST( Machine, MachineOmniDiscovery )
{
    Machine machines[GAME_MAP_WIDTH*GAME_MAP_HEIGHT];
    int i=0;
    for( int y =0; y<GAME_MAP_HEIGHT; y++ )
    {
        for( int x = 0; x<GAME_MAP_WIDTH; x++, i++ )
        {
            p2 gridPoint = { x,y };
            CreateMachine( &machines[i], gridPoint );
        }
    }
    machines[0].alive = true;

    // test with gridpoint
    p2 gridPoint = { 1, 0 };
    Machine* adj[MACHINE_MAX_ADJ] = {};
    ASSERT_TRUE( GetAdjacentMachines( machines, gridPoint, adj ) );

    EXPECT_NE( nullptr, adj[MACHINE_ADJ_LEFT] );
    EXPECT_EQ( 0, adj[MACHINE_ADJ_RIGHT] );

    // test null case
    gridPoint.x = 5;
    Machine* adj3[MACHINE_MAX_ADJ] = {};
    ASSERT_FALSE( GetAdjacentMachines( machines, gridPoint, adj ) );

    EXPECT_EQ( 0, adj3[MACHINE_ADJ_LEFT] );
    EXPECT_EQ( 0, adj3[MACHINE_ADJ_RIGHT] );
}
Example #3
0
TEST( Machine, PlaceMachine )
{
    Machine machines[GAME_MAP_WIDTH*GAME_MAP_HEIGHT];
    int i=0;
    for( int y =0; y<GAME_MAP_HEIGHT; y++ )
    {
        for( int x = 0; x<GAME_MAP_WIDTH; x++, i++ )
        {
            p2 gridPoint = { x,y };
            CreateMachine( &machines[i], gridPoint );
        }
    }
    machines[0].alive = true;

    // test valid placement
    p2 gridPoint = { 1, 0 };
    ASSERT_NE( nullptr, PlaceMachine( machines, gridPoint, 2 , 0 ) );
    EXPECT_EQ( 2, machines[1].type );

    // test out of bounds, underflow, y only
    gridPoint.y = -1;
    ASSERT_EQ( nullptr, PlaceMachine( machines, gridPoint, 2, 0 ) );

    // test out of bounds, underflow, x only
    gridPoint.y = 0;
    gridPoint.x = -1;
    ASSERT_EQ( nullptr, PlaceMachine( machines, gridPoint, 2, 0 ) );

    // test out of bounds, overflow, x only
    gridPoint.x = GAME_MAP_WIDTH+1;
    ASSERT_EQ( nullptr, PlaceMachine( machines, gridPoint, 2, 0 ) );

    // test out of bounds, overflow, y only
    gridPoint.x = 0;
    gridPoint.y = GAME_MAP_HEIGHT+1;
    ASSERT_EQ( nullptr, PlaceMachine( machines, gridPoint, 2, 0 ) );

    // test placement on occupied tile
    gridPoint.y = 0;
    ASSERT_EQ( nullptr, PlaceMachine( machines, gridPoint, 2, 0 ) );
    EXPECT_EQ( 1, machines[0].type );
}
Example #4
0
IMachine *VirtualBoxBridge::cloneVM(QString qName, bool reInitIfaces, IMachine *m)
{
	nsXPIDLString name; name.AssignWithConversion(qName.toStdString().c_str());
	nsXPIDLString osTypeId;
	nsresult rc;

	m->GetOSTypeId(getter_Copies(osTypeId));

	IMachine *new_machine;
	IProgress *progress;

	NS_CHECK_AND_DEBUG_ERROR(virtualBox, FindMachine(name, &new_machine), rc);
	if(rc != VBOX_E_OBJECT_NOT_FOUND)
	{
		std::cout << "machine: " << &new_machine << std::endl;
		return NULL;
	}

	nsXPIDLString settingsFile;
	virtualBox->ComposeMachineFilename(name, NULL, NULL, NULL, getter_Copies(settingsFile));
	std::cout << "Predicted settings file name: " << returnQStringValue(settingsFile).toStdString() << std::endl;

	QFile file(returnQStringValue(settingsFile));
	QFile file_prev(returnQStringValue(settingsFile).append("-prev"));

	if(file.exists())
	{
		if(file.remove())
			std::cerr  << "Deleted old settings file: " << file.fileName().toStdString() << std::endl;
		else
			std::cerr  << "Error while deleting old settings file: " << file.fileName().toStdString() << std::endl;
	}
	if(file_prev.exists())
	{
		if(file_prev.remove())
			std::cerr  << "Deleted old backup settings file: " << file_prev.fileName().toStdString() << std::endl;
		else
			std::cerr  << "Error while deleting old backup settings file: " << file_prev.fileName().toStdString() << std::endl;
	}
	
	QString label = QString::fromUtf8("Creazione macchina \"").append(qName).append("\"...");
	ProgressDialog p(label);
	p.ui->progressBar->setValue(0);
	p.ui->label->setText(label);
	p.open();
	
	NS_CHECK_AND_DEBUG_ERROR(virtualBox, CreateMachine(NULL, name, 0, NULL, osTypeId, NULL, &new_machine), rc);
	if(NS_FAILED(rc))
		return NULL;

	std::cout << "Machine " << qName.toStdString() << " created" << std::endl;

	if(!reInitIfaces)
	{
		uint32_t clone_options[1];
		clone_options[0] = CloneOptions::KeepAllMACs;
		NS_CHECK_AND_DEBUG_ERROR(m, CloneTo(new_machine, CloneMode::MachineState, 1, clone_options, &progress), rc);
	}
	else
		NS_CHECK_AND_DEBUG_ERROR(m, CloneTo(new_machine, CloneMode::MachineState, 0, NULL, &progress), rc);

	if(NS_FAILED(rc))
		return NULL;

	int32_t resultCode;
	PRBool progress_completed;
	do
	{
		uint32_t percent;
		progress->GetCompleted(&progress_completed);
		progress->GetPercent(&percent);
		p.ui->progressBar->setValue(percent);
		p.refresh();
		usleep(750000);
	} while(!progress_completed);

	progress->GetResultCode(&resultCode);

	if (resultCode != 0) // check success
	{
		std::cout << "Error during clone process: " << resultCode << std::endl;
		return NULL;
	}

	std::cout << "Machine " << qName.toStdString() << " cloned" << std::endl;

	p.ui->label->setText(QString::fromUtf8("Registrazione macchina \"").append(qName).append("\"..."));
	NS_CHECK_AND_DEBUG_ERROR(virtualBox, RegisterMachine(new_machine), rc);
	if(NS_FAILED(rc))
		return NULL;
	
	std::cout << "Machine " << qName.toStdString() << " registered" << std::endl;
	return new_machine;
}
int ZEOLoader::OpenFile(QString filename)
{
    QFile file(filename);
    if (filename.toLower().endsWith(".csv")) {
        if (!file.open(QFile::ReadOnly)) {
            qDebug() << "Couldn't open zeo file" << filename;
            return 0;
        }
    } else {// if (filename.toLower().endsWith(".dat")) {

        return 0;
        // not supported.
    }
    QTextStream text(&file);
    QString headerdata=text.readLine();
    QStringList header=headerdata.split(",");
    QString line;
    QStringList linecomp;
    QDateTime start_of_night, end_of_night, rise_time;
    SessionID sid;

    //const qint64 WindowSize=30000;
    qint64 st,tt;
    int stage;

    int ZQ, TotalZ, TimeToZ, TimeInWake, TimeInREM, TimeInLight, TimeInDeep, Awakenings;
    int AlarmReason, SnoozeTime, WakeTone, WakeWindow, AlarmType, MorningFeel;
    QString FirmwareVersion, MyZeoVersion;

    QDateTime FirstAlarmRing, LastAlarmRing, FirstSnoozeTime, LastSnoozeTime, SetAlarmTime;

    QStringList SG, DSG;

    Machine *mach=CreateMachine(p_profile);


    int idxZQ=header.indexOf("ZQ");
    int idxTotalZ=header.indexOf("Total Z");
    int idxAwakenings=header.indexOf("Awakenings");
    int idxSG=header.indexOf("Sleep Graph");
    int idxDSG=header.indexOf("Detailed Sleep Graph");
    int idxTimeInWake=header.indexOf("Time in Wake");
    int idxTimeToZ=header.indexOf("Time to Z");
    int idxTimeInREM=header.indexOf("Time in REM");
    int idxTimeInLight=header.indexOf("Time in Light");
    int idxTimeInDeep=header.indexOf("Time in Deep");
    int idxStartOfNight=header.indexOf("Start of Night");
    int idxEndOfNight=header.indexOf("End of Night");
    int idxRiseTime=header.indexOf("Rise Time");
    int idxAlarmReason=header.indexOf("Alarm Reason");
    int idxSnoozeTime=header.indexOf("Snooze Time");
    int idxWakeTone=header.indexOf("Wake Tone");
    int idxWakeWindow=header.indexOf("Wake Window");
    int idxAlarmType=header.indexOf("Alarm Type");
    int idxFirstAlaramRing=header.indexOf("First Alarm Ring");
    int idxLastAlaramRing=header.indexOf("Last Alarm Ring");
    int idxFirstSnoozeTime=header.indexOf("First Snooze Time");
    int idxLastSnoozeTime=header.indexOf("Last Snooze Time");
    int idxSetAlarmTime=header.indexOf("Set Alarm Time");
    int idxMorningFeel=header.indexOf("Morning Feel");
    int idxFirmwareVersion=header.indexOf("Firmware Version");
    int idxMyZEOVersion=header.indexOf("My ZEO Version");

    bool ok;
    bool dodgy;
    do {
        line=text.readLine();
        dodgy=false;
        if (line.isEmpty()) continue;
        linecomp=line.split(",");
        ZQ=linecomp[idxZQ].toInt(&ok);
        if (!ok) dodgy=true;
        TotalZ=linecomp[idxTotalZ].toInt(&ok);
        if (!ok) dodgy=true;
        TimeToZ=linecomp[idxTimeToZ].toInt(&ok);
        if (!ok) dodgy=true;
        TimeInWake=linecomp[idxTimeInWake].toInt(&ok);
        if (!ok) dodgy=true;
        TimeInREM=linecomp[idxTimeInREM].toInt(&ok);
        if (!ok) dodgy=true;
        TimeInLight=linecomp[idxTimeInLight].toInt(&ok);
        if (!ok) dodgy=true;
        TimeInDeep=linecomp[idxTimeInDeep].toInt(&ok);
        if (!ok) dodgy=true;
        Awakenings=linecomp[idxAwakenings].toInt(&ok);
        if (!ok) dodgy=true;
        start_of_night=QDateTime::fromString(linecomp[idxStartOfNight],"MM/dd/yyyy HH:mm");
        if (!start_of_night.isValid()) dodgy=true;
        end_of_night=QDateTime::fromString(linecomp[idxEndOfNight],"MM/dd/yyyy HH:mm");
        if (!end_of_night.isValid()) dodgy=true;
        rise_time=QDateTime::fromString(linecomp[idxRiseTime],"MM/dd/yyyy HH:mm");
        if (!rise_time.isValid()) dodgy=true;

        AlarmReason=linecomp[idxAlarmReason].toInt(&ok);
        if (!ok) dodgy=true;
        SnoozeTime=linecomp[idxSnoozeTime].toInt(&ok);
        if (!ok) dodgy=true;
        WakeTone=linecomp[idxWakeTone].toInt(&ok);
        if (!ok) dodgy=true;
        WakeWindow=linecomp[idxWakeWindow].toInt(&ok);
        if (!ok) dodgy=true;
        AlarmType=linecomp[idxAlarmType].toInt(&ok);
        if (!ok) dodgy=true;

        if (!linecomp[idxFirstAlaramRing].isEmpty()) {
            FirstAlarmRing=QDateTime::fromString(linecomp[idxFirstAlaramRing],"MM/dd/yyyy HH:mm");
            if (!FirstAlarmRing.isValid()) dodgy=true;
        }
        if (!linecomp[idxLastAlaramRing].isEmpty()) {
            LastAlarmRing=QDateTime::fromString(linecomp[idxLastAlaramRing],"MM/dd/yyyy HH:mm");
            if (!LastAlarmRing.isValid()) dodgy=true;
        }
        if (!linecomp[idxFirstSnoozeTime].isEmpty()) {
            FirstSnoozeTime=QDateTime::fromString(linecomp[idxFirstSnoozeTime],"MM/dd/yyyy HH:mm");
            if (!FirstSnoozeTime.isValid()) dodgy=true;
        }
        if (!linecomp[idxLastSnoozeTime].isEmpty()) {
            LastSnoozeTime=QDateTime::fromString(linecomp[idxLastSnoozeTime],"MM/dd/yyyy HH:mm");
            if (!LastSnoozeTime.isValid()) dodgy=true;
        }
        if (!linecomp[idxSetAlarmTime].isEmpty()) {
            SetAlarmTime=QDateTime::fromString(linecomp[idxSetAlarmTime],"MM/dd/yyyy HH:mm");
            if (!SetAlarmTime.isValid()) dodgy=true;
        }
        MorningFeel=linecomp[idxMorningFeel].toInt(&ok);

        if (!ok) MorningFeel=0;

        FirmwareVersion=linecomp[idxFirmwareVersion];
        if (idxMyZEOVersion>=0) MyZeoVersion=linecomp[idxMyZEOVersion];

        if (dodgy)
            continue;
        SG=linecomp[idxSG].split(" ");
        DSG=linecomp[idxDSG].split(" ");

        const int WindowSize=30000;
        sid=start_of_night.toTime_t();
        if (DSG.size()==0)
            continue;
        if (mach->SessionExists(sid))
            continue;
        Session *sess=new Session(mach,sid);

        sess->settings[ZEO_Awakenings]=Awakenings;
        sess->settings[ZEO_MorningFeel]=MorningFeel;
        sess->settings[ZEO_TimeToZ]=TimeToZ;
        sess->settings[ZEO_ZQ]=ZQ;
        sess->settings[ZEO_TimeInWake]=TimeInWake;
        sess->settings[ZEO_TimeInREM]=TimeInREM;
        sess->settings[ZEO_TimeInLight]=TimeInLight;
        sess->settings[ZEO_TimeInDeep]=TimeInDeep;

        st=qint64(start_of_night.toTime_t()) * 1000L;
        sess->really_set_first(st);
        tt=st;
        EventList * sleepstage=sess->AddEventList(ZEO_SleepStage,EVL_Event,1,0,0,4);
        for (int i=0;i<DSG.size();i++) {
            stage=DSG[i].toInt(&ok);
            if (ok) {
                sleepstage->AddEvent(tt,stage);
            }
            tt+=WindowSize;
        }
        sess->really_set_last(tt);
        int size=DSG.size();
        sess->SetChanged(true);
        mach->AddSession(sess,p_profile);


        qDebug() << linecomp[0] << start_of_night << end_of_night << rise_time << size << "30 second chunks";

    } while (!line.isNull());
    mach->Save();
    return true;
}