Example #1
0
END_TEST

START_TEST(showbar_with_big_max_and_small_numbers)
{
	int len;
	suppress_output();
	len = showbar(0, 1, 0, 2, 1000, 10);
	ck_assert_int_eq(len, 0);
}
Example #2
0
END_TEST

START_TEST(showbar_with_zero_len_is_nothing)
{
	int len;
	suppress_output();
	len = showbar(1, 0, 2, 0, 3, 0);
	ck_assert_int_eq(len, 0);
}
Example #3
0
END_TEST

START_TEST(showbar_with_max_smaller_than_real_max)
{
	int len;
	suppress_output();
	len = showbar(0, 1, 0, 2, 1, 10);
	ck_assert_int_eq(len, 0);
}
Example #4
0
int Output::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: start(); break;
        case 1: showbar(); break;
        case 2: hidebar(); break;
        case 3: startTestLoop(); break;
        case 4: paintEvent((*reinterpret_cast< QPaintEvent*(*)>(_a[1]))); break;
        case 5: hideMessage(); break;
        default: ;
        }
        _id -= 6;
    }
    return _id;
}
Example #5
0
END_TEST

START_TEST(showbar_with_half_and_half)
{
	int pipe, len;
	char buffer[512];
	memset(&buffer, '\0', sizeof(buffer));

	defaultcfg();
	cfg.rxchar[0] = 'r';
	cfg.txchar[0] = 't';
	pipe = pipe_output();
	len = showbar(0, 1, 0, 1, 2, 10);
	ck_assert_int_eq(len, 10);
	fflush(stdout);

	len = read(pipe, buffer, 512);
	ck_assert_str_eq(buffer, "  rrrrrttttt");
}
Example #6
0
END_TEST

START_TEST(showbar_can_also_do_mb_calculations)
{
	int pipe, len;
	char buffer[512];
	memset(&buffer, '\0', sizeof(buffer));

	defaultcfg();
	cfg.rxchar[0] = 'r';
	cfg.txchar[0] = 't';
	pipe = pipe_output();
	len = showbar(0, 1024, 0, 1024, 2048, 2);
	ck_assert_int_eq(len, 2);
	fflush(stdout);

	len = read(pipe, buffer, 512);
	ck_assert_str_eq(buffer, "  rt");
}
Example #7
0
/*
 * 1. Open 'p' pcap-handle(s)
 * 2. Capture 'n' packets per pcap-handle using a round-robin algorithm
 * 3. Print global statistics information
 */
