void repaint_helper(IScoreboard *pScoreboard, bool bRepaintUsed) { bool bRes = false; // Test Invalidate() // if repaint is supported, then invalidating should cause 'repaint needed' to be true, // otherwise it shouldn't have any effect pScoreboard->Invalidate(); bRes = pScoreboard->is_repaint_needed(); TEST_CHECK_EQUAL(bRes, bRepaintUsed); // clear 'repaint needed' flag bRes = pScoreboard->RepaintIfNeeded(); TEST_CHECK_EQUAL(bRes, bRepaintUsed); bRes = pScoreboard->is_repaint_needed(); TEST_CHECK(!bRes); bRes = pScoreboard->RepaintIfNeeded(); TEST_CHECK(!bRes); // force a repaint pScoreboard->pre_set_digit(0, IScoreboard::CREDITS1_0); pScoreboard->pre_set_digit(1, IScoreboard::CREDITS1_0); bRes = pScoreboard->is_repaint_needed(); TEST_CHECK_EQUAL(bRes, bRepaintUsed); }
void files_cache_tests::test_delete_file(const int & n) { TEST_SUBTEST_START(n, "delete_file", false); // should have full cache (2) from previous test TEST_CHECK_EQUAL(_files_cache->get_cache_size(), 2); // should have had #3 from previous test in the cache _files_cache->delete_file(files_cache_tests::get_filename(3)); TEST_CHECK_EQUAL(_files_cache->get_cache_size(), 1); // done TEST_SUBTEST_END(); }
// check for the 'A' used in Space Ace Enhanced (SAE) void test_scoreboard_for_a(IScoreboard *pScoreboard) { bool bRes = false; unsigned int uVal = 0; bRes = pScoreboard->pre_set_digit(0xC, IScoreboard::PLAYER2_0); TEST_CHECK(bRes); // a repaint should be needed at this point bRes = pScoreboard->is_repaint_needed(); TEST_CHECK(bRes); bRes = pScoreboard->pre_set_digit(0xE, IScoreboard::PLAYER2_0); TEST_CHECK(bRes); // repaint should happen here too, digit should now be set to 'A' bRes = pScoreboard->is_repaint_needed(); TEST_CHECK(bRes); // when cycling 0xC and 0xE on the scoreboard, that means we should have an 'A' pScoreboard->pre_get_digit(uVal, IScoreboard::PLAYER2_0); TEST_CHECK_EQUAL(uVal, 0x10); // clear repaint_needed flag for next test pScoreboard->RepaintIfNeeded(); // back to 0xC, we should still have an 'A' bRes = pScoreboard->pre_set_digit(0xC, IScoreboard::PLAYER2_0); TEST_CHECK(bRes); pScoreboard->pre_get_digit(uVal, IScoreboard::PLAYER2_0); TEST_CHECK_EQUAL(uVal, 0x10); // we should still be at 'A', so a repaint should not occur bRes = pScoreboard->is_repaint_needed(); TEST_CHECK(!bRes); // repaint should occur if we set digit to something else pScoreboard->pre_set_digit(0, IScoreboard::PLAYER2_0); bRes = pScoreboard->is_repaint_needed(); TEST_CHECK(bRes); // clear repaint_needed flag for next test pScoreboard->RepaintIfNeeded(); // but if we set it again, repaint should not occur pScoreboard->pre_set_digit(0, IScoreboard::PLAYER2_0); bRes = pScoreboard->is_repaint_needed(); TEST_CHECK(!bRes); }
void visibility_helper(IScoreboard *pScoreboard, bool bExpectedResult) { bool bRes = false; // visibility probably starts as on by default, so disable it bRes = pScoreboard->ChangeVisibility(false); TEST_CHECK_EQUAL(bRes, bExpectedResult); bRes = pScoreboard->ChangeVisibility(true); TEST_CHECK_EQUAL(bRes, bExpectedResult); // if we expect to be able to change the visibility, then make sure that repaint is now needed if (bExpectedResult == true) { bRes = pScoreboard->is_repaint_needed(); TEST_CHECK(bRes); // trying to change to the current state should return false bRes = pScoreboard->ChangeVisibility(true); TEST_CHECK(!bRes); } }
void annunciator_helper(IScoreboard *pScoreboard, IScoreboard::WhichDigit digit, bool bRepaintExpected) { bool bRes = false; bRes = pScoreboard->pre_set_digit(0xC, digit); TEST_CHECK(bRes); bRes = pScoreboard->is_repaint_needed(); TEST_CHECK(bRes); pScoreboard->RepaintIfNeeded(); // now set the digit again, we should not do any repaint bRes = pScoreboard->pre_set_digit(0xC, digit); TEST_CHECK(bRes); bRes = pScoreboard->is_repaint_needed(); TEST_CHECK_EQUAL(bRes, bRepaintExpected); pScoreboard->RepaintIfNeeded(); }
void test_scoreboard_helper(IScoreboard *pScoreboard) { bool bRes = false; unsigned int uVal = 0; // Test to make sure that scoreboard has been initialized to all 0's for (unsigned int u = 0; u < IScoreboard::DIGIT_COUNT; u++) { bRes = pScoreboard->pre_get_digit(uVal, (IScoreboard::WhichDigit) u); TEST_REQUIRE(bRes); TEST_CHECK_EQUAL(uVal, 0x0F); } // try a value that's out of range bRes = pScoreboard->pre_get_digit(uVal, IScoreboard::DIGIT_COUNT); TEST_CHECK(!bRes); // now try the convenience functions // CREDITS // out of range bRes = pScoreboard->update_credits(2, 0); // try a value out of range TEST_CHECK(!bRes); // out of range 2 bRes = pScoreboard->update_credits(0, 17); // try a value out of range TEST_CHECK(!bRes); // in range bRes = pScoreboard->update_credits(1, 5); TEST_CHECK(bRes); bRes = pScoreboard->pre_get_digit(uVal, IScoreboard::CREDITS1_1); TEST_CHECK_EQUAL(uVal, 5); // PLAYER LIVES // out of range bRes = pScoreboard->update_player_lives(0, 2); TEST_CHECK(!bRes); // within range bRes = pScoreboard->update_player_lives(9, 1); TEST_CHECK(bRes); // make sure value is correct bRes = pScoreboard->pre_get_digit(uVal, IScoreboard::LIVES1); TEST_CHECK_EQUAL(uVal, 9); // test annunciator value bRes = pScoreboard->update_player_lives(0x0C, 1); TEST_CHECK(bRes); // PLAYER SCORE // out of range on digit bRes = pScoreboard->update_player_score(6, 0, 0); TEST_CHECK(!bRes); // out of range on player bRes = pScoreboard->update_player_score(5, 0, 2); TEST_CHECK(!bRes); // should pass bRes = pScoreboard->update_player_score(5, 9, 1); TEST_CHECK(bRes); bRes = pScoreboard->pre_get_digit(uVal, IScoreboard::PLAYER2_5); TEST_CHECK_EQUAL(uVal, 9); // make sure that player1's digit hasn't changed bRes = pScoreboard->pre_get_digit(uVal, IScoreboard::PLAYER1_5); TEST_CHECK_EQUAL(uVal, 0xF); // test annunciator values bRes = pScoreboard->update_player_score(4, 0x0C, 0); TEST_CHECK(bRes); // now test player 1's score bRes = pScoreboard->update_player_score(1, 6, 0); TEST_CHECK(bRes); bRes = pScoreboard->pre_get_digit(uVal, IScoreboard::PLAYER1_1); TEST_CHECK_EQUAL(uVal, 6); }
void files_cache_tests::test_open_file(const int & n) { TEST_SUBTEST_START(n, "open_file", false); // "touch" all the files for(int ii = 0; ii < FILENAME_MAX_NUM; ++ii) { my::filename_t filename = files_cache_tests::get_filename(ii); rrdb_files_cache::fstream_ptr fs = rrdb_files_cache::open_file( _files_cache->get_full_path(filename), std::ios_base::trunc ); fs->close(); } my::time_t ts = time(NULL); my::size_t size = 2; // this is what we set in init my::size_t hits = 0; my::size_t misses = 0; // insert two files, both should be misses _files_cache->open_file(files_cache_tests::get_filename(1), ts + 0); ++misses; _files_cache->open_file(files_cache_tests::get_filename(2), ts + 1); ++misses; _files_cache->open_file(files_cache_tests::get_filename(3), ts + 2); ++misses; TEST_CHECK_EQUAL(_files_cache->get_cache_size(), size); TEST_CHECK_EQUAL(_files_cache->get_cache_hits(), hits); TEST_CHECK_EQUAL(_files_cache->get_cache_misses(), misses); // insert the file #2 and #3 again: both should be in the cache... this time // we put later timestamp on #2 _files_cache->open_file(files_cache_tests::get_filename(3), ts + 3); ++hits; _files_cache->open_file(files_cache_tests::get_filename(2), ts + 4); ++hits; TEST_CHECK_EQUAL(_files_cache->get_cache_size(), size); TEST_CHECK_EQUAL(_files_cache->get_cache_hits(), hits); TEST_CHECK_EQUAL(_files_cache->get_cache_misses(), misses); // now if we insert another one, then it should kick out #3 since we "used" #2 more recently _files_cache->open_file(files_cache_tests::get_filename(4), ts + 5); ++misses; TEST_CHECK_EQUAL(_files_cache->get_cache_size(), size); TEST_CHECK_EQUAL(_files_cache->get_cache_hits(), hits); TEST_CHECK_EQUAL(_files_cache->get_cache_misses(), misses); // #2 should be in the cache _files_cache->open_file(files_cache_tests::get_filename(2), ts + 6); ++hits; TEST_CHECK_EQUAL(_files_cache->get_cache_size(), size); TEST_CHECK_EQUAL(_files_cache->get_cache_hits(), hits); TEST_CHECK_EQUAL(_files_cache->get_cache_misses(), misses); // #3 should've been kicked from the cache _files_cache->open_file(files_cache_tests::get_filename(3), ts + 7); ++misses; TEST_CHECK_EQUAL(_files_cache->get_cache_size(), size); TEST_CHECK_EQUAL(_files_cache->get_cache_hits(), hits); TEST_CHECK_EQUAL(_files_cache->get_cache_misses(), misses); // done TEST_SUBTEST_END(); }