Exemplo n.º 1
0
TEST(Vector, reserve) {
  EXPECT_EQ(0, TestItem::counter);

  Vector_TestItem v;
  const size_t MAXITEM = 100;

  v.reserve(1000);

  EXPECT_TRUE(v.empty());
  EXPECT_EQ(static_cast<size_t>(1000), v.capacity());

  for (size_t i = 0; i < MAXITEM; ++i) {
    // push twice
    EXPECT_EQ(i * 2, v.size());
    EXPECT_EQ(static_cast<size_t>(1000), v.capacity());
    v.push_back(TestItem(i)).push_back(TestItem(i));
    EXPECT_EQ(i * 2 + 2, v.size());
    EXPECT_EQ(static_cast<size_t>(1000), v.capacity());
  }

  for (size_t i = 0; i < MAXITEM; ++i) {
    EXPECT_EQ(i, v[i * 2 + 0].v());
    EXPECT_EQ(i, v[i * 2 + 1].v());
  }

  EXPECT_TRUE(!v.empty());
}
Exemplo n.º 2
0
TEST(StringFrom_ForAVector, AcceptsTransformLambdaSoYouCanBuildYourOwnEasily) {
    std::vector<TestItem> items { TestItem(1), TestItem(2), TestItem(3) };

    auto string = StringFrom<TestItem>(items,
    [](TestItem item) {
        return std::to_string(item.Number);
    });

    CHECK_EQUAL("1,2,3", string);
}
Exemplo n.º 3
0
void testCase15()
{
    assert(TestItem::getCount() == 0);
    {
        typedef TinySTL::vector<TestItem> TVector;
        TVector t(10);
        t.push_back(TestItem());
        t.push_back(TestItem());
        t.push_back(TestItem());
        t.insert(t.begin(), t.begin(), t.begin() + 1);

    }
    assert(TestItem::getCount() == 0);

}
Exemplo n.º 4
0
int main(void)
{
    uint32_t u32Item;
    /* Init System, IP clock and multi-function I/O */
    SYS_Init();
    /* Init UART0 for printf */
    UART0_Init();
    /* Init UART1 for testing */
    UART1_Init();

/*---------------------------------------------------------------------------------------------------------*/
/* SAMPLE CODE                                                                                             */
/*---------------------------------------------------------------------------------------------------------*/
    
    printf("\n\nCPU @ %dHz\n", SystemCoreClock);

    do{
        TestItem();
        u32Item = getchar();
        printf("%c\n",u32Item);
        switch(u32Item)
        {
            case '1':   UART_FunctionTest();     break;
            case '2':   IrDA_FunctionTest();     break;
            case '3':   RS485_FunctionTest();    break;
            case '4':   LIN_FunctionTest();      break;
            case '5':   AutoFlow_FunctionTest(); break;
            case '6':   LIN_FunctionTestUsingLinCtlReg();      break;            
            default:    break;
        }
    }while(u32Item != 27); 

}
Exemplo n.º 5
0
TEST(Vector, clear) {
  EXPECT_EQ(0, TestItem::counter);

  Vector_TestItem v;
  v.reserve(1000);
  EXPECT_EQ(static_cast<size_t>(1000), v.capacity());

  v.clear();
  EXPECT_EQ(static_cast<size_t>(0), v.capacity());

  // --------------------
  v.push_back(TestItem(1));
  v.push_back(TestItem(2));
  EXPECT_EQ(static_cast<size_t>(2), v.capacity());

  v.clear();
  EXPECT_EQ(static_cast<size_t>(0), v.capacity());
}
Exemplo n.º 6
0
TEST(Vector, frontback) {
  EXPECT_EQ(0, TestItem::counter);

  Vector_TestItem v;

  const size_t MAXITEM = 10;
  for (size_t i = 0; i < MAXITEM; ++i) {
    v.push_back(TestItem(i));
  }

  EXPECT_EQ(static_cast<size_t>(0), v.front().v());
  EXPECT_EQ(static_cast<size_t>(MAXITEM - 1), v.back().v());
}
Exemplo n.º 7
0
int main(void)
{
    uint32_t u32Item;

    /* Unlock protected registers */
    SYS_UnlockReg();

    /* Init System, peripheral clock and multi-function I/O */
    SYS_Init();

    /* Lock protected registers */
    SYS_LockReg();

    /* Init UART0 for printf */
    UART0_Init();

    /* Init UART1 for testing */
    UART1_Init();

    /*---------------------------------------------------------------------------------------------------------*/
    /* SAMPLE CODE                                                                                             */
    /*---------------------------------------------------------------------------------------------------------*/

    printf("\n\nCPU @ %dHz\n", SystemCoreClock);

    printf("\n\nUART Sample Program\n");

    /* UART sample LIN function */
    do
    {
        TestItem();
        u32Item = getchar();
        printf("%c\n", u32Item);
        switch(u32Item)
        {
            case '1':
                LIN_FunctionTest();
                break;
            case '2':
                LIN_FunctionTestUsingLinCtlReg();
                break;
            default:
                break;
        }
    }
    while(u32Item != 27);

    while(1);

}
Exemplo n.º 8
0
TEST(Vector, push_back) {
  EXPECT_EQ(0, TestItem::counter);

  Vector_TestItem v;
  const size_t MAXITEM = 10;

  EXPECT_TRUE(v.empty());
  EXPECT_EQ(static_cast<size_t>(0), v.capacity());

  for (size_t i = 0; i < MAXITEM; ++i) {
    // push twice
    EXPECT_EQ(i * 2, v.size());
    EXPECT_EQ(i * 2, v.capacity());
    v.push_back(TestItem(i)).push_back(TestItem(i));
    EXPECT_EQ(i * 2 + 2, v.size());
    EXPECT_EQ(i * 2 + 2, v.capacity());
  }

  for (size_t i = 0; i < MAXITEM; ++i) {
    EXPECT_EQ(i, v[i * 2 + 0].v());
    EXPECT_EQ(i, v[i * 2 + 1].v());

    EXPECT_EQ(0, v[i * 2 + 0].vector(0));
    EXPECT_EQ(1, v[i * 2 + 0].vector(1));
    EXPECT_EQ(2, v[i * 2 + 0].vector(2));
    EXPECT_EQ(3, v[i * 2 + 0].vector(3));

    EXPECT_EQ(0, v[i * 2 + 1].vector(0));
    EXPECT_EQ(1, v[i * 2 + 1].vector(1));
    EXPECT_EQ(2, v[i * 2 + 1].vector(2));
    EXPECT_EQ(3, v[i * 2 + 1].vector(3));
  }

  EXPECT_TRUE(!v.empty());

  EXPECT_TRUE(TestItem::counter > 0);
}
void CxResLibImgList::OnRButtonDown(UINT nFlags, CPoint point)
{
	m_ToolTip.Deactivate();
	Invalidate();

	vector<int> vSel;
	int nCurSel = -1;
	TestItem(vSel, nCurSel);

	m_RMenu.DestroyMenu();

	if ( nCurSel != -1 )
	{
		SetItemState(m_nLastFocusItem, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
		RedrawItems(m_nLastFocusItem, m_nLastFocusItem);
	}

	if ( nFlags == MK_RBUTTON && m_nLastFocusItem != -1 )
	{
		if ( vSel.size() == 1 )
		{
			ClearCurSel();
			SetItemState(m_nLastFocusItem, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
			RedrawItems(m_nLastFocusItem, m_nLastFocusItem);
		}

		if ( m_RMenu.GetSafeHmenu() == NULL )
		{
			m_RMenu.LoadMenu(IDR_RESLIB_LIST_POP);
		}
		
		CPoint pt = point;
		ClientToScreen( &pt);
		CMenu * pPopup = m_RMenu.GetSubMenu(0);
		pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, this);

		//不加这句话时,在图片上点击右键菜单,然后在其他窗口点击鼠标,使右键菜单消失。
		//此时,原来被菜单覆盖的图片区域没有被重绘。
		Invalidate();
	}
	
	CxListCtrl::OnRButtonDown(nFlags, point);
}
Exemplo n.º 10
0
 static TestItem extract(const TestItem& item) {
     return TestItem(item.value/extractor_div_with);
 }
Exemplo n.º 11
0
 static TestItem toItem(uint index) {
     return TestItem(index);
 }
Exemplo n.º 12
0
    void testFiltering() {
        clock_t stdTime = 0;
        clock_t algoTime = 0;
        clock_t treeAlgoTime = 0;
        clock_t treeAlgoVisitorTime = 0;

        clock_t insertionStdTime = 0;
        clock_t insertionAlgoTime = 0;
        clock_t insertionTreeAlgoTime = 0;

        typedef Utils::StorableSet<TestItem, TestItemConversion, StaticRepository> RepositorySet;

        const uint cycles = 3000;
        const uint setSize = 1500;

        uint totalItems = 0, totalFilteredItems = 0;

        srand(time(nullptr));
        for(uint a = 0; a < cycles; ++a) {
            KDevelop::ConvenientFreeListSet<TestItem, TestItemHandler> set1;
            std::set<uint> testSet1;

            KDevelop::ConvenientFreeListSet<TestItem, TestItemHandler> set2;
            std::set<uint> testSet2;
            RepositorySet repSet2;

            if(a % (cycles / 10) == 0) {
                qDebug() << "cycle" << a;
            }

            //Build the sets
            extractor_div_with = (rand() % 10) + 1;
            for(uint a = 0; a < setSize; ++a) {
                uint value = rand() % 3000;
                uint divValue = value/extractor_div_with;
                if(!divValue)
                    continue;
//                 qDebug() << "inserting" << value;

                std::set<uint>::const_iterator it = testSet1.lower_bound(value);
                int pos = set1.iterator().lowerBound(TestItem(value));
                //This tests the upperBound functionality
                if (pos != -1) {
                    QVERIFY(it != testSet1.end());
                    QVERIFY(set1.data()[pos].value == *it);
                } else {
                    QVERIFY(it == testSet1.end());
                }

                if((rand() % 10) == 0) {

                    set1.insert(TestItem(value));
                    testSet1.insert(value);
                }

                //This is tuned so in the end, about 99% of all declarations are filtered out, like in the symbol table.
                if((rand() % (extractor_div_with*100)) == 0) {

                    clock_t start = clock();

                    set2.insert(TestItem(divValue));

                    insertionStdTime += clock() - start;
                    start = clock();

                    testSet2.insert(divValue);

                    insertionAlgoTime += clock() - start;
                    start = clock();

                    repSet2.insert(TestItem(divValue));

                    insertionTreeAlgoTime += clock() - start;
                    start = clock();
                }
            }

            std::set<uint> verifySet1;
            for(KDevelop::ConvenientFreeListSet<TestItem, TestItemHandler>::Iterator it = set1.iterator(); it; ++it)
                verifySet1.insert(it->value);

            std::set<uint> verifySet2;
            for(KDevelop::ConvenientFreeListSet<TestItem, TestItemHandler>::Iterator it = set2.iterator(); it; ++it)
                verifySet2.insert(it->value);

            std::set<uint> verifyRepSet2;
            for(RepositorySet::Iterator it = repSet2.iterator(); it; ++it)
                verifyRepSet2.insert((*it).value);

            QCOMPARE(verifySet1, testSet1);
            QCOMPARE(verifySet2, testSet2);
            QCOMPARE(verifyRepSet2, testSet2);

            std::set<uint> algoFiltered;
            std::set<uint> treeAlgoFiltered;
            std::set<uint> treeAlgoVisitorFiltered;

            {
                //Do the filtering once without actions on the filtered items, just for calculating the time
                clock_t start = clock();

                {
                    KDevelop::ConvenientEmbeddedSetFilterIterator<TestItem, TestItemHandler, TestItem, TestItemHandler, Extractor> filterIterator(set1.iterator(), set2.iterator());
                    while(filterIterator)
                        ++filterIterator;

                    algoTime += clock() - start;
                }

                start = clock();

                {
                    KDevelop::ConvenientEmbeddedSetTreeFilterIterator<TestItem, TestItemHandler, TestItem, RepositorySet, Extractor> filterIterator(set1.iterator(), repSet2);
                    while(filterIterator)
                        ++filterIterator;

                    treeAlgoTime += clock() - start;
                }

                {
                    start = clock();

                    NothingDoVisitor v;
                    KDevelop::ConvenientEmbeddedSetTreeFilterVisitor<TestItem, TestItemHandler, TestItem, RepositorySet, Extractor, NothingDoVisitor> visit(v, set1.iterator(), repSet2);

                    treeAlgoVisitorTime += clock() - start;
                }


                start = clock();

                for(std::set<uint>::const_iterator it = testSet1.begin(); it != testSet1.end(); ++it) {
                    if(testSet2.count((*it) / extractor_div_with) == 1) {
                    }
                }

                stdTime += clock() - start;
            }

            {
                KDevelop::ConvenientEmbeddedSetFilterIterator<TestItem, TestItemHandler, TestItem, TestItemHandler, Extractor> filterIterator(set1.iterator(), set2.iterator());
                while(filterIterator) {
                    algoFiltered.insert(filterIterator->value);
                    ++filterIterator;
                }
            }
            {
                KDevelop::ConvenientEmbeddedSetTreeFilterIterator<TestItem, TestItemHandler, TestItem, RepositorySet, Extractor> filterIterator(set1.iterator(), repSet2);
                while(filterIterator) {
                    treeAlgoFiltered.insert((*filterIterator).value);
                    ++filterIterator;
                }
            }
            {
                UintSetVisitor v(treeAlgoVisitorFiltered);
                KDevelop::ConvenientEmbeddedSetTreeFilterVisitor<TestItem, TestItemHandler, TestItem, RepositorySet, Extractor, UintSetVisitor> visit(v, set1.iterator(), repSet2);
            }


            totalItems += testSet1.size();
            totalFilteredItems += algoFiltered.size();


            std::set<uint> stdFiltered;

            for(std::set<uint>::const_iterator it = testSet1.begin(); it != testSet1.end(); ++it) {
                if(testSet2.count((*it) / extractor_div_with) == 1) {
                    stdFiltered.insert(*it);
                }
            }

            QCOMPARE(algoFiltered, stdFiltered);
            QCOMPARE(treeAlgoFiltered, stdFiltered);
            QCOMPARE(treeAlgoVisitorFiltered, stdFiltered);

        }
        qDebug() << "Filtering performance: embedded-list filtering:" << toSeconds(algoTime) << "set-repository filtering:" << toSeconds(treeAlgoTime) << "set-repository visitor filtering:" << toSeconds(treeAlgoVisitorTime) << "std::set filtering:" << toSeconds(stdTime) << "Normal -> Embedded speedup ratio:" << (toSeconds(stdTime) / toSeconds(algoTime)) << "Normal -> Repository speedup ratio:" << (toSeconds(stdTime) / toSeconds(treeAlgoVisitorTime)) << "total processed items:" << totalItems << "total items after filtering:" << totalFilteredItems;
        qDebug() << "Insertion: embedded-list:" << toSeconds(insertionAlgoTime) << "set-repository:" << toSeconds(insertionTreeAlgoTime) << "std::set:" << toSeconds(insertionStdTime);

    }
Exemplo n.º 13
0
 bool contains(uint item) {
     KDevelop::EmbeddedTreeAlgorithms<TestItem, TestItemHandler> alg(data.data(), data.size(), m_centralFree);
     return alg.indexOf(TestItem(item)) != -1;
 }
Exemplo n.º 14
0
 static void createFreeItem(TestItem& data) {
     data = TestItem();
 }
Exemplo n.º 15
0
/*----------------------------------------------------------------------------*/
int main (void)
{
	uint8_t item;
    UNLOCKREG();

    SYS_Init();
    UART0_Init();
    
    /* Set GPD14 to control CAN transceiver for Nuvoton board */
    PD14 = 0;

	/* Select CAN Multi-Function */
    CAN_Init();
    Note_Configure();
    SelectCANSpeed();
    do
    {
        TestItem();
        item = GetChar();    
        printf("\n");
        switch (item)
        {
            case '0':
            {
                printf("[0] Transmit a message by basic mode\n\n");
                printf("Please confirm receiver is ready.\n");
                printf("Press any key to continue ...\n\n");
                GetChar();
                Test_BasicMode_Tx();
                break;     
            }
            case '1': 
            {
                printf("[1] Receive a message by basic mode\n\n");
                Test_BasicMode_Rx();
                break;     
            }
            case '2':
            {
                printf("[2] Transmit a message by normal mode\n\n");
                printf("Please confirm receiver is ready.\n");
                printf("Press any key to continue ...\n\n");
                GetChar();
                Test_NormalMode_Tx();
                break;     
            }
            case '3': 
            {
                printf("[3] Receive a message by normal mode\n\n");
                Test_NormalMode_Rx();
                break;     
            }
            case '4':
            {
                printf("[4] Test Mask Filter\n\n");
                printf("Please confirm [Set Mask Filter] of receiver is selected.\n");
                printf("Press any key to continue ...\n\n");
                GetChar();
                Test_TestMaskFilter();
                break;      
            }
            case '5':
            {
                printf("[5] Set Mask Filter\n\n");
                Test_SetMaskFilter();
                break;
            }
            default:
            {
                printf("Unknown command!\n\n");
            }
              
        }
    }while(item != 27);
	
	CAN_Close(); 
}
Exemplo n.º 16
0
int32_t main(void)							   
{
	int32_t bLoop = true;
	uint32_t com, seg, onoff;
	uint8_t u8Item;
	char input;
	char text[LCD_DIGIT_NUM]="";
	int32_t idx = 0, blinkfreq, ret;
	long long num;
	S_LCD_INIT lcdinit;
	STR_UART_T param;	
	
	SYS_SetChipClockSrc((CLK_PWRCTL_HXT_EN | CLK_PWRCTL_LXT_EN), 1);

	// Wait HXT and LXT stable
	while(SYS_CheckChipClockSrc(CLK_CLKSTATUS_LXT_STB | CLK_CLKSTATUS_HXT_STB) != 0) ;

	/* Select UART Clock Source From 12MHz */
	SYS_SelectIPClockSource_1(CLK_CLKSEL1_UART_MASK, CLK_CLKSEL1_UART_HXT);

	MFP_UART0_TO_PORTA();
	
    param.u32BaudRate         = 115200;
    param.u32cDataBits        = DRVUART_DATABITS_8;
    param.u32cStopBits        = DRVUART_STOPBITS_1;
    param.u32cParity          = DRVUART_PARITY_NONE;
    param.u32cRxTriggerLevel  = DRVUART_FIFO_1BYTES;
    param.u8TimeOut        	  = 0;
    UART_Init(UART0, &param);

	/* Select LCD Clock Source From 32KHz */
	SYS_SelectIPClockSource_1(CLK_CLKSEL1_LCD_MASK, CLK_CLKSEL1_LCD_LXT);

	/* Select LCD Clock Source From 10KHz */
	//SYS_SelectIPClockSource_1(CLK_CLKSEL1_LCD_MASK, CLK_CLKSEL1_LCD_LIRC);

	/* Select LCD COMs, SEGs, V1 ~ V3, DH1, DH2 */
	MFP_LCD_TYPEA();
	
	/* LCD Initialize */
	lcdinit.cpump_enable = true;
	lcdinit.internal_bias = false;
	lcdinit.cpump_freqdiv = LCD_CPUMP_DIV1;
	lcdinit.cpump_voltage = LCD_CPVOl_3V;
	lcdinit.bias = LCD_BIAS_THIRD;
	lcdinit.mux = LCD_MUX_ONE_FOURTH;
	lcdinit.freqdiv = LCD_FREQ_DIV64;
	LCD_Init(&lcdinit);

	while(bLoop)
	{
		idx = 0;
		strcpy(text, "");	// clear buffer
			
		TestItem();
		u8Item = getchar();
		printf("%c\n", u8Item);
		
		switch(u8Item)
		{
			case '0':
			{					
				printf("Input text: ");
				while(1)
				{
					input = getchar();
					printf("%c", input);
					if(input == 0xD) break;
					strcat( text, &input);
					idx++;
					if(idx >= LCD_ALPHABET_NUM) break;
				}
				printf("\n");
				printf("%s \n", text);

				LCD_Write(text);						

				break;
			}
			case '1':
			{
				printf("Input number: ");
				while(1)
				{
					input = getchar();
					printf("%c", input);
					if(input == 0xD) break;
					strcat( text, &input);
					idx++;
					if(idx >= LCD_DIGIT_NUM) break;
				}
				printf("\n");

				//num = atof(text);
				num = local_atoi(text);

				LCD_Number(num);						
								
				break;				
			}
			case '2':
			{
				//DrvLCD_Write("NUVOTON");
				LCD_Number(8888888888888);
input:					
				printf("Input the frequency of blinking (ms): ");
				blinkfreq = sysGetNum();
				printf("\n");
				ret = LCD_BlinkFrequency(blinkfreq);
				if(ret == ERR_LCD_CAL_BLINK_FAIL)
				{
					printf("Over the time range and input again...\n");
					goto input;
				}
				LCD_EnableInt(LCD_FRAMECOUNT_INT);
				LCD_EnableBlink();

				printf("Any key to end Blinking display...");
				getchar();
				LCD_DisableBlink();
				break;
			}
			case '3':
				printf("Pixel On/Off (1:On, 0:Off): ");
				onoff = sysGetNum();
				printf("\n");
				if(onoff>1) continue;

				printf("Input Com: ");
				com = sysGetNum();

				printf("\nInput Segment: ");
				seg = sysGetNum();

				if(onoff)
					LCD_EnableSegment(com, seg);
				else
					LCD_DisableSegment(com, seg);
				break;
			case '4':
				bLoop = false;
				break;
			default:
				printf("Wrong Item\n");
				break;			
		}
			
	}	

	LCD_Disable();
		
	return true;

}