int main (int argc, char * argv [])
{
  int option;

  char * interface = DEFAULT_INTERFACE;    /* interface name */
  int promiscuous  = 1;
  int snapshot     = DEFAULT_SNAPSHOT;

  /* How many pcap-handles */
  int handles = DEFAULT_HANDLES;
  pcap_t ** table = NULL;
  int p;
  char ebuf [PCAP_ERRBUF_SIZE];
  const unsigned char * packet;
  struct pcap_pkthdr header;

  /* How many packets */
  unsigned long maxcount = DEFAULT_PACKETS;
  unsigned long partial  = 0;
  unsigned long errors   = 0;

  int hb = -1;      /* heartbeat */
  int quiet = 0;

  struct timeval started;
  struct timeval stopped;
  double delta;

  /* Notice the program name */
  char * progname = strrchr (argv [0], '/');
  progname = ! progname ? * argv : progname + 1;

#define OPTSTRING "hvi:s:n:c:b:q"
  while ((option = getopt (argc, argv, OPTSTRING)) != EOF)
    {
      switch (option)
	{
	default: return -1;

	case 'h': usage (progname);   return 0;
        case 'v': version (progname); return 0;

	case 'i': interface = optarg;       break;
	case 's': snapshot = atoi (optarg); break;

	case 'n': handles = atoi (optarg);
	  if (! handles)
	    handles = 1;
	  break;

	case 'c': maxcount = atoi (optarg); break;

	case 'b': hb = atoi (optarg); break;
	case 'q': quiet = 1; break;
	}
    }

  /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */

  /* Set unbuffered stdout */
  setvbuf (stdout, NULL, _IONBF, 0);

  if ((getuid () && geteuid ()) || setuid (0))
    {
      printf ("%s: sorry, you must be root in order to run this program\n", progname);
      return -1;
    }

  /* Find a suitable interface, if you don't have one */
  if (! interface && ! (interface = pcap_lookupdev (ebuf)))
    {
      printf ("%s: no suitable interface found, please specify one with -d\n", progname);
      return -1;
    }

  signal (SIGINT, on_ctrl_c);

  /* Announce */
  printf ("%s: requested to open #%d pcap-handle%s\n", progname, handles, handles > 1 ? "s" : "");

  /* Allocate enough memory to keep the pointers to the pcap-handle(s) */
  table = calloc ((handles + 1) * sizeof (pcap_t *), 1);
  for (p = 0; p < handles; p ++)
    table [p] = NULL;
  table [p] = NULL;

  /* Open the interface for packet capturing */
  for (p = 0; p < handles; p ++)
    if (! (table [p] = pcap_open_live (interface, snapshot, promiscuous, 1000, ebuf)))
      {
	printf ("%s: cannot open interface '%s' due to '%s'\n", progname, interface, ebuf);
	return -1;
      }

  printf ("%s: listening from %s using %s\n\n", progname, interface, pcap_lib_version ());

  /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */

  if (hb == -1)
    hb = maxcount / DEFAULT_HB;
  if (! hb)
    hb = 1;

  printf ("%s: starting to capture #%lu pckts using #%d pcap-handle%s...\n", progname, maxcount, handles, handles > 1 ? "s" : "");

  gettimeofday (& started, NULL);

  p = 0;
  while (! maxcount || (partial + errors) < maxcount)
    {
      /* Please give me just a packet at once from the interface */
      if ((packet = pcap_next (table [p], & header)))
	{
	  partial ++;
	  if (! quiet)
	    {
	      if (! (partial % hb))
		{
		  static unsigned long previous = 0;
		  static struct timeval latest;

		  struct timeval now;

		  /* Show pkts/secs in the latest period */
		  gettimeofday (& now, NULL);
		  delta = delta_time_in_milliseconds (& now, & latest);

		  printf ("%s: pkts rcvd #%lu of #%lu %s", progname, partial, maxcount, percentage (partial, maxcount));
		  if (previous && delta)
		    printf (" [%8.2f pkts/sec => +%lu pkts in %s]",
			    (double) (partial - previous) * 1000 / delta,
			    partial - previous, elapsed_time (& latest, & now));
		  printf ("\n");

		  previous = partial;
		  latest = now;
		}
	      else
		showbar (partial);
	    }
	}
      else
	errors ++;

      /* Round-robin to choose the pcap-handle candidate for the packet capture */
      p = (p + 1) % handles;
    }

  /* Close the pcap-handle(s) */
  for (p = 0; p < handles; p ++)
    pcap_close (table [p]);
  free (table);

  gettimeofday (& stopped, NULL);
  delta = (double) delta_time_in_milliseconds (& stopped, & started);

  printf ("              \n");

  printf ("Time:\n");
  printf ("=====\n");
  print_time_in_secs (& started, "Started:       ");
  print_time_in_secs (& stopped, "Finished:      ");
  printf ("Elapsed Time:  %s\n", elapsed_time (& started, & stopped));
  printf ("\n");

  /* Print out test results */
  printf ("Great Totals:\n");
  printf ("=============\n");
  printf ("pkts rcvd #%lu pckts of #%lu => %7.2f pkts/sec\n", partial, maxcount, (double) partial * 1000 / delta);

  return 0;
}
Example #8
0
  void WaveTest_Play(char *pszFileName)
 {
     HWAVELIB hWaveLib = WaveLib_Init(pszFileName, FALSE);
	 PWAVELIB pWaveLib = (PWAVELIB)hWaveLib;
	 int x;
	 // hWaveLib = WaveLib_Init(pszFileName, FALSE);
     FileSize = GetSize();
	 FileLength = GetLength();
	 //waveOutGetDevCaps(&pWaveLib->hThread,&devicecapability, sizeof(devicecapability));
	 if(hWaveLib)
	 {
		 do
		 {
			PlaybackTimeNow =GetPlayTime(hWaveLib);
			PlaybackPercentage = (PlaybackTimeNow/total_time)*100;
			//printf("Querying device capabilities...\n");

			//loadbar(PlaybackTimeNow,total_time,10,10);
			//getPlaybackTimePercentage(FileLength, PlaybackTimeNow);
			showbar();
			
			if (PlaybackPercentage >= 0 && PlaybackPercentage < 10)
			 {
				 //waveOutGetVolume(pWaveLib->hWaveOut,&volume);
				 nextvolume = 0x0000;
				 nextvolume = ((int)PlaybackPercentage*25)<<8;
				 waveOutSetVolume(pWaveLib->hWaveOut,nextvolume);
				 printf("Ch1++|Vol:%X|", nextvolume);
			 }
			 else if (PlaybackPercentage >= 10 && PlaybackPercentage < 20)
			 {
				 nextvolume = 0xFF00 -  (((int)(PlaybackPercentage-10)*25)<<8);
				 waveOutSetVolume(pWaveLib->hWaveOut,nextvolume);
				 printf("Ch1--|Vol:%X|", nextvolume);
			 }
			 else if (PlaybackPercentage >= 20 && PlaybackPercentage < 30)
			 {
				 nextvolume = 0x0000;
				 nextvolume = ((int)(PlaybackPercentage-20)*25);
				 waveOutSetVolume(pWaveLib->hWaveOut,nextvolume);
				 printf("Ch2++|Vol:00%X|", nextvolume);
			 }
			 else if (PlaybackPercentage >= 30 && PlaybackPercentage < 40)
			 {
				 nextvolume = 0x00FF - ((int)(PlaybackPercentage-30)*25);
				 waveOutSetVolume(pWaveLib->hWaveOut,nextvolume);
				 printf("Ch2--|Vol:00%X|", nextvolume);
			 }
			 else if (PlaybackPercentage >= 40 && PlaybackPercentage < 50)
			 {
				 nextvolume = 0x0000;
				 nextvolume = (((int)(PlaybackPercentage-40)*25<<8)) | ((int)(PlaybackPercentage-40)*25);
				 waveOutSetVolume(pWaveLib->hWaveOut,nextvolume);
				 printf("Ch1&2++|Vol:%X|", nextvolume);
			 }
			 else if (PlaybackPercentage >= 50 && PlaybackPercentage < 70)
			 {
				 playbackrate = ((((int)(PlaybackPercentage-50)*25)/64)<<16);
				 result = waveOutSetPlaybackRate(pWaveLib->hWaveOut,playbackrate);
				 if (result == MMSYSERR_INVALHANDLE){
					 printf("nohandle");}
				 else if (result == MMSYSERR_NODRIVER)
					 printf("nodriver");
				 else if (result == MMSYSERR_NOMEM)
					 printf("nomem");
				 else if (result == MMSYSERR_NOTSUPPORTED){
					 printf("notsup");//printf("WARNING: Changing playback rate unsupported.\n");
				 }
				 else if (result == MMSYSERR_NOERROR);
					 printf("@%dx|", (((int)(PlaybackPercentage-50)*25)/64));
			 }
			 else if (PlaybackPercentage >= 70 && PlaybackPercentage < 90)
			 {
				 //playbackrate = ((((int)(PlaybackPercentage-70)*25)/64)<<16);
				 waveOutGetPlaybackRate(pWaveLib->hWaveOut,&playbackrate);
				 //printf("@%dx|", (((int)(PlaybackPercentage-50)*25)/64));
				 printf("@%Xx|", playbackrate);
			 }
		 }

		 while(PlaybackTimeNow < FileLength);
		 printf("Playbacktime: %d | FileLength: %d",PlaybackTimeNow,total_time);
		 WaveLib_UnInit(hWaveLib);
	 }
	 else
	 {
		 WaveTest_PrintError();
	 }
     
 }