void test_null_copying() { const any null; any copied = null, assigned; assigned = null; check_true(null.empty(), "empty on null"); check_true(copied.empty(), "empty on copied"); check_true(assigned.empty(), "empty on copied"); }
void tst_schedulBatchAndWait() { GLOBAL_COUNTER = 0; WorkQueue queue; const int COUNT = 5; std::vector<shared_ptr<WorkQueue::Job> > jobs; // Schedule a couple of jobs.. for (int i=0; i<COUNT; ++i) { jobs.push_back(shared_ptr<WorkQueue::Job>(new OneJob(i))); queue.schedule(jobs.back()); } // Wait for the very last one... jobs.back()->waitForCompletion(); for (int i=0; i<COUNT; ++i) { OneJob *j = static_cast<OneJob *>(jobs.at(i).get()); // Job should have completed. check_true(j->hasCompleted()); // This will guarantee that the jobs have been completed in the right // order.. check_equal(j->runId, j->jobId); } cout << __FUNCTION__ << ": ok" << endl; }
void test_default_ctor() { const any value; check_true(value.empty(), "empty"); check_null(any_cast<int>(&value), "any_cast<int>"); check_equal(value.type(), typeid(void), "type"); }
void tst_runOneJob() { GLOBAL_COUNTER = 1; WorkQueue queue; shared_ptr<WorkQueue::Job> job(new OneJob(1)); check_true(!job->hasCompleted()); check_equal(static_cast<OneJob *>(job.get())->runId, -1); queue.schedule(job); // Spin a while loop, waiting 1 ms at a time, to see if the job completes // on its own. If we're still spinning after 10000 iterations, emit a warning // that the thing is probably locked up int counter = 0; while (!job->hasCompleted()) { this_thread::sleep_for(std::chrono::milliseconds(1)); ++counter; if (counter > 10000) { cout << __FUNCTION__ << ": has with all likelyhood timed out, assuming failure!" << endl; check_true(false); } } if (counter == 0) { cout << " - job seems to have completed without any delay.. This is suspicious.." << endl; return; } // The runId should be the one we set up above, namely 1, as this is the // only job executing at present. check_equal(static_cast<OneJob *>(job.get())->runId, 1); cout << __FUNCTION__ << ": ok" << endl; }
void test_swap() { stl::string text = "test message"; any original (text), swapped; stl::string * original_ptr = any_cast<stl::string>(&original); any * swap_result = &original.swap(swapped); check_true(original.empty(), "empty on original"); check_false(swapped.empty(), "empty on swapped"); check_equal(swapped.type(), typeid(stl::string), "type"); check_equal( text, any_cast<stl::string>(swapped), "comparing swapped copy against original text"); check_non_null(original_ptr, "address in pre-swapped original"); check_equal( original_ptr, any_cast<stl::string>(&swapped), "comparing address in swapped against original"); check_equal(swap_result, &original, "address of swap result"); }
void click(int x, int y, DARNIT_TEXT_SURFACE *textplace){ unsigned int hits[8] = {110, 110, 110, 110, 110, 110, 110, 110}; d_bbox_test(buttonlist, x, y, 1, 1, hits, 8); //Now we check if the clicked point is overlapping any of //our four buttons. looked.frames_looked = 0; //Reset the frames looked. if(check_true(hits, button_up)){ if(state == UI){ robot_motors = MOTORS; robot_state = MOTORS_FORWARD; send_message(); //Tell the robot to drive forwards, and send us camera data. } } else if(check_true(hits, button_down)){ //Down button click. if(state == UI){ robot_motors = MOTORS; robot_state = MOTORS_BACKWARDS; send_message(); //Tell the robot to drive backwards, and send us camera data. } } else if(check_true(hits, button_left)){ //Left button click. if(state == UI){ robot_motors = MOTORS; robot_state = TURN_LEFT; send_message(); //Tell the robot to turn left, and send us camera data. } } else if(check_true(hits, button_right)){ //Right button click. if(state == UI){ robot_motors = MOTORS; robot_state = TURN_RIGHT; send_message(); //Tell the robot to turn right, and send us camera data. } } else if(check_true(hits, button_menu)){ //Menu button click. if((state & 0xF) == UI){ state &= 0xF0; state &= 0x0; state |= SOUND; } else if((state & 0xF) == TALK){ state &= 0xF0; state |= UI; } } else if(check_true(hits, button_color)){ if((state & 0xF) == UI){ state &= 0xF0; state |= TALK; } else if ((state & 0xF) == SOUND){ state &= 0xF0; state |= UI; } } else { //And if we *haven't* pressed a button, this is where we go. if(state == UI){ robot_motors = MOTORS; robot_state = 0; send_message(); //Tell the robot to shut down its motors, and send us camera data. } } }