Пример #1
0
Файл: misc.c Проект: elfmz/far2l
int main(void)
{
    int passes = 0, fails = 0;

#define TEST1(func, string, arg2, suffix, result) do                    \
    {                                                                   \
        const char *str = string;                                       \
        unsigned ret = func(string, arg2) suffix;                       \
        if (ret == result) {                                            \
            passes++;                                                   \
        } else {                                                        \
            printf("fail: %s(%s,%s)%s = %u, expected %u\n",             \
                   #func, #string, #arg2, #suffix, ret, result);        \
            fails++;                                                    \
        }                                                               \
} while (0)

    TEST1(host_strchr, "[1:2:3]:4:5", ':', -str, 7);
    TEST1(host_strrchr, "[1:2:3]:4:5", ':', -str, 9);
    TEST1(host_strcspn, "[1:2:3]:4:5", "/:",, 7);
    TEST1(host_strchr, "[1:2:3]", ':', == NULL, 1);
    TEST1(host_strrchr, "[1:2:3]", ':', == NULL, 1);
    TEST1(host_strcspn, "[1:2:3]", "/:",, 7);
    TEST1(host_strcspn, "[1:2/3]", "/:",, 4);
    TEST1(host_strcspn, "[1:2:3]/", "/:",, 7);

    printf("passed %d failed %d total %d\n", passes, fails, passes+fails);
    return fails != 0 ? 1 : 0;
}
/* Compare the repeat rule properties of the entries before and after storing
@param aEntry1 Pointer to the stored entry
@param aEntry2 Pointer to the entry fetched from the database
*/
void CTestCalInterimApiSuiteStepBase::CompareRepeatRulePropertiesL(CCalEntry* aEntry1, CCalEntry* aEntry2)
	{
	TCalRRule	rptDef1;
	TBool	rpt1 = aEntry1->GetRRuleL(rptDef1);
	TCalRRule	rptDef2;
	TBool	rpt2 = aEntry2->GetRRuleL(rptDef2);
	if ( rpt1 )
		{
		TEST1( rptDef1.Type() == rptDef2.Type(), ETrue );
		TEST1( rptDef1.DtStart().TimeUtcL() == rptDef2.DtStart().TimeUtcL(), ETrue );
		TEST1( rptDef1.Until().TimeUtcL() == rptDef2.Until().TimeUtcL(), ETrue );
		TEST1( rptDef1.Count() == rptDef2.Count(), ETrue );
		TEST1( rptDef1.Interval() == rptDef2.Interval(), ETrue );
		RArray<TDay>	days1;
		CleanupClosePushL(days1);
		rptDef1.GetByDayL(days1);
		RArray<TDay>	days2;
		CleanupClosePushL(days2);
		rptDef2.GetByDayL(days2);
		TEST1( days1.Count() == days2.Count(), ETrue );
		for ( TInt i = 0; i < days1.Count(); i++ )
			{
			TESTL( days1[i] == days2[i] );
			}
		CleanupStack::PopAndDestroy(2); //days2, days1
		RArray<TInt>	monthDays1;
		CleanupClosePushL(monthDays1);
		rptDef1.GetByMonthDayL(monthDays1);
		RArray<TInt>	monthDays2;
		CleanupClosePushL(monthDays2);
		rptDef2.GetByMonthDayL(monthDays2);
		TEST1( monthDays1.Count() == monthDays2.Count(), ETrue );
		for ( TInt j = 0; j < monthDays1.Count(); j++ )
			{
			TESTL( monthDays1[j] == monthDays1[j] );
			}
		CleanupStack::PopAndDestroy(2); // monthDays2, monthDays1
		RArray<TMonth>	months1;
		CleanupClosePushL(months1);
		rptDef1.GetByMonthL(months1);
		RArray<TMonth>	months2;
		CleanupClosePushL(months2);
		rptDef2.GetByMonthL(months2);
		TEST1( months1.Count() == months2.Count(), ETrue );
		TEST1( rptDef1.WkSt() == rptDef2.WkSt(), ETrue );
		for ( TInt k = 0; k < months1.Count(); k++ )
			{
			TESTL( months1[k] == months2[k] );
			}
		CleanupStack::PopAndDestroy(2); // months2, months1
		}
	else
		{ // rptDef1 is NULL. Test that rptDef2 is NULL too
		TEST1( !rpt2, ETrue );
		}
	}
Пример #3
0
// Just write something to a speech device.
int test_speech(playerc_client_t *client, int index)
{
  //int t;
  //void *rdevice;
  playerc_speech_t *device;
  char text[]="Hello World!";
  char text2[]="12345678901234567890123456789012345678901234567890";

  printf("device [speech] index [%d]\n", index);

  device = playerc_speech_create(client, index);

  TEST("subscribing (read/write)");
  if (playerc_speech_subscribe(device, PLAYER_OPEN_MODE) < 0)
  {
    FAIL();
    return -1;
  }
  PASS();


        TEST1("writing data (attempt %d)",1);

        if (playerc_speech_say(device, text  )  != 0) {
            FAIL();
        } else {
          PASS();
        }
        usleep(1000000);  //some time to see the effect

        TEST1("writing data (attempt %d)",2);

        TEST1("Printing: %s",text2);
        if (playerc_speech_say(device, text2  )  != 0) {
            FAIL();
        } else {
          PASS();
        }
        usleep(1000000);  //some time to see the effect



  TEST("unsubscribing");
  if (playerc_speech_unsubscribe(device) != 0)
  {
    FAIL();
    return -1;
  }
  PASS();
  
  playerc_speech_destroy(device);
  
  return 0;
}
int main()
{
#if (_MIPS_ARCH_OCTEON2) || (__mips_dsp)
   int i;
   for(i = 8; i <= 255; i += 8)
      TEST1("ldx",  i, reg_val);
   for(i = 8; i <= 255; i += 8)
      TEST1("lbux",  i, reg_val);
   for(i = 8; i <= 255; i += 8)
      TEST1("lwx",  i, reg_val);
#endif
   return 0;
}
/* Compare the organizer properties of the entries before and after storing
@param aEntry1 Pointer to the stored entry
@param aEntry2 Pointer to the entry fetched from the database
*/
void CTestCalInterimApiSuiteStepBase::CompareOrganizerPropertiesL(CCalEntry* aEntry1, CCalEntry* aEntry2)
	{
	CCalUser*	organizer1 = aEntry1->OrganizerL();
	CCalUser*	organizer2 = aEntry2->OrganizerL();
	if ( organizer1 )
		{
		TEST1( organizer1->Address() == organizer2->Address(), ETrue );
		TEST1( organizer1->CommonName() == organizer2->CommonName(), ETrue );
		TEST1( organizer1->SentBy() == organizer2->SentBy(), ETrue );
		}
	else
		{ // organizer1 is NULL. Test that organizer2 is NULL too
		TEST1( !organizer2, ETrue );
		}
	}
Пример #6
0
// Basic test for camera device.
int test_camera(playerc_client_t *client, int index)
{
  int t;
  void *rdevice;
  playerc_camera_t *device;
  char filename[128];
  int csize, usize;

  printf("device [camera] index [%d]\n", index);

  device = playerc_camera_create(client, index);

  TEST("subscribing (read)");
  if (playerc_camera_subscribe(device, PLAYER_OPEN_MODE) != 0)
  {
    FAIL();
    return -1;
  }
  PASS();

  for (t = 0; t < 10; t++)
  {
    TEST1("reading data (attempt %d)", t);

    do
      rdevice = playerc_client_read(client);
    while (rdevice == client);

    if (rdevice == device)
    {
      PASS();

      // Decompress the image
      csize = device->image_count;
      playerc_camera_decompress(device);
      usize = device->image_count;

      printf("camera: [w %d h %d d %d] [%d/%d bytes]\n",
             device->width, device->height, device->bpp, csize, usize);

      snprintf(filename, sizeof(filename), "camera_%03d.ppm", t);
      printf("camera: saving [%s]\n", filename);
      playerc_camera_save(device, filename);
    }
    else
      FAIL();
  }

  TEST("unsubscribing");
  if (playerc_camera_unsubscribe(device) != 0)
  {
    FAIL();
    return -1;
  }
  PASS();

  playerc_camera_destroy(device);

  return 0;
}
Пример #7
0
// Basic sonar test
int test_sonar(playerc_client_t *client, int index)
{
  int t, i;
  void *rdevice;
  playerc_sonar_t *device;

  printf("device [sonar] index [%d]\n", index);

  device = playerc_sonar_create(client, index);

  TEST("subscribing (read)");
  if (playerc_sonar_subscribe(device, PLAYER_OPEN_MODE) == 0)
    PASS();
  else
    FAIL();

  TEST("getting geometry");
  if (playerc_sonar_get_geom(device) == 0)
    PASS();
  else
    FAIL();

  printf("sonar geom: ");
  for (i = 0; i < device->pose_count; i++)
    printf("[%6.3f %6.3f %6.3f] ", device->poses[i].px, device->poses[i].py, device->poses[i].pyaw);
  printf("\n");

  for (t = 0; t < 10; t++)
  {
    TEST1("reading data (attempt %d)", t);

    do
      rdevice = playerc_client_read(client);
    while (rdevice == client);
    
    if (rdevice == device)
    {
      PASS();
      printf("sonar range: [%d] ", device->scan_count);
      for (i = 0; i < 3; i++)
        printf("[%6.3f] ", device->scan[i]);
      printf("\n");
    }
    else
    {
      FAIL();
      break;
    }
  }
  
  TEST("unsubscribing");
  if (playerc_sonar_unsubscribe(device) == 0)
    PASS();
  else
    FAIL();
  
  playerc_sonar_destroy(device);
  
  return 0;
}
Пример #8
0
// Basic test for the laser beacon device.
int test_fiducial(playerc_client_t *client, int index)
{
  int t, i;
  //int bit_count; double bit_width;
  void *rdevice;
  playerc_fiducial_t *device;

  printf("device [fiducial] index [%d]\n", index);

  device = playerc_fiducial_create(client, index);

  TEST("subscribing (read/write)");
  if (playerc_fiducial_subscribe(device, PLAYER_ALL_MODE) < 0)
  {
    FAIL();
    return -1;
  }
  PASS();

  for (t = 0; t < 10; t++)
  {
    TEST1("reading data (attempt %d)", t);

    do
      rdevice = playerc_client_read(client);
    while (rdevice == client);
    
    if (rdevice == device)
    {
      PASS();

      printf("fiducial: [%d] ", device->fiducial_count);
      for (i = 0; i < min(3, device->fiducial_count); i++)
        printf("[%d %6.3f %6.3f %6.3f %6.3f %6.3f] ", device->fiducials[i].id,
               device->fiducials[i].pos[0], device->fiducials[i].pos[1],
               device->fiducials[i].range, device->fiducials[i].bearing * 180 / M_PI,
               device->fiducials[i].orient);
      printf("\n");
    }
    else
    {
      FAIL();
      break;
    }
  }
  
  TEST("unsubscribing");
  if (playerc_fiducial_unsubscribe(device) != 0)
  {
    FAIL();
    return -1;
  }
  PASS();
  
  playerc_fiducial_destroy(device);
  
  return 0;
}
/**
Compares the properties of two alarms
@param aAlarm1 alarm of the stored entry
@param aAlarm1 alarm of the entry fetched from the database
*/
void CTestCalInterimApiSuiteStepBase::CompareAlarmsL(CCalAlarm* aAlarm1, CCalAlarm* aAlarm2)
	{
	if(aAlarm1)
		{
		CCalContent* content1 = aAlarm1->AlarmAction();
		CCalContent* content2 = aAlarm2->AlarmAction();

		TEST1(aAlarm1->TimeOffset() == aAlarm2->TimeOffset(), ETrue);
		TEST1(aAlarm1->AlarmSoundNameL() == aAlarm2->AlarmSoundNameL(), ETrue);

		if(content1)
			{
			TEST1(content1->Content() == content2->Content(), ETrue);
			TEST1(content1->Disposition() == content2->Disposition(), ETrue);
			TEST1(content1->MimeType() == content2->MimeType(), ETrue);
			}
		else
			{// content1 is NULL. Test that content2 is NULL too
			TEST1(!content2, ETrue);
			}
		}
	else
		{// alarm1 is NULL. Test that alarm2 is NULL too
		TEST1(!aAlarm2, ETrue);
		}
	}
void CPerformanceFunctionalityBase::CloseProcessL(const TDesC& aProcessName, const TInt aIteration)
    {
	_LIT(KillString, "Kill");
	if ( aProcessName != KNullDesC )
		{
		_LIT(KServerRunning,"*** The CntSrv process is running ***");
		_LIT(KServerIteration, "Found server process on iteration: %d");
		INFO_PRINTF1(KServerRunning);
		INFO_PRINTF2(KServerIteration, aIteration);

		// the CntSrv process is running so wait
		RProcess process;
		const TInt OpenError = process.Open(aProcessName);
		if ( OpenError == KErrNone)
			{
			TRequestStatus status;
			process.Logon(status); // ask for a callback when the process ends
			User::WaitForRequest(status);
			const TInt serverError = process.ExitReason();
			TExitCategoryName category = process.ExitCategory();
			_LIT(KServerClosed,"*** The CntSrv process has ended with error type: %S, and error value: %d ***");
			INFO_PRINTF3(KServerClosed, &category, serverError);
			process.Close();
			if( ( category != KillString ) || ( serverError != KErrNone ) )
				{
				_LIT(KServerError,"*** The server caused an error while closing ***");
				ERR_PRINTF1(KServerError);
				TEST1( EFalse, ETrue);
				}
			}
		else
			{
			_LIT(KProcessFailure,"*** Failed to open process, error: %d ***");
			ERR_PRINTF2(KProcessFailure, OpenError);
			TEST1(EFalse, ETrue);
			}
		}
	else
		{
		_LIT(KNoProcess,"*** The CntSrv process is NOT running ***");
		ERR_PRINTF1(KNoProcess);
		TEST1(EFalse, ETrue);
		}
    }
Пример #11
0
// Basic test for wifi device.
int test_wifi(playerc_client_t *client, int index)
{
  int i, t;
  void *rdevice;
  playerc_wifi_t *device;

  printf("device [wifi] index [%d]\n", index);

  device = playerc_wifi_create(client, index);

  TEST("subscribing (read)");
  if (playerc_wifi_subscribe(device, PLAYER_READ_MODE) != 0)
  {
    FAIL();
    return -1;
  }
  PASS();

  for (t = 0; t < 3; t++)
  {
    TEST1("reading data (attempt %d)", t);

    do
      rdevice = playerc_client_read(client);
    while (rdevice == client);

    if (rdevice == device)
    {
      PASS();

      for (i = 0; i < device->link_count; i++)
      {
        printf("wifi: [%.3f] [%s] [%s] [%s] [%4d] [%4d] [%4d]\n",
               device->info.datatime,
               device->links[i].mac,
               device->links[i].essid, device->links[i].ip,
               device->links[i].qual, device->links[i].level, device->links[i].noise);
      }
    }
    else
      FAIL();
  }

  TEST("unsubscribing");
  if (playerc_wifi_unsubscribe(device) != 0)
  {
    FAIL();
    return -1;
  }
  PASS();
  
  playerc_wifi_destroy(device);
  
  return 0;
}
/** Check the GEO Property value stored in entry, with expected GEO Property value
@param	aCalEntry Pointer to CCalEntry
@param	aGeoLat Expected GEO latitude value
@param	aGeoLong Expected GEO longitude value
*/
void CTestCalInterimApiFetchEntryAndCheckData::CheckGEOPropertyL(CCalEntry* aCalEntry, const TDesC& aGeoLat, const TDesC& aGeoLong)
	{
	CCalGeoValue* geoValue = NULL;
	
	TRAPD(err, geoValue = aCalEntry->GeoValueL());

	if (err != KErrNone)
		{
		ERR_PRINTF2(_L("GeoValuesL Error Code %d"), err);
		SetTestStepResult(EFail);
		SetTestStepError(err);
		}
	else
		{
		CleanupStack::PushL(geoValue);
		}
	
	TReal lat = 0.0;
	TReal longitude = 0.0;
	TBool hasGEO = geoValue->GetLatLong(lat,longitude);
	
	TESTL(hasGEO);

	TLex lex(aGeoLat);
	TReal expectLat = 0.0;
	lex.Val(expectLat);

	TLex lex1(aGeoLong);
	TReal expectLong = 0.0;
	lex1.Val(expectLong);

	INFO_PRINTF5(KExpectedAndFoundGEO, expectLat, lat, expectLong, longitude);

	TEST1(lat == expectLat, ETrue);
	TEST1(longitude == expectLong, ETrue);
	
	if (err == KErrNone)
		{
		CleanupStack::PopAndDestroy(geoValue);	
		}
	}
Пример #13
0
// Basic blobfinder test
int test_blobfinder(playerc_client_t *client, int index)
{
  int t, i;
  void *rdevice;
  playerc_blobfinder_t *device;

  printf("device [blobfinder] index [%d]\n", index);

  device = playerc_blobfinder_create(client, index);

  TEST("subscribing (read)");
  if (playerc_blobfinder_subscribe(device, PLAYER_OPEN_MODE) == 0)
    PASS();
  else
    FAIL();

  for (t = 0; t < 10; t++)
  {
    TEST1("reading data (attempt %d)", t);

    do
      rdevice = playerc_client_read(client);
    while (rdevice == client);

    if (rdevice == device)
    {
      PASS();
      printf("blobfinder: [%d, %d] [%d] ", device->width, device->height, device->blobs_count);
      for (i = 0; i < min(3, device->blobs_count); i++)
        printf("[%d : (%d %d) (%d %d %d %d) : %d] ", device->blobs[i].id,
               device->blobs[i].x, device->blobs[i].y,
               device->blobs[i].left, device->blobs[i].top,
               device->blobs[i].right, device->blobs[i].bottom,
               device->blobs[i].area);
      printf("\n");
    }
    else
    {
      FAIL();
      break;
    }
  }

  TEST("unsubscribing");
  if (playerc_blobfinder_unsubscribe(device) == 0)
    PASS();
  else
    FAIL();

  playerc_blobfinder_destroy(device);

  return 0;
}
void CPerformanceFunctionalityBase::PrintTestComparison(const TBool aResult,
														const TText *aCompare,
														const TInt aLine,
														const TText *aFile)
	{
	_LIT(KComparePrint, "The comparison: %s failed at line: %d in file: %s");
	if( !aResult )
		{
		ERR_PRINTF4( KComparePrint, aCompare, aLine, aFile );
		TEST1( EFalse , ETrue );
		}
	}
Пример #15
0
// Just read from a aio device.
int test_aio(playerc_client_t *client, int index)
{
  int t;
  void *rdevice;
  playerc_aio_t *device;

  printf("device [aio] index [%d]\n", index);

  device = playerc_aio_create(client, index);

  TEST("subscribing (read/write)");
  if (playerc_aio_subscribe(device, PLAYER_OPEN_MODE) < 0)
  {
    FAIL();
    return -1;
  }
  PASS();

  for (t = 0; t < 5; t++)
  {
    TEST1("reading data (attempt %d)", t);

    do
      rdevice = playerc_client_read(client);
    while (rdevice == client);

    if (rdevice == device)
    {
      PASS();
      printf("aio: [%8.3f]  AI0,...,AI7: [%5.3f] [%5.3f] [%5.3f] [%5.3f] [%5.3f] [%5.3f] [%5.3f] [%5.3f]\n",
             device->info.datatime, device->voltages[0], device->voltages[1],device->voltages[2],device->voltages[3],device->voltages[4],device->voltages[5],device->voltages[6],device->voltages[7]);
    }
    else
    {
      //printf("error: %s", playerc_error_str());
      FAIL();
      break;
    }
  }

  TEST("unsubscribing");
  if (playerc_aio_unsubscribe(device) != 0)
  {
    FAIL();
    return -1;
  }
  PASS();
  
  playerc_aio_destroy(device);
  
  return 0;
}
Пример #16
0
static int DetectCsumValidArgsTestParse01(void)
{
    TEST1(ipv4);
    TEST1(tcpv4);
    TEST1(tcpv6);
    TEST1(udpv4);
    TEST1(udpv6);
    TEST1(icmpv4);
    TEST1(icmpv6);
    PASS;
}
int main()
{
	TEST1();
	TEST2();
	TEST2();
	TEST3();
	TEST4();
	TEST5();
	TEST6();
	TEST7();
	TEST8();
	TEST9();

	TEST10();
	TEST11();
	TEST12();
	TEST12();
	TEST13();
	TEST14();
	TEST15();
	TEST16();
	TEST17();
	TEST18();
	TEST19();

	TEST20();
	TEST21();
	TEST22();
	TEST22();
	TEST23();
	TEST24();
	TEST25();
	TEST26();
	TEST27();
	TEST28();
	TEST29();

	TEST30();
	TEST31();
	TEST32();
	TEST32();
	TEST33();
	TEST34();
	TEST35();
	TEST36();
	TEST37();
	TEST38();
	TEST39();

	return 0;
}
TBool CPerformanceFunctionalityBase::IntegerComparisonTestPrint(	const TInt	aCompareL,
                    												const TText *aCompareOperator,
                    												const TInt 	aCompareR,
                    												const TBool aResult,
                    												const TInt 	aIteration,
                    												const TInt 	aSubIteration,
                    												const TInt 	aLine,
                    												const TText *aFile)
	{
	_LIT(KComparePrint, "%d %s %d: failed on subiteration %d of iteration %d");
	_LIT(KFilePrint, "In file: %s at line: %d");
	if( !aResult )
		{
		ERR_PRINTF6( KComparePrint, aCompareL, aCompareOperator, aCompareR, aSubIteration, aIteration);
		ERR_PRINTF3( KFilePrint, aFile, aLine );
		TEST1( EFalse , ETrue );
		}
	return aResult;
	}
/** Comparing the datas with the set values from the ini file.
@param	aCalEntry Pointer to CCalEntry.
@param	aEntryProperties Structure containing the entry properties
*/
void CTestCalInterimApiFetchEntryAndCheckData::CheckDataL(CCalEntry* aCalEntry, const TEntryProperties& aEntryProperties)
	{
	if ( aEntryProperties.iSummary != KNullDesC16() )
		{
		TPtrC	summary(aCalEntry->SummaryL());
		INFO_PRINTF3(KExpectedAndFoundSummary, &aEntryProperties.iSummary, &summary);
		TEST1( summary == aEntryProperties.iSummary, ETrue);
		}
	if ( aEntryProperties.iDescription != KNullDesC16() )
		{
		TPtrC	description(aCalEntry->DescriptionL());
		INFO_PRINTF3(KExpectedAndFoundDescription, &aEntryProperties.iDescription, &description);
		TEST1( description == aEntryProperties.iDescription, ETrue);
		}
	if ( aEntryProperties.iLocation != KNullDesC16() )
		{
		TPtrC	location(aCalEntry->LocationL());
		INFO_PRINTF3(KExpectedAndFoundLocation, &aEntryProperties.iLocation, &location);
		TEST1( location == aEntryProperties.iLocation, ETrue);	
		}
	if(aEntryProperties.iCategories != KNullDesC16() )
		{
		CheckCategoriesL(aCalEntry, aEntryProperties.iCategories);
		}
	if(aEntryProperties.iHasLocalId )
		{
		TCalLocalUid	localId(aCalEntry->LocalUidL());
		INFO_PRINTF3(KExpectedAndFoundLocalId, aEntryProperties.iLocalId, localId);
		TEST1( localId == aEntryProperties.iLocalId, ETrue );
		}
	if(aEntryProperties.iHasPriority )
		{
		TUint	priority(aCalEntry->PriorityL());
		INFO_PRINTF3(KExpectedAndFoundPriority, aEntryProperties.iPriority, priority);
		TEST1( priority == aEntryProperties.iPriority, ETrue );
		}
	if (aEntryProperties.iGeoLat != KNullDesC16() && aEntryProperties.iGeoLong != KNullDesC16())
		{
		CheckGEOPropertyL(aCalEntry, aEntryProperties.iGeoLat, aEntryProperties.iGeoLong);
		}
	if (aEntryProperties.iTrans != KValueIntNotIni)
		{
		TInt trans(aCalEntry->TimeTransparencyL());
		INFO_PRINTF3(KExpectedAndFoundStatus, aEntryProperties.iTrans, trans);
		TEST1( trans == aEntryProperties.iTrans, ETrue);
		}
		
	}
Пример #20
0
TVerdict CTestMacrosTestStep::doTestStepL()
/**
 * @return - TVerdict code
 * Override of base class pure virtual
 * Our implementation only gets called if the base class doTestStepPreambleL() did
 * not leave. That being the case, the current test result value will be EPass.
 */
	{
	TPtrC macro;
	GetStringFromConfig(ConfigSection(), KMacro, macro);
	if (macro == KTest)
		{
		TBool parameter;
		TInt parameter2;
		TInt expectedResult;
		GetBoolFromConfig(ConfigSection(), KParameter, parameter);
		GetIntFromConfig(ConfigSection(), KParameter2, parameter2);
		GetIntFromConfig(ConfigSection(), KExpectedResult, expectedResult);
		_LIT(KStartInfo, "Start to run %S test of macros TEST(E) & TEST(E)L");
		INFO_PRINTF2(KStartInfo, POS_NEG_SEL);
		TEST(parameter);
		TESTE(parameter, parameter2);
		if (expectedResult != TestStepResult())
			{
			ERR_PRINTF2(_L("The %S test of macro TEST(E) test is failed!"), POS_NEG_SEL);
			SetTestStepResult(EFail);
			}
		else
			{
			SetTestStepResult(EPass);
			INFO_PRINTF3(_L("The %S test of macro TEST(E) is passed. Start to run %S test of macro TEST(E)L"), POS_NEG_SEL, POS_NEG_SEL);
			
			TRAPD(err, TESTL(parameter));
			TRAPD(err1, TESTEL(parameter, parameter2));
			if ((expectedResult==EPass && KErrNone!=err) || (expectedResult==EFail && TEST_ERROR_CODE!=err && parameter2!=err1))
				{
				ERR_PRINTF2(_L("The %S test of macro TEST(E)L test is failed!"), POS_NEG_SEL);
				SetTestStepResult(EFail);
				}
			else
				{
				INFO_PRINTF2(_L("The %S test of macro TEST(E)L is passed."), POS_NEG_SEL);
				SetTestStepResult(EPass);
				}
			}
		}
	else if (macro == KTest1)
		{
		TBool parameter;
		TBool parameter2;
		TInt parameter3;
		TInt initState;
		TInt expectedResult;
		GetBoolFromConfig(ConfigSection(), KParameter, parameter);
		GetBoolFromConfig(ConfigSection(), KParameter2, parameter2);
		GetIntFromConfig(ConfigSection(), KParameter3, parameter3);
		GetIntFromConfig(ConfigSection(), KInitState, initState);
		GetIntFromConfig(ConfigSection(), KExpectedResult, expectedResult);
		SetTestStepResult((TVerdict)initState);
		_LIT(KStartInfo, "Start to run %S test of macros TEST(E)1 & TEST(E)1L");
		INFO_PRINTF2(KStartInfo, POS_NEG_SEL);
		TEST1(parameter, parameter2);
		TESTE1(parameter, parameter3, parameter2);
		if (expectedResult != TestStepResult())
			{
			ERR_PRINTF1(_L("Macro TEST(E)1 test failed!"));
			SetTestStepResult(EFail);
			}
		else
			{
			SetTestStepResult(EPass);
			INFO_PRINTF3(_L("The %S test of macro TEST(E)1 has passed. Start to run %S test of macro TEST(E)1L"), POS_NEG_SEL, POS_NEG_SEL);
			
			TRAPD(err, TEST1L(parameter, parameter2));
			TRAP_IGNORE(TESTE1L(parameter, parameter3, parameter2));
			if ((expectedResult==EPass && KErrNone!=err) || ((expectedResult==EFail) && (parameter && ((TEST_ERROR_CODE==err)||(parameter3==err))) || (!parameter && TEST_ERROR_CODE!=err && parameter3!=err)))
				{
				ERR_PRINTF1(_L("Macro TEST(E)1L test failed!"));
				SetTestStepResult(EFail);
				}
			else
				{
				INFO_PRINTF2(_L("The %S test of macro TEST(E)1L has passed."), POS_NEG_SEL);
				SetTestStepResult(EPass);
				}
			}
		}

	else if (macro == KTestCheckL)
		{
		TInt parameter;
		TInt parameter1;
		TPtrC parameter2;
		TInt expectedResult;
		GetIntFromConfig(ConfigSection(), KParameter, parameter1);
		GetStringFromConfig(ConfigSection(), KParameter2, parameter2);
		GetIntFromConfig(ConfigSection(), KExpectedResult, expectedResult);
		
		parameter = (parameter1==expectedResult);
		INFO_PRINTF3(_L("Start %S test of macro %S"), POS_NEG_SEL, &KTestCheckL());
		
		TRAPD(err, TEST_CHECKL(parameter1, expectedResult, parameter2));
		_LIT(KPassInfo, "This test should be passed!");
		_LIT(KFailInfo, "This test should be failed!");
		if ((KErrNone==err && parameter2==KPassInfo()) || (parameter1==err && parameter2==KFailInfo()))
			{
			INFO_PRINTF2(_L("The macro %S test is passed!"), &KTestCheckL());
			SetTestStepResult(EPass);
			}
		else
			{
			ERR_PRINTF2(_L("The macro %S test is failed!"), &KTestCheckL());
			SetTestStepResult(EFail);
			}
		}
	else
		{
		WARN_PRINTF2(_L("Unrecognized Marco %S"), macro);
		}
	
	return TestStepResult();
	}
Пример #21
0
// Basic localize test
int test_localize(playerc_client_t *client, int index)
{
  int t, i;
  void *rdevice;
  playerc_localize_t *device;

  //double min, max;
  //int resolution, intensity;

  printf("device [localize] index [%d]\n", index);

  device = playerc_localize_create(client, index);

  TEST("subscribing (read)");
  if (playerc_localize_subscribe(device, PLAYER_READ_MODE) == 0)
    PASS();
  else
  {
    FAIL();
    return(-1);
  }

  // deprecated: get map from map interface now
#if 0
  TEST("get map");
  if (playerc_localize_get_map(device) == 0)
    PASS();
  else
    FAIL();
#endif

  /* FIX
  TEST("set configuration");
  min = -M_PI/2;
  max = +M_PI/2;
  resolution = 100;
  intensity = 1;
  if (playerc_localize_set_config(device, min, max, resolution, intensity) == 0)
    PASS();
  else
    FAIL();

  TEST("get configuration");
  if (playerc_localize_get_config(device, &min, &max, &resolution, &intensity) == 0)
    PASS();
  else
    FAIL();

  TEST("check configuration sanity");
  if (abs(min + M_PI/2) > 0.01 || abs(max - M_PI/2) > 0.01)
    FAIL();
  else if (resolution != 100 || intensity != 1)
    FAIL();
  else
    PASS();
  */

  for (t = 0; t < 10; t++)
  {
    TEST1("reading data (attempt %d)", t);

    do
      rdevice = playerc_client_read(client);
    while (rdevice == client);
    
    if (rdevice == device)
    {
      PASS();

      printf("localize: [%d %14.3f] [%d] ",
             device->pending_count, device->pending_time, device->hypoth_count);
      for (i = 0; i < device->hypoth_count; i++)
        printf("[%6.3f, %6.3f %6.3f] ",
               device->hypoths[i].mean[0], device->hypoths[i].mean[1], device->hypoths[i].mean[2]);
      printf("\n");
    }
    else
    {
      FAIL();
      break;
    }
  }
  
  TEST("unsubscribing");
  if (playerc_localize_unsubscribe(device) == 0)
    PASS();
  else
    FAIL();
  
  playerc_localize_destroy(device);
  
  return 0;
}
Пример #22
0
void test_stringf() {
	TEST0("", "");
	TEST0("Hello.", "Hello.");

	TEST0("backslash: \\", "backslash: \\");
	TEST0("2-backslash: \\\\", "2-backslash: \\\\");

	TEST0("%%", "%");
	TEST0("Hello: %%", "Hello: %");
	TEST0("%%: Hello", "%: Hello");
	TEST0("foo %% bar", "foo % bar");

	TEST0("%", "%(err: unfinished reference)");
	TEST0("Hello: %", "Hello: %(err: unfinished reference)");
	TEST0("% xyz", "%(err: unfinished reference) xyz");
	TEST0("%0", "%(err: unknown arg '0')");
	TEST0("%1", "%(err: unknown arg '1')");
	TEST0("%10", "%(err: unknown arg '10')");
	TEST0("%1.", "%(err: unknown arg '1').");
	TEST0("Hello: %1.", "Hello: %(err: unknown arg '1').");
	TEST0("Hello: %xyz", "Hello: %(err: unknown arg 'xyz')");
	TEST0("Hello: %xyz-hello", "Hello: %(err: unknown arg 'xyz')-hello");
	TEST0("Hello: %{xyz-he}llo", "Hello: %(err: unknown arg 'xyz-he')llo");

	TEST0("Hello: %{} end", "Hello: %(err: blank reference) end");
	TEST0("Hello: %_hello end", "Hello: %(err: unknown arg '_hello') end");

	TEST1("Hello: %xyz end", formatarg("x", 42), "Hello: %(err: unknown arg 'xyz') end");
	TEST1("Hello: %x end", formatarg("xyz", 42), "Hello: %(err: unknown arg 'x') end");
	TEST1("Hello: %1 end", formatarg("x", 42), "Hello: %(err: unknown arg '1') end");

	TEST1("Hello: %0 end", formatarg("x", 42), "Hello: 42 end");
	TEST1("Hello: %xyz end", formatarg("xyz", 42), "Hello: 42 end");
	TEST1("Hello: %{xyz} end", formatarg("xyz", 42), "Hello: 42 end");

	TEST1("Hello: %xyz%xyz end", formatarg("xyz", 42), "Hello: 4242 end");
	TEST1("Hello: %xyz %xyz end", formatarg("xyz", 42), "Hello: 42 42 end");

	TEST3("[%x, %y, %z]", formatarg("x", "X"), formatarg("y", "Y"), formatarg("z", "Z"), "[X, Y, Z]");
	TEST3("[%z, %y, %x]", formatarg("x", "X"), formatarg("y", "Y"), formatarg("z", "Z"), "[Z, Y, X]");
	TEST3("[%z, %y, %z]", formatarg("x", "X"), formatarg("y", "Y"), formatarg("z", "Z"), "[Z, Y, Z]");
	TEST3("[%0x, %1y, %2z]", formatarg("x", "X"), formatarg("y", "Y"), formatarg("z", "Z"), "[Xx, Yy, Zz]");

	TEST3("[%0x, %1y, %2z]", formatarg("x", "X"), formatarg("y", "Y"), formatarg("z", "Z"), "[Xx, Yy, Zz]");

	TESTPF1("%0{f}", 42.125, "%f");
	TESTPF1("%0{g}", 42.125, "%g");
	TESTPF1("%0{G}", 42.125, "%G");
	TESTPF1("%0{g}", 42.125e10, "%g");
	TESTPF1("%0{G}", 42.125e10, "%G");
	TESTPF1("%0{e}", 42.125, "%e");
	TESTPF1("%0{E}", 42.125, "%E");

	TESTPF1("%0{f.5}", 42.125, "%.5f");
	TESTPF1("%0{f.0}", 42.125, "%.0f");
	TESTPF1("%0{f8}", 42.125, "%8f");
	TESTPF1("%0{f0}", 42.125, "%0f");
	TESTPF1("%0{f#}", 42.125, "%#f");
	TESTPF1("%0{f+}", 42.125, "%+f");
	TESTPF1("%0{f-8.1}", 42.125, "%-8.1f");
	TESTPF1("%0{f08}", 42.125, "%08f");
	TESTPF1("%0{f+08}", 42.125, "%+08f");
	TESTPF1("%0{f+08.2}", 42.125, "%+08.2f");
	TESTPF1("%0{f08.2}", 42.125, "%08.2f");

	TESTPF1("%0{f.5}", 42.0, "%.5f");
	TESTPF1("%0{f.0}", 42.0, "%.0f");
	TESTPF1("%0{f8}", 42.0, "%8f");
	TESTPF1("%0{f0}", 42.0, "%0f");
	TESTPF1("%0{f#}", 42.0, "%#f");
	TESTPF1("%0{f+}", 42.0, "%+f");
	TESTPF1("%0{f-8.1}", 42.0, "%-8.1f");
	TESTPF1("%0{f08}", 42.0, "%08f");
	TESTPF1("%0{f+08}", 42.0, "%+08f");
	TESTPF1("%0{f+08.2}", 42.0, "%+08.2f");
	TESTPF1("%0{f08.2}", 42.0, "%08.2f");
	TEST1("%0{f }", 42.0, "%(err: bad format)");

	TESTPF1("%0{i8}", 42, "%8i");
	TESTPF1("%0{i0}", 42, "%0i");
	TESTPF1("%0{i+}", 42, "%+i");
	TESTPF1("%0{i-8}", 42, "%-8i");
	TESTPF1("%0{i08}", 42, "%08i");
	TESTPF1("%0{i+08}", 42, "%+08i");
	TESTPF1("%0{i+8}", 42, "%+8i");

	TESTPF1("%0{x02}", 93u, "%02x");

	TEST1("%0{i.0}", 42, "%(err: bad format)");
	TEST1("%0{i }", 42, "%(err: bad format)");
}
Пример #23
0
int main(int argc, char *argv[])
{

    // PHASE 1 : Cosntruction Du Réseau

    // On construit le réseau parisien complet avec 302 stations et 16 lignes (De 1 à 14, 3bis et 7bis)

    reseauparis RATP;
    RATP.Codage();
    RATP.CreationReseauStation();
    RATP.CreationReseauLigne();
    RATP.CreationMatrices();
    std::vector <std::vector <double> > MDistanceTrajet = RATP.GetMatriceTrajet();
    std::vector <std::vector <std::vector <double> > > MLigne= RATP.GetMatriceLigneSurTrajet();

    /*
     * A l'issue de la construction nous obtenons donc 2 matrices :
     * l'une contient les distances en mètre entre tout les couples de station
     * - 0 entre une station et elle-même
     * - une valeur arbitrairement grande entre 2 stations qui ne sont pas en lien direct : 1 000 000
     * - la distance exacte entre 2 stations en lien direct
     *
     * L'autre contient dans chacune de ses cases un vecteur avec les codes des "lignes avec direction"
     * qui utilisent chaque trajet.
     *
     * Attention  :
     * les trajets sont signés : A->B différent de b->A
     * et de plus cette phase ne s'execute qu'une seule fois au lancement du programme
     * et non pas à chaque nouvelle recherche de trajet optimal d'un utilisateur
     */



    //PHASE 2 : Mise en place des durée des trajet et des durées des correspondances

    estimdurees Regress(MDistanceTrajet);
    Regress.SetTempsArretMoyenStation(20.0);
    Regress.SetCoefLinRegressionLineaire(0.9);
    Regress.SetCoefQuadraRegressionLineaire(0.23);
    Regress.CalculDureesTrajet();
    Regress.SetTempsCorrespondanceMoyen(240.0);
    //std::vector <std::vector <double> > MDureeTrajet = Regress.GetMatriceDuree();
    double Tcm = Regress.GetTpsCorres();

    //Temps attente première station moyen (selon la RATP en secondes)
    double Tam = 150.0;

    /*
     * En effet comme le calcul des durée est le point du projet qui peut être transformé pour
     * coller mieux à la réalité on le sépare de la construction du réseau.
     * Ainsi un utilisateur du programme pourra modifier l'algorithme permettant le calcul des
     * durées des trajet simple (trajet entre 2 stations directement liées) à partir de la distance
     * entre 2 stations (issues des coordonnées GPS)
     * Et aussi affiner les temps de correspondances que nous considerons comme unique et constant
     * et égal à 4 minutes ou 240.0 secondes
     * (valeur cohérante au vu de ce qui est dit sur le site de la RATP)
     */


    //PHASE 3 : recherche du chemin le plus rapide avec l'algorithme dijkstra


    //dijkstra DJK(MDureeTrajet, MLigne,Tcm,Tam);




    // PHASE 4 : Interface Graphique

    // doonée de test

    std::vector <double> TEST1(4,0.0);
    std::vector <std::vector <double> > TEST2(3,TEST1);

    TEST2[0][0] = 4.0;
    TEST2[0][1] = 14.0;
    TEST2[0][2] = 1.2;
    TEST2[0][3] = 725.0;

    TEST2[1][0] = 14.0;
    TEST2[1][1] = 86.0;
    TEST2[1][2] = 4.2;
    TEST2[1][3] = 260.0;

    TEST2[2][0] = 86.0;
    TEST2[2][1] = 110.0;
    TEST2[2][2] = 10.2;
    TEST2[2][3] = 455.0;

    double DurTot = 2070.0;
    int nbcor = 2;





    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
}
Пример #24
0
// Basic ptz test
int test_ptz(playerc_client_t *client, int index)
{
  int t;
  void *rdevice;
  playerc_ptz_t *device;
  double period;

  printf("device [ptz] index [%d]\n", index);

  device = playerc_ptz_create(client, index);

  TEST("subscribing (read)");
  if (0 == playerc_ptz_subscribe(device, PLAYER_OPEN_MODE))
    PASS();
  else
    FAIL();

  period = 10 / M_PI * 2;

  for (t = 0; t < 20; t++)
  {
    TEST1("reading data (attempt %d)", t);

    do
      rdevice = playerc_client_read(client);
    while (rdevice == client);

    if (rdevice == device)
    {
      PASS();
      printf("ptz: [%d %d %d]\n",
             (int) (device->pan * 180 / M_PI),
             (int) (device->tilt * 180 / M_PI),
             (int) (device->zoom * 180 / M_PI));
    }
    else
    {
      FAIL();
      break;
    }

    TEST1("writing data (attempt %d)", t);
    if (playerc_ptz_set(device,
                        sin(t / period) * M_PI / 2,
                        sin(t / period) * M_PI / 3,
                        (1 - t / 20.0) * M_PI) != 0)
    {
      FAIL();
      break;
    }
    PASS();
  }

  TEST1("writing data (attempt %d)", t);
  if (playerc_ptz_set(device, 0, 0, M_PI) != 0)
    FAIL();
  else
    PASS();

  TEST("unsubscribing");
  if (playerc_ptz_unsubscribe(device) == 0)
    PASS();
  else
    FAIL();

  playerc_ptz_destroy(device);

  return 0;
}
int main()
{
   logical_op op;
   int i;
   init_reg_val2();
   for (op = AND; op <= XORI; op++) {
      for (i = 0; i < N; i++) {
         switch (op) {
            case AND:
               /* No Integer Overflow exception occurs under any
                  circumstances. */
               TEST1("and $t0, $t1, $t2", reg_val1[i], reg_val1[N-i-1],
                                          t0, t1, t2);
               TEST1("and $s0, $s1, $s2", reg_val2[i], reg_val2[N-i-1],
                                          s0, s1, s2);
               break;

            case ANDI:
               /* No Integer Overflow exception occurs under any
                  circumstances. */
               TEST2("andi $t0, $t1, 0xff",   reg_val1[i], 0xff,   t0, t1);
               TEST2("andi $t2, $t3, 0xffff", reg_val1[i], 0xffff, t2, t3);
               TEST2("andi $a0, $a1, 0x0",    reg_val1[i], 0x0,    a0, a1);
               TEST2("andi $s0, $s1, 0x23",   reg_val1[i], 0x23,   s0, s1);
               TEST2("andi $t0, $t1, 0xff",   reg_val2[i], 0xff,   t0, t1);
               TEST2("andi $t2, $t3, 0xffff", reg_val2[i], 0xffff, t2, t3);
               TEST2("andi $a0, $a1, 0x0",    reg_val2[i], 0x0,    a0, a1);
               TEST2("andi $s0, $s1, 0x23",   reg_val2[i], 0x23,   s0, s1);
               break;

            case LUI:
               /* No Integer Overflow exception occurs under any
                  circumstances. */
               if (i == 0) {
                  TEST6("lui $t0, 0xffff", 0xffff, t0);
                  TEST6("lui $a0, 0x0",    0x0,    a0);
                  TEST6("lui $t9, 0xff",   0xff,   t9);
                  TEST6("lui $v0, 0xfff",  0xfff,  v0);
                  TEST6("lui $s0, 0x2",    0x2,    s0);
               }
               break;

            case NOR:
               /* No arithmetic exception occurs under any circumstances. */
               TEST1("nor $t0, $t1, $t2", reg_val1[i], reg_val1[N-i-1],
                                          t0, t1, t2);
               TEST1("nor $s0, $s1, $s2", reg_val2[i], reg_val2[N-i-1],
                                          s0, s1, s2);
               break;

            case OR:
               /* No arithmetic exception occurs under any circumstances. */
               TEST1("or $t0, $t1, $t2", reg_val1[i], reg_val1[N-i-1],
                                         t0, t1, t2);
               TEST1("or $s0, $s1, $s2", reg_val2[i], reg_val2[N-i-1],
                                         s0, s1, s2);
               break;

            case ORI:
               /* No arithmetic exception occurs under any circumstances. */
               TEST2("ori $t0, $t1, 0xff",   reg_val1[i], 0xff,   t0, t1);
               TEST2("ori $t2, $t3, 0xffff", reg_val1[i], 0xffff, t2, t3);
               TEST2("ori $a0, $a1, 0x0",    reg_val1[i], 0x0,    a0, a1);
               TEST2("ori $s0, $s1, 0x23",   reg_val1[i], 0x23,   s0, s1);
               TEST2("ori $t0, $t1, 0xff",   reg_val2[i], 0xff,   t0, t1);
               TEST2("ori $t2, $t3, 0xffff", reg_val2[i], 0xffff, t2, t3);
               TEST2("ori $a0, $a1, 0x0",    reg_val2[i], 0x0,    a0, a1);
               TEST2("ori $s0, $s1, 0x23",   reg_val2[i], 0x23,   s0, s1);
               break;

            case XOR:
               /* No arithmetic exception occurs under any circumstances. */
               TEST1("xor $t0, $t1, $t2", reg_val1[i], reg_val1[N-i-1],
                                          t0, t1, t2);
               TEST1("xor $s0, $s1, $s2", reg_val2[i], reg_val2[N-i-1],
                                          s0, s1, s2);
               break;

            case XORI:
               /* No arithmetic exception occurs under any circumstances. */
               TEST2("xori $t0, $t1, 0xff",   reg_val1[i], 0xff,   t0, t1);
               TEST2("xori $t2, $t3, 0xffff", reg_val1[i], 0xffff, t2, t3);
               TEST2("xori $a0, $a1, 0x0",    reg_val1[i], 0x0,    a0, a1);
               TEST2("xori $s0, $s1, 0x23",   reg_val1[i], 0x23,   s0, s1);
               TEST2("xori $t0, $t1, 0xff",   reg_val2[i], 0xff,   t0, t1);
               TEST2("xori $t2, $t3, 0xffff", reg_val2[i], 0xffff, t2, t3);
               TEST2("xori $a0, $a1, 0x0",    reg_val2[i], 0x0,    a0, a1);
               TEST2("xori $s0, $s1, 0x23",   reg_val2[i], 0x23,   s0, s1);
               break;
         }
      }
   }
   return 0;
}
Пример #26
0
int
main(int argc, char *argv[])
{
    struct thr *thr;
    pthread_t pthr;
    int c, rc, i;

    pfl_init();
    progname = argv[0];
    while ((c = getopt(argc, argv, "i:n:")) != -1)
        switch (c) {
        case 'i':
            niter = atoi(optarg);
            break;
        case 'n':
            nthr = atoi(optarg);
            break;
        default:
            usage();
        }
    argc -= optind;
    if (argc)
        usage();

    psc_assert(psc_atomic64_read(&v64) == UINT64_C(100000000000));
    TEST(psc_atomic64, set, &v64, &v64, UINT64_C(2000000000000), UINT64_C(2000000000000));
    TEST(psc_atomic64, add, &v64, &v64, 15, UINT64_C(2000000000015));
    TEST(psc_atomic64, sub, &v64, &v64, 9, UINT64_C(2000000000006));
    TEST1(psc_atomic64, inc, &v64, UINT64_C(2000000000007));
    TEST1(psc_atomic64, dec, &v64, UINT64_C(2000000000006));

    psc_atomic16_set(&v16, 2);
    TEST(psc_atomic16, set, &v16, &v16, 200, 200);
    TEST(psc_atomic16, add, &v16, &v16, 15, 215);
    TEST(psc_atomic16, sub, &v16, &v16, 9, 206);
    TEST1(psc_atomic16, inc, &v16, 207);
    TEST1(psc_atomic16, dec, &v16, 206);
    TEST1V(psc_atomic16, dec_and_test0, &v16, 205, 0);
    TEST(psc_atomic16, set, &v16, &v16, 1, 1);
    TEST1V(psc_atomic16, dec_and_test0, &v16, 0, 1);
    TEST(psc_atomic16, setmask, &v16, &v16, 0x75, 0x75);
    TEST(psc_atomic16, clearmask, &v16, &v16, 0x41, 0x34);
    TEST(psc_atomic16, set, &v16, &v16, 0, 0);

    psc_atomic32_set(&v32, 2);
    TEST(psc_atomic32, set, &v32, &v32, 200, 200);
    TEST(psc_atomic32, add, &v32, &v32, 15, 215);
    TEST(psc_atomic32, sub, &v32, &v32, 9, 206);
    TEST1(psc_atomic32, inc, &v32, 207);
    TEST1(psc_atomic32, dec, &v32, 206);
    TEST1V(psc_atomic32, dec_and_test0, &v32, 205, 0);
    TEST(psc_atomic32, set, &v32, &v32, 1, 1);
    TEST1V(psc_atomic32, dec_and_test0, &v32, 0, 1);
    TEST(psc_atomic32, setmask, &v32, &v32, 0x75, 0x75);
    TEST(psc_atomic32, clearmask, &v32, &v32, 0x41, 0x34);
    TEST(psc_atomic32, set, &v32, &v32, 0, 0);

    psc_atomic64_set(&v64, 2);
    TEST(psc_atomic64, set, &v64, &v64, 200, 200);
    TEST(psc_atomic64, add, &v64, &v64, 15, 215);
    TEST(psc_atomic64, sub, &v64, &v64, 9, 206);
    TEST1(psc_atomic64, inc, &v64, 207);
    TEST1(psc_atomic64, dec, &v64, 206);
    TEST1V(psc_atomic64, dec_and_test0, &v64, 205, 0);
    TEST(psc_atomic64, set, &v64, &v64, 1, 1);
    TEST1V(psc_atomic64, dec_and_test0, &v64, 0, 1);
    TEST(psc_atomic64, setmask, &v64, &v64, 0x75, 0x75);
    TEST(psc_atomic64, clearmask, &v64, &v64, 0x41, 0x34);
    TEST(psc_atomic64, set, &v64, &v64, 0, 0);

    TEST1(psc_atomic16, inc, &v16, 1);
    TEST1V(psc_atomic16, dec_and_test0, &v16, 0, 1);

    rc = pthread_barrier_init(&barrier, NULL, nthr + 1);
    if (rc)
        psc_fatalx("pthread_barrier_init: %s", strerror(rc));
    for (i = 0; i < nthr; i++) {
        thr = PSCALLOC(sizeof(*thr));
        thr->pos = i;
        rc = pthread_create(&pthr, NULL, startf, thr);
        if (rc)
            psc_fatalx("pthread_create: %s", strerror(rc));
    }
    pthread_barrier_wait(&barrier);
    pthread_barrier_wait(&barrier);
    exit(0);
}
Пример #27
0
void test(double d1, double d2, float f1, float f2,
	  long double ld1, long double ld2)
{
  /* These are always nonnegative.  */

#define TEST1(FN) \
 extern void link_failure_##FN (void); PROTOTYPE(FN) \
 if (signbit(FN(d1)) || signbitf(FN##f(f1)) || signbitl(FN##l(ld1))) \
   link_failure_##FN()

#define TEST2(FN) \
 extern void link_failure_##FN (void); PROTOTYPE2(FN) \
 if (signbit(FN(d1,d2)) || signbitf(FN##f(f1,f2)) || signbitl(FN##l(ld1,ld2))) \
   link_failure_##FN()

#define CTEST1(FN) \
 extern void link_failure_##FN (void); CPROTOTYPE1(FN) \
 if (signbit(FN(d1)) || signbitf(FN##f(f1)) || signbitl(FN##l(ld1))) \
   link_failure_##FN()

#define ITEST1(FN) \
 extern void link_failure_##FN (void); IPROTOTYPE(FN) \
 if (signbit(FN(d1)) || signbitf(FN##l(f1)) || signbitl(FN##ll(ld1))) \
   link_failure_##FN()

  TEST1 (acos);
  TEST1 (acosh);
  CTEST1 (cabs);
  TEST1 (cosh);
  TEST1 (erfc);
  TEST1 (exp);
  TEST1 (exp10);
  TEST1 (exp2);
  TEST1 (fabs);
  TEST2 (fdim);
  TEST2 (hypot);
  TEST1 (pow10);
  TEST1 (sqrt);
  ITEST1 (ffs);
  ITEST1 (__builtin_parity);
  ITEST1 (__builtin_popcount);

  /* These are nonnegative if the first argument is.  */
#define ARG1TEST1(FN) \
 extern void link_failure_##FN (void); PROTOTYPE(FN) \
 if (signbit(FN(fabs(d1))) || signbitf(FN##f(fabsf(f1))) \
     || signbitl(FN##l(fabsl(ld1)))) \
   link_failure_##FN()

  /* Same, but allow specifying the return type.  */
#define ARG1TEST1_RTYPE(FN,RTYPE) \
 extern void link_failure_##FN (void); PROTOTYPE_RTYPE(FN,RTYPE) \
 if (signbit(FN(fabs(d1))) || signbitf(FN##f(fabsf(f1))) \
     || signbitl(FN##l(fabsl(ld1)))) \
   link_failure_##FN()

  /* These are nonnegative if the first argument is.  */
#define ARG1TEST2(FN) \
 extern void link_failure_##FN (void); PROTOTYPE2(FN) \
 if (signbit(FN(fabs(d1),d2)) || signbitf(FN##f(fabsf(f1),f2)) \
     || signbitl(FN##l(fabsl(ld1),ld2))) \
   link_failure_##FN()

  /* These are nonnegative if the second argument is.  */
#define ARG2TEST2(FN) \
 extern void link_failure_##FN (void); PROTOTYPE2(FN) \
 if (signbit(FN(d1,fabs(d2))) || signbitf(FN##f(f1,fabsf(f2))) \
     || signbitl(FN##l(ld1,fabsl(ld2)))) \
   link_failure_##FN()

  /* These are nonnegative if the first OR second argument is.  */
#define ARG2TESTor(FN) \
 extern void link_failure_##FN (void); PROTOTYPE2(FN) \
 if (signbit(FN(fabs(d1),d2)) || signbitf(FN##f(fabsf(f1),f2)) \
     || signbitl(FN##l(fabsl(ld1),ld2)) || signbit(FN(d1,fabs(d2))) \
     || signbitf(FN##f(f1,fabsf(f2))) || signbitl(FN##l(ld1,fabsl(ld2)))) \
   link_failure_##FN()

  /* These are nonnegative if the first AND second argument is.  */
#define ARG2TESTand(FN) \
 extern void link_failure_##FN (void); PROTOTYPE2(FN) \
 if (signbit(FN(fabs(d1),fabs(d2))) || signbitf(FN##f(fabsf(f1),fabsf(f2))) \
     || signbitl(FN##l(fabsl(ld1),fabsl(ld2)))) \
   link_failure_##FN()

  /* These are nonnegative if the first argument is, 2nd arg is int.  */
#define ARG2TEST1_A2INT(FN) \
 extern void link_failure_##FN (void); PROTOTYPE2TYPE2(FN, int) \
 if (signbit(FN(fabs(d1),d2)) || signbitf(FN##f(fabsf(f1),f2)) \
     || signbitl(FN##l(fabsl(ld1),ld2))) \
   link_failure_##FN()

  /* These are nonnegative if the first argument is, specify 2nd arg.  */
#define ARG2TEST1_A2FPTR(FN) \
 extern void link_failure_##FN (void); PROTOTYPE2_A2FPTR(FN) \
 if (signbit(FN(fabs(d1),&d2)) || signbitf(FN##f(fabsf(f1),&f2)) \
     || signbitl(FN##l(fabsl(ld1),&ld2))) \
   link_failure_##FN()

  ARG1TEST1 (asinh);
  ARG1TEST1 (atan);
  ARG1TEST1 (atanh);
  ARG1TEST1 (cbrt);
  ARG1TEST1 (ceil);
  ARG1TEST1 (erf);
  ARG1TEST1 (expm1);
  ARG1TEST1 (floor);
  ARG1TEST2 (fmod);
  ARG2TEST1_A2INT (ldexp);
  ARG1TEST1_RTYPE (__builtin_llceil, long long);
  ARG1TEST1_RTYPE (__builtin_llfloor, long long);
  ARG1TEST1_RTYPE (llrint, long long);
  ARG1TEST1_RTYPE (llround, long long);
  ARG1TEST1_RTYPE (__builtin_lceil, long);
  ARG1TEST1_RTYPE (__builtin_lfloor, long);
  ARG1TEST1_RTYPE (lrint, long);
  ARG1TEST1_RTYPE (lround, long);
  /* The modf* functions aren't ever "const" or "pure" even with
     -ffast-math so they won't be eliminated and yield a link failure.  */
  /* ARG2TEST1_A2FPTR (modf);*/
  ARG1TEST1 (nearbyint);
  ARG1TEST2 (pow);
  ARG1TEST1 (rint);
  ARG1TEST1 (round);
  ARG1TEST1_RTYPE (signbit, int);
  ARG1TEST1 (sinh);
  ARG1TEST1 (tanh);
  ARG1TEST1 (trunc);

  ARG2TESTor (fmax);
  ARG2TESTand (fmin);
  ARG2TEST2 (copysign);

}
/* Compare the Non recurrence properties of the entries
@param aEntry1 Pointer to the stored entry
@param aEntry2 Pointer to the entry fetched from the database
*/
void CTestCalInterimApiSuiteStepBase::CompareNonRecurrencePropertiesL(CCalEntry* aEntry1, CCalEntry* aEntry2)
	{
	TEST1( aEntry1->StartTimeL().TimeUtcL() == aEntry2->StartTimeL().TimeUtcL(), ETrue );
	TEST1( aEntry1->EndTimeL().TimeUtcL() == aEntry2->EndTimeL().TimeUtcL(), ETrue );
	TEST1( aEntry1->DTStampL().TimeUtcL() == aEntry2->DTStampL().TimeUtcL(), ETrue );
	TEST1( aEntry1->CompletedTimeL().TimeUtcL() == aEntry2->CompletedTimeL().TimeUtcL(), ETrue );
	TEST1( aEntry1->SummaryL() == aEntry2->SummaryL(), ETrue );
	TEST1( aEntry1->DescriptionL() == aEntry2->DescriptionL(), ETrue );
	TEST1( aEntry1->PriorityL() == aEntry2->PriorityL(), ETrue );
	TEST1( aEntry1->LocationL() == aEntry2->LocationL(), ETrue );
	TEST1( aEntry1->StatusL() == aEntry2->StatusL(), ETrue );
	TEST1( aEntry1->ReplicationStatusL() == aEntry2->ReplicationStatusL(), ETrue );
	TEST1( aEntry1->MethodL() == aEntry2->MethodL(), ETrue );
	TEST1( aEntry1->SequenceNumberL() == aEntry2->SequenceNumberL(), ETrue );
	
	CompareTransL(aEntry1, aEntry2);
	
	CompareRDatesL(aEntry1, aEntry2);
	CompareExDatesL(aEntry1, aEntry2);
	}
Пример #29
0
static void check(short dbr_type) {
    dbChannel *pch;
    db_field_log *pfl;
    dbAddr valaddr;
    dbAddr offaddr;
    const char *offname = NULL, *valname = NULL, *typname = NULL;
    epicsInt32 buf[26];
    long off, req;
    int i;

    switch (dbr_type) {
    case DBR_LONG:
        offname = "i32.OFF";
        valname = "i32.VAL";
        typname = "long";
        break;
    case DBR_DOUBLE:
        offname = "f64.OFF";
        valname = "f64.VAL";
        typname = "double";
        break;
    case DBR_STRING:
        offname = "c40.OFF";
        valname = "c40.VAL";
        typname = "string";
        break;
    default:
        testDiag("Invalid data type %d", dbr_type);
    }

    (void) dbNameToAddr(offname, &offaddr);
    (void) dbNameToAddr(valname, &valaddr);

    testHead("Ten %s elements", typname);

    /* Fill the record's array field with data, 10..19 */

    epicsInt32 ar[10] = {10,11,12,13,14,15,16,17,18,19};
    (void) dbPutField(&valaddr, DBR_LONG, ar, 10);

    /* Open a channel to it, make sure no filters present */

    createAndOpen(valname, &pch);
    testOk(pch->final_type == valaddr.field_type,
           "final type unchanged (%d->%d)", valaddr.field_type, pch->final_type);
    testOk(pch->final_no_elements == valaddr.no_elements,
           "final no_elements unchanged (%ld->%ld)", valaddr.no_elements, pch->final_no_elements);

    /* TEST1 sets the record's OFF field, then requests 10 elements from the channel,
     * passing in a transparent db_field_log and converting the data to LONG on the way in.
     * It checks that it got back the expected data and the right number of elements.
     */

#define TEST1(Size, Offset, Text, Expected) \
    testDiag("Reading from offset = %d (%s)", Offset, Text); \
    off = Offset; req = 10; \
    memset(buf, 0, sizeof(buf)); \
    (void) dbPutField(&offaddr, DBR_LONG, &off, 1); \
    pfl = db_create_read_log(pch); \
    testOk(pfl && pfl->type == dbfl_type_rec, "Valid pfl, type = rec"); \
    testOk(!dbChannelGetField(pch, DBR_LONG, buf, NULL, &req, pfl), "Got Field value"); \
    testOk(req == Size, "Got %ld elements (expected %d)", req, Size); \
    if (!testOk(!memcmp(buf, Expected, sizeof(Expected)), "Data correct")) \
        for (i=0; i<Size; i++) \
            testDiag("Element %d expected %d got %d", i, Expected[i], buf[i]); \
    db_delete_field_log(pfl);

    const epicsInt32 res_10_0[] = {10,11,12,13,14,15,16,17,18,19};
    TEST1(10, 0, "no offset", res_10_0);

    const epicsInt32 res_10_4[] = {14,15,16,17,18,19,10,11,12,13};
    TEST1(10, 4, "wrapped", res_10_4);

    /* Partial array */

    testHead("Five %s elements", typname);
    off = 0;    /* Reset offset for writing the next buffer */
    (void) dbPutField(&offaddr, DBR_LONG, &off, 1);
    (void) dbPutField(&valaddr, DBR_LONG, &ar[5], 5);

    createAndOpen(valname, &pch);
    testOk(pch->final_type == valaddr.field_type,
           "final type unchanged (%d->%d)", valaddr.field_type, pch->final_type);
    testOk(pch->final_no_elements == valaddr.no_elements,
           "final no_elements unchanged (%ld->%ld)", valaddr.no_elements, pch->final_no_elements);

    const epicsInt32 res_5_0[] = {15,16,17,18,19};
    TEST1(5, 0, "no offset", res_5_0);

    const epicsInt32 res_5_3[] = {18,19,15,16,17};
    TEST1(5, 3, "wrapped", res_5_3);

    /* TEST2 sets the record's OFF field, then requests 15 elements from the channel
     * but passes in a db_field_log with alternate data, converting that data to LONG.
     * It checks that it got back the expected data and the right number of elements.
     */

#define TEST2(Size, Offset, Text, Expected) \
    testDiag("Reading from offset = %d (%s)", Offset, Text); \
    off = Offset; req = 15; \
    memset(buf, 0, sizeof(buf)); \
    (void) dbPutField(&offaddr, DBR_LONG, &off, 1); \
    pfl = db_create_read_log(pch); \
    pfl->type = dbfl_type_ref; \
    pfl->field_type = DBF_CHAR; \
    pfl->field_size = 1; \
    pfl->no_elements = 26; \
    pfl->u.r.dtor = freeArray; \
    pfl->u.r.field = epicsStrDup("abcdefghijklmnopqrsstuvwxyz"); \
    testOk(!dbChannelGetField(pch, DBR_LONG, buf, NULL, &req, pfl), "Got Field value"); \
    testOk(req == Size, "Got %ld elements (expected %d)", req, Size); \
    if (!testOk(!memcmp(buf, Expected, sizeof(Expected)), "Data correct")) \
        for (i=0; i<Size; i++) \
            testDiag("Element %d expected '%c' got '%c'", i, Expected[i], buf[i]); \
    db_delete_field_log(pfl);

    testHead("Fifteen letters from field-log instead of %s", typname);

    const epicsInt32 res_15[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
        'm', 'n', 'o'};
    TEST2(15, 0, "no offset", res_15);
    TEST2(15, 10, "ignored", res_15);

    dbChannelDelete(pch);
}
Пример #30
0
static void check(short dbr_type) {
    dbChannel *pch;
    db_field_log *pfl, *pfl2;
    dbAddr valaddr;
    dbAddr offaddr;
    const char *offname = NULL, *valname = NULL, *typname = NULL;
    epicsInt32 ar[10] = {10,11,12,13,14,15,16,17,18,19};
    epicsInt32 *ar10_0_1 = ar;
    epicsInt32 ar10_4_1[10] = {14,15,16,17,18,19,10,11,12,13};
    epicsInt32 ar5_0_1[10] = {12,13,14,15,16};
    epicsInt32 ar5_3_1[10] = {15,16,17,18,19};
    epicsInt32 ar5_5_1[10] = {17,18,19,10,11};
    epicsInt32 ar5_9_1[10] = {11,12,13,14,15};
    epicsInt32 ar5_0_2[10] = {12,14,16};
    epicsInt32 ar5_3_2[10] = {15,17,19};
    epicsInt32 ar5_5_2[10] = {17,19,11};
    epicsInt32 ar5_9_2[10] = {11,13,15};
    epicsInt32 ar5_0_3[10] = {12,15};
    epicsInt32 ar5_3_3[10] = {15,18};
    epicsInt32 ar5_5_3[10] = {17,10};
    epicsInt32 ar5_9_3[10] = {11,14};
    epicsInt32 off = 0;

    switch (dbr_type) {
    case DBR_LONG:
        offname = "x.OFF";
        valname = "x.VAL";
        typname = "long";
        break;
    case DBR_DOUBLE:
        offname = "y.OFF";
        valname = "y.VAL";
        typname = "double";
        break;
    case DBR_STRING:
        offname = "z.OFF";
        valname = "z.VAL";
        typname = "string";
        break;
    default:
        testDiag("Invalid data type %d", dbr_type);
    }

    (void) dbNameToAddr(offname, &offaddr);

    (void) dbNameToAddr(valname, &valaddr);
    (void) dbPutField(&valaddr, DBR_LONG, ar, 10);

    /* Default: should not change anything */

    testHead("Ten %s elements from rec, increment 1, full size (default)", typname);
    createAndOpen(valname, "{\"arr\":{}}", "(default)", &pch, 1);
    testOk(pch->final_type == valaddr.field_type,
           "final type unchanged (%d->%d)", valaddr.field_type, pch->final_type);
    testOk(pch->final_no_elements == valaddr.no_elements,
           "final no_elements unchanged (%ld->%ld)", valaddr.no_elements, pch->final_no_elements);
    TEST1(10, 0, 1, "no offset");
    TEST1(10, 4, 1, "wrapped");
    dbChannelDelete(pch);

    testHead("Ten %s elements from rec, increment 1, out-of-bound start parameter", typname);
    createAndOpen(valname, "{\"arr\":{\"s\":-500}}", "out-of-bound start", &pch, 1);
    testOk(pch->final_type == valaddr.field_type,
           "final type unchanged (%d->%d)", valaddr.field_type, pch->final_type);
    testOk(pch->final_no_elements == valaddr.no_elements,
           "final no_elements unchanged (%ld->%ld)", valaddr.no_elements, pch->final_no_elements);
    TEST1(10, 4, 1, "wrapped");
    dbChannelDelete(pch);

    testHead("Ten %s elements from rec, increment 1, out-of-bound end parameter", typname);
    createAndOpen(valname, "{\"arr\":{\"e\":500}}", "out-of-bound end", &pch, 1);
    testOk(pch->final_type == valaddr.field_type,
           "final type unchanged (%d->%d)", valaddr.field_type, pch->final_type);
    testOk(pch->final_no_elements == valaddr.no_elements,
           "final no_elements unchanged (%ld->%ld)", valaddr.no_elements, pch->final_no_elements);
    TEST1(10, 4, 1, "wrapped");
    dbChannelDelete(pch);

    testHead("Ten %s elements from rec, increment 1, zero increment parameter", typname);
    createAndOpen(valname, "{\"arr\":{\"i\":0}}", "zero increment", &pch, 1);
    testOk(pch->final_type == valaddr.field_type,
           "final type unchanged (%d->%d)", valaddr.field_type, pch->final_type);
    testOk(pch->final_no_elements == valaddr.no_elements,
           "final no_elements unchanged (%ld->%ld)", valaddr.no_elements, pch->final_no_elements);
    TEST1(10, 4, 1, "wrapped");
    dbChannelDelete(pch);

    testHead("Ten %s elements from rec, increment 1, invalid increment parameter", typname);
    createAndOpen(valname, "{\"arr\":{\"i\":-30}}", "invalid increment", &pch, 1);
    testOk(pch->final_type == valaddr.field_type,
           "final type unchanged (%d->%d)", valaddr.field_type, pch->final_type);
    testOk(pch->final_no_elements == valaddr.no_elements,
           "final no_elements unchanged (%ld->%ld)", valaddr.no_elements, pch->final_no_elements);
    TEST1(10, 4, 1, "wrapped");
    dbChannelDelete(pch);

#define TEST5(Incr, Left, Right, Type) \
    testHead("Five %s elements from rec, increment " #Incr ", " Type " addressing", typname); \
    createAndOpen(valname, "{\"arr\":{\"s\":" #Left ",\"e\":" #Right ",\"i\":" #Incr "}}", \
                  "(" #Left ":" #Incr ":" #Right ")", &pch, 1); \
    testOk(pch->final_type == valaddr.field_type, \
           "final type unchanged (%d->%d)", valaddr.field_type, pch->final_type); \
    testOk(pch->final_no_elements == 4 / Incr + 1, \
           "final no_elements correct (%ld->%ld)", valaddr.no_elements, pch->final_no_elements); \
    TEST1(5, 0, Incr, "no offset"); \
    TEST1(5, 3, Incr, "from upper block"); \
    TEST1(5, 5, Incr, "wrapped"); \
    TEST1(5, 9, Incr, "from lower block"); \
    dbChannelDelete(pch);

    /* Contiguous block of 5 */

    TEST5(1,  2,  6, "regular");
    TEST5(1, -8,  6, "left side from-end");
    TEST5(1,  2, -4, "right side from-end");
    TEST5(1, -8, -4, "both sides from-end");

    /* 5 elements with increment 2 */

    TEST5(2,  2,  6, "regular");
    TEST5(2, -8,  6, "left side from-end");
    TEST5(2,  2, -4, "right side from-end");
    TEST5(2, -8, -4, "both sides from-end");

    /* 5 elements with increment 3 */

    TEST5(3,  2,  6, "regular");
    TEST5(3, -8,  6, "left side from-end");
    TEST5(3,  2, -4, "right side from-end");
    TEST5(3, -8, -4, "both sides from-end");

    /* From buffer (plugin chain) */

#define TEST5B(Incr, Left, Right, Type) \
    testHead("Five %s elements from buffer, increment " #Incr ", " Type " addressing", typname); \
    createAndOpen(valname, "{\"arr\":{},\"arr\":{\"s\":" #Left ",\"e\":" #Right ",\"i\":" #Incr "}}", \
                  "(" #Left ":" #Incr ":" #Right ")", &pch, 2); \
    testOk(pch->final_type == valaddr.field_type, \
           "final type unchanged (%d->%d)", valaddr.field_type, pch->final_type); \
    testOk(pch->final_no_elements == 4 / Incr + 1, \
           "final no_elements correct (%ld->%ld)", valaddr.no_elements, pch->final_no_elements); \
    TEST1(5, 0, Incr, "no offset"); \
    dbChannelDelete(pch);

    /* Contiguous block of 5 */

    TEST5B(1,  2,  6, "regular");
    TEST5B(1, -8,  6, "left side from-end");
    TEST5B(1,  2, -4, "right side from-end");
    TEST5B(1, -8, -4, "both sides from-end");

    /* 5 elements with increment 2 */

    TEST5B(2,  2,  6, "regular");
    TEST5B(2, -8,  6, "left side from-end");
    TEST5B(2,  2, -4, "right side from-end");
    TEST5B(2, -8, -4, "both sides from-end");

    /* 5 elements with increment 3 */

    TEST5B(3,  2,  6, "regular");
    TEST5B(3, -8,  6, "left side from-end");
    TEST5B(3,  2, -4, "right side from-end");
    TEST5B(3, -8, -4, "both sides from-end");
}