Пример #1
0
void IntlCalendarTest::TestBuddhistFormat() {
    UErrorCode status = U_ZERO_ERROR;
    
    // Test simple parse/format with adopt
    
    // First, a contrived english test..
    UDate aDate = 999932400000.0; 
    SimpleDateFormat *fmt = new SimpleDateFormat(UnicodeString("MMMM d, yyyy G"), Locale("en_US@calendar=buddhist"), status);
    CHECK(status, "creating date format instance");
    SimpleDateFormat *fmt2 = new SimpleDateFormat(UnicodeString("MMMM d, yyyy G"), Locale("en_US@calendar=gregorian"), status);
    CHECK(status, "creating gregorian date format instance");
    if(!fmt) { 
        errln("Coudln't create en_US instance");
    } else {
        UnicodeString str;
        fmt2->format(aDate, str);
        logln(UnicodeString() + "Test Date: " + str);
        str.remove();
        fmt->format(aDate, str);
        logln(UnicodeString() + "as Buddhist Calendar: " + escape(str));
        UnicodeString expected("September 8, 2544 BE");
        if(str != expected) {
            errln("Expected " + escape(expected) + " but got " + escape(str));
        }
        UDate otherDate = fmt->parse(expected, status);
        if(otherDate != aDate) { 
            UnicodeString str3;
            fmt->format(otherDate, str3);
            errln("Parse incorrect of " + escape(expected) + " - wanted " + aDate + " but got " +  otherDate + ", " + escape(str3));
        } else {
            logln("Parsed OK: " + expected);
        }
        delete fmt;
    }
    delete fmt2;
    
    CHECK(status, "Error occured testing Buddhist Calendar in English ");
    
    status = U_ZERO_ERROR;
    // Now, try in Thai
    {
        UnicodeString expect = CharsToUnicodeString("\\u0E27\\u0E31\\u0E19\\u0E40\\u0E2A\\u0E32\\u0E23\\u0E4C\\u0E17\\u0E35\\u0E48"
            " 8 \\u0E01\\u0E31\\u0e19\\u0e22\\u0e32\\u0e22\\u0e19 \\u0e1e.\\u0e28. 2544");
        UDate         expectDate = 999932400000.0;
        Locale        loc("th_TH_TRADITIONAL"); // legacy
        
        simpleTest(loc, expect, expectDate, status);
    }
    status = U_ZERO_ERROR;
    {
        UnicodeString expect = CharsToUnicodeString("\\u0E27\\u0E31\\u0E19\\u0E40\\u0E2A\\u0E32\\u0E23\\u0E4C\\u0E17\\u0E35\\u0E48"
            " 8 \\u0E01\\u0E31\\u0e19\\u0e22\\u0e32\\u0e22\\u0e19 \\u0e1e.\\u0e28. 2544");
        UDate         expectDate = 999932400000.0;
        Locale        loc("th_TH@calendar=buddhist");
        
        simpleTest(loc, expect, expectDate, status);
    }
    status = U_ZERO_ERROR;
    {
        UnicodeString expect = CharsToUnicodeString("\\u0E27\\u0E31\\u0E19\\u0E40\\u0E2A\\u0E32\\u0E23\\u0E4C\\u0E17\\u0E35\\u0E48"
            " 8 \\u0E01\\u0E31\\u0e19\\u0e22\\u0e32\\u0e22\\u0e19 \\u0e04.\\u0e28. 2001");
        UDate         expectDate = 999932400000.0;
        Locale        loc("th_TH@calendar=gregorian");
        
        simpleTest(loc, expect, expectDate, status);
    }
    status = U_ZERO_ERROR;
    {
        UnicodeString expect = CharsToUnicodeString("\\u0E27\\u0E31\\u0E19\\u0E40\\u0E2A\\u0E32\\u0E23\\u0E4C\\u0E17\\u0E35\\u0E48"
            " 8 \\u0E01\\u0E31\\u0e19\\u0e22\\u0e32\\u0e22\\u0e19 \\u0e04.\\u0e28. 2001");
        UDate         expectDate = 999932400000.0;
        Locale        loc("th_TH_TRADITIONAL@calendar=gregorian");
        
        simpleTest(loc, expect, expectDate, status);
    }
}
Пример #2
0
//
//	Recursive descent parser, old-school style.
//
void getfactor(void) {
numvar thesymval = symval;
byte thesym = sym;
	getsym();		// eat the sym we just saved

	switch (thesym) {
		case s_nval:
			vpush(thesymval);
			break;
			
		case s_nvar:
			if (sym == s_equals) {		// assignment, push is after the break;
				getsym();
				assignVar(thesymval, getnum());
			}
			else if (sym == s_incr) {	// postincrement nvar++
				vpush(getVar(thesymval));
				assignVar(thesymval, getVar(thesymval) + 1);
				getsym();
				break;
			}
			else if (sym == s_decr) {	// postdecrement nvar--
				vpush(getVar(thesymval));
				assignVar(thesymval, getVar(thesymval) - 1);
				getsym();
				break;
			}
			vpush(getVar(thesymval));			// both assignment and reference get pushed here
			break;

		case s_nfunct:
			dofunctioncall(thesymval);			// get its value onto the stack
			break;

		// Script-function-returning-value used as a factor
		case s_script_eeprom:				// macro returning value
			callscriptfunction(SCRIPT_EEPROM, findend(thesymval));
			break;

		case s_script_progmem:
			callscriptfunction(SCRIPT_PROGMEM, thesymval);
			break;

		case s_script_file:
			callscriptfunction(SCRIPT_FILE, (numvar) 0);	// name implicitly in idbuf!
			break;

		case s_apin:					// analog pin reference like a0
			if (sym == s_equals) { 		// digitalWrite or analogWrite
				getsym();
				analogWrite(thesymval, getnum());
				vpush(expval);
			}
			else vpush(analogRead(thesymval));
			break;

		case s_dpin:					// digital pin reference like d1
			if (sym == s_equals) { 		// digitalWrite or analogWrite
				getsym();
				digitalWrite(thesymval, getnum());
				vpush(expval);
			}
			else vpush(digitalRead(thesymval));
			break;

		case s_incr:
			if (sym != s_nvar) expected(M_var);
			assignVar(symval, getVar(symval) + 1);
			vpush(getVar(symval));
			getsym();
			break;

		case s_decr:		// pre decrement
			if (sym != s_nvar) expected(M_var);
			assignVar(symval, getVar(symval) - 1);
			vpush(getVar(symval));
			getsym();
			break;

		case s_arg:			// arg(n) - argument value
			if (sym != s_lparen) expectedchar(s_lparen);
			getsym(); 		// eat '('
			vpush(getarg(getnum()));
			if (sym != s_rparen) expectedchar(s_rparen);
			getsym();		// eat ')'
			break;

		case s_lparen:  // expression in parens
			getexpression();
			if (exptype != s_nval) expected(M_number);
			if (sym != s_rparen) missing(M_rparen);
			vpush(expval);
			getsym();	// eat the )
			break;

		//
		// The Family of Unary Operators, which Bind Most Closely to their Factor
		//
		case s_add:			// unary plus (like +3) is kind of a no-op
			getfactor();	// scan a factor and leave its result on the stack
			break;			// done
	
		case s_sub:			// unary minus (like -3)
			getfactor();
			vpush(-vpop());	// similar to above but we adjust the stack value
			break;
	
		case s_bitnot:
			getfactor();
			vpush(~vpop());
			break;
	
		case s_logicalnot:
			getfactor();
			vpush(!vpop());
			break;

		case s_bitand:		// &var gives address-of-var; &macro gives eeprom address of macro
			if (sym == s_nvar) vpush((numvar) &vars[symval]);
			else if (sym == s_script_eeprom) vpush(symval);
			else expected(M_var);
			getsym();		// eat the var reference
			break;

		case s_mul:			// *foo is contents-of-address-foo; *foo=bar is byte poke assignment

/*****
// what is really acceptable for an lvalue here? ;)
//	*y = 5 is failing now by assigning 5 to y before the * is dereferenced
//	due to calling getfactor
//	everything else works :(
*****/
			getfactor();
#if 0
			if (sym == s_equals) {
				getsym();	// eat '='
				getexpression();
				* (volatile byte *) vpop() = (byte) expval;
				vpush((numvar) (byte) expval);
			} 
			else 
#endif
			vpush((numvar) (* (volatile byte *) vpop()));
			break;

		default: 
			unexpected(M_number);
	}

}
/* verifica se entrada combina com o esperado */
void match(char c)
{
	if (look != c)
		expected("'%c'", c);
	nextChar();
}
Пример #4
0
static void test_CPoint()
{
    CPoint empty;

    ok(empty.x == 0, "Expected x to be 0, was %ld\n", empty.x);
    ok(empty.y == 0, "Expected y to be 0, was %ld\n", empty.y);

    CPoint ptTopLeft(0, 0);
    POINT ptHere;
    ptHere.x = 35;
    ptHere.y = 95;

    CPoint ptMFCHere(ptHere);

    SIZE sHowBig;
    sHowBig.cx = 300;
    sHowBig.cy = 10;

    CPoint ptMFCBig(sHowBig);
    DWORD dwSize;
    dwSize = MAKELONG(35, 95);

    CPoint ptFromDouble(dwSize);
    ok_point(ptFromDouble, ptMFCHere);

    CPoint ptStart(100, 100);
    ptStart.Offset(35, 35);

    CPoint ptResult(135, 135);
    ok_point(ptStart, ptResult);

    ptStart = CPoint(100, 100);
    POINT pt;

    pt.x = 35;
    pt.y = 35;

    ptStart.Offset(pt);
    ok_point(ptStart, ptResult);

    ptStart = CPoint(100, 100);
    SIZE size;

    size.cx = 35;
    size.cy = 35;

    ptStart.Offset(size);
    ok_point(ptStart, ptResult);

    CPoint ptFirst(256, 128);
    CPoint ptTest(256, 128);
    ok_point(ptFirst, ptTest);

    pt.x = 256;
    pt.y = 128;
    ok_point(ptTest, pt);

    ptTest = CPoint(111, 333);
    nok_point(ptFirst, ptTest);

    pt.x = 333;
    pt.y = 111;
    nok_point(ptTest, pt);

    ptStart = CPoint(100, 100);
    CSize szOffset(35, 35);

    ptStart += szOffset;

    ok_point(ptResult, ptStart);

    ptStart = CPoint(100, 100);

    ptStart += size;
    ok_point(ptResult, ptStart);

    ptStart = CPoint(100, 100);

    ptStart -= szOffset;

    ptResult = CPoint(65, 65);
    ok_point(ptResult, ptStart);


    ptStart = CPoint(100, 100);

    ptStart -= size;
    ok_point(ptResult, ptStart);

    ptStart = CPoint(100, 100);
    CPoint ptEnd;

    ptEnd = ptStart + szOffset;

    ptResult = CPoint(135, 135);
    ok_point(ptResult, ptEnd);

    ptEnd = ptStart + size;
    ok_point(ptResult, ptEnd);

    ptEnd = ptStart + pt;
    ptResult = CPoint(433, 211);
    ok_point(ptResult, ptEnd);

    ptEnd = ptStart - szOffset;
    ptResult = CPoint(65, 65);
    ok_point(ptResult, ptEnd);

    ptEnd = ptStart - size;
    ok_point(ptResult, ptEnd);

    szOffset = ptStart - pt;
    CSize expected(-233, -11);
    ok_size(szOffset, expected);

    ptStart += pt;
    ptResult = CPoint(433, 211);
    ok_point(ptResult, ptStart);

    ptStart -= pt;
    ptResult = CPoint(100, 100);
    ok_point(ptResult, ptStart);

    ptTest = CPoint(35, 35);
    ptTest = -ptTest;

    CPoint ptNeg(-35, -35);
    ok_point(ptTest, ptNeg);

    RECT rc = { 1, 2, 3, 4 };

    CRect rcres = ptStart + &rc;
    CRect rcexp(101, 102, 103, 104);
    ok_rect(rcexp, rcres);

    rcres = ptStart - &rc;
    rcexp = CRect(-99, -98, -97, -96);
    ok_rect(rcexp, rcres);
}
Пример #5
0
int main( int argc, char** argv ) {
    QApplication app( argc, argv );

    KDReports::Report report;

    report.setHeaderBodySpacing( 10 ); // mm
    report.setFooterBodySpacing( 10 ); // mm

//     report.setWatermarkPixmap( QPixmap( ":/kdab.jpg" ) );
//     report.setWatermarkText( QString::null );

    KDReports::Header& header = report.header( KDReports::OddPages );
    QPixmap kdab( ":/kdab_small.jpg" );
    // add a border around the pixmap, mostly for debugging
    //QPainter painter( &kdab );
    //painter.drawRect( 0, 0, kdab.width() - 1, kdab.height() - 1 );
    KDReports::ImageElement imageElement( kdab );
    // The image size can be set in mm or in percent of the page width (without margins)
    // imageElement.setWidth( 50 ); // mm
    imageElement.setWidth( 40, KDReports::Percent );

    header.addElement( imageElement );
    header.addVariable( KDReports::PageNumber );
    header.addInlineElement( KDReports::TextElement( " / " ) );
    header.addVariable( KDReports::PageCount );
    header.addInlineElement( KDReports::TextElement( ", Date: " ) );
    header.addVariable( KDReports::TextDate );
    header.addInlineElement( KDReports::TextElement( ", Time: " ) );
    header.addVariable( KDReports::TextTime );

    KDReports::Header& evenPagesHeader = report.header( KDReports::EvenPages );
    evenPagesHeader.addElement( imageElement );
    evenPagesHeader.addInlineElement( KDReports::TextElement( "Even pages header: " ) );
    evenPagesHeader.addVariable( KDReports::PageNumber );
    evenPagesHeader.addInlineElement( KDReports::TextElement( " / " ) );
    evenPagesHeader.addVariable( KDReports::PageCount );

    KDReports::Footer& footer = report.footer();
    KDReports::TextElement companyAddressElement( QString::fromUtf8( "Klarälvdalens Datakonsult AB\nRysktorp\nSE-68392 Hagfors\nSweden" ) );
    footer.addElement( companyAddressElement, Qt::AlignRight );

    KDReports::TextElement titleElement;
    titleElement << "Price list example";
    titleElement.setPointSize( 18 );
    report.addElement( titleElement, Qt::AlignHCenter );

    report.addVerticalSpacing( 10 ); // 1 cm

    const QColor titleElementColor( 204, 204, 255 );

    // A text element with the title above a table
    // Note that the background color is not just behind the text (as setBackground() would do),
    // but behind the whole paragraph, up until the right margin of the page.
    KDReports::TextElement tableTitleElement( "Network Peripherals" );
    tableTitleElement.setBold( true );
    report.addElement( tableTitleElement, Qt::AlignLeft, titleElementColor );

    TableModel table1;
    table1.setDataHasVerticalHeaders( false );
    table1.loadFromCSV( ":/table1" );
    // Q_ASSERT( table1.headerData( 0, Qt::Vertical ).toString() == "10/100 Mbps switch" );
    //Q_ASSERT( table1.data( table1.index( 0, 0 ) ).toString() == "Product" );
    KDReports::AutoTableElement autoTableElement1( &table1 );
    autoTableElement1.setWidth( 100, KDReports::Percent );
    report.addElement( autoTableElement1 );

    report.addVerticalSpacing( 5 );

    // Notice how elements can be copied and modified
    // This way, we use the same font attributes for all title elements
    KDReports::TextElement tableTitleElement2 = tableTitleElement;
    tableTitleElement2.setText( "Printer Cartridges" );
    report.addElement( tableTitleElement2, Qt::AlignLeft, titleElementColor );

    TableModel table2;
    table2.setDataHasVerticalHeaders( false );
    table2.loadFromCSV( ":/table2" );
    KDReports::AutoTableElement autoTableElement2( &table2 );
    autoTableElement2.setWidth( 100, KDReports::Percent );
    report.addElement( autoTableElement2 );

    // and again, on the second page
    report.addPageBreak();
    report.addElement( tableTitleElement, Qt::AlignLeft, titleElementColor );
    report.addElement( autoTableElement1 );
    report.addVerticalSpacing( 5 );
    report.addElement( tableTitleElement2, Qt::AlignLeft, titleElementColor );
    report.addElement( autoTableElement2 );

    report.addVerticalSpacing( 5 );

    // ===========================================================================
    // Another kind of table, where the data comes from code and not from a model:
    // ===========================================================================
    KDReports::TableElement tableElement;
    tableElement.setHeaderRowCount( 2 );
    tableElement.setPadding( 3 );
    QColor headerColor( "#DADADA" );
    // Merged header in row 0
    KDReports::Cell& topHeader = tableElement.cell( 0, 0 );
    topHeader.setColumnSpan( 2 );
    topHeader.setBackground( headerColor );
    topHeader.addElement( KDReports::TextElement( "TableElement example" ), Qt::AlignHCenter );

    // Normal header in row 1
    KDReports::Cell& headerCell1 = tableElement.cell( 1, 0 );
    headerCell1.setBackground( headerColor );
    // This would look better if centered vertically. This feature is only available since
    // Qt-4.3 though (QTextCharFormat::AlignMiddle)
    QPixmap systemPixmap( ":/system.png" );
    headerCell1.addElement( KDReports::ImageElement( systemPixmap ) );
    headerCell1.addInlineElement( KDReports::TextElement( " Item" ) );
    KDReports::Cell& headerCell2 = tableElement.cell( 1, 1 );
    headerCell2.setBackground( headerColor );
    KDReports::TextElement expected( "Expected" );
    expected.setItalic( true );
    expected.setBackground( QColor("#999999") ); // note that this background only applies to this element
    headerCell2.addElement( expected );
    headerCell2.addInlineElement( KDReports::TextElement( " shipping time" ) );

    // Data in rows 2 and 3
    tableElement.cell( 2, 0 ).addElement( KDReports::TextElement( "Network Peripherals" ) );
    tableElement.cell( 2, 1 ).addElement( KDReports::TextElement( "4 days" ) );
    tableElement.cell( 3, 0 ).addElement( KDReports::TextElement( "Printer Cartridges" ) );
    tableElement.cell( 3, 1 ).addElement( KDReports::TextElement( "3 days" ) );

    report.addElement( tableElement );

    KDReports::PreviewDialog preview( &report );
    return preview.exec();
}
Пример #6
0
static void test_invert(skiatest::Reporter* reporter) {
    SkMatrix44 inverse(SkMatrix44::kUninitialized_Constructor);
    double inverseData[16];

    SkMatrix44 identity(SkMatrix44::kIdentity_Constructor);
    identity.invert(&inverse);
    inverse.asRowMajord(inverseData);
    assert16<double>(reporter, inverseData,
                     1, 0, 0, 0,
                     0, 1, 0, 0,
                     0, 0, 1, 0,
                     0, 0, 0, 1);

    SkMatrix44 translation(SkMatrix44::kUninitialized_Constructor);
    translation.setTranslate(2, 3, 4);
    translation.invert(&inverse);
    inverse.asRowMajord(inverseData);
    assert16<double>(reporter, inverseData,
                     1, 0, 0, -2,
                     0, 1, 0, -3,
                     0, 0, 1, -4,
                     0, 0, 0, 1);

    SkMatrix44 scale(SkMatrix44::kUninitialized_Constructor);
    scale.setScale(2, 4, 8);
    scale.invert(&inverse);
    inverse.asRowMajord(inverseData);
    assert16<double>(reporter, inverseData,
                     0.5, 0,    0,     0,
                     0,   0.25, 0,     0,
                     0,   0,    0.125, 0,
                     0,   0,    0,     1);

    SkMatrix44 scaleTranslation(SkMatrix44::kUninitialized_Constructor);
    scaleTranslation.setScale(32, 128, 1024);
    scaleTranslation.preTranslate(2, 3, 4);
    scaleTranslation.invert(&inverse);
    inverse.asRowMajord(inverseData);
    assert16<double>(reporter, inverseData,
                     0.03125,  0,          0,            -2,
                     0,        0.0078125,  0,            -3,
                     0,        0,          0.0009765625, -4,
                     0,        0,          0,             1);

    SkMatrix44 rotation(SkMatrix44::kUninitialized_Constructor);
    rotation.setRotateDegreesAbout(0, 0, 1, 90);
    rotation.invert(&inverse);
    SkMatrix44 expected(SkMatrix44::kUninitialized_Constructor);
    double expectedInverseRotation[16] =
    {   0,  1, 0, 0,
        -1, 0, 0, 0,
        0,  0, 1, 0,
        0,  0, 0, 1
    };
    expected.setRowMajord(expectedInverseRotation);
    REPORTER_ASSERT(reporter, nearly_equal(expected, inverse));

    SkMatrix44 affine(SkMatrix44::kUninitialized_Constructor);
    affine.setRotateDegreesAbout(0, 0, 1, 90);
    affine.preScale(10, 20, 100);
    affine.preTranslate(2, 3, 4);
    affine.invert(&inverse);
    double expectedInverseAffine[16] =
    {   0,    0.1,  0,   -2,
        -0.05, 0,   0,   -3,
        0,     0,  0.01, -4,
        0,     0,   0,   1
    };
    expected.setRowMajord(expectedInverseAffine);
    REPORTER_ASSERT(reporter, nearly_equal(expected, inverse));

    SkMatrix44 perspective(SkMatrix44::kIdentity_Constructor);
    perspective.setDouble(3, 2, 1.0);
    perspective.invert(&inverse);
    double expectedInversePerspective[16] =
    {   1, 0,  0, 0,
        0, 1,  0, 0,
        0, 0,  1, 0,
        0, 0, -1, 1
    };
    expected.setRowMajord(expectedInversePerspective);
    REPORTER_ASSERT(reporter, nearly_equal(expected, inverse));

    SkMatrix44 affineAndPerspective(SkMatrix44::kIdentity_Constructor);
    affineAndPerspective.setDouble(3, 2, 1.0);
    affineAndPerspective.preScale(10, 20, 100);
    affineAndPerspective.preTranslate(2, 3, 4);
    affineAndPerspective.invert(&inverse);
    double expectedInverseAffineAndPerspective[16] =
    {   0.1, 0,    2,   -2,
        0,  0.05,  3,   -3,
        0,   0,   4.01, -4,
        0,   0,   -1,    1
    };
    expected.setRowMajord(expectedInverseAffineAndPerspective);
    REPORTER_ASSERT(reporter, nearly_equal(expected, inverse));

    SkMatrix44 tinyScale(SkMatrix44::kIdentity_Constructor);
    tinyScale.setDouble(0, 0, 1e-39);
    REPORTER_ASSERT(reporter, tinyScale.getType() == SkMatrix44::kScale_Mask);
    REPORTER_ASSERT(reporter, !tinyScale.invert(nullptr));
    REPORTER_ASSERT(reporter, !tinyScale.invert(&inverse));

    SkMatrix44 tinyScaleTranslate(SkMatrix44::kIdentity_Constructor);
    tinyScaleTranslate.setDouble(0, 0, 1e-38);
    REPORTER_ASSERT(reporter, tinyScaleTranslate.invert(nullptr));
    tinyScaleTranslate.setDouble(0, 3, 10);
    REPORTER_ASSERT(
        reporter, tinyScaleTranslate.getType() ==
        (SkMatrix44::kScale_Mask | SkMatrix44::kTranslate_Mask));
    REPORTER_ASSERT(reporter, !tinyScaleTranslate.invert(nullptr));
    REPORTER_ASSERT(reporter, !tinyScaleTranslate.invert(&inverse));

    SkMatrix44 tinyScalePerspective(SkMatrix44::kIdentity_Constructor);
    tinyScalePerspective.setDouble(0, 0, 1e-39);
    tinyScalePerspective.setDouble(3, 2, -1);
    REPORTER_ASSERT(reporter, (tinyScalePerspective.getType() &
                               SkMatrix44::kPerspective_Mask) ==
                    SkMatrix44::kPerspective_Mask);
    REPORTER_ASSERT(reporter, !tinyScalePerspective.invert(nullptr));
    REPORTER_ASSERT(reporter, !tinyScalePerspective.invert(&inverse));
}
Пример #7
0
void RunTests()
{
	std::string output;

	CoreParameter coreParam;
	coreParam.cpuCore = g_Config.bJit ? CPU_JIT : CPU_INTERPRETER;
	coreParam.gpuCore = GPU_GLES;
	coreParam.enableSound = g_Config.bEnableSound;
	coreParam.mountIso = "";
	coreParam.startPaused = false;
	coreParam.enableDebugging = false;
	coreParam.printfEmuLog = false;
	coreParam.headLess = false;
	coreParam.renderWidth = 480;
	coreParam.renderHeight = 272;
	coreParam.pixelWidth = 480;
	coreParam.pixelHeight = 272;
	coreParam.collectEmuLog = &output;
	coreParam.unthrottle = true;
	coreParam.updateRecent = false;

#ifdef IOS
	std::string baseDirectory = g_Config.flashDirectory + "../";
#else
	std::string baseDirectory = g_Config.memCardDirectory;
#endif

	// Never report from tests.
	std::string savedReportHost = g_Config.sReportHost;
	g_Config.sReportHost = "";

	for (size_t i = 0; i < ARRAY_SIZE(testsToRun); i++) {
		const char *testName = testsToRun[i];
		coreParam.fileToStart = baseDirectory + "pspautotests/tests/" + testName + ".prx";
		std::string expectedFile = baseDirectory + "pspautotests/tests/" + testName + ".expected";

		ILOG("Preparing to execute %s", testName)
		std::string error_string;
		output = "";
		if (!PSP_Init(coreParam, &error_string)) {
			ELOG("Failed to init unittest %s : %s", testsToRun[i], error_string.c_str());
			return;
		}

		// Run the emu until the test exits
		while (true) {
			int blockTicks = usToCycles(1000000 / 10);
			while (coreState == CORE_RUNNING) {
				u64 nowTicks = CoreTiming::GetTicks();
				mipsr4k.RunLoopUntil(nowTicks + blockTicks);
			}
			// Hopefully coreState is now CORE_NEXTFRAME
			if (coreState == CORE_NEXTFRAME) {
				// set back to running for the next frame
				coreState = CORE_RUNNING;
			} else if (coreState == CORE_POWERDOWN)	{
				ILOG("Finished running test %s", testName);
				break;
			}
		}
	
		std::ifstream expected(expectedFile.c_str(), std::ios_base::in);
		if (!expected) {
			ELOG("Error opening expectedFile %s", expectedFile.c_str());
			return;
		}

		std::istringstream logoutput(output);

		int line = 0;
		while (true) {
			++line;
			std::string e, o;
			std::getline(expected, e);
			std::getline(logoutput, o);
			// Remove stray returns
			while (e[e.size()-1] == 10 || e[e.size()-1] == 13)
				e = e.substr(0, e.size() - 1);  // For some reason we get some extra character
			while (o[o.size()-1] == 10 || o[o.size()-1] == 13)
				o = o.substr(0, o.size() - 1);  // For some reason we get some extra character
			if (e != o) {
				ELOG("DIFF on line %i!", line);
				ILOG("O: %s", o.c_str());
				ILOG("E: %s", e.c_str());
			}
			if (expected.eof()) {
				break;
			}
			if (logoutput.eof()) {
				break;
			}
		}
		PSP_Shutdown();
	}
	glstate.Restore();
	glstate.viewport.set(0,0,pixel_xres,pixel_yres);

	g_Config.sReportHost = savedReportHost;
}
Пример #8
0
int main(){
	expected("",		HEARTBEAT_CONTROLLER);
	expected("/",		HEARTBEAT_CONTROLLER);
	expected("/api",	HEARTBEAT_CONTROLLER);
	expected("/api/",	HEARTBEAT_CONTROLLER);
	expected("/api/comments",	COMMENTS_CONTROLLER);
	expected("/api/comments/",	COMMENTS_CONTROLLER);
	expected("/api/comments?type=needs",	COMMENTS_CONTROLLER);
	expected("/api/heatmap",	HEATMAP_CONTROLLER);
	expected("/api/heatmap/",	HEATMAP_CONTROLLER);
	expected("/api/heatmap?latDegrees=23.45&latOffset=2.0&lonDegrees=40.3&lonOffset=5.12",	HEATMAP_CONTROLLER);
	expected("/api/pins",	MARKER_CONTROLLER);
	expected("/api/pins/",	MARKER_CONTROLLER);
	expected("/api/pins?id=32424j23k4j2kldsafasdf",	MARKER_CONTROLLER);
	expected("/api/debug",	REPORT_CONTROLLER);
	expected("/api/debug/",	REPORT_CONTROLLER);
	expected("/api/debug/?origin=6f3d78c8ca1d63645015d6fa2d975902348d585f954efd0e8ecca4f362c697d9&hash=aed60d05a1bd",	REPORT_CONTROLLER);
	expected("/api/de",		INVALID_CONTROLLER);
	expected("/api/asadssd",INVALID_CONTROLLER);
	expected("/ap",			INVALID_CONTROLLER);
	expected("/aasspi/asd",	INVALID_CONTROLLER);

	/* Be sure to flush before closing the lid on the i/o */
	fflush(stdout);
	fflush(stderr);
	close(STDIN_FILENO);
	close(STDOUT_FILENO);
	close(STDERR_FILENO);
	return 0;
}
Пример #9
0
void testImplementationReal()
{
    typedef short_vec<CARGO, ARITY> ShortVec;
    int numElements = ShortVec::ARITY * 10;

    std::vector<CARGO> vec1(numElements);
    std::vector<CARGO> vec2(numElements, 4711);

    // init vec1:
    for (int i = 0; i < numElements; ++i) {
        vec1[i] = i + 0.1;
    }

    // test default c-tor:
    for (int i = 0; i < numElements; ++i) {
        BOOST_TEST(4711 == vec2[i]);
    }
    for (int i = 0; i < (numElements - ShortVec::ARITY + 1); i += ShortVec::ARITY) {
        ShortVec v;
        &vec2[i] << v;
    }
    for (int i = 0; i < numElements; ++i) {
        BOOST_TEST(0 == vec2[i]);
    }

    // tests vector load/store:
    for (int i = 0; i < (numElements - ShortVec::ARITY + 1); i += ShortVec::ARITY) {
        ShortVec v = &vec1[i];
        &vec2[i] << v;
    }
    for (int i = 0; i < numElements; ++i) {
        TEST_REAL((i + 0.1), vec2[i]);
    }

    // tests scalar load, vector add:
    ShortVec w = vec1[0];

    for (int i = 0; i < (numElements - ShortVec::ARITY + 1); i += ShortVec::ARITY) {
        ShortVec v = &vec1[i];
        &vec2[i] << (v + w);
    }
    for (int i = 0; i < numElements; ++i) {
        TEST_REAL((i + 0.2), vec2[i]);
    }

    // tests +=
    for (int i = 0; i < (numElements - ShortVec::ARITY + 1); i += ShortVec::ARITY) {
        ShortVec v = &vec1[i];
        ShortVec w = &vec2[i];
        v += w;
        &vec2[i] << v;
    }
    for (int i = 0; i < numElements; ++i) {
        TEST_REAL((2 * i + 0.3), vec2[i]);
    }

    // test -
    for (int i = 0; i < (numElements - ShortVec::ARITY + 1); i += ShortVec::ARITY) {
        ShortVec v = &vec1[i];
        ShortVec w = &vec2[i];
        &vec2[i] << (v - w);
    }
    for (int i = 0; i < numElements; ++i) {
        TEST_REAL((-i - 0.2), vec2[i]);
    }

    // test -=
    for (int i = 0; i < (numElements - ShortVec::ARITY + 1); i += ShortVec::ARITY) {
        ShortVec v = &vec1[i];
        ShortVec w = &vec2[i];
        v -= w;
        &vec2[i] << v;
    }
    for (int i = 0; i < numElements; ++i) {
        TEST_REAL((2 * i + 0.3), vec2[i]);
    }

    // test *
    for (int i = 0; i < (numElements - ShortVec::ARITY + 1); i += ShortVec::ARITY) {
        ShortVec v = &vec1[i];
        ShortVec w = &vec2[i];
        &vec2[i] << (v * w);
    }
    for (int i = 0; i < numElements; ++i) {
        double reference = ((i + 0.1) * (2 * i + 0.3));
        TEST_REAL(reference, vec2[i]);
    }

    // test *=
    for (int i = 0; i < numElements; ++i) {
        vec2[i] = i + 0.2;
    }
    for (int i = 0; i < (numElements - ShortVec::ARITY + 1); i += ShortVec::ARITY) {
        ShortVec v = &vec1[i];
        ShortVec w = &vec2[i];
        v *= w;
        &vec2[i] << v;
    }
    for (int i = 0; i < numElements; ++i) {
        TEST_REAL((i + 0.1) * (i + 0.2), vec2[i]);
    }

    // test /
    for (int i = 0; i < numElements; ++i) {
        vec2[i] = i + 0.2;
    }
    for (int i = 0; i < (numElements - ShortVec::ARITY + 1); i += ShortVec::ARITY) {
        ShortVec v = &vec1[i];
        ShortVec w = &vec2[i];
        &vec2[i] << (v / w);
    }
    for (int i = 0; i < numElements; ++i) {
        // accept lower accuracy for estimated division, really low
        // accuracy accepted because of results from ARM NEON:
        TEST_REAL_ACCURACY((i + 0.1) / (i + 0.2), vec2[i], 0.0025);
    }

    // test /=
    for (int i = 0; i < numElements; ++i) {
        vec2[i] = i + 0.2;
    }
    for (int i = 0; i < (numElements - ShortVec::ARITY + 1); i += ShortVec::ARITY) {
        ShortVec v = &vec1[i];
        ShortVec w = &vec2[i];
        v /= w;
        &vec2[i] << v;
    }
    for (int i = 0; i < numElements; ++i) {
        // here, too, lower accuracy is acceptable. As with divisions,
        // ARM NEON costs us an order of magnitude here compared to X86.
        TEST_REAL_ACCURACY((i + 0.1) / (i + 0.2), vec2[i], 0.0025);
    }

    // test sqrt()
    for (int i = 0; i < (numElements - ShortVec::ARITY + 1); i += ShortVec::ARITY) {
        ShortVec v = &vec1[i];
        &vec2[i] << sqrt(v);
    }
    for (int i = 0; i < numElements; ++i) {
        // lower accuracy, mainly for ARM NEON
        TEST_REAL_ACCURACY(std::sqrt(double(i + 0.1)), vec2[i], 0.0025);
    }

    // test "/ sqrt()"
    for (int i = 0; i < numElements; ++i) {
        vec2[i] = i + 0.2;
    }
    for (int i = 0; i < (numElements - ShortVec::ARITY + 1); i += ShortVec::ARITY) {
        ShortVec v = &vec1[i];
        ShortVec w = &vec2[i];
        &vec2[i] << w / sqrt(v);
    }
    for (int i = 0; i < numElements; ++i) {
        // the expression "foo / sqrt(bar)" will again result in an
        // estimated result for single precision floats, so lower accuracy is acceptable:
        TEST_REAL_ACCURACY((i + 0.2) / std::sqrt(double(i + 0.1)), vec2[i], 0.0035);
    }

    // test string conversion
    for (int i = 0; i < ShortVec::ARITY; ++i) {
        vec1[i] = i + 0.1;
    }
    ShortVec v(&vec1[0]);
    std::ostringstream buf1;
    buf1 << v;

    std::ostringstream buf2;
    buf2 << "[";
    for (int i = 0; i < (ShortVec::ARITY - 1); ++i) {
        buf2 << (i + 0.1) << ", ";
    }
    buf2 << (ShortVec::ARITY - 1 + 0.1) << "]";

    BOOST_TEST(buf1.str() == buf2.str());

    // test gather
    {
        CARGO array[ARITY * 10];
        std::vector<int, aligned_allocator<int, 64> > indices(ARITY);
        CARGO actual[ARITY];
        CARGO expected[ARITY];
        std::memset(array, '\0', sizeof(CARGO) * ARITY * 10);

        for (int i = 0; i < ARITY * 10; ++i) {
            if (i % 10 == 0) {
                array[i] = i * 0.75;
            }
        }

        for (int i = 0; i < ARITY; ++i) {
            indices[i] = i * 10;
            expected[i] = (i * 10) * 0.75;
        }

        ShortVec vec;
        vec.gather(array, &indices[0]);
        actual << vec;

        for (int i = 0; i < ARITY; ++i) {
            TEST_REAL_ACCURACY(actual[i], expected[i], 0.001);
        }
    }

#ifdef LIBFLATARRAY_WITH_CPP14
    // test gather via initializer_list
    {
        CARGO actual1[ARITY];
        CARGO actual2[ARITY];
        CARGO expected[ARITY];
        for (int i = 0; i < ARITY; ++i) {
            expected[i] = (i * 10) * 0.75;
        }

        // max: 32
        ShortVec vec1 = { 0.0, 7.5, 15.0, 22.50, 30.0, 37.5, 45.0, 52.5,
                          60.0, 67.5, 75.0, 82.5, 90.0, 97.5, 105.0, 112.5,
                          120.0, 127.5, 135.0, 142.5, 150.0, 157.5, 165.0, 172.5,
                          180.0, 187.5, 195.0, 202.5, 210.0, 217.5, 225.0, 232.5 };
        ShortVec vec2;
        vec2 = { 0.0, 7.5, 15.0, 22.50, 30.0, 37.5, 45.0, 52.5,
                 60.0, 67.5, 75.0, 82.5, 90.0, 97.5, 105.0, 112.5,
                 120.0, 127.5, 135.0, 142.5, 150.0, 157.5, 165.0, 172.5,
                 180.0, 187.5, 195.0, 202.5, 210.0, 217.5, 225.0, 232.5 };
        actual1 << vec1;
        actual2 << vec2;
        for (int i = 0; i < ARITY; ++i) {
            TEST_REAL_ACCURACY(actual1[i], expected[i], 0.001);
            TEST_REAL_ACCURACY(actual2[i], expected[i], 0.001);
        }
    }
#endif

    // test scatter
    {
        ShortVec vec;
        CARGO array[ARITY * 10];
        CARGO expected[ARITY * 10];
        std::vector<int, aligned_allocator<int, 64> > indices(ARITY);
        std::memset(array,    '\0', sizeof(CARGO) * ARITY * 10);
        std::memset(expected, '\0', sizeof(CARGO) * ARITY * 10);
        for (int i = 0; i < ARITY * 10; ++i) {
            if (i % 10 == 0) {
                expected[i] = i * 0.75;
            }
        }
        for (int i = 0; i < ARITY; ++i) {
            indices[i] = i * 10;
        }

        vec.gather(expected, &indices[0]);
        vec.scatter(array, &indices[0]);
        for (int i = 0; i < ARITY * 10; ++i) {
            TEST_REAL_ACCURACY(array[i], expected[i], 0.001);
        }
    }

    // test non temporal stores
    {
        std::vector<CARGO, aligned_allocator<CARGO, 64> > array(ARITY);
        std::vector<CARGO, aligned_allocator<CARGO, 64> > expected(ARITY);

        for (int i = 0; i < ARITY; ++i) {
            expected[i] = 5.0;
        }
        ShortVec v1 = 5.0;
        v1.store_nt(&array[0]);
        for (int i = 0; i < ARITY; ++i) {
            TEST_REAL_ACCURACY(array[i], expected[i], 0.001);
        }

        for (int i = 0; i < ARITY; ++i) {
            expected[i] = i + 0.1;
        }
        ShortVec v2 = &expected[0];
        v2.store_nt(&array[0]);
        for (int i = 0; i < ARITY; ++i) {
            TEST_REAL_ACCURACY(array[i], expected[i], 0.001);
        }
    }

    // test aligned stores
    {
        std::vector<CARGO, aligned_allocator<CARGO, 64> > array(ARITY);
        std::vector<CARGO, aligned_allocator<CARGO, 64> > expected(ARITY);

        for (int i = 0; i < ARITY; ++i) {
            expected[i] = 5.0;
        }
        ShortVec v1 = 5.0;
        v1.store_aligned(&array[0]);
        for (int i = 0; i < ARITY; ++i) {
            TEST_REAL_ACCURACY(array[i], expected[i], 0.001);
        }

        for (int i = 0; i < ARITY; ++i) {
            expected[i] = i + 0.1;
        }
        ShortVec v2 = &expected[0];
        v2.store_aligned(&array[0]);
        for (int i = 0; i < ARITY; ++i) {
            TEST_REAL_ACCURACY(array[i], expected[i], 0.001);
        }
    }

    // test aligned loads
    {
        std::vector<CARGO, aligned_allocator<CARGO, 64> > array(ARITY);
        std::vector<CARGO, aligned_allocator<CARGO, 64> > expected(ARITY);

        for (int i = 0; i < ARITY; ++i) {
            array[i]    = i + 0.1;
            expected[i] = 0;
        }
        ShortVec v1;
        v1.load_aligned(&array[0]);
        v1.store(&expected[0]);
        for (int i = 0; i < ARITY; ++i) {
            TEST_REAL_ACCURACY(array[i], expected[i], 0.001);
        }
    }
}
Пример #10
0
void Win32DateTimeTest::testLocales(TestLog *log)
{
    SYSTEMTIME winNow;
    UDate icuNow = 0;
    SYSTEMTIME st;
    FILETIME ft;
    UnicodeString zoneID;
    const TimeZone *tz = TimeZone::createDefault();
    TIME_ZONE_INFORMATION tzi;

    tz->getID(zoneID);
    if (! uprv_getWindowsTimeZoneInfo(&tzi, zoneID.getBuffer(), zoneID.length())) {
        UBool found = FALSE;
        int32_t ec = TimeZone::countEquivalentIDs(zoneID);

        for (int z = 0; z < ec; z += 1) {
            UnicodeString equiv = TimeZone::getEquivalentID(zoneID, z);

            if (found = uprv_getWindowsTimeZoneInfo(&tzi, equiv.getBuffer(), equiv.length())) {
                break;
            }
        }

        if (! found) {
            GetTimeZoneInformation(&tzi);
        }
    }

    GetSystemTime(&st);
    SystemTimeToFileTime(&st, &ft);
    SystemTimeToTzSpecificLocalTime(&tzi, &st, &winNow);

    int64_t wftNow = ((int64_t) ft.dwHighDateTime << 32) + ft.dwLowDateTime;
    UErrorCode status = U_ZERO_ERROR;

    int64_t udtsNow = utmscale_fromInt64(wftNow, UDTS_WINDOWS_FILE_TIME, &status);

    icuNow = (UDate) utmscale_toInt64(udtsNow, UDTS_ICU4C_TIME, &status);

    int32_t lcidCount = 0;
    Win32Utilities::LCIDRecord *lcidRecords = Win32Utilities::getLocales(lcidCount);

    for(int i = 0; i < lcidCount; i += 1) {
        UErrorCode status = U_ZERO_ERROR;
        WCHAR longDateFormat[81], longTimeFormat[81], wdBuffer[256], wtBuffer[256];
        int32_t calType = 0;

        // NULL localeID means ICU didn't recognize this locale
        if (lcidRecords[i].localeID == NULL) {
            continue;
        }

        GetLocaleInfoW(lcidRecords[i].lcid, LOCALE_SLONGDATE,   longDateFormat, 81);
        GetLocaleInfoW(lcidRecords[i].lcid, LOCALE_STIMEFORMAT, longTimeFormat, 81);
        GetLocaleInfoW(lcidRecords[i].lcid, LOCALE_RETURN_NUMBER|LOCALE_ICALENDARTYPE, (LPWSTR) calType, sizeof(int32_t));

        char localeID[64];

        uprv_strcpy(localeID, lcidRecords[i].localeID);
        uprv_strcat(localeID, getCalendarType(calType));

        UnicodeString ubBuffer, udBuffer, utBuffer;
        Locale ulocale(localeID);
        int32_t wdLength, wtLength;

        wdLength = GetDateFormatW(lcidRecords[i].lcid, DATE_LONGDATE, &winNow, NULL, wdBuffer, UPRV_LENGTHOF(wdBuffer));
        wtLength = GetTimeFormatW(lcidRecords[i].lcid, 0, &winNow, NULL, wtBuffer, UPRV_LENGTHOF(wtBuffer));

        if (uprv_strchr(localeID, '@') > 0) {
            uprv_strcat(localeID, ";");
        } else {
            uprv_strcat(localeID, "@");
        }

        uprv_strcat(localeID, "compat=host");

        Locale wlocale(localeID);
        DateFormat *wbf = DateFormat::createDateTimeInstance(DateFormat::kFull, DateFormat::kFull, wlocale);
        DateFormat *wdf = DateFormat::createDateInstance(DateFormat::kFull, wlocale);
        DateFormat *wtf = DateFormat::createTimeInstance(DateFormat::kFull, wlocale);

        wbf->format(icuNow, ubBuffer);
        wdf->format(icuNow, udBuffer);
        wtf->format(icuNow, utBuffer);

        if (ubBuffer.indexOf(wdBuffer, wdLength - 1, 0) < 0) {
            UnicodeString baseName(wlocale.getBaseName());
            UnicodeString expected(wdBuffer);

            log->errln("DateTime format error for locale " + baseName + ": expected date \"" + expected +
                       "\" got \"" + ubBuffer + "\"");
        }

        if (ubBuffer.indexOf(wtBuffer, wtLength - 1, 0) < 0) {
            UnicodeString baseName(wlocale.getBaseName());
            UnicodeString expected(wtBuffer);

            log->errln("DateTime format error for locale " + baseName + ": expected time \"" + expected +
                       "\" got \"" + ubBuffer + "\"");
        }

        if (udBuffer.compare(wdBuffer) != 0) {
            UnicodeString baseName(wlocale.getBaseName());
            UnicodeString expected(wdBuffer);

            log->errln("Date format error for locale " + baseName + ": expected \"" + expected +
                       "\" got \"" + udBuffer + "\"");
        }

        if (utBuffer.compare(wtBuffer) != 0) {
            UnicodeString baseName(wlocale.getBaseName());
            UnicodeString expected(wtBuffer);

            log->errln("Time format error for locale " + baseName + ": expected \"" + expected +
                       "\" got \"" + utBuffer + "\"");
        }
        delete wbf;
        delete wdf;
        delete wtf;
    }

    Win32Utilities::freeLocales(lcidRecords);
    delete tz;
}
Пример #11
0
int main(int argc, char* argv[])
{
    if (argc != 3) {
      std::cout << "usage: " << argv[0] << " hash file " << std::endl;
      std::cout << "       check the MD5 hash of a file" << std::endl;
      std::cout << "       Adobe Source Libraries v" << ADOBE_VERSION_MAJOR
                << "." << ADOBE_VERSION_MINOR << "." << ADOBE_VERSION_SUBMINOR << std::endl;
      std::cout << "       Boost v" << BOOST_VERSION / 100000 << "." << BOOST_VERSION / 100 % 1000 
                << "." << BOOST_VERSION % 100 << std::endl;
      
      return 1;
    }

    bool success = false;

    try
    {
      adobe::md5_t m;
      boost::filesystem::path file_path(argv[2], boost::filesystem::native);
      boost::filesystem::ifstream stream(file_path, std::ios::binary | std::ios::in);

        while (stream.good())
        {
            boost::array<std::ifstream::char_type, 256*1024> buffer;

            stream.read(&buffer[0], static_cast<std::streamsize>(buffer.size()));

            std::streamsize gcount(stream.gcount());

            if (gcount > 0) m.update(&buffer[0], static_cast<std::size_t>(gcount));
        }

        adobe::md5_t::digest_t              hash(m.final());
        adobe::md5_t::digest_t::iterator    first(hash.begin());
        adobe::md5_t::digest_t::iterator    last(hash.end());

        std::string actual;
        std::ostringstream oss(actual);
        for(; first != last; ++first){
            oss.width(2);
            oss << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(*first);
        }
        

        std::string expected(argv[1]);
        std::string::iterator e(expected.begin());
        success = oss.str() == expected;
        if(!success)
            std::cout << "Expected: " << expected
                      << " actual: " << oss.str() << std::endl;
        
    }

    catch( const std::exception& error )
        { 
            std::cerr << "Exception: " << error.what() << std::endl; 
        }
    catch( ... )
        { 
            std::cerr << "Unknown exception" << std::endl; 
        }
    return success ? 0 : 1;
}
Пример #12
0
/*==============================================================================
 * FUNCTION:        LoaderTest::testWinLoad
 * OVERVIEW:        Test loading Windows programs
 *============================================================================*/
