Пример #1
0
char* sptest(struct jl_asciistring_t str) {
    //Unpack an ASCIIString
    return stest(str.data->data);
}
Пример #2
0
int
main(int argc, char *argv[])
{
	static const int ex_under = FE_UNDERFLOW | FE_INEXACT;	/* shorthand */
	static const int ex_over = FE_OVERFLOW | FE_INEXACT;
	long double ldbl_small, ldbl_eps, ldbl_max;

	printf("1..5\n");

#ifdef	__i386__
	fpsetprec(FP_PE);
#endif
	/*
	 * We can't use a compile-time constant here because gcc on
	 * FreeBSD/i386 assumes long doubles are truncated to the
	 * double format.
	 */
	ldbl_small = ldexpl(1.0, LDBL_MIN_EXP - LDBL_MANT_DIG);
	ldbl_eps = LDBL_EPSILON;
	ldbl_max = ldexpl(1.0 - ldbl_eps / 2, LDBL_MAX_EXP);

	/*
	 * Special cases involving zeroes.
	 */
#define	ztest(prec)							      \
	test##prec(copysign##prec(1.0, nextafter##prec(0.0, -0.0)), -1.0, 0); \
	test##prec(copysign##prec(1.0, nextafter##prec(-0.0, 0.0)), 1.0, 0);  \
	test##prec(copysign##prec(1.0, nexttoward##prec(0.0, -0.0)), -1.0, 0);\
	test##prec(copysign##prec(1.0, nexttoward##prec(-0.0, 0.0)), 1.0, 0)

	ztest();
	ztest(f);
	ztest(l);
#undef	ztest

#define	stest(next, eps, prec)					\
	test##prec(next(-0.0, 42.0), eps, ex_under);		\
	test##prec(next(0.0, -42.0), -eps, ex_under);		\
	test##prec(next(0.0, INFINITY), eps, ex_under);		\
	test##prec(next(-0.0, -INFINITY), -eps, ex_under)

	stest(nextafter, 0x1p-1074, );
	stest(nextafterf, 0x1p-149f, f);
	stest(nextafterl, ldbl_small, l);
	stest(nexttoward, 0x1p-1074, );
	stest(nexttowardf, 0x1p-149f, f);
	stest(nexttowardl, ldbl_small, l);
#undef	stest

	printf("ok 1 - next\n");

	/*
	 * `x == y' and NaN tests
	 */
	testall(42.0, 42.0, 42.0, 0);
	testall(-42.0, -42.0, -42.0, 0);
	testall(INFINITY, INFINITY, INFINITY, 0);
	testall(-INFINITY, -INFINITY, -INFINITY, 0);
	testall(NAN, 42.0, NAN, 0);
	testall(42.0, NAN, NAN, 0);
	testall(NAN, NAN, NAN, 0);

	printf("ok 2 - next\n");

	/*
	 * Tests where x is an ordinary normalized number
	 */
	testboth(1.0, 2.0, 1.0 + DBL_EPSILON, 0, );
	testboth(1.0, -INFINITY, 1.0 - DBL_EPSILON/2, 0, );
	testboth(1.0, 2.0, 1.0 + FLT_EPSILON, 0, f);
	testboth(1.0, -INFINITY, 1.0 - FLT_EPSILON/2, 0, f);
	testboth(1.0, 2.0, 1.0 + ldbl_eps, 0, l);
	testboth(1.0, -INFINITY, 1.0 - ldbl_eps/2, 0, l);

	testboth(-1.0, 2.0, -1.0 + DBL_EPSILON/2, 0, );
	testboth(-1.0, -INFINITY, -1.0 - DBL_EPSILON, 0, );
	testboth(-1.0, 2.0, -1.0 + FLT_EPSILON/2, 0, f);
	testboth(-1.0, -INFINITY, -1.0 - FLT_EPSILON, 0, f);
	testboth(-1.0, 2.0, -1.0 + ldbl_eps/2, 0, l);
	testboth(-1.0, -INFINITY, -1.0 - ldbl_eps, 0, l);

	/* Cases where nextafter(...) != nexttoward(...) */
	test(nexttoward(1.0, 1.0 + ldbl_eps), 1.0 + DBL_EPSILON, 0);
	testf(nexttowardf(1.0, 1.0 + ldbl_eps), 1.0 + FLT_EPSILON, 0);
	testl(nexttowardl(1.0, 1.0 + ldbl_eps), 1.0 + ldbl_eps, 0);

	printf("ok 3 - next\n");

	/*
	 * Tests at word boundaries, normalization boundaries, etc.
	 */
	testboth(0x1.87654ffffffffp+0, INFINITY, 0x1.87655p+0, 0, );
	testboth(0x1.87655p+0, -INFINITY, 0x1.87654ffffffffp+0, 0, );
	testboth(0x1.fffffffffffffp+0, INFINITY, 0x1p1, 0, );
	testboth(0x1p1, -INFINITY, 0x1.fffffffffffffp+0, 0, );
	testboth(0x0.fffffffffffffp-1022, INFINITY, 0x1p-1022, 0, );
	testboth(0x1p-1022, -INFINITY, 0x0.fffffffffffffp-1022, ex_under, );

	testboth(0x1.fffffep0f, INFINITY, 0x1p1, 0, f);
	testboth(0x1p1, -INFINITY, 0x1.fffffep0f, 0, f);
	testboth(0x0.fffffep-126f, INFINITY, 0x1p-126f, 0, f);
	testboth(0x1p-126f, -INFINITY, 0x0.fffffep-126f, ex_under, f);

#if LDBL_MANT_DIG == 53
	testboth(0x1.87654ffffffffp+0L, INFINITY, 0x1.87655p+0L, 0, l);
	testboth(0x1.87655p+0L, -INFINITY, 0x1.87654ffffffffp+0L, 0, l);
	testboth(0x1.fffffffffffffp+0L, INFINITY, 0x1p1L, 0, l);
	testboth(0x1p1L, -INFINITY, 0x1.fffffffffffffp+0L, 0, l);
	testboth(0x0.fffffffffffffp-1022L, INFINITY, 0x1p-1022L, 0, l);
	testboth(0x1p-1022L, -INFINITY, 0x0.fffffffffffffp-1022L, ex_under, l);
#elif LDBL_MANT_DIG == 64 && !defined(__i386)
	testboth(0x1.87654321fffffffep+0L, INFINITY, 0x1.87654322p+0L, 0, l);
	testboth(0x1.87654322p+0L, -INFINITY, 0x1.87654321fffffffep+0L, 0, l);
	testboth(0x1.fffffffffffffffep0L, INFINITY, 0x1p1L, 0, l);
	testboth(0x1p1L, -INFINITY, 0x1.fffffffffffffffep0L, 0, l);
	testboth(0x0.fffffffffffffffep-16382L, INFINITY, 0x1p-16382L, 0, l);
	testboth(0x1p-16382L, -INFINITY,
	    0x0.fffffffffffffffep-16382L, ex_under, l);
#elif LDBL_MANT_DIG == 113
	testboth(0x1.876543210987ffffffffffffffffp+0L, INFINITY,
	    0x1.876543210988p+0, 0, l);
	testboth(0x1.876543210988p+0L, -INFINITY,
	    0x1.876543210987ffffffffffffffffp+0L, 0, l);
	testboth(0x1.ffffffffffffffffffffffffffffp0L, INFINITY, 0x1p1L, 0, l);
	testboth(0x1p1L, -INFINITY, 0x1.ffffffffffffffffffffffffffffp0L, 0, l);
	testboth(0x0.ffffffffffffffffffffffffffffp-16382L, INFINITY,
	    0x1p-16382L, 0, l);
	testboth(0x1p-16382L, -INFINITY,
	    0x0.ffffffffffffffffffffffffffffp-16382L, ex_under, l);
#endif

	printf("ok 4 - next\n");

	/*
	 * Overflow tests
	 */
	test(idd(nextafter(DBL_MAX, INFINITY)), INFINITY, ex_over);
	test(idd(nextafter(INFINITY, 0.0)), DBL_MAX, 0);
	test(idd(nexttoward(DBL_MAX, DBL_MAX * 2.0L)), INFINITY, ex_over);
#if LDBL_MANT_DIG > 53
	test(idd(nexttoward(INFINITY, DBL_MAX * 2.0L)), DBL_MAX, 0);
#endif

	testf(idf(nextafterf(FLT_MAX, INFINITY)), INFINITY, ex_over);
	testf(idf(nextafterf(INFINITY, 0.0)), FLT_MAX, 0);
	testf(idf(nexttowardf(FLT_MAX, FLT_MAX * 2.0)), INFINITY, ex_over);
	testf(idf(nexttowardf(INFINITY, FLT_MAX * 2.0)), FLT_MAX, 0);

	testboth(ldbl_max, INFINITY, INFINITY, ex_over, l);
	testboth(INFINITY, 0.0, ldbl_max, 0, l);

	printf("ok 5 - next\n");

	return (0);
}
Пример #3
0
LOCAL_C TInt secondaryThread(TAny* aTestInfo)
	{
	RTest stest(_L("Secondary test thread"));
	stest.Title();
	
	stest.Start(_L("Check which test to perform"));
	SSecondaryThreadInfo& sti=*((SSecondaryThreadInfo*)aTestInfo);
	TInt r;
	switch(sti.iTestId)
		{
		case ESecThreadConfigPlayback:
			{
			stest.Next(_L("Duplicate the channel handle passed from main thread"));
			
			// Get a reference to the main thread - which created the handle
			RThread thread;
			r=thread.Open(sti.iThreadId);
			stest(r==KErrNone);
	
			// Duplicate the driver handle passed from the other thread - for this thread
			RSoundSc snddev;
			snddev.SetHandle(sti.iDrvHandle);
			r=snddev.Duplicate(thread);
			stest(r==KErrNone);
			thread.Close();
			
			stest.Next(_L("Configure the driver"));
			// Read the capabilties of this device.
			TSoundFormatsSupportedV02Buf capsBuf;
			snddev.Caps(capsBuf);
			TSoundFormatsSupportedV02& caps=capsBuf();
			
			// Read back the default configuration - which must be valid.
			TCurrentSoundFormatV02Buf formatBuf;
			snddev.AudioFormat(formatBuf);
			TCurrentSoundFormatV02& format=formatBuf();
			
			if (caps.iEncodings&KSoundEncoding16BitPCM)
				format.iEncoding = ESoundEncoding16BitPCM;
			if (caps.iRates&KSoundRate16000Hz)
				format.iRate = ESoundRate16000Hz;
			if (caps.iChannels&KSoundStereoChannel)
				format.iChannels = 2;
			r=snddev.SetAudioFormat(formatBuf);
			stest(r==KErrNone);
			r=snddev.SetVolume(KSoundMaxVolume);
			stest(r==KErrNone);
			
			stest.Next(_L("Close the channel again"));
			snddev.Close();
			
			break;	
			}
			
		case ESecThreadConfigRecord:
			{
			stest.Next(_L("Use the channel passed from main thread to configure driver"));
			
			break;		
			}
			
		default:
			break;
		}
	
//	stest.Getch();	
	stest.End();
	return(KErrNone);	
	}
