Beispiel #1
0
void test_work_queue() {
  WorkQueue<string> q;
  string t = "hello";
  q.push(t);
  string s;
  if(q.try_pop(s, 500)){
    cout << "got " << s << " from queue" << endl;
  }
  bool ok = q.try_pop(s,500);
  if(ok) {
    cout << "failed, should have timed out" << endl;
  }
  else{
    cout << "passed, timed out as expected" << endl;
  }
}
Beispiel #2
0
void test_usb() {
  cout << "test usb" << endl;
  Usb usb;
  usb.write_on_connect("\ntd+\n");
  WorkQueue<string> q;
  usb.add_line_listener(&q);
  cout << "about to run usb " << endl;
  usb.run();
  string s;
  int i = 0;

  auto t_start = high_resolution_clock::now();

  usb.write_line("td+");
  usb.write_line("td+");
  cout << "entering loop for usb" << endl;
  while(q.try_pop(s, 15000)) {
    auto d = high_resolution_clock::now()-t_start;
    duration<double> secs = duration_cast<duration<double>>(d);
    cout << secs.count() << "got item " << s << endl;
    cout << flush;
    i++;
  }
  usb.stop();
  cout << "timed out waiting for data" << endl;
}