void LoaderTest::testWinLoad ()
{
    std::ostringstream ost;

#if 0 /* FIXME: these tests should use non-proprietary programs */
    // Load Windows program calc.exe
    BinaryFileFactory bff;
    BinaryFile* pBF = bff.Load(CALC_WINDOWS);
    CPPUNIT_ASSERT(pBF != NULL);
    int n;
    SectionInfo* si;
    n = pBF->GetNumSections();
    ost << "Number of sections = " << std::dec << n << "\r\n";
    for (int i=0; i < n; i++)
        {
            si = pBF->GetSectionInfo(i);
            ost << si->pSectionName << "\t";
        }

    // Note: the string below needs to have embedded tabs. Edit with caution!
    std::string expected("Number of sections = 5\r\n"
                         ".text	.rdata	.data	.rsrc	.reloc	");
    std::string actual(ost.str());
    CPPUNIT_ASSERT_EQUAL(expected, actual);

    ADDRESS addr = pBF->GetMainEntryPoint();
    CPPUNIT_ASSERT(addr != NO_ADDRESS);

    // Test symbol table (imports)
    const char* s = pBF->SymbolByAddress(0x1292060U);
    if (s == 0)
        actual = "<not found>";
    else
        actual = std::string(s);
    expected = std::string("SetEvent");
    CPPUNIT_ASSERT_EQUAL(expected, actual);

    ADDRESS a = pBF->GetAddressByName("SetEvent");
    ADDRESS expectedAddr = 0x1292060;
    CPPUNIT_ASSERT_EQUAL(expectedAddr, a);
    pBF->UnLoad();
    bff.UnLoad();

    // Test loading the "new style" exes, as found in winXP etc
    pBF = bff.Load(CALC_WINXP);
    CPPUNIT_ASSERT(pBF != NULL);
    addr = pBF->GetMainEntryPoint();
    std::ostringstream ost1;
    ost1 << std::hex << addr;
    actual = ost1.str();
    expected = "1001f51";
    CPPUNIT_ASSERT_EQUAL(expected, actual);
    pBF->UnLoad();
    bff.UnLoad();

    // Test loading the calc.exe found in Windows 2000 (more NT based)
    pBF = bff.Load(CALC_WIN2000);
    CPPUNIT_ASSERT(pBF != NULL);
    expected = "1001680";
    addr = pBF->GetMainEntryPoint();
    std::ostringstream ost2;
    ost2 << std::hex << addr;
    actual = ost2.str();
    CPPUNIT_ASSERT_EQUAL(expected, actual);
    pBF->UnLoad();
    bff.UnLoad();

    // Test loading the lpq.exe program - console mode PE file
    pBF = bff.Load(LPQ_WINDOWS);
    CPPUNIT_ASSERT(pBF != NULL);
    addr = pBF->GetMainEntryPoint();
    std::ostringstream ost3;
    ost3 << std::hex << addr;
    actual = ost3.str();
    expected = "18c1000";
    CPPUNIT_ASSERT_EQUAL(expected, actual);
    pBF->UnLoad();
    bff.UnLoad();
#endif

    // Borland
    BinaryFileFactory bff;
    BinaryFile* pBF = bff.Load(SWITCH_BORLAND);
    CPPUNIT_ASSERT(pBF != NULL);
    ADDRESS addr = pBF->GetMainEntryPoint();
    std::ostringstream ost4;
    ost4 << std::hex << addr;
    std::string actual(ost4.str());
    std::string expected("401150");
    CPPUNIT_ASSERT_EQUAL(expected, actual);
    pBF->UnLoad();
    bff.UnLoad();
}
    void a(std::initializer_list<int> list) {
        std::vector<int> expected(list);

//        EXPECT_TRUE(ArraysMatch(expected, vec));
        EXPECT_THAT(vec, ::testing::ContainerEq(expected));
    }