Пример #4
0
//------------------------------------------------------------------------
int notmain ( void )
{
    unsigned int ra;
    unsigned int rb;
    unsigned int rc;
    unsigned int rd;
    unsigned int re;


    uart_send(0x0D);
    uart_send(0x0A);
    uart_send(0x0A);

    rd=0x0432;
    re=0x0137;

    for(ra=0;ra<4;ra++)
    {
        for(rb=0;rb<4;rb++)
        {
            rc=atest(ra<<30,rb<<30);
            show_op(ra);
            show_op(rb);
            if(rc&1) uart_send(0x31); else uart_send(0x30);
            if(rd&0x8000) uart_send(0x31); else uart_send(0x30);
            rd<<=1;
            uart_send(0x20);
            if(rc&2) uart_send(0x31); else uart_send(0x30);
            if(re&0x8000) uart_send(0x31); else uart_send(0x30);
            re<<=1;
            uart_send(0x0D);
            uart_send(0x0A);
        }
    }

    uart_send(0x0D);
    uart_send(0x0A);
    uart_send(0x0A);

    rd=0x2340;
    re=0x8CEF;

    for(ra=0;ra<4;ra++)
    {
        for(rb=0;rb<4;rb++)
        {
            rc=stest(ra<<30,rb<<30);
            show_op(ra);
            show_op(rb);
            if(rc&1) uart_send(0x31); else uart_send(0x30);
            if(rd&0x8000) uart_send(0x31); else uart_send(0x30);
            rd<<=1;
            uart_send(0x20);
            if(rc&2) uart_send(0x31); else uart_send(0x30);
            if(re&0x8000) uart_send(0x31); else uart_send(0x30);
            re<<=1;
            rc=ra-rb;
            if(rc&4) uart_send(0x30); else uart_send(0x31);
            uart_send(0x0D);
            uart_send(0x0A);
        }
    }

    uart_send(0x0D);
    uart_send(0x0A);
    uart_send(0x0A);










    return(0);
}
Пример #5
0
void TestSuite::TestString(void){
    UnitTest::SetPrefix("TestString.cpp - Test String Class");
    {
	   json_string s;
	   assertEmpty(s);
    }

    {
	   json_string s;
	   assertEmpty(s);
	   json_string m(s);
	   assertEmpty(m);
	   assertEmpty(s);
	   assertSame(s, m);
    }

    {
	   json_string s(JSON_TEXT("hello"));
	   assertEquals(s.length(), 5);
	   assertFalse(s.empty());
	   assertCStringSame(s.c_str(), JSON_TEXT("hello"));
	   assertEquals(s, s);
	   assertEquals(s, JSON_TEXT("hello"));
	   s.clear();
	   assertEmpty(s);
    }

    {
	   json_string s(5, 'h');
	   assertEquals(s.length(), 5);
	   assertFalse(s.empty());
	   assertCStringSame(s.c_str(), JSON_TEXT("hhhhh"));
	   assertEquals(s, s);
	   assertEquals(s, JSON_TEXT("hhhhh"));
	   s.clear();
	   assertEmpty(s);
    }

    {
	   json_string s(5, 'h');
	   json_string m(s);
	   assertSame(s, m);
    }

    {
	   json_string s(5, 'h');
	   json_string m(s);
	   assertSame(s, m);
	   s.clear();
	   assertEmpty(s);
	   assertEquals(s.length(), 0);
	   assertDifferent(s, m);
    }


    {
	   json_string s(JSON_TEXT("hello"));
	   json_string m = s;
	   assertSame(s, m);
	   m = s.substr(1, 3);
	   assertEquals(m.length(), 3);
	   assertEquals(m, JSON_TEXT("ell"));
    }

    {
	   json_string s(JSON_TEXT("hello"));
	   json_string m = s;
	   assertSame(s, m);
	   m = s.substr(1);
	   assertEquals(m.length(), 4);
	   assertEquals(m, JSON_TEXT("ello"));
    }

    {
	   json_string s(JSON_TEXT("hello"));
	   s += JSON_TEXT(" world");
	   assertEquals(s.length(), 11);
	   assertEquals(s, JSON_TEXT("hello world"));
    }


    {
	   json_string s(JSON_TEXT("hello"));
	   json_string m = s + JSON_TEXT(" world ") + s;
	   assertEquals(m.length(), 17);
	   assertEquals(m, JSON_TEXT("hello world hello"));
    }

    {
	   json_string s(JSON_TEXT("hello"));
	   s += 'a';
	   s += 'a';
	   s += 'a';
	   s += 'a';
	   assertEquals(s.length(), 9);
	   assertEquals(s, JSON_TEXT("helloaaaa"));
    }

    {
	   json_string s(JSON_TEXT("hello world"));
	   size_t pos = s.find('w');
	   assertEquals(pos, 6);
    }

    {
	   json_string s(JSON_TEXT("hello world"));
	   size_t pos = s.find('z');
	   assertEquals(pos, json_string::npos);
    }

    {
	   json_string s(JSON_TEXT("hello world"));
	   size_t pos = s.find_first_not_of(JSON_TEXT("helo"));
	   assertEquals(pos, 5);
    }

    {
	   json_string s(JSON_TEXT("hello world"));
	   size_t pos = s.find_first_of(JSON_TEXT("ol"));
	   assertEquals(pos, 2);
    }

    {
	   json_string s(JSON_TEXT("hello world"));
	   s.erase(s.begin(), s.begin() + 3);
	   assertEquals(s, JSON_TEXT("lo world"));
    }

	{
	   json_string s(JSON_TEXT("hello world"), 5);
	   assertEquals(s, JSON_TEXT("hello"));
    }

    #ifndef JSON_STRING_HEADER
        {
	        json_string s(JSON_TEXT("hello world"));
	        std::wstring wtest(L"hello world");
	        std::string stest("hello world");
	        assertEquals(libjson::to_std_string(s), stest);
	        assertEquals(stest, libjson::to_std_string(s));
	        assertEquals(libjson::to_std_wstring(s), wtest);
	        assertEquals(wtest, libjson::to_std_wstring(s));

	        assertEquals(s, libjson::to_json_string(stest));
	        assertEquals(libjson::to_json_string(stest), s);
	        assertEquals(s, libjson::to_json_string(wtest));
	        assertEquals(libjson::to_json_string(wtest), s);
        }
    #endif
}