int compareVersion(string version1, string version2) {
     vector<int> v1 = split(version1);
     vector<int> v2 = split(version2);
     
     int pos = 0;
     while (pos < v1.size() && pos < v2.size()) {
         if (v1[pos] > v2[pos])
             return 1;
         if (v1[pos] < v2[pos])
             return -1;
         ++pos;
     }
     
     if (pos < v1.size()) {
         if (allZero(v1, pos))
             return 0;
         return 1;
     }
     if (pos < v2.size()) {
         if (allZero(v2, pos))
             return 0;
         return -1;
     }
     return 0;
 }
Exemple #2
0
BVValue BVValue::shift(const BVValue& _other, bool _left, bool _arithmetic) const {
	std::size_t firstSize = width() - 1;
	std::size_t highestRelevantPos = 0;

	bool fillWithOnes = !_left && _arithmetic && (*this)[width() - 1];

	while ((firstSize >>= 1) != 0)
		++highestRelevantPos;

	for (std::size_t i = highestRelevantPos + 1; i < _other.width(); ++i) {
		if (_other[i]) {
			Base allZero(width());
			return BVValue(fillWithOnes ? ~allZero : allZero);
		}
	}

	Base shifted(fillWithOnes ? ~mValue : mValue);
	std::size_t shiftBy = 1;

	for (std::size_t i = 0; i <= highestRelevantPos && i < _other.width(); ++i) {
		if (_other[i]) {
			if (_left) {
				shifted <<= shiftBy;
			} else {
				shifted >>= shiftBy;
			}
		}
		shiftBy *= 2;
	}

	return BVValue(fillWithOnes ? ~shifted : shifted);
}
int main(void)
{
	FILE *fp;
	unsigned char levelBuf[READ_LEVEL_DATA_SIZE];
	unsigned char *levelData;
	int curLevel = 0;
	int readSize= 0, isGood = 1;
	unsigned long curPos = MAP_START_POSITION;
	unsigned long dspPos = curPos;
	
	if((fp = fopen(FILE_NAME, "rb")) ==NULL) {
		printf("Open file \"%s\" failed !\n", FILE_NAME);
		return 1;
	}
	
	if(fseek(fp, curPos, SEEK_SET) != 0) {
		printf("Fseek error ! @%d\n", __LINE__);
		fclose(fp);
		return 1;
	}

	dumpTitle();

	printf("var %s = [\n", DATA_VAR_NAME);	

	while(
#ifndef START_ALL_ISGOOD	
		   isGood &&
#endif
		   curLevel < MAX_LEVEL && 
	       (readSize = fread(levelBuf, sizeof(char), READ_LEVEL_DATA_SIZE, fp)) ==  READ_LEVEL_DATA_SIZE 
	){
		levelData = levelBuf;	
#ifdef START_GOOD_BYTE
		unsigned char startByte = *(levelData++);
		
		switch(startByte) {
		case START_SKIP_BYTE1:
#ifdef START_SKIP_BYTE2			
		case START_SKIP_BYTE2:
#endif			
#ifdef START_SKIP_BYTE3
		case START_SKIP_BYTE3:
#endif			
#ifdef START_SKIP_BYTE4
		case START_SKIP_BYTE4:
#endif			
			//printf("SKIP0 - %x\n", dspPos);
			break;
		case 0:	 //good if not allzero
			if(allZero(levelData)){
				//printf("SKIP1 - %x\n", dspPos);
				break;
			}
#ifdef START_ALL_ISGOOD			
		default:	
#endif		
		case START_GOOD_BYTE:
#endif	       
			if((isGood = goodLevel(levelData))) {
				//dumpLevel(++curLevel, levelData);
				//printf("%x", dspPos);
				dumpLevel4JavaScript(++curLevel, levelData);
			}
#ifdef START_GOOD_BYTE
			break;
#ifndef START_ALL_ISGOOD
		default:
			isGood = 0;
			printf("%x", dspPos);
			break;
#endif			
		}
#endif	
		dspPos += READ_LEVEL_DATA_SIZE;
	}
	printf("];\n");
	
	fclose(fp);	
}
    void degreesToString_data()
    {
        QTest::addColumn<QGeoCoordinate>("coord");
        QTest::addColumn<QGeoCoordinate::CoordinateFormat>("format");
        QTest::addColumn<QString>("string");

        QGeoCoordinate northEast(27.46758, 153.027892);
        QGeoCoordinate northEastWithAlt(27.46758, 153.027892, 28.23411);
        QGeoCoordinate southEast(-27.46758, 153.027892);
        QGeoCoordinate southEastWithAlt(-27.46758, 153.027892, 28.23411);
        QGeoCoordinate northWest(27.46758, -153.027892);
        QGeoCoordinate northWestWithAlt(27.46758, -153.027892, 28.23411);
        QGeoCoordinate southWest(-27.46758, -153.027892);
        QGeoCoordinate southWestWithAlt(-27.46758, -153.027892, 28.23411);

        QGeoCoordinate empty;
        QGeoCoordinate toohigh(90.1, 180.1);
        QGeoCoordinate toolow(-90.1, -180.1);
        QGeoCoordinate zeroLatLong(0.0, 0.0);
        QGeoCoordinate allZero(0.0, 0.0, 0.0);

        QTest::newRow("empty, dd, no hemisphere")
                << empty << QGeoCoordinate::Degrees
                << QString();
        QTest::newRow("empty, dd, hemisphere")
                << empty << QGeoCoordinate::DegreesWithHemisphere
                << QString();
        QTest::newRow("empty, dm, no hemisphere")
                << empty << QGeoCoordinate::DegreesMinutes
                << QString();
        QTest::newRow("empty, dm, hemisphere")
                << empty << QGeoCoordinate::DegreesMinutesWithHemisphere
                << QString();
        QTest::newRow("empty, dms, no hemisphere")
                << empty << QGeoCoordinate::DegreesMinutesSeconds
                << QString();
        QTest::newRow("empty, dms, hemisphere")
                << empty << QGeoCoordinate::DegreesMinutesSecondsWithHemisphere
                << QString();

        QTest::newRow("too low, dd, no hemisphere")
                << toolow << QGeoCoordinate::Degrees
                << QString();
        QTest::newRow("too low, dd, hemisphere")
                << toolow << QGeoCoordinate::DegreesWithHemisphere
                << QString();
        QTest::newRow("too low, dm, no hemisphere")
                << toolow << QGeoCoordinate::DegreesMinutes
                << QString();
        QTest::newRow("too low, dm, hemisphere")
                << toolow << QGeoCoordinate::DegreesMinutesWithHemisphere
                << QString();
        QTest::newRow("too low, dms, no hemisphere")
                << toolow << QGeoCoordinate::DegreesMinutesSeconds
                << QString();
        QTest::newRow("too low, dms, hemisphere")
                << toolow << QGeoCoordinate::DegreesMinutesSecondsWithHemisphere
                << QString();

        QTest::newRow("too high, dd, no hemisphere")
                << toohigh << QGeoCoordinate::Degrees
                << QString();
        QTest::newRow("too high, dd, hemisphere")
                << toohigh << QGeoCoordinate::DegreesWithHemisphere
                << QString();
        QTest::newRow("too high, dm, no hemisphere")
                << toohigh << QGeoCoordinate::DegreesMinutes
                << QString();
        QTest::newRow("too high, dm, hemisphere")
                << toohigh << QGeoCoordinate::DegreesMinutesWithHemisphere
                << QString();
        QTest::newRow("too high, dms, no hemisphere")
                << toohigh << QGeoCoordinate::DegreesMinutesSeconds
                << QString();
        QTest::newRow("too high, dms, hemisphere")
                << toohigh << QGeoCoordinate::DegreesMinutesSecondsWithHemisphere
                << QString();

        QTest::newRow("zeroLatLong, dd, no hemisphere")
                << zeroLatLong << QGeoCoordinate::Degrees
                << QString("0.00000%1, 0.00000%1").arg(DEGREES_SYMB);
        QTest::newRow("zeroLatLong, dd, hemisphere")
                << zeroLatLong << QGeoCoordinate::DegreesWithHemisphere
                << QString("0.00000%1, 0.00000%1").arg(DEGREES_SYMB);
        QTest::newRow("zeroLatLong, dm, no hemisphere")
                << zeroLatLong << QGeoCoordinate::DegreesMinutes
                << QString("0%1 0.000', 0%1 0.000'").arg(DEGREES_SYMB);
        QTest::newRow("zeroLatLong, dm, hemisphere")
                << zeroLatLong << QGeoCoordinate::DegreesMinutesWithHemisphere
                << QString("0%1 0.000', 0%1 0.000'").arg(DEGREES_SYMB);
        QTest::newRow("zeroLatLong, dms, no hemisphere")
                << zeroLatLong << QGeoCoordinate::DegreesMinutesSeconds
                << QString("0%1 0' 0.0\", 0%1 0' 0.0\"").arg(DEGREES_SYMB);
        QTest::newRow("zeroLatLong, dms, hemisphere")
                << zeroLatLong << QGeoCoordinate::DegreesMinutesSecondsWithHemisphere
                << QString("0%1 0' 0.0\", 0%1 0' 0.0\"").arg(DEGREES_SYMB);

        QTest::newRow("allZero, dd, no hemisphere")
                << allZero << QGeoCoordinate::Degrees
                << QString("0.00000%1, 0.00000%1, 0m").arg(DEGREES_SYMB);
        QTest::newRow("allZero, dd, hemisphere")
                << allZero << QGeoCoordinate::DegreesWithHemisphere
                << QString("0.00000%1, 0.00000%1, 0m").arg(DEGREES_SYMB);
        QTest::newRow("allZero, dm, no hemisphere")
                << allZero << QGeoCoordinate::DegreesMinutes
                << QString("0%1 0.000', 0%1 0.000', 0m").arg(DEGREES_SYMB);
        QTest::newRow("allZero, dm, hemisphere")
                << allZero << QGeoCoordinate::DegreesMinutesWithHemisphere
                << QString("0%1 0.000', 0%1 0.000', 0m").arg(DEGREES_SYMB);
        QTest::newRow("allZero, dms, no hemisphere")
                << allZero << QGeoCoordinate::DegreesMinutesSeconds
                << QString("0%1 0' 0.0\", 0%1 0' 0.0\", 0m").arg(DEGREES_SYMB);
        QTest::newRow("allZero, dms, hemisphere")
                << allZero << QGeoCoordinate::DegreesMinutesSecondsWithHemisphere
                << QString("0%1 0' 0.0\", 0%1 0' 0.0\", 0m").arg(DEGREES_SYMB);

        QTest::newRow("NE, dd, no hemisphere")
                << northEast << QGeoCoordinate::Degrees
                << QString("27.46758%1, 153.02789%1").arg(DEGREES_SYMB);
        QTest::newRow("NE, dd, hemisphere")
                << northEast << QGeoCoordinate::DegreesWithHemisphere
                << QString("27.46758%1 N, 153.02789%1 E").arg(DEGREES_SYMB);
        QTest::newRow("NE, dm, no hemisphere")
                << northEast << QGeoCoordinate::DegreesMinutes
                << QString("27%1 28.055', 153%1 1.674'").arg(DEGREES_SYMB);
        QTest::newRow("NE, dm, hemisphere")
                << northEast << QGeoCoordinate::DegreesMinutesWithHemisphere
                << QString("27%1 28.055' N, 153%1 1.674' E").arg(DEGREES_SYMB);
        QTest::newRow("NE, dms, no hemisphere")
                << northEast << QGeoCoordinate::DegreesMinutesSeconds
                << QString("27%1 28' 3.3\", 153%1 1' 40.4\"").arg(DEGREES_SYMB);
        QTest::newRow("NE, dms, hemisphere")
                << northEast << QGeoCoordinate::DegreesMinutesSecondsWithHemisphere
                << QString("27%1 28' 3.3\" N, 153%1 1' 40.4\" E").arg(DEGREES_SYMB);

        QTest::newRow("NE with alt, dd, no hemisphere")
                << northEastWithAlt << QGeoCoordinate::Degrees
                << QString("27.46758%1, 153.02789%1, 28.2341m").arg(DEGREES_SYMB);
        QTest::newRow("NE with alt, dd, hemisphere")
                << northEastWithAlt << QGeoCoordinate::DegreesWithHemisphere
                << QString("27.46758%1 N, 153.02789%1 E, 28.2341m").arg(DEGREES_SYMB);
        QTest::newRow("NE with alt, dm, no hemisphere")
                << northEastWithAlt << QGeoCoordinate::DegreesMinutes
                << QString("27%1 28.055', 153%1 1.674', 28.2341m").arg(DEGREES_SYMB);
        QTest::newRow("NE with alt, dm, hemisphere")
                << northEastWithAlt << QGeoCoordinate::DegreesMinutesWithHemisphere
                << QString("27%1 28.055' N, 153%1 1.674' E, 28.2341m").arg(DEGREES_SYMB);
        QTest::newRow("NE with alt, dms, no hemisphere")
                << northEastWithAlt << QGeoCoordinate::DegreesMinutesSeconds
                << QString("27%1 28' 3.3\", 153%1 1' 40.4\", 28.2341m").arg(DEGREES_SYMB);
        QTest::newRow("NE with alt, dms, hemisphere")
                << northEastWithAlt << QGeoCoordinate::DegreesMinutesSecondsWithHemisphere
                << QString("27%1 28' 3.3\" N, 153%1 1' 40.4\" E, 28.2341m").arg(DEGREES_SYMB);

        QTest::newRow("SE, dd, no hemisphere")
                << southEast << QGeoCoordinate::Degrees
                << QString("-27.46758%1, 153.02789%1").arg(DEGREES_SYMB);
        QTest::newRow("SE, dd, hemisphere")
                << southEast << QGeoCoordinate::DegreesWithHemisphere
                << QString("27.46758%1 S, 153.02789%1 E").arg(DEGREES_SYMB);
        QTest::newRow("SE, dm, no hemisphere")
                << southEast << QGeoCoordinate::DegreesMinutes
                << QString("-27%1 28.055', 153%1 1.674'").arg(DEGREES_SYMB);
        QTest::newRow("SE, dm, hemisphere")
                << southEast << QGeoCoordinate::DegreesMinutesWithHemisphere
                << QString("27%1 28.055' S, 153%1 1.674' E").arg(DEGREES_SYMB);
        QTest::newRow("SE, dms, no hemisphere")
                << southEast << QGeoCoordinate::DegreesMinutesSeconds
                << QString("-27%1 28' 3.3\", 153%1 1' 40.4\"").arg(DEGREES_SYMB);
        QTest::newRow("SE, dms, hemisphere")
                << southEast << QGeoCoordinate::DegreesMinutesSecondsWithHemisphere
                << QString("27%1 28' 3.3\" S, 153%1 1' 40.4\" E").arg(DEGREES_SYMB);

        QTest::newRow("SE with alt, dd, no hemisphere, 28.2341m")
                << southEastWithAlt << QGeoCoordinate::Degrees
                << QString("-27.46758%1, 153.02789%1, 28.2341m").arg(DEGREES_SYMB);
        QTest::newRow("SE with alt, dd, hemisphere, 28.2341m")
                << southEastWithAlt << QGeoCoordinate::DegreesWithHemisphere
                << QString("27.46758%1 S, 153.02789%1 E, 28.2341m").arg(DEGREES_SYMB);
        QTest::newRow("SE with alt, dm, no hemisphere, 28.2341m")
                << southEastWithAlt << QGeoCoordinate::DegreesMinutes
                << QString("-27%1 28.055', 153%1 1.674', 28.2341m").arg(DEGREES_SYMB);
        QTest::newRow("SE with alt, dm, hemisphere, 28.2341m")
                << southEastWithAlt << QGeoCoordinate::DegreesMinutesWithHemisphere
                << QString("27%1 28.055' S, 153%1 1.674' E, 28.2341m").arg(DEGREES_SYMB);
        QTest::newRow("SE with alt, dms, no hemisphere, 28.2341m")
                << southEastWithAlt << QGeoCoordinate::DegreesMinutesSeconds
                << QString("-27%1 28' 3.3\", 153%1 1' 40.4\", 28.2341m").arg(DEGREES_SYMB);
        QTest::newRow("SE with alt, dms, hemisphere, 28.2341m")
                << southEastWithAlt << QGeoCoordinate::DegreesMinutesSecondsWithHemisphere
                << QString("27%1 28' 3.3\" S, 153%1 1' 40.4\" E, 28.2341m").arg(DEGREES_SYMB);;

        QTest::newRow("NW, dd, no hemisphere")
                << northWest << QGeoCoordinate::Degrees
                << QString("27.46758%1, -153.02789%1").arg(DEGREES_SYMB);
        QTest::newRow("NW, dd, hemisphere")
                << northWest << QGeoCoordinate::DegreesWithHemisphere
                << QString("27.46758%1 N, 153.02789%1 W").arg(DEGREES_SYMB);
        QTest::newRow("NW, dm, no hemisphere")
                << northWest << QGeoCoordinate::DegreesMinutes
                << QString("27%1 28.055', -153%1 1.674'").arg(DEGREES_SYMB);
        QTest::newRow("NW, dm, hemisphere")
                << northWest << QGeoCoordinate::DegreesMinutesWithHemisphere
                << QString("27%1 28.055' N, 153%1 1.674' W").arg(DEGREES_SYMB);
        QTest::newRow("NW, dms, no hemisphere")
                << northWest << QGeoCoordinate::DegreesMinutesSeconds
                << QString("27%1 28' 3.3\", -153%1 1' 40.4\"").arg(DEGREES_SYMB);
        QTest::newRow("NW, dms, hemisphere")
                << northWest << QGeoCoordinate::DegreesMinutesSecondsWithHemisphere
                << QString("27%1 28' 3.3\" N, 153%1 1' 40.4\" W").arg(DEGREES_SYMB);

        QTest::newRow("NW with alt, dd, no hemisphere, 28.2341m")
                << northWestWithAlt << QGeoCoordinate::Degrees
                << QString("27.46758%1, -153.02789%1, 28.2341m").arg(DEGREES_SYMB);
        QTest::newRow("NW with alt, dd, hemisphere, 28.2341m")
                << northWestWithAlt << QGeoCoordinate::DegreesWithHemisphere
                << QString("27.46758%1 N, 153.02789%1 W, 28.2341m").arg(DEGREES_SYMB);
        QTest::newRow("NW with alt, dm, no hemisphere, 28.2341m")
                << northWestWithAlt << QGeoCoordinate::DegreesMinutes
                << QString("27%1 28.055', -153%1 1.674', 28.2341m").arg(DEGREES_SYMB);
        QTest::newRow("NW with alt, dm, hemisphere, 28.2341m")
                << northWestWithAlt << QGeoCoordinate::DegreesMinutesWithHemisphere
                << QString("27%1 28.055' N, 153%1 1.674' W, 28.2341m").arg(DEGREES_SYMB);
        QTest::newRow("NW with alt, dms, no hemisphere, 28.2341m")
                << northWestWithAlt << QGeoCoordinate::DegreesMinutesSeconds
                << QString("27%1 28' 3.3\", -153%1 1' 40.4\", 28.2341m").arg(DEGREES_SYMB);
        QTest::newRow("NW with alt, dms, hemisphere, 28.2341m")
                << northWestWithAlt << QGeoCoordinate::DegreesMinutesSecondsWithHemisphere
                << QString("27%1 28' 3.3\" N, 153%1 1' 40.4\" W, 28.2341m").arg(DEGREES_SYMB);

        QTest::newRow("SW, dd, no hemisphere")
                << southWest << QGeoCoordinate::Degrees
                << QString("-27.46758%1, -153.02789%1").arg(DEGREES_SYMB);
        QTest::newRow("SW, dd, hemisphere")
                << southWest << QGeoCoordinate::DegreesWithHemisphere
                << QString("27.46758%1 S, 153.02789%1 W").arg(DEGREES_SYMB);
        QTest::newRow("SW, dm, no hemisphere")
                << southWest << QGeoCoordinate::DegreesMinutes
                << QString("-27%1 28.055', -153%1 1.674'").arg(DEGREES_SYMB);
        QTest::newRow("SW, dm, hemisphere")
                << southWest << QGeoCoordinate::DegreesMinutesWithHemisphere
                << QString("27%1 28.055' S, 153%1 1.674' W").arg(DEGREES_SYMB);
        QTest::newRow("SW, dms, no hemisphere")
                << southWest << QGeoCoordinate::DegreesMinutesSeconds
                << QString("-27%1 28' 3.3\", -153%1 1' 40.4\"").arg(DEGREES_SYMB);
        QTest::newRow("SW, dms, hemisphere")
                << southWest << QGeoCoordinate::DegreesMinutesSecondsWithHemisphere
                << QString("27%1 28' 3.3\" S, 153%1 1' 40.4\" W").arg(DEGREES_SYMB);

        QTest::newRow("SW with alt, dd, no hemisphere, 28.2341m")
                << southWestWithAlt << QGeoCoordinate::Degrees
                << QString("-27.46758%1, -153.02789%1, 28.2341m").arg(DEGREES_SYMB);
        QTest::newRow("SW with alt, dd, hemisphere, 28.2341m")
                << southWestWithAlt << QGeoCoordinate::DegreesWithHemisphere
                << QString("27.46758%1 S, 153.02789%1 W, 28.2341m").arg(DEGREES_SYMB);
        QTest::newRow("SW with alt, dm, no hemisphere, 28.2341m")
                << southWestWithAlt << QGeoCoordinate::DegreesMinutes
                << QString("-27%1 28.055', -153%1 1.674', 28.2341m").arg(DEGREES_SYMB);
        QTest::newRow("SW with alt, dm, hemisphere, 28.2341m")
                << southWestWithAlt << QGeoCoordinate::DegreesMinutesWithHemisphere
                << QString("27%1 28.055' S, 153%1 1.674' W, 28.2341m").arg(DEGREES_SYMB);
        QTest::newRow("SW with alt, dms, no hemisphere, 28.2341m")
                << southWestWithAlt << QGeoCoordinate::DegreesMinutesSeconds
                << QString("-27%1 28' 3.3\", -153%1 1' 40.4\", 28.2341m").arg(DEGREES_SYMB);
        QTest::newRow("SW with alt, dms, hemisphere, 28.2341m")
                << southWestWithAlt << QGeoCoordinate::DegreesMinutesSecondsWithHemisphere
                << QString("27%1 28' 3.3\" S, 153%1 1' 40.4\" W, 28.2341m").arg(DEGREES_SYMB);

        QTest::newRow("Wrap seconds to Minutes DMSH")
                << QGeoCoordinate(1.1333333, 1.1333333) << QGeoCoordinate::DegreesMinutesSecondsWithHemisphere
                << QString( "1%1 8' 0.0\" N, 1%1 8' 0.0\" E").arg(DEGREES_SYMB);
        QTest::newRow("Wrap seconds to Minutes DMS")
                << QGeoCoordinate(1.1333333, 1.1333333) << QGeoCoordinate::DegreesMinutesSeconds
                << QString( "1%1 8' 0.0\", 1%1 8' 0.0\"").arg(DEGREES_SYMB);
        QTest::newRow("Wrap minutes to Degrees DMH")
                << QGeoCoordinate(1.999999, 1.999999) << QGeoCoordinate::DegreesMinutesWithHemisphere
                << QString( "2%1 0.000' N, 2%1 0.000' E").arg(DEGREES_SYMB);
        QTest::newRow("Wrap minutes to Degrees DM")
                << QGeoCoordinate(1.999999, 1.999999) << QGeoCoordinate::DegreesMinutes
                << QString( "2%1 0.000', 2%1 0.000'").arg(DEGREES_SYMB);

        QTest::newRow("Wrap seconds to minutes to Degrees DM -> above valid long/lat values")
                << QGeoCoordinate(89.9999, 179.9999) << QGeoCoordinate::DegreesMinutesSeconds
                << QString( "90%1 0' 0.0\", 180%1 0' 0.0\"").arg(DEGREES_SYMB);

        QTest::newRow("Wrap minutes to Degrees DM ->above valid long/lat values")
                << QGeoCoordinate(89.9999, 179.9999) << QGeoCoordinate::DegreesMinutes
                << QString( "90%1 0.000', 180%1 0.000'").arg(DEGREES_SYMB);

    }
void FlightController::disarm(){
	throttleServo.writeMicroseconds(1000);
	yawServo.writeMicroseconds(2000);
	delay(6000);
	allZero();
}