Пример #14
0
void IntlCalendarTest::TestJapaneseFormat() {
    Calendar *cal;
    UErrorCode status = U_ZERO_ERROR;
    cal = Calendar::createInstance("ja_JP_TRADITIONAL", status);
    CHECK(status, UnicodeString("Creating ja_JP_TRADITIONAL calendar"));
    
    Calendar *cal2 = cal->clone();
    delete cal;
    cal = NULL;
    
    // Test simple parse/format with adopt
    
    UDate aDate = 999932400000.0; 
    SimpleDateFormat *fmt = new SimpleDateFormat(UnicodeString("MMMM d, yy G"), Locale("en_US@calendar=japanese"), status);
    SimpleDateFormat *fmt2 = new SimpleDateFormat(UnicodeString("MMMM d, yyyy G"), Locale("en_US@calendar=gregorian"), status);
    CHECK(status, "creating date format instance");
    if(!fmt) { 
        errln("Coudln't create en_US instance");
    } else {
        UnicodeString str;
        fmt2->format(aDate, str);
        logln(UnicodeString() + "Test Date: " + str);
        str.remove();
        fmt->format(aDate, str);
        logln(UnicodeString() + "as Japanese Calendar: " + str);
        UnicodeString expected("September 8, 13 Heisei");
        if(str != expected) {
            errln("Expected " + expected + " but got " + str);
        }
        UDate otherDate = fmt->parse(expected, status);
        if(otherDate != aDate) { 
            UnicodeString str3;
            ParsePosition pp;
            fmt->parse(expected, *cal2, pp);
            fmt->format(otherDate, str3);
            errln("Parse incorrect of " + expected + " - wanted " + aDate + " but got " +  " = " +   otherDate + ", " + str3 + " = " + CalendarTest::calToStr(*cal2) );
            
        } else {
            logln("Parsed OK: " + expected);
        }
        delete fmt;
    }

    // Test parse with incomplete information
    fmt = new SimpleDateFormat(UnicodeString("G y"), Locale("en_US@calendar=japanese"), status);
    /* The test data below should points to 1868-09-08T00:00:00 in America/Los_Angeles.
     * The time calculated by original test code uses -7:00 UTC offset, because it assumes
     * DST is observed (because of a timezone bug, DST is observed for early 20th century
     * day to infinite past time).  The bug was fixed and DST is no longer used for time before
     * 1900 for any zones.  However, ICU timezone transition data is represented by 32-bit integer
     * (sec) and cannot represent transitions before 1901 defined in Olson tzdata.  For example,
     * based on Olson definition, offset -7:52:58 should be used for Nov 18, 1883 or older dates.
     * If ICU properly capture entire Olson zone definition, the start time of "Meiji 1" is
     * -3197117222000. -Yoshito
     */
    /* TODO: When ICU support the Olson LMT offset for America/Los_Angeles, we need to update
     * the reference data.
     */
    //aDate = -3197120400000.;
    aDate = -3197116800000.;
    CHECK(status, "creating date format instance");
    if(!fmt) { 
        errln("Coudln't create en_US instance");
    } else {
        UnicodeString str;
        fmt2->format(aDate, str);
        logln(UnicodeString() + "Test Date: " + str);
        str.remove();
        fmt->format(aDate, str);
        logln(UnicodeString() + "as Japanese Calendar: " + str);
        UnicodeString expected("Meiji 1");
        if(str != expected) {
            errln("Expected " + expected + " but got " + str);
        }
        UDate otherDate = fmt->parse(expected, status);
        if(otherDate != aDate) { 
            UnicodeString str3;
            ParsePosition pp;
            fmt->parse(expected, *cal2, pp);
            fmt->format(otherDate, str3);
            errln("Parse incorrect of " + expected + " - wanted " + aDate + " but got " +  " = " +
                otherDate + ", " + str3 + " = " + CalendarTest::calToStr(*cal2) );
        } else {
            logln("Parsed OK: " + expected);
        }
        delete fmt;
    }

    delete cal2;
    delete fmt2;
    CHECK(status, "Error occured");
    
    // Now, try in Japanese
    {
        UnicodeString expect = CharsToUnicodeString("\\u5e73\\u621013\\u5e749\\u67088\\u65e5\\u571f\\u66dc\\u65e5");
        UDate         expectDate = 999932400000.0; // Testing a recent date
        Locale        loc("ja_JP@calendar=japanese");
        
        status = U_ZERO_ERROR;
        simpleTest(loc, expect, expectDate, status);
    }
    {
        UnicodeString expect = CharsToUnicodeString("\\u5e73\\u621013\\u5e749\\u67088\\u65e5\\u571f\\u66dc\\u65e5");
        UDate         expectDate = 999932400000.0; // Testing a recent date
        Locale        loc("ja_JP_TRADITIONAL"); // legacy
        
        status = U_ZERO_ERROR;
        simpleTest(loc, expect, expectDate, status);
    }
    {
        UnicodeString expect = CharsToUnicodeString("\\u5b89\\u6c385\\u5e747\\u67084\\u65e5\\u6728\\u66dc\\u65e5");
        //UDate         expectDate = -6106035600000.0;
        UDate         expectDate = -6106032000000.0; // 1776-07-04T00:00:00Z-0800
        Locale        loc("ja_JP@calendar=japanese");
        
        status = U_ZERO_ERROR;
        simpleTest(loc, expect, expectDate, status);    
        
    }
    {   // Jitterbug 1869 - this is an ambiguous era. (Showa 64 = Jan 6 1989, but Showa could be 2 other eras) )
        UnicodeString expect = CharsToUnicodeString("\\u662d\\u548c64\\u5e741\\u67086\\u65e5\\u91d1\\u66dc\\u65e5");
        UDate         expectDate = 600076800000.0;
        Locale        loc("ja_JP@calendar=japanese");
        
        status = U_ZERO_ERROR;
        simpleTest(loc, expect, expectDate, status);    
        
    }
    {   // This Feb 29th falls on a leap year by gregorian year, but not by Japanese year.
        UnicodeString expect = CharsToUnicodeString("\\u5EB7\\u6B632\\u5e742\\u670829\\u65e5\\u65e5\\u66dc\\u65e5");
        // Add -1:00 to the following for historical TZ - aliu
        //UDate         expectDate =  -16214403600000.0;  // courtesy of date format round trip test
        UDate         expectDate =  -16214400000000.0;  // 1456-03-09T00:00:00Z-0800
        Locale        loc("ja_JP@calendar=japanese");
        
        status = U_ZERO_ERROR;
        simpleTest(loc, expect, expectDate, status);    
        
    }
}
Пример #15
0
void
PluralFormatTest::pluralFormatExtendedTest(void) {
  const char *targets[] = {
    "There are no widgets.",
    "There is one widget.",
    "There is a bling widget and one other widget.",
    "There is a bling widget and 2 other widgets.",
    "There is a bling widget and 3 other widgets.",
    "Widgets, five (5-1=4) there be.",
    "There is a bling widget and 5 other widgets.",
    "There is a bling widget and 6 other widgets.",
  };

  const char* fmt =
      "offset:1.0 "
      "=0 {There are no widgets.} "
      "=1.0 {There is one widget.} "
      "=5 {Widgets, five (5-1=#) there be.} "
      "one {There is a bling widget and one other widget.} "
      "other {There is a bling widget and # other widgets.}";

  UErrorCode status = U_ZERO_ERROR;
  UnicodeString fmtString(fmt, -1, US_INV);
  PluralFormat pf(Locale::getEnglish(), fmtString, status);
  MessageFormat mf(UNICODE_STRING_SIMPLE("{0,plural,").append(fmtString).append((UChar)0x7d /* '}' */),
                   Locale::getEnglish(), status);
  Formattable args;
  FieldPosition ignore;
  if (U_FAILURE(status)) {
    dataerrln("Failed to apply pattern - %s", u_errorName(status));
    return;
  }
  for (int32_t i = 0; i < 7; ++i) {
    UnicodeString result = pf.format(i, status);
    if (U_FAILURE(status)) {
      errln("PluralFormat.format(value %d) failed - %s", i, u_errorName(status));
      return;
    }
    UnicodeString expected(targets[i], -1, US_INV);
    if (expected != result) {
      UnicodeString message("PluralFormat.format(): Expected '", -1, US_INV);
      message.append(expected);
      message.append(UnicodeString("' but got '", -1, US_INV));
      message.append(result);
      message.append("'", -1, US_INV);
      errln(message);
    }
    args.setLong(i);
    mf.format(&args, 1, result.remove(), ignore, status);
    if (U_FAILURE(status)) {
      errln("MessageFormat.format(value %d) failed - %s", i, u_errorName(status));
      return;
    }
    if (expected != result) {
      UnicodeString message("MessageFormat.format(): Expected '", -1, US_INV);
      message.append(expected);
      message.append(UnicodeString("' but got '", -1, US_INV));
      message.append(result);
      message.append("'", -1, US_INV);
      errln(message);
    }
  }
}
Пример #16
0
void testImplementationInt()
{
    typedef short_vec<CARGO, ARITY> ShortVec;
    const int numElements = ShortVec::ARITY * 10;

    std::vector<CARGO> vec1(numElements);
    std::vector<CARGO> vec2(numElements, 4711);

    // init vec1:
    for (int i = 0; i < numElements; ++i) {
        vec1[i] = i;
    }

    // test default c-tor:
    for (int i = 0; i < numElements; ++i) {
        BOOST_TEST(4711 == vec2[i]);
    }
    for (int i = 0; i < (numElements - ShortVec::ARITY + 1); i += ShortVec::ARITY) {
        ShortVec v;
        &vec2[i] << v;
    }
    for (int i = 0; i < numElements; ++i) {
        BOOST_TEST(0 == vec2[i]);
    }

    // tests vector load/store:
    for (int i = 0; i < (numElements - ShortVec::ARITY + 1); i += ShortVec::ARITY) {
        ShortVec v = &vec1[i];
        &vec2[i] << v;
    }
    for (int i = 0; i < numElements; ++i) {
        BOOST_TEST_EQ(i, vec2[i]);
    }

    // tests scalar load, vector add:
    ShortVec w = vec1[1];

    for (int i = 0; i < (numElements - ShortVec::ARITY + 1); i += ShortVec::ARITY) {
        ShortVec v = &vec1[i];
        &vec2[i] << (v + w);
    }
    for (int i = 0; i < numElements; ++i) {
        BOOST_TEST_EQ((i + 1), vec2[i]);
    }

    // tests +=
    for (int i = 0; i < (numElements - ShortVec::ARITY + 1); i += ShortVec::ARITY) {
        ShortVec v = &vec1[i];
        ShortVec w = &vec2[i];
        v += w;
        &vec2[i] << v;
    }
    for (int i = 0; i < numElements; ++i) {
        BOOST_TEST_EQ((2 * i + 1), vec2[i]);
    }

    // test -
    for (int i = 0; i < (numElements - ShortVec::ARITY + 1); i += ShortVec::ARITY) {
        ShortVec v = &vec1[i];
        ShortVec w = &vec2[i];
        &vec2[i] << (v - w);
    }
    for (int i = 0; i < numElements; ++i) {
        BOOST_TEST_EQ((-i - 1), vec2[i]);
    }

    // test -=
    for (int i = 0; i < (numElements - ShortVec::ARITY + 1); i += ShortVec::ARITY) {
        ShortVec v = &vec1[i];
        ShortVec w = &vec2[i];
        v -= w;
        &vec2[i] << v;
    }
    for (int i = 0; i < numElements; ++i) {
        BOOST_TEST_EQ((2 * i + 1), vec2[i]);
    }

    // test *
    for (int i = 0; i < (numElements - ShortVec::ARITY + 1); i += ShortVec::ARITY) {
        ShortVec v = &vec1[i];
        ShortVec w = &vec2[i];
        &vec2[i] << (v * w);
    }
    for (int i = 0; i < numElements; ++i) {
        int reference = (i * (2 * i + 1));
        BOOST_TEST_EQ(reference, vec2[i]);
    }

    // test *=
    for (int i = 0; i < numElements; ++i) {
        vec2[i] = i + 2;
    }
    for (int i = 0; i < (numElements - ShortVec::ARITY + 1); i += ShortVec::ARITY) {
        ShortVec v = &vec1[i];
        ShortVec w = &vec2[i];
        v *= w;
        &vec2[i] << v;
    }
    for (int i = 0; i < numElements; ++i) {
        BOOST_TEST_EQ(i * (i + 2), vec2[i]);
    }

    // test /
    for (int i = 0; i < numElements; ++i) {
        vec1[i] = 4 * (i + 1);
        vec2[i] = (i + 1);
    }
    for (int i = 0; i < (numElements - ShortVec::ARITY + 1); i += ShortVec::ARITY) {
        ShortVec v = &vec1[i];
        ShortVec w = &vec2[i];
        &vec2[i] << (v / w);
    }
    for (int i = 0; i < numElements; ++i) {
        BOOST_TEST_EQ(4, vec2[i]);
    }

    // test /=
    for (int i = 0; i < numElements; ++i) {
        vec1[i] = 4 * (i + 1);
        vec2[i] = (i + 1);
    }
    for (int i = 0; i < (numElements - ShortVec::ARITY + 1); i += ShortVec::ARITY) {
        ShortVec v = &vec1[i];
        ShortVec w = &vec2[i];
        v /= w;
        &vec2[i] << v;
    }
    for (int i = 0; i < numElements; ++i) {
        BOOST_TEST_EQ(4, vec2[i]);
    }

    // test sqrt()
    for (int i = 0; i < numElements; ++i) {
        vec1[i] = i * i;
    }
    for (int i = 0; i < (numElements - ShortVec::ARITY + 1); i += ShortVec::ARITY) {
        ShortVec v = &vec1[i];
        &vec2[i] << sqrt(v);
    }
    for (int i = 0; i < numElements; ++i) {
        BOOST_TEST_EQ(i, vec2[i]);
    }

    // test "/ sqrt()"
    for (int i = 0; i < numElements; ++i) {
        vec1[i] = (i + 1) * (i + 1);
        vec2[i] = (i + 1) * 2;
    }
    for (int i = 0; i < (numElements - ShortVec::ARITY + 1); i += ShortVec::ARITY) {
        ShortVec v = &vec1[i];
        ShortVec w = &vec2[i];
        &vec2[i] << w / sqrt(v);
    }
    for (int i = 0; i < numElements; ++i) {
        BOOST_TEST_EQ(2, vec2[i]);
    }

    // test string conversion
    for (int i = 0; i < ShortVec::ARITY; ++i) {
        vec1[i] = i + 5;
    }
    ShortVec v(&vec1[0]);
    std::ostringstream buf1;
    buf1 << v;

    std::ostringstream buf2;
    buf2 << "[";
    for (int i = 0; i < (ShortVec::ARITY - 1); ++i) {
        buf2 << (i + 5) << ", ";
    }
    buf2 << (ShortVec::ARITY - 1 + 5) << "]";

    BOOST_TEST(buf1.str() == buf2.str());

    // test gather
    {
        CARGO array[ARITY * 10];
        std::vector<int, aligned_allocator<int, 64> > indices(ARITY);
        CARGO actual[ARITY];
        CARGO expected[ARITY];
        std::memset(array, '\0', sizeof(CARGO) * ARITY * 10);

        for (int i = 0; i < ARITY * 10; ++i) {
            if (i % 10 == 0) {
                array[i] = i + 5;
            }
        }

        for (int i = 0; i < ARITY; ++i) {
            indices[i] = i * 10;
            expected[i] = (i * 10) + 5;
        }

        ShortVec vec;
        vec.gather(array, &indices[0]);
        actual << vec;

        for (int i = 0; i < ARITY; ++i) {
            BOOST_TEST_EQ(actual[i], expected[i]);
        }
    }

#ifdef LIBFLATARRAY_WITH_CPP14
    // test gather via initializer_list
    {
        CARGO actual1[ARITY];
        CARGO actual2[ARITY];
        CARGO expected[ARITY];
        for (int i = 0; i < ARITY; ++i) {
            expected[i] = (i * 10) + 5;
        }

        // max: 32
        ShortVec vec1 = { 5, 15, 25, 35, 45, 55, 65, 75,
                          85, 95, 105, 115, 125, 135, 145, 155,
                          165, 175, 185, 195, 205, 215, 225, 235,
                          245, 255, 265, 275, 285, 295, 305, 315 };
        ShortVec vec2;
        vec2 = { 5, 15, 25, 35, 45, 55, 65, 75,
                 85, 95, 105, 115, 125, 135, 145, 155,
                 165, 175, 185, 195, 205, 215, 225, 235,
                 245, 255, 265, 275, 285, 295, 305, 315 };
        actual1 << vec1;
        actual2 << vec2;
        for (int i = 0; i < ARITY; ++i) {
            BOOST_TEST_EQ(actual1[i], expected[i]);
            BOOST_TEST_EQ(actual2[i], expected[i]);
        }
    }
#endif

    // test scatter
    {
        ShortVec vec;
        CARGO array[ARITY * 10];
        CARGO expected[ARITY * 10];
        std::vector<int, aligned_allocator<int, 64> > indices(ARITY);
        std::memset(array,    '\0', sizeof(CARGO) * ARITY * 10);
        std::memset(expected, '\0', sizeof(CARGO) * ARITY * 10);
        for (int i = 0; i < ARITY * 10; ++i) {
            if (i % 10 == 0) {
                expected[i] = i + 5;
            }
        }
        for (int i = 0; i < ARITY; ++i) {
            indices[i] = i * 10;
        }

        vec.gather(expected, &indices[0]);
        vec.scatter(array, &indices[0]);
        for (int i = 0; i < ARITY * 10; ++i) {
            BOOST_TEST_EQ(array[i], expected[i]);
        }
    }

    // test non temporal stores
    {
        std::vector<CARGO, aligned_allocator<CARGO, 64> > array(ARITY);
        std::vector<CARGO, aligned_allocator<CARGO, 64> > expected(ARITY);

        for (int i = 0; i < ARITY; ++i) {
            expected[i] = 5;
        }
        ShortVec v1 = 5;
        v1.store_nt(&array[0]);
        for (int i = 0; i < ARITY; ++i) {
            BOOST_TEST_EQ(array[i], expected[i]);
        }

        for (int i = 0; i < ARITY; ++i) {
            expected[i] = i;
        }
        ShortVec v2 = &expected[0];
        v2.store_nt(&array[0]);
        for (int i = 0; i < ARITY; ++i) {
            BOOST_TEST_EQ(array[i], expected[i]);
        }
    }

    // test aligned stores
    {
        std::vector<CARGO, aligned_allocator<CARGO, 64> > array(ARITY);
        std::vector<CARGO, aligned_allocator<CARGO, 64> > expected(ARITY);

        for (int i = 0; i < ARITY; ++i) {
            expected[i] = 5;
        }
        ShortVec v1 = 5;
        v1.store_aligned(&array[0]);
        for (int i = 0; i < ARITY; ++i) {
            BOOST_TEST_EQ(array[i], expected[i]);
        }

        for (int i = 0; i < ARITY; ++i) {
            expected[i] = i;
        }
        ShortVec v2 = &expected[0];
        v2.store_aligned(&array[0]);
        for (int i = 0; i < ARITY; ++i) {
            BOOST_TEST_EQ(array[i], expected[i]);
        }
    }

    // test aligned loads
    {
        std::vector<CARGO, aligned_allocator<CARGO, 64> > array(ARITY);
        std::vector<CARGO, aligned_allocator<CARGO, 64> > expected(ARITY);

        for (int i = 0; i < ARITY; ++i) {
            array[i]    = i;
            expected[i] = 0;
        }
        ShortVec v1;
        v1.load_aligned(&array[0]);
        v1.store(&expected[0]);
        for (int i = 0; i < ARITY; ++i) {
            BOOST_TEST_EQ(array[i], expected[i]);
        }
    }
}
Пример #17
0
// Get a statement
numvar getstatement(void) {
numvar retval = 0;

#if !defined(TINY_BUILD) && !defined(UNIX_BUILD)
	chkbreak();
#endif

	if (sym == s_while) {
		// at this point sym is pointing at s_while, before the conditional expression
		// save fetchptr so we can restart parsing from here as the while iterates
		parsepoint fetchmark;
		markparsepoint(&fetchmark);
		for (;;) {
			returntoparsepoint(&fetchmark, 0);
			getsym(); 						// fetch the start of the conditional
			if (getnum()) {
				retval = getstatement();
				if (sym == s_returning) break;	// exit if we caught a return
			}
			else {
				skipstatement();
				break;
			}
		}
	}
	
	else if (sym == s_if) {
		getsym();			// eat "if"
		if (getnum()) {
			retval = getstatement();
			if (sym == s_else) {
				getsym();	// eat "else"
				skipstatement();
			}
		} else {
			skipstatement();
			if (sym == s_else) {
				getsym();	// eat "else"
				retval = getstatement();
			}
		}
	}
	else if (sym == s_lcurly) {
		getsym(); 	// eat "{"
		while ((sym != s_eof) && (sym != s_returning) && (sym != s_rcurly)) retval = getstatement();
		if (sym == s_rcurly) getsym();	// eat "}"
	}
	else if (sym == s_return) {
		getsym();	// eat "return"
		if ((sym != s_eof) && (sym != s_semi)) retval = getnum();
		sym = s_returning;		// signal we're returning up the line
	}

#if !defined(TINY_BUILD)
	else if (sym == s_switch) retval = getswitchstatement();
#endif

	else if (sym == s_function) cmd_function();

	else if (sym == s_run) {	// run macroname
		getsym();
		if ((sym != s_script_eeprom) && (sym != s_script_progmem) &&
			(sym != s_script_file)) unexpected(M_id);

		// address of macroid is in symval via parseid
		// check for [,snoozeintervalms]
		getsym();	// eat macroid to check for comma; symval untouched
		if (sym == s_comma) {
			vpush(symval);
			getsym();			// eat the comma
			getnum();			// get a number or else
			startTask(vpop(), expval);
		}
		else startTask(symval, 0);
	}

	else if (sym == s_stop) {
		getsym();
#if !defined(TINY_BUILD)
		if (sym == s_mul) {						// stop * stops all tasks
			initTaskList();
			getsym();
		}
		else if ((sym == s_semi) || (sym == s_eof)) {
			if (background) stopTask(curtask);	// stop with no args stops the current task IF we're in back
			else initTaskList();				// in foreground, stop all
		}
		else 
#endif
			stopTask(getnum());
	}

	else if (sym == s_rm) {		// rm "sym" or rm *
		getsym();
		if (sym == s_script_eeprom) {
			eraseentry(idbuf);
		} 
#if !defined(TINY_BUILD)
		else if (sym == s_mul) nukeeeprom();
#endif
		else if (sym != s_undef) expected(M_id);
		getsym();
	}
	else if (sym == s_ls) 	{ getsym(); cmd_ls(); }
#if !defined(TINY_BUILD)
	else if (sym == s_boot) cmd_boot();
	else if (sym == s_ps) 	{ getsym();	showTaskList(); }
	else if (sym == s_peep) { getsym(); cmd_peep(); }
	else if (sym == s_help) { getsym(); cmd_help(); }
#endif
	else if (sym == s_print) { getsym(); cmd_print(); }
	else if (sym == s_semi)	{ ; }	// ;)

#ifdef HEX_UPLOAD
	// a line beginning with a colon is treated as a hex record
	// containing data to upload to eeprom
	//
	// TODO: verify checksum
	//
	else if (sym == s_colon) {
		// fetchptr points at the byte count
		byte byteCount = gethex(2);		// 2 bytes byte count
		int addr = gethex(4);			// 4 bytes address
		byte recordType = gethex(2);	// 2 bytes record type; now fetchptr -> data
		if (recordType == 1) reboot();	// reboot on EOF record (01)
		if (recordType != 0) return;	// we only handle the data record (00)
		if (addr == 0) nukeeeprom();	// auto-clear eeprom on write to 0000
		while (byteCount--) eewrite(addr++, gethex(2));		// update the eeprom
		gethex(2);						// discard the checksum
		getsym();						// and re-prime the parser
	}
#endif

	else {
	    getexpression();
	    retval = expval;
	}

	if (sym == s_semi) getsym();		// eat trailing ';'
	return retval;
}
Пример #18
0
static void extractItem(char *buffer, SEXP ans, int i, LocalData *d)
{
    char *endp;
    switch(TYPEOF(ans)) {
    case NILSXP:
	break;
    case LGLSXP:
	if (isNAstring(buffer, 0, d))
	    LOGICAL(ans)[i] = NA_INTEGER;
	else {
	    int tr = StringTrue(buffer), fa = StringFalse(buffer);
	    if(tr || fa) LOGICAL(ans)[i] = tr;
	    else expected("a logical", buffer, d);
	}
	break;
    case INTSXP:
	if (isNAstring(buffer, 0, d))
	    INTEGER(ans)[i] = NA_INTEGER;
	else {
	    INTEGER(ans)[i] = Strtoi(buffer, 10);
	    if (INTEGER(ans)[i] == NA_INTEGER)
		expected("an integer", buffer, d);
	}
	break;
    case REALSXP:
	if (isNAstring(buffer, 0, d))
	    REAL(ans)[i] = NA_REAL;
	else {
	    REAL(ans)[i] = Strtod(buffer, &endp, TRUE, d);
	    if (!isBlankString(endp))
		expected("a real", buffer, d);
	}
	break;
    case CPLXSXP:
	if (isNAstring(buffer, 0, d))
	    COMPLEX(ans)[i].r = COMPLEX(ans)[i].i = NA_REAL;
	else {
	    COMPLEX(ans)[i] = strtoc(buffer, &endp, TRUE, d);
	    if (!isBlankString(endp))
		expected("a complex", buffer, d);
	}
	break;
    case STRSXP:
	if (isNAstring(buffer, 1, d))
	    SET_STRING_ELT(ans, i, NA_STRING);
	else
	    SET_STRING_ELT(ans, i, insertString(buffer, d));
	break;
    case RAWSXP:
	if (isNAstring(buffer, 0, d))
	    RAW(ans)[i] = 0;
	else {
	    RAW(ans)[i] = strtoraw(buffer, &endp);
	    if (!isBlankString(endp))
		expected("a raw", buffer, d);
	}
	break;
    default:
	UNIMPLEMENTED_TYPE("extractItem", ans);
    }
}
Пример #19
0
void simplePlot2D(){
	
	///gROOT->ProcessLine(".x paperStyle.C");
	
	gStyle->SetCanvasDefH(600); //Height of canvas
	gStyle->SetCanvasDefW(640); //Width of canvas
	gStyle->SetCanvasDefX(0);   //POsition on screen
	gStyle->SetCanvasDefY(0);

	gStyle->SetPadLeftMargin(0.125);//0.16);
	gStyle->SetPadRightMargin(0.165);//0.02);
	gStyle->SetPadTopMargin(0.085);//0.02);
	gStyle->SetPadBottomMargin(0.12);//0.02);

	  // For g axis titles:
	gStyle->SetTitleColor(1, "XYZ");
	gStyle->SetTitleFont(42, "XYZ");
	gStyle->SetTitleSize(0.045, "Z");
	gStyle->SetTitleSize(0.055, "XY");
	gStyle->SetTitleXOffset(1.0);//0.9);
	gStyle->SetTitleYOffset(1.12); // => 1.15 if exponents

	// For g axis labels:
	gStyle->SetLabelColor(1, "XYZ");
	gStyle->SetLabelFont(42, "XYZ");
	gStyle->SetLabelOffset(0.007, "XYZ");
	gStyle->SetLabelSize(0.04, "XYZ");

	// Legends
	gStyle->SetLegendBorderSize(0);
	gStyle->SetLegendFillColor(kWhite);
	gStyle->SetLegendFont(42);

	gStyle->SetOptStat(0);
	//gStyle->SetPalette(51);

        /* 
	// Fewer colors, one band per 0.1 
	// *************************************************************
	 int ncontours = 10; 
	 double stops[6]   = {0.0 , .2,   .4,   .6,    .8,    1};  
	 double blue[6]    = {1.0 ,  1,    1,    1,     1,    1}; 
	 double green[6]   = {0.1,  0.3,  0.5,  0.72,   0.82, 1}; 
	 double red [6]    = {0.1,  0.2,  0.24, 0.45,   0.7,  1}; 
	 
	 int npoints = 6; 
	 TColor::CreateGradientColorTable(npoints, stops, red, green, blue, ncontours); 
	 gStyle->SetNumberContours(ncontours); 
	//gStyle->SetPalette(kCherry);
	// *************************************************************
	*/

	// *************************************************************
	 int ncontours = 15; 
	 double stops[5]   = {0.0 ,  .1,   .25    , .5     , 1    };  
	 double blue[5]    = {1.0 ,  1.  , 1  , 1     , 1.00   }; 
	 double green[5]   = {0.25 , 0.3 ,   0.5  , 0.75    , 1.00   }; 
	 double red [5]    = {0.1,  0.15 ,   0.4 , 0.6     , 1.00   }; 
	 
	 int npoints = 5; 
	 TColor::CreateGradientColorTable(npoints, stops, red, green, blue, ncontours); 
	 gStyle->SetNumberContours(ncontours); 
	// *************************************************************

	TFile *fi = TFile::Open("allpoints.root");
	TTree *tree = (TTree*)fi->Get("limit");



	TH2D expected(grKappa(tree,-1));
	TH2D dummyK("dummyK","dummy",1,KVMIN,KVMAX,1,KFMIN,KFMAX);
	dummyK.SetTitle("");
	dummyK.GetZaxis()->SetTitleOffset(1.2);
	dummyK.GetYaxis()->SetTitle("#it{#kappa}_{F}");
	dummyK.GetXaxis()->SetTitle("#it{#kappa}_{V}");
	//dummyK.GetXaxis()->SetRangeUser(KVMIN,KVMAX);
	//dummyK.GetYaxis()->SetRangeUser(KFMIN,KFMAX);
	dummyK.GetZaxis()->SetTitle("B(H #rightarrow inv.) - 95% CL upper limit");
	//dummyK.GetXaxis()->SetLimits(KVMIN,KVMAX);
	//dummyK.GetYaxis()->SetLimits(KFMIN,KFMAX);
	//dummyK.SetMaximum(0.8);
	//dummyK.SetMinimum(0.1);
	
	TCanvas *can = new TCanvas("cc","c",800,720);
	can->cd();
	
	//expected.GetXaxis()->SetRangeUser(KVMIN,KVMAX);
	//expected.GetYaxis()->SetRangeUser(KFMIN,KFMAX);

	TFile *flhc = TFile::Open("scan2d_kappa_V_kappa_F_exp.root");
	TGraph *grlhc_68 = (TGraph*) flhc->Get("graph68_comb_0");
	TGraph *grlhc_95 = (TGraph*) flhc->Get("graph95_comb_0");
	TGraph *grlhc_bf = (TGraph*) flhc->Get("comb_best");
	grlhc_68->SetLineColor(kWhite);
        grlhc_95->SetLineColor(kWhite);
	grlhc_bf->SetMarkerStyle(34);
	grlhc_bf->SetMarkerSize(1.8);
	grlhc_bf->SetMarkerColor(kWhite);

	grlhc_68->SetLineWidth(2);
        grlhc_95->SetLineWidth(2);
        grlhc_95->SetLineStyle(2);

	TH2D *histocomb = (TH2D*)flhc->Get("comb_hist_processed");
	
	double xmin =expected.GetXaxis()->GetXmin();
	double xmax =expected.GetXaxis()->GetXmax();
	double ymin =expected.GetYaxis()->GetXmin();
	double ymax =expected.GetYaxis()->GetXmax();
	TLine SMH(KVMIN,1,KVMAX,1);
	TLine SMV(1,KFMIN,1,KFMAX);
//	TLine SMH(xmin,1,xmax,1);
//	TLine SMV(1,ymin,1,ymax);
	SMH.SetLineColor(2);
	SMH.SetLineStyle(2);
	SMV.SetLineColor(2);
	SMV.SetLineStyle(2);

	//dummyK.Draw("AXIS");
	expected.Draw("colz");
	grlhc_68->Draw("Lsame");
        grlhc_95->Draw("Lsame");
        grlhc_bf->Draw("Psame");

	SMH.Draw("L");
	SMV.Draw("L");
	decorate(can,expected);

	printRanges(&expected,histocomb);

	can->SaveAs("couplings_limits.pdf");
	TFile *fiMU = TFile::Open("allpoints_mu.root");
	TTree *treeMU = (TTree*)fiMU->Get("limit");
	TH2D expectedmu(grMu(treeMU,-1));
	TH2D dummyMu("dummyMu","dummy",1,MUVMIN,MUVMAX,1,MUFMIN,MUFMAX);
	dummyMu.SetTitle("");
	dummyMu.GetZaxis()->SetTitleOffset(1.2);
	dummyMu.GetYaxis()->SetTitle("#it{#mu}_{ggH}");
	dummyMu.GetXaxis()->SetTitle("#it{#mu}_{qqH,VH}");
	dummyMu.GetZaxis()->SetTitle("B(H #rightarrow inv.) - 95% CL upper limit");
	//dummyMu.GetXaxis()->SetRangeUser(MUVMIN,MUVMAX);
	//dummyMu.GetYaxis()->SetRangeUser(MUFMIN,MUFMAX);
	//dummyMu.GetXaxis()->SetLimits(MUVMIN,MUVMAX);
	//dummyMu.GetYaxis()->SetLimits(MUFMIN,MUFMAX);
	//dummyMu.SetMaximum(0.8);
	//dummyMu.SetMinimum(0.1);
	//expectedmu.GetXaxis()->SetRangeUser(KVMIN,KVMAX);
	//expectedmu.GetYaxis()->SetRangeUser(KFMIN,KFMAX);

	xmin =expectedmu.GetXaxis()->GetXmin();
	xmax =expectedmu.GetXaxis()->GetXmax();
	ymin =expectedmu.GetYaxis()->GetXmin();
	ymax =expectedmu.GetYaxis()->GetXmax();

	TLine SM2H(MUVMIN,1,MUVMAX,1);
	TLine SM2V(1,MUFMIN,1,MUFMAX);
	//TLine SM2H(xmin,1,xmax,1);
	//TLine SM2V(1,ymin,1,ymax);
	SM2H.SetLineColor(2);
	SM2H.SetLineStyle(2);
	SM2V.SetLineColor(2);
	SM2V.SetLineStyle(2);

	//dummyMu.Draw("axis");
	expectedmu.Draw("colz");

	TH2D *expectedmuCont = (TH2D*)expectedmu.Clone(); 
	//expectedmuCont->SetName("contours");
	//expectedmuCont->SetContour(15);
	//expectedmuCont->Draw("cont2 same");
	SM2H.Draw("L");
	SM2V.Draw("L");
	decorate(can,expectedmu,false);

	can->SaveAs("mu_limits.pdf");
}
Пример #20
0
		void Parser::parse(double &real)
		{
			if (!lex.getNextToken()) throw expected("real", "end of stream", lex);
			if (lex.tokenType() != Lexer::Real) throw expected("real", lex);
			real = lex.getReal();
		}
Пример #21
0
        TEST(TermTableBuilder, GeneralCases)
        {
            // Construct a test environment that provides the ITermTreatment
            // and DocumentFrequencyTable to be used by the TermTableBuilder.
            // The test environment also provides a hand-constructed expected
            // TermTable for verification purposes.
            TestEnvironment environment;

            // Run the TermTableBuilder to configure a TermTable.
            ITermTreatment const & treatment = environment.GetTermTreatment();
            DocumentFrequencyTable const & terms =
                environment.GetDocFrequencyTable();
            IFactSet const & facts = environment.GetFactSet();
            TermTable termTable;
            double density = 0.1;
            double adhocFrequency = 0.0001;
            unsigned c_randomSkipDistance = 0;
            TermTableBuilder builder(density,
                                     adhocFrequency,
                                     treatment,
                                     terms,
                                     facts,
                                     termTable,
                                     c_randomSkipDistance);

            // builder.Print(std::cout);

            //
            // Verify that configured TermTable is the same as the expected
            // TermTable provided by the environment.
            //

            // Ensure that all known terms have the same RowIdSequences.
            // NOTE: This test relies on the existence of a separate unit test
            // for TermTable that ensures that RowIds and Terms are added
            // correctly. Without such a test, a bogus TermTable that ignores
            // all RowId additions would allow TermTableBuilderTest to pass
            // (because they will both return the empty set of rows).
            for (auto term : terms)
            {
                RowIdSequence expected(term.GetTerm(),
                                       environment.GetTermTable());
                RowIdSequence observed(term.GetTerm(), termTable);

                EXPECT_TRUE(std::equal(observed.begin(),
                                       observed.end(),
                                       expected.begin()));
                EXPECT_TRUE(std::equal(expected.begin(),
                                       expected.end(),
                                       observed.begin()));
            }


            // NOTE: This test relies on the existence of a separate unit test
            // for TermTable that ensures that row counts are recorded
            // correctly. Without such a test, a bogus TermTable that ignores
            // all SetRowCounts would allow TermTableBuilderTest to pass.
            for (Rank rank = 0; rank <= c_maxRankValue; ++rank)
            {
                EXPECT_EQ(environment.GetTermTable().GetTotalRowCount(rank),
                          termTable.GetTotalRowCount(rank));
            }

            // TODO: Verify adhoc
            // TODO: Verify facts
            // TODO: Verify row counts.
        }
Пример #22
0
		void Parser::parse(int &i)
		{
			if (!lex.getNextToken()) throw expected("integer", "end of stream", lex);
			if (lex.tokenType() != Lexer::Integer) throw expected("integer", lex);
			i = lex.getInteger();
		}
Пример #23
0
/*==============================================================================
 * FUNCTION:        DfaTest::testMeetInt
 * OVERVIEW:        Test meeting IntegerTypes with various other types
 *============================================================================*/
void DfaTest::testMeetInt()
{
    IntegerType i32(32, 1);
    IntegerType j32(32, 0);
    IntegerType u32(32, -1);
    IntegerType xint(0);
    IntegerType j16(16, 0);
    SizeType s32(32);
    SizeType s64(64);
    FloatType flt(32);
    PointerType pt(&flt);
    VoidType v;

    bool ch = false;
    i32.meetWith(&i32, ch, false);
    CPPUNIT_ASSERT(ch == false);
    std::ostringstream ost1;
    ost1 << &i32;
    std::string actual(ost1.str());
    std::string expected("i32");
    CPPUNIT_ASSERT_EQUAL(expected, actual);

    i32.meetWith(&j32, ch, false);
    CPPUNIT_ASSERT(ch == false);
    j32.meetWith(&i32, ch, false);
    CPPUNIT_ASSERT(ch == true);
    std::ostringstream ost2;
    ost2 << &i32;
    actual = ost2.str();
    expected = "i32";
    CPPUNIT_ASSERT_EQUAL(expected, actual);

    ch = false;
    j32.setSigned(0);
    j32.meetWith(&v, ch, false);
    CPPUNIT_ASSERT(ch == false);
    std::ostringstream ost2a;
    ost2a << &j32;
    actual = ost2a.str();
    expected = "j32";
    CPPUNIT_ASSERT_EQUAL(expected, actual);

    ch = false;
    j32.meetWith(&u32, ch, false);
    CPPUNIT_ASSERT(ch == true);
    std::ostringstream ost3;
    ost3 << &j32;
    actual = ost3.str();
    expected = "u32";
    CPPUNIT_ASSERT_EQUAL(expected, actual);

    ch = false;
    u32.meetWith(&s32, ch, false);
    CPPUNIT_ASSERT(ch == false);
    std::ostringstream ost4;
    ost4 << &u32;
    actual = ost4.str();
    expected = "u32";
    CPPUNIT_ASSERT_EQUAL(expected, actual);

    u32.meetWith(&s64, ch, false);
    CPPUNIT_ASSERT(ch == true);
    std::ostringstream ost5;
    ost5 << &u32;
    actual = ost5.str();
    expected = "u64";
    CPPUNIT_ASSERT_EQUAL(expected, actual);

    ch = false;
    Type *res = i32.meetWith(&flt, ch, false);
    CPPUNIT_ASSERT(ch == true);
    std::ostringstream ost6;
    ost6 << res;
    actual = ost6.str();
    expected = "union";
    CPPUNIT_ASSERT_EQUAL(expected, actual);

    ch = false;
    res = i32.meetWith(&pt, ch, false);
    CPPUNIT_ASSERT(ch == true);
    std::ostringstream ost7;
    ost7 << res;
    actual = ost7.str();
    expected = "union";
    CPPUNIT_ASSERT_EQUAL(expected, actual);
}
Пример #24
0
		void Parser::parse(char &ch)
		{
			if (!lex.getNextToken()) throw expected("character", "end of stream", lex);
			lex.ungetToken();
			if (!test(ch)) throw expected("character", lex);
		}
Пример #25
0
char get_num()
{
	if(isdigit(look)==0) expected("Integer");
	get_char();
	return look;
}
Пример #26
0
		void Parser::parse(Identifier &identifier)
		{
			if (!lex.getNextToken()) throw expected("identifier", "end of stream", lex);
			if (lex.tokenType() != Lexer::Identifier) throw expected("identifier", lex);
			identifier.str = lex.getIdentifier();
		}
Пример #27
0
// Get a number from the input stream.  Result to expval.
numvar getnum(void) {
	getexpression();
	if (exptype != s_nval) expected(M_number);
	return expval;
}
Пример #28
0
		void Parser::parse(string &str)
		{
			if (!lex.getNextToken()) throw expected("string", "end of stream", lex);
			if (lex.tokenType() != Lexer::String) throw expected("string", lex);
			str = lex.getString();
		}
Пример #29
0
size_t Approximator::test_function (
        const std::string & name,
        const Function & fun)
{
    POMAGMA_INFO("Testing " << name << " approximation");

    size_t ob_fail_count = 0;
    size_t upper_fail_count = 0;
    size_t upper_extra_count = 0;
    size_t upper_missing_count = 0;
    size_t lower_fail_count = 0;
    size_t lower_extra_count = 0;
    size_t lower_missing_count = 0;

    const size_t item_dim = m_item_dim;
    #pragma omp parallel
    {
        DenseSet temp_set(item_dim);

        #pragma omp for schedule(dynamic, 1)
        for (Ob x = 1; x <= item_dim; ++x) {
            Approximation approx_x(x, m_less);
            approx_x.ob = 0;

            for (auto iter = fun.iter_lhs(x); iter.ok(); iter.next()) {
                Ob y = * iter;
                Approximation approx_y(y, m_less);
                approx_y.ob = 0;

                Ob xy = fun.find(x, y);
                Approximation expected(xy, m_less);
                Approximation actual = find(fun, approx_x, approx_y);

                if (actual.ob != expected.ob) {
                    #pragma omp atomic
                    ob_fail_count += 1;
                }
                if (actual.upper != expected.upper) {
                    #pragma omp atomic
                    upper_fail_count += 1;
                    temp_set.set_diff(actual.upper, expected.upper);
                    if (size_t count = temp_set.count_items()) {
                        #pragma omp atomic
                        upper_extra_count += count;
                    }
                    temp_set.set_diff(expected.upper, actual.upper);
                    if (size_t count = temp_set.count_items()) {
                        #pragma omp atomic
                        upper_missing_count += count;
                    }
                }
                if (actual.lower != expected.lower) {
                    #pragma omp atomic
                    lower_fail_count += 1;
                    temp_set.set_diff(actual.lower, expected.lower);
                    if (size_t count = temp_set.count_items()) {
                        #pragma omp atomic
                        lower_extra_count += count;
                    }
                    temp_set.set_diff(expected.lower, actual.lower);
                    if (size_t count = temp_set.count_items()) {
                        #pragma omp atomic
                        lower_missing_count += count;
                    }
                }
            }
        }
    }

    if (ob_fail_count) {
        POMAGMA_WARN(name << " ob failed " << ob_fail_count << " cases");
    }
    if (upper_missing_count or upper_extra_count) {
        POMAGMA_WARN(name << " upper has "
            << upper_missing_count << " missing and "
            << upper_extra_count << " extra obs in "
            << upper_fail_count << " cases");
    }
    if (lower_missing_count or lower_extra_count) {
        POMAGMA_WARN(name << " lower has "
            << lower_missing_count << " missing and "
            << lower_extra_count << " extra obs in "
            << lower_fail_count << " cases");
    }

    return ob_fail_count + upper_fail_count + lower_fail_count;
}
TEST(Basic, FAIL04){
    vector<pair<int, int>> input({});
    vector<int> expected({ 0 });
    Solution sol;
    ASSERT_EQ(sol.findOrder(1, input), expected);
}