示例#1
0
void UpdaterTest::testRun()
{
	vector<string> versionStrings;
	versionStrings.push_back("800");
	versionStrings.push_back("900");
	versionStrings.push_back("1000");
	versionStrings.push_back("Error, no connection");
	versionStrings.push_back("1100");
	versionStrings.push_back("1200");

	MockUpdateServer *mus = new MockUpdateServer(versionStrings);
	Updater *u = new Updater((UpdateServer*)mus, 1100, ".", 0, 0, 0);

	u->run();

	vector<bool> wasDownloadAttempted = mus->_recordedDownloadAttemptsAfterUpdateChecks;
	CPPUNIT_ASSERT_EQUAL((size_t)6, wasDownloadAttempted.size());
	CPPUNIT_ASSERT_EQUAL(false, (bool)wasDownloadAttempted[0]);
	CPPUNIT_ASSERT_EQUAL(false, (bool)wasDownloadAttempted[1]);
	CPPUNIT_ASSERT_EQUAL(false, (bool)wasDownloadAttempted[2]);
	CPPUNIT_ASSERT_EQUAL(false, (bool)wasDownloadAttempted[3]);
	CPPUNIT_ASSERT_EQUAL(false, (bool)wasDownloadAttempted[4]);
	CPPUNIT_ASSERT_EQUAL(true, (bool)wasDownloadAttempted[5]);

	delete mus;
	delete u;

}
示例#2
0
void UpdaterTest::testRunTiming()
{
	vector<string> versionStrings;
	versionStrings.push_back("800");
	versionStrings.push_back("900");
	versionStrings.push_back("1000");
	versionStrings.push_back("Error, no connection");
	versionStrings.push_back("1100");
	versionStrings.push_back("1200");

	MockUpdateServer *mus = new MockUpdateServer(versionStrings);

	int currentVersion = 1100;
	uint retryTimeAfterFailedUpdateCheck = 50;
	uint timeBetweenUpdateChecks = 150;
	Updater *u = new Updater((UpdateServer*)mus,
		currentVersion,
		".",
		retryTimeAfterFailedUpdateCheck,
		timeBetweenUpdateChecks,
		0);

	u->run();

	vector<bool> wasDownloadAttempted = mus->_recordedDownloadAttemptsAfterUpdateChecks;
	CPPUNIT_ASSERT_EQUAL((size_t)6, wasDownloadAttempted.size());
	CPPUNIT_ASSERT_EQUAL(false, (bool)wasDownloadAttempted[0]);
	CPPUNIT_ASSERT_EQUAL(false, (bool)wasDownloadAttempted[1]);
	CPPUNIT_ASSERT_EQUAL(false, (bool)wasDownloadAttempted[2]);
	CPPUNIT_ASSERT_EQUAL(false, (bool)wasDownloadAttempted[3]);
	CPPUNIT_ASSERT_EQUAL(false, (bool)wasDownloadAttempted[4]);
	CPPUNIT_ASSERT_EQUAL(true, (bool)wasDownloadAttempted[5]);

	vector<uint> timeBetweenDownloadAttempts = mus->_recordedTimeForEachUpdateCheck;
	CPPUNIT_ASSERT_EQUAL((size_t)6, timeBetweenDownloadAttempts.size());
	CPPUNIT_ASSERT(timeBetweenDownloadAttempts[0] < 10);
	CPPUNIT_ASSERT(145 < timeBetweenDownloadAttempts[1] && timeBetweenDownloadAttempts[1] < 155);
	CPPUNIT_ASSERT(145 < timeBetweenDownloadAttempts[2] && timeBetweenDownloadAttempts[2] < 155);
	CPPUNIT_ASSERT(145 < timeBetweenDownloadAttempts[3] && timeBetweenDownloadAttempts[3] < 155);
	CPPUNIT_ASSERT(45 < timeBetweenDownloadAttempts[4] && timeBetweenDownloadAttempts[4] < 55);
	CPPUNIT_ASSERT(145 < timeBetweenDownloadAttempts[5] && timeBetweenDownloadAttempts[5] < 155